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 CViewControl::~CViewControl()
00021 {
00022 delete iTextView;
00023 delete iLayout;
00024 delete iRichText;
00025 delete iCharFormatLayer;
00026 delete iParaFormatLayer;
00027 delete iBitmap;
00028 }
00029
00030 void CViewControl::UpdateModelL()
00031 {
00032
00033
00034
00035 _LIT(KText1, "To be, or not to be, that is the question; \
00036 whether 'tis nobler in the mind to suffer the \
00037 slings and arrows of outrageous fortune, or \
00038 to stand against a sea of troubles, and by \
00039 opposing end them.");
00040 _LIT(KText4,"Format band set. Num formatted lines=%d");
00041 _LIT(KText5,"Format band unset. Num formatted lines=%d");
00042 _LIT(KPathAndFile,"\\resource\\apps\\cursors.mbm");
00043 _LIT(KCDrive,"\\");
00044 _LIT(KZDrive,"Z:");
00045 _LIT(KStatus0,"Initialised - with grey fill colour");
00046 _LIT(KStatus1,"Added lots of text");
00047 _LIT(KStatus2,"Selected first paragraph");
00048 _LIT(KStatus3,"Formatted the selected text (and cancelled selection)");
00049 _LIT(KStatus6,"Set 20 pixel line cursor margin and 2 cursors");
00050 _LIT(KStatus7,"Reset the view rectangle - old wrapping still applies");
00051 _LIT(KStatus8,"Text wrapping set to new view rectangle");
00052 _LIT(KStatus9,"View rectangle and wrap width reset");
00053 _LIT(KStatus10,"Horizontal scroll left");
00054 _LIT(KStatus11,"Scrolling DOWN, blank space NOT scrolled");
00055 _LIT(KStatus12,"Back to top and horizontal scroll right");
00056 _LIT(KStatus13,"Reset();");
00057 _LIT(KStatusDefault,"(overshot!!)");
00058
00059 switch (Phase())
00060 {
00061 case 0:
00062 {
00063
00064 TCharFormat charFormat;
00065 TCharFormatMask charFormatMask;
00066 iUpdateModelDoesRedraw=ETrue;
00067
00068
00069 iParaFormatLayer=CParaFormatLayer::NewL();
00070 iCharFormatLayer=CCharFormatLayer::NewL();
00071
00072 iRichText=CRichText::NewL(iParaFormatLayer, iCharFormatLayer);
00073
00074 iViewRect=Rect();
00075 iViewRect.Shrink(3,3);
00076
00077 CWindowGc& gc=SystemGc();
00078 CBitmapDevice* device=(CBitmapDevice*) (gc.Device());
00079
00080
00081 iLayout=CTextLayout::NewL(iRichText,iViewRect.Width());
00082
00083 iTextView=CTextView::NewL(iLayout, iViewRect,
00084 device,
00085 device,
00086 &Window(),
00087 &iCoeEnv->RootWin(),
00088 &iCoeEnv->WsSession()
00089 );
00090
00091
00092 charFormatMask.SetAttrib(EAttFontHeight);
00093
00094 charFormat.iFontSpec.iHeight=200;
00095 iRichText->ApplyCharFormatL(charFormat,charFormatMask,0,0);
00096
00097 CParaFormat* paraFormat=CParaFormat::NewL();
00098 TParaFormatMask paraFormatMask;
00099 paraFormat->iFillColor=TRgb(204,204,204);
00100 paraFormatMask.SetAttrib(EAttFillColor);
00101
00102 iRichText->ApplyParaFormatL(paraFormat,paraFormatMask,0,0);
00103 iTextView->FormatTextL();
00104 iFormObserver->NotifyStatus(KStatus0);
00105 delete paraFormat;
00106 break;
00107 }
00108 case 1:
00109 {
00110
00111 iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
00112
00113 iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
00114
00115
00116 iRichText->ApplyCharFormatL(iCharFormat,iCharFormatMask, 0,0);
00117
00118
00119 for (TInt count=0;count<5;count++)
00120 {
00121 iRichText->InsertL(iRichText->DocumentLength(),KText1);
00122 iRichText->InsertL(iRichText->DocumentLength(),
00123 CEditableText::EParagraphDelimiter);
00124 };
00125 TCursorSelection selection(0, iRichText->DocumentLength());
00126
00127 iTextView->HandleInsertDeleteL(selection, 0);
00128
00129 iFormObserver->NotifyStatus(KStatus1);
00130 break;
00131 }
00132 case 2:
00133 {
00134
00135 TInt pos=1;
00136 TUint scanMask=CPlainText::EScanToUnitEnd;
00137 iRichText->ScanParas(pos,scanMask);
00138
00139
00140 iTextView->SetDocPosL(pos,ETrue);
00141 iFormObserver->NotifyStatus(KStatus2);
00142 break;
00143 }
00144 case 3:
00145 {
00146
00147 TCursorSelection cursorSelection;
00148 TCharFormat charFormat;
00149 TCharFormatMask charFormatMask;
00150
00151 charFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
00152 charFormatMask.SetAttrib(EAttFontPosture);
00153
00154 cursorSelection=iTextView->Selection();
00155 TInt lowerPos=cursorSelection.LowerPos();
00156 TInt length=cursorSelection.Length();
00157
00158 iRichText->ApplyCharFormatL(charFormat,charFormatMask,lowerPos,length);
00159 iTextView->HandleRangeFormatChangeL(cursorSelection);
00160 iTextView->CancelSelectionL();
00161 iFormObserver->NotifyStatus(KStatus3);
00162 break;
00163 }
00164 case 4:
00165 {
00166 TBuf<80> message;
00167
00168 iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
00169 iTextView->HandleGlobalChangeL();
00170 message.Format(KText4,iLayout->NumFormattedLines());
00171 iFormObserver->NotifyStatus(message);
00172 break;
00173 }
00174 case 5:
00175 {
00176 TBuf<80> message;
00177
00178
00179 iLayout->SetAmountToFormat(CTextLayout::EFFormatAllText);
00180 iTextView->HandleGlobalChangeL();
00181 message.Format(KText5,iLayout->NumFormattedLines());
00182 iFormObserver->NotifyStatus(message);
00183 break;
00184 }
00185 case 6:
00186 {
00187
00188 iTextView->SetMarginWidths(0,20);
00189 iTextView->DrawL(iViewRect);
00190
00191 iBitmap=new(ELeave) CFbsBitmap();
00192 TBufC<40> pathandfile(KPathAndFile);
00193 TParse bitmapFileName;
00194 TBufC<2> c_drive(KCDrive);
00195 TBufC<2> z_drive(KZDrive);
00196
00197 bitmapFileName.Set(pathandfile,&c_drive,NULL);
00198
00199 if (iBitmap->Load(bitmapFileName.FullName()))
00200
00201 {
00202 bitmapFileName.Set(pathandfile,&z_drive,NULL);
00203 iBitmap->Load(bitmapFileName.FullName());
00204 iTextView->SetLineCursorBitmap(iBitmap);
00205 iTextView->SetCursorVisibilityL(TCursor::EFCursorVisible,
00206 TCursor::EFCursorFlashing);
00207
00208 iFormObserver->NotifyStatus(KStatus6);
00209 }
00210 break;
00211 }
00212 case 7:
00213 {
00214
00215
00216
00217
00218 ActivateGc();
00219 SystemGc().Clear(iViewRect);
00220 DeactivateGc();
00221
00222 iViewRect.Shrink(40,40);
00223 iTextView->SetViewRect(iViewRect);
00224 iTextView->DrawL(iViewRect);
00225
00226 iFormObserver->NotifyStatus(KStatus7);
00227 break;
00228 }
00229 case 8:
00230 {
00231
00232
00233
00234 TInt labelMarginWidth;
00235 TInt lineCursorMarginWidth;
00236 iTextView->MarginWidths(labelMarginWidth,lineCursorMarginWidth);
00237 iLayout->SetWrapWidth(iViewRect.Width()-(labelMarginWidth+lineCursorMarginWidth));
00238 iLayout->ForceNoWrapping(EFalse);
00239 iTextView->HandleGlobalChangeL();
00240 iFormObserver->NotifyStatus(KStatus8);
00241 break;
00242 }
00243 case 9:
00244 {
00245
00246
00247 TInt labelMarginWidth;
00248 TInt lineCursorMarginWidth;
00249 iTextView->MarginWidths(labelMarginWidth,lineCursorMarginWidth);
00250 iViewRect.Grow(40,40);
00251
00252 iTextView->SetViewRect(iViewRect);
00253 iLayout->SetWrapWidth(iViewRect.Width()-(labelMarginWidth+lineCursorMarginWidth));
00254 iTextView->HandleGlobalChangeL();
00255 iFormObserver->NotifyStatus((KStatus9));
00256 break;
00257 }
00258 case 10:
00259
00260 iTextView->SetHorizontalScrollJump(40);
00261 iTextView->ScrollDisplayL(TCursorPosition::EFLeft,CTextLayout::EFAllowScrollingBlankSpace);
00262
00263 iFormObserver->NotifyStatus(KStatus10);
00264 break;
00265 case 11:
00266 {
00267
00268 iFormObserver->NotifyStatus(KStatus11);
00269 TInt pixelsScrolled;
00270
00271 do
00272 pixelsScrolled=iTextView->ScrollDisplayL(TCursorPosition::EFLineDown,
00273 CTextLayout::EFDisallowScrollingBlankSpace);
00274 while (pixelsScrolled);
00275 break;
00276 }
00277 case 12:
00278 {
00279
00280 iFormObserver->NotifyStatus(KStatus12);
00281 TInt pixelsScrolled;
00282 do
00283 pixelsScrolled=iTextView->ScrollDisplayL(TCursorPosition::EFLineUp);
00284 while (pixelsScrolled);
00285 iTextView->ScrollDisplayL(TCursorPosition::EFRight);
00286
00287 break;
00288 }
00289 case 13:
00290 {
00291
00292 iRichText->Reset();
00293 iTextView->FormatTextL();
00294 iTextView->DrawL(iViewRect);
00295 iFormObserver->NotifyStatus(KStatus13);
00296 break;
00297 }
00298 default:
00299 iFormObserver->NotifyStatus(KStatusDefault);
00300 break;
00301 }
00302 }
00303
00304 void CViewControl::Draw(const TRect& aRect) const
00305 {
00306
00307 CGraphicsContext& gc=SystemGc();
00308 TRect rect=Rect();
00309 gc.DrawRect(rect);
00310 rect.Shrink(1,1);
00311 gc.SetPenColor(KRgbWhite);
00312 gc.DrawRect(rect);
00313 rect.Shrink(1,1);
00314 gc.SetPenColor(KRgbBlack);
00315 gc.DrawRect(rect);
00316
00317 TInt err;
00318 TRAP(err,iTextView->DrawL(aRect));
00319 }
00320