os/textandloc/textrendering/word/SRC/WPAPPUT.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <s32std.h>
sl@0
    20
#include <txtrich.h>
sl@0
    21
#include <frmprint.h>
sl@0
    22
#include <frmvis.h>
sl@0
    23
#include <prnsetup.h>
sl@0
    24
#include <apgdoor.h>
sl@0
    25
#include <coeutils.h>
sl@0
    26
#include <barsread.h>
sl@0
    27
sl@0
    28
#include <techview/eikchlst.h>
sl@0
    29
#include <eikembal.h>
sl@0
    30
#include <eikenv.h>
sl@0
    31
#include <eikproc.h>
sl@0
    32
#include <techview/eiktbar.h>
sl@0
    33
#include <techview/eikprtpv.h>
sl@0
    34
#include <techview/eikprtdg.h>
sl@0
    35
#include <techview/eikpword.h>
sl@0
    36
#include <techview/eikbtgpc.h>
sl@0
    37
#include <techview/eikon.rsg>
sl@0
    38
#include <eikon.mbg>
sl@0
    39
sl@0
    40
#include "WPAPPUI.H"
sl@0
    41
#include "WPDIALGS.H"
sl@0
    42
#include "WPDOC.H"
sl@0
    43
#include "WPTEST.H"
sl@0
    44
#include <word.rsg>
sl@0
    45
#include "WORD.HRH"
sl@0
    46
sl@0
    47
const TInt KZoomStateOne=660;
sl@0
    48
const TInt KZoomStateTwo=800;
sl@0
    49
const TInt KZoomStateThree=TZoomFactor::EZoomOneToOne;
sl@0
    50
const TInt KZoomStateFour=1500;
sl@0
    51
const TInt KDefaultZoomState=KZoomStateTwo;
sl@0
    52
sl@0
    53
const TInt KFirstPageNum=0;
sl@0
    54
sl@0
    55
const TInt KPrintPreviewBandsPerPage=6;
sl@0
    56
sl@0
    57
TBool CWordAppUi::ProcessCommandParametersL(TApaCommand aCommand ,TFileName& aDocumentName, const TDesC8& /*aTail*/)
sl@0
    58
//
sl@0
    59
	{return CEikAppUi::ProcessCommandParametersL(aCommand,aDocumentName);}
sl@0
    60
sl@0
    61
sl@0
    62
void CWordAppUi::CreateEdwinL()
sl@0
    63
	{
sl@0
    64
	CGraphicsDevice* device=iCoeEnv->ScreenDevice();
sl@0
    65
	iAppZoom.SetGraphicsDeviceMap(device);
sl@0
    66
	iAppZoom.SetZoomFactor(KDefaultZoomState);
sl@0
    67
	iRichEd=new(ELeave) CWordTextEditor(TGulBorder::ESingleBlack);
sl@0
    68
	const TInt flags=EEikEdwinOwnsWindow|EEikEdwinKeepDocument|EEikEdwinInclusiveSizeFixed|EEikEdwinUserSuppliedText|
sl@0
    69
						EEikEdwinNoAutoSelection|EEikEdwinAlwaysShowSelection;
sl@0
    70
	iRichEd->ConstructL(NULL,0,0,flags);
sl@0
    71
	iRichEd->SetObserver(this);
sl@0
    72
	iRichEd->SetEdwinObserver(this);
sl@0
    73
	iRichEd->CreateScrollBarFrameL();
sl@0
    74
	iRichEd->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
sl@0
    75
	iRichEd->SetAdjacent(EGulAdjTop|EGulAdjRight);
sl@0
    76
	iRichEd->SetZoomFactorL(&iAppZoom);
sl@0
    77
	//
sl@0
    78
	SetEdwinL();
sl@0
    79
	// 
sl@0
    80
	iTest = CWordTest::NewL(iRichEd->TextView());	
sl@0
    81
	iTest->TurnOnCustomDrawing(iRichEd->TextLayout());
sl@0
    82
	iRichEd->ActivateL();
sl@0
    83
//	iRichEd->SetFocus(ETrue);
sl@0
    84
	AddToStackL(iRichEd);
sl@0
    85
	iRichEd->TextView()->SetParagraphFillTextOnly(ETrue);  // call when text view has been initalised
sl@0
    86
	SetReadOnly(iEmbeddedAndReadOnly);
sl@0
    87
	}
sl@0
    88
sl@0
    89
sl@0
    90
void CWordAppUi::HandleModelChangeL()
sl@0
    91
	{
sl@0
    92
	iModel=Document()->Model();
sl@0
    93
	SetUiData();
sl@0
    94
	ResetPrint();
sl@0
    95
	ResetEdwinL();  // may use print data if in wysiwyg mode.
sl@0
    96
	UpdateToolbarsL();
sl@0
    97
	SetPaginationOutOfDate(ETrue);
sl@0
    98
	iEikonEnv->BusyMsgCancel();
sl@0
    99
	if (iRichEd->IsReadOnly())
sl@0
   100
		iEikonEnv->InfoMsg(R_WORD_FILE_READ_ONLY);
sl@0
   101
	iRichEd->TextView()->SetCursorPlacement(ECursorVertical);
sl@0
   102
	}
sl@0
   103
sl@0
   104
sl@0
   105
void CWordAppUi::ReformatDueToStateChangeL()
sl@0
   106
// Called from numerous places where content has
sl@0
   107
// changed, requiring a reformat of the current document.
sl@0
   108
//
sl@0
   109
	{
sl@0
   110
	iRichEd->NotifyNewFormatL();
sl@0
   111
	UpdateToolbandButtonsL();
sl@0
   112
	SetPaginationOutOfDate(ETrue);
sl@0
   113
	}
sl@0
   114
sl@0
   115
sl@0
   116
void CWordAppUi::UpdateToolbarsL()
sl@0
   117
	{
sl@0
   118
	UpdateToolbandButtonsL();
sl@0
   119
	UpdateFileNameLabelL();
sl@0
   120
	ResetFlags();
sl@0
   121
	}
sl@0
   122
sl@0
   123
void CWordAppUi::ResetEdwinL()
sl@0
   124
	{
sl@0
   125
	iRichEd->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOff);
sl@0
   126
	if (WysiwygModeIsSet())
sl@0
   127
		iRichEd->SetWysiwygModeOn(PageLayoutWidth(),iModel->PrintSetup()->PrinterDevice());
sl@0
   128
	else
sl@0
   129
		iRichEd->SetWysiwygModeOff();
sl@0
   130
	SetEdwinL();
sl@0
   131
	TInt adjacent=EGulAdjNone;
sl@0
   132
	if (iEikonEnv->AppUiFactory()->ToolBar()->IsVisible())
sl@0
   133
		adjacent |= EGulAdjRight;
sl@0
   134
	if (iEikonEnv->AppUiFactory()->ToolBand()->IsVisible())
sl@0
   135
		adjacent |= EGulAdjTop;
sl@0
   136
	iRichEd->SetAdjacent(adjacent);
sl@0
   137
	TViewYPosQualifier yPosQualifier;
sl@0
   138
	yPosQualifier.SetMakeLineFullyVisible();
sl@0
   139
	yPosQualifier.SetFillScreen();
sl@0
   140
	yPosQualifier.SetHotSpot(TViewYPosQualifier::EFViewBottomOfLine);
sl@0
   141
	TInt docPos=iRichEd->TextView()->Selection().iCursorPos;
sl@0
   142
	TInt yPos=iRichEd->TextView()->ViewRect().iBr.iY;
sl@0
   143
	iRichEd->TextView()->SetViewL(docPos,yPos,yPosQualifier,CTextView::EFViewDiscardAllNoRedraw);  // !! casues format
sl@0
   144
	iRichEd->SetRect(ClientRect());  // !! causes format but no draw
sl@0
   145
	if (WysiwygModeIsSet())
sl@0
   146
		iRichEd->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,CEikScrollBarFrame::EAuto);
sl@0
   147
	else
sl@0
   148
		iRichEd->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);
sl@0
   149
	//
sl@0
   150
	// for use when running as a main document.
sl@0
   151
	// Read-only status is determined by looking at the AppFileMode.
sl@0
   152
	if (iContainerAppUi)
sl@0
   153
		SetReadOnly(iEmbeddedAndReadOnly);
sl@0
   154
	else
sl@0
   155
		SetReadOnly((TBool)!(iDocument->AppFileMode()&EFileWrite));
sl@0
   156
	//
sl@0
   157
	iRichEd->ForceScrollBarUpdateL();
sl@0
   158
	iRichEd->NotifyNewFormatL(); // re-flow layout
sl@0
   159
	iRichEd->DrawNow();  // !! causes draw
sl@0
   160
	UpdateToolbandButtonsL(EVisibilityDependant);
sl@0
   161
	UpdateFileNameLabelL();
sl@0
   162
	iCoeEnv->WsSession().Flush();
sl@0
   163
	}
sl@0
   164
sl@0
   165
void CWordAppUi::SetEdwinL()
sl@0
   166
	{
sl@0
   167
	iModel=Document()->Model();
sl@0
   168
	iRichEd->SetDocumentContentL(*Text(),CEikEdwin::EUseText);
sl@0
   169
	iRichEd->SetRect(ClientRect());	
sl@0
   170
	iRichEd->InitialiseUnifiedEditorL();
sl@0
   171
	CFbsBitmap* lineCursor=iEikonEnv->CreateBitmapL(TPtrC(),EMbmEikonLncusr1);
sl@0
   172
	iRichEd->SetLineCursorBitmapL(lineCursor);
sl@0
   173
	}
sl@0
   174
sl@0
   175
void CWordAppUi::ResetPrint()
sl@0
   176
	{
sl@0
   177
	iPrintSetup=iModel->PrintSetup();
sl@0
   178
	CTextPageRegionPrinter& printer=PageRegionPrinter();
sl@0
   179
	printer.SetFirstPageOfDoc(KFirstPageNum);
sl@0
   180
	printer.SetDocument(Text());
sl@0
   181
	printer.SetPrinterDevice(iPrintSetup->PrinterDevice());
sl@0
   182
	printer.SetPageList(iModel->PageTable());	 
sl@0
   183
	printer.SetPageMarginsInTwips(iPrintSetup->iPageMarginsInTwips.iMargins);	
sl@0
   184
	printer.SetPageSpecInTwips(iPrintSetup->PrinterDevice()->CurrentPageSpecInTwips());	
sl@0
   185
	printer.SetParagraphFillTextOnly(ETrue);
sl@0
   186
	}
sl@0
   187
sl@0
   188
void CWordAppUi::ResetFlags()
sl@0
   189
	{
sl@0
   190
	iAlignment = RTmParFormat::EAlignNormal;
sl@0
   191
	iWordFlags &= EWysiwygModeOn;
sl@0
   192
	}
sl@0
   193
sl@0
   194
void CWordAppUi::RunGoToDialogL()
sl@0
   195
	{
sl@0
   196
	TInt pageNo=1;	  // etext should provide a function that gives current page number.
sl@0
   197
	TInt aMaxPages=iModel->PageTable()->Count();
sl@0
   198
	CEikDialog* dialog=new(ELeave) CWordGoToDialog(aMaxPages,&pageNo);
sl@0
   199
	if (!dialog->ExecuteLD(R_WORD_DIALOG_GOTO))
sl@0
   200
        return;
sl@0
   201
	TInt total=0;
sl@0
   202
	CArrayFix<TInt>* pageTable=iModel->PageTable();
sl@0
   203
	for (TInt ii=0;ii<pageNo-1;ii++)
sl@0
   204
		total+=(*pageTable)[ii];
sl@0
   205
    iRichEd->SetCursorPosL(total,EFalse);
sl@0
   206
	}
sl@0
   207
sl@0
   208
void CWordAppUi::SetBulletL()
sl@0
   209
	{
sl@0
   210
	TParaFormatMask mask;
sl@0
   211
	CParaFormat* paraFormat = CParaFormat::NewLC();
sl@0
   212
	const TCursorSelection cursorSelection = iRichEd->TextView()->Selection();
sl@0
   213
	const TInt lower = cursorSelection.LowerPos();
sl@0
   214
	const TInt selectionLength = cursorSelection.Length();
sl@0
   215
	CRichText* text = Text();
sl@0
   216
	text->GetParaFormatL(paraFormat, mask, lower, selectionLength);
sl@0
   217
	delete paraFormat->iBullet;
sl@0
   218
	mask.ClearAll();
sl@0
   219
	mask.SetAttrib(EAttBullet);
sl@0
   220
	mask.SetAttrib(EAttIndent);
sl@0
   221
	if (((CEikButtonBase*)iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonBullets))->State() == CEikButtonBase::EClear)
sl@0
   222
		{
sl@0
   223
		paraFormat->iBullet = NULL;
sl@0
   224
		paraFormat->iIndentInTwips = 0;
sl@0
   225
		}
sl@0
   226
	else
sl@0
   227
		{
sl@0
   228
		TBullet* bullet = new(ELeave) TBullet;
sl@0
   229
		if (!iBullet)
sl@0
   230
			CreateDefaultBulletL();
sl@0
   231
		*bullet = *iBullet;
sl@0
   232
		paraFormat->iBullet = bullet;
sl@0
   233
		if (iBullet->iHangingIndent)
sl@0
   234
			paraFormat->iIndentInTwips = 283; // about 1/2cm - completely arbitrary value !!
sl@0
   235
		else
sl@0
   236
			paraFormat->iIndentInTwips = 0;
sl@0
   237
		}
sl@0
   238
	iRichEd->ApplyParaFormatL(paraFormat, mask);
sl@0
   239
	CleanupStack::PopAndDestroy();
sl@0
   240
	}
sl@0
   241
sl@0
   242
void CWordAppUi::RunSelectBulletDialogL()
sl@0
   243
	{
sl@0
   244
	if (!iBullet)
sl@0
   245
		CreateDefaultBulletL();
sl@0
   246
	CParaFormat* paraFormat=CParaFormat::NewLC();
sl@0
   247
	TParaFormatMask paraUndeterminedMask;
sl@0
   248
	TCharFormat charFormat;
sl@0
   249
	TCharFormatMask charFormatMask;
sl@0
   250
	const TCursorSelection selection=iRichEd->TextView()->Selection();
sl@0
   251
	Text()->GetParaFormatL(paraFormat,paraUndeterminedMask,selection.LowerPos(),selection.Length());
sl@0
   252
	Text()->GetCharFormat(charFormat,charFormatMask,selection.LowerPos(),selection.Length());
sl@0
   253
	TRgb backColor=paraFormat->iFillColor;
sl@0
   254
	if (paraUndeterminedMask.AttribIsSet(EAttFillColor))
sl@0
   255
		backColor=KRgbWhite; // what else could be done ???
sl@0
   256
	if (paraFormat->iBullet)
sl@0
   257
		*iBullet=*paraFormat->iBullet;
sl@0
   258
	CEikDialog* dialog=new(ELeave) CWordBulletDialog(iBullet,backColor,NULL,charFormat.iFontSpec.iTypeface.iName);
sl@0
   259
	if (dialog->ExecuteLD(R_WORD_DIALOG_BULLET))
sl@0
   260
		{
sl@0
   261
		CEikButtonBase* but = (CEikButtonBase*)iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonBullets);
sl@0
   262
		but->SetState(CEikButtonBase::ESet);
sl@0
   263
		SetBulletL();
sl@0
   264
		but->DrawNow();
sl@0
   265
		}
sl@0
   266
	CleanupStack::PopAndDestroy();
sl@0
   267
	}
sl@0
   268
sl@0
   269
void CWordAppUi::CreateDefaultBulletL()
sl@0
   270
	{
sl@0
   271
	iBullet=new(ELeave) TBullet;
sl@0
   272
	iBullet->iCharacterCode=0x2022;
sl@0
   273
	iBullet->iHeightInTwips=iEikonEnv->NormalFont()->FontSpecInTwips().iHeight;
sl@0
   274
	iBullet->iTypeface.iName=_L("Swiss");
sl@0
   275
	}
sl@0
   276
sl@0
   277
void CWordAppUi::SetParaAlignmentL(TInt aIndex)
sl@0
   278
	{
sl@0
   279
	RTmParFormatLayer format;
sl@0
   280
	format.iMask.iFlags = 0;
sl@0
   281
	format.iMask.Set(TTmParFormatMask::EAlignment);
sl@0
   282
	switch(aIndex)
sl@0
   283
		{
sl@0
   284
		case 0:
sl@0
   285
		case EWordCmdAlignLeft:
sl@0
   286
			format.iFormat.iAlignment = RTmParFormat::EAlignNormal;
sl@0
   287
			break;
sl@0
   288
		case 1:
sl@0
   289
		case EWordCmdAlignCenter:	
sl@0
   290
			format.iFormat.iAlignment = RTmParFormat::EAlignCenter;
sl@0
   291
			break;
sl@0
   292
		case 2:
sl@0
   293
		case EWordCmdAlignRight:
sl@0
   294
			format.iFormat.iAlignment = RTmParFormat::EAlignReverse;
sl@0
   295
			break;
sl@0
   296
		case 3:
sl@0
   297
		case EWordCmdAlignJustify:
sl@0
   298
			format.iFormat.iAlignment = RTmParFormat::EAlignJustify;
sl@0
   299
			break;
sl@0
   300
		default:
sl@0
   301
			format.iFormat.iAlignment = RTmParFormat::EAlignNormal;
sl@0
   302
		}
sl@0
   303
	TCursorSelection sel = iRichEd->Selection();
sl@0
   304
	iRichEd->SetParFormatL(sel.LowerPos(),sel.Length(),format);
sl@0
   305
	UpdateAlignButtonL(format.iFormat.iAlignment);
sl@0
   306
	}
sl@0
   307
sl@0
   308
sl@0
   309
void CWordAppUi::CmdChangeAlignmentL()
sl@0
   310
	{
sl@0
   311
	CParaFormat format;
sl@0
   312
	TParaFormatMask undeterminedMask;
sl@0
   313
	const TCursorSelection selection=iRichEd->Selection();
sl@0
   314
	Text()->GetParaFormatL(&format,undeterminedMask,selection.LowerPos(),selection.Length());
sl@0
   315
	//
sl@0
   316
	TInt index=format.iHorizontalAlignment+1;  // toggle the alignment
sl@0
   317
	//
sl@0
   318
	if (undeterminedMask.AttribIsSet(EAttAlignment))
sl@0
   319
		index=4;  // ...to force default case
sl@0
   320
	//
sl@0
   321
	if (index>=4)
sl@0
   322
		index=0;  // where alignment > justifed, make it left aligned.
sl@0
   323
	SetParaAlignmentL(index);
sl@0
   324
	}
sl@0
   325
sl@0
   326
sl@0
   327
void CWordAppUi::ZoomL(TInt aZoomCmd)
sl@0
   328
	{
sl@0
   329
	TInt zoomFactor=iAppZoom.ZoomFactor();
sl@0
   330
	
sl@0
   331
	if (zoomFactor>KZoomStateFour)
sl@0
   332
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateOne : KZoomStateFour;
sl@0
   333
	
sl@0
   334
	else if (zoomFactor==KZoomStateFour)
sl@0
   335
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateOne : KZoomStateThree;
sl@0
   336
	
sl@0
   337
	else if (zoomFactor>KZoomStateThree)
sl@0
   338
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateFour : KZoomStateThree;
sl@0
   339
	
sl@0
   340
	else if (zoomFactor==KZoomStateThree)
sl@0
   341
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateFour : KZoomStateTwo;
sl@0
   342
sl@0
   343
	else if (zoomFactor>KZoomStateTwo)
sl@0
   344
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateThree : KZoomStateTwo;
sl@0
   345
sl@0
   346
	else if (zoomFactor==KZoomStateTwo)
sl@0
   347
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateThree : KZoomStateOne;
sl@0
   348
	
sl@0
   349
	else if (zoomFactor>KZoomStateOne)
sl@0
   350
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateTwo : KZoomStateOne;
sl@0
   351
	
sl@0
   352
	else if (zoomFactor==KZoomStateOne)
sl@0
   353
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateTwo : KZoomStateFour;
sl@0
   354
	
sl@0
   355
	else
sl@0
   356
		zoomFactor=(aZoomCmd==EEikCmdZoomIn) ? KZoomStateOne : KZoomStateFour;
sl@0
   357
	//
sl@0
   358
	iAppZoom.SetZoomFactor(zoomFactor);
sl@0
   359
	TInt bitmapId=EMbmEikonLncusr1;
sl@0
   360
	switch (zoomFactor)
sl@0
   361
		{
sl@0
   362
	case KZoomStateOne:
sl@0
   363
	case KZoomStateTwo:
sl@0
   364
		break;
sl@0
   365
	case KZoomStateThree:
sl@0
   366
		bitmapId=EMbmEikonLncusr3;
sl@0
   367
		break;
sl@0
   368
	case KZoomStateFour:
sl@0
   369
		bitmapId=EMbmEikonLncusr4;
sl@0
   370
		break;
sl@0
   371
	default:
sl@0
   372
		;
sl@0
   373
		}
sl@0
   374
	CFbsBitmap* lineCursor=iEikonEnv->CreateBitmapL(TPtrC(),bitmapId);
sl@0
   375
	iRichEd->SetLineCursorBitmapL(lineCursor);
sl@0
   376
	iRichEd->NotifyNewFormatL();
sl@0
   377
	}
sl@0
   378
sl@0
   379
void CWordAppUi::InsertCharacterL(TChar aCharacter)
sl@0
   380
	{
sl@0
   381
	iRichEd->InsertCharacterL(aCharacter);
sl@0
   382
	UpdateToolbandButtonsL();
sl@0
   383
	SetPaginationOutOfDate(ETrue);
sl@0
   384
	//
sl@0
   385
	if (aCharacter==CEditableText::EPageBreak)
sl@0
   386
		RunPaginationDialogL();
sl@0
   387
	}
sl@0
   388
sl@0
   389
void CWordAppUi::CmdWrapToScreenL()
sl@0
   390
// Toggle the state of the screen mapping.
sl@0
   391
// Swaps between wrap to screen and wrap to page width
sl@0
   392
//
sl@0
   393
	{
sl@0
   394
	TBool wysiwygModeNowOn=ToggleWysiwygMode();
sl@0
   395
	CEikScrollBarFrame::TScrollBarVisibility horizVisibility=(wysiwygModeNowOn)
sl@0
   396
		? CEikScrollBarFrame::EAuto
sl@0
   397
		: CEikScrollBarFrame::EOff;
sl@0
   398
	iRichEd->ScrollBarFrame()->SetScrollBarVisibilityL(horizVisibility,CEikScrollBarFrame::EAuto);
sl@0
   399
	//
sl@0
   400
	if (wysiwygModeNowOn)
sl@0
   401
		UpdatePageLayoutL();  // wrap to the page width
sl@0
   402
	else
sl@0
   403
		{// wrap to screen width
sl@0
   404
		iRichEd->SetWysiwygModeOff();
sl@0
   405
		iRichEd->NotifyNewFormatL();
sl@0
   406
		}
sl@0
   407
	}
sl@0
   408
sl@0
   409
sl@0
   410
void CWordAppUi::UpdatePageLayoutL()
sl@0
   411
	{
sl@0
   412
	if (WysiwygModeIsSet())
sl@0
   413
		{
sl@0
   414
		iRichEd->SetWysiwygModeOn(PageLayoutWidth(),iModel->PrintSetup()->PrinterDevice());
sl@0
   415
		iRichEd->NotifyNewFormatL();
sl@0
   416
		}
sl@0
   417
	}
sl@0
   418
sl@0
   419
TInt CWordAppUi::PageLayoutWidth() const
sl@0
   420
	{
sl@0
   421
	const CPrintSetup* print=Document()->Model()->PrintSetup();
sl@0
   422
	const TPageSpec pageSpec=print->PrinterDevice()->CurrentPageSpecInTwips();
sl@0
   423
	TInt width=(pageSpec.iOrientation? pageSpec.iPortraitPageSize.iHeight : pageSpec.iPortraitPageSize.iWidth);
sl@0
   424
	const TMargins margins=print->iPageMarginsInTwips.iMargins;
sl@0
   425
	width-=(margins.iLeft+margins.iRight);
sl@0
   426
	return width;
sl@0
   427
	}
sl@0
   428
sl@0
   429
void CWordAppUi::RunViewPreferencesDialogL()
sl@0
   430
	{
sl@0
   431
	TNonPrintingCharVisibility visibility=iRichEd->TextLayout()->NonPrintingCharsVisibility();
sl@0
   432
	CWordViewPreferencesDialog* dialog=new(ELeave) CWordViewPreferencesDialog(visibility);
sl@0
   433
	if (dialog->ExecuteLD(R_WORD_DIALOG_VIEW_PREFERENCES))
sl@0
   434
		{
sl@0
   435
		visibility.SetPageBreaksVisible(ETrue);  // for now this is the default
sl@0
   436
		iRichEd->TextLayout()->SetNonPrintingCharsVisibility(visibility);
sl@0
   437
		iRichEd->NotifyNewFormatL();
sl@0
   438
		}
sl@0
   439
	}
sl@0
   440
sl@0
   441
sl@0
   442
void CWordAppUi::RunObjectPreferencesDialogL()
sl@0
   443
	{
sl@0
   444
	TBool sketchAsGlass=SketchAsGlass();
sl@0
   445
	TBool graphAsGlass=GraphAsGlass();
sl@0
   446
	CWordObjectPreferencesDialog* dialog=new(ELeave) CWordObjectPreferencesDialog(sketchAsGlass,graphAsGlass);
sl@0
   447
	if (dialog->ExecuteLD(R_WORD_DIALOG_OBJECT_PREFERENCES))
sl@0
   448
		{
sl@0
   449
		SetSketchAsGlass(sketchAsGlass);
sl@0
   450
		SetGraphAsGlass(graphAsGlass);
sl@0
   451
		}
sl@0
   452
	}
sl@0
   453
sl@0
   454
void CWordAppUi::RunOutlineDialogL()
sl@0
   455
	{
sl@0
   456
	TInt newCursorPosition = 0;
sl@0
   457
sl@0
   458
	CEikDialog* dialog = new(ELeave) CWordOutlineDialog(Document()->Model()->Text(), iRichEd, newCursorPosition);
sl@0
   459
	
sl@0
   460
	if (dialog->ExecuteLD(R_WORD_DIALOG_OUTLINE))
sl@0
   461
		{
sl@0
   462
		iRichEd->SetCursorPosL(newCursorPosition,EFalse);
sl@0
   463
		if (iEikonEnv->AppUiFactory()->ToolBar()->IsVisible() || iEikonEnv->AppUiFactory()->ToolBand()->IsVisible())
sl@0
   464
			iToolBarUpdate->Start(CWordToolBarUpdate::EFullUpdate);
sl@0
   465
		}
sl@0
   466
	 }
sl@0
   467
sl@0
   468
sl@0
   469
TFileName CWordAppUi::BitmapStore() const
sl@0
   470
	{
sl@0
   471
	return _L("*");
sl@0
   472
	}
sl@0
   473
sl@0
   474
sl@0
   475
TBool CWordAppUi::RunPaginationDialogL()
sl@0
   476
	{
sl@0
   477
	TPageTable* pageTable=iModel->PageTable();
sl@0
   478
	const TBool paginationCancelled=iRichEd->RunPaginateDialogL(iPrintSetup,pageTable);
sl@0
   479
	if (!paginationCancelled)
sl@0
   480
		{
sl@0
   481
		iPrintParameters.iFirstPage=0;
sl@0
   482
		iPrintParameters.iLastPage=pageTable->Count()-1;
sl@0
   483
		SetPaginationOutOfDate(EFalse);
sl@0
   484
		Text()->SetPageTable(pageTable);
sl@0
   485
		iRichEd->DrawNow();  // need to display any page breaks immediatley.
sl@0
   486
		}
sl@0
   487
	return paginationCancelled;
sl@0
   488
	}
sl@0
   489
sl@0
   490
sl@0
   491
void CWordAppUi::RunPreviewDialogL()
sl@0
   492
//
sl@0
   493
//
sl@0
   494
	{
sl@0
   495
	TBool paginationCancelled=EFalse;
sl@0
   496
	if (PaginationOutOfDate())
sl@0
   497
		paginationCancelled=RunPaginationDialogL();
sl@0
   498
	if (paginationCancelled)
sl@0
   499
		return;
sl@0
   500
	//
sl@0
   501
	TInt totalNumPages=iModel->PageTable()->Count();
sl@0
   502
	CTextPageRegionPrinter& printer=PageRegionPrinter();
sl@0
   503
	printer.SetPrintPreview(ETrue);
sl@0
   504
	if (CEikPrintPreviewDialog::RunDlgLD(*iPrintSetup, printer, totalNumPages, this, KPrintPreviewBandsPerPage))
sl@0
   505
		DoPrintL();
sl@0
   506
	}
sl@0
   507
sl@0
   508
sl@0
   509
TBool CWordAppUi::PageSetupChangedL(CPrintSetup* aPrintSetup,TInt& aNumPagesInDoc)
sl@0
   510
// Return ETrue if pagination is cancelled, otherwise return EFalse.
sl@0
   511
//
sl@0
   512
	{
sl@0
   513
	CTextPageRegionPrinter& printer=PageRegionPrinter();
sl@0
   514
	printer.SetPageMarginsInTwips(aPrintSetup->iPageMarginsInTwips.iMargins);
sl@0
   515
	printer.SetPageSpecInTwips(aPrintSetup->PrinterDevice()->CurrentPageSpecInTwips());
sl@0
   516
	SetPaginationOutOfDate(ETrue);
sl@0
   517
	SetDocChanged();
sl@0
   518
	if (RunPaginationDialogL())
sl@0
   519
		return ETrue;
sl@0
   520
	aNumPagesInDoc=iModel->PageTable()->Count();
sl@0
   521
	return EFalse;
sl@0
   522
	}
sl@0
   523
sl@0
   524
sl@0
   525
TBool CWordAppUi::RunPrintRangeDialogL(CPrintSetup* aPrintSetup,TInt& aNumPagesInDoc)
sl@0
   526
// Return ETrue if pagination is cancelled, otherwise return EFalse.
sl@0
   527
//
sl@0
   528
	{			 
sl@0
   529
	TUid oldUid = aPrintSetup->PrinterDevice()->Model().iUid;
sl@0
   530
	TUid uid = oldUid;
sl@0
   531
	CEikPrintRangeDialog* dialog = new(ELeave) CEikPrintRangeDialog(iPrintParameters, aPrintSetup, uid);
sl@0
   532
	//
sl@0
   533
	// fix for SW1-157.
sl@0
   534
	// an Eikon defect that cannot be fixed without breaking binary compatibility
sl@0
   535
	//
sl@0
   536
	dialog->iPageRange.iLowerLimit = 1;  // 
sl@0
   537
	dialog->iPageRange.iUpperLimit = iModel->PageTable()->Count();
sl@0
   538
	dialog->ExecuteLD(R_EIK_DIALOG_PRINT_RANGE_SETUP);
sl@0
   539
	if (oldUid != uid)	
sl@0
   540
		{
sl@0
   541
		aPrintSetup->CreatePrinterDeviceL(uid, iEikonEnv->FsSession());
sl@0
   542
		CTextPageRegionPrinter& printer = PageRegionPrinter();
sl@0
   543
		printer.SetPrinterDevice(aPrintSetup->PrinterDevice());
sl@0
   544
		UpdatePageLayoutL();
sl@0
   545
		SetDocChanged();
sl@0
   546
		SetPaginationOutOfDate(ETrue);
sl@0
   547
		if (RunPaginationDialogL())
sl@0
   548
			return ETrue;
sl@0
   549
		}
sl@0
   550
	aNumPagesInDoc = iModel->PageTable()->Count();
sl@0
   551
	return EFalse;  // no cancellation during pagination
sl@0
   552
	}
sl@0
   553
sl@0
   554
void CWordAppUi::RunPrintDialogL()
sl@0
   555
	{
sl@0
   556
	TUid oldUid = iPrintSetup->PrinterDevice()->Model().iUid; 	
sl@0
   557
	TUid uid = oldUid;
sl@0
   558
	CEikPrintRangeDialog* dialog = new(ELeave) CEikPrintRangeDialog(iPrintParameters, iPrintSetup, uid, ETrue);
sl@0
   559
	//
sl@0
   560
	// fix for SW1-157.
sl@0
   561
	// an Eikon defect that cannot be fixed without breaking binary compatibility
sl@0
   562
	//
sl@0
   563
	dialog->iPageRange.iLowerLimit = 1;  // 
sl@0
   564
	dialog->iPageRange.iUpperLimit = iModel->PageTable()->Count();;
sl@0
   565
	if (dialog->ExecuteLD(R_EIK_DIALOG_PRINT_RANGE_SETUP))
sl@0
   566
		{
sl@0
   567
		if (oldUid != uid)
sl@0
   568
			{
sl@0
   569
			iPrintSetup->CreatePrinterDeviceL(uid, iEikonEnv->FsSession());
sl@0
   570
			CTextPageRegionPrinter& printer = PageRegionPrinter();
sl@0
   571
			printer.SetPrinterDevice(iPrintSetup->PrinterDevice());
sl@0
   572
			UpdatePageLayoutL();
sl@0
   573
			SetDocChanged();
sl@0
   574
			SetPaginationOutOfDate(ETrue);
sl@0
   575
			}
sl@0
   576
		}
sl@0
   577
	else
sl@0
   578
		return;
sl@0
   579
	TBool cancel = EFalse;
sl@0
   580
	if (PaginationOutOfDate())
sl@0
   581
		cancel = RunPaginationDialogL();
sl@0
   582
	if (cancel)
sl@0
   583
		return;
sl@0
   584
	DoPrintL();
sl@0
   585
	}
sl@0
   586
sl@0
   587
sl@0
   588
void CWordAppUi::DoPrintL()
sl@0
   589
// Run the print progress dialog
sl@0
   590
//
sl@0
   591
	{
sl@0
   592
	CTextPageRegionPrinter& printer=PageRegionPrinter();
sl@0
   593
	printer.SetPrintPreview(EFalse);
sl@0
   594
	CEikPrintProgressDialog::RunDlgLD(iPrintSetup, &printer, iPrintParameters);
sl@0
   595
	iPrintSetup->FreeModelList();
sl@0
   596
	}
sl@0
   597
sl@0
   598
sl@0
   599
TBool CWordAppUi::ConfirmationDialogL(TConfirmationText aTitle,TConfirmationText aText)const
sl@0
   600
// Generate a query window with the specified text.
sl@0
   601
//
sl@0
   602
	{
sl@0
   603
	TResourceReader reader;
sl@0
   604
	return iEikonEnv->QueryWinL(reader.ReadTPtrC(aTitle,MUTABLE_CAST(HBufC8*,iConfirmationText)),
sl@0
   605
								reader.ReadTPtrC(aText,MUTABLE_CAST(HBufC8*,iConfirmationText)) );
sl@0
   606
	}
sl@0
   607
sl@0
   608
sl@0
   609
void CWordAppUi::GetUiData(TWordUiData& aData)const
sl@0
   610
//
sl@0
   611
	{
sl@0
   612
	aData.iNpcVisibility=0;
sl@0
   613
	if (!(iRichEd && iRichEd->TextLayout()))
sl@0
   614
		return;
sl@0
   615
	TNonPrintingCharVisibility visibility=iRichEd->TextLayout()->NonPrintingCharsVisibility();
sl@0
   616
	if (visibility.TabsVisible())
sl@0
   617
		aData.iNpcVisibility|=ENpcTabsVisible;
sl@0
   618
	if (visibility.SpacesVisible())
sl@0
   619
		aData.iNpcVisibility|=ENpcSpacesVisible;
sl@0
   620
	if (visibility.ParagraphDelimitersVisible())
sl@0
   621
		aData.iNpcVisibility|=NpcParagraphsVisible;
sl@0
   622
	if (visibility.LineBreaksVisible())
sl@0
   623
		aData.iNpcVisibility|=NpcForcedLineBreaksVisible;
sl@0
   624
	if (visibility.PotentialHyphensVisible())
sl@0
   625
		aData.iNpcVisibility|=NpcSoftHyphensVisible;
sl@0
   626
	if (visibility.NonBreakingHyphensVisible())
sl@0
   627
		aData.iNpcVisibility|=NpcHardHyphensVisible;
sl@0
   628
	if (visibility.NonBreakingSpacesVisible())
sl@0
   629
		aData.iNpcVisibility|=NpcHardSpacesVisible;
sl@0
   630
	//
sl@0
   631
	// sketch/graph default appearance
sl@0
   632
	aData.iPicturePrefs=0;
sl@0
   633
	aData.iPicturePrefs=iPicturePrefs;
sl@0
   634
	//
sl@0
   635
	// cursor pos
sl@0
   636
	aData.iCursorPos=iRichEd->CursorPos();
sl@0
   637
	//
sl@0
   638
	// toolbar visibilities
sl@0
   639
	aData.iToolbandVisibility = iEikonEnv->AppUiFactory()->ToolBand()->IsVisible();
sl@0
   640
	aData.iToolbarVisibility = iEikonEnv->AppUiFactory()->ToolBar()->IsVisible();
sl@0
   641
	//
sl@0
   642
	// zoom factor
sl@0
   643
	aData.iZoomFactor=iAppZoom.ZoomFactor();
sl@0
   644
	//
sl@0
   645
	// WYSIWYG flag
sl@0
   646
	aData.iWysiwygOn=WysiwygModeIsSet();
sl@0
   647
	}
sl@0
   648
sl@0
   649
sl@0
   650
void CWordAppUi::SetUiData()
sl@0
   651
	{
sl@0
   652
	const TWordUiData& data=Document()->UiData();
sl@0
   653
	//
sl@0
   654
	// Non-printing-char prefs
sl@0
   655
	TNonPrintingCharVisibility visibility;
sl@0
   656
	visibility.SetPageBreaksVisible(ETrue);
sl@0
   657
	visibility.SetTabsVisible(data.iNpcVisibility&ENpcTabsVisible);
sl@0
   658
	visibility.SetSpacesVisible(data.iNpcVisibility&ENpcSpacesVisible);
sl@0
   659
	visibility.SetParagraphDelimitersVisible(data.iNpcVisibility&NpcParagraphsVisible);
sl@0
   660
	visibility.SetLineBreaksVisible(data.iNpcVisibility&NpcForcedLineBreaksVisible);
sl@0
   661
	visibility.SetPotentialHyphensVisible(data.iNpcVisibility&NpcSoftHyphensVisible);
sl@0
   662
	visibility.SetNonBreakingHyphensVisible(data.iNpcVisibility&NpcHardHyphensVisible);
sl@0
   663
	visibility.SetNonBreakingSpacesVisible(data.iNpcVisibility&NpcHardSpacesVisible);
sl@0
   664
	iRichEd->TextLayout()->SetNonPrintingCharsVisibility(visibility);
sl@0
   665
	//
sl@0
   666
	// sketch/graph default appearance
sl@0
   667
	iPicturePrefs=data.iPicturePrefs;
sl@0
   668
	//
sl@0
   669
	// cursor pos
sl@0
   670
	iRichEd->TextView()->SetPendingSelection(TCursorSelection(data.iCursorPos,data.iCursorPos));
sl@0
   671
	//
sl@0
   672
	// toolbar visibilites
sl@0
   673
	iEikonEnv->AppUiFactory()->ToolBand()->MakeVisible(data.iToolbandVisibility);
sl@0
   674
	iEikonEnv->AppUiFactory()->ToolBar()->MakeVisible(data.iToolbarVisibility);
sl@0
   675
	//
sl@0
   676
	// zoom factor
sl@0
   677
	iAppZoom.SetZoomFactor(data.iZoomFactor);
sl@0
   678
	//
sl@0
   679
	// WYSIWYG flag
sl@0
   680
	if (data.iWysiwygOn)
sl@0
   681
		iWordFlags|=EWysiwygModeOn;
sl@0
   682
	else
sl@0
   683
   		iWordFlags&=~EWysiwygModeOn;
sl@0
   684
	}
sl@0
   685
sl@0
   686
sl@0
   687
TWordUiData::TWordUiData()
sl@0
   688
	:iNpcVisibility(0),
sl@0
   689
	iPicturePrefs(0),
sl@0
   690
	iToolbandVisibility(ETrue),
sl@0
   691
	iToolbarVisibility(ETrue),
sl@0
   692
	iCursorPos(0),
sl@0
   693
	iZoomFactor(KDefaultZoomState),
sl@0
   694
	iWysiwygOn(EFalse)
sl@0
   695
	{}
sl@0
   696
sl@0
   697
sl@0
   698
void TWordUiData::Reset()
sl@0
   699
	{
sl@0
   700
	iNpcVisibility=0;
sl@0
   701
	iPicturePrefs=0;
sl@0
   702
	iToolbandVisibility=ETrue;
sl@0
   703
	iToolbarVisibility=ETrue;
sl@0
   704
	iCursorPos=0;
sl@0
   705
	iZoomFactor=KDefaultZoomState;
sl@0
   706
	iWysiwygOn=EFalse;
sl@0
   707
	}
sl@0
   708
sl@0
   709
sl@0
   710
void TWordUiData::InternalizeL(RReadStream& aStream)
sl@0
   711
	{
sl@0
   712
	TCardinality version;
sl@0
   713
	version.InternalizeL(aStream);
sl@0
   714
	if (version!=KVersionAppConfigurationData)
sl@0
   715
		User::Leave(KErrCorrupt); // !! need better error
sl@0
   716
sl@0
   717
	iNpcVisibility=0;
sl@0
   718
	iNpcVisibility=aStream.ReadUint8L();
sl@0
   719
	iPicturePrefs=0;
sl@0
   720
	iPicturePrefs=aStream.ReadUint8L();
sl@0
   721
	iToolbandVisibility=(TBool)aStream.ReadInt8L();
sl@0
   722
	iToolbarVisibility=(TBool)aStream.ReadInt8L();
sl@0
   723
	iWysiwygOn=(TBool)aStream.ReadInt8L();
sl@0
   724
sl@0
   725
	iCursorPos=aStream.ReadInt32L();
sl@0
   726
	iZoomFactor=aStream.ReadInt32L();
sl@0
   727
	}
sl@0
   728
sl@0
   729
sl@0
   730
void TWordUiData::ExternalizeL(RWriteStream& aStream) const
sl@0
   731
	{
sl@0
   732
	const TCardinality version=KVersionAppConfigurationData;
sl@0
   733
	version.ExternalizeL(aStream);
sl@0
   734
sl@0
   735
	aStream.WriteUint8L((TUint8)iNpcVisibility);
sl@0
   736
	aStream.WriteUint8L((TUint8)iPicturePrefs);
sl@0
   737
	aStream.WriteInt8L(iToolbandVisibility);
sl@0
   738
	aStream.WriteInt8L(iToolbarVisibility);
sl@0
   739
	aStream.WriteInt8L(iWysiwygOn);
sl@0
   740
sl@0
   741
	aStream.WriteInt32L(iCursorPos);
sl@0
   742
	aStream.WriteInt32L(iZoomFactor);
sl@0
   743
	}
sl@0
   744
sl@0
   745