00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "txtexamp.h"
00017
00018 #include <txtrich.h>
00019
00020 CStyleControl::~CStyleControl()
00021 {
00022 delete iTextView;
00023 delete iLayout;
00024 delete iRichText;
00025 delete iNormalCharFormatLayer;
00026 delete iNormalParaFormatLayer;
00027 }
00028
00029 void CStyleControl::CreateNormalL()
00030 {
00031
00032
00033
00034 CParaFormat* paraFormat=CParaFormat::NewLC();
00035 TParaFormatMask paraFormatMask;
00036 paraFormat->iLeftMarginInTwips=360;
00037 paraFormatMask.SetAttrib(EAttLeftMargin);
00038 paraFormat->iLineSpacingInTwips=300;
00039 paraFormatMask.SetAttrib(EAttLineSpacing);
00040
00041 iNormalParaFormatLayer=CParaFormatLayer::NewL(paraFormat,paraFormatMask);
00042 CleanupStack::PopAndDestroy();
00043 TCharFormat charFormat;
00044 TCharFormatMask charFormatMask;
00045 charFormatMask.SetAttrib(EAttFontHeight);
00046 iNormalCharFormatLayer=CCharFormatLayer::NewL(charFormat,charFormatMask);
00047 }
00048
00049 void CStyleControl::CreateStylesL()
00050 {
00051
00052
00053 _LIT(KStyle,"Warning");
00054 _LIT(KStyleTwo,"ListBullet");
00055 CParaFormat* paraFormat=CParaFormat::NewLC();
00056 TParaFormatMask paraFormatMask;
00057 TCharFormat charFormat;
00058 TCharFormatMask charFormatMask;
00059
00060 iStyleOne=CParagraphStyle::NewL(
00061 *iNormalParaFormatLayer,*iNormalCharFormatLayer);
00062
00063
00064 TParaBorder paraBorder;
00065 paraBorder.iLineStyle=TParaBorder::ESolid;
00066 paraBorder.iThickness=4;
00067 paraBorder.iColor=KRgbGray;
00068 paraBorder.iAutoColor=EFalse;
00069 paraFormat->SetParaBorderL(CParaFormat::EParaBorderTop,paraBorder);
00070 paraFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,paraBorder);
00071 paraFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,paraBorder);
00072 paraFormat->SetParaBorderL(CParaFormat::EParaBorderRight,paraBorder);
00073 paraFormatMask.SetAttrib(EAttTopBorder);
00074 paraFormatMask.SetAttrib(EAttBottomBorder);
00075 paraFormatMask.SetAttrib(EAttRightBorder);
00076 paraFormatMask.SetAttrib(EAttLeftBorder);
00077 iStyleOne->SetL(paraFormat,paraFormatMask);
00078
00079
00080 CCharFormatLayer* charStyleFormatLayer = iStyleOne->CharFormatLayer();
00081 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
00082 charFormatMask.SetAttrib(EAttFontStrokeWeight);
00083
00084 charStyleFormatLayer->SetL(charFormat,charFormatMask);
00085
00086 iStyleOne->iName=KStyle;
00087
00088
00089 paraFormat->Strip();
00090 paraFormatMask.ClearAll();
00091 iStyleTwo=CParagraphStyle::NewL(
00092 *iNormalParaFormatLayer,*iNormalCharFormatLayer);
00093 paraFormat->iBullet=new(ELeave)TBullet;
00094 paraFormat->iBullet->iHeightInTwips=480;
00095 paraFormat->iBullet->iHangingIndent=ETrue;
00096 paraFormatMask.SetAttrib(EAttBullet);
00097 iStyleTwo->SetL(paraFormat,paraFormatMask);
00098
00099 iStyleTwo->iName=KStyleTwo;
00100
00101
00102 iStyleList=CStyleList::NewL();
00103 RParagraphStyleInfo info1(iStyleOne);
00104 RParagraphStyleInfo info2(iStyleTwo);
00105 iStyleList->AppendL(&info1);
00106 iStyleList->AppendL(&info2);
00107
00108 iRichText=CRichText::NewL(iNormalParaFormatLayer,iNormalCharFormatLayer,*iStyleList);
00109 CleanupStack::PopAndDestroy();
00110 }
00111
00112 void CStyleControl::UpdateModelL()
00113 {
00114
00115
00116 _LIT(KText1,"Some text using normal style");
00117 _LIT(KText2,"Text in warning style - based on normal");
00118 _LIT(KText3,"Text in list bullet style");
00119 _LIT(KText4,"Some more text in list bullet style");
00120 _LIT(KText5,"Some text in italics");
00121 _LIT(KStatus0,"Initialised styles and view");
00122 _LIT(KStatus1,"Normal");
00123 _LIT(KStatus2,"Warning style");
00124 _LIT(KStatus3,"List bullet style");
00125 _LIT(KStatus4,"Character and paragraph formatting applied to styled text");
00126 _LIT(KStatus5,"All specific formatting removed from third paragraph");
00127 _LIT(KStatus6,"Inserted some normal text with specific formatting");
00128 _LIT(KStatus7,"Applied a style (warning) to text, retaining specific formatting");
00129 _LIT(KStatus8,"Reset();");
00130 _LIT(KStatusDefault,"(overshot!!)");
00131
00132
00133 switch (Phase())
00134 {
00135
00136 case 0:
00137 {
00138
00139 CreateNormalL();
00140
00141 CreateStylesL();
00142
00143 iViewRect=Rect();
00144 iViewRect.Shrink(3,3);
00145
00146 CWindowGc& gc=SystemGc();
00147 CBitmapDevice* device=(CBitmapDevice*) (gc.Device());
00148
00149 iLayout=CTextLayout::NewL(iRichText,iViewRect.Width());
00150
00151
00152 iTextView=CTextView::NewL(iLayout, iViewRect,
00153 device,
00154 device,
00155 &Window(),
00156 0,
00157 &iCoeEnv->WsSession()
00158 );
00159 iFormObserver->NotifyStatus(KStatus0);
00160 break;
00161 }
00162 case 1:
00163
00164 iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
00165
00166 iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
00167
00168
00169 iRichText->ApplyCharFormatL(iCharFormat,iCharFormatMask, 0,0);
00170
00171
00172 iRichText->InsertL(0,KText1);
00173 iRichText->InsertL(iRichText->DocumentLength(),
00174 CEditableText::EParagraphDelimiter);
00175 iFormObserver->NotifyStatus(KStatus1);
00176 break;
00177 case 2:
00178 {
00179
00180 TInt length;
00181 TInt startPos;
00182 iRichText->InsertL(iRichText->DocumentLength(),KText2);
00183 iRichText->InsertL(iRichText->DocumentLength(),
00184 CEditableText::EParagraphDelimiter);
00185
00186 startPos=iRichText->CharPosOfParagraph(length,1);
00187
00188 iRichText->ApplyParagraphStyleL(*iStyleList->At(0).iStyle,startPos,1,
00189 CParagraphStyle::ERetainAllSpecificFormats);
00190 iFormObserver->NotifyStatus(KStatus2);
00191 break;
00192 }
00193 case 3:
00194
00195 {
00196 TInt length;
00197 TInt startPos;
00198
00199 iRichText->InsertL(iRichText->DocumentLength(),KText3);
00200 iRichText->InsertL(iRichText->DocumentLength(),
00201 CEditableText::EParagraphDelimiter);
00202
00203 iRichText->InsertL(iRichText->DocumentLength(),KText4);
00204 iRichText->InsertL(iRichText->DocumentLength(),
00205 CEditableText::EParagraphDelimiter);
00206
00207
00208 startPos=iRichText->CharPosOfParagraph(length,2);
00209
00210
00211 iRichText->ApplyParagraphStyleL(*iStyleList->At(1).iStyle,startPos,length+1,
00212 CParagraphStyle::ERetainAllSpecificFormats);
00213 iFormObserver->NotifyStatus(KStatus3);
00214 break;
00215 }
00216 case 4:
00217
00218
00219 {
00220 TInt startPos, length;
00221
00222 startPos=iRichText->CharPosOfParagraph(length,2);
00223
00224 TCharFormat charFormat;
00225 TCharFormatMask charFormatMask;
00226 charFormat.iFontPresentation.iUnderline=EUnderlineOn;
00227 charFormatMask.SetAttrib(EAttFontUnderline);
00228
00229
00230 iRichText->ApplyCharFormatL(charFormat, charFormatMask,startPos,length-1);
00231 CParaFormat* paraFormat=CParaFormat::NewL();
00232 TParaFormatMask paraFormatMask;
00233 paraFormat->iHorizontalAlignment=CParaFormat::ERightAlign;
00234 paraFormatMask.SetAttrib(EAttAlignment);
00235
00236 iRichText->ApplyParaFormatL(paraFormat, paraFormatMask,startPos,1);
00237 iFormObserver->NotifyStatus(KStatus4);
00238 delete paraFormat;
00239 break;
00240 }
00241 case 5:
00242
00243 {
00244 TInt startPos, length;
00245 startPos=iRichText->CharPosOfParagraph(length,2);
00246
00247 iRichText->RemoveSpecificCharFormatL(startPos,length);
00248
00249 iRichText->RemoveSpecificParaFormatL(startPos,2);
00250 iFormObserver->NotifyStatus(KStatus5);
00251 break;
00252 }
00253 case 6:
00254
00255 {
00256 TCharFormat charFormat;
00257 TCharFormatMask charFormatMask;
00258 charFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
00259 charFormatMask.SetAttrib(EAttFontPosture);
00260
00261 iRichText->SetInsertCharFormatL(charFormat,charFormatMask,iRichText->DocumentLength());
00262 iRichText->InsertL(iRichText->DocumentLength(),KText5);
00263 iRichText->CancelInsertCharFormat();
00264 iRichText->InsertL(iRichText->DocumentLength(),
00265 CEditableText::EParagraphDelimiter);
00266 iFormObserver->NotifyStatus(KStatus6);
00267 break;
00268 }
00269 case 7:
00270 {
00271
00272 TInt startPos, length;
00273
00274 startPos=iRichText->CharPosOfParagraph(length,4);
00275 iRichText->ApplyParagraphStyleL(*iStyleList->At(0).iStyle,startPos,1,
00276 CParagraphStyle::ERetainAllSpecificFormats);
00277 iFormObserver->NotifyStatus(KStatus7);
00278 break;
00279 }
00280 case 8:
00281
00282 iRichText->Reset();
00283
00284 iFormObserver->NotifyStatus(KStatus8);
00285 break;
00286 default:
00287 iFormObserver->NotifyStatus(KStatusDefault);
00288 break;
00289 }
00290 }
00291
00292 void CStyleControl::Draw(const TRect& aRect) const
00293 {
00294
00295 CGraphicsContext& gc=SystemGc();
00296 TRect rect=Rect();
00297 gc.DrawRect(rect);
00298 rect.Shrink(1,1);
00299 gc.SetPenColor(KRgbWhite);
00300 gc.DrawRect(rect);
00301 rect.Shrink(1,1);
00302 gc.SetPenColor(KRgbBlack);
00303 gc.DrawRect(rect);
00304
00305 TInt err;
00306 TRAP(err,iTextView->FormatTextL());
00307 if (err) return;
00308 TRAP(err,iTextView->DrawL(aRect));
00309 }
00310