os/textandloc/textrendering/word/SRC/WPDIALGS.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 <frmvis.h>
    20 
    21 #include <prninf.h>
    22 #include <prnsetup.h>
    23 
    24 #include <badesca.h>
    25 #include <bamatch.h>
    26 
    27 #include <e32std.h>
    28 
    29 #include <coeutils.h>
    30 
    31 #include <eikenv.h>
    32 #include <eikfctry.h>
    33 #include <techview/eikchlst.h>
    34 #include <techview/eikfprev.h>
    35 #include <techview/eikbtpan.h>
    36 #include <techview/eikcmbut.h>
    37 #include <techview/eikchkbx.h>
    38 #include <techview/eikfpne.h>
    39 #include <techview/eikcfdlg.h>
    40 #include <techview/eikfsel.h>
    41 #include <techview/eikprtdg.h>
    42 #include <techview/eikinfo.h>
    43 #include <techview/eikon.rsg>
    44 #include <techview/eikfsel.h>
    45 #include <eikfutil.h>
    46 #include <techview/eikdclbm.h>
    47 #include <techview/eikfbrow.h>
    48 #include <techview/eikufsel.h>
    49 #include <techview/eiklbbut.h>
    50 #include <techview/eikchmap.h>
    51 #include <techview/eikbtgpc.h>
    52 
    53 #include "WPOUTLNE.H"
    54 #include "WPDIALGS.H"
    55 #include "WPPANIC.H"
    56 #include "wpresources.h"
    57 #include "WORD.HRH"
    58 #include <word.rsg>
    59 #include "WPMAIN.H"
    60 
    61 const TInt KShortErrorMessageLength = 64;
    62 const TInt KMaxDisplayedFullNameLen	= 35;
    63 
    64 //
    65 // class CWordBulletDialog
    66 //
    67 
    68 CWordBulletDialog::CWordBulletDialog(TBullet* aBullet,TRgb aBackColor, CPrinterDevice* ,const TDesC& aFontName)
    69 	:iFontName(aFontName)
    70 	{
    71 	iWordBullet=aBullet;
    72 	iBullet=*aBullet;
    73 	iBackColor=aBackColor;
    74 	}
    75 
    76 CWordBulletDialog::~CWordBulletDialog()
    77 	{
    78 	}
    79 
    80 void CWordBulletDialog::PreLayoutDynInitL()
    81 	{
    82 	CEikCharMap* charMap = STATIC_CAST(CEikCharMap*, Control(EWordCidBulletCharMap));
    83 	charMap->SetChar(iBullet.iCharacterCode);
    84 	charMap->DrawNow();
    85 	}
    86 
    87 void CWordBulletDialog::HandleControlStateChangeL(TInt aControlId)
    88 	{
    89 	if (aControlId == EWordCidBulletCharMap)
    90 		{
    91 		const TUint charCode = STATIC_CAST(CEikCharMap*, Control(EWordCidBulletCharMap))->GetChar();
    92 		iBullet.iCharacterCode = (TText)charCode;
    93 		}
    94 	}
    95 
    96 TBool CWordBulletDialog::OkToExitL(TInt aButtonId)
    97 	{
    98 	if (aButtonId==EWordCidFormatBullet)
    99 		{
   100 		CEikDialog* dialog=new(ELeave) CWordBulletFormatDialog(&iBullet,iBackColor,NULL,iFontName);
   101 		dialog->ExecuteLD(R_WORD_DIALOG_FORMAT_BULLET);
   102 		return EFalse;
   103 		}
   104 	*iWordBullet=iBullet;
   105 	return ETrue;
   106 	}
   107 
   108 //
   109 // class CWordBulletFormatDialog
   110 //
   111 
   112 CWordBulletFormatDialog::CWordBulletFormatDialog(TBullet* aBullet,TRgb aBackColor, CPrinterDevice* ,const TDesC& aFontName)
   113 	:iFontName(aFontName)
   114 	{
   115 	iWordBullet=aBullet;
   116 	iBullet=*aBullet;
   117 	iBackColor=aBackColor;
   118 	}
   119 
   120 CWordBulletFormatDialog::~CWordBulletFormatDialog()
   121 	{
   122 	delete iTwipsList;
   123 	}
   124 
   125 SEikControlInfo CWordBulletFormatDialog::CreateCustomControlL(TInt aControlType)
   126 	{
   127 	SEikControlInfo info;
   128     info.iControl=NULL;
   129 	info.iTrailerTextId=0;
   130 	info.iFlags=EEikControlIsNonFocusing;
   131 	if (aControlType==EWordCtBulletPreviewLabel)
   132 		info.iControl=new(ELeave) CWordBulletPreviewLabel;
   133 	return info;
   134 	}
   135 
   136 void CWordBulletFormatDialog::PreLayoutDynInitL()
   137 	{
   138 	CWordBulletPreviewLabel* label=(CWordBulletPreviewLabel*)Control(EWordCidBulletCharacter);
   139 	label->iBrushColor=iBackColor;
   140 	label->iTextColor=iBullet.iColor;
   141 	TFontSpec fontSpec;
   142 	fontSpec.iHeight=iBullet.iHeightInTwips;
   143 	fontSpec.iTypeface.iName=_L("Swiss");
   144 	label->SetFontSpecL(fontSpec);
   145 	SetPreviewLabelL(iBullet.iCharacterCode);
   146 	SetGraySelectorColor(EWordCidBulletColor,iBullet.iColor);
   147 	iTwipsList=new(ELeave) CArrayFixFlat<TInt>(4);
   148 	iPointsList=new(ELeave) CDesCArrayFlat(4);
   149 	FontUtils::GetAvailableHeightsInTwipsAndPointsL(*iCoeEnv->ScreenDevice(),iFontName,*iTwipsList,*iPointsList);
   150 	CEikChoiceList* chlst=(CEikChoiceList*)Control(EWordCidBulletHeight);
   151 	chlst->SetArrayL(iPointsList);
   152 	chlst->SetArrayExternalOwnership(EFalse);
   153 	const TInt index = FontUtils::IndexOfNearestHeight(*iTwipsList, iBullet.iHeightInTwips);
   154 	chlst->SetCurrentItem(index);
   155 	CEikButtonBase::TState state=(iBullet.iHangingIndent? CEikButtonBase::ESet : CEikButtonBase::EClear);
   156 	SetCheckBoxState(EWordCidBulletIndent,state);
   157 	}
   158 
   159 void CWordBulletFormatDialog::SetPreviewLabelL(TUint aCharCode)
   160 	{
   161 	TChar bullet(aCharCode);
   162 	TBuf<1> buf;
   163 	buf.Append(bullet);
   164 	SetLabelL(EWordCidBulletCharacter,buf);
   165 	}
   166 
   167 void CWordBulletFormatDialog::HandleControlStateChangeL(TInt aControlId)
   168 	{
   169 	switch (aControlId)
   170 		{
   171 	case EWordCidBulletColor:
   172 		{
   173 		const TRgb color=GraySelectorColor(EWordCidBulletColor);
   174 		CWordBulletPreviewLabel* label=(CWordBulletPreviewLabel*)Control(EWordCidBulletCharacter);
   175 		label->iTextColor=color;
   176 		label->DrawNow();
   177 		iBullet.iColor=color;
   178 		break;
   179 		}
   180 	case EWordCidBulletHeight:
   181 		{
   182 		const TInt height=(*iTwipsList)[ChoiceListCurrentItem(EWordCidBulletHeight)];
   183 		iBullet.iHeightInTwips=height;
   184 		TFontSpec fontSpec;
   185 		CWordBulletPreviewLabel* label=(CWordBulletPreviewLabel*)Control(EWordCidBulletCharacter);
   186 		fontSpec.iHeight=height;
   187 		fontSpec.iTypeface.iName=_L("Swiss");
   188 		label->SetFontSpecL(fontSpec);
   189 		label->DrawNow();
   190 		break;
   191 		}
   192 	case EWordCidBulletIndent:
   193 		iBullet.iHangingIndent=(CheckBoxState(EWordCidBulletIndent)==CEikButtonBase::ESet);
   194 		break;
   195 	default:
   196 		;
   197 		}
   198 	}
   199 
   200 TBool CWordBulletFormatDialog::OkToExitL(TInt /*aButtonId*/)
   201 	{
   202 	*iWordBullet=iBullet;
   203 	return ETrue;
   204 	}
   205 
   206 //
   207 // class CWordBulletPreviewLabel
   208 //
   209 
   210 CWordBulletPreviewLabel::CWordBulletPreviewLabel()
   211 	{}
   212 
   213 CWordBulletPreviewLabel::~CWordBulletPreviewLabel()
   214 	{
   215 	iCoeEnv->ReleaseScreenFont(CONST_CAST(CFont*,iPrevFont));
   216 	}
   217 
   218 void CWordBulletPreviewLabel::SetFontSpecL(TFontSpec& aFontSpec)
   219 	{
   220 	iCoeEnv->ReleaseScreenFont(CONST_CAST(CFont*,iPrevFont));
   221 	iPrevFont=iCoeEnv->CreateScreenFontL(aFontSpec);
   222 	}
   223 
   224 TSize CWordBulletPreviewLabel::MinimumSize()
   225 	{
   226 	return TSize(40,40); // an attempt to make label big enough for most font heights
   227 	}
   228 
   229 void CWordBulletPreviewLabel::Draw(const TRect& /*aRect*/) const
   230 	{
   231 	CWindowGc& gc=SystemGc();
   232 	gc.UseFont(iPrevFont);
   233 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
   234 	gc.SetBrushColor(iBrushColor);
   235 	gc.SetPenStyle(CGraphicsContext::ESolidPen);
   236 	gc.SetPenColor(iTextColor);
   237 	const TInt ascent=iPrevFont->AscentInPixels();
   238 	const TRect rect(Rect());
   239 	const TInt baselineOffset=ascent+((rect.Height()-ascent)/2);
   240 	gc.DrawText(*iText,rect,baselineOffset,CGraphicsContext::ECenter);
   241 	}
   242 
   243 //
   244 // class CWordGoToDialog
   245 //
   246 
   247 CWordGoToDialog::CWordGoToDialog(TInt aMaxPages, TInt* aCurrentPage)
   248     {
   249 	iMaxPages=aMaxPages;
   250 	iCurrentPage=aCurrentPage;
   251     }
   252     
   253 void CWordGoToDialog::PreLayoutDynInitL()
   254 	{
   255 	SetNumberEditorMinAndMax(EWordCidPageNumber,1,iMaxPages);
   256 	SetNumberEditorValue(EWordCidPageNumber,*iCurrentPage);
   257 
   258 	TBuf<10> buf;
   259 	buf.Num(iMaxPages);
   260     SetLabelL(EWordCidPages, buf);
   261 	}
   262 
   263 TBool CWordGoToDialog::OkToExitL(TInt /*aButtonId*/)
   264 	{
   265 	*iCurrentPage=NumberEditorValue(EWordCidPageNumber);
   266 	return(ETrue);
   267 	}
   268 
   269 //
   270 //	CWordViewPreferencesDialog
   271 //
   272 
   273 CWordViewPreferencesDialog::CWordViewPreferencesDialog(TNonPrintingCharVisibility& aVisibility)
   274 	: iVisibility(aVisibility)
   275 	{}
   276 
   277 void CWordViewPreferencesDialog::PreLayoutDynInitL()
   278 	{
   279 	CEikButtonBase::TState button=CEikButtonBase::EClear;
   280 	//tabs
   281 	button=(iVisibility.TabsVisible())?CEikButtonBase::ESet : CEikButtonBase::EClear;	
   282 	SetCheckBoxState(EWordCidTab,button);
   283 	//spaces
   284 	button=(iVisibility.SpacesVisible())?CEikButtonBase::ESet : CEikButtonBase::EClear;		
   285 	SetCheckBoxState(EWordCidSpaces,button);
   286 	//paragraph ends
   287 	button=(iVisibility.ParagraphDelimitersVisible())?CEikButtonBase::ESet : CEikButtonBase::EClear;		
   288 	SetCheckBoxState(EWordCidParaEnds,button);
   289 	//hyphens
   290 	button=(iVisibility.NonBreakingHyphensVisible())?CEikButtonBase::ESet : CEikButtonBase::EClear;		
   291 	SetCheckBoxState(EWordCidHardHyphens,button);
   292 	//line breaks
   293 	button=(iVisibility.LineBreaksVisible())?CEikButtonBase::ESet : CEikButtonBase::EClear;		
   294 	SetCheckBoxState(EWordCidForcedLineBreaks,button);
   295 	//nonbreaking spaces
   296 	button=(iVisibility.NonBreakingSpacesVisible())?CEikButtonBase::ESet : CEikButtonBase::EClear;		
   297 	SetCheckBoxState(EWordCidNonBreakingSpace,button);
   298 	}
   299 
   300 void CWordViewPreferencesDialog::WordSetCheckBoxState(CEikButtonBase::TState aState)
   301 	{
   302 	SetCheckBoxState(EWordCidTab,aState);
   303 	SetCheckBoxState(EWordCidSpaces,aState);
   304 	SetCheckBoxState(EWordCidParaEnds,aState);
   305 	SetCheckBoxState(EWordCidHardHyphens,aState);
   306 	SetCheckBoxState(EWordCidForcedLineBreaks,aState);
   307 	SetCheckBoxState(EWordCidNonBreakingSpace,aState);
   308 	} 												  
   309 
   310 TBool CWordViewPreferencesDialog::OkToExitL(TInt /*aButtonId*/)
   311 	{
   312 	TBool visible;
   313 	CEikButtonBase::TState button=CEikButtonBase::EClear;
   314 	//tabs
   315 	button=CheckBoxState(EWordCidTab);
   316 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   317 	iVisibility.SetTabsVisible(visible);
   318 	//spaces
   319 	button=CheckBoxState(EWordCidSpaces);
   320 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   321 	iVisibility.SetSpacesVisible(visible);
   322 	//paragraph ends
   323 	button=CheckBoxState(EWordCidParaEnds);
   324 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   325 	iVisibility.SetParagraphDelimitersVisible(visible);
   326 	//hyphens
   327 	button=CheckBoxState(EWordCidHardHyphens);
   328 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   329 	iVisibility.SetNonBreakingHyphensVisible(visible);
   330 	//line breaks
   331 	button=CheckBoxState(EWordCidForcedLineBreaks);
   332 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   333 	iVisibility.SetLineBreaksVisible(visible);
   334 	//nonbreaking spaces
   335 	button=CheckBoxState(EWordCidNonBreakingSpace);
   336 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   337 	iVisibility.SetNonBreakingSpacesVisible(visible);
   338 	//
   339 	return ETrue;
   340 	}
   341 
   342 
   343 
   344 //
   345 //	CWordObjectPreferencesDialog & Revert To Style dialog
   346 //
   347 
   348 CWordObjectPreferencesDialog::CWordObjectPreferencesDialog(TBool& aSketchAsGlass,TBool& aGraphAsGlass/*,TInt aButton*/)
   349 	: iSketchAsGlass(aSketchAsGlass),iGraphAsGlass(aGraphAsGlass)/*,iButton(aButton)*/
   350 	{}
   351 
   352 void CWordObjectPreferencesDialog::PreLayoutDynInitL()
   353 	{
   354 //	//
   355 //	// Change the dialog text as appropriate
   356 //	if (!iObjectPreferenceDialog)
   357 //		{
   358 ///		SetTitleL(R_WORD_STYLE_REVERT_TITLE);
   359 //
   360 ///		}
   361 
   362 	CEikButtonBase::TState button=CEikButtonBase::EClear;
   363 	//
   364 	// Sketch as glass
   365 	button=(iSketchAsGlass) ? CEikButtonBase::EClear : CEikButtonBase::ESet;
   366 	SetCheckBoxState(EWordCidShowSketch,button);
   367 	// graph as glass
   368 	button=(iGraphAsGlass) ? CEikButtonBase::EClear : CEikButtonBase::ESet;
   369 	SetCheckBoxState(EWordCidShowGraph,button);
   370 	}
   371 
   372 void CWordObjectPreferencesDialog::WordSetCheckBoxState(CEikButtonBase::TState aState)
   373 	{
   374 	SetCheckBoxState(EWordCidShowSketch,aState);
   375 	SetCheckBoxState(EWordCidShowGraph,aState);
   376 	} 												  
   377 
   378 TBool CWordObjectPreferencesDialog::OkToExitL(TInt /*aButtonId*/)
   379 	{
   380 	TBool visible;
   381 	CEikButtonBase::TState button=CEikButtonBase::EClear;
   382 	//
   383 	// sketch as glass
   384 	button=CheckBoxState(EWordCidShowSketch);
   385 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   386 	iSketchAsGlass=!visible;
   387 	// graph as glass
   388 	button=CheckBoxState(EWordCidShowGraph);
   389 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   390 	iGraphAsGlass=!visible;
   391 	//
   392 	return ETrue;
   393 	}
   394 
   395 //
   396 //	CWordObjectPreferencesDialog & Revert To Style dialog
   397 //
   398 
   399 CWordRevertToStyleDialog::CWordRevertToStyleDialog(TBool& aSketchAsGlass,TBool& aGraphAsGlass)
   400 	: iSketchAsGlass(aSketchAsGlass),iGraphAsGlass(aGraphAsGlass)
   401 	{}
   402 
   403 void CWordRevertToStyleDialog::PreLayoutDynInitL()
   404 	{
   405 //	//
   406 //	// Change the dialog text as appropriate
   407 //	if (!iObjectPreferenceDialog)
   408 //		{
   409 ///		SetTitleL(R_WORD_STYLE_REVERT_TITLE);
   410 //
   411 ///		}
   412 
   413 	CEikButtonBase::TState button=CEikButtonBase::EClear;
   414 	//
   415 	// Sketch as glass
   416 	button=(iSketchAsGlass) ? CEikButtonBase::ESet : CEikButtonBase::EClear;
   417 	SetCheckBoxState(EWordCidRemoveChar,button);
   418 	// graph as glass
   419 	button=(iGraphAsGlass) ? CEikButtonBase::ESet : CEikButtonBase::EClear;
   420 	SetCheckBoxState(EWordCidRemovePara,button);
   421 	}
   422 
   423 void CWordRevertToStyleDialog::WordSetCheckBoxState(CEikButtonBase::TState aState)
   424 	{
   425 	SetCheckBoxState(EWordCidRemoveChar,aState);
   426 	SetCheckBoxState(EWordCidRemovePara,aState);
   427 	} 												  
   428 
   429 TBool CWordRevertToStyleDialog::OkToExitL(TInt /*aButtonId*/)
   430 	{
   431 	TBool visible;
   432 	CEikButtonBase::TState button=CEikButtonBase::EClear;
   433 	//
   434 	// sketch as glass
   435 	button=CheckBoxState(EWordCidRemoveChar);
   436 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   437 	iSketchAsGlass=visible;
   438 	// graph as glass
   439 	button=CheckBoxState(EWordCidRemovePara);
   440 	visible=button? CEikButtonBase::ESet : CEikButtonBase::EClear; 
   441 	iGraphAsGlass=visible;
   442 	//
   443 	return ETrue;
   444 	}
   445 
   446 //
   447 // Manual zoom setting dialog
   448 // 
   449 
   450 CWordTempManualZoomDialog::CWordTempManualZoomDialog(TInt& aOrigZoomFactor)
   451 	: iOrigZoomFactor(aOrigZoomFactor)
   452 	{__ASSERT_DEBUG(iOrigZoomFactor>0,Panic(EWordZeroZoomFactor));}
   453 
   454 
   455 void CWordTempManualZoomDialog::PreLayoutDynInitL()
   456 	{
   457 	// set the control with the current zoom factor
   458 	__ASSERT_DEBUG(iOrigZoomFactor>0,Panic(EWordZeroZoomFactor));
   459 	SetNumberEditorValue(EWordCidZoomSet,iOrigZoomFactor/10);
   460 	}
   461 
   462 
   463 TBool CWordTempManualZoomDialog::OkToExitL(TInt /*aButtonId*/)
   464 	{
   465 	iOrigZoomFactor=(NumberEditorValue(EWordCidZoomSet))*10;
   466 	return ETrue;
   467 	}
   468 
   469 
   470 //
   471 // Custom File Open dialog
   472 //
   473 
   474 
   475 CWordFileOpenDialog::CWordFileOpenDialog(TDes* aFileName,TBool& aReadOnly,TInt aTitleId)
   476 	: CEikFileOpenDialog(aFileName,aTitleId),
   477 	  iReadOnly(aReadOnly)
   478     {
   479 	__DECLARE_NAME(_S("CWordFileOpenDialog"));
   480     }
   481 
   482 
   483 void CWordFileOpenDialog::HandleControlStateChangeL(TInt)
   484 	{
   485 	}
   486 
   487 TBool CWordFileOpenDialog::OkToExitL(TInt aButtonId)
   488     {
   489 	if (CEikFileOpenDialog::OkToExitL(aButtonId))
   490 		{
   491 		iReadOnly=CheckBoxState(EWordCidReadOnly)==CEikButtonBase::ESet;
   492 		return ETrue;
   493 		}
   494 	else return EFalse;
   495     }
   496 
   497 //
   498 // Custom File New dialog with templates
   499 //
   500 
   501 CWordTemplateNewFileDialog::CWordTemplateNewFileDialog(TDes* aFileName, TFileName& aTemplateFileName, TUidType aUid)
   502 	: CEikFileSaveAsDialog(aFileName,NULL,R_EIK_TBUF_CREATE_NEW_FILE), iTemplateFileName(aTemplateFileName),
   503 		iUid(aUid)
   504 	{
   505 	}
   506 
   507 TBool CWordTemplateNewFileDialog::OkToExitL(TInt aButtonId)
   508 	{
   509 	if(!CEikFileSaveAsDialog::OkToExitL(aButtonId))
   510 		return EFalse;
   511 	// Check to see if the template is still there
   512 	CEikUnifiedFileNameSelector* templateFileNameSel = (CEikUnifiedFileNameSelector*) (Control(EEikCtUnifiedFileSel));
   513 	iTemplateFileName = templateFileNameSel->FullName();
   514 	if(ConeUtils::FileExists(iTemplateFileName))
   515 		return ETrue;
   516 	else
   517 		{
   518 		iEikonEnv->InfoMsg(R_WORD_TEMPLATE_NOT_AVAILABLE);
   519 		return EFalse;
   520 		}
   521 	}
   522 
   523 void CWordTemplateNewFileDialog::PreLayoutDynInitL()
   524 	{
   525 	CEikFileSaveAsDialog::PreLayoutDynInitL();
   526 	TFileName templateFileName;
   527 	TWordFilePath::GetNormalTemplateFolderName(templateFileName);
   528 	TFileName tempFileName;
   529 	TFindFile ff(iEikonEnv->FsSession());
   530 
   531 	iEikonEnv->ReadResource(tempFileName, R_WORD_NORMAL_TEMPLATE_FILE_NAME);
   532 	templateFileName.Append(tempFileName);
   533 	templateFileName[0] = 'Y';
   534 	TParsePtr parse(templateFileName);
   535 	TInt err = ff.FindByDir(parse.NameAndExt(),parse.DriveAndPath());
   536 	if(err)
   537 		{
   538 		// no normal template, search ROM for blank
   539 		TWordFilePath::GetNormalTemplateFolderName(templateFileName);
   540 		iEikonEnv->ReadResource(tempFileName, R_WORD_BLANK_TEMPLATE_FILE_NAME);
   541 		templateFileName.Append(tempFileName);
   542 		templateFileName[0] = 'Z';
   543 		TParsePtr blankParse(templateFileName);
   544 		User::LeaveIfError(ff.FindByDir(blankParse.NameAndExt(),blankParse.DriveAndPath()));
   545 		}
   546 	templateFileName = ff.File();
   547 	
   548 	CEikUnifiedFileNameSelector* templateFileNameSel = (CEikUnifiedFileNameSelector*) (Control(EEikCtUnifiedFileSel));
   549 	templateFileNameSel->SetUidType(iUid);
   550 	templateFileNameSel->SetROMIncluded(ETrue);
   551 	templateFileNameSel->SetFullNameL(templateFileName);	
   552 	}
   553 
   554 SEikControlInfo CWordTemplateNewFileDialog::CreateCustomControlL(TInt aControlType)
   555 	{
   556 	SEikControlInfo controlInfo;
   557 	controlInfo.iControl=NULL;
   558 	controlInfo.iTrailerTextId=0;
   559 	controlInfo.iFlags=0;
   560 
   561 	switch(aControlType)
   562 		{
   563 	case EWordUnifiedFileNameSelector:
   564 		{
   565 		CWordUnifiedFileSelector* newControl = new(ELeave) CWordUnifiedFileSelector();
   566 		controlInfo.iControl = newControl;
   567 		controlInfo.iFlags = EEikControlHasEars;
   568 		break;
   569 		}
   570 	default:
   571 		break;
   572 		}
   573 	return controlInfo;
   574 	}
   575 
   576 //
   577 // class CWordUnifiedFileSelector file selector with sorting
   578 // 
   579 
   580 void CWordUnifiedFileSelector::SortArray(MDesCArray* aFileNames)
   581 	{
   582 	TFileName blank;
   583 	iEikonEnv->ReadResource(blank, R_WORD_BLANK_TEMPLATE_FILE_NAME);
   584 	TInt count = aFileNames->MdcaCount();
   585 	for (TInt i = 0 ; i < count; i++)
   586 		{
   587 		if (aFileNames->MdcaPoint(i) == blank)
   588 			{
   589 			if (i == 0)
   590 				break;
   591 			CDesCArray* array = STATIC_CAST(CDesCArray*,aFileNames);
   592 			TRAPD(err,array->InsertL(0, blank)); // top
   593 			if (err == KErrNone)
   594 				{
   595 				array->Delete(++i);
   596 				}
   597 			break;
   598 			}
   599 		}
   600 	}
   601 
   602 void CWordUnifiedFileSelector::BuildFileNameArrayL(const TParse& aParse, MDesCArray* aFileNames)
   603 	{
   604 	CEikUnifiedFileNameSelector::BuildFileNameArrayL(aParse, aFileNames);
   605 	SortArray(aFileNames);
   606 	}
   607 
   608 //
   609 // class CWordDeleteTemplateDialog
   610 //
   611 
   612 CWordDeleteTemplateDialog::CWordDeleteTemplateDialog(TFileName& aTemplateFileName, TUidType aUid)
   613 	: iTemplateFileName(aTemplateFileName), iUid(aUid)
   614 	{
   615 	}
   616 
   617 TBool CWordDeleteTemplateDialog::OkToExitL(TInt /*aButtonId*/)
   618 	{
   619 	CEikUnifiedFileNameSelector* templateFileNameSel = STATIC_CAST(CEikUnifiedFileNameSelector*,(Control(EEikCtUnifiedFileSel)));
   620 	iTemplateFileName = templateFileNameSel->FullName();
   621 	
   622 	if (!iTemplateFileName.Length())
   623 		return ETrue;
   624 
   625 	// Confirm this is what the user really wants
   626 	TParsePtrC parse(iTemplateFileName);
   627 	TFileName confirmPre;
   628 	TBuf<30> confirmPost;
   629 	iEikonEnv->ReadResource(confirmPre, R_WORD_TEMPLATE_DELETE_CONFIRMATION_PRE);
   630 	iEikonEnv->ReadResource(confirmPost, R_WORD_TEMPLATE_DELETE_CONFIRMATION_POST);
   631 	TInt gap = 60 - confirmPre.Length() - confirmPost.Length();
   632 	if (parse.NameAndExt().Length() > gap)
   633 		{
   634 		TFileName name = parse.NameAndExt();
   635 		confirmPre.Append(name.Left(gap - 1));
   636 		confirmPre.Append((TChar)KEllipsis);
   637 		}
   638 	else
   639 		confirmPre.Append(parse.NameAndExt());
   640 	confirmPre.Append(confirmPost);
   641 	confirmPost = _L("");
   642 		
   643 	if (!iEikonEnv->QueryWinL(confirmPre, confirmPost))
   644 		iTemplateFileName = TFileName();
   645 	return ETrue;
   646 	}
   647 
   648 void CWordDeleteTemplateDialog::PreLayoutDynInitL()
   649 	{
   650 	CEikUnifiedFileNameSelector* templateFileNameSel = STATIC_CAST(CEikUnifiedFileNameSelector*,(Control(EEikCtUnifiedFileSel)));
   651 	templateFileNameSel->SetUidType(iUid);
   652 	templateFileNameSel->SetROMIncluded(EFalse);
   653 	templateFileNameSel->SetFullNameL(iTemplateFileName);
   654 	}
   655 
   656 //
   657 // class CWordSaveAsTemplateDialog
   658 //
   659 
   660 CWordSaveAsTemplateDialog::CWordSaveAsTemplateDialog(TFileName& aTemplateFileName, TUidType aUid)
   661 	: iTemplateFileName(aTemplateFileName), iUid(aUid)
   662 	{
   663 	}
   664 
   665 TBool CWordSaveAsTemplateDialog::OkToExitL(TInt /*aButtonId*/)
   666 	{
   667 	CEikFileNameEditor* templateFileNameEd = STATIC_CAST(CEikFileNameEditor*,(Control(EEikCidFileNameEd)));
   668 	CEikDriveNameSelector *driveNameSelector = STATIC_CAST(CEikDriveNameSelector*,(Control(EEikCidDriveNameSel)));
   669 	templateFileNameEd->GetFullNameL(iTemplateFileName);
   670 
   671 	TFileName drivename = driveNameSelector->FullName();
   672 	TParse parse;
   673 	User::LeaveIfError(parse.Set(drivename, &iTemplateFileName,NULL));
   674 	iTemplateFileName = parse.FullName();
   675 	TBool doNotReplaceExistingFile = EFalse;
   676 	TUint attributes = 0;
   677 	if (ConeUtils::FileExists(iTemplateFileName))
   678 		{
   679 		TBuf<32> infoDialogTitle;
   680 		iEikonEnv->ReadResource(infoDialogTitle, R_EIK_TBUF_DIALOG_TITLE_CONFIRM_FILE_REPLACE);
   681 		TBuf<KShortErrorMessageLength> formatStr;
   682 		User::LeaveIfError(iEikonEnv->FsSession().Att(iTemplateFileName, attributes));
   683 		if (attributes & KEntryAttReadOnly)
   684 			iEikonEnv->LeaveWithInfoMsg(R_EIK_TBUF_CANNOT_REPLACE_READONLY_FILE);
   685 		else
   686 			iEikonEnv->ReadResource(formatStr, R_EIK_TBUF_FILE_REPLACE_CONFIRM1);
   687 		TBuf<KMaxDisplayedFullNameLen> abbrevName;
   688 		User::LeaveIfError(EikFileUtils::Parse(iTemplateFileName));
   689 		TParsePtr parse(iTemplateFileName);
   690 		EikFileUtils::AbbreviateFileName(parse.NameAndExt(), abbrevName);
   691 		TBuf<KShortErrorMessageLength + KMaxDisplayedFullNameLen> textMsg;
   692 		textMsg.Format(formatStr, &abbrevName);
   693 		CEikDialog* infoDialog = new(ELeave) CEikInfoDialog(infoDialogTitle, textMsg,CEikInfoDialog::EIgnoreEnter);
   694 		if (!(infoDialog->ExecuteLD(R_EIK_DIALOG_SINGLE_FILE_REPLACE)))
   695 			doNotReplaceExistingFile = ETrue;
   696 		}
   697 	return !doNotReplaceExistingFile;
   698 	}
   699 
   700 void CWordSaveAsTemplateDialog::PreLayoutDynInitL()
   701 	{
   702 	TFileName templateFileName;
   703 	TWordFilePath::GetNormalTemplateFolderName(templateFileName);
   704 
   705 	CEikFileNameEditor* templateFileNameEd = STATIC_CAST(CEikFileNameEditor*,(Control(EEikCidFileNameEd)));
   706 	CEikDriveNameSelector *driveNameSelector = STATIC_CAST(CEikDriveNameSelector*,(Control(EEikCidDriveNameSel)));
   707 	
   708 	templateFileNameEd->SetFullNameL(templateFileName);
   709 	
   710 	// set drive to be system drive
   711 	templateFileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
   712 	
   713 	driveNameSelector->ShowRom(EFalse);
   714 	driveNameSelector->SetFullNameL(templateFileName);
   715 	}
   716 
   717 // Outline Dialog
   718 
   719 CWordOutlineDialog::CWordOutlineDialog(CRichText* aText, CEikEdwin* aEdWin, TInt& aNewCursorPosition)
   720 	:iText(aText), 
   721 	iEdWin(aEdWin),
   722 	iNewCursorPosition(aNewCursorPosition)
   723 {
   724 }
   725 
   726 
   727 
   728 TBool CWordOutlineDialog::OkToExitL(TInt aButtonId)
   729 	{
   730 	switch(aButtonId)
   731 		{
   732 	case EEikBidOk:
   733 		iNewCursorPosition = iOutlineNav->OutlineModel()->CurrentCharPosition();
   734 		return ETrue;
   735 	case EWordBidOpenAll:
   736 		iOutlineNav->ExpandAllItemsL();
   737 		return EFalse;
   738 	case EWordBidCloseAll:
   739 		iOutlineNav->CollapseAllItemsL();
   740 		return EFalse;
   741 	default:
   742 		return EFalse;
   743 		}
   744 	}
   745 
   746 
   747 SEikControlInfo CWordOutlineDialog::CreateCustomControlL(TInt aControlType)
   748 	{
   749 	SEikControlInfo controlInfo;
   750 	controlInfo.iControl=NULL;
   751 	controlInfo.iTrailerTextId=0;
   752 	controlInfo.iFlags=0;
   753 
   754 	COutlineHListBox* newControl;
   755 
   756 	switch(aControlType)
   757 		{
   758 	case EWordCtOutlineNav:
   759 		newControl = new(ELeave)COutlineHListBox(iText,iEdWin->CursorPos());
   760 		controlInfo.iControl = newControl;
   761 		iOutlineNav = newControl;
   762 		break;
   763 	default:
   764 		break;
   765 		}
   766 	return controlInfo;
   767 	}