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