os/textandloc/textrendering/word/SRC/WPAPPTBR.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 <txtrich.h>
    20 
    21 #include <prnsetup.h>
    22 
    23 #include <eikenv.h>
    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>
    30 #include <eikon.mbg>
    31 #include <techview/eikbtgpc.h>
    32 #include <eikfutil.h>
    33 
    34 #include "WPAPPUI.H"
    35 #include "WPSTYLE.H"
    36 #include "WPDEF.H"
    37 #include "WORD.HRH"
    38 #include <word.rsg>
    39 #include <word.mbg>
    40 #include "WPPANIC.H"
    41 
    42 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    43 #include "txtfmlyr_internal.h"
    44 #endif
    45 
    46 void CWordAppUi::UpdateToolBarAndBandL(TInt aCommand)
    47 	{
    48 	__ASSERT_ALWAYS(aCommand == EWordCmdToolband || aCommand == EWordCmdToolbar, Panic(EInvalidCommandParameter));
    49 	
    50 	TBool getsHidden = EFalse;
    51 	if(aCommand == EWordCmdToolband)
    52 		{
    53 		getsHidden = !ToggleToolbarControlL(*iEikonEnv->AppUiFactory()->ToolBand());
    54 		}
    55 	else
    56 		{
    57 		iEikonEnv->AppUiFactory()->ToolBar()->SetComponentsToInheritVisibility(ETrue);
    58 		getsHidden = iEikonEnv->AppUiFactory()->ToolBar()->IsVisible();
    59 		iEikonEnv->AppUiFactory()->ToolBar()->MakeVisible(!getsHidden);
    60 		}
    61 
    62 	if (getsHidden)
    63 		{
    64 		if (aCommand == EWordCmdToolbar)
    65 			iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordCmdFileName)->DrawNow();  // redraw the filename label only
    66 		else
    67 			{
    68 			TRect bottomBorder = iRichEd->Rect();
    69 			bottomBorder.iTl.iY = bottomBorder.iBr.iY - 1;
    70 			STATIC_CAST(RWindow*, iRichEd->DrawableWindow())->Invalidate(bottomBorder);
    71 			}
    72 		}
    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();
    81 	iRichEd->DrawNow();
    82 	}
    83 
    84 
    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.
    89 //
    90 	{
    91 	const TBool visible = aToolBar.IsVisible();
    92 	if (!visible)
    93 		{// Update buttons if the toolbar is about to appear
    94 		UpdateToolbandButtonsL(EVisibilityIndependant);
    95 		}
    96 	aToolBar.MakeVisible(!visible);
    97 	return !visible;
    98 	}
    99 
   100 void CWordAppUi::UpdateToolbandButtonsL(TToolBarUpdate aUpdate)
   101 	{
   102 	if (!aUpdate && !iEikonEnv->AppUiFactory()->ToolBand()->IsVisible())
   103 		return;
   104 	UpdateCharFormatButtonsL();
   105 	UpdateParaFormatButtonsL();
   106 	}
   107 
   108 
   109 void CWordAppUi::UpdateCharFormatButtonsL()
   110 	{
   111 	TCharFormat format;
   112 	TCharFormatMask mask;
   113 	const TCursorSelection selection=iRichEd->Selection();
   114 	Text()->GetCharFormat(format,mask,selection.LowerPos(),selection.Length());
   115 	//
   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);
   119 	//
   120 	UpdateToolBandFontNameButtonL(format.iFontSpec.iTypeface.iName);
   121 	UpdateToolBandFontHeightButtonL(format.iFontSpec.iHeight);
   122 	}
   123 
   124 
   125 void CWordAppUi::UpdateToolBandButton(TInt aCommand,CEikButtonBase::TState aNewState)
   126 // Sets the state of the specified latching button in the toolband.
   127 //
   128 	{
   129 	CEikButtonBase* button = STATIC_CAST(CEikButtonBase*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(aCommand));
   130 	if (button->State() != aNewState)
   131 		{
   132 		button->SetState(aNewState);
   133 		button->DrawNow();
   134 		}
   135 	}
   136 
   137 void CWordAppUi::UpdateParaFormatButtonsL()
   138 	{
   139 	RTmParFormatLayer format;
   140 	TInt run_length;
   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();
   145 	format.Close();
   146 
   147 	UpdateStyleButtonL();
   148 	UpdateAlignButtonL(alignment);
   149 	UpdateToolBandButton(EWordButtonBullets,have_bullet ? CEikButtonBase::ESet : CEikButtonBase::EClear);
   150 	UpdateBorderButtonL(have_borders);
   151 	}
   152 
   153 void CWordAppUi::UpdateToolBandFontNameButtonL(TDesC& aNewFontName)
   154 // 
   155 	{
   156 	TBuf<KMaxTypefaceNameLength> typefaceName;
   157 	typefaceName=aNewFontName;
   158 	UpdateToolBandFontNameButtonL(typefaceName);
   159 	}
   160 
   161 void CWordAppUi::UpdateToolBandFontNameButtonL(TDes& aNewFontName)
   162 // Only change the label text if the current font is different from that specified.
   163 //
   164 	{
   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())
   170 		{
   171 		buttonLabel->SetTextL(aNewFontName);
   172 		buttonLabel->DrawNow();
   173 		}
   174 	}
   175 
   176 void CWordAppUi::UpdateToolBandFontHeightButtonL(const TInt aNewFontHeight)
   177 // Only change the label text if necessary
   178 //
   179 	{
   180 	const TInt points = FontUtils::PointsFromTwips(aNewFontHeight);
   181 	TBuf<16> noPoints;
   182 	noPoints.Num(points);    
   183 	TBuf<4> temp;
   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)
   189 		{
   190 		buttonLabel->SetTextL(noPoints);
   191 		buttonLabel->DrawNow();
   192 		}
   193 	}
   194 
   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.
   198 //
   199 	{
   200 	const TCursorSelection selection = iRichEd->Selection();
   201 	TBool styleChange;
   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;
   207 	else
   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)
   214 		{
   215 		buttonLabel->SetTextL(name);
   216 		buttonLabel->DrawNow();
   217 		}
   218 	}
   219 
   220 void CWordAppUi::UpdateAlignButtonL(RTmParFormat::TAlignment aNewAlignment)
   221 // Update the alignment button.
   222 //
   223 	{
   224 	if (iAlignment == aNewAlignment)
   225 		return;
   226 	CEikBitmapButton* align = STATIC_CAST(CEikBitmapButton*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonAlign));
   227 	switch(aNewAlignment)
   228 		{
   229 		case RTmParFormat::EAlignCenter:
   230 			align->SetPictureFromFileL(TPtrC(), EMbmEikonCenta, EMbmEikonCenta, CEikCommandButtonBase::EFirst);
   231 			break;
   232 		case RTmParFormat::EAlignJustify:
   233 			align->SetPictureFromFileL(TPtrC(), EMbmEikonJusta, EMbmEikonJusta, CEikCommandButtonBase::EFirst);
   234 			break;
   235 		case RTmParFormat::EAlignReverse:
   236 			align->SetPictureFromFileL(TPtrC(), EMbmEikonRighta, EMbmEikonRighta, CEikCommandButtonBase::EFirst);
   237 			break;
   238 		case RTmParFormat::EAlignNormal:
   239 		default:
   240 			align->SetPictureFromFileL(TPtrC(), EMbmEikonLefta, EMbmEikonLefta, CEikCommandButtonBase::EFirst);
   241 			break;
   242 		}
   243 	iAlignment = aNewAlignment;
   244 	align->Picture()->DrawNow();
   245 	}
   246 
   247 
   248 void CWordAppUi::UpdateBorderButtonL(TBool aBordersPresent)
   249 // Changes the border button, but only if the desired state is different from the current state.
   250 //
   251 	{
   252 	CEikBitmapButton* button = STATIC_CAST(CEikBitmapButton*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonBorders));
   253 	if (aBordersPresent != iBorderPresent)
   254 		{// Change the button
   255 		if (aBordersPresent)
   256 			button->SetPictureFromFileL(BitmapStore(), EMbmWordBorderf, EMbmWordBorderfm, CEikCommandButtonBase::EFirst);
   257 		else
   258 			button->SetPictureFromFileL(BitmapStore(), EMbmWordBordern, EMbmWordBordernm, CEikCommandButtonBase::EFirst);
   259 		iBorderPresent = aBordersPresent;
   260 		button->Picture()->DrawNow();
   261 		}
   262 	}
   263 
   264 
   265 void CWordAppUi::UpdateFileNameLabelL()
   266 // Update the label text on both the toolbar and toolband filename controls
   267 //
   268 	{
   269 	CEikFileNameLabel* label = STATIC_CAST(CEikFileNameLabel*, iEikonEnv->AppUiFactory()->ToolBar()->ControlOrNull(EWordCmdFileName));
   270 	if(label != NULL)
   271 		{
   272 		label->UpdateL();
   273 		label->DrawNow();
   274 		}
   275 	label = STATIC_CAST(CEikFileNameLabel*, iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordCmdFileName));
   276 	if (!iContainerAppUi)
   277 		label->UpdateL();
   278 	label->DrawNow();
   279 	}
   280 
   281 
   282 //
   283 // class CWordToolBarUpdate
   284 //
   285 
   286 CWordToolBarUpdate* CWordToolBarUpdate::NewL(CWordAppUi& aAppUi)
   287 // Create a new idle object.
   288 	{
   289 	CWordToolBarUpdate* self=new(ELeave) CWordToolBarUpdate(aAppUi);
   290 	CActiveScheduler::Add(self);
   291 	return(self);
   292 	}
   293 
   294 CWordToolBarUpdate::CWordToolBarUpdate(CWordAppUi& aAppUi)
   295 // Constructor.
   296 	: CActive(EActivePriorityDefault), iAppUi(aAppUi)
   297 	{
   298 	iCount=(TInt)(CWordAppUi::EStyleName);
   299 	}
   300 
   301 CWordToolBarUpdate::~CWordToolBarUpdate()
   302 // Destructor.
   303 	{
   304 	Cancel();
   305 	}
   306 
   307 void CWordToolBarUpdate::Start(TUpdateType aUpdateType)
   308 // Start the object.
   309 	{
   310 	if (aUpdateType==EFullUpdate)
   311 		{
   312 		iCount=(TInt)(CWordAppUi::EStyleName);
   313 		iUpdateType=EFullUpdate;
   314 		}
   315 	else
   316 		{
   317 		if (iUpdateType==ECharFormatUpdate)
   318 			iCount=(TInt)(CWordAppUi::EFontName);
   319 		else
   320 			{
   321 			if (iCount>(TInt)(CWordAppUi::EBorder))
   322 				{
   323 				iCount=(TInt)(CWordAppUi::EFontName);
   324 				iUpdateType=ECharFormatUpdate;
   325 				}
   326 			else
   327 				iCount=Min((TInt)(CWordAppUi::EFontName),iCount);
   328 			}
   329 		}
   330 	if (IsActive())
   331 		return;
   332 	TRequestStatus* pS=(&iStatus);
   333 	User::RequestComplete(pS,0);
   334 	SetActive();
   335 	}
   336 
   337 void CWordToolBarUpdate::RunL()
   338 // Called when nothing of a higher priority can be scheduled.
   339 	{
   340 	if (!STATIC_CAST(CEikonEnv*, iAppUi.iCoeEnv)->AppUiFactory()->ToolBand()->IsVisible())
   341 		return;
   342 	switch(iCount)
   343 		{
   344 	case CWordAppUi::EStyleName:
   345 		iAppUi.UpdateStyleButtonL();
   346 		break;
   347 	case CWordAppUi::EFontName:
   348 		{
   349 		//
   350 		// Get the current character format
   351 		TCharFormat format;
   352 		TCharFormatMask mask;
   353 		const TCursorSelection selection=iAppUi.iRichEd->Selection();
   354 		iAppUi.Text()->GetCharFormat(format,mask,selection.LowerPos(),selection.Length());
   355 		//
   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;
   361 		//
   362 		// Update the font name button
   363 		TBuf<KMaxTypefaceNameLength> typefaceName;
   364 		typefaceName=format.iFontSpec.iTypeface.iName;
   365 		iAppUi.UpdateToolBandFontNameButtonL(typefaceName);
   366 		break;
   367 		}
   368 	case CWordAppUi::EFontHeight:
   369 		iAppUi.UpdateToolBandFontHeightButtonL(iFontHeightInTwips);
   370 		break;
   371 	case CWordAppUi::EBold:
   372 		iAppUi.UpdateToolBandButton(EEikCmdFontBold,iStrokeWeight==EStrokeWeightBold? CEikButtonBase::ESet : CEikButtonBase::EClear);
   373 		break;
   374 	case CWordAppUi::EItalic:
   375 		iAppUi.UpdateToolBandButton(EEikCmdFontItalic,iPosture==EPostureItalic? CEikButtonBase::ESet : CEikButtonBase::EClear);
   376 		break;
   377 	case CWordAppUi::EUnderline:
   378 		iAppUi.UpdateToolBandButton(EEikCmdFontUnderline,iUnderline==EUnderlineOn? CEikButtonBase::ESet : CEikButtonBase::EClear);
   379 		break;
   380 	case CWordAppUi::EAlignment:
   381 		{
   382 		RTmParFormatLayer format;
   383 		TInt run_length;
   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();
   388 		format.Close();
   389 		iAppUi.UpdateAlignButtonL(alignment);
   390 		break;
   391 		}
   392 	case CWordAppUi::EBullet:
   393 		iAppUi.UpdateToolBandButton(EWordButtonBullets,iBulletPresent ? CEikButtonBase::ESet : CEikButtonBase::EClear);
   394 		break;
   395 	case CWordAppUi::EBorder:
   396 		iAppUi.UpdateBorderButtonL(iBordersPresent);
   397 		break;
   398 		};
   399 	++iCount;
   400 	if ((iUpdateType==EFullUpdate && iCount<=(TInt)(CWordAppUi::EBorder)) ||
   401 		(iUpdateType==ECharFormatUpdate && iCount<=(TInt)(CWordAppUi::EUnderline)))
   402 		{
   403 		TRequestStatus* pS=(&iStatus);
   404 		User::RequestComplete(pS,0);
   405 		SetActive();
   406 		}
   407 	}
   408 
   409 void CWordToolBarUpdate::DoCancel()
   410 // Cancel
   411 	{
   412 	}