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.
30 #include <clock.h> // RMessageWindow::EMaxTextLength
32 #include <techview/eikmnbut.h>
33 #include <techview/eikbtpan.h>
34 #include <techview/eiklbbut.h>
35 #include <techview/eikdlgtb.h>
36 #include <techview/eiktxlbx.h>
37 #include <techview/eiktxlbm.h>
39 #include <techview/eikrted.h>
40 #include <techview/eikchkbx.h>
41 #include <techview/eikbutb.h>
42 #include <techview/eikfontd.h>
43 #include <techview/eikparad.h>
44 #include <techview/eiktabdg.h>
46 #include <techview/eikon.rsg>
47 #include <techview/eikclb.h>
48 #include <techview/eikclbd.h>
49 #include <techview/eikbtgpc.h>
59 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
60 #include "txtfmlyr_internal.h"
63 const TInt KNormalIndex=1;
64 const TInt KMaxStyleHotKeyDescription=20;
65 const TInt KDescriptionGranularity=100;
66 const TInt KStyleColumnSpacerWidth=5;
67 const TUint KNoHotkey=0;
70 { EDesLeftMargin=EAttLeftMargin,
107 TWordStyleGalleryData::TWordStyleGalleryData(CRichText& aText,CStyleList& aStyleList,CStyleShortCutList& aHotKeyList,
108 TChar& aNormalStyleHotKey,CPrintSetup& aPrintSetup,TBool& aApplyStyle,const TCursorSelection& aSelection,
109 MUnifiedEditor& aEditor):
111 iStyleList(aStyleList),
112 iHotKeyList(aHotKeyList),
113 iNormalStyleHotKey(aNormalStyleHotKey),
114 iPrintSetup(aPrintSetup),
115 iApplyStyle(aApplyStyle),
116 iSelection(aSelection),
122 CWordStyleGallery::CWordStyleGallery(TWordStyleGalleryData& aData)
127 CWordStyleGallery::~CWordStyleGallery()
129 delete iStyleNameKeyList;
130 delete iStyleNameList;
131 delete iStyleDescriptor;
134 void CWordStyleGallery::ConstructL()
136 iStyleNameList=new(ELeave) CDesCArrayFlat(4);
137 iStyleNameKeyList=new(ELeave) CDesCArrayFlat(4);
140 CWordStyleGallery* CWordStyleGallery::NewLC(TWordStyleGalleryData& aData)
142 CWordStyleGallery* self = new (ELeave) CWordStyleGallery(aData);
143 CleanupStack::PushL(self);
148 CWordStyleGallery* CWordStyleGallery::NewL(TWordStyleGalleryData& aData)
150 CWordStyleGallery* self = CWordStyleGallery::NewLC(aData);
151 CleanupStack::Pop(self);
155 void CWordStyleGallery::StyleDescriptionL(TInt aIndex)
157 TParagraphStyleName name=(*iStyleNameList)[aIndex];
158 TInt index=iData.iStyleList.IndexByName(name);
159 const CParaFormatLayer* layer=(index==KErrNotFound)
160 ? iData.iText.GlobalParaFormatLayer()
161 : iData.iStyleList.At(index).iStyle;
166 void CWordStyleGallery::FillBufferL(const CParaFormatLayer& aParaFormatLayer)
168 CEikGlobalTextEditor* edwin=(CEikGlobalTextEditor*)Control(EWordCidStyleInfo);
169 TCharFormat charFormat;
170 TCharFormatMask charMask;
171 CParaFormat* paraFormat=CParaFormat::NewLC();
172 TParaFormatMask paraMask;
175 iCurrentDescription=HBufC::NewL(KDescriptionGranularity);
176 TPtr buf=iCurrentDescription->Des();
177 TBool isNormalStyle=(aParaFormatLayer.Type()==KNormalParagraphStyleUid);
180 const CParagraphStyle* flayer=REINTERPRET_CAST(const CParagraphStyle*,aParaFormatLayer.SenseBase());
181 TUid type=flayer->Type();
182 if (type==KNormalParagraphStyleUid)
183 buf.Append(iNormalName);
185 buf.Append(flayer->iName);
190 iData.iText.GlobalCharFormatLayer()->Sense(charFormat,charMask);
192 REINTERPRET_CAST(const CParagraphStyle&,aParaFormatLayer).CharFormatLayer()->Sense(charFormat,charMask);
193 aParaFormatLayer.SenseL(paraFormat,paraMask);
195 if (!charMask.IsNull())
197 if (charMask.AttribIsSet(EAttFontTypeface))
198 DoAppendDescriptionL(charFormat.iFontSpec.iTypeface.iName);
199 if (charMask.AttribIsSet(EAttFontHeight))
201 TInt height=charFormat.iFontSpec.iHeight;
202 height=(height+10)/20;
206 iCoeEnv->ReadResource(unit,R_WORD_FONT_UNITS);
208 DoAppendDescriptionL(num);
210 if (charMask.AttribIsSet(EAttFontPosture))
212 if (charFormat.iFontSpec.iFontStyle.Posture()==EPostureItalic)
213 DoAppendDescriptionL((*iStyleDescriptor)[EDesItalic]);
215 if (charMask.AttribIsSet(EAttFontStrokeWeight))
217 if (charFormat.iFontSpec.iFontStyle.StrokeWeight()==EStrokeWeightBold)
218 DoAppendDescriptionL((*iStyleDescriptor)[EDesBold]);
220 if (charMask.AttribIsSet(EAttFontPrintPos))
222 TFontPrintPosition pos=charFormat.iFontSpec.iFontStyle.PrintPosition();
225 case EPrintPosSuperscript:
226 DoAppendDescriptionL((*iStyleDescriptor)[EDesSuperscript]);
228 case EPrintPosSubscript:
229 DoAppendDescriptionL((*iStyleDescriptor)[EDesSubscript]);
235 if (charMask.AttribIsSet(EAttFontUnderline))
237 if (charFormat.iFontPresentation.iUnderline==EUnderlineOn)
238 DoAppendDescriptionL((*iStyleDescriptor)[EDesUnderline]);
240 if (charMask.AttribIsSet(EAttFontStrikethrough))
242 if (charFormat.iFontPresentation.iStrikethrough==EStrikethroughOn)
243 DoAppendDescriptionL((*iStyleDescriptor)[EDesStrikethrough]);
246 if (!paraMask.IsNull())
248 AppendDescriptionL(EAttLeftMargin,paraMask);
249 AppendDescriptionL(EAttRightMargin,paraMask);
250 AppendDescriptionL(EAttIndent,paraMask);
251 if (paraMask.AttribIsSet(EAttAlignment))
252 DoAppendDescriptionL((*iStyleDescriptor)[EDesLeftAlign+paraFormat->iHorizontalAlignment]);
253 AppendDescriptionL(EAttLineSpacing,paraMask);
254 AppendDescriptionL(EAttSpaceBefore,paraMask);
255 AppendDescriptionL(EAttSpaceAfter,paraMask);
256 AppendDescriptionL(EAttKeepTogether,paraMask);
257 AppendDescriptionL(EAttKeepWithNext,paraMask);
258 AppendDescriptionL(EAttStartNewPage,paraMask);
259 AppendDescriptionL(EAttWidowOrphan,paraMask);
260 AppendDescriptionL(EAttBorderMargin,paraMask);
261 AppendDescriptionL(EAttTopBorder,*paraFormat,paraMask);
262 AppendDescriptionL(EAttBottomBorder,*paraFormat,paraMask);
263 AppendDescriptionL(EAttLeftBorder,*paraFormat,paraMask);
264 AppendDescriptionL(EAttRightBorder,*paraFormat,paraMask);
265 AppendDescriptionL(EAttBullet,paraMask);
266 AppendDescriptionL(EAttTabStop,*paraFormat,paraMask);
268 CleanupStack::PopAndDestroy(); // paraFormat
269 edwin->SetTextL(iCurrentDescription);
270 delete iCurrentDescription;
271 iCurrentDescription=NULL;
276 void CWordStyleGallery::AppendDescriptionL(TTextFormatAttribute aAttribute,const CParaFormat& aFormat,const TParaFormatMask& aMask)
278 if (aMask.AttribIsSet(aAttribute) &&
279 aFormat.ParaBorder((CParaFormat::TParaBorderSide)(aAttribute-EAttTopBorder)).iLineStyle!=TParaBorder::ENullLineStyle)
281 DoAppendDescriptionL((*iStyleDescriptor)[(TDescriptor)aAttribute]);
286 void CWordStyleGallery::AppendDescriptionL(TTextFormatAttribute aAttribute,const TParaFormatMask& aMask)
288 if (aMask.AttribIsSet(aAttribute))
289 DoAppendDescriptionL((*iStyleDescriptor)[(TDescriptor)aAttribute]);
293 void CWordStyleGallery::DoAppendDescriptionL(const TDesC& aText)
295 TInt newLength=iCurrentDescription->Length()+aText.Length();
296 if (iCurrentDescription->Length()>0)
297 newLength+=2; // add 2 characters for the separator.
298 if (newLength>iCurrentDescription->Des().MaxLength())
300 TInt alloc=KDescriptionGranularity*((newLength+KDescriptionGranularity-1)/KDescriptionGranularity);
301 iCurrentDescription=iCurrentDescription->ReAllocL(alloc);
303 TPtr ptr=iCurrentDescription->Des();
305 ptr.Append(_L(", "));
309 void CWordStyleGallery::DrawEdwinL()
311 CEikGlobalTextEditor* edwin=(CEikGlobalTextEditor*)Control(EWordCidStyleInfo);
312 TViewYPosQualifier yPosQualifier;
313 yPosQualifier.SetMakeLineFullyVisible();
314 edwin->TextView()->HandleGlobalChangeL(yPosQualifier); // !! Reconsider this
318 void CWordStyleGallery::PreLayoutDynInitL()
320 DoCalcColumnWidthsL();
324 void CWordStyleGallery::PostLayoutDynInitL()
326 DoCalcColumnWidthsL();
327 iStyleDescriptor=iCoeEnv->ReadDesCArrayResourceL(R_WORD_STYLE_GALLERY_DESCRIPTIONS);
329 iCoeEnv->ReadResource(iNormalName , R_WORD_NORMAL);
330 iCoeEnv->ReadResource(iHotKey , R_WORD_HOTKEY);
332 iStyleNameList->Reset();
333 iStyleNameList->AppendL(iNormalName);
336 TInt keycount=iData.iHotKeyList.Count();
338 const CParaFormatLayer* style=iData.iText.ParagraphStyle(styleChange,iData.iSelection.LowerPos(),iData.iSelection.Length());
339 TInt count=iData.iStyleList.Count();
340 for (TInt i=0;i<count;i++)
341 iStyleNameList->AppendL(iData.iStyleList.At(i).iStyle->iName);
342 iStyleNameList->Sort();
343 TUid id=style->Type();
344 for (TInt k=0;k<iStyleNameList->Count();k++)
346 if (id==KNormalParagraphStyleUid)
348 if (iNormalName==(*iStyleNameList)[k])
354 else if(((CParagraphStyle*)style)->iName==(*iStyleNameList)[k])
361 // Make sure all styles have a hot key, even if it's not assigned
362 // since any pasted styles will be missing hot key info
365 if (keycount < count)
368 TInt keysToAdd = count-keycount;
370 for (idx=0; idx<keysToAdd; idx++)
371 iData.iHotKeyList.AppendL(KNoHotkey);
374 else if ( keycount > count )
376 //too many, they should be the same so remove extras
378 for (idx=keycount-1; idx>=count; idx--)
379 iData.iHotKeyList.Delete(idx);
383 ListBox()->CreateScrollBarFrameL();
384 ListBox()->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
385 ListBox()->Model()->SetItemTextArray(iStyleNameKeyList);
386 ListBox()->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
387 ListBox()->HandleItemAdditionL();
388 SetListBoxCurrentItem(EWordCidStyleNameList,pos);
391 CEikGlobalTextEditor* edwin=(CEikGlobalTextEditor*)Control(EWordCidStyleInfo);
392 CCharFormatLayer* clayer=CONST_CAST(CCharFormatLayer*,(edwin->GlobalText())->GlobalCharFormatLayer());
393 CParaFormatLayer* player=CONST_CAST(CParaFormatLayer*,(edwin->GlobalText())->GlobalParaFormatLayer());
395 TCharFormatMask defaultCharFormatMask;
396 TCharFormat defaultCharFormat;
397 TInt fontAttributes=TTypeface::EProportional;
398 defaultCharFormat.iFontSpec.iTypeface.SetAttributes(fontAttributes);
399 defaultCharFormat.iFontSpec.iHeight=160;
401 defaultCharFormatMask.SetAttrib(EAttFontHeight);
402 defaultCharFormatMask.SetAttrib(EAttFontTypeface);
403 clayer->SetL(defaultCharFormat,defaultCharFormatMask);
406 TParaFormatMask pMask;
407 pFormat.iLineSpacingInTwips=160;
408 pMask.SetAttrib(EAttLineSpacing);
409 player->SetL(&pFormat,pMask);
411 StyleDescriptionL(pos);
412 SetLineNonFocusing(EWordCidStyleInfo);
416 void CWordStyleGallery::MergeArraysL()
418 iStyleNameKeyList->Reset();
419 TInt count=iStyleNameList->Count();
421 for (TInt ii=0;ii<count;ii++)
425 CEikColumnListBox* CWordStyleGallery::ListBox() const
427 return STATIC_CAST(CEikColumnListBox*,Control(EWordCidStyleNameList));
430 void CWordStyleGallery::DoCalcColumnWidthsL()
432 CColumnListBoxData* columnData = ListBox()->ItemDrawer()->ColumnData();
436 font = iEikonEnv->NormalFont();
437 columnData->SetColumnFontL(0, font);
438 columnData->SetColumnAlignmentL(0, CGraphicsContext::ELeft);
441 columnData->SetColumnWidthPixelL(1, KStyleColumnSpacerWidth);
444 font = iEikonEnv->LegendFont();
445 columnData->SetColumnFontL(2, font);
446 TBuf<KMaxStyleHotKeyDescription> hotkey;
447 iCoeEnv->ReadResource(hotkey, R_WORD_HOTKEY);
448 TInt width2 = font->TextWidthInPixels(hotkey) + font->MaxCharWidthInPixels();
449 columnData->SetColumnWidthPixelL(2, width2);
450 columnData->SetColumnAlignmentL(2, CGraphicsContext::ELeft);
453 TInt width0 = ListBox()->View()->ViewRect().Width() - KStyleColumnSpacerWidth - width2 - CEikScrollBar::DefaultScrollBarBreadth(); // only works if called from PostLayout...
454 columnData->SetColumnWidthPixelL(0, width0);
457 void CWordStyleGallery::SetDeleteButton()
459 TInt index = ListBoxCurrentItem(EWordCidStyleNameList);
460 TBool dimmed = EFalse;
461 if (iNormalName == (*iStyleNameList)[index])
465 CParagraphStyle* paraStyle = iData.iStyleList.PtrByName((*iStyleNameList)[index])->iStyle;
466 TUid type = paraStyle->Type();
467 dimmed = (type == KSystemParagraphStyleUid);
469 ButtonGroupContainer().DimCommand(EEikBidDelete, dimmed);
472 TBool CWordStyleGallery::OkToExitL(TInt aButtonId)
476 case EWordCidAddStyle:
477 case EWordCidModifyStyle:
482 if (ButtonGroupContainer().IsCommandDimmed(EEikBidDelete))
484 TInt index = ListBoxCurrentItem(EWordCidStyleNameList);
485 TParagraphStyleName name = (*iStyleNameList)[index];
487 TBuf<RMessageWindow::EMaxTextLength> title;
488 TBuf<RMessageWindow::EMaxTextLength> res;
489 iCoeEnv->ReadResource(res, R_WORD_DELETE_STYLE_TITLE);
490 title.Format(res, &name);
492 if (iEikonEnv->QueryWinL(title, _L("")))
493 {// Can never delete the normal style
494 CParagraphStyle* paraStyle = iData.iStyleList.PtrByName(name)->iStyle;
495 TInt offset = iData.iStyleList.IndexByPtr(paraStyle);
496 __ASSERT_ALWAYS(offset >= 0, Panic(EWordGalleryInvalidStyle));
497 iData.iText.NotifyStyleDeletedL(paraStyle);
498 iData.iStyleList.Remove(paraStyle);
499 iStyleNameList->Delete(index);
500 iStyleNameKeyList->Delete(index);
501 iData.iHotKeyList.Delete(offset);
503 if (index == iStyleNameList->Count())
504 index = index-KNormalIndex;
505 ListBox()->SetCurrentItemIndex(index);
506 ListBox()->UpdateScrollBarsL(); //don't have to this.listbox should provide Handledeleteitem method
507 ListBox()->ScrollToMakeItemVisible(index);
508 ListBox()->DrawNow();
509 SetTextForCancelButtonL();
510 iData.iApplyStyle = ETrue;
513 StyleDescriptionL(index);
518 TInt index = ListBoxCurrentItem(EWordCidStyleNameList);
519 MUnifiedEditor::MStyleSupport* style_support = iData.iEditor.StyleSupport();
522 TPtrC styleName = (*iStyleNameList)[index];
523 // normal style name will not be recognised by the editor object,
524 // as it is our own invention. A null descriptor should be used.
526 if (styleName == iNormalName)
527 styleName.Set(nullDes);
528 style_support->SetStyleL(iData.iSelection.LowerPos(), iData.iSelection.Length(), styleName);
530 iData.iApplyStyle=ETrue;
537 void CWordStyleGallery::HandleControlStateChangeL(TInt aControlId)
539 if (aControlId==EWordCidStyleNameList)
541 TInt index=ListBoxCurrentItem(EWordCidStyleNameList);
542 StyleDescriptionL(index);
547 void CWordStyleGallery::StyleL(TInt aControlId)
549 TInt index=ListBoxCurrentItem(EWordCidStyleNameList);
550 CParagraphStyle* paraStyle=NULL;
551 CEikDialog* dialog=NULL;
553 TChar newHotkey=KNoHotkey;
554 if (aControlId==EWordCidAddStyle)
556 paraStyle=CParagraphStyle::NewL(*(iData.iText.GlobalParaFormatLayer()),*(iData.iText.GlobalCharFormatLayer()));
557 dialog=new(ELeave) CWordStyleFormatDialog(iNormalName,iData.iNormalStyleHotKey,iData.iStyleList,
558 aControlId,iData.iText,&iData.iPrintSetup,iData.iHotKeyList,newHotkey,paraStyle);
562 if ((*iStyleNameList)[index]==iNormalName)
565 dialog=new(ELeave) CWordStyleFormatDialog(iNormalName,iData.iNormalStyleHotKey,iData.iStyleList,
566 aControlId,iData.iText,&iData.iPrintSetup,iData.iHotKeyList,newHotkey,NULL,normal);
570 paraStyle=iData.iStyleList.PtrByName((*iStyleNameList)[index])->iStyle;
571 dialog=new(ELeave) CWordStyleFormatDialog(iNormalName,iData.iNormalStyleHotKey,iData.iStyleList,
572 aControlId,iData.iText,&iData.iPrintSetup,iData.iHotKeyList,newHotkey,paraStyle);
575 newHotkey=iData.iNormalStyleHotKey;
578 TInt ii=iData.iStyleList.IndexByPtr(paraStyle);
579 __ASSERT_DEBUG(ii!=KErrNotFound,Panic(EStyleIntegrityError));
580 newHotkey=iData.iHotKeyList[ii];
584 if (dialog->ExecuteLD(R_WORD_DIALOG_STYLE_FORMAT))
586 SetTextForCancelButtonL();
587 // remove the hotkey from any old style if it has been re-assigned
588 if (newHotkey==iData.iNormalStyleHotKey)
589 iData.iNormalStyleHotKey=0;
592 TInt hotkeyCount=iData.iHotKeyList.Count();
593 for (TInt ii=0;ii<hotkeyCount;ii++)
595 if (newHotkey==iData.iHotKeyList[ii] && newHotkey!=KNoHotkey)
597 iData.iHotKeyList[ii]=0;
603 if (aControlId==EWordCidAddStyle)
605 RParagraphStyleInfo styleSet(paraStyle);
606 iData.iStyleList.AppendL(&styleSet);
610 iStyleNameList->Delete(index);
611 iStyleNameKeyList->Delete(index);
614 iStyleNameList->AppendL(iNormalName);
616 iStyleNameList->AppendL(paraStyle->iName);
617 iStyleNameList->Sort();
619 TParagraphStyleName name=(normal) ? iNormalName : paraStyle->iName;
620 for (TInt ii=0;ii<iStyleNameList->Count();ii++)
622 if (name==(*iStyleNameList)[ii])
629 if (aControlId==EWordCidAddStyle)
630 iData.iHotKeyList.AppendL(newHotkey);
634 iData.iNormalStyleHotKey=newHotkey;
637 CParagraphStyle* style=iData.iStyleList.PtrByName((*iStyleNameList)[index])->iStyle;
638 TInt offset=iData.iStyleList.IndexByPtr(style);
639 iData.iHotKeyList[offset]=newHotkey;
643 ListBox()->HandleItemAdditionL();
644 ListBox()->SetCurrentItemIndexAndDraw(index);
645 StyleDescriptionL(index);
650 if (aControlId==EWordCidAddStyle)
655 void CWordStyleGallery::AppendL(TInt aIndex)
658 name = (*iStyleNameList)[aIndex];
660 // truncate name if necessary
661 CColumnListBoxData* columnData = ListBox()->ItemDrawer()->ColumnData();
662 TInt columnWidth = columnData->ColumnWidthPixel(0);
663 const CFont* columnFont = columnData->ColumnFont(0);
664 if (columnFont->TextWidthInPixels(name) > columnWidth)
665 TextUtils::ClipToFit(name, *columnFont, columnWidth);
667 TChar key = iData.iNormalStyleHotKey;
668 if (name != iNormalName)
670 CParagraphStyle* pp = iData.iStyleList.PtrByName(name)->iStyle;
671 TInt index = iData.iStyleList.IndexByPtr(pp);
672 key = iData.iHotKeyList[index];
676 name.Append(KColumnListSeparator);
677 name.Append(KColumnListSeparator); // one for empty spacer column
678 name.Append(iHotKey);
680 name.Append(KColumnListSeparator);
682 iStyleNameKeyList->AppendL(name);
685 void CWordStyleGallery::SetTextForCancelButtonL()
688 iCoeEnv->ReadResource(buf, R_WORD_CLOSE);
689 const TInt pos = ButtonGroupContainer().PositionById(EEikBidCancel);
690 ButtonGroupContainer().SetCommandL(pos, EEikBidCancel, buf);
691 iData.iApplyStyle = ETrue;
694 ///////////////////Add Modify button dialogs//////////////////////
696 CWordStyleFormatDialog::CWordStyleFormatDialog(const TParagraphStyleName& aNormalName,const TChar aNormalStyleHotkey,const CStyleList& aStyleList,const TInt aButton,CRichText& aText,CPrintSetup* aPrintSetup,CArrayFix<TChar>& aHotKeyList,TChar& aChar,CParagraphStyle* aParagraphStyle,TBool aNormalStyle)
698 iStyleList(aStyleList),
701 iParagraphStyle(aParagraphStyle),
702 iNormalStyle(aNormalStyle),
703 iPrintSetup(aPrintSetup),
704 iHotKeyList(&aHotKeyList),
705 iNormalStyleHotkey(aNormalStyleHotkey),
706 iNormalName(aNormalName),
709 if (aParagraphStyle) iOutline = aParagraphStyle->OutlineLevel();
713 CWordStyleFormatDialog::~CWordStyleFormatDialog()
718 void CWordStyleFormatDialog::PreLayoutDynInitL()
721 // Dynamically change the title of this dialog as appropriate
722 TInt id = (iButton == EWordCidAddStyle)?
723 R_WORD_STYLEFORMAT_TITLE_ADD : R_WORD_STYLEFORMAT_TITLE_MODIFY;
724 if (id == R_WORD_STYLEFORMAT_TITLE_ADD)
729 iCoeEnv->ReadResource(buf,R_WORD_STYLEFORMAT_TITLE_MODIFY);
730 TBuf<24+KMaxParagraphStyleName> title; // 56
731 TParagraphStyleName name;
732 name = (iNormalStyle)? iNormalName : iParagraphStyle->iName;
733 title.Format(buf,&name);
737 TParaFormatMask paraMask;
738 CParaFormat* paraFormat=CParaFormat::NewLC();
739 ButtonGroupContainer().ButtonById(EWordCidFormatList)->
740 SetButtonLayout(CEikCommandButton::ETextLeftPictureRight);
743 TParagraphStyleName name;
744 iCoeEnv->ReadResource(name , R_WORD_NORMAL);
745 SetEdwinTextL(EWordCidStyleName,&name);
746 SetLineDimmedNow(EWordCidStyleName,ETrue);
747 SetLineDimmedNow(EWordCidOutline,ETrue);
748 iText->GlobalParaFormatLayer()->SenseL(paraFormat,paraMask);
752 SetEdwinTextL(EWordCidStyleName,&iParagraphStyle->iName);
753 TUid type=iParagraphStyle->Type();
754 if (type==KSystemParagraphStyleUid)
755 SetLineDimmedNow(EWordCidStyleName,ETrue);
756 iParagraphStyle->SenseL(paraFormat,paraMask);
759 if (iButton==EWordCidModifyStyle)
761 CEikCharEditor* editor=(CEikCharEditor*)Control(EWordCidHotKey);
762 editor->SetChar(iChar);
765 CEikButtonBase::TState state;
766 state=(paraFormat->iBullet)? CEikButtonBase::ESet : CEikButtonBase::EClear ;
767 SetCheckBoxState(EWordCidBullet,state);
769 // Set values for Outline level
771 SetNumberEditorValue(EWordCidOutline,iOutline);
773 CleanupStack::PopAndDestroy();
777 TBool CWordStyleFormatDialog::OkToExitL(TInt aButtonId)
779 if (aButtonId == EWordCidFormatList)
781 CEikLabeledButton* labelButton = STATIC_CAST(CEikLabeledButton*,ButtonGroupContainer().ControlOrNull(EWordCidFormatList));
782 if (labelButton != NULL)
784 CEikMenuButton* menuButton = STATIC_CAST(CEikMenuButton*, labelButton->Button());
785 menuButton->LaunchPopupMenuL(this);
789 if (aButtonId == EEikBidOk)
791 TParagraphStyleName name;
792 GetEdwinText(name,EWordCidStyleName);
795 iEikonEnv->InfoMsg(R_WORD_NOSTYLENAME);
801 iOutline = NumberEditorValue(EWordCidOutline);
802 iParagraphStyle->SetOutlineLevel(iOutline);
806 // check for normal name as well
807 TParagraphStyleName normalName;
808 iCoeEnv->ReadResource(normalName , R_WORD_NORMAL);
809 // you cannot modify names of the built in styles
810 if (iButton == EWordCidModifyStyle)
816 TUid type = iParagraphStyle->Type();
817 if (type == KSystemParagraphStyleUid)
819 else // userdefined style
820 { // now check the style list to see if the specified style already exists
821 CStyleList* styleList = iText->StyleList();
822 for (TInt i = 0; i < styleList->Count(); i++)
824 if ((name == (*styleList)[i].iStyle->iName) || (name == normalName))
826 if (name != iParagraphStyle->iName)
828 iEikonEnv->InfoMsg(R_WORD_STYLENAMEEXISTS);
838 CStyleList* list = iText->StyleList();
839 for (TInt i = 0; i < list->Count(); i++)
840 if ((name == (*list)[i].iStyle->iName) || (name == normalName))
842 iEikonEnv->InfoMsg(R_WORD_STYLENAMEEXISTS);
846 GetEdwinText(iParagraphStyle->iName, EWordCidStyleName);
851 SEikControlInfo CWordStyleFormatDialog::CreateCustomControlL(TInt aControlType)
853 SEikControlInfo info;
854 info.iTrailerTextId=0;
856 if (aControlType==EWordCtStyleShortcutKeyEditor)
857 info.iControl=new(ELeave) CWordStyleHotKeyEditor(this);
863 void CWordStyleFormatDialog::HandleControlStateChangeL(TInt aControlId)
865 if (aControlId==EWordCidBullet)
867 if (aControlId==EWordCidHotKey)
868 iChar = ((CEikCharEditor*)Control(EWordCidHotKey))->GetChar();
872 void CWordStyleFormatDialog::HandleInteractionRefused(TInt aControlId)
874 if (aControlId==EWordCidOutline)
875 iEikonEnv->InfoMsg(R_WORD_NORMAL_OUTLINE);
877 iEikonEnv->InfoMsg(R_EIK_TBUF_NOT_AVAILABLE);
881 TBool CWordStyleFormatDialog::ValidateHotkey(TKeyEvent& aKeyEvent)
882 // return false if the hotkey is invalid
883 // otherwise set aKeyEvent to the hotkey I have validated (ie uppercase it)
885 // check that the key is a valid character
886 TChar hotkey=aKeyEvent.iCode;
887 if (!hotkey.IsAlphaDigit())
889 iEikonEnv->InfoMsg(R_WORD_HOTKEY_INVALID);
893 // upper-case the key
896 // check that it isn't already in use
897 HotkeyConflict(hotkey);
899 // set the hotkey and return
900 aKeyEvent.iCode = hotkey;
905 TBool CWordStyleFormatDialog::HotkeyConflict(TChar aHotkey)
907 TBool hotkeyConflict=EFalse;
909 if (aHotkey==iNormalStyleHotkey)
910 hotkeyConflict=ETrue;
913 TInt hotkeyCount=iHotKeyList->Count();
914 for (index=0;index<hotkeyCount;index++)
916 if (aHotkey==(*iHotKeyList)[index])
918 hotkeyConflict=ETrue;
926 //there isnt an entry in the stylelist
927 if (index >iStyleList.Count() )
928 hotkeyConflict=EFalse;
934 iCoeEnv->ReadResource(fmtString,R_WORD_HOTKEYEXISTS);
935 TParagraphStyleName name=(index>=0)
936 ? iStyleList.At(index).iStyle->iName
938 msg.Format(fmtString,&name);
939 iEikonEnv->InfoMsg(msg);
943 return hotkeyConflict;
947 void CWordStyleFormatDialog::SetBulletL()
949 TParaFormatMask paraMask;
950 CParaFormat* paraFormat=CParaFormat::NewLC();
952 iText->GlobalParaFormatLayer()->SenseL(paraFormat,paraMask);
954 iParagraphStyle->SenseL(paraFormat,paraMask);
955 delete paraFormat->iBullet;
957 if(((CEikCheckBox*)Control(EWordCidBullet))->State()==CEikButtonBase::EClear)
959 paraFormat->iBullet=NULL;
960 paraFormat->iIndentInTwips=0;
961 paraMask.ClearAttrib(EAttBullet);
962 paraMask.ClearAttrib(EAttIndent);
966 paraMask.SetAttrib(EAttBullet);
967 paraMask.SetAttrib(EAttIndent);
968 TBullet* bullet=new(ELeave) TBullet;
970 CreateDefaultBulletL();
972 paraFormat->iBullet=bullet;
973 if (iBullet->iHangingIndent)
974 paraFormat->iIndentInTwips=283; // about 1/2cm - completely arbitrary value !!
976 paraFormat->iIndentInTwips=0;
979 ((CParaFormatLayer*)iText->GlobalParaFormatLayer())->SetL(paraFormat,paraMask);
981 iParagraphStyle->SetL(paraFormat,paraMask);
982 TViewYPosQualifier yPosQ;
983 yPosQ.SetMakeLineFullyVisible();
984 CleanupStack::PopAndDestroy();
987 void CWordStyleFormatDialog::CreateDefaultBulletL()
989 iBullet=new(ELeave) TBullet;
990 iBullet->iCharacterCode=0x2022;
991 iBullet->iHeightInTwips=iEikonEnv->NormalFont()->FontSpecInTwips().iHeight;
992 iBullet->iTypeface.iName=_L("Swiss");
995 void CWordStyleFormatDialog::ProcessCommandL(TInt aCommand)
999 case EEikCmdFontChange:
1002 case EEikCmdParaIndent:
1003 case EEikCmdParaSpacing:
1004 case EEikCmdParaBorder:
1005 case EEikCmdParaTabs:
1006 case EEikCmdParaAlign:
1007 RunDialogL((TStyleFormatDialog)aCommand);
1009 case EWordCmdFormatBullet:
1010 RunSelectBulletDialogL();
1015 CParaFormatLayer* CWordStyleFormatDialog::GetParaLayerAndFormattingL(CParaFormat& aFormat,TParaFormatMask& aMask)
1018 CParaFormatLayer* layer=(iNormalStyle)
1019 ? CONST_CAST(CParaFormatLayer*,iText->GlobalParaFormatLayer())
1021 DoGetParaFormatL(aFormat,aMask,*layer);
1026 void CWordStyleFormatDialog::DoGetParaFormatL(CParaFormat& aFormat,TParaFormatMask& aMask,const CParaFormatLayer& aLayer)
1029 aLayer.SenseEffectiveL(&aFormat);
1030 aLayer.SenseL(&aFormat,aMask);
1034 void CWordStyleFormatDialog::RunSelectBulletDialogL()
1037 CreateDefaultBulletL();
1038 CParaFormat* paraFormat=CParaFormat::NewLC();
1039 TParaFormatMask paraMask;
1040 TCharFormat charFormat;
1041 TCharFormatMask charMask;
1042 // TCharFormatMask charUndeterminedMask;
1045 iText->GlobalParaFormatLayer()->SenseL(paraFormat,paraMask);
1046 iText->GlobalCharFormatLayer()->Sense(charFormat,charMask);
1050 iParagraphStyle->SenseEffectiveL(paraFormat);
1051 iParagraphStyle->CharFormatLayer()->SenseEffective(charFormat);
1053 TRgb backColor=paraFormat->iFillColor;
1054 if (paraMask.AttribIsSet(EAttFillColor))
1055 backColor=KRgbWhite; // what else could be done ???
1056 CEikDialog* dialog=new(ELeave) CWordBulletDialog(iBullet,backColor,NULL,charFormat.iFontSpec.iTypeface.iName);
1057 if (dialog->ExecuteLD(R_WORD_DIALOG_BULLET))
1059 SetCheckBoxState(EWordCidBullet,CEikButtonBase::ESet);
1062 CleanupStack::PopAndDestroy();
1066 void CWordStyleFormatDialog::RunDialogL(TStyleFormatDialog aFunction)
1068 TParaFormatMask mask;
1069 TParaFormatMask undeterminedMask; // always NULL for these calls
1070 CParaFormat* format=CParaFormat::NewLC(); // !! could use 1 on the stack for some
1071 CParaFormatLayer* layer=GetParaLayerAndFormattingL(*format,mask);
1072 // CEikDialog* dialog=NULL;
1075 case EIndentsDialog:
1078 TPageSpec pageSpec=iPrintSetup->PrinterDevice()->CurrentPageSpecInTwips();
1079 TInt width=pageSpec.iPortraitPageSize.iWidth;
1080 if (pageSpec.iOrientation==TPageSpec::ELandscape)
1081 width=pageSpec.iPortraitPageSize.iHeight;
1082 width-=(iPrintSetup->iPageMarginsInTwips.iMargins.iLeft+iPrintSetup->iPageMarginsInTwips.iMargins.iRight);
1083 if (aFunction==ETabsDialog)
1085 (void)CEikTabsDialog::RunDlgLD(format, mask, undeterminedMask, width);
1089 (void)CEikIndentDialog::RunDlgLD(format, mask, undeterminedMask, width);
1093 case EBordersDialog:
1094 (void)CEikBorderDialog::RunDlgLD(format, mask, undeterminedMask);
1096 case EAlignmentDialog:
1097 (void)CEikAlignDialog::RunDlgLD(format,mask,undeterminedMask);
1099 case ELineSpacingDialog:
1100 (void)CEikSpaceDialog::RunDlgLD(format,mask,undeterminedMask);
1103 layer->SetL(format,mask);
1104 CleanupStack::PopAndDestroy(); // format
1108 void CWordStyleFormatDialog::RunFontDialogL()
1110 TCharFormat charFormat;
1111 TCharFormatMask charMask;
1112 CCharFormatLayer* charLayer=NULL;
1115 charLayer=CONST_CAST(CCharFormatLayer*,iText->GlobalCharFormatLayer());
1116 charLayer->SenseEffective(charFormat); // used to seed the dialog
1117 charLayer->Sense(charFormat,charMask); // gets the mask
1121 charLayer=iParagraphStyle->CharFormatLayer();
1122 charLayer->SenseEffective(charFormat);
1123 charLayer->Sense(charFormat,charMask);
1125 if (!CEikFontDialog::RunDlgLD(charFormat, charMask, EGulNoSymbolFonts, iCoeEnv->ScreenDevice()))
1127 charLayer->SetL(charFormat,charMask);
1130 void CWordStyleFormatDialog::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/)
1136 // class CWordStyleHotKeyEditor
1139 CWordStyleHotKeyEditor::CWordStyleHotKeyEditor(MWordHotkeyValidator* aValidator)
1140 :iValidator(aValidator)
1144 TKeyResponse CWordStyleHotKeyEditor::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
1146 if (aType!=EEventKey)
1147 return EKeyWasNotConsumed;
1149 TChar hotkey=aKeyEvent.iCode;
1150 if (hotkey==EKeyUpArrow || hotkey==EKeyDownArrow || hotkey==EKeyLeftArrow || hotkey==EKeyRightArrow)
1151 return EKeyWasNotConsumed;
1153 TKeyEvent event=aKeyEvent;
1154 if (!iValidator->ValidateHotkey(event))
1155 return EKeyWasConsumed;
1157 return CEikCharEditor::OfferKeyEventL(event,aType);