sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* TTranspEditor test source file. A base set of classes, neeeded for transparent editors
|
sl@0
|
16 |
* functionality testing, is defined here.
|
sl@0
|
17 |
* It is an "APP" test, where you can run TTranspEditor test application and check how the
|
sl@0
|
18 |
* trransparency/opaque drawing works. Currently you may see the effect of opaque drawing
|
sl@0
|
19 |
* applied on texts, pictures, selections.
|
sl@0
|
20 |
*
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
#include <coecntrl.h>
|
sl@0
|
25 |
#include <coeccntx.h>
|
sl@0
|
26 |
#include <coemain.h>
|
sl@0
|
27 |
#include <eikon.hrh>
|
sl@0
|
28 |
#include <eikappui.h>
|
sl@0
|
29 |
#include <eikapp.h>
|
sl@0
|
30 |
#include <eikdoc.h>
|
sl@0
|
31 |
#include <eikenv.h>
|
sl@0
|
32 |
#include <eikdef.h>
|
sl@0
|
33 |
#include <txtrich.h>
|
sl@0
|
34 |
#include <frmtview.h>
|
sl@0
|
35 |
#include <eikstart.h>
|
sl@0
|
36 |
#include "TTranspEditor.h"
|
sl@0
|
37 |
#include "TTranspEditor.hrh"
|
sl@0
|
38 |
#include <ttranspeditor.rsg>
|
sl@0
|
39 |
|
sl@0
|
40 |
const TUid KAppUid = {0x13579ACE};
|
sl@0
|
41 |
|
sl@0
|
42 |
////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
43 |
//Picture
|
sl@0
|
44 |
//CTestPicture's instances can be inserted and displayed into the transparent text view,
|
sl@0
|
45 |
//used in the test.
|
sl@0
|
46 |
|
sl@0
|
47 |
CTestPicture* CTestPicture::NewL()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
CTestPicture* self = new (ELeave) CTestPicture;
|
sl@0
|
50 |
CleanupStack::PushL(self);
|
sl@0
|
51 |
self->ConstructL();
|
sl@0
|
52 |
CleanupStack::Pop(self);
|
sl@0
|
53 |
return self;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
CTestPicture::~CTestPicture()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
delete iBitmap;
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
CTestPicture::CTestPicture()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
void CTestPicture::ConstructL()
|
sl@0
|
66 |
{
|
sl@0
|
67 |
_LIT(KDataMbmFile, "z:\\system\\data\\TTrEdData.mbm");
|
sl@0
|
68 |
iBitmap = new (ELeave) CFbsBitmap;
|
sl@0
|
69 |
User::LeaveIfError(iBitmap->Load(KDataMbmFile, 0));
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
void CTestPicture::Draw(CGraphicsContext& aGc, const TPoint&, const TRect& aRc, MGraphicsDeviceMap*) const
|
sl@0
|
73 |
{
|
sl@0
|
74 |
aGc.DrawBitmap(aRc, iBitmap, aRc);
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
void CTestPicture::ExternalizeL(RWriteStream&) const
|
sl@0
|
78 |
{
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
void CTestPicture::GetOriginalSizeInTwips(TSize& aSize) const
|
sl@0
|
82 |
{
|
sl@0
|
83 |
aSize = iBitmap->SizeInTwips();
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
TInt CTestPicture::ScaleFactorWidth() const
|
sl@0
|
87 |
{
|
sl@0
|
88 |
return CPicture::ScaleFactorWidth() * 6;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
TInt CTestPicture::ScaleFactorHeight() const
|
sl@0
|
92 |
{
|
sl@0
|
93 |
return CPicture::ScaleFactorHeight() * 6;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
97 |
//Application
|
sl@0
|
98 |
|
sl@0
|
99 |
CApaDocument* CTranspEditorApp::CreateDocumentL()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
return new (ELeave) CTranspEditorDoc(*this);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
TUid CTranspEditorApp::AppDllUid() const
|
sl@0
|
105 |
{
|
sl@0
|
106 |
return KAppUid;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
110 |
//View1
|
sl@0
|
111 |
//It is used to create and display a background bitmap, needed for asserting opaque drawing
|
sl@0
|
112 |
//functionality.
|
sl@0
|
113 |
|
sl@0
|
114 |
CTranspEditorView1* CTranspEditorView1::NewL()
|
sl@0
|
115 |
{
|
sl@0
|
116 |
CTranspEditorView1* self = new (ELeave) CTranspEditorView1;
|
sl@0
|
117 |
CleanupStack::PushL(self);
|
sl@0
|
118 |
self->ContructL();
|
sl@0
|
119 |
CleanupStack::Pop(self);
|
sl@0
|
120 |
return self;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
CTranspEditorView1::~CTranspEditorView1()
|
sl@0
|
124 |
{
|
sl@0
|
125 |
delete iBitmap;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
void CTranspEditorView1::ContructL()
|
sl@0
|
129 |
{
|
sl@0
|
130 |
_LIT(KDilbertMbmFile, "z:\\system\\data\\TTrEdDilbert.mbm");
|
sl@0
|
131 |
iBitmap = new (ELeave) CFbsBitmap;
|
sl@0
|
132 |
User::LeaveIfError(iBitmap->Load(KDilbertMbmFile, 0));
|
sl@0
|
133 |
|
sl@0
|
134 |
CreateWindowL();
|
sl@0
|
135 |
TSize size = iEikonEnv->ScreenDevice()->SizeInPixels();
|
sl@0
|
136 |
const TRect KViewRect(size);
|
sl@0
|
137 |
SetRect(KViewRect);
|
sl@0
|
138 |
ActivateL();
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
void CTranspEditorView1::Draw(const TRect&) const
|
sl@0
|
142 |
{
|
sl@0
|
143 |
CWindowGc& gc = SystemGc();
|
sl@0
|
144 |
TRect rc = Rect();
|
sl@0
|
145 |
TRect rc2(rc.iTl.iX + 1, rc.iTl.iY + 1, rc.iBr.iX - 1, rc.iBr.iY - 1);
|
sl@0
|
146 |
|
sl@0
|
147 |
gc.Clear();
|
sl@0
|
148 |
|
sl@0
|
149 |
TRgb cl(0xFF, 0x50, 0x00);
|
sl@0
|
150 |
gc.SetPenColor(cl);
|
sl@0
|
151 |
gc.DrawRect(rc);
|
sl@0
|
152 |
|
sl@0
|
153 |
gc.DrawBitmap(rc2, iBitmap);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
/////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
157 |
//View2
|
sl@0
|
158 |
//Transparent text view.
|
sl@0
|
159 |
|
sl@0
|
160 |
CTranspEditorView2* CTranspEditorView2::NewL()
|
sl@0
|
161 |
{
|
sl@0
|
162 |
CTranspEditorView2* self = new (ELeave) CTranspEditorView2;
|
sl@0
|
163 |
CleanupStack::PushL(self);
|
sl@0
|
164 |
self->ContructL();
|
sl@0
|
165 |
CleanupStack::Pop(self);
|
sl@0
|
166 |
return self;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
CTranspEditorView2::~CTranspEditorView2()
|
sl@0
|
170 |
{
|
sl@0
|
171 |
delete iTextView;
|
sl@0
|
172 |
delete iLayout;
|
sl@0
|
173 |
delete iRichText;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
//Correspond to EAppCmdInsertText user interface command.
|
sl@0
|
177 |
//Insert a text chunk into the transparent text view.
|
sl@0
|
178 |
void CTranspEditorView2::InsertTextL()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
_LIT(KText, "ABC123");
|
sl@0
|
181 |
iRichText->InsertL(iRichText->DocumentLength(), KText);
|
sl@0
|
182 |
|
sl@0
|
183 |
TViewYPosQualifier a1;
|
sl@0
|
184 |
a1.SetFillScreen();
|
sl@0
|
185 |
a1.SetMakeLineFullyVisible();
|
sl@0
|
186 |
iTextView->HandleGlobalChangeL(a1);
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
//Correspond to EAppCmdSwitchOpaque user interface command.
|
sl@0
|
190 |
//Switch on/off opaque drawing mode.
|
sl@0
|
191 |
void CTranspEditorView2::SwitchOpaque()
|
sl@0
|
192 |
{
|
sl@0
|
193 |
iOpaque = !iOpaque;
|
sl@0
|
194 |
iTextView->SetOpaque(iOpaque);
|
sl@0
|
195 |
DrawNow();
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
//Correspond to EAppCmdSwitchSelect user interface command.
|
sl@0
|
199 |
//Switch on/off text selection.
|
sl@0
|
200 |
void CTranspEditorView2::SwitchSelectL()
|
sl@0
|
201 |
{
|
sl@0
|
202 |
iSelect = !iSelect;
|
sl@0
|
203 |
if(iSelect)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
TTmDocPosSpec docPosSpec(10, TTmDocPosSpec::ELeftToRight);
|
sl@0
|
206 |
TTmPosInfo2 posInfo;
|
sl@0
|
207 |
TBool res = iTextView->FindDocPosL(docPosSpec, posInfo);
|
sl@0
|
208 |
if(res)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
TCursorSelection sel(posInfo.iDocPos.iPos, 0);
|
sl@0
|
211 |
iTextView->SetSelectionL(sel);
|
sl@0
|
212 |
DrawNow();
|
sl@0
|
213 |
}
|
sl@0
|
214 |
}
|
sl@0
|
215 |
else
|
sl@0
|
216 |
{
|
sl@0
|
217 |
iTextView->ClearSelectionL();
|
sl@0
|
218 |
DrawNow();
|
sl@0
|
219 |
}
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|
sl@0
|
222 |
//Correspond to EAppCmdInsertPicture user interface command.
|
sl@0
|
223 |
//Create and insert a picture into the transparent text view.
|
sl@0
|
224 |
void CTranspEditorView2::InsertPictureL()
|
sl@0
|
225 |
{
|
sl@0
|
226 |
CTestPicture* pic = CTestPicture::NewL();
|
sl@0
|
227 |
CleanupStack::PushL(pic);
|
sl@0
|
228 |
|
sl@0
|
229 |
TSize size;
|
sl@0
|
230 |
pic->GetOriginalSizeInTwips(size);
|
sl@0
|
231 |
|
sl@0
|
232 |
TPictureHeader pictheader;
|
sl@0
|
233 |
pictheader.iSize = size;
|
sl@0
|
234 |
pictheader.iPicture = pic;
|
sl@0
|
235 |
|
sl@0
|
236 |
iRichText->InsertL(iRichText->DocumentLength(), pictheader);
|
sl@0
|
237 |
CleanupStack::Pop(pic);
|
sl@0
|
238 |
|
sl@0
|
239 |
TViewYPosQualifier a1;
|
sl@0
|
240 |
a1.SetFillScreen();
|
sl@0
|
241 |
a1.SetMakeLineFullyVisible();
|
sl@0
|
242 |
iTextView->HandleGlobalChangeL(a1);
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
//Correspond to EAppCmdSetCharFormat user interface command.
|
sl@0
|
246 |
//Change the format of the selected text.
|
sl@0
|
247 |
void CTranspEditorView2::SetCharFormatL()
|
sl@0
|
248 |
{
|
sl@0
|
249 |
TCharFormat charFormat;
|
sl@0
|
250 |
TCharFormatMask charFormatMask;
|
sl@0
|
251 |
charFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
|
sl@0
|
252 |
charFormatMask.SetAttrib(EAttFontPosture);
|
sl@0
|
253 |
TCursorSelection select = iTextView->Selection();
|
sl@0
|
254 |
if(select.Length() != 0)
|
sl@0
|
255 |
{
|
sl@0
|
256 |
iRichText->ApplyCharFormatL(charFormat, charFormatMask, select.LowerPos(), select.Length());
|
sl@0
|
257 |
iTextView->HandleRangeFormatChangeL(select);
|
sl@0
|
258 |
}
|
sl@0
|
259 |
else
|
sl@0
|
260 |
{
|
sl@0
|
261 |
iRichText->SetInsertCharFormatL(charFormat, charFormatMask, select.iCursorPos);
|
sl@0
|
262 |
}
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
//Construct a transparent text view, which is displayed on top of the background bitmap,
|
sl@0
|
266 |
//which makes the transparency effect very well visible.
|
sl@0
|
267 |
void CTranspEditorView2::ContructL()
|
sl@0
|
268 |
{
|
sl@0
|
269 |
CreateWindowL();
|
sl@0
|
270 |
TSize size = iEikonEnv->ScreenDevice()->SizeInPixels();
|
sl@0
|
271 |
const TRect KViewRect(15, 15, size.iWidth - 15, size.iHeight - 15);
|
sl@0
|
272 |
SetRect(KViewRect);
|
sl@0
|
273 |
|
sl@0
|
274 |
iRichText = CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(), iEikonEnv->SystemCharFormatLayerL());
|
sl@0
|
275 |
iLayout = CTextLayout::NewL(iRichText, KViewRect.Width() - 2);
|
sl@0
|
276 |
|
sl@0
|
277 |
TRect rc(KViewRect);
|
sl@0
|
278 |
rc.Shrink(1, 1);
|
sl@0
|
279 |
rc.Move(-rc.iTl.iX + 1, -rc.iTl.iY + 1);
|
sl@0
|
280 |
iTextView = CTextView::NewL(iLayout,
|
sl@0
|
281 |
rc,
|
sl@0
|
282 |
iEikonEnv->ScreenDevice(),
|
sl@0
|
283 |
iEikonEnv->ScreenDevice(),
|
sl@0
|
284 |
&Window(),
|
sl@0
|
285 |
&iEikonEnv->RootWin(),
|
sl@0
|
286 |
&iEikonEnv->WsSession());
|
sl@0
|
287 |
|
sl@0
|
288 |
iTextView->EnablePictureFrameL(ETrue);
|
sl@0
|
289 |
const TRgb KTransparencyColor(85, 85, 85);
|
sl@0
|
290 |
Window().SetTransparencyFactor(KTransparencyColor);
|
sl@0
|
291 |
|
sl@0
|
292 |
ActivateL();
|
sl@0
|
293 |
}
|
sl@0
|
294 |
|
sl@0
|
295 |
void CTranspEditorView2::Draw(const TRect&) const
|
sl@0
|
296 |
{
|
sl@0
|
297 |
CWindowGc& gc = SystemGc();
|
sl@0
|
298 |
TRect rc = Rect();
|
sl@0
|
299 |
TRect rc2(rc.iTl.iX + 1, rc.iTl.iY + 1, rc.iBr.iX - 1, rc.iBr.iY - 1);
|
sl@0
|
300 |
|
sl@0
|
301 |
gc.Clear();
|
sl@0
|
302 |
|
sl@0
|
303 |
const TRgb KPenColor(0x00, 0x00, 0xFF);
|
sl@0
|
304 |
gc.SetPenColor(KPenColor);
|
sl@0
|
305 |
gc.DrawRect(rc);
|
sl@0
|
306 |
|
sl@0
|
307 |
TRAPD(err, iTextView->DrawL(rc2));
|
sl@0
|
308 |
if(err != KErrNone)
|
sl@0
|
309 |
{
|
sl@0
|
310 |
SystemGc().Clear(rc2);
|
sl@0
|
311 |
iEikonEnv->NotifyIdleErrorWhileRedrawing(err);
|
sl@0
|
312 |
}
|
sl@0
|
313 |
}
|
sl@0
|
314 |
|
sl@0
|
315 |
////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
316 |
//Document
|
sl@0
|
317 |
|
sl@0
|
318 |
CTranspEditorDoc::CTranspEditorDoc(CEikApplication& aApp) :
|
sl@0
|
319 |
CEikDocument(aApp)
|
sl@0
|
320 |
{
|
sl@0
|
321 |
}
|
sl@0
|
322 |
|
sl@0
|
323 |
CEikAppUi* CTranspEditorDoc::CreateAppUiL()
|
sl@0
|
324 |
{
|
sl@0
|
325 |
return new (ELeave) CTranspEditorUi;
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
329 |
//UI
|
sl@0
|
330 |
|
sl@0
|
331 |
void CTranspEditorUi::ConstructL()
|
sl@0
|
332 |
{
|
sl@0
|
333 |
BaseConstructL();
|
sl@0
|
334 |
|
sl@0
|
335 |
iTranspEditorView1 = CTranspEditorView1::NewL();
|
sl@0
|
336 |
AddToStackL(iTranspEditorView1);
|
sl@0
|
337 |
|
sl@0
|
338 |
iTranspEditorView2 = CTranspEditorView2::NewL();
|
sl@0
|
339 |
AddToStackL(iTranspEditorView2);
|
sl@0
|
340 |
}
|
sl@0
|
341 |
|
sl@0
|
342 |
CTranspEditorUi::~CTranspEditorUi()
|
sl@0
|
343 |
{
|
sl@0
|
344 |
RemoveFromStack(iTranspEditorView2);
|
sl@0
|
345 |
delete iTranspEditorView2;
|
sl@0
|
346 |
|
sl@0
|
347 |
RemoveFromStack(iTranspEditorView1);
|
sl@0
|
348 |
delete iTranspEditorView1;
|
sl@0
|
349 |
}
|
sl@0
|
350 |
|
sl@0
|
351 |
void CTranspEditorUi::HandleCommandL(TInt aCommand)
|
sl@0
|
352 |
{
|
sl@0
|
353 |
switch(aCommand)
|
sl@0
|
354 |
{
|
sl@0
|
355 |
case EAppCmdExit:
|
sl@0
|
356 |
CBaActiveScheduler::Exit();
|
sl@0
|
357 |
break;
|
sl@0
|
358 |
case EAppCmdInsertText:
|
sl@0
|
359 |
iTranspEditorView2->InsertTextL();
|
sl@0
|
360 |
break;
|
sl@0
|
361 |
case EAppCmdSwitchOpaque:
|
sl@0
|
362 |
iTranspEditorView2->SwitchOpaque();
|
sl@0
|
363 |
break;
|
sl@0
|
364 |
case EAppCmdSwitchSelect:
|
sl@0
|
365 |
iTranspEditorView2->SwitchSelectL();
|
sl@0
|
366 |
break;
|
sl@0
|
367 |
case EAppCmdInsertPicture:
|
sl@0
|
368 |
iTranspEditorView2->InsertPictureL();
|
sl@0
|
369 |
break;
|
sl@0
|
370 |
case EAppCmdSetCharFormat:
|
sl@0
|
371 |
iTranspEditorView2->SetCharFormatL();
|
sl@0
|
372 |
break;
|
sl@0
|
373 |
default:
|
sl@0
|
374 |
break;
|
sl@0
|
375 |
}
|
sl@0
|
376 |
}
|
sl@0
|
377 |
|
sl@0
|
378 |
////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
379 |
//
|
sl@0
|
380 |
|
sl@0
|
381 |
static CApaApplication* NewApplication()
|
sl@0
|
382 |
{
|
sl@0
|
383 |
return new CTranspEditorApp;
|
sl@0
|
384 |
}
|
sl@0
|
385 |
|
sl@0
|
386 |
TInt E32Main()
|
sl@0
|
387 |
{
|
sl@0
|
388 |
return EikStart::RunApplication(&NewApplication);
|
sl@0
|
389 |
}
|
sl@0
|
390 |
|
sl@0
|
391 |
|