First public contribution.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
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>
39 #include <techview/eiktxlbm.h>
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");
59 CWordAppUi::CWordAppUi()
60 :iAlignment(RTmParFormat::EAlignNormal)
64 CWordAppUi::~CWordAppUi()
68 MApaEmbeddedDocObserver::TExitMode exitMode=MApaEmbeddedDocObserver::EKeepChanges;
70 exitMode=MApaEmbeddedDocObserver::ENoChanges;
71 if (Document()->Model()->Text()->DocumentLength()==0)
72 exitMode=MApaEmbeddedDocObserver::EEmpty;
73 iDoorObserver->NotifyExit(exitMode);
76 RemoveFromStack(iRichEd);
78 delete iToolBarUpdate;
81 delete iPopoutListBox;
82 delete iConfirmationText;
86 void CWordAppUi::ConstructL()
88 Document()->SetChanged(FALSE);
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
97 iToolBarUpdate=CWordToolBarUpdate::NewL(*this);
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();
109 TKeyResponse CWordAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
111 if (iRichEd->IsReadOnly())
113 iRichEd->CEikRichTextEditor::OfferKeyEventL(aKeyEvent, aType);
114 return EKeyWasConsumed;
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;
127 if (eventKey && isEnter && (aKeyEvent.iModifiers & EModifierCtrl))
128 {// Insert a breaking character
129 InsertCharacterL(CEditableText::EPageBreak);
130 return EKeyWasConsumed;
133 if ((aKeyEvent.iCode==EKeySpace || isEnter) && iRichEd->CheckForObjectL())
135 return EKeyWasConsumed;
138 // Allow the test harness to apply a custom keyboard map.
140 TKeyResponse r = iTest->OfferKeyEventL(aKeyEvent,aType,c);
141 if (r == EKeyWasConsumed)
145 return EKeyWasConsumed;
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).
152 if (eventKey && (aKeyEvent.iCode < 0xF700 || aKeyEvent.iCode >= 0xF900))
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);
162 InsertCharacterL((aKeyEvent.iModifiers & EModifierShift)?
163 CEditableText::ELineBreak : CEditableText::EParagraphDelimiter);
166 InsertCharacterL(aKeyEvent.iCode);
167 return EKeyWasConsumed;
169 iRichEd->CEikRichTextEditor::OfferKeyEventL(aKeyEvent, aType);
170 if (eventKey && (iEikonEnv->AppUiFactory()->ToolBar()->IsVisible() || iEikonEnv->AppUiFactory()->ToolBand()->IsVisible()))
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);
177 return EKeyWasConsumed;
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.
185 const CParagraphStyle* styleToApply=NULL;
186 if (aKey==iModel->NormalStyleShortCut())
187 styleToApply=REINTERPRET_CAST(const CParagraphStyle*,Text()->GlobalParaFormatLayer());
190 const CStyleShortCutList* shortCutList=iModel->StyleShortCutList();
191 const TInt count=(shortCutList) ? shortCutList->Count() : 0;
194 while (index<count && !matched)
196 TChar match=(*shortCutList)[index];
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;
208 TCursorSelection selection=iRichEd->Selection();
209 Text()->ApplyParagraphStyleL(*styleToApply,selection.LowerPos(),selection.Length(),KApplyParaStyleMode);
210 ReformatDueToStateChangeL();
211 iRichEd->UpdateScrollBarsL();
212 return EKeyWasConsumed;
216 void CWordAppUi::SetAndDrawFocus(TBool aFocus)
219 iRichEd->SetFocus(aFocus,EDrawNow);
223 TCoeInputCapabilities CWordAppUi::InputCapabilities() const
225 TCoeInputCapabilities inputCapabilities=CEikAppUi::InputCapabilities();
226 if ((iRichEd!=NULL) && iRichEd->IsFocused() && !iRichEd->IsReadOnly())
228 inputCapabilities.MergeWith(iRichEd->InputCapabilities());
230 return inputCapabilities;
233 TBool CWordAppUi::DocHasChanged() const
235 if (iDocument->HasChanged())
237 if (iRichEd->IsAtBookmark())
242 void CWordAppUi::HandleCommandL(TInt aCommand)
247 GetUiData(Document()->UiData());
248 if (DocHasChanged() && !iContainerAppUi)
253 case EEikCmdFileOpen:
254 case EEikCmdFileSave:
255 case EEikCmdFileSaveAs:
256 case EEikCmdFileRevert:
257 case EWordCmdFileSaveAsTemplate:
258 case EWordCmdFileDeleteTemplate:
265 case (EEikCmdFileNew):
268 case (EEikCmdFileOpen):
271 case (EEikCmdFileSave):
274 case (EEikCmdFileSaveAs):
277 case (EEikCmdFileRevert):
280 case (EWordCmdFileSaveAsTemplate):
281 CmdFileSaveAsTemplateL();
283 case (EWordCmdFileDeleteTemplate):
284 CmdFileDeleteTemplateL();
289 case EEikCmdEditCopy:
290 iRichEd->ClipboardCopyL();
292 case EEikCmdFileExport:
293 CmdFileTextExportL();
295 case EWordCmdPageSetup:
296 RunPageSetupDialogL();
298 case EEikCmdPrintPaginate:
299 RunPaginationDialogL();
301 case EEikCmdPrintPrint:
302 case EEikCmdPrintSetup:
303 case EEikCmdPrintPreview:
307 if (PaginationOutOfDate())
308 cancel=RunPaginationDialogL();
313 case EEikCmdPrintSetup:
315 TInt pages=iModel->PageTable()->Count();
316 RunPrintRangeDialogL(iPrintSetup,pages);
319 case EEikCmdPrintPrint:
322 case EEikCmdPrintPreview:
331 case EEikCmdSearchFind:
332 iRichEd->RunFindDialogL();
334 case EEikCmdSearchFindAgain:
335 iRichEd->RunFindAgainDialogL();
337 case EEikCmdEditSelectAll:
339 const TInt docLength=iRichEd->TextLength();
341 iRichEd->SetSelectionL(docLength,0);
344 case EWordCmdReEditObject:
345 iRichEd->ReEditObjectL();
347 case EWordCmdToolbar:
348 case EWordCmdToolband:
349 UpdateToolBarAndBandL(aCommand);
351 case EWordCmdWrapToScreen:
354 case EWordCmdViewPreferences:
355 RunViewPreferencesDialogL();
358 iEikonEnv->InfoMsg(R_WORD_NO_WORDS,(iRichEd->CountWords()));
364 case EWordCmdZoomSet:
366 TInt zoomFactor=iAppZoom.ZoomFactor();
367 CEikDialog* dialog=new(ELeave) CWordTempManualZoomDialog(zoomFactor);
368 if (dialog->ExecuteLD(R_WORD_DIALOG_ZOOM_SET))
370 iAppZoom.SetZoomFactor(zoomFactor);
371 CFbsBitmap* lineCursor=iEikonEnv->CreateBitmapL(TPtrC(),EMbmEikonLncusr1);
372 iRichEd->SetLineCursorBitmapL(lineCursor);
373 iRichEd->NotifyNewFormatL();
374 iRichEd->UpdateScrollBarsL();
378 case EWordCmdOutline:
382 // State changing commands
383 // disallow when read-only
386 case EEikCmdFileImport:
387 case EWordCmdHtmlImport:
391 case EEikCmdEditPaste:
393 // CHARACTER FORMATTING
394 case EEikCmdFontBold:
395 case EEikCmdFontItalic:
396 case EEikCmdFontUnderline:
397 case EEikCmdFontChange:
398 case EEikCmdInsertSymbol:
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:
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:
424 case EWordCmdObjectPreferences:
427 case EWordButtonStyle:
428 case EWordButtonFont:
429 case EWordButtonFontSize:
430 case EWordButtonAlign:
431 case EWordButtonBorders:
432 case EWordCmdInsertBullet:
433 case EWordButtonBullets:
436 case EWordCmdRevertToStylePara:
437 case EWordCmdRevertToStyleChar:
438 case EWordCmdStyleGallery:
440 const TBool readOnly=(iContainerAppUi)? iEmbeddedAndReadOnly : !(iDocument->AppFileMode()&EFileWrite);
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.
452 case EEikCmdFileImport:
453 CmdFileTextImportL();
455 case EWordCmdHtmlImport:
456 CmdFileHtmlImportL();
461 iRichEd->ClipboardCutL();
462 UpdateToolbandButtonsL();
464 case EEikCmdEditPaste:
465 if (KErrNotFound == iRichEd->ClipboardPasteL())
466 iEikonEnv->InfoMsg(R_WORD_NO_TEXT_TO_PASTE);
468 UpdateToolbandButtonsL();
471 // CHARACTER FORMATTING
472 case EEikCmdFontBold:
473 iRichEd->BoldItalicUnderlineEventL(CEikGlobalTextEditor::EBold);
475 case EEikCmdFontItalic:
476 iRichEd->BoldItalicUnderlineEventL(CEikGlobalTextEditor::EItalic);
478 case EEikCmdFontUnderline:
479 iRichEd->BoldItalicUnderlineEventL(CEikGlobalTextEditor::EUnderline);
481 case EEikCmdFontChange:
482 iRichEd->RunFontDialogL(EGulNoSymbolFonts, iCoeEnv->ScreenDevice());
483 UpdateCharFormatButtonsL();
485 case EEikCmdInsertSymbol:
486 iRichEd->RunCharMapDialogL();
489 // PARAGRAPH FORMATTING
490 case EEikCmdParaBorder:
491 case EEikCmdParaSpacing:
492 iRichEd->RunParaDialogsL(aCommand);
494 case EEikCmdParaIndent:
495 case EEikCmdParaTabs:
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);
505 iRichEd->RunTabsDialogL(width);
508 case EEikCmdParaAlign:
509 CmdChangeAlignmentL();
511 case EWordCmdAlignLeft:
512 case EWordCmdAlignRight:
513 case EWordCmdAlignCenter:
514 case EWordCmdAlignJustify:
516 SetParaAlignmentL(aCommand);
517 RTmParFormat::TAlignment alignment = RTmParFormat::EAlignNormal;
520 case EWordCmdAlignLeft:
521 alignment = RTmParFormat::EAlignNormal;
523 case EWordCmdAlignRight:
524 alignment = RTmParFormat::EAlignReverse;
526 case EWordCmdAlignCenter:
527 alignment = RTmParFormat::EAlignCenter;
529 case EWordCmdAlignJustify:
530 alignment = RTmParFormat::EAlignJustify;
533 UpdateAlignButtonL(alignment);
536 case EWordCmdFormatBullet:
537 RunSelectBulletDialogL();
541 case EEikCmdSearchReplace:
542 iRichEd->RunReplaceDialogL();
544 case EEikCmdEditPictureFormat:
545 iRichEd->EditPictureFormatL();
547 case EWordCmdInsertSketch:
548 iRichEd->InsertObjectL(KSketchDllName,KUidPaintApp,(SketchAsGlass())?CEikRichTextEditor::EGlassIfPossible : CEikRichTextEditor::EAlwaysIconic);
550 case EWordCmdInsertSheet:
551 iRichEd->InsertObjectL(KSheetDllName,KUidSheet,(GraphAsGlass())?CEikRichTextEditor::EGlassIfPossible : CEikRichTextEditor::EAlwaysIconic);
553 case EWordCmdInsertObject:
554 iRichEd->InsertObjectL(CEikRichTextEditor::EGlassIfPossible);
556 case EWordCmdInsertPageBreak:
557 case EWordCmdInsertLineBreak:
558 InsertCharacterL((aCommand==EWordCmdInsertPageBreak)
559 ? CEditableText::EPageBreak
560 : CEditableText::ELineBreak);
562 case EEikCmdEditUndo:
565 case EEikCmdEditRedo:
570 case EWordCmdObjectPreferences:
571 RunObjectPreferencesDialogL();
575 case EWordButtonStyle:
576 LaunchStylesPopupL();
578 case EWordButtonFont:
581 case EWordButtonFontSize:
582 LaunchFontHeightsPopupL();
584 case EWordButtonAlign:
587 case EWordButtonBorders:
588 LaunchBordersPopupL();
590 case EWordCmdInsertBullet:
592 if (REINTERPRET_CAST(CEikButtonBase*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonBullets))->State() == CEikButtonBase::EClear)
593 UpdateToolBandButton(EWordButtonBullets,CEikButtonBase::ESet);
595 UpdateToolBandButton(EWordButtonBullets,CEikButtonBase::EClear);
596 } // drops into next case with a purpose
597 case EWordButtonBullets:
602 case EWordCmdRevertToStylePara:
604 TCursorSelection selection=iRichEd->Selection();
605 Text()->RemoveSpecificParaFormatL(selection.LowerPos(),selection.Length());
606 ReformatDueToStateChangeL();
609 case EWordCmdRevertToStyleChar:
611 TCursorSelection selection=iRichEd->Selection();
612 Text()->RemoveSpecificCharFormatL(selection.LowerPos(),selection.Length());
613 ReformatDueToStateChangeL();
616 case EWordCmdStyleGallery:
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);
625 CEikDialog* dialog=CWordStyleGallery::NewL(data);
626 dialog->ExecuteLD(R_WORD_DIALOG_STYLE_GALLERY);
629 ReformatDueToStateChangeL();
639 case EWordCmdHighlight:
640 iRichEd->ToggleHighlightL(TTmCharFormat::EBackground);
643 iRichEd->ToggleHighlightL(TTmCharFormat::EShadow);
645 case EWordCmdCustomHighlight:
646 iRichEd->ToggleHighlightL((TUint)TFontPresentation::EFontHighlightFirstCustomStyle << TTmCharFormat::EUserDefinedShift);
648 case EWordCmdStandardKeyboard:
649 iTest->SetKeyboardL(CWordTest::EStandardKeyboard);
651 case EWordCmdArabicKeyboard:
652 iTest->SetKeyboardL(CWordTest::EArabicKeyboard);
654 case EWordCmdGreekKeyboard:
655 iTest->SetKeyboardL(CWordTest::EGreekKeyboard);
657 case EWordCmdRussianKeyboard:
658 iTest->SetKeyboardL(CWordTest::ERussianKeyboard);
660 case EWordCmdChineseOn:
662 const TUid KUidTFepChinese = { 0x1028716D };
663 iEikonEnv->InstallFepL(KUidTFepChinese);
666 case EWordCmdChineseOff:
667 iEikonEnv->InstallFepL(KNullUid);
669 case EWordCmdRuledPaper:
670 iTest->SetRuledPaperL(iRichEd,!iTest->RuledPaper());
672 case EWordCmdBackgroundBitmap:
673 iTest->SetBackgroundBitmapL(iRichEd,!iTest->BackgroundBitmap());
675 case EWordCmdUpperCase:
676 iTest->ToggleCaseL(iRichEd);
678 case EWordCmdBenchmark:
681 case EWordCmdTruncateWithEllipsis:
682 iTest->SetTruncateWithEllipsisL(iRichEd,!iTest->TruncateWithEllipsis());
684 case EWordCmdPictureAlignTop:
685 iTest->SetPictureAlignmentL(iRichEd,TFontPresentation::EAlignTop);
687 case EWordCmdPictureAlignBottom:
688 iTest->SetPictureAlignmentL(iRichEd,TFontPresentation::EAlignBottom);
690 case EWordCmdPictureAlignCenter:
691 iTest->SetPictureAlignmentL(iRichEd,TFontPresentation::EAlignCentered);
693 case EWordCmdPictureAlignBaseline:
694 iTest->SetPictureAlignmentL(iRichEd,TFontPresentation::EAlignBaseLine);
697 iTest->SetWrapL(iRichEd,TRUE);
699 case EWordCmdWrapOff:
700 iTest->SetWrapL(iRichEd,FALSE);
702 case EWordCmdInsertPicture:
704 iTest->InsertPictureL(iRichEd);
705 Document()->SetChanged(ETrue);
708 case EWordCmdCursorStyleFlash:
709 iTest->ToggleCursorFlash();
711 case EWordCmdCursorStyleVertical:
712 iTest->SetCursorPlacement(ECursorVertical);
714 case EWordCmdCursorStyleUnderlineNext:
715 iTest->SetCursorPlacement(ECursorUnderlineNext);
717 case EWordCmdCursorStyleUnderlinePrev:
718 iTest->SetCursorPlacement(ECursorUnderlinePrev);
720 case EWordCmdCursorStyleHeavy:
721 iTest->SetCursorWeight(iTest->CursorWeight() == 3 ? 1 : 3);
723 case EWordCmdCursorStyleRed:
724 iTest->SetCursorXorColor(iTest->CursorXorColor() == KRgbWhite ? KRgbCyan : KRgbWhite);
726 case EWordCmdUndoTestNotUndoable:
727 iRichEd->TestRunNotUndoableCommandL();
729 case EWordCmdPositioningHintNeutral:
730 iTest->SetCursorPositioningHintL(TCursorPosition::EPosHintUndefined);
732 case EWordCmdPositioningHintInsertLeftToRight:
733 iTest->SetCursorPositioningHintL(TCursorPosition::EInsertStrongL2R);
735 case EWordCmdPositioningHintInsertRightToLeft:
736 iTest->SetCursorPositioningHintL(TCursorPosition::EInsertStrongR2L);
738 case EWordCmdSelectionHighlightNormal:
739 iRichEd->TextView()->SetSelectionVisibilityL(EFalse);
740 iTest->SetSelectionHighlightStyle(0);
741 iRichEd->TextView()->SetSelectionVisibilityL(ETrue);
743 case EWordCmdSelectionHighlightCustom1:
744 iRichEd->TextView()->SetSelectionVisibilityL(EFalse);
745 iTest->SetSelectionHighlightStyle(1);
746 iRichEd->TextView()->SetSelectionVisibilityL(ETrue);
748 case EWordCmdSelectionHighlightCustom2:
749 iRichEd->TextView()->SetSelectionVisibilityL(EFalse);
750 iTest->SetSelectionHighlightStyle(2);
751 iRichEd->TextView()->SetSelectionVisibilityL(ETrue);
756 void CWordAppUi::DynInitMenuPaneL(TInt aMenuId,CEikMenuPane* aMenuPane)
758 TBool readOnly=iRichEd->IsReadOnly();
763 case R_WORD_FILE_MENU:
767 aMenuPane->DeleteMenuItem(EEikCmdFileNew);
768 aMenuPane->DeleteMenuItem(EEikCmdFileOpen);
774 case R_WORD_FILEOPTIONS_MENU:
778 aMenuPane->DeleteMenuItem(EEikCmdFileSave);
779 aMenuPane->DeleteMenuItem(EEikCmdFileSaveAs);
780 aMenuPane->DeleteMenuItem(EEikCmdFileRevert);
781 aMenuPane->DeleteMenuItem(EWordCmdFileSaveAsTemplate);
782 aMenuPane->DeleteMenuItem(EWordCmdFileDeleteTemplate);
786 aMenuPane->SetItemDimmed(EEikCmdFileSave,TRUE);
787 aMenuPane->SetItemDimmed(EEikCmdFileRevert,TRUE);
791 aMenuPane->SetItemDimmed(EEikCmdFileImport,TRUE);
792 aMenuPane->SetItemDimmed(EWordCmdHtmlImport,ETrue);
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();
806 aMenuPane->SetItemDimmed(EEikCmdEditCopy,TRUE);
807 if (readOnly || selection==0)
808 aMenuPane->SetItemDimmed(EEikCmdEditCut,TRUE);
810 aMenuPane->SetItemDimmed(EEikCmdEditPaste,TRUE);
815 case R_WORD_EDITFIND_MENU:
817 TInt documentLength=iRichEd->TextLength();
818 if (documentLength==0)
820 aMenuPane->SetItemDimmed(EEikCmdSearchFind,TRUE);
821 aMenuPane->SetItemDimmed(EEikCmdSearchFindAgain,TRUE);
822 aMenuPane->SetItemDimmed(EWordCmdGoTo,TRUE);
824 if (documentLength==0 || readOnly)
825 aMenuPane->SetItemDimmed(EEikCmdSearchReplace,TRUE);
830 case R_WORD_EDITOPTIONS_MENU:
832 aMenuPane->SetItemDimmed(EEikCmdEditPictureFormat,TRUE);
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);
848 case R_WORD_INSERT_MENU:
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);
861 case R_WORD_TEXT_MENU:
863 TCharFormat charFormat;
864 TCharFormatMask charUndeterminedMask;
865 ((CRichText*)iRichEd->Text())->GetCharFormat(charFormat,charUndeterminedMask,iRichEd->CursorPos(),0);
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);
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);
885 case R_WORD_PARAGRAPH_MENU:
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);
900 case R_WORD_PARA_ALIGNMENT_MENU:
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))
908 switch (paraFormat->iHorizontalAlignment)
910 case CParaFormat::ELeftAlign:
911 aMenuPane->SetItemButtonState(EWordCmdAlignLeft,EEikMenuItemSymbolOn);
912 aMenuPane->SetSelectedItem(0);
914 case CParaFormat::ERightAlign:
915 aMenuPane->SetItemButtonState(EWordCmdAlignRight,EEikMenuItemSymbolOn);
916 aMenuPane->SetSelectedItem(1);
918 case CParaFormat::ECenterAlign:
919 aMenuPane->SetItemButtonState(EWordCmdAlignCenter,EEikMenuItemSymbolOn);
920 aMenuPane->SetSelectedItem(2);
922 case CParaFormat::EJustifiedAlign:
923 aMenuPane->SetItemButtonState(EWordCmdAlignJustify,EEikMenuItemSymbolOn);
924 aMenuPane->SetSelectedItem(3);
930 CleanupStack::PopAndDestroy();
933 aMenuPane->SetItemDimmed(EWordCmdAlignLeft,TRUE);
934 aMenuPane->SetItemDimmed(EWordCmdAlignRight,TRUE);
935 aMenuPane->SetItemDimmed(EWordCmdAlignCenter,TRUE);
936 aMenuPane->SetItemDimmed(EWordCmdAlignJustify,TRUE);
942 case R_WORD_PARA_BULLETS_MENU:
945 aMenuPane->SetItemDimmed(EWordCmdInsertBullet,TRUE);
946 aMenuPane->SetItemDimmed(EWordCmdFormatBullet,TRUE);
951 case R_WORD_TOOLS_MENU:
954 aMenuPane->SetItemDimmed(EWordCmdObjectPreferences,TRUE);
959 case R_EIK_SIDEBAR_IRDA_MENU:
960 case R_WORD_TOOLS_INFRARED:
961 aMenuPane->SetItemDimmed(EEikCmdIrdaReceive, TRUE);
962 aMenuPane->SetItemDimmed(EEikCmdIrdaSend, TRUE);
966 case R_EIK_SIDEBAR_EDIT_MENU:
968 TInt selection=iRichEd->Selection().Length();
970 aMenuPane->SetItemDimmed(EEikCmdEditCopy,TRUE);
971 if (readOnly || selection==0)
972 aMenuPane->SetItemDimmed(EEikCmdEditCut,TRUE);
974 aMenuPane->SetItemDimmed(EEikCmdEditPaste,TRUE);
978 case R_WORD_TEST_MENU:
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);
1001 case R_WORD_PICTURE_ALIGNMENT_MENU:
1004 TCursorSelection sel = iRichEd->Selection();
1005 TCharFormatMask varies;
1006 Text()->GetCharFormat(format,varies,sel.LowerPos(),sel.Length());
1007 if (!varies.AttribIsSet(EAttFontPictureAlignment))
1009 switch (format.iFontPresentation.iPictureAlignment)
1011 case TFontPresentation::EAlignTop:
1012 aMenuPane->SetItemButtonState(EWordCmdPictureAlignTop,EEikMenuItemSymbolOn);
1013 aMenuPane->SetSelectedItem(0);
1015 case TFontPresentation::EAlignBottom:
1016 aMenuPane->SetItemButtonState(EWordCmdPictureAlignBottom,EEikMenuItemSymbolOn);
1017 aMenuPane->SetSelectedItem(1);
1019 case TFontPresentation::EAlignCentered:
1020 aMenuPane->SetItemButtonState(EWordCmdPictureAlignCenter,EEikMenuItemSymbolOn);
1021 aMenuPane->SetSelectedItem(2);
1023 case TFontPresentation::EAlignBaseLine:
1024 aMenuPane->SetItemButtonState(EWordCmdPictureAlignBaseline,EEikMenuItemSymbolOn);
1025 aMenuPane->SetSelectedItem(3);
1033 aMenuPane->SetItemDimmed(EWordCmdPictureAlignTop,TRUE);
1034 aMenuPane->SetItemDimmed(EWordCmdPictureAlignBottom,TRUE);
1035 aMenuPane->SetItemDimmed(EWordCmdPictureAlignCenter,TRUE);
1036 aMenuPane->SetItemDimmed(EWordCmdPictureAlignBaseline,TRUE);
1041 case R_WORD_KEYBOARD_MENU:
1042 switch (iTest->Keyboard())
1044 case CWordTest::EStandardKeyboard:
1045 aMenuPane->SetItemButtonState(EWordCmdStandardKeyboard,EEikMenuItemSymbolOn);
1046 aMenuPane->SetSelectedItem(0);
1048 case CWordTest::EGreekKeyboard:
1049 aMenuPane->SetItemButtonState(EWordCmdGreekKeyboard,EEikMenuItemSymbolOn);
1050 aMenuPane->SetSelectedItem(1);
1052 case CWordTest::ERussianKeyboard:
1053 aMenuPane->SetItemButtonState(EWordCmdRussianKeyboard,EEikMenuItemSymbolOn);
1054 aMenuPane->SetSelectedItem(2);
1056 case CWordTest::EArabicKeyboard:
1057 aMenuPane->SetItemButtonState(EWordCmdArabicKeyboard,EEikMenuItemSymbolOn);
1058 aMenuPane->SetSelectedItem(3);
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())
1072 case ECursorVertical:
1073 aMenuPane->SetItemButtonState(EWordCmdCursorStyleVertical,EEikMenuItemSymbolOn);
1074 aMenuPane->SetSelectedItem(1);
1076 case ECursorUnderlineNext:
1077 aMenuPane->SetItemButtonState(EWordCmdCursorStyleUnderlineNext,EEikMenuItemSymbolOn);
1078 aMenuPane->SetSelectedItem(2);
1080 case ECursorUnderlinePrev:
1081 aMenuPane->SetItemButtonState(EWordCmdCursorStyleUnderlinePrev,EEikMenuItemSymbolOn);
1082 aMenuPane->SetSelectedItem(3);
1086 case R_WORD_SELECTION_HIGHLIGHT_MENU:
1087 aMenuPane->SetItemButtonState(
1088 aMenuPane->MenuItemCommandId(iTest->SelectionHighlightStyle()),
1089 EEikMenuItemSymbolOn);
1092 case R_WORD_POSITIONING_HINT_TEST_MENU:
1093 switch(iTest->CursorPositioningHint())
1095 case TCursorPosition::EPosHintUndefined:
1096 aMenuPane->SetItemButtonState(
1097 EWordCmdPositioningHintNeutral,
1098 EEikMenuItemSymbolOn);
1099 aMenuPane->SetSelectedItem(1);
1101 case TCursorPosition::EInsertStrongL2R:
1102 aMenuPane->SetItemButtonState(
1103 EWordCmdPositioningHintInsertLeftToRight,
1104 EEikMenuItemSymbolOn);
1105 aMenuPane->SetSelectedItem(2);
1107 case TCursorPosition::EInsertStrongR2L:
1108 aMenuPane->SetItemButtonState(
1109 EWordCmdPositioningHintInsertRightToLeft,
1110 EEikMenuItemSymbolOn);
1111 aMenuPane->SetSelectedItem(3);
1120 void CWordAppUi::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
1122 if (iWordFlags&EFNameBoxPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
1124 if (aEventType==EEventRequestExit)
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);
1133 charFormat.iFontSpec.iTypeface.SetAttributes(FontUtils::TypefaceAttributes(*iCoeEnv->ScreenDevice(),charFormat.iFontSpec.iTypeface.iName));
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);
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);
1149 iWordFlags&=~EFNameBoxPopped;
1150 DestroyPopoutLBox();
1153 else if (iWordFlags&EStyleBoxPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
1155 if (aEventType==EEventRequestExit)
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);
1166 const CParagraphStyle& paraStyle=*(Text()->StyleList()->PtrByName((*array)[index])->iStyle);
1167 Text()->ApplyParagraphStyleL(paraStyle,selection.LowerPos(),selection.Length(),KApplyParaStyleMode);
1169 ReformatDueToStateChangeL();
1171 iWordFlags&=~EStyleBoxPopped;
1172 DestroyPopoutLBox();
1175 else if (iWordFlags&EAlignBoxPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
1177 if (aEventType==EEventRequestExit)
1179 const TInt index = iBitmapPopout->CurrentItemIndex();
1180 SetParaAlignmentL(index);
1181 ReformatDueToStateChangeL();
1183 iWordFlags&=~EAlignBoxPopped;
1184 DestroyPopoutLBox();
1187 else if (iWordFlags&EFHeightBoxPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
1189 if (aEventType==EEventRequestExit)
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);
1199 iWordFlags&=~EFHeightBoxPopped;
1200 DestroyPopoutLBox();
1203 else if (iWordFlags&EBordersPopped && (aEventType==EEventRequestCancel ||aEventType==EEventRequestExit))
1205 if (aEventType==EEventRequestExit)
1211 const TInt index=iMcBitmapPopout->CurrentItemIndex();
1214 case (ESingleFull-ESingleFull):
1215 top.iThickness=KThinBorderThicknessInTwips;
1216 bottom.iThickness=KThinBorderThicknessInTwips;
1217 left.iThickness=KThinBorderThicknessInTwips;
1218 right.iThickness=KThinBorderThicknessInTwips;
1220 case (ESingleTop-ESingleFull):
1221 top.iThickness=KThinBorderThicknessInTwips;
1223 case (ESingleBottom-ESingleFull):
1224 bottom.iThickness=KThinBorderThicknessInTwips;
1226 case (ESingleTopAndBottom-ESingleFull):
1227 top.iThickness=KThinBorderThicknessInTwips;
1228 bottom.iThickness=KThinBorderThicknessInTwips;
1230 case (EDoubleFull-ESingleFull):
1231 top.iThickness=KThickBorderThicknessInTwips;
1232 bottom.iThickness=KThickBorderThicknessInTwips;
1233 left.iThickness=KThickBorderThicknessInTwips;
1234 right.iThickness=KThickBorderThicknessInTwips;
1236 case (EDoubleTop-ESingleFull):
1237 top.iThickness=KThickBorderThicknessInTwips;
1239 case (EDoubleBottom-ESingleFull):
1240 bottom.iThickness=KThickBorderThicknessInTwips;
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;
1252 case (ESingleTop-ESingleFull):
1253 case (EDoubleTop-ESingleFull):
1254 top.iLineStyle=TParaBorder::ESolid;
1256 case (ESingleBottom-ESingleFull):
1257 case (EDoubleBottom-ESingleFull):
1258 bottom.iLineStyle=TParaBorder::ESolid;
1260 case (ESingleTopAndBottom-ESingleFull):
1261 top.iLineStyle=TParaBorder::ESolid;
1262 bottom.iLineStyle=TParaBorder::ESolid;
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
1278 iWordFlags&=~EBordersPopped;
1279 DestroyPopoutLBox();
1282 if (aEventType==EEventStateChanged)
1284 SetPaginationOutOfDate(TRUE);
1285 if (aControl==iRichEd)
1286 iToolBarUpdate->Start(CWordToolBarUpdate::ECharFormatUpdate);
1288 if (iPaginateDialogCalled && aEventType==EEventRequestExit)
1289 { // !! possibly better - the dialog should define its own observer class
1291 SetPaginationOutOfDate(FALSE);
1292 iPaginateDialogCalled=FALSE;
1298 void CWordAppUi::HandleEdwinEventL(CEikEdwin* aEdwin,TEdwinEvent aEventType)
1300 if (aEdwin==iRichEd && (aEventType==MEikEdwinObserver::EEventFormatChanged ||
1301 aEventType==MEikEdwinObserver::EEventNavigation))
1303 if (aEventType==MEikEdwinObserver::EEventFormatChanged)
1305 SetPaginationOutOfDate(TRUE);
1308 if (iEikonEnv->AppUiFactory()->ToolBar()->IsVisible() || iEikonEnv->AppUiFactory()->ToolBand()->IsVisible())
1309 iToolBarUpdate->Start(CWordToolBarUpdate::EFullUpdate);
1313 void CWordAppUi::RunPageSetupDialogL()
1315 if (CEikPageSetupDialog::RunDlgLD(iPrintSetup))
1317 CTextPageRegionPrinter& printer=PageRegionPrinter();
1318 printer.SetPageMarginsInTwips(iPrintSetup->iPageMarginsInTwips.iMargins);
1319 printer.SetPageSpecInTwips(iPrintSetup->PrinterDevice()->CurrentPageSpecInTwips());
1320 SetPaginationOutOfDate(TRUE);
1322 UpdatePageLayoutL();
1323 iRichEd->DrawNow(); // need to display any page breaks immediatley.