os/textandloc/textrendering/word/SRC/WPAPPUI.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 <s32mem.h>
    20 
    21 #include <txtrich.h>
    22 
    23 #include <frmprint.h>
    24 
    25 #include <badesca.h>
    26 
    27 #include <coedef.h>
    28 #include <coeinput.h>
    29 
    30 #include <prnsetup.h>
    31 
    32 #include <techview/eikprtdg.h>
    33 #include <techview/eikmenup.h>
    34 #include <techview/eiktbar.h>
    35 #include <techview/eikbtgpc.h>
    36 #include <techview/eikclb.h>
    37 #include <techview/eikon.rsg>
    38 #include <eikon.mbg>
    39 #include <techview/eiktxlbm.h>
    40 
    41 #include "WPAPPUI.H"
    42 #include "WPDIALGS.H"
    43 #include "WPDOC.H"
    44 #include "WPLBOX.H"
    45 #include "WPSTYLE.H"
    46 #include "WPDEF.H"
    47 #include "WPTEST.H"
    48 #include <word.rsg>
    49 
    50 #include "WORD.HRH"
    51 
    52 
    53 const TUid KUidSheet={0x10003A7D};
    54 const TUid KUidPaintApp={0x1000007D};
    55 // the next four are strictly temporary items!
    56 _LIT(KSketchDllName,"PAINT.APP");
    57 _LIT(KSheetDllName,"SHEET.APP");
    58 
    59 CWordAppUi::CWordAppUi()
    60    	:iAlignment(RTmParFormat::EAlignNormal)
    61 	{
    62 	}
    63 
    64 CWordAppUi::~CWordAppUi()
    65     {
    66 	if (iDoorObserver)
    67 		{
    68 		MApaEmbeddedDocObserver::TExitMode exitMode=MApaEmbeddedDocObserver::EKeepChanges;
    69 		if (!DocHasChanged())
    70 			exitMode=MApaEmbeddedDocObserver::ENoChanges;
    71 		if (Document()->Model()->Text()->DocumentLength()==0)
    72 			exitMode=MApaEmbeddedDocObserver::EEmpty;
    73 		iDoorObserver->NotifyExit(exitMode);
    74 		}
    75 	if (iRichEd)
    76 		RemoveFromStack(iRichEd);
    77 	delete iBullet;
    78 	delete iToolBarUpdate;
    79 	delete iRichEd;
    80 	delete iTwipsList;
    81 	delete iPopoutListBox;
    82 	delete iConfirmationText;
    83 	delete iTest;
    84 	}
    85 
    86 void CWordAppUi::ConstructL()
    87     {
    88 	Document()->SetChanged(FALSE);
    89 	//
    90 	BaseConstructL();
    91 	//
    92 	iModel=Document()->Model();
    93 	ResetPrint();  // initialise print related components
    94 	CreateEdwinL();  // create & initialise edwin components (may use print data if in wysiwyg)
    95 	UpdateToolbarsL();  // set the remainder components of the word view
    96 	//
    97 	iToolBarUpdate=CWordToolBarUpdate::NewL(*this);
    98 	//
    99 	iEikonEnv->AppUiFactory()->ToolBand()->ActivateL();
   100 	iEikonEnv->AppUiFactory()->ToolBar()->ActivateL();
   101 	iEikonEnv->AppUiFactory()->ToolBand()->DrawNow();
   102 	iEikonEnv->AppUiFactory()->ToolBar()->DrawNow();
   103 	iCoeEnv->WsSession().Flush();
   104 	iConfirmationText = iEikonEnv->AllocReadResourceAsDes8L(R_WORD_CONFIRMATION_TEXTS);
   105 	SetPaginationOutOfDate(TRUE);
   106 	iRichEd->SetBookmark();
   107     }
   108 
   109 TKeyResponse CWordAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
   110 	{
   111 	if (iRichEd->IsReadOnly())
   112 		{
   113 		iRichEd->CEikRichTextEditor::OfferKeyEventL(aKeyEvent, aType);
   114 		return EKeyWasConsumed;
   115 		}
   116 	const TBool eventKey(aType == EEventKey);
   117 	const TBool isEnter(aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyLineFeed);
   118 	const TCursorSelection selection = iRichEd->Selection();
   119 	if (eventKey && (aKeyEvent.iModifiers & EModifierCtrl) && (aKeyEvent.iModifiers & EModifierFunc))
   120 		{// Paragraph style hot key
   121 		TChar key = ((aKeyEvent.iCode >= 1) && (aKeyEvent.iCode <= 26))
   122 			? aKeyEvent.iCode + 'A' - 1	// an alphabetic key was pressed.
   123 			: aKeyEvent.iCode;			// a non-alphabetic key was pressed
   124 		if (ProcessStyleHotKeyL(key) == EKeyWasConsumed)
   125 			return EKeyWasConsumed;
   126 		}
   127 	if (eventKey && isEnter && (aKeyEvent.iModifiers & EModifierCtrl))
   128 		{// Insert a breaking character
   129 		InsertCharacterL(CEditableText::EPageBreak);
   130 		return EKeyWasConsumed;
   131 		}
   132 
   133 	if ((aKeyEvent.iCode==EKeySpace || isEnter) && iRichEd->CheckForObjectL())
   134 		{
   135 		return EKeyWasConsumed;
   136 		}
   137 
   138 	// Allow the test harness to apply a custom keyboard map.
   139 	TChar c;
   140 	TKeyResponse r = iTest->OfferKeyEventL(aKeyEvent,aType,c);
   141 	if (r == EKeyWasConsumed)
   142 		{
   143 		if (c != 0xFFFF)
   144 			InsertCharacterL(c);
   145 		return EKeyWasConsumed;
   146 		}
   147 
   148 	/*
   149 	Handle all non-system keycodes via the unified editing interface, (except for space and enter
   150 	on an embedded object, which allow it to be edited).
   151 	*/
   152 	if (eventKey && (aKeyEvent.iCode < 0xF700 || aKeyEvent.iCode >= 0xF900))
   153 		{
   154 		if (aKeyEvent.iCode == EKeyBackspace)
   155 			iRichEd->DeleteLeftL();
   156 		else if (aKeyEvent.iCode == EKeyDelete)
   157 			iRichEd->DeleteRightL();
   158 		else if (aKeyEvent.iCode == EKeySpace && (aKeyEvent.iModifiers & EModifierShift))
   159 			InsertCharacterL(CEditableText::ENonBreakingSpace);
   160 		else if (isEnter)
   161 			{
   162 			InsertCharacterL((aKeyEvent.iModifiers & EModifierShift)?
   163 				CEditableText::ELineBreak : CEditableText::EParagraphDelimiter);
   164 			}
   165 		else
   166 			InsertCharacterL(aKeyEvent.iCode);
   167 		return EKeyWasConsumed;
   168 		}
   169 	iRichEd->CEikRichTextEditor::OfferKeyEventL(aKeyEvent, aType);
   170 	if (eventKey && (iEikonEnv->AppUiFactory()->ToolBar()->IsVisible() || iEikonEnv->AppUiFactory()->ToolBand()->IsVisible()))
   171 		{
   172 		if ((aKeyEvent.iCode == EKeyBackspace || aKeyEvent.iCode == EKeyDelete) && selection.Length())
   173 			iToolBarUpdate->Start(CWordToolBarUpdate::EFullUpdate);
   174 		else if (isEnter && !(aKeyEvent.iModifiers & EModifierShift))
   175 			iToolBarUpdate->Start(CWordToolBarUpdate::EFullUpdate);
   176 		}
   177 	return EKeyWasConsumed;
   178 	}
   179 
   180 TKeyResponse CWordAppUi::ProcessStyleHotKeyL(const TChar& aKey)
   181 // Look up the specified key in the style short cut list.
   182 // Apply the relevant style if found.
   183 //
   184 	{
   185 	const CParagraphStyle* styleToApply=NULL;
   186 	if (aKey==iModel->NormalStyleShortCut())
   187 		styleToApply=REINTERPRET_CAST(const CParagraphStyle*,Text()->GlobalParaFormatLayer());
   188 	else
   189 		{
   190 		const CStyleShortCutList* shortCutList=iModel->StyleShortCutList();
   191 		const TInt count=(shortCutList) ? shortCutList->Count() : 0;
   192 		TInt index=0;
   193 		TBool matched=FALSE;
   194 		while (index<count && !matched)
   195 			{
   196 			TChar match=(*shortCutList)[index];
   197 			if (match==aKey)
   198 				break;
   199 			index++;
   200 			}
   201 		if (index>=count)
   202 			return EKeyWasNotConsumed;  // checked all hotkeys in the list and not matched any of them.
   203 		//there could be a shortcut that hasnt a style
   204 		if ( index > iModel->StyleList()->Count() )
   205 			return EKeyWasNotConsumed; 
   206 		styleToApply=iModel->StyleList()->At(index).iStyle;
   207 		}
   208 	TCursorSelection selection=iRichEd->Selection();
   209 	Text()->ApplyParagraphStyleL(*styleToApply,selection.LowerPos(),selection.Length(),KApplyParaStyleMode);
   210 	ReformatDueToStateChangeL();
   211 	iRichEd->UpdateScrollBarsL();
   212 	return EKeyWasConsumed;
   213 	}
   214 
   215 
   216 void CWordAppUi::SetAndDrawFocus(TBool aFocus)
   217 	{
   218 	if (iRichEd)
   219 		iRichEd->SetFocus(aFocus,EDrawNow);
   220 	}
   221 
   222 
   223 TCoeInputCapabilities CWordAppUi::InputCapabilities() const
   224 	{
   225 	TCoeInputCapabilities inputCapabilities=CEikAppUi::InputCapabilities();
   226 	if ((iRichEd!=NULL) && iRichEd->IsFocused() && !iRichEd->IsReadOnly())
   227 		{
   228 		inputCapabilities.MergeWith(iRichEd->InputCapabilities());
   229 		}
   230 	return inputCapabilities;
   231 	}
   232 
   233 TBool CWordAppUi::DocHasChanged() const
   234 	{
   235 	if (iDocument->HasChanged())
   236 		return ETrue;
   237 	if (iRichEd->IsAtBookmark())
   238 		return EFalse;
   239 	return ETrue;
   240 	}
   241 
   242 void CWordAppUi::HandleCommandL(TInt aCommand)
   243 	{
   244 	switch (aCommand)
   245 		{
   246 	case EEikCmdExit:
   247 		GetUiData(Document()->UiData());
   248 		if (DocHasChanged() && !iContainerAppUi)
   249 			CmdFileSaveL();
   250 		Exit();
   251 		break;
   252 	case EEikCmdFileNew:
   253 	case EEikCmdFileOpen:
   254 	case EEikCmdFileSave:
   255 	case EEikCmdFileSaveAs:
   256 	case EEikCmdFileRevert:
   257 	case EWordCmdFileSaveAsTemplate:
   258 	case EWordCmdFileDeleteTemplate:
   259 		if (iContainerAppUi)
   260 			break;
   261 		else
   262 			{
   263 			switch (aCommand)
   264 				{
   265 			case (EEikCmdFileNew):
   266 				CmdFileNewL();
   267 		        break;
   268 			case (EEikCmdFileOpen):
   269 				CmdFileOpenL();
   270 				break;
   271 			case (EEikCmdFileSave):
   272 				CmdFileSaveL();
   273 				break;
   274 			case (EEikCmdFileSaveAs):
   275 		        CmdFileSaveAsL();
   276 			    break;
   277 			case (EEikCmdFileRevert):
   278 		        CmdFileRevertL();
   279 			    break;
   280 			case (EWordCmdFileSaveAsTemplate):
   281 				CmdFileSaveAsTemplateL();
   282 				break;
   283 			case (EWordCmdFileDeleteTemplate):
   284 				CmdFileDeleteTemplateL();
   285 				break;
   286 				}
   287 			}
   288 		break;
   289 	case EEikCmdEditCopy:
   290 		iRichEd->ClipboardCopyL();
   291 		break;
   292 	case EEikCmdFileExport:
   293 		CmdFileTextExportL();
   294 		break;
   295 	case EWordCmdPageSetup:
   296 		RunPageSetupDialogL();
   297 		break;
   298 	case EEikCmdPrintPaginate:
   299 		RunPaginationDialogL();
   300 		break;
   301 	case EEikCmdPrintPrint:
   302 	case EEikCmdPrintSetup:
   303 	case EEikCmdPrintPreview:										    
   304 	case EWordCmdGoTo:	
   305 		{
   306 		TBool cancel=FALSE;
   307  		if (PaginationOutOfDate())
   308 			cancel=RunPaginationDialogL();
   309 		if (cancel)
   310 			break;
   311 		switch (aCommand)
   312 			{
   313 			case EEikCmdPrintSetup:
   314 				{
   315 				TInt pages=iModel->PageTable()->Count();
   316 				RunPrintRangeDialogL(iPrintSetup,pages);
   317 				break;
   318 				}
   319 			case EEikCmdPrintPrint:
   320 				RunPrintDialogL();
   321 				break;
   322 			case EEikCmdPrintPreview:
   323 				RunPreviewDialogL();
   324 				break;
   325 			case EWordCmdGoTo:
   326 				RunGoToDialogL();
   327 				break;
   328 			}
   329 		break;
   330 		}
   331 	case EEikCmdSearchFind:
   332 		iRichEd->RunFindDialogL();
   333 		break;
   334 	case EEikCmdSearchFindAgain:
   335 		iRichEd->RunFindAgainDialogL();
   336 		break;
   337 	case EEikCmdEditSelectAll:
   338 		{
   339 		const TInt docLength=iRichEd->TextLength();
   340 		if (docLength)
   341 			iRichEd->SetSelectionL(docLength,0);
   342 		break;
   343 		}
   344 	case EWordCmdReEditObject:
   345 		iRichEd->ReEditObjectL();
   346 		break;
   347 	case EWordCmdToolbar:
   348 	case EWordCmdToolband:
   349 		UpdateToolBarAndBandL(aCommand);
   350 		break;
   351 	case EWordCmdWrapToScreen:
   352 		CmdWrapToScreenL();
   353 		break;
   354 	case EWordCmdViewPreferences:
   355 		RunViewPreferencesDialogL();
   356 		break;
   357 	case EWordCmdCount:
   358 		iEikonEnv->InfoMsg(R_WORD_NO_WORDS,(iRichEd->CountWords()));	
   359 		break;
   360 	case EEikCmdZoomIn:
   361 	case EEikCmdZoomOut:
   362 		ZoomL(aCommand);
   363 		break;
   364 	case EWordCmdZoomSet:
   365 		{
   366 		TInt zoomFactor=iAppZoom.ZoomFactor();
   367 		CEikDialog* dialog=new(ELeave) CWordTempManualZoomDialog(zoomFactor);
   368 		if (dialog->ExecuteLD(R_WORD_DIALOG_ZOOM_SET))
   369 			{
   370 			iAppZoom.SetZoomFactor(zoomFactor);
   371 			CFbsBitmap* lineCursor=iEikonEnv->CreateBitmapL(TPtrC(),EMbmEikonLncusr1);
   372 			iRichEd->SetLineCursorBitmapL(lineCursor);
   373 			iRichEd->NotifyNewFormatL();
   374 			iRichEd->UpdateScrollBarsL();
   375 			}
   376 		break;
   377 		}
   378 	case EWordCmdOutline:
   379 		RunOutlineDialogL();
   380 		break;
   381 	//
   382 	// State changing commands
   383 	// disallow when read-only
   384 	//
   385 	// FILE HANDLING
   386 	case EEikCmdFileImport:
   387 	case EWordCmdHtmlImport:
   388 	//
   389 	// CLIPBOARDING
   390 	case EEikCmdEditCut:
   391 	case EEikCmdEditPaste:
   392 	//
   393 	// CHARACTER FORMATTING
   394 	case EEikCmdFontBold:
   395 	case EEikCmdFontItalic:
   396 	case EEikCmdFontUnderline:
   397 	case EEikCmdFontChange:
   398 	case EEikCmdInsertSymbol:
   399 	//
   400 	// PARAGRAPH FORMATTING
   401 	case EEikCmdParaBorder:
   402 	case EEikCmdParaSpacing:
   403 	case EEikCmdParaIndent:
   404 	case EEikCmdParaTabs:
   405 	case EEikCmdParaAlign:
   406 	case EWordCmdAlignLeft:
   407 	case EWordCmdAlignRight:
   408 	case EWordCmdAlignCenter:
   409 	case EWordCmdAlignJustify:
   410 	case EWordCmdFormatBullet:
   411 	//
   412 	// EDIT
   413 	case EEikCmdSearchReplace:
   414 	case EEikCmdEditPictureFormat:
   415 	case EWordCmdInsertSketch:
   416 	case EWordCmdInsertSheet:
   417 	case EWordCmdInsertObject:
   418 	case EWordCmdInsertPageBreak:
   419 	case EWordCmdInsertLineBreak:
   420 	case EEikCmdEditUndo:
   421 	case EEikCmdEditRedo:
   422 	//
   423 	// TOOLS
   424 	case EWordCmdObjectPreferences:
   425 	//
   426 	// TOP TOOLBAND
   427 	case EWordButtonStyle:
   428 	case EWordButtonFont:
   429 	case EWordButtonFontSize:		
   430 	case EWordButtonAlign:
   431 	case EWordButtonBorders:
   432 	case EWordCmdInsertBullet:
   433 	case EWordButtonBullets:
   434 	//
   435 	// STYLES
   436 	case EWordCmdRevertToStylePara:
   437 	case EWordCmdRevertToStyleChar:
   438 	case EWordCmdStyleGallery:
   439 		{
   440 		const TBool readOnly=(iContainerAppUi)? iEmbeddedAndReadOnly : !(iDocument->AppFileMode()&EFileWrite);
   441 		if (readOnly)
   442 			{
   443 			iEikonEnv->InfoMsg(R_WORD_FILE_READ_ONLY);  // feedback this is a readonly file
   444 			if (aCommand==EEikCmdFontBold || aCommand==EEikCmdFontItalic || aCommand==EEikCmdFontUnderline)
   445 				UpdateCharFormatButtonsL();  // undo the pressing of the emphasis buttons.
   446 			break;
   447 			}
   448 		switch (aCommand)
   449 			{
   450 		//
   451 		// FILE HANDLING
   452 			case EEikCmdFileImport:
   453 				CmdFileTextImportL();
   454 				break;
   455 			case EWordCmdHtmlImport:
   456 				CmdFileHtmlImportL();
   457 				break;			
   458 		//
   459 		// CLIPBOARDING
   460 			case EEikCmdEditCut:
   461 				iRichEd->ClipboardCutL();
   462 				UpdateToolbandButtonsL();
   463 				break;
   464 			case EEikCmdEditPaste:
   465 				if (KErrNotFound == iRichEd->ClipboardPasteL())
   466 					iEikonEnv->InfoMsg(R_WORD_NO_TEXT_TO_PASTE);
   467 				else
   468 					UpdateToolbandButtonsL();
   469 				break;
   470 		//
   471 		// CHARACTER FORMATTING
   472 			case EEikCmdFontBold:
   473 				iRichEd->BoldItalicUnderlineEventL(CEikGlobalTextEditor::EBold); 
   474 				break;
   475 			case EEikCmdFontItalic:
   476 				iRichEd->BoldItalicUnderlineEventL(CEikGlobalTextEditor::EItalic); 
   477 				break;
   478 			case EEikCmdFontUnderline:
   479 				iRichEd->BoldItalicUnderlineEventL(CEikGlobalTextEditor::EUnderline); 
   480 				break;
   481 			case EEikCmdFontChange:
   482 				iRichEd->RunFontDialogL(EGulNoSymbolFonts, iCoeEnv->ScreenDevice());
   483 				UpdateCharFormatButtonsL();
   484 				break;
   485 			case EEikCmdInsertSymbol:
   486 				iRichEd->RunCharMapDialogL();
   487 				break;
   488 		//
   489 		// PARAGRAPH FORMATTING
   490 			case EEikCmdParaBorder:
   491 			case EEikCmdParaSpacing:
   492 				iRichEd->RunParaDialogsL(aCommand);
   493 				break;
   494 			case EEikCmdParaIndent:
   495 			case EEikCmdParaTabs:
   496 				{
   497 				TPageSpec pageSpec=iPrintSetup->PrinterDevice()->CurrentPageSpecInTwips();
   498 				TInt width=pageSpec.iPortraitPageSize.iWidth;
   499 				if (pageSpec.iOrientation==TPageSpec::ELandscape)
   500 					width=pageSpec.iPortraitPageSize.iHeight;
   501 				width-=(iPrintSetup->iPageMarginsInTwips.iMargins.iLeft+iPrintSetup->iPageMarginsInTwips.iMargins.iRight);
   502 				if (aCommand==EEikCmdParaIndent)
   503 					iRichEd->RunIndentsDialogL(width);
   504 				else
   505 					iRichEd->RunTabsDialogL(width);
   506 				break;
   507 				}
   508 			case EEikCmdParaAlign:
   509 				CmdChangeAlignmentL();
   510 				break;
   511 			case EWordCmdAlignLeft:
   512 			case EWordCmdAlignRight:
   513 			case EWordCmdAlignCenter:
   514 			case EWordCmdAlignJustify:
   515 				{
   516 				SetParaAlignmentL(aCommand);	
   517 				RTmParFormat::TAlignment alignment = RTmParFormat::EAlignNormal;
   518 				switch (aCommand)
   519 					{
   520 					case EWordCmdAlignLeft:
   521 						alignment = RTmParFormat::EAlignNormal;
   522 						break;
   523 					case EWordCmdAlignRight:
   524 						alignment = RTmParFormat::EAlignReverse;
   525 						break;
   526 					case EWordCmdAlignCenter:
   527 						alignment = RTmParFormat::EAlignCenter;
   528 						break;
   529 					case EWordCmdAlignJustify:
   530 						alignment = RTmParFormat::EAlignJustify;
   531 						break;
   532 					}
   533 				UpdateAlignButtonL(alignment);
   534 				break;
   535 				}
   536 			case EWordCmdFormatBullet:
   537 				RunSelectBulletDialogL();
   538 				break;
   539 		//
   540 		// EDIT
   541 			case EEikCmdSearchReplace:
   542 				iRichEd->RunReplaceDialogL();
   543 				break;
   544 			case EEikCmdEditPictureFormat:
   545 				iRichEd->EditPictureFormatL();
   546 				break;
   547 			case EWordCmdInsertSketch:
   548 				iRichEd->InsertObjectL(KSketchDllName,KUidPaintApp,(SketchAsGlass())?CEikRichTextEditor::EGlassIfPossible : CEikRichTextEditor::EAlwaysIconic);
   549 				break;
   550 			case EWordCmdInsertSheet:
   551 				iRichEd->InsertObjectL(KSheetDllName,KUidSheet,(GraphAsGlass())?CEikRichTextEditor::EGlassIfPossible : CEikRichTextEditor::EAlwaysIconic);
   552 				break;
   553 			case EWordCmdInsertObject:
   554 				iRichEd->InsertObjectL(CEikRichTextEditor::EGlassIfPossible);
   555 				break;
   556 			case EWordCmdInsertPageBreak:
   557 			case EWordCmdInsertLineBreak:
   558 				InsertCharacterL((aCommand==EWordCmdInsertPageBreak)
   559 					? CEditableText::EPageBreak
   560 					: CEditableText::ELineBreak);
   561 				break;
   562 			case EEikCmdEditUndo:
   563 				iRichEd->UndoL();
   564 				break;
   565 			case EEikCmdEditRedo:
   566 				iRichEd->RedoL();
   567 				break;
   568 		//
   569 		// TOOLS
   570 			case EWordCmdObjectPreferences:
   571 				RunObjectPreferencesDialogL();
   572 				break;
   573 		//
   574 		// TOP TOOLBAND
   575 			case EWordButtonStyle:
   576 				LaunchStylesPopupL();
   577 				break;
   578 			case EWordButtonFont:
   579 				LaunchFontsPopupL();
   580 				break;
   581 			case EWordButtonFontSize:		
   582 				LaunchFontHeightsPopupL();
   583 				break; 
   584 			case EWordButtonAlign:
   585 				LaunchAlignPopupL();
   586 				break;
   587 			case EWordButtonBorders:
   588 				LaunchBordersPopupL();
   589 				break;
   590 			case EWordCmdInsertBullet:
   591 				{
   592 				if (REINTERPRET_CAST(CEikButtonBase*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonBullets))->State() == CEikButtonBase::EClear)
   593 					UpdateToolBandButton(EWordButtonBullets,CEikButtonBase::ESet); 
   594 				else
   595 					UpdateToolBandButton(EWordButtonBullets,CEikButtonBase::EClear);
   596 				}  // drops into next case with a purpose
   597 			case EWordButtonBullets:
   598 				SetBulletL();
   599 				break;
   600 		//
   601 		// STYLES
   602 			case EWordCmdRevertToStylePara:
   603 				{
   604 				TCursorSelection selection=iRichEd->Selection();
   605 				Text()->RemoveSpecificParaFormatL(selection.LowerPos(),selection.Length());
   606 				ReformatDueToStateChangeL();
   607 				break;
   608 				}
   609 			case EWordCmdRevertToStyleChar:
   610 				{
   611 				TCursorSelection selection=iRichEd->Selection();
   612 				Text()->RemoveSpecificCharFormatL(selection.LowerPos(),selection.Length());
   613 				ReformatDueToStateChangeL();
   614 				break;
   615 				}
   616 			case EWordCmdStyleGallery:
   617 				{
   618 				TBool close=FALSE;
   619 				CRichText* originalText=Text();
   620 				const TCursorSelection selection=iRichEd->Selection();
   621 				TChar& normalStyleShortCut=iModel->NormalStyleShortCut();
   622 				TWordStyleGalleryData data(*originalText,*iModel->StyleList(),*iModel->StyleShortCutList(),
   623 					normalStyleShortCut,*iPrintSetup,close,selection,*iRichEd);
   624 
   625 				CEikDialog* dialog=CWordStyleGallery::NewL(data);
   626 				dialog->ExecuteLD(R_WORD_DIALOG_STYLE_GALLERY);
   627 				if (!close)
   628 					break;
   629 				ReformatDueToStateChangeL();
   630 				SetDocChanged();
   631 				break;
   632 				}
   633 			}
   634 
   635 		break;
   636 		}
   637 
   638 		// test commands
   639 		case EWordCmdHighlight:
   640 			iRichEd->ToggleHighlightL(TTmCharFormat::EBackground);
   641 			break;
   642 		case EWordCmdShadow:
   643 			iRichEd->ToggleHighlightL(TTmCharFormat::EShadow);
   644 			break;
   645 		case EWordCmdCustomHighlight:
   646 			iRichEd->ToggleHighlightL((TUint)TFontPresentation::EFontHighlightFirstCustomStyle << TTmCharFormat::EUserDefinedShift);
   647 			break;
   648 		case EWordCmdStandardKeyboard:
   649 			iTest->SetKeyboardL(CWordTest::EStandardKeyboard);
   650 			break;
   651 		case EWordCmdArabicKeyboard:
   652 			iTest->SetKeyboardL(CWordTest::EArabicKeyboard);
   653 			break;
   654 		case EWordCmdGreekKeyboard:
   655 			iTest->SetKeyboardL(CWordTest::EGreekKeyboard);
   656 			break;
   657 		case EWordCmdRussianKeyboard:
   658 			iTest->SetKeyboardL(CWordTest::ERussianKeyboard);
   659 			break;
   660 		case EWordCmdChineseOn:
   661 		    {
   662 			const TUid KUidTFepChinese = { 0x1028716D };
   663 			iEikonEnv->InstallFepL(KUidTFepChinese);
   664 		    }
   665 		break;
   666 		case EWordCmdChineseOff:
   667 			iEikonEnv->InstallFepL(KNullUid);			
   668 			break;	
   669 		case EWordCmdRuledPaper:
   670 			iTest->SetRuledPaperL(iRichEd,!iTest->RuledPaper());
   671 			break;
   672 		case EWordCmdBackgroundBitmap:
   673 			iTest->SetBackgroundBitmapL(iRichEd,!iTest->BackgroundBitmap());
   674 			break;
   675 		case EWordCmdUpperCase:
   676 			iTest->ToggleCaseL(iRichEd);
   677 			break;
   678 		case EWordCmdBenchmark:
   679 			iTest->BenchmarkL();
   680 			break;
   681 		case EWordCmdTruncateWithEllipsis:
   682 			iTest->SetTruncateWithEllipsisL(iRichEd,!iTest->TruncateWithEllipsis());
   683 			break;
   684 		case EWordCmdPictureAlignTop:
   685 			iTest->SetPictureAlignmentL(iRichEd,TFontPresentation::EAlignTop);
   686 			break;
   687 		case EWordCmdPictureAlignBottom:
   688 			iTest->SetPictureAlignmentL(iRichEd,TFontPresentation::EAlignBottom);
   689 			break;
   690 		case EWordCmdPictureAlignCenter:
   691 			iTest->SetPictureAlignmentL(iRichEd,TFontPresentation::EAlignCentered);
   692 			break;
   693 		case EWordCmdPictureAlignBaseline:
   694 			iTest->SetPictureAlignmentL(iRichEd,TFontPresentation::EAlignBaseLine);
   695 			break;
   696 		case EWordCmdWrapOn:
   697 			iTest->SetWrapL(iRichEd,TRUE);
   698 			break;
   699 		case EWordCmdWrapOff:
   700 			iTest->SetWrapL(iRichEd,FALSE);
   701 			break;
   702 		case EWordCmdInsertPicture:
   703 			{
   704 			iTest->InsertPictureL(iRichEd);
   705 			Document()->SetChanged(ETrue);
   706 			break;	
   707 			}		
   708 		case EWordCmdCursorStyleFlash:
   709 			iTest->ToggleCursorFlash();
   710 			break;
   711 		case EWordCmdCursorStyleVertical:
   712 			iTest->SetCursorPlacement(ECursorVertical);
   713 			break;
   714 		case EWordCmdCursorStyleUnderlineNext:
   715 			iTest->SetCursorPlacement(ECursorUnderlineNext);
   716 			break;
   717 		case EWordCmdCursorStyleUnderlinePrev:
   718 			iTest->SetCursorPlacement(ECursorUnderlinePrev);
   719 			break;
   720 		case EWordCmdCursorStyleHeavy:
   721 			iTest->SetCursorWeight(iTest->CursorWeight() == 3 ? 1 : 3);
   722 			break;
   723 		case EWordCmdCursorStyleRed:
   724 			iTest->SetCursorXorColor(iTest->CursorXorColor() == KRgbWhite ? KRgbCyan : KRgbWhite);
   725 			break;
   726 		case EWordCmdUndoTestNotUndoable:
   727 			iRichEd->TestRunNotUndoableCommandL();
   728 			break;
   729 		case EWordCmdPositioningHintNeutral:
   730 			iTest->SetCursorPositioningHintL(TCursorPosition::EPosHintUndefined);
   731 			break;
   732 		case EWordCmdPositioningHintInsertLeftToRight:
   733 			iTest->SetCursorPositioningHintL(TCursorPosition::EInsertStrongL2R);
   734 			break;
   735 		case EWordCmdPositioningHintInsertRightToLeft:
   736 			iTest->SetCursorPositioningHintL(TCursorPosition::EInsertStrongR2L);
   737 			break;
   738 		case EWordCmdSelectionHighlightNormal:
   739 			iRichEd->TextView()->SetSelectionVisibilityL(EFalse);
   740 			iTest->SetSelectionHighlightStyle(0);
   741 			iRichEd->TextView()->SetSelectionVisibilityL(ETrue);
   742 			break;
   743 		case EWordCmdSelectionHighlightCustom1:
   744 			iRichEd->TextView()->SetSelectionVisibilityL(EFalse);
   745 			iTest->SetSelectionHighlightStyle(1);
   746 			iRichEd->TextView()->SetSelectionVisibilityL(ETrue);
   747 			break;
   748 		case EWordCmdSelectionHighlightCustom2:
   749 			iRichEd->TextView()->SetSelectionVisibilityL(EFalse);
   750 			iTest->SetSelectionHighlightStyle(2);
   751 			iRichEd->TextView()->SetSelectionVisibilityL(ETrue);
   752 			break;
   753 		}
   754 	}
   755 
   756 void CWordAppUi::DynInitMenuPaneL(TInt aMenuId,CEikMenuPane* aMenuPane)
   757 	{
   758 	TBool readOnly=iRichEd->IsReadOnly();
   759 	switch (aMenuId)
   760 		{
   761 	//
   762 	//
   763 	case R_WORD_FILE_MENU:
   764 		{
   765 		if (iContainerAppUi)
   766 			{
   767 			aMenuPane->DeleteMenuItem(EEikCmdFileNew);
   768 			aMenuPane->DeleteMenuItem(EEikCmdFileOpen);
   769 			}
   770 		break;
   771 		}
   772 	//
   773 	//
   774 	case R_WORD_FILEOPTIONS_MENU:
   775 		{
   776 		if (iContainerAppUi)
   777 			{
   778 			aMenuPane->DeleteMenuItem(EEikCmdFileSave);
   779 			aMenuPane->DeleteMenuItem(EEikCmdFileSaveAs);
   780 			aMenuPane->DeleteMenuItem(EEikCmdFileRevert);
   781 			aMenuPane->DeleteMenuItem(EWordCmdFileSaveAsTemplate);
   782 			aMenuPane->DeleteMenuItem(EWordCmdFileDeleteTemplate);
   783 			}
   784 		else if (readOnly)
   785 			{
   786 			aMenuPane->SetItemDimmed(EEikCmdFileSave,TRUE);
   787 			aMenuPane->SetItemDimmed(EEikCmdFileRevert,TRUE);
   788 			}
   789 		if (readOnly)
   790 			{
   791 			aMenuPane->SetItemDimmed(EEikCmdFileImport,TRUE);
   792 			aMenuPane->SetItemDimmed(EWordCmdHtmlImport,ETrue);
   793 			}
   794 		break;
   795 		}
   796 	//
   797 	//
   798 	case R_WORD_EDIT_MENU:
   799 		{// read-only dependancies
   800 		if (readOnly || (!iRichEd->CanUndo()) )
   801 			aMenuPane->SetItemDimmed(EEikCmdEditUndo,TRUE);
   802 		if (readOnly || (!iRichEd->CanRedo()) )
   803 			aMenuPane->SetItemDimmed(EEikCmdEditRedo,TRUE);
   804 		TInt selection=iRichEd->Selection().Length();
   805 		if (selection==0)
   806 			aMenuPane->SetItemDimmed(EEikCmdEditCopy,TRUE);
   807 		if (readOnly || selection==0)
   808 			aMenuPane->SetItemDimmed(EEikCmdEditCut,TRUE);
   809 		if (readOnly)
   810 			aMenuPane->SetItemDimmed(EEikCmdEditPaste,TRUE);
   811 		break;
   812 		}
   813 	//
   814 	//
   815 	case R_WORD_EDITFIND_MENU:
   816 		{
   817 		TInt documentLength=iRichEd->TextLength();
   818 		if (documentLength==0)
   819 			{
   820 			aMenuPane->SetItemDimmed(EEikCmdSearchFind,TRUE);
   821 			aMenuPane->SetItemDimmed(EEikCmdSearchFindAgain,TRUE);
   822 			aMenuPane->SetItemDimmed(EWordCmdGoTo,TRUE);
   823 			}
   824 		if (documentLength==0 || readOnly)
   825 			aMenuPane->SetItemDimmed(EEikCmdSearchReplace,TRUE);
   826 		break;
   827 		}
   828 	//
   829 	//
   830 	case R_WORD_EDITOPTIONS_MENU:
   831 		if (readOnly)
   832 			aMenuPane->SetItemDimmed(EEikCmdEditPictureFormat,TRUE);
   833 		break;
   834 	//
   835 	//
   836 	case R_WORD_VIEW_MENU:
   837 		{// No read-only dependant menu options here
   838 		if (!WysiwygModeIsSet())
   839 			aMenuPane->SetItemButtonState(EWordCmdWrapToScreen, EEikMenuItemSymbolOn);
   840 		if (iEikonEnv->AppUiFactory()->ToolBand()->IsVisible())
   841 			aMenuPane->SetItemButtonState(EWordCmdToolband, EEikMenuItemSymbolOn);
   842 		if (iEikonEnv->AppUiFactory()->ToolBar()->IsVisible())
   843 			aMenuPane->SetItemButtonState(EWordCmdToolbar, EEikMenuItemSymbolOn);
   844 		break;
   845 		}
   846 	//
   847 	//
   848 	case R_WORD_INSERT_MENU:
   849 		if (readOnly)
   850 			{
   851 			aMenuPane->SetItemDimmed(EWordCmdInsertSketch,TRUE);
   852 			aMenuPane->SetItemDimmed(EWordCmdInsertSheet,TRUE);
   853 			aMenuPane->SetItemDimmed(EWordCmdInsertObject,TRUE);
   854 			aMenuPane->SetItemDimmed(EWordCmdInsertPageBreak,TRUE);
   855 			aMenuPane->SetItemDimmed(EWordCmdInsertLineBreak,TRUE);
   856 			aMenuPane->SetItemDimmed(EEikCmdInsertSymbol,TRUE);
   857 			}
   858 		break;
   859 	//
   860 	//
   861 	case R_WORD_TEXT_MENU:
   862 		{
   863 		TCharFormat charFormat;
   864 		TCharFormatMask charUndeterminedMask;
   865 		((CRichText*)iRichEd->Text())->GetCharFormat(charFormat,charUndeterminedMask,iRichEd->CursorPos(),0);
   866 
   867 		if (charFormat.iFontSpec.iFontStyle.StrokeWeight()==EStrokeWeightBold)
   868 			aMenuPane->SetItemButtonState(EEikCmdFontBold,EEikMenuItemSymbolOn);
   869 		if (charFormat.iFontSpec.iFontStyle.Posture()==EPostureItalic)
   870 			aMenuPane->SetItemButtonState(EEikCmdFontItalic,EEikMenuItemSymbolOn);
   871 		if (charFormat.iFontPresentation.iUnderline==EUnderlineOn)
   872 			aMenuPane->SetItemButtonState(EEikCmdFontUnderline,EEikMenuItemSymbolOn);
   873 		if (readOnly)
   874 			{
   875 			aMenuPane->SetItemDimmed(EEikCmdFontBold,TRUE);
   876 			aMenuPane->SetItemDimmed(EEikCmdFontItalic,TRUE);
   877 			aMenuPane->SetItemDimmed(EEikCmdFontUnderline,TRUE);
   878 			aMenuPane->SetItemDimmed(EEikCmdFontChange,TRUE);
   879 			aMenuPane->SetItemDimmed(EWordCmdRevertToStyleChar,TRUE);
   880 			}
   881 		break;
   882 		}
   883 	//
   884 	//
   885 	case R_WORD_PARAGRAPH_MENU:
   886 		{
   887 		if (readOnly)
   888 			{
   889 			aMenuPane->SetItemDimmed(EWordCmdRevertToStylePara,TRUE);
   890 			aMenuPane->SetItemDimmed(EEikCmdParaIndent,TRUE);
   891 			aMenuPane->SetItemDimmed(EEikCmdParaTabs,TRUE);
   892 			aMenuPane->SetItemDimmed(EEikCmdParaSpacing,TRUE);
   893 			aMenuPane->SetItemDimmed(EEikCmdParaBorder,TRUE);
   894 			aMenuPane->SetItemDimmed(EWordCmdStyleGallery,TRUE);
   895 			}
   896 		break;
   897 		}
   898 	//
   899 	//
   900 	case R_WORD_PARA_ALIGNMENT_MENU:
   901 		{
   902 		CParaFormat* paraFormat=CParaFormat::NewLC();
   903 		TParaFormatMask paraUndeterminedMask;
   904 		const TCursorSelection selection=iRichEd->Selection();
   905 		Text()->GetParaFormatL(paraFormat,paraUndeterminedMask,selection.LowerPos(),selection.Length());
   906 		if (!paraUndeterminedMask.AttribIsSet(EAttAlignment))
   907 			{
   908 			switch (paraFormat->iHorizontalAlignment)
   909 				{
   910 			case CParaFormat::ELeftAlign:
   911 				aMenuPane->SetItemButtonState(EWordCmdAlignLeft,EEikMenuItemSymbolOn);
   912 				aMenuPane->SetSelectedItem(0);
   913 				break;
   914 			case CParaFormat::ERightAlign:
   915 				aMenuPane->SetItemButtonState(EWordCmdAlignRight,EEikMenuItemSymbolOn);
   916 				aMenuPane->SetSelectedItem(1);
   917 				break;
   918 			case CParaFormat::ECenterAlign:	
   919 				aMenuPane->SetItemButtonState(EWordCmdAlignCenter,EEikMenuItemSymbolOn);
   920 				aMenuPane->SetSelectedItem(2);
   921 				break;
   922 			case CParaFormat::EJustifiedAlign:
   923 				aMenuPane->SetItemButtonState(EWordCmdAlignJustify,EEikMenuItemSymbolOn);
   924 				aMenuPane->SetSelectedItem(3);
   925 				break;
   926 			default:
   927 				break;
   928 				}
   929 			}
   930 		CleanupStack::PopAndDestroy();
   931 		if (readOnly)
   932 			{
   933 			aMenuPane->SetItemDimmed(EWordCmdAlignLeft,TRUE);
   934 			aMenuPane->SetItemDimmed(EWordCmdAlignRight,TRUE);
   935 			aMenuPane->SetItemDimmed(EWordCmdAlignCenter,TRUE);
   936 			aMenuPane->SetItemDimmed(EWordCmdAlignJustify,TRUE);
   937 			}
   938 		break;
   939 		}
   940 	//
   941 	//
   942 	case R_WORD_PARA_BULLETS_MENU:
   943 		if (readOnly)
   944 			{
   945 			aMenuPane->SetItemDimmed(EWordCmdInsertBullet,TRUE);
   946 			aMenuPane->SetItemDimmed(EWordCmdFormatBullet,TRUE);
   947 			}
   948 		break;
   949 	//
   950 	//
   951 	case R_WORD_TOOLS_MENU:
   952 		if (readOnly)
   953 			{
   954 			aMenuPane->SetItemDimmed(EWordCmdObjectPreferences,TRUE);
   955 			}
   956 		break;
   957 	//
   958 	//
   959 	case R_EIK_SIDEBAR_IRDA_MENU:
   960 	case R_WORD_TOOLS_INFRARED:
   961 		aMenuPane->SetItemDimmed(EEikCmdIrdaReceive, TRUE);
   962 		aMenuPane->SetItemDimmed(EEikCmdIrdaSend, TRUE);
   963 		break;
   964 	//
   965 	//
   966 	case R_EIK_SIDEBAR_EDIT_MENU:
   967 		{
   968 		TInt selection=iRichEd->Selection().Length();
   969 		if (selection==0)
   970 			aMenuPane->SetItemDimmed(EEikCmdEditCopy,TRUE);
   971 		if (readOnly || selection==0)
   972 			aMenuPane->SetItemDimmed(EEikCmdEditCut,TRUE);
   973 		if (readOnly)
   974 			aMenuPane->SetItemDimmed(EEikCmdEditPaste,TRUE);
   975 		}
   976 		break;
   977 
   978 	case R_WORD_TEST_MENU:
   979 		{
   980 		TPtrC text;
   981 		TCharFormat format;
   982 		iRichEd->RichText()->GetChars(text,format,iRichEd->Selection().LowerPos());
   983 		TFontPresentation::TFontHighlightStyle highlight = format.iFontPresentation.iHighlightStyle;
   984 		if (highlight == TFontPresentation::EFontHighlightNormal)
   985 			aMenuPane->SetItemButtonState(EWordCmdHighlight,EEikMenuItemSymbolOn);
   986 		else if (highlight == TFontPresentation::EFontHighlightShadow)
   987 			aMenuPane->SetItemButtonState(EWordCmdShadow,EEikMenuItemSymbolOn);
   988 		else if (highlight == TFontPresentation::EFontHighlightFirstCustomStyle)
   989 			aMenuPane->SetItemButtonState(EWordCmdCustomHighlight,EEikMenuItemSymbolOn);
   990 		if (iTest->RuledPaper())
   991 			aMenuPane->SetItemButtonState(EWordCmdRuledPaper,EEikMenuItemSymbolOn);
   992 		if (iTest->BackgroundBitmap())
   993 			aMenuPane->SetItemButtonState(EWordCmdBackgroundBitmap,EEikMenuItemSymbolOn);
   994 		if (text.Length() && TChar(text[0]).IsUpper())
   995 			aMenuPane->SetItemButtonState(EWordCmdUpperCase,EEikMenuItemSymbolOn);
   996 		if (iTest->TruncateWithEllipsis())
   997 			aMenuPane->SetItemButtonState(EWordCmdTruncateWithEllipsis,EEikMenuItemSymbolOn);
   998 		}
   999 		break;
  1000 
  1001 	case R_WORD_PICTURE_ALIGNMENT_MENU:
  1002 		{
  1003 		TCharFormat format;
  1004 		TCursorSelection sel = iRichEd->Selection();
  1005 		TCharFormatMask varies;
  1006 		Text()->GetCharFormat(format,varies,sel.LowerPos(),sel.Length());
  1007 		if (!varies.AttribIsSet(EAttFontPictureAlignment))
  1008 			{
  1009 			switch (format.iFontPresentation.iPictureAlignment)
  1010 				{
  1011 				case TFontPresentation::EAlignTop:
  1012 					aMenuPane->SetItemButtonState(EWordCmdPictureAlignTop,EEikMenuItemSymbolOn);
  1013 					aMenuPane->SetSelectedItem(0);
  1014 					break;
  1015 				case TFontPresentation::EAlignBottom:
  1016 					aMenuPane->SetItemButtonState(EWordCmdPictureAlignBottom,EEikMenuItemSymbolOn);
  1017 					aMenuPane->SetSelectedItem(1);
  1018 					break;
  1019 				case TFontPresentation::EAlignCentered:	
  1020 					aMenuPane->SetItemButtonState(EWordCmdPictureAlignCenter,EEikMenuItemSymbolOn);
  1021 					aMenuPane->SetSelectedItem(2);
  1022 					break;
  1023 				case TFontPresentation::EAlignBaseLine:
  1024 					aMenuPane->SetItemButtonState(EWordCmdPictureAlignBaseline,EEikMenuItemSymbolOn);
  1025 					aMenuPane->SetSelectedItem(3);
  1026 					break;
  1027 				default:
  1028 					break;
  1029 				}
  1030 			}
  1031 		if (readOnly)
  1032 			{
  1033 			aMenuPane->SetItemDimmed(EWordCmdPictureAlignTop,TRUE);
  1034 			aMenuPane->SetItemDimmed(EWordCmdPictureAlignBottom,TRUE);
  1035 			aMenuPane->SetItemDimmed(EWordCmdPictureAlignCenter,TRUE);
  1036 			aMenuPane->SetItemDimmed(EWordCmdPictureAlignBaseline,TRUE);
  1037 			}
  1038 		break;
  1039 		}
  1040 
  1041 	case R_WORD_KEYBOARD_MENU:
  1042 		switch (iTest->Keyboard())
  1043 			{
  1044 			case CWordTest::EStandardKeyboard:
  1045 				aMenuPane->SetItemButtonState(EWordCmdStandardKeyboard,EEikMenuItemSymbolOn);
  1046 				aMenuPane->SetSelectedItem(0);
  1047 				break;
  1048 			case CWordTest::EGreekKeyboard:
  1049 				aMenuPane->SetItemButtonState(EWordCmdGreekKeyboard,EEikMenuItemSymbolOn);
  1050 				aMenuPane->SetSelectedItem(1);
  1051 				break;
  1052 			case CWordTest::ERussianKeyboard:
  1053 				aMenuPane->SetItemButtonState(EWordCmdRussianKeyboard,EEikMenuItemSymbolOn);
  1054 				aMenuPane->SetSelectedItem(2);
  1055 				break;
  1056 			case CWordTest::EArabicKeyboard:
  1057 				aMenuPane->SetItemButtonState(EWordCmdArabicKeyboard,EEikMenuItemSymbolOn);
  1058 				aMenuPane->SetSelectedItem(3);
  1059 				break;
  1060 			}
  1061 		break;
  1062 
  1063 	case R_WORD_CURSOR_STYLE_MENU:
  1064 		if (iTest->CursorFlashing())
  1065 			aMenuPane->SetItemButtonState(EWordCmdCursorStyleFlash,EEikMenuItemSymbolOn);
  1066 		if (iTest->CursorWeight() >= 3)
  1067 			aMenuPane->SetItemButtonState(EWordCmdCursorStyleHeavy,EEikMenuItemSymbolOn);
  1068 		if (iTest->CursorXorColor() == KRgbCyan)
  1069 			aMenuPane->SetItemButtonState(EWordCmdCursorStyleRed,EEikMenuItemSymbolOn);
  1070 		switch (iTest->CursorPlacement())
  1071 			{
  1072 			case ECursorVertical:
  1073 				aMenuPane->SetItemButtonState(EWordCmdCursorStyleVertical,EEikMenuItemSymbolOn);
  1074 				aMenuPane->SetSelectedItem(1);
  1075 				break;
  1076 			case ECursorUnderlineNext:
  1077 				aMenuPane->SetItemButtonState(EWordCmdCursorStyleUnderlineNext,EEikMenuItemSymbolOn);
  1078 				aMenuPane->SetSelectedItem(2);
  1079 				break;
  1080 			case ECursorUnderlinePrev:
  1081 				aMenuPane->SetItemButtonState(EWordCmdCursorStyleUnderlinePrev,EEikMenuItemSymbolOn);
  1082 				aMenuPane->SetSelectedItem(3);
  1083 				break;
  1084 			}
  1085 		break;
  1086 	case R_WORD_SELECTION_HIGHLIGHT_MENU:
  1087 		aMenuPane->SetItemButtonState(
  1088 			aMenuPane->MenuItemCommandId(iTest->SelectionHighlightStyle()),
  1089 			EEikMenuItemSymbolOn);
  1090 		break;
  1091 
  1092 	case R_WORD_POSITIONING_HINT_TEST_MENU:
  1093 		switch(iTest->CursorPositioningHint())
  1094 			{
  1095 		case TCursorPosition::EPosHintUndefined:
  1096 			aMenuPane->SetItemButtonState(
  1097 				EWordCmdPositioningHintNeutral,
  1098 				EEikMenuItemSymbolOn);
  1099 			aMenuPane->SetSelectedItem(1);
  1100 			break;
  1101 		case TCursorPosition::EInsertStrongL2R:
  1102 			aMenuPane->SetItemButtonState(
  1103 				EWordCmdPositioningHintInsertLeftToRight,
  1104 				EEikMenuItemSymbolOn);
  1105 			aMenuPane->SetSelectedItem(2);
  1106 			break;
  1107 		case TCursorPosition::EInsertStrongR2L:
  1108 			aMenuPane->SetItemButtonState(
  1109 				EWordCmdPositioningHintInsertRightToLeft,
  1110 				EEikMenuItemSymbolOn);
  1111 			aMenuPane->SetSelectedItem(3);
  1112 			break;
  1113 			}
  1114 		break;
  1115 	default:
  1116 		break;
  1117 		}
  1118 	}
  1119 	
  1120 void CWordAppUi::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
  1121 	{
  1122 	if (iWordFlags&EFNameBoxPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
  1123 		{
  1124 		if (aEventType==EEventRequestExit)
  1125 			{
  1126 			TCharFormatMask charFormatMask;
  1127 			TCharFormat charFormat;
  1128 			const TCursorSelection selection=iRichEd->Selection();
  1129 			Text()->GetCharFormat(charFormat,charFormatMask,selection.LowerPos(),selection.Length());
  1130 			TInt index=iPopoutListBox->CurrentItemIndex();
  1131 			charFormat.iFontSpec.iTypeface.iName=iPopoutListBox->Model()->ItemText(index);
  1132 
  1133 			charFormat.iFontSpec.iTypeface.SetAttributes(FontUtils::TypefaceAttributes(*iCoeEnv->ScreenDevice(),charFormat.iFontSpec.iTypeface.iName));
  1134 
  1135 			iTwipsList=new(ELeave) CArrayFixFlat<TInt>(4);
  1136 			FontUtils::GetAvailableHeightsInTwipsL(*iCoeEnv->ScreenDevice(),charFormat.iFontSpec.iTypeface.iName,*iTwipsList);
  1137 			index=FontUtils::IndexOfNearestHeight(*iTwipsList,charFormat.iFontSpec.iHeight);
  1138 			charFormat.iFontSpec.iHeight=(*iTwipsList)[index];
  1139 			charFormatMask.ClearAll();
  1140 			charFormatMask.SetAttrib(EAttFontTypeface);	 
  1141 			iRichEd->ApplyCharFormatL(charFormat,charFormatMask);
  1142 			//
  1143 			// Sense format of lower pos of selection to display appropriate info on toolband button labels
  1144 			Text()->GetCharFormat(charFormat,charFormatMask,selection.LowerPos(),selection.Length());
  1145 			UpdateToolBandFontNameButtonL(charFormat.iFontSpec.iTypeface.iName);
  1146 			UpdateToolBandFontHeightButtonL(charFormat.iFontSpec.iHeight);
  1147 			SetPaginationOutOfDate(TRUE);
  1148 			}
  1149 		iWordFlags&=~EFNameBoxPopped;
  1150 		DestroyPopoutLBox();
  1151 		return;
  1152 		}
  1153 	else if (iWordFlags&EStyleBoxPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
  1154 		{
  1155 		if (aEventType==EEventRequestExit)
  1156 			{
  1157 			const TCursorSelection selection=iRichEd->Selection();
  1158 			TInt index=iPopoutListBox->CurrentItemIndex();
  1159 			TParagraphStyleName name;
  1160 			iCoeEnv->ReadResource(name, R_WORD_NORMAL);
  1161 			CDesCArray* array=(CDesCArray*)(iPopoutListBox->Model()->ItemTextArray());
  1162 			if (name==(*array)[index])
  1163 				Text()->ApplyParagraphStyleL(*(CParagraphStyle*)Text()->GlobalParaFormatLayer(),selection.LowerPos(),selection.Length(),KApplyParaStyleMode);
  1164 			else
  1165 				{
  1166 				const CParagraphStyle& paraStyle=*(Text()->StyleList()->PtrByName((*array)[index])->iStyle);
  1167 		   		Text()->ApplyParagraphStyleL(paraStyle,selection.LowerPos(),selection.Length(),KApplyParaStyleMode);
  1168 				}
  1169 			ReformatDueToStateChangeL();
  1170 			}
  1171 		iWordFlags&=~EStyleBoxPopped;
  1172 		DestroyPopoutLBox();
  1173 		return;
  1174 		}
  1175 	else if (iWordFlags&EAlignBoxPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
  1176 		{
  1177 		if (aEventType==EEventRequestExit)
  1178 			{
  1179 			const TInt index = iBitmapPopout->CurrentItemIndex();
  1180 			SetParaAlignmentL(index);
  1181 			ReformatDueToStateChangeL();
  1182 			}
  1183 		iWordFlags&=~EAlignBoxPopped;
  1184 		DestroyPopoutLBox();
  1185 		return;
  1186 		}
  1187 	else if (iWordFlags&EFHeightBoxPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
  1188 		{
  1189 		if (aEventType==EEventRequestExit)
  1190 			{
  1191 			TCharFormatMask charFormatMask;
  1192 			TCharFormat charFormat;
  1193 			TInt index=iPopoutListBox->CurrentItemIndex();
  1194 			charFormatMask.SetAttrib(EAttFontHeight);	 
  1195 			charFormat.iFontSpec.iHeight=(*iTwipsList)[index];
  1196 			iRichEd->ApplyCharFormatL(charFormat,charFormatMask);
  1197 			UpdateToolBandFontHeightButtonL(charFormat.iFontSpec.iHeight);
  1198 			}
  1199 		iWordFlags&=~EFHeightBoxPopped;
  1200 		DestroyPopoutLBox();
  1201 		return;
  1202 		}
  1203 	else if (iWordFlags&EBordersPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
  1204 		{
  1205 		if (aEventType==EEventRequestExit)
  1206 			{
  1207 			TParaBorder top;
  1208 			TParaBorder bottom;
  1209 			TParaBorder left;
  1210 			TParaBorder right;
  1211 			const TInt index=iMcBitmapPopout->CurrentItemIndex();
  1212 			switch (index)
  1213 				{
  1214 			case (ESingleFull-ESingleFull):
  1215 				top.iThickness=KThinBorderThicknessInTwips;
  1216 				bottom.iThickness=KThinBorderThicknessInTwips;
  1217 				left.iThickness=KThinBorderThicknessInTwips;
  1218 				right.iThickness=KThinBorderThicknessInTwips;
  1219 				break;
  1220 			case (ESingleTop-ESingleFull):
  1221 				top.iThickness=KThinBorderThicknessInTwips;
  1222 				break;
  1223 			case (ESingleBottom-ESingleFull):
  1224 				bottom.iThickness=KThinBorderThicknessInTwips;
  1225 				break;
  1226 			case (ESingleTopAndBottom-ESingleFull):
  1227 				top.iThickness=KThinBorderThicknessInTwips;
  1228 				bottom.iThickness=KThinBorderThicknessInTwips;
  1229 				break;
  1230 			case (EDoubleFull-ESingleFull):
  1231 				top.iThickness=KThickBorderThicknessInTwips;
  1232 				bottom.iThickness=KThickBorderThicknessInTwips;
  1233 				left.iThickness=KThickBorderThicknessInTwips;
  1234 				right.iThickness=KThickBorderThicknessInTwips;
  1235 				break;
  1236 			case (EDoubleTop-ESingleFull):
  1237 				top.iThickness=KThickBorderThicknessInTwips;
  1238 				break;
  1239 			case (EDoubleBottom-ESingleFull):
  1240 				bottom.iThickness=KThickBorderThicknessInTwips;
  1241 				break;
  1242 				}
  1243 			switch (index)
  1244 				{
  1245 			case (ESingleFull-ESingleFull):
  1246 			case (EDoubleFull-ESingleFull):
  1247 				top.iLineStyle=TParaBorder::ESolid;
  1248 				bottom.iLineStyle=TParaBorder::ESolid;
  1249 				left.iLineStyle=TParaBorder::ESolid;
  1250 				right.iLineStyle=TParaBorder::ESolid;
  1251 				break;
  1252 			case (ESingleTop-ESingleFull):
  1253 			case (EDoubleTop-ESingleFull):
  1254 				top.iLineStyle=TParaBorder::ESolid;
  1255 				break;
  1256 			case (ESingleBottom-ESingleFull):
  1257 			case (EDoubleBottom-ESingleFull):
  1258 				bottom.iLineStyle=TParaBorder::ESolid;
  1259 				break;
  1260 			case (ESingleTopAndBottom-ESingleFull):
  1261 				top.iLineStyle=TParaBorder::ESolid;
  1262 				bottom.iLineStyle=TParaBorder::ESolid;
  1263 				break;
  1264 				}
  1265 			TParaFormatMask mask;
  1266 			mask.SetAttrib(EAttTopBorder);
  1267 			mask.SetAttrib(EAttBottomBorder);
  1268 			mask.SetAttrib(EAttLeftBorder);
  1269 			mask.SetAttrib(EAttRightBorder);
  1270 			CParaFormat* paraFormat=CParaFormat::NewLC();
  1271 			paraFormat->SetParaBorderL(CParaFormat::EParaBorderTop,top);
  1272 			paraFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,bottom);
  1273 			paraFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,left);
  1274 			paraFormat->SetParaBorderL(CParaFormat::EParaBorderRight,right);
  1275 			iRichEd->ApplyParaFormatL(paraFormat,mask);
  1276 			CleanupStack::PopAndDestroy(); // paraFormat
  1277 			}
  1278 		iWordFlags&=~EBordersPopped;
  1279 		DestroyPopoutLBox();
  1280 		return;
  1281 		}
  1282     if (aEventType==EEventStateChanged)
  1283 		{
  1284 		SetPaginationOutOfDate(TRUE);
  1285 		if (aControl==iRichEd)
  1286 			iToolBarUpdate->Start(CWordToolBarUpdate::ECharFormatUpdate);
  1287 		}
  1288 	if (iPaginateDialogCalled && aEventType==EEventRequestExit)
  1289 		{ // !! possibly better - the dialog should define its own observer class
  1290 		delete aControl;
  1291 		SetPaginationOutOfDate(FALSE);
  1292 		iPaginateDialogCalled=FALSE;
  1293 		return;
  1294 		}  
  1295 	}
  1296 
  1297 
  1298 void CWordAppUi::HandleEdwinEventL(CEikEdwin* aEdwin,TEdwinEvent aEventType)
  1299 	{
  1300 	if (aEdwin==iRichEd && (aEventType==MEikEdwinObserver::EEventFormatChanged || 
  1301 							aEventType==MEikEdwinObserver::EEventNavigation))
  1302 		{
  1303 		if (aEventType==MEikEdwinObserver::EEventFormatChanged)
  1304 			{
  1305 			SetPaginationOutOfDate(TRUE);
  1306 			SetDocChanged();
  1307 			}
  1308 		if (iEikonEnv->AppUiFactory()->ToolBar()->IsVisible() || iEikonEnv->AppUiFactory()->ToolBand()->IsVisible())
  1309 			iToolBarUpdate->Start(CWordToolBarUpdate::EFullUpdate);
  1310 		}
  1311 	}
  1312 
  1313 void CWordAppUi::RunPageSetupDialogL()
  1314 	{
  1315 	if (CEikPageSetupDialog::RunDlgLD(iPrintSetup))
  1316 		{
  1317 		CTextPageRegionPrinter& printer=PageRegionPrinter();
  1318 		printer.SetPageMarginsInTwips(iPrintSetup->iPageMarginsInTwips.iMargins);
  1319 		printer.SetPageSpecInTwips(iPrintSetup->PrinterDevice()->CurrentPageSpecInTwips());
  1320 		SetPaginationOutOfDate(TRUE);
  1321 		SetDocChanged();
  1322 		UpdatePageLayoutL();
  1323 		iRichEd->DrawNow();  // need to display any page breaks immediatley.
  1324 		}
  1325 	}