Update contrib.
2 * Copyright (c) 2004-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.
15 * TTranspEditor test source file. A base set of classes, neeeded for transparent editors
16 * functionality testing, is defined here.
17 * It is an "APP" test, where you can run TTranspEditor test application and check how the
18 * trransparency/opaque drawing works. Currently you may see the effect of opaque drawing
19 * applied on texts, pictures, selections.
36 #include "TTranspEditor.h"
37 #include "TTranspEditor.hrh"
38 #include <ttranspeditor.rsg>
40 const TUid KAppUid = {0x13579ACE};
42 ////////////////////////////////////////////////////////////////////////////////////////////
44 //CTestPicture's instances can be inserted and displayed into the transparent text view,
47 CTestPicture* CTestPicture::NewL()
49 CTestPicture* self = new (ELeave) CTestPicture;
50 CleanupStack::PushL(self);
52 CleanupStack::Pop(self);
56 CTestPicture::~CTestPicture()
61 CTestPicture::CTestPicture()
65 void CTestPicture::ConstructL()
67 _LIT(KDataMbmFile, "z:\\system\\data\\TTrEdData.mbm");
68 iBitmap = new (ELeave) CFbsBitmap;
69 User::LeaveIfError(iBitmap->Load(KDataMbmFile, 0));
72 void CTestPicture::Draw(CGraphicsContext& aGc, const TPoint&, const TRect& aRc, MGraphicsDeviceMap*) const
74 aGc.DrawBitmap(aRc, iBitmap, aRc);
77 void CTestPicture::ExternalizeL(RWriteStream&) const
81 void CTestPicture::GetOriginalSizeInTwips(TSize& aSize) const
83 aSize = iBitmap->SizeInTwips();
86 TInt CTestPicture::ScaleFactorWidth() const
88 return CPicture::ScaleFactorWidth() * 6;
91 TInt CTestPicture::ScaleFactorHeight() const
93 return CPicture::ScaleFactorHeight() * 6;
96 ////////////////////////////////////////////////////////////////////////////////////////////
99 CApaDocument* CTranspEditorApp::CreateDocumentL()
101 return new (ELeave) CTranspEditorDoc(*this);
104 TUid CTranspEditorApp::AppDllUid() const
109 ////////////////////////////////////////////////////////////////////////////////////////////
111 //It is used to create and display a background bitmap, needed for asserting opaque drawing
114 CTranspEditorView1* CTranspEditorView1::NewL()
116 CTranspEditorView1* self = new (ELeave) CTranspEditorView1;
117 CleanupStack::PushL(self);
119 CleanupStack::Pop(self);
123 CTranspEditorView1::~CTranspEditorView1()
128 void CTranspEditorView1::ContructL()
130 _LIT(KDilbertMbmFile, "z:\\system\\data\\TTrEdDilbert.mbm");
131 iBitmap = new (ELeave) CFbsBitmap;
132 User::LeaveIfError(iBitmap->Load(KDilbertMbmFile, 0));
135 TSize size = iEikonEnv->ScreenDevice()->SizeInPixels();
136 const TRect KViewRect(size);
141 void CTranspEditorView1::Draw(const TRect&) const
143 CWindowGc& gc = SystemGc();
145 TRect rc2(rc.iTl.iX + 1, rc.iTl.iY + 1, rc.iBr.iX - 1, rc.iBr.iY - 1);
149 TRgb cl(0xFF, 0x50, 0x00);
153 gc.DrawBitmap(rc2, iBitmap);
156 /////////////////////////////////////////////////////////////////////////////////////////////
158 //Transparent text view.
160 CTranspEditorView2* CTranspEditorView2::NewL()
162 CTranspEditorView2* self = new (ELeave) CTranspEditorView2;
163 CleanupStack::PushL(self);
165 CleanupStack::Pop(self);
169 CTranspEditorView2::~CTranspEditorView2()
176 //Correspond to EAppCmdInsertText user interface command.
177 //Insert a text chunk into the transparent text view.
178 void CTranspEditorView2::InsertTextL()
180 _LIT(KText, "ABC123");
181 iRichText->InsertL(iRichText->DocumentLength(), KText);
183 TViewYPosQualifier a1;
185 a1.SetMakeLineFullyVisible();
186 iTextView->HandleGlobalChangeL(a1);
189 //Correspond to EAppCmdSwitchOpaque user interface command.
190 //Switch on/off opaque drawing mode.
191 void CTranspEditorView2::SwitchOpaque()
194 iTextView->SetOpaque(iOpaque);
198 //Correspond to EAppCmdSwitchSelect user interface command.
199 //Switch on/off text selection.
200 void CTranspEditorView2::SwitchSelectL()
205 TTmDocPosSpec docPosSpec(10, TTmDocPosSpec::ELeftToRight);
207 TBool res = iTextView->FindDocPosL(docPosSpec, posInfo);
210 TCursorSelection sel(posInfo.iDocPos.iPos, 0);
211 iTextView->SetSelectionL(sel);
217 iTextView->ClearSelectionL();
222 //Correspond to EAppCmdInsertPicture user interface command.
223 //Create and insert a picture into the transparent text view.
224 void CTranspEditorView2::InsertPictureL()
226 CTestPicture* pic = CTestPicture::NewL();
227 CleanupStack::PushL(pic);
230 pic->GetOriginalSizeInTwips(size);
232 TPictureHeader pictheader;
233 pictheader.iSize = size;
234 pictheader.iPicture = pic;
236 iRichText->InsertL(iRichText->DocumentLength(), pictheader);
237 CleanupStack::Pop(pic);
239 TViewYPosQualifier a1;
241 a1.SetMakeLineFullyVisible();
242 iTextView->HandleGlobalChangeL(a1);
245 //Correspond to EAppCmdSetCharFormat user interface command.
246 //Change the format of the selected text.
247 void CTranspEditorView2::SetCharFormatL()
249 TCharFormat charFormat;
250 TCharFormatMask charFormatMask;
251 charFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
252 charFormatMask.SetAttrib(EAttFontPosture);
253 TCursorSelection select = iTextView->Selection();
254 if(select.Length() != 0)
256 iRichText->ApplyCharFormatL(charFormat, charFormatMask, select.LowerPos(), select.Length());
257 iTextView->HandleRangeFormatChangeL(select);
261 iRichText->SetInsertCharFormatL(charFormat, charFormatMask, select.iCursorPos);
265 //Construct a transparent text view, which is displayed on top of the background bitmap,
266 //which makes the transparency effect very well visible.
267 void CTranspEditorView2::ContructL()
270 TSize size = iEikonEnv->ScreenDevice()->SizeInPixels();
271 const TRect KViewRect(15, 15, size.iWidth - 15, size.iHeight - 15);
274 iRichText = CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(), iEikonEnv->SystemCharFormatLayerL());
275 iLayout = CTextLayout::NewL(iRichText, KViewRect.Width() - 2);
279 rc.Move(-rc.iTl.iX + 1, -rc.iTl.iY + 1);
280 iTextView = CTextView::NewL(iLayout,
282 iEikonEnv->ScreenDevice(),
283 iEikonEnv->ScreenDevice(),
285 &iEikonEnv->RootWin(),
286 &iEikonEnv->WsSession());
288 iTextView->EnablePictureFrameL(ETrue);
289 const TRgb KTransparencyColor(85, 85, 85);
290 Window().SetTransparencyFactor(KTransparencyColor);
295 void CTranspEditorView2::Draw(const TRect&) const
297 CWindowGc& gc = SystemGc();
299 TRect rc2(rc.iTl.iX + 1, rc.iTl.iY + 1, rc.iBr.iX - 1, rc.iBr.iY - 1);
303 const TRgb KPenColor(0x00, 0x00, 0xFF);
304 gc.SetPenColor(KPenColor);
307 TRAPD(err, iTextView->DrawL(rc2));
310 SystemGc().Clear(rc2);
311 iEikonEnv->NotifyIdleErrorWhileRedrawing(err);
315 ////////////////////////////////////////////////////////////////////////////////////////////
318 CTranspEditorDoc::CTranspEditorDoc(CEikApplication& aApp) :
323 CEikAppUi* CTranspEditorDoc::CreateAppUiL()
325 return new (ELeave) CTranspEditorUi;
328 ////////////////////////////////////////////////////////////////////////////////////////////
331 void CTranspEditorUi::ConstructL()
335 iTranspEditorView1 = CTranspEditorView1::NewL();
336 AddToStackL(iTranspEditorView1);
338 iTranspEditorView2 = CTranspEditorView2::NewL();
339 AddToStackL(iTranspEditorView2);
342 CTranspEditorUi::~CTranspEditorUi()
344 RemoveFromStack(iTranspEditorView2);
345 delete iTranspEditorView2;
347 RemoveFromStack(iTranspEditorView1);
348 delete iTranspEditorView1;
351 void CTranspEditorUi::HandleCommandL(TInt aCommand)
356 CBaActiveScheduler::Exit();
358 case EAppCmdInsertText:
359 iTranspEditorView2->InsertTextL();
361 case EAppCmdSwitchOpaque:
362 iTranspEditorView2->SwitchOpaque();
364 case EAppCmdSwitchSelect:
365 iTranspEditorView2->SwitchSelectL();
367 case EAppCmdInsertPicture:
368 iTranspEditorView2->InsertPictureL();
370 case EAppCmdSetCharFormat:
371 iTranspEditorView2->SetCharFormatL();
378 ////////////////////////////////////////////////////////////////////////////////////////////
381 static CApaApplication* NewApplication()
383 return new CTranspEditorApp;
388 return EikStart::RunApplication(&NewApplication);