|
1 /* |
|
2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implement of pen input plugin utils:resource,repository,LafEnv |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <centralrepository.h> |
|
19 #include <apacmdln.h> |
|
20 #include <coemain.h> |
|
21 #include <barsread.h> |
|
22 #include <e32std.h> |
|
23 #include <bitmtrans/bitmtranspanic.h> //for panic enum |
|
24 |
|
25 #include "peninputpluginutils.h" |
|
26 #include "AknsUtils.h" |
|
27 |
|
28 // constant |
|
29 const TInt KInvalidResId = -1; |
|
30 const TInt KInvalidBmp = -1 ; |
|
31 const TInt KInvalidColorGroup = -1; |
|
32 |
|
33 const TInt KTransparency[256] = |
|
34 { |
|
35 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, |
|
36 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13, |
|
37 14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 19, |
|
38 19, 19, 20, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 23, 24, 24, |
|
39 24, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 29, |
|
40 30, 30, 30, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, |
|
41 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 40, 40, 40, |
|
42 41, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46, |
|
43 46, 46, 47, 47, 47, 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 50, 51, 51, |
|
44 51, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 56, |
|
45 57, 57, 57, 58, 58, 58, 59, 59, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62, |
|
46 62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 67, 67, 67, |
|
47 68, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 71, 72, 72, 72, 73, |
|
48 73, 73, 74, 74, 74, 74, 75, 75, 75, 76, 76, 76, 77, 77 |
|
49 }; |
|
50 // ======== MEMBER FUNCTIONS ======== |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // C++ constructor. |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CAknFepTimer::CAknFepTimer(MAknFepTimerHandler* aTimerHandler) |
|
57 :CActive(EPriorityStandard), iTimerHandler(aTimerHandler) |
|
58 { |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Symbian Constructor |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CAknFepTimer* CAknFepTimer::NewL(MAknFepTimerHandler* aTimerHandler) |
|
66 { |
|
67 CAknFepTimer *self = new (ELeave) CAknFepTimer(aTimerHandler); |
|
68 |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(self); |
|
72 |
|
73 return self; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // Destructor |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C CAknFepTimer::~CAknFepTimer() |
|
81 { |
|
82 Cancel(); |
|
83 iTimer.Close(); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Set timer delay |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C void CAknFepTimer::SetTimer(const TTimeIntervalMicroSeconds32& aDelay) |
|
91 { |
|
92 Cancel(); |
|
93 iTimer.After(iStatus,aDelay); |
|
94 SetActive(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Symbian second-phase constructor |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CAknFepTimer::ConstructL() |
|
102 { |
|
103 User::LeaveIfError(iTimer.CreateLocal()); |
|
104 |
|
105 CActiveScheduler::Add(this); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // Will be called when timer ends |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CAknFepTimer::RunL() |
|
113 { |
|
114 iTimerHandler->HandleTimerOut(this); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // Will be called if RunL leaves |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CAknFepTimer::RunError(TInt /*aError*/) |
|
122 { |
|
123 return KErrNone; |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // Will be called when timer has been cancelled |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CAknFepTimer::DoCancel() |
|
131 { |
|
132 iTimer.Cancel(); |
|
133 } |
|
134 |
|
135 |
|
136 EXPORT_C CAknFepRepositoryWatcher* CAknFepRepositoryWatcher::NewL( |
|
137 const TUid aUid, |
|
138 const TUint32 aKey, |
|
139 CCenRepNotifyHandler::TCenRepKeyType aKeyType, |
|
140 TCallBack aCallBack, |
|
141 CRepository* aRepository) |
|
142 { |
|
143 CAknFepRepositoryWatcher* self = new(ELeave) CAknFepRepositoryWatcher(aUid, aKey, |
|
144 aCallBack, aRepository); |
|
145 |
|
146 CleanupStack::PushL(self); |
|
147 self->ConstructL(aKeyType); |
|
148 CleanupStack::Pop(self); |
|
149 |
|
150 return self; |
|
151 } |
|
152 |
|
153 EXPORT_C CAknFepRepositoryWatcher* CAknFepRepositoryWatcher::NewL( |
|
154 const TUid aUid, |
|
155 TCallBack aCallBack, |
|
156 CRepository* aRepository) |
|
157 { |
|
158 CAknFepRepositoryWatcher* self = new(ELeave) CAknFepRepositoryWatcher(aUid, |
|
159 NCentralRepositoryConstants::KInvalidNotificationId, |
|
160 aCallBack, aRepository); |
|
161 |
|
162 CleanupStack::PushL(self); |
|
163 self->ConstructL(); |
|
164 CleanupStack::Pop(self); |
|
165 |
|
166 return self; |
|
167 } |
|
168 |
|
169 EXPORT_C CAknFepRepositoryWatcher::~CAknFepRepositoryWatcher() |
|
170 { |
|
171 iNotifyHandler->StopListening(); |
|
172 delete iNotifyHandler; |
|
173 } |
|
174 |
|
175 CAknFepRepositoryWatcher::CAknFepRepositoryWatcher( |
|
176 const TUid aUid, |
|
177 const TUint32 aKey, |
|
178 TCallBack aCallBack, |
|
179 CRepository* aRepository) |
|
180 : |
|
181 iUid(aUid), iKey(aKey), iCallBack(aCallBack), iRepository(aRepository) |
|
182 { |
|
183 } |
|
184 |
|
185 void CAknFepRepositoryWatcher::ConstructL(CCenRepNotifyHandler::TCenRepKeyType aKeyType) |
|
186 { |
|
187 iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iRepository, aKeyType, iKey); |
|
188 iNotifyHandler->StartListeningL(); |
|
189 } |
|
190 |
|
191 void CAknFepRepositoryWatcher::ConstructL() |
|
192 { |
|
193 iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iRepository); |
|
194 iNotifyHandler->StartListeningL(); |
|
195 } |
|
196 |
|
197 EXPORT_C TUint32 CAknFepRepositoryWatcher::ChangedKey() |
|
198 { |
|
199 return iChangedKey; |
|
200 } |
|
201 |
|
202 EXPORT_C void CAknFepRepositoryWatcher::HandleNotifyInt(TUint32 aKey, TInt /*aNewValue*/) |
|
203 { |
|
204 iChangedKey = aKey; |
|
205 iCallBack.CallBack(); |
|
206 iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId; |
|
207 } |
|
208 |
|
209 EXPORT_C void CAknFepRepositoryWatcher::HandleNotifyError(TUint32 /*aKey*/, TInt /*aError*/, |
|
210 CCenRepNotifyHandler* /*aHandler*/) |
|
211 { |
|
212 } |
|
213 |
|
214 EXPORT_C void CAknFepRepositoryWatcher::HandleNotifyGeneric(TUint32 aId) |
|
215 { |
|
216 iChangedKey = aId; |
|
217 iCallBack.CallBack(); |
|
218 iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // Get ISO code accroding to language ID |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 EXPORT_C TBool AknPenInputUtils::GetISOLanguageCode(const TLanguage aLanguage, |
|
226 TDes& aISOCode) |
|
227 { |
|
228 struct TMapArray {TInt iLanguageCode; TPtrC iLanguageSb;}; |
|
229 const TInt KPrc= 0x7B80; |
|
230 const TInt KTw = 0x81fa; |
|
231 const TInt KHk = 0x6e2f; |
|
232 |
|
233 const TMapArray KISOCode[] = |
|
234 { |
|
235 {ELangEnglish,_L("en")},{ELangFrench,_L("fr")}, |
|
236 {ELangGerman,_L("de")}, {ELangSpanish,_L("es")}, |
|
237 {ELangItalian,_L("it")},{ELangSwedish,_L("sv")}, |
|
238 {ELangDanish,_L("da")}, {ELangNorwegian, _L("no")}, |
|
239 {ELangFinnish,_L("fi")},{ELangAmerican,_L("")}, |
|
240 {ELangSwissFrench,_L("")},{ELangSwissGerman,_L("")}, |
|
241 {ELangPortuguese,_L("pt")},{ELangTurkish,_L("tr")}, |
|
242 {ELangIcelandic,_L("is")}, {ELangRussian, _L("ru")}, |
|
243 {ELangHungarian,_L("hu")},{ELangDutch,_L("nl")}, |
|
244 {ELangBelgianFlemish,_L("nl")},{ELangAustralian,_L("as")}, |
|
245 {ELangBelgianFrench,_L("")},{ELangAustrian,_L("")}, |
|
246 {ELangNewZealand,_L("")},{ELangInternationalFrench, _L("")}, |
|
247 {ELangCzech,_L("cs")},{ELangSlovak,_L("sk")}, |
|
248 {ELangPolish,_L("pl")}, {ELangSlovenian,_L("sl")}, |
|
249 {ELangTaiwanChinese,_L("")},{ELangHongKongChinese,_L("")}, |
|
250 {ELangPrcChinese,_L("zh")}, {ELangJapanese, _L("ja")}, |
|
251 {ELangThai,_L("th")},{ELangAfrikaans,_L("af")}, |
|
252 {ELangAlbanian,_L("sq")},{ELangAmharic,_L("am")}, |
|
253 {ELangArabic,_L("ar")},{ELangArmenian,_L("hy")}, |
|
254 {ELangTagalog,_L("tl")},{ELangBelarussian, _L("be")}, |
|
255 {ELangBengali,_L("bn")}, {ELangBulgarian,_L("bg")}, |
|
256 {ELangBurmese,_L("my")},{ELangCatalan,_L("ca")}, |
|
257 {ELangCroatian,_L("hr")},{ELangCanadianEnglish,_L("")}, |
|
258 {ELangInternationalEnglish,_L("")},{ELangSouthAfricanEnglish, _L("")}, |
|
259 {ELangEstonian,_L("et")},{ELangFarsi,_L("fa")}, |
|
260 {ELangCanadianFrench,_L("cf")},{ELangScotsGaelic,_L("")}, |
|
261 {ELangGeorgian,_L("ka")},{ELangGreek,_L("el")}, |
|
262 {ELangCyprusGreek,_L("")}, {ELangGujarati, _L("gu")}, |
|
263 {ELangKorean,_L("ko")},{ELangLao,_L("lo")}, |
|
264 {ELangLatvian,_L("lv")},{ELangLithuanian,_L("lt")}, |
|
265 {ELangMacedonian,_L("mk")},{ELangMalay,_L("ms")}, |
|
266 {ELangMalayalam,_L("ml")}, {ELangMarathi, _L("mr")}, |
|
267 {ELangMoldavian,_L("mo")},{ELangMongolian,_L("mn")}, |
|
268 {ELangNorwegianNynorsk,_L("nn")},{ELangBrazilianPortuguese,_L("pt")}, |
|
269 {ELangPunjabi,_L("pa")},{ELangRomanian,_L("ro")}, |
|
270 {ELangSerbian,_L("sr")}, {ELangSinhalese, _L("si")}, |
|
271 {ELangSomali,_L("so")},{ELangInternationalSpanish,_L("fr")}, |
|
272 {ELangLatinAmericanSpanish,_L("es")},{ELangSwahili,_L("sw")}, |
|
273 {ELangFinlandSwedish,_L("")},{ELangTamil,_L("ta")}, |
|
274 {ELangTelugu, _L("te")},{ELangTibetan,_L("bo")}, |
|
275 {ELangTigrinya,_L("ti")},{ELangCyprusTurkish,_L("")}, |
|
276 {ELangTurkmen,_L("tk")},{ELangUkrainian,_L("uk")}, |
|
277 {ELangUrdu,_L("ur")},{ELangVietnamese, _L("vi")}, |
|
278 {ELangWelsh,_L("cy")},{ELangZulu,_L("zu")}, |
|
279 {ELangHebrew,_L("he")}, {ELangIndonesian,_L("in")}, |
|
280 {ELangHindi,_L("hi")} |
|
281 }; |
|
282 |
|
283 switch(aLanguage) |
|
284 { |
|
285 case ELangPrcChinese: |
|
286 aISOCode.Zero(); |
|
287 aISOCode.Append(KPrc); |
|
288 return ETrue; |
|
289 case ELangTaiwanChinese: |
|
290 aISOCode.Zero(); |
|
291 aISOCode.Append(KTw); |
|
292 return ETrue; |
|
293 case ELangHongKongChinese: |
|
294 aISOCode.Zero(); |
|
295 aISOCode.Append(KHk); |
|
296 return ETrue; |
|
297 default: |
|
298 break; |
|
299 } |
|
300 for (TInt temp = 0; temp < (sizeof(KISOCode)/sizeof(TMapArray)); temp++) |
|
301 { |
|
302 if (KISOCode[temp].iLanguageCode == aLanguage && |
|
303 KISOCode[temp].iLanguageSb.Length() > 0) |
|
304 { |
|
305 aISOCode.Copy(KISOCode[temp].iLanguageSb); |
|
306 return ETrue; |
|
307 } |
|
308 } |
|
309 |
|
310 return EFalse; |
|
311 } |
|
312 |
|
313 EXPORT_C void AknPenInputUtils::StartAppL( const TDesC& aAppName ) |
|
314 { |
|
315 TFindServer findApp( aAppName ); |
|
316 TFullName name; |
|
317 if (findApp.Next( name ) == KErrNone) |
|
318 { |
|
319 // if server is already running return immediately |
|
320 return; |
|
321 } |
|
322 |
|
323 RProcess process; |
|
324 TInt err = process.Create( aAppName, KNullDesC ); |
|
325 User::LeaveIfError(err); |
|
326 |
|
327 CApaCommandLine* commandLine = CApaCommandLine::NewLC(); |
|
328 commandLine->SetDocumentNameL( KNullDesC ); |
|
329 commandLine->SetExecutableNameL( aAppName ); |
|
330 commandLine->SetProcessEnvironmentL( process ); |
|
331 CleanupStack::PopAndDestroy( commandLine ); |
|
332 |
|
333 process.Resume(); |
|
334 process.Close(); |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------------------------- |
|
338 // Combine two image into one |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 EXPORT_C CFbsBitmap* AknPenImageUtils::CombineTwoImagesL(const CFbsBitmap* aBmp1, |
|
342 const CFbsBitmap* aBmp2, |
|
343 TDisplayMode aMode, |
|
344 TBool aHorizontal) |
|
345 { |
|
346 CFbsBitmap* offscreenbmp = new (ELeave) CFbsBitmap(); |
|
347 CleanupStack::PushL(offscreenbmp); |
|
348 |
|
349 TInt bigger; |
|
350 TSize newsize; |
|
351 TSize bmp1size = aBmp1->SizeInPixels(); |
|
352 TSize bmp2size = aBmp2->SizeInPixels(); |
|
353 |
|
354 if (aHorizontal) |
|
355 { |
|
356 bigger = bmp1size.iHeight > bmp2size.iHeight ? bmp1size.iHeight : bmp2size.iHeight; |
|
357 newsize = TSize(bmp1size.iWidth + bmp2size.iWidth, |
|
358 bigger); |
|
359 } |
|
360 else |
|
361 { |
|
362 bigger = bmp1size.iWidth > bmp2size.iWidth ? bmp1size.iWidth : bmp2size.iWidth; |
|
363 newsize = TSize(bigger, |
|
364 bmp1size.iHeight + bmp2size.iHeight); |
|
365 } |
|
366 |
|
367 offscreenbmp->Create(newsize, aMode); |
|
368 |
|
369 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(offscreenbmp); |
|
370 CleanupStack::PushL(bitmapDevice); |
|
371 |
|
372 CFbsBitGc* bitmapContext = NULL; |
|
373 bitmapDevice->CreateContext(bitmapContext); |
|
374 CleanupStack::PushL(bitmapContext); |
|
375 |
|
376 // copy image1 to context, and thus to offscreenbmp |
|
377 bitmapContext->BitBlt(TPoint(0,0), aBmp1); |
|
378 |
|
379 // copy image2 to context, thus to offscreenbmp |
|
380 if (aHorizontal) |
|
381 { |
|
382 bitmapContext->BitBlt(TPoint(bmp1size.iWidth, 0), aBmp2); |
|
383 } |
|
384 else |
|
385 { |
|
386 bitmapContext->BitBlt(TPoint(0, bmp1size.iHeight), aBmp2); |
|
387 } |
|
388 |
|
389 CleanupStack::PopAndDestroy(2, bitmapDevice); |
|
390 CleanupStack::Pop(offscreenbmp); |
|
391 return offscreenbmp; |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // draw 3 pieces skined frame |
|
396 // --------------------------------------------------------------------------- |
|
397 // |
|
398 EXPORT_C void AknPenInputDrawUtils::Draw3PiecesFrame(MAknsSkinInstance *aInstance, |
|
399 CFbsBitGc& aGc, |
|
400 const TRect& aLeftOrTopRect, |
|
401 const TRect& aCenterRect, |
|
402 const TRect& aRightOrBottomRect, |
|
403 const TAknsItemID& aSideLeftOrTopID, |
|
404 const TAknsItemID& aCenterID, |
|
405 const TAknsItemID& aSideRightOrBottomID) |
|
406 { |
|
407 if( !aInstance ) |
|
408 return; |
|
409 AknsDrawUtils::DrawCachedImage( aInstance, aGc, aLeftOrTopRect, aSideLeftOrTopID); |
|
410 AknsDrawUtils::DrawCachedImage( aInstance, aGc, aCenterRect, aCenterID); |
|
411 AknsDrawUtils::DrawCachedImage( aInstance, aGc, aRightOrBottomRect, aSideRightOrBottomID); |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // draw 3 pieces skined frame |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 EXPORT_C void AknPenInputDrawUtils::Draw3PiecesFrame(MAknsSkinInstance *aInstance, |
|
419 CFbsBitGc& aGc, |
|
420 const TRect& aOuterRect, |
|
421 const TRect& aInnerRect, |
|
422 const TAknsItemID& aSideLeftOrTopID, |
|
423 const TAknsItemID& aCenterID, |
|
424 const TAknsItemID& aSideRightOrBottomID) |
|
425 { |
|
426 TRect aSideRect1, aSideRect2; |
|
427 // horizon |
|
428 if( aOuterRect.iTl.iY == aInnerRect.iTl.iY && aOuterRect.iBr.iY == aInnerRect.iBr.iY ) |
|
429 { |
|
430 aSideRect1 = TRect( aOuterRect.iTl, TPoint( aInnerRect.iTl.iX, aInnerRect.iBr.iY ) ); |
|
431 aSideRect2 = TRect( TPoint( aInnerRect.iBr.iX, aInnerRect.iTl.iY), aOuterRect.iBr ); |
|
432 } |
|
433 else if( aOuterRect.iTl.iX == aInnerRect.iTl.iX && aOuterRect.iBr.iX == aInnerRect.iBr.iX ) |
|
434 { |
|
435 aSideRect1 = TRect( aOuterRect.iTl, TPoint( aInnerRect.iBr.iX, aInnerRect.iTl.iY ) ); |
|
436 aSideRect2 = TRect( TPoint( aInnerRect.iTl.iX, aInnerRect.iBr.iY), aOuterRect.iBr ); |
|
437 } |
|
438 Draw3PiecesFrame( aInstance, |
|
439 aGc, |
|
440 aSideRect1, |
|
441 aInnerRect, |
|
442 aSideRect2, |
|
443 aSideLeftOrTopID, |
|
444 aCenterID, |
|
445 aSideRightOrBottomID ); |
|
446 } |
|
447 |
|
448 // --------------------------------------------------------------------------- |
|
449 // calculate the graphic rect for common button |
|
450 // --------------------------------------------------------------------------- |
|
451 // |
|
452 EXPORT_C void AknPenImageUtils::CalculateGraphicRect(const TRect& aBoundRect, TRect& aGraphicRect) |
|
453 { |
|
454 // judge whether the width or height is larger |
|
455 TPoint ltPoint; |
|
456 TInt unitLength = 0; |
|
457 if( aBoundRect.Width() > aBoundRect.Height() ) |
|
458 { |
|
459 unitLength = aBoundRect.Height(); |
|
460 ltPoint.iX = aBoundRect.iTl.iX + (aBoundRect.Width() - aBoundRect.Height()) / 2; |
|
461 ltPoint.iY = aBoundRect.iTl.iY; |
|
462 aGraphicRect.SetRect( ltPoint, TSize( unitLength, unitLength ) ); |
|
463 } |
|
464 else |
|
465 { |
|
466 unitLength = aBoundRect.Width(); |
|
467 ltPoint.iX = aBoundRect.iTl.iX; |
|
468 ltPoint.iY = aBoundRect.iTl.iY + (aBoundRect.Height() - aBoundRect.Width()) / 2; |
|
469 aGraphicRect.SetRect( ltPoint, TSize( unitLength, unitLength ) ); |
|
470 } |
|
471 aGraphicRect.Shrink(5, 5); |
|
472 } |
|
473 |
|
474 // --------------------------------------------------------------------------- |
|
475 // calculate the graphic rect for common button |
|
476 // --------------------------------------------------------------------------- |
|
477 // |
|
478 EXPORT_C void AknPenImageUtils::CalculateLongBtnGraphicRect(const TRect& aBoundRect, |
|
479 TRect& aGraphicRect) |
|
480 { |
|
481 // Shrink 1/5 in width and height |
|
482 TInt shrLength = aBoundRect.Width() / 5; |
|
483 TInt shrHeight = aBoundRect.Height() / 5; |
|
484 aGraphicRect = aBoundRect; |
|
485 aGraphicRect.Shrink( shrLength, shrHeight ); |
|
486 } |
|
487 |
|
488 // --------------------------------------------------------------------------- |
|
489 // DrawColorIcon |
|
490 // --------------------------------------------------------------------------- |
|
491 // |
|
492 EXPORT_C void AknPenInputDrawUtils::DrawColorIcon( CPenInputColorIcon *aColorIcon, |
|
493 CFbsBitGc& aGc, |
|
494 const TRect& aRect ) |
|
495 { |
|
496 if( NULL == aColorIcon ) |
|
497 return; |
|
498 |
|
499 CFbsBitmap* bmpMask = aColorIcon->IsDimmed() ? aColorIcon->DimmedBitmapMask() : |
|
500 aColorIcon->BitmapMask(); |
|
501 TRect srcRect( TPoint( 0, 0 ), aColorIcon->Bitmap()->SizeInPixels() ); |
|
502 if( bmpMask ) |
|
503 { |
|
504 aGc.BitBltMasked( aRect.iTl, |
|
505 aColorIcon->Bitmap(), |
|
506 srcRect, |
|
507 bmpMask, |
|
508 EFalse); |
|
509 } |
|
510 } |
|
511 |
|
512 // --------------------------------------------------------------------------- |
|
513 // Draw3PiecesColorIcon |
|
514 // --------------------------------------------------------------------------- |
|
515 // |
|
516 EXPORT_C void AknPenInputDrawUtils:: |
|
517 Draw3PiecesColorIcon( CPenInput3PiecesColorIcons *aColorIcons, |
|
518 CFbsBitGc& aGc, |
|
519 const TRect& aOuterRect, |
|
520 const TRect& aInnerRect ) |
|
521 { |
|
522 if( NULL == aColorIcons) |
|
523 return; |
|
524 |
|
525 TRect aSideRect1, aSideRect2; |
|
526 // horizon |
|
527 if( aOuterRect.iTl.iY == aInnerRect.iTl.iY && aOuterRect.iBr.iY == aInnerRect.iBr.iY ) |
|
528 { |
|
529 aSideRect1 = TRect( aOuterRect.iTl, TPoint( aInnerRect.iTl.iX, aInnerRect.iBr.iY ) ); |
|
530 aSideRect2 = TRect( TPoint( aInnerRect.iBr.iX, aInnerRect.iTl.iY), aOuterRect.iBr ); |
|
531 } |
|
532 else if( aOuterRect.iTl.iX == aInnerRect.iTl.iX && aOuterRect.iBr.iX == aInnerRect.iBr.iX ) |
|
533 { |
|
534 aSideRect1 = TRect( aOuterRect.iTl, TPoint( aInnerRect.iBr.iX, aInnerRect.iTl.iY ) ); |
|
535 aSideRect2 = TRect( TPoint( aInnerRect.iTl.iX, aInnerRect.iBr.iY), aOuterRect.iBr ); |
|
536 } |
|
537 |
|
538 if( aColorIcons->FirstIcon() ) |
|
539 { |
|
540 if( aColorIcons->FirstIcon()->Bitmap()->SizeInPixels() != aSideRect1.Size() ) |
|
541 TRAP_IGNORE( aColorIcons->FirstIcon()->ResizeL( aSideRect1.Size() ) ); |
|
542 |
|
543 AknPenInputDrawUtils::DrawColorIcon( aColorIcons->FirstIcon(), |
|
544 aGc, |
|
545 aSideRect1 ); |
|
546 } |
|
547 if( aColorIcons->MiddleIcon() ) |
|
548 { |
|
549 if( aColorIcons->MiddleIcon()->Bitmap()->SizeInPixels() != aInnerRect.Size() ) |
|
550 TRAP_IGNORE( aColorIcons->MiddleIcon()->ResizeL( aInnerRect.Size() ) ); |
|
551 |
|
552 AknPenInputDrawUtils::DrawColorIcon( aColorIcons->MiddleIcon(), |
|
553 aGc, |
|
554 aInnerRect ); |
|
555 } |
|
556 if( aColorIcons->LastIcon() ) |
|
557 { |
|
558 if( aColorIcons->LastIcon()->Bitmap()->SizeInPixels() != aSideRect2.Size() ) |
|
559 TRAP_IGNORE( aColorIcons->LastIcon()->ResizeL( aSideRect2.Size() ) ); |
|
560 |
|
561 AknPenInputDrawUtils::DrawColorIcon( aColorIcons->LastIcon(), |
|
562 aGc, |
|
563 aSideRect2 ); |
|
564 } |
|
565 } |
|
566 |
|
567 EXPORT_C CPenInputColorIcon* CPenInputColorIcon::NewL( TInt aResID ) |
|
568 { |
|
569 CPenInputColorIcon *self = CPenInputColorIcon::NewLC( aResID ); |
|
570 CleanupStack::Pop(self); |
|
571 return self; |
|
572 } |
|
573 |
|
574 EXPORT_C CPenInputColorIcon* CPenInputColorIcon::NewLC( TInt aResID ) |
|
575 { |
|
576 CPenInputColorIcon *self = new (ELeave) CPenInputColorIcon( aResID ); |
|
577 |
|
578 CleanupStack::PushL(self); |
|
579 self->ConstructL(); |
|
580 |
|
581 return self; |
|
582 } |
|
583 |
|
584 EXPORT_C void CPenInputColorIcon::ConstructFromResourceL( TInt aResID ) |
|
585 { |
|
586 if (aResID == KInvalidResId) |
|
587 { |
|
588 User::Leave( KErrArgument ); |
|
589 } |
|
590 DestroyRes(); |
|
591 |
|
592 TResourceReader reader; |
|
593 CCoeEnv::Static()->CreateResourceReaderLC(reader, aResID); |
|
594 |
|
595 // Read the file name of the bmps |
|
596 TPtrC bmpFileName = reader.ReadTPtrC(); |
|
597 TInt32 imgMajorSkinId = reader.ReadInt32(); |
|
598 TInt colorGroup = reader.ReadInt16(); |
|
599 TAknsItemID id; |
|
600 |
|
601 // Get the image ids and mask ids from resource |
|
602 TInt bmpId = reader.ReadInt16(); |
|
603 TInt bmpMskId = reader.ReadInt16(); |
|
604 |
|
605 // Read skin item id |
|
606 const TInt skinitemid = reader.ReadInt16(); |
|
607 id.Set(TInt(imgMajorSkinId), skinitemid); |
|
608 |
|
609 if ( bmpId == KInvalidBmp || |
|
610 bmpMskId == KInvalidBmp || |
|
611 colorGroup == KInvalidColorGroup ) |
|
612 { |
|
613 User::Leave( KErrGeneral ); |
|
614 } |
|
615 |
|
616 AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(), |
|
617 id, |
|
618 KAknsIIDQsnIconColors, |
|
619 colorGroup, |
|
620 iBmp, |
|
621 iBmpMask, |
|
622 bmpFileName, |
|
623 bmpId, |
|
624 bmpMskId, |
|
625 TRgb() ); |
|
626 |
|
627 CleanupStack::PopAndDestroy(); // reader |
|
628 } |
|
629 |
|
630 EXPORT_C void CPenInputColorIcon::ResizeL( const TSize& aSize ) |
|
631 { |
|
632 ASSERT( iBmp && iBmpMask ); |
|
633 AknIconUtils::SetSize(iBmp, aSize, EAspectRatioNotPreserved); |
|
634 AknIconUtils::SetSize(iBmpMask, aSize, EAspectRatioNotPreserved); |
|
635 //CreateDimmedMaskL( iDimmedBmp, iBmpMask ); |
|
636 } |
|
637 |
|
638 CPenInputColorIcon::~CPenInputColorIcon() |
|
639 { |
|
640 DestroyRes(); |
|
641 } |
|
642 |
|
643 void CPenInputColorIcon::CreateDimmedMaskL( CFbsBitmap*& aDimmedMask, |
|
644 const CFbsBitmap* aMask ) |
|
645 { |
|
646 if (aMask && aMask->DisplayMode() == EGray256) |
|
647 { |
|
648 delete aDimmedMask; |
|
649 aDimmedMask = NULL; |
|
650 |
|
651 aDimmedMask = new (ELeave) CFbsBitmap; |
|
652 |
|
653 User::LeaveIfError(aDimmedMask->Create(aMask->SizeInPixels(), EGray256)); |
|
654 CleanupStack::PushL(aDimmedMask); |
|
655 |
|
656 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(aDimmedMask); |
|
657 CleanupStack::PushL(bitmapDevice); |
|
658 |
|
659 CFbsBitGc* bitGc(NULL); |
|
660 User::LeaveIfError(bitmapDevice->CreateContext(bitGc)); |
|
661 CleanupStack::PushL(bitGc); |
|
662 |
|
663 bitGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
664 bitGc->BitBlt(TPoint(0, 0), aMask); |
|
665 |
|
666 aDimmedMask->LockHeap(); |
|
667 TInt w = aMask->SizeInPixels().iWidth; |
|
668 TInt h = aMask->SizeInPixels().iHeight; |
|
669 TInt dataStride = aMask->DataStride() - w; |
|
670 unsigned char* address = (unsigned char *)aDimmedMask->DataAddress(); |
|
671 |
|
672 for ( TInt i = 0; i < h; ++i ) |
|
673 { |
|
674 for ( TInt j = 0; j < w; ++j ) |
|
675 { |
|
676 *address = KTransparency[*address]; |
|
677 ++address; |
|
678 } |
|
679 address += dataStride; |
|
680 } |
|
681 |
|
682 aDimmedMask->UnlockHeap(); |
|
683 |
|
684 CleanupStack::PopAndDestroy(2); // bitmapDevice, bitGc |
|
685 CleanupStack::Pop(1); // aDimmedMask |
|
686 } |
|
687 } |
|
688 |
|
689 void CPenInputColorIcon::DestroyRes() |
|
690 { |
|
691 delete iBmp; |
|
692 delete iBmpMask; |
|
693 delete iDimmedBmp; |
|
694 iBmp = NULL; |
|
695 iBmpMask = NULL; |
|
696 iDimmedBmp = NULL; |
|
697 } |
|
698 |
|
699 EXPORT_C CPenInput3PiecesColorIcons* |
|
700 CPenInput3PiecesColorIcons::NewL( TInt aFirstIconResID, |
|
701 TInt aMiddleIconResID, |
|
702 TInt aLastIconResID ) |
|
703 { |
|
704 CPenInput3PiecesColorIcons *self = |
|
705 CPenInput3PiecesColorIcons::NewLC( aFirstIconResID, |
|
706 aMiddleIconResID, |
|
707 aLastIconResID ); |
|
708 CleanupStack::Pop(self); |
|
709 return self; |
|
710 } |
|
711 |
|
712 EXPORT_C CPenInput3PiecesColorIcons* |
|
713 CPenInput3PiecesColorIcons::NewLC( TInt aFirstIconResID, |
|
714 TInt aMiddleIconResID, |
|
715 TInt aLastIconResID ) |
|
716 { |
|
717 CPenInput3PiecesColorIcons *self = new (ELeave) CPenInput3PiecesColorIcons(); |
|
718 |
|
719 CleanupStack::PushL(self); |
|
720 self->ConstructFromResourceL( aFirstIconResID, |
|
721 aMiddleIconResID, |
|
722 aLastIconResID); |
|
723 |
|
724 return self; |
|
725 } |
|
726 |
|
727 CPenInput3PiecesColorIcons::~CPenInput3PiecesColorIcons() |
|
728 { |
|
729 delete iFirstIcon; |
|
730 delete iMiddleIcon; |
|
731 delete iLastIcon; |
|
732 } |
|
733 |
|
734 void CPenInput3PiecesColorIcons::ConstructFromResourceL( TInt aFirstIconResID, |
|
735 TInt aMiddleIconResID, |
|
736 TInt aLastIconResID ) |
|
737 { |
|
738 iFirstIcon = CPenInputColorIcon::NewL( aFirstIconResID ); |
|
739 iMiddleIcon = CPenInputColorIcon::NewL( aMiddleIconResID ); |
|
740 iLastIcon = CPenInputColorIcon::NewL( aLastIconResID ); |
|
741 } |
|
742 |
|
743 EXPORT_C void CPenInput3PiecesColorIcons::ReConstructL() |
|
744 { |
|
745 iFirstIcon->ReConstructL(); |
|
746 iMiddleIcon->ReConstructL(); |
|
747 iLastIcon->ReConstructL(); |
|
748 } |
|
749 |
|
750 |
|
751 EXPORT_C CPeninputSyncBitmapRotator* CPeninputSyncBitmapRotator::NewL() |
|
752 { |
|
753 CPeninputSyncBitmapRotator* self = new(ELeave) CPeninputSyncBitmapRotator(); |
|
754 CleanupStack::PushL(self); |
|
755 self->ConstructL(); |
|
756 CleanupStack::Pop(self); |
|
757 return self; |
|
758 } |
|
759 |
|
760 /** |
|
761 Constructor for this class. Adds itself to <code>CActiveScheduler</code>. |
|
762 The priority of this active object is CActive::EPriorityIdle |
|
763 */ |
|
764 |
|
765 CPeninputSyncBitmapRotator::CPeninputSyncBitmapRotator() |
|
766 :iScanlineDes(NULL,0) |
|
767 { |
|
768 } |
|
769 |
|
770 |
|
771 /** |
|
772 Performs second phase of contruction |
|
773 * |
|
774 */ |
|
775 |
|
776 void CPeninputSyncBitmapRotator::ConstructL() |
|
777 { |
|
778 } |
|
779 |
|
780 /** |
|
781 * |
|
782 * Default destructor for this class. |
|
783 * |
|
784 */ |
|
785 |
|
786 CPeninputSyncBitmapRotator::~CPeninputSyncBitmapRotator() |
|
787 { |
|
788 Cleanup(); |
|
789 |
|
790 // should have been deleted by cleanup |
|
791 ASSERT(iScanlineBuffer==NULL); |
|
792 ASSERT(iTempBitmap==NULL); |
|
793 ASSERT(iDevice==NULL); |
|
794 ASSERT(iGc==NULL); |
|
795 } |
|
796 |
|
797 /** |
|
798 This function performs deallocation of memory allocated by the class |
|
799 |
|
800 */ |
|
801 |
|
802 void CPeninputSyncBitmapRotator::Cleanup() |
|
803 { |
|
804 delete [] iScanlineBuffer; iScanlineBuffer = NULL; |
|
805 delete iTempBitmap; iTempBitmap = NULL; |
|
806 delete iGc; iGc = NULL; |
|
807 delete iDevice; iDevice = NULL; |
|
808 delete iScanlineBitmap; iScanlineBitmap = NULL; |
|
809 #if defined(ROTATION_PROFILING) |
|
810 TUint fcTaken=User::FastCounter() - iStartedAtFc; |
|
811 RDebug::Print(_L("BmpRotator: FC time taken %d"),fcTaken); |
|
812 #endif // |
|
813 } |
|
814 |
|
815 /** |
|
816 The function Rotate schedules a rotate/mirror operation on a bitmap supplied in the |
|
817 aSrcBitmap whose output overwrites aSrcBitmap. |
|
818 Preconditions: |
|
819 aRequestStatus is not a NULL pointer |
|
820 aSrcBitmap is a fully constructed bitmap of unknown size including zero dimension |
|
821 aAngle is a member of the enumeration TSyncRotationAngle |
|
822 |
|
823 @param "CFbsBitmap& aBitmap" |
|
824 is a reference to a CFbsBitmap. This bitmap should have been created |
|
825 and is also an output |
|
826 @param "TSyncRotationAngle aAngle" |
|
827 aAngle is a member of the enumeration TSyncRotationAngle and specifies the rotation mirror operation |
|
828 |
|
829 @panic This function panics with TBitmapTransformsMain::ENoSourceBitmap when the aSrcBitmap has not been constructed |
|
830 ie its handle is 0 |
|
831 |
|
832 Sucess Guarantee |
|
833 aSrcBitmap contains the rotated bitmap |
|
834 aRequestStatus points to the value KErrorNone |
|
835 |
|
836 */ |
|
837 |
|
838 EXPORT_C TInt CPeninputSyncBitmapRotator::Rotate(CFbsBitmap& aBitmap, TSyncRotationAngle aAngle) |
|
839 { |
|
840 //[ panic if the src has not been created] |
|
841 __ASSERT_ALWAYS( (aBitmap.Handle() != 0), User::Panic(_L("PENINPUTUTILITY"), ENoSourceBitmap ) ); |
|
842 |
|
843 //[ assert the angle is ok ] |
|
844 __ASSERT_ALWAYS( ( aAngle >= CBitmapRotator::ERotation90DegreesClockwise ) && |
|
845 ( aAngle <= CBitmapRotator::EMirrorVerticalAxis ), |
|
846 User::Panic(_L("PENINPUTUTILITY"),EBadArgumentRotate) ); |
|
847 |
|
848 ASSERT(iTempBitmap==NULL); |
|
849 iTempBitmap = new CFbsBitmap; |
|
850 if (!iTempBitmap) |
|
851 { |
|
852 return KErrNoMemory; |
|
853 } |
|
854 return Rotate(aBitmap, *iTempBitmap, aAngle); |
|
855 } |
|
856 |
|
857 /** |
|
858 The Rotate function schedules a rotate/mirror operation on a bitmap supplied in the srcBitmap and |
|
859 produces the output in the tgtBitmap. |
|
860 The CPeninputSyncBitmapRotator is an active object and as such provides asynchronous operations |
|
861 |
|
862 Preconditions: |
|
863 aRequestStatus is not a NULL pointer |
|
864 aSrcBitmap is a fully constructed bitmap of unknown size including zero dimension and |
|
865 of type EColor16M |
|
866 aTgtBitmap is a fully constructed bitmap of unknown size including zero dimension |
|
867 and is of type EColor16M |
|
868 aAngle is a member of the enumeration TSyncRotationAngle |
|
869 |
|
870 Sucess Guarantee: |
|
871 aTgtBitmap contains the rotated bitmap |
|
872 aRequestStatus points to the value KErrNone |
|
873 |
|
874 Minimal Guarantee: |
|
875 The bitmap supplied in aSrcBitmap is unaltered |
|
876 |
|
877 |
|
878 @param "CFbsBitmap& aSrcBitmap" |
|
879 This bitmap should have been created and be of type EColor16M |
|
880 @param "CFbsBitmap& aTgtBitmap" |
|
881 This bitmap should have been created and be of type EColor16M |
|
882 @param "TSyncRotationAngle aAngle" |
|
883 is a member of the enumeration TSyncRotationAngle and specifies the rotation mirror operation |
|
884 |
|
885 |
|
886 @panic This function panics with TBitmapTransformsMain::ENoSourceBitmap when the aSrcBitmap has not been constructed |
|
887 i.e. its handle is zero |
|
888 |
|
889 |
|
890 */ |
|
891 |
|
892 EXPORT_C TInt CPeninputSyncBitmapRotator::Rotate(CFbsBitmap& aSrcBitmap, CFbsBitmap& aTgtBitmap, TSyncRotationAngle aAngle) |
|
893 { |
|
894 //[ panic if the src has not been created] |
|
895 __ASSERT_ALWAYS( (aSrcBitmap.Handle() != 0), User::Panic(_L("PENINPUTUTILITY"), ENoSourceBitmap ) ); |
|
896 |
|
897 //[ assert the angle is ok ] |
|
898 __ASSERT_ALWAYS( ( aAngle >= CBitmapRotator::ERotation90DegreesClockwise ) && |
|
899 ( aAngle <= CBitmapRotator::EMirrorVerticalAxis ), |
|
900 User::Panic(_L("AKNFEP"),EBadArgumentRotate) ); |
|
901 |
|
902 //[ we do not need to ensure a tgt has been created] |
|
903 #if defined(ROTATION_PROFILING) |
|
904 iStartedAtFc = User::FastCounter(); |
|
905 #endif // ROTATION_PROFILING |
|
906 // Initialize member variables |
|
907 iSrcBitmap = &aSrcBitmap; |
|
908 iTgtBitmap = &aTgtBitmap; |
|
909 iAngle = aAngle; |
|
910 iCurOffset = 0; |
|
911 iBitmapSize = iSrcBitmap->SizeInPixels(); |
|
912 iDisplayMode = iSrcBitmap->DisplayMode(); |
|
913 |
|
914 TSize newSize; |
|
915 if ((aAngle == CBitmapRotator::ERotation90DegreesClockwise) || (aAngle == CBitmapRotator::ERotation270DegreesClockwise)) |
|
916 { |
|
917 newSize.SetSize(iBitmapSize.iHeight, iBitmapSize.iWidth); // Swap width and height |
|
918 } |
|
919 else |
|
920 { |
|
921 newSize.SetSize(iBitmapSize.iWidth, iBitmapSize.iHeight); |
|
922 } |
|
923 TInt err = iTgtBitmap->Create(newSize, iDisplayMode); |
|
924 |
|
925 TBool bmpDeviceNeeded=EFalse; |
|
926 if (iSrcBitmap->DisplayMode()==EColor16M || iSrcBitmap->DisplayMode()==EColor16MU || |
|
927 iSrcBitmap->DisplayMode()==EColor16MA || |
|
928 iSrcBitmap->DisplayMode()==EColor256 || iSrcBitmap->DisplayMode()==EGray256 || |
|
929 iSrcBitmap->DisplayMode()==EColor64K ) |
|
930 { |
|
931 iScanlineDisplayMode = iSrcBitmap->DisplayMode(); |
|
932 } |
|
933 else |
|
934 { |
|
935 // we can't cope with that color mode, then use the highest one for intermediate buffer |
|
936 bmpDeviceNeeded = ETrue; |
|
937 iScanlineDisplayMode= EColor16MA; |
|
938 } |
|
939 iPixelSizeInBytes = TDisplayModeUtils::NumDisplayModeBitsPerPixel(iScanlineDisplayMode) / 8; |
|
940 |
|
941 TInt scanlineLength=iSrcBitmap->ScanLineLength(newSize.iWidth, iScanlineDisplayMode); |
|
942 scanlineLength=Align4(scanlineLength); |
|
943 if (err == KErrNone) |
|
944 { |
|
945 ASSERT(iScanlineBuffer==NULL); |
|
946 iScanlineBuffer = new TUint32 [ scanlineLength ]; |
|
947 if(!iScanlineBuffer) |
|
948 { |
|
949 err = KErrNoMemory; |
|
950 } |
|
951 } |
|
952 if (err != KErrNone) |
|
953 { |
|
954 return err; |
|
955 } |
|
956 iRows = newSize.iHeight; |
|
957 |
|
958 TPtr8 scanlineDes(reinterpret_cast<TText8*>(iScanlineBuffer),scanlineLength,scanlineLength); // Use a temporary to avoid compiler warnings |
|
959 iScanlineDes.Set(scanlineDes); |
|
960 |
|
961 ASSERT(iDevice==NULL); |
|
962 if (bmpDeviceNeeded) |
|
963 { |
|
964 iScanlineBitmap = new CFbsBitmap(); |
|
965 err= (iScanlineBitmap? iScanlineBitmap->Create(TSize(iTgtBitmap->SizeInPixels().iWidth, 1), iScanlineDisplayMode) |
|
966 : KErrNoMemory); |
|
967 if (err==KErrNone) |
|
968 { |
|
969 TRAP(err, iDevice = CFbsBitmapDevice::NewL(iTgtBitmap)); |
|
970 } |
|
971 if (err == KErrNone) |
|
972 { |
|
973 err = iDevice->CreateContext(iGc); |
|
974 } |
|
975 } |
|
976 DoRotate(); |
|
977 |
|
978 return err; |
|
979 } |
|
980 |
|
981 /** |
|
982 This function is called by the Active Scheduler |
|
983 to perform the rotate operation |
|
984 |
|
985 */ |
|
986 void CPeninputSyncBitmapRotator::DoRotate() |
|
987 { |
|
988 while (iCurOffset < iRows) |
|
989 { |
|
990 switch (iAngle) |
|
991 { |
|
992 // Rotation of 90 degrees |
|
993 case CBitmapRotator::ERotation90DegreesClockwise: |
|
994 { |
|
995 iSrcBitmap->GetVerticalScanLine(iScanlineDes, iCurOffset, iScanlineDisplayMode); |
|
996 FlipScanLine(iScanlineDes, iTgtBitmap->SizeInPixels().iWidth); |
|
997 PutScanline(iCurOffset); |
|
998 break; |
|
999 } |
|
1000 |
|
1001 // Rotation of 180 degrees |
|
1002 case CBitmapRotator::ERotation180DegreesClockwise: |
|
1003 { |
|
1004 iSrcBitmap->GetScanLine(iScanlineDes,TPoint(0, iCurOffset), iBitmapSize.iWidth, iScanlineDisplayMode); |
|
1005 FlipScanLine(iScanlineDes, iBitmapSize.iWidth); |
|
1006 PutScanline(iBitmapSize.iHeight - 1 - iCurOffset); |
|
1007 break; |
|
1008 } |
|
1009 |
|
1010 // Rotation of 270 degrees |
|
1011 case CBitmapRotator::ERotation270DegreesClockwise: |
|
1012 { |
|
1013 iSrcBitmap->GetVerticalScanLine(iScanlineDes, iCurOffset, iScanlineDisplayMode); |
|
1014 PutScanline(iBitmapSize.iWidth - 1 - iCurOffset); |
|
1015 break; |
|
1016 } |
|
1017 |
|
1018 // Flip about the vertical Axis |
|
1019 case CBitmapRotator::EMirrorVerticalAxis: |
|
1020 { |
|
1021 iSrcBitmap->GetScanLine(iScanlineDes,TPoint(0,iCurOffset),iBitmapSize.iWidth,iScanlineDisplayMode); |
|
1022 FlipScanLine(iScanlineDes, iBitmapSize.iWidth); |
|
1023 PutScanline(iCurOffset); |
|
1024 break; |
|
1025 } |
|
1026 |
|
1027 // Flip about the horizontal axis |
|
1028 case CBitmapRotator::EMirrorHorizontalAxis: |
|
1029 { |
|
1030 iSrcBitmap->GetScanLine(iScanlineDes,TPoint(0,iCurOffset),iBitmapSize.iWidth,iScanlineDisplayMode); |
|
1031 PutScanline(iBitmapSize.iHeight-1-iCurOffset); |
|
1032 break; |
|
1033 } |
|
1034 |
|
1035 default: |
|
1036 { |
|
1037 ASSERT( EFalse ); |
|
1038 } |
|
1039 } |
|
1040 |
|
1041 iCurOffset++; |
|
1042 } |
|
1043 |
|
1044 if (iCurOffset == iRows) |
|
1045 { |
|
1046 if (iTempBitmap) |
|
1047 { |
|
1048 iSrcBitmap->Duplicate(iTgtBitmap->Handle()); |
|
1049 } |
|
1050 Cleanup(); |
|
1051 } |
|
1052 } |
|
1053 |
|
1054 /** |
|
1055 template function that can be used for swapping of memory locations |
|
1056 of particular pointer type |
|
1057 @param ptr1 - pointer to value1 |
|
1058 @param ptr2 - pointer to value2 |
|
1059 */ |
|
1060 template <class T> |
|
1061 inline void SwapPixels(T* ptr1, T* ptr2) |
|
1062 { |
|
1063 T temp = *ptr1; |
|
1064 *ptr1 = *ptr2; |
|
1065 *ptr2 = temp; |
|
1066 } |
|
1067 |
|
1068 /** |
|
1069 template function that can be used for mirroring of linear |
|
1070 memory location of a particular scalar type |
|
1071 @param aScanLinePtr location address |
|
1072 @param aWidth width of location in elements, not bytes |
|
1073 */ |
|
1074 template <class T> |
|
1075 inline void FlipLine(TUint8* aScanLinePtr, TInt aWidth) |
|
1076 { |
|
1077 T* startPixelPtr = reinterpret_cast<T*>(aScanLinePtr); |
|
1078 T* endPixelPtr = startPixelPtr + aWidth - 1; |
|
1079 if (aWidth&1) |
|
1080 { |
|
1081 SwapPixels(startPixelPtr++, endPixelPtr--); |
|
1082 } |
|
1083 while (startPixelPtr < endPixelPtr) |
|
1084 { |
|
1085 SwapPixels(startPixelPtr++, endPixelPtr--); |
|
1086 SwapPixels(startPixelPtr++, endPixelPtr--); |
|
1087 } |
|
1088 } |
|
1089 |
|
1090 /** |
|
1091 This function flips a scan line buffer of width aWidth |
|
1092 PreConditions: |
|
1093 aWidth >= 0 && aWidth is the length of the buffer |
|
1094 aDes is a reference to a buffer of rgb pixels |
|
1095 Postcondition: |
|
1096 The contents of the buffer have flipped about the buffers centre |
|
1097 |
|
1098 @param TDes8 aDes |
|
1099 reference to a buffer of rgb pixels of lenth aWidth |
|
1100 @param Tint aWidth |
|
1101 is the width of the buffer |
|
1102 |
|
1103 */ |
|
1104 void CPeninputSyncBitmapRotator::FlipScanLine(TDes8& aDes, TInt aWidth) |
|
1105 { |
|
1106 //[ assert consistency between descriptor length and width ] |
|
1107 ASSERT( (aDes.Length() == (iPixelSizeInBytes * aWidth) )); |
|
1108 |
|
1109 TUint8* const scanLinePtr=const_cast<TUint8*>(aDes.Ptr()); |
|
1110 |
|
1111 switch (iPixelSizeInBytes) |
|
1112 { |
|
1113 case 4: |
|
1114 { |
|
1115 FlipLine<TUint32>(scanLinePtr, aWidth); |
|
1116 } |
|
1117 break; |
|
1118 case 3: |
|
1119 { |
|
1120 TUint8* startPixelPtr = scanLinePtr; |
|
1121 TUint8* endPixelPtr = startPixelPtr + (aWidth - 1)*iPixelSizeInBytes; |
|
1122 while (startPixelPtr < endPixelPtr) |
|
1123 { |
|
1124 TUint8 temp0 = startPixelPtr[0]; |
|
1125 TUint8 temp1 = startPixelPtr[1]; |
|
1126 TUint8 temp2 = startPixelPtr[2]; |
|
1127 startPixelPtr[0] = endPixelPtr[0]; |
|
1128 startPixelPtr[1] = endPixelPtr[1]; |
|
1129 startPixelPtr[2] = endPixelPtr[2]; |
|
1130 endPixelPtr[0] = temp0; |
|
1131 endPixelPtr[1] = temp1; |
|
1132 endPixelPtr[2] = temp2; |
|
1133 startPixelPtr += iPixelSizeInBytes; |
|
1134 endPixelPtr -= iPixelSizeInBytes; |
|
1135 } |
|
1136 } |
|
1137 break; |
|
1138 case 2: |
|
1139 { |
|
1140 FlipLine<TUint16>(scanLinePtr, aWidth); |
|
1141 } |
|
1142 break; |
|
1143 case 1: |
|
1144 { |
|
1145 FlipLine<TUint8>(scanLinePtr, aWidth); |
|
1146 } |
|
1147 break; |
|
1148 |
|
1149 default: |
|
1150 ASSERT(EFalse); |
|
1151 } |
|
1152 } |
|
1153 |
|
1154 void CPeninputSyncBitmapRotator::PutScanline(TInt aYPos) |
|
1155 { |
|
1156 if (iScanlineBitmap) |
|
1157 { |
|
1158 iScanlineBitmap->SetScanLine(iScanlineDes, 0); |
|
1159 iGc->BitBlt(TPoint(0, aYPos), iScanlineBitmap); |
|
1160 } |
|
1161 else |
|
1162 { |
|
1163 iTgtBitmap->SetScanLine(iScanlineDes, aYPos); |
|
1164 } |
|
1165 } |
|
1166 |
|
1167 |
|
1168 EXPORT_C TBool AknPenInputTrailColorUtils::CheckColorInColorTable(TInt color) |
|
1169 { |
|
1170 for (TInt i = 0; i < ColorCount(); i++) |
|
1171 { |
|
1172 if (ColorAt(i).Value() == color) |
|
1173 { |
|
1174 return ETrue; |
|
1175 } |
|
1176 } |
|
1177 return EFalse; |
|
1178 } |
|
1179 |
|
1180 EXPORT_C TInt AknPenInputTrailColorUtils::ColorCount() |
|
1181 { |
|
1182 const TRgb KRgbArray[] = |
|
1183 { |
|
1184 KRgbBlack, |
|
1185 KRgbDarkGray, |
|
1186 KRgbDarkRed, |
|
1187 KRgbDarkGreen, |
|
1188 KRgbDarkYellow, |
|
1189 KRgbDarkBlue, |
|
1190 KRgbDarkMagenta, |
|
1191 KRgbDarkCyan, |
|
1192 KRgbRed, |
|
1193 KRgbGreen, |
|
1194 KRgbYellow, |
|
1195 KRgbBlue, |
|
1196 KRgbMagenta, |
|
1197 KRgbCyan, |
|
1198 KRgbGray, |
|
1199 KRgbWhite |
|
1200 }; |
|
1201 |
|
1202 return sizeof(KRgbArray)/sizeof(TRgb); |
|
1203 } |
|
1204 |
|
1205 EXPORT_C TRgb AknPenInputTrailColorUtils::ColorAt(TInt aIndex) |
|
1206 { |
|
1207 const TRgb KRgbArray[] = |
|
1208 { |
|
1209 KRgbBlack, |
|
1210 KRgbDarkGray, |
|
1211 KRgbDarkRed, |
|
1212 KRgbDarkGreen, |
|
1213 KRgbDarkYellow, |
|
1214 KRgbDarkBlue, |
|
1215 KRgbDarkMagenta, |
|
1216 KRgbDarkCyan, |
|
1217 KRgbRed, |
|
1218 KRgbGreen, |
|
1219 KRgbYellow, |
|
1220 KRgbBlue, |
|
1221 KRgbMagenta, |
|
1222 KRgbCyan, |
|
1223 KRgbGray, |
|
1224 KRgbWhite |
|
1225 }; |
|
1226 |
|
1227 if((aIndex >=0) && (aIndex < ColorCount())) |
|
1228 return KRgbArray[aIndex]; |
|
1229 else |
|
1230 return KRgbArray[0]; |
|
1231 } |
|
1232 EXPORT_C TInt AknPenInputTrailColorUtils::GetTrailColorByTheme() |
|
1233 { |
|
1234 TRgb color(0x000000); |
|
1235 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
1236 color, KAknsIIDQsnOtherColors, EAknsCIQsnOtherColorsCG20 ); |
|
1237 return color.Value(); |
|
1238 |
|
1239 } |
|
1240 |
|
1241 // End Of File |