Update contrib.
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.
24 #include <techview/eiklabel.h>
25 #include <techview/eikimage.h>
26 #include <techview/eikrted.h>
27 #include <techview/eiktbar.h>
28 #include <techview/eikcmbut.h>
29 #include <techview/eikfnlab.h>
31 #include <techview/eikbtgpc.h>
42 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
43 #include "txtfmlyr_internal.h"
46 void CWordAppUi::UpdateToolBarAndBandL(TInt aCommand)
48 __ASSERT_ALWAYS(aCommand == EWordCmdToolband || aCommand == EWordCmdToolbar, Panic(EInvalidCommandParameter));
50 TBool getsHidden = EFalse;
51 if(aCommand == EWordCmdToolband)
53 getsHidden = !ToggleToolbarControlL(*iEikonEnv->AppUiFactory()->ToolBand());
57 iEikonEnv->AppUiFactory()->ToolBar()->SetComponentsToInheritVisibility(ETrue);
58 getsHidden = iEikonEnv->AppUiFactory()->ToolBar()->IsVisible();
59 iEikonEnv->AppUiFactory()->ToolBar()->MakeVisible(!getsHidden);
64 if (aCommand == EWordCmdToolbar)
65 iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordCmdFileName)->DrawNow(); // redraw the filename label only
68 TRect bottomBorder = iRichEd->Rect();
69 bottomBorder.iTl.iY = bottomBorder.iBr.iY - 1;
70 STATIC_CAST(RWindow*, iRichEd->DrawableWindow())->Invalidate(bottomBorder);
73 TInt adjacent = EGulAdjNone;
74 if (iEikonEnv->AppUiFactory()->ToolBar()->IsVisible())
75 adjacent |= EGulAdjRight;
76 if (iEikonEnv->AppUiFactory()->ToolBand()->IsVisible())
77 adjacent |= EGulAdjTop;
78 iRichEd->SetAdjacent(adjacent);
79 iRichEd->SetRect(ClientRect());
80 iRichEd->ForceScrollBarUpdateL();
85 TBool CWordAppUi::ToggleToolbarControlL(CEikToolBar& aToolBar)
86 // Toggles the visibility of the specified toolbar conttrol.
87 // Returns ETrue if the toolbar becomes visible as a result of this action,
88 // otherwise returns EFalse.
91 const TBool visible = aToolBar.IsVisible();
93 {// Update buttons if the toolbar is about to appear
94 UpdateToolbandButtonsL(EVisibilityIndependant);
96 aToolBar.MakeVisible(!visible);
100 void CWordAppUi::UpdateToolbandButtonsL(TToolBarUpdate aUpdate)
102 if (!aUpdate && !iEikonEnv->AppUiFactory()->ToolBand()->IsVisible())
104 UpdateCharFormatButtonsL();
105 UpdateParaFormatButtonsL();
109 void CWordAppUi::UpdateCharFormatButtonsL()
112 TCharFormatMask mask;
113 const TCursorSelection selection=iRichEd->Selection();
114 Text()->GetCharFormat(format,mask,selection.LowerPos(),selection.Length());
116 UpdateToolBandButton(EEikCmdFontBold,format.iFontSpec.iFontStyle.StrokeWeight()==EStrokeWeightBold? CEikButtonBase::ESet : CEikButtonBase::EClear);
117 UpdateToolBandButton(EEikCmdFontItalic,format.iFontSpec.iFontStyle.Posture()==EPostureItalic? CEikButtonBase::ESet : CEikButtonBase::EClear);
118 UpdateToolBandButton(EEikCmdFontUnderline,format.iFontPresentation.iUnderline==EUnderlineOn? CEikButtonBase::ESet : CEikButtonBase::EClear);
120 UpdateToolBandFontNameButtonL(format.iFontSpec.iTypeface.iName);
121 UpdateToolBandFontHeightButtonL(format.iFontSpec.iHeight);
125 void CWordAppUi::UpdateToolBandButton(TInt aCommand,CEikButtonBase::TState aNewState)
126 // Sets the state of the specified latching button in the toolband.
129 CEikButtonBase* button = STATIC_CAST(CEikButtonBase*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(aCommand));
130 if (button->State() != aNewState)
132 button->SetState(aNewState);
137 void CWordAppUi::UpdateParaFormatButtonsL()
139 RTmParFormatLayer format;
141 iRichEd->GetParFormatL(iRichEd->CursorPos(),MUnifiedEditor::EEffective,format,run_length);
142 RTmParFormat::TAlignment alignment = format.iFormat.iAlignment;
143 TBool have_bullet = format.iFormat.Bullet() != NULL;
144 TBool have_borders = format.iFormat.HaveBorders();
147 UpdateStyleButtonL();
148 UpdateAlignButtonL(alignment);
149 UpdateToolBandButton(EWordButtonBullets,have_bullet ? CEikButtonBase::ESet : CEikButtonBase::EClear);
150 UpdateBorderButtonL(have_borders);
153 void CWordAppUi::UpdateToolBandFontNameButtonL(TDesC& aNewFontName)
156 TBuf<KMaxTypefaceNameLength> typefaceName;
157 typefaceName=aNewFontName;
158 UpdateToolBandFontNameButtonL(typefaceName);
161 void CWordAppUi::UpdateToolBandFontNameButtonL(TDes& aNewFontName)
162 // Only change the label text if the current font is different from that specified.
165 CEikCommandButton* button = STATIC_CAST(CEikCommandButton*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonFont));
166 CEikLabel* buttonLabel=button->Label();
167 TInt maxWidthInPixels=buttonLabel->Size().iWidth;
168 TextUtils::ClipToFit(aNewFontName,*iEikonEnv->LegendFont(),maxWidthInPixels,KClippedTextCharacter);
169 if (aNewFontName!=*buttonLabel->Text())
171 buttonLabel->SetTextL(aNewFontName);
172 buttonLabel->DrawNow();
176 void CWordAppUi::UpdateToolBandFontHeightButtonL(const TInt aNewFontHeight)
177 // Only change the label text if necessary
180 const TInt points = FontUtils::PointsFromTwips(aNewFontHeight);
182 noPoints.Num(points);
184 iCoeEnv->ReadResource(temp, R_WORD_FONT_UNITS);
185 noPoints.Append(temp);
186 CEikCommandButton* button = STATIC_CAST(CEikCommandButton*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonFontSize));
187 CEikLabel* buttonLabel = button->Label();
188 if (*buttonLabel->Text() != noPoints)
190 buttonLabel->SetTextL(noPoints);
191 buttonLabel->DrawNow();
195 void CWordAppUi::UpdateStyleButtonL()
196 // Update the label on the style name button, but only if, after clipping,
197 // the text is different to the current setting.
200 const TCursorSelection selection = iRichEd->Selection();
202 const CParaFormatLayer* style = Text()->ParagraphStyle(styleChange, selection.LowerPos(), selection.Length());
203 TUid type = style->Type();
204 TParagraphStyleName name;
205 if (type != KNormalParagraphStyleUid)
206 name = ((CParagraphStyle*)style)->iName;
208 iCoeEnv->ReadResource(name, R_WORD_NORMAL);
209 CEikCommandButton* button = STATIC_CAST(CEikCommandButton*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonStyle));
210 CEikLabel* buttonLabel = button->Label();
211 TInt maxWidthInPixels = buttonLabel->Size().iWidth;
212 TextUtils::ClipToFit(name, *iEikonEnv->LegendFont(), maxWidthInPixels, KClippedTextCharacter);
213 if (*buttonLabel->Text() != name)
215 buttonLabel->SetTextL(name);
216 buttonLabel->DrawNow();
220 void CWordAppUi::UpdateAlignButtonL(RTmParFormat::TAlignment aNewAlignment)
221 // Update the alignment button.
224 if (iAlignment == aNewAlignment)
226 CEikBitmapButton* align = STATIC_CAST(CEikBitmapButton*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonAlign));
227 switch(aNewAlignment)
229 case RTmParFormat::EAlignCenter:
230 align->SetPictureFromFileL(TPtrC(), EMbmEikonCenta, EMbmEikonCenta, CEikCommandButtonBase::EFirst);
232 case RTmParFormat::EAlignJustify:
233 align->SetPictureFromFileL(TPtrC(), EMbmEikonJusta, EMbmEikonJusta, CEikCommandButtonBase::EFirst);
235 case RTmParFormat::EAlignReverse:
236 align->SetPictureFromFileL(TPtrC(), EMbmEikonRighta, EMbmEikonRighta, CEikCommandButtonBase::EFirst);
238 case RTmParFormat::EAlignNormal:
240 align->SetPictureFromFileL(TPtrC(), EMbmEikonLefta, EMbmEikonLefta, CEikCommandButtonBase::EFirst);
243 iAlignment = aNewAlignment;
244 align->Picture()->DrawNow();
248 void CWordAppUi::UpdateBorderButtonL(TBool aBordersPresent)
249 // Changes the border button, but only if the desired state is different from the current state.
252 CEikBitmapButton* button = STATIC_CAST(CEikBitmapButton*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonBorders));
253 if (aBordersPresent != iBorderPresent)
254 {// Change the button
256 button->SetPictureFromFileL(BitmapStore(), EMbmWordBorderf, EMbmWordBorderfm, CEikCommandButtonBase::EFirst);
258 button->SetPictureFromFileL(BitmapStore(), EMbmWordBordern, EMbmWordBordernm, CEikCommandButtonBase::EFirst);
259 iBorderPresent = aBordersPresent;
260 button->Picture()->DrawNow();
265 void CWordAppUi::UpdateFileNameLabelL()
266 // Update the label text on both the toolbar and toolband filename controls
269 CEikFileNameLabel* label = STATIC_CAST(CEikFileNameLabel*, iEikonEnv->AppUiFactory()->ToolBar()->ControlOrNull(EWordCmdFileName));
275 label = STATIC_CAST(CEikFileNameLabel*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordCmdFileName));
276 if (!iContainerAppUi)
283 // class CWordToolBarUpdate
286 CWordToolBarUpdate* CWordToolBarUpdate::NewL(CWordAppUi& aAppUi)
287 // Create a new idle object.
289 CWordToolBarUpdate* self=new(ELeave) CWordToolBarUpdate(aAppUi);
290 CActiveScheduler::Add(self);
294 CWordToolBarUpdate::CWordToolBarUpdate(CWordAppUi& aAppUi)
296 : CActive(EActivePriorityDefault), iAppUi(aAppUi)
298 iCount=(TInt)(CWordAppUi::EStyleName);
301 CWordToolBarUpdate::~CWordToolBarUpdate()
307 void CWordToolBarUpdate::Start(TUpdateType aUpdateType)
310 if (aUpdateType==EFullUpdate)
312 iCount=(TInt)(CWordAppUi::EStyleName);
313 iUpdateType=EFullUpdate;
317 if (iUpdateType==ECharFormatUpdate)
318 iCount=(TInt)(CWordAppUi::EFontName);
321 if (iCount>(TInt)(CWordAppUi::EBorder))
323 iCount=(TInt)(CWordAppUi::EFontName);
324 iUpdateType=ECharFormatUpdate;
327 iCount=Min((TInt)(CWordAppUi::EFontName),iCount);
332 TRequestStatus* pS=(&iStatus);
333 User::RequestComplete(pS,0);
337 void CWordToolBarUpdate::RunL()
338 // Called when nothing of a higher priority can be scheduled.
340 if (!STATIC_CAST(CEikonEnv*, iAppUi.iCoeEnv)->AppUiFactory()->ToolBand()->IsVisible())
344 case CWordAppUi::EStyleName:
345 iAppUi.UpdateStyleButtonL();
347 case CWordAppUi::EFontName:
350 // Get the current character format
352 TCharFormatMask mask;
353 const TCursorSelection selection=iAppUi.iRichEd->Selection();
354 iAppUi.Text()->GetCharFormat(format,mask,selection.LowerPos(),selection.Length());
356 // Store values for later use
357 iFontHeightInTwips=format.iFontSpec.iHeight;
358 iStrokeWeight=format.iFontSpec.iFontStyle.StrokeWeight();
359 iPosture=format.iFontSpec.iFontStyle.Posture();
360 iUnderline=format.iFontPresentation.iUnderline;
362 // Update the font name button
363 TBuf<KMaxTypefaceNameLength> typefaceName;
364 typefaceName=format.iFontSpec.iTypeface.iName;
365 iAppUi.UpdateToolBandFontNameButtonL(typefaceName);
368 case CWordAppUi::EFontHeight:
369 iAppUi.UpdateToolBandFontHeightButtonL(iFontHeightInTwips);
371 case CWordAppUi::EBold:
372 iAppUi.UpdateToolBandButton(EEikCmdFontBold,iStrokeWeight==EStrokeWeightBold? CEikButtonBase::ESet : CEikButtonBase::EClear);
374 case CWordAppUi::EItalic:
375 iAppUi.UpdateToolBandButton(EEikCmdFontItalic,iPosture==EPostureItalic? CEikButtonBase::ESet : CEikButtonBase::EClear);
377 case CWordAppUi::EUnderline:
378 iAppUi.UpdateToolBandButton(EEikCmdFontUnderline,iUnderline==EUnderlineOn? CEikButtonBase::ESet : CEikButtonBase::EClear);
380 case CWordAppUi::EAlignment:
382 RTmParFormatLayer format;
384 iAppUi.iRichEd->GetParFormatL(iAppUi.iRichEd->CursorPos(),MUnifiedEditor::EEffective,format,run_length);
385 RTmParFormat::TAlignment alignment = format.iFormat.iAlignment;
386 iBulletPresent = format.iFormat.Bullet() != NULL;
387 iBordersPresent = format.iFormat.HaveBorders();
389 iAppUi.UpdateAlignButtonL(alignment);
392 case CWordAppUi::EBullet:
393 iAppUi.UpdateToolBandButton(EWordButtonBullets,iBulletPresent ? CEikButtonBase::ESet : CEikButtonBase::EClear);
395 case CWordAppUi::EBorder:
396 iAppUi.UpdateBorderButtonL(iBordersPresent);
400 if ((iUpdateType==EFullUpdate && iCount<=(TInt)(CWordAppUi::EBorder)) ||
401 (iUpdateType==ECharFormatUpdate && iCount<=(TInt)(CWordAppUi::EUnderline)))
403 TRequestStatus* pS=(&iStatus);
404 User::RequestComplete(pS,0);
409 void CWordToolBarUpdate::DoCancel()