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: bitmap db manager,which is used by drop down list |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <w32std.h> |
|
21 #include <fbs.h> |
|
22 #include <peninputlayoutbasecontrol.h> |
|
23 #include <peninputlayout.h> |
|
24 #include <aknenv.h> |
|
25 #include "peninputbitmapdb.h" |
|
26 |
|
27 const TUint32 KDefaultTextColor = 0x000000; |
|
28 const TUint32 KDefaultFrameColor = 0x000000; |
|
29 |
|
30 const TInt KInvalidBmp = -1; |
|
31 |
|
32 const TInt KTransparency[256] = |
|
33 { |
|
34 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, |
|
35 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13, |
|
36 14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 19, |
|
37 19, 19, 20, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 23, 24, 24, |
|
38 24, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 29, |
|
39 30, 30, 30, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, |
|
40 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 40, 40, 40, |
|
41 41, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46, |
|
42 46, 46, 47, 47, 47, 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 50, 51, 51, |
|
43 51, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 56, |
|
44 57, 57, 57, 58, 58, 58, 59, 59, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62, |
|
45 62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 67, 67, 67, |
|
46 68, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 71, 72, 72, 72, 73, |
|
47 73, 73, 74, 74, 74, 74, 75, 75, 75, 76, 76, 76, 77, 77 |
|
48 }; |
|
49 |
|
50 // ======== MEMBER FUNCTIONS ======== |
|
51 |
|
52 // Implementation of Class CBitmapDb |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CBitmapDb::NewL |
|
56 // factory function |
|
57 // (other items were commented in a header). |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CBitmapDb* CBitmapDb::NewL(TResourceReader& aReader, |
|
61 TSize aBitmapSize, |
|
62 TSize aExpandSize, |
|
63 TSize aSpinBtnSize) |
|
64 { |
|
65 CBitmapDb* self = new (ELeave) CBitmapDb(); |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(aReader, |
|
68 aBitmapSize, |
|
69 aExpandSize, |
|
70 aSpinBtnSize); |
|
71 CleanupStack::Pop(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CBitmapDb::~CBitmapDb |
|
77 // destructor function |
|
78 // (other items were commented in a header). |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CBitmapDb::~CBitmapDb() |
|
82 { |
|
83 // Delete all bitmap |
|
84 iBmpList.ResetAndDestroy(); |
|
85 iBmpList.Close(); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CBitmapDb::GetBitMap |
|
90 // get bitmap according to the assigned type |
|
91 // (other items were commented in a header). |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 const CFbsBitmap* CBitmapDb::GetBitMap(const TBitmapType aType) |
|
95 { |
|
96 // Return corresponding bitmap according aType |
|
97 return iBmpList[aType]; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CBitmapDb::CreateIconL |
|
102 // (other items were commented in a header). |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CBitmapDb::CreateIconL(const TDesC& aBmpFileName, |
|
106 TAknsItemID aId, |
|
107 CFbsBitmap** aBmp, |
|
108 CFbsBitmap** aMaskBmp, |
|
109 TInt aBmpId, |
|
110 TInt aMaskBmpId, |
|
111 TSize aSize, |
|
112 TBool aColorIcon) |
|
113 { |
|
114 if (aBmpId != KInvalidBmp) |
|
115 { |
|
116 if (aMaskBmpId != KInvalidBmp) |
|
117 { |
|
118 if (aColorIcon) |
|
119 { |
|
120 AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(), |
|
121 aId, |
|
122 KAknsIIDQsnIconColors, |
|
123 EAknsCIQsnIconColorsCG30, |
|
124 *aBmp, |
|
125 *aMaskBmp, |
|
126 aBmpFileName, |
|
127 aBmpId, |
|
128 aMaskBmpId, |
|
129 AKN_LAF_COLOR( 0 ) ); |
|
130 } |
|
131 else |
|
132 { |
|
133 AknsUtils::CreateIconL(AknsUtils::SkinInstance(), |
|
134 aId, |
|
135 *aBmp, |
|
136 *aMaskBmp, |
|
137 aBmpFileName, |
|
138 aBmpId, |
|
139 aMaskBmpId); |
|
140 } |
|
141 |
|
142 AknIconUtils::SetSize(*aMaskBmp, aSize, EAspectRatioNotPreserved); |
|
143 } |
|
144 else |
|
145 { |
|
146 AknsUtils::CreateIconL(AknsUtils::SkinInstance(), |
|
147 aId, |
|
148 *aBmp, |
|
149 aBmpFileName, |
|
150 aBmpId); |
|
151 } |
|
152 |
|
153 AknIconUtils::SetSize(*aBmp, aSize, EAspectRatioNotPreserved); |
|
154 } |
|
155 } |
|
156 |
|
157 void CBitmapDb::ConstructFromResourceL(TResourceReader& aReader, |
|
158 TSize aBitmapSize, |
|
159 TSize aExpandSize, |
|
160 TSize aSpinBtnSize) |
|
161 { |
|
162 for (TInt i = 0; i < EBitmapLastType + 1; ++i) |
|
163 { |
|
164 delete iBmpList[i]; |
|
165 iBmpList[i] = NULL; |
|
166 } |
|
167 |
|
168 // Read mbm file name from the aReader |
|
169 TPtrC bmpFile = aReader.ReadTPtrC(); |
|
170 TInt imgMajorSkinId = aReader.ReadInt32(); |
|
171 |
|
172 TAknsItemID id; |
|
173 |
|
174 for (TInt i = 0; i < EBitmapLastType + 1; i+=2) |
|
175 { |
|
176 TInt bmpId = aReader.ReadInt16(); |
|
177 TInt maskId = aReader.ReadInt16(); |
|
178 TInt minorSkinId = aReader.ReadInt16(); |
|
179 |
|
180 TSize bmpsize = aBitmapSize; |
|
181 |
|
182 if ((i >= EBitmapNextDisable && i < EBitmapNextPressMask) || |
|
183 (i >= EBitmapPrevious && i < EBitmapPreviousPressMask)) |
|
184 { |
|
185 bmpsize = aSpinBtnSize; |
|
186 } |
|
187 else if (i >= EBitmapExpand && i < EBitmapExpandPressMask) |
|
188 { |
|
189 bmpsize = aExpandSize; |
|
190 } |
|
191 |
|
192 id.Set(imgMajorSkinId, minorSkinId); |
|
193 |
|
194 TBool colorIcon; |
|
195 if ( i == EBitmapNext || i == EBitmapNextMask || |
|
196 i == EBitmapClose || i == EBitmapCloseMask || |
|
197 i == EBitmapPrevious || i == EBitmapPreviousMask || |
|
198 i == EBitmapExpand || i == EBitmapExpandMask) |
|
199 { |
|
200 colorIcon = ETrue; |
|
201 } |
|
202 else |
|
203 { |
|
204 colorIcon = EFalse; |
|
205 } |
|
206 |
|
207 CreateIconL(bmpFile, |
|
208 id, |
|
209 &(iBmpList[i]), |
|
210 &(iBmpList[i+1]), |
|
211 bmpId, |
|
212 maskId, |
|
213 bmpsize, |
|
214 colorIcon); |
|
215 |
|
216 if( i == EBitmapNextDisable ) |
|
217 { |
|
218 CFbsBitmap* newMask = NULL; |
|
219 CreateDimmedMaskL( newMask, iBmpList[i+1]); |
|
220 delete iBmpList[i+1]; |
|
221 iBmpList[i+1] = newMask; |
|
222 } |
|
223 } |
|
224 |
|
225 TInt colorMajorSkinId = aReader.ReadInt32(); |
|
226 TInt skinitemid = aReader.ReadInt16(); |
|
227 TInt textcoloridx = aReader.ReadInt16(); |
|
228 |
|
229 id.Set(colorMajorSkinId, skinitemid); |
|
230 TInt error = AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), |
|
231 iTextColor, |
|
232 id, |
|
233 textcoloridx); |
|
234 |
|
235 if (error != KErrNone) |
|
236 { |
|
237 iTextColor = TRgb(KDefaultTextColor); |
|
238 } |
|
239 |
|
240 TInt frameMajorSkinId = aReader.ReadInt32(); |
|
241 skinitemid = aReader.ReadInt16(); |
|
242 TInt framecoloridx = aReader.ReadInt16(); |
|
243 |
|
244 id.Set(frameMajorSkinId, skinitemid); |
|
245 error = AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), |
|
246 iFrameColor, |
|
247 id, |
|
248 framecoloridx); |
|
249 |
|
250 if (error != KErrNone) |
|
251 { |
|
252 iFrameColor = TRgb(KDefaultFrameColor); |
|
253 } |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CBitmapDb::ConstructL |
|
258 // 2nd construct function |
|
259 // (other items were commented in a header). |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 void CBitmapDb::ConstructL(TResourceReader& aReader, |
|
263 TSize aBitmapSize, |
|
264 TSize aExpandSize, |
|
265 TSize aSpinBtnSize) |
|
266 { |
|
267 for (TInt i = 0; i < EBitmapLastType + 1; ++i) |
|
268 { |
|
269 iBmpList.AppendL(NULL); |
|
270 } |
|
271 |
|
272 ConstructFromResourceL(aReader, |
|
273 aBitmapSize, |
|
274 aExpandSize, |
|
275 aSpinBtnSize); |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CBitmapDb::TextColor |
|
280 // Get text color of drop down list |
|
281 // (other items were commented in a header). |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 const TRgb CBitmapDb::TextColor() |
|
285 { |
|
286 return iTextColor; |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CBitmapDb::FrameColor |
|
291 // Get frame color of drop down list |
|
292 // (other items were commented in a header). |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 const TRgb CBitmapDb::FrameColor() |
|
296 { |
|
297 return iFrameColor; |
|
298 } |
|
299 // --------------------------------------------------------------------------- |
|
300 // CBitmapDb::CreateDimmedMaskL |
|
301 // This methods shall be called by the container's SizeChanged handler |
|
302 // (other items were commented in a header). |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 void CBitmapDb::CreateDimmedMaskL( CFbsBitmap*& aDimmedMask, |
|
306 const CFbsBitmap* aMask |
|
307 /*TScaleMode aScaleMode*/ ) |
|
308 { |
|
309 if (aMask && aMask->DisplayMode() == EGray256) |
|
310 { |
|
311 delete aDimmedMask; |
|
312 aDimmedMask = NULL; |
|
313 |
|
314 aDimmedMask = new (ELeave) CFbsBitmap; |
|
315 |
|
316 User::LeaveIfError(aDimmedMask->Create(aMask->SizeInPixels(), EGray256)); |
|
317 CleanupStack::PushL(aDimmedMask); |
|
318 |
|
319 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(aDimmedMask); |
|
320 CleanupStack::PushL(bitmapDevice); |
|
321 |
|
322 CFbsBitGc* bitGc(NULL); |
|
323 User::LeaveIfError(bitmapDevice->CreateContext(bitGc)); |
|
324 CleanupStack::PushL(bitGc); |
|
325 |
|
326 bitGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
327 bitGc->BitBlt(TPoint(0, 0), aMask); |
|
328 |
|
329 aDimmedMask->LockHeap(); |
|
330 TInt w = aMask->SizeInPixels().iWidth; |
|
331 TInt h = aMask->SizeInPixels().iHeight; |
|
332 TInt dataStride = aMask->DataStride() - w; |
|
333 unsigned char* address = (unsigned char *)aDimmedMask->DataAddress(); |
|
334 |
|
335 for ( TInt i = 0; i < h; ++i ) |
|
336 { |
|
337 for ( TInt j = 0; j < w; ++j ) |
|
338 { |
|
339 *address = KTransparency[*address]; |
|
340 ++address; |
|
341 } |
|
342 address += dataStride; |
|
343 } |
|
344 |
|
345 aDimmedMask->UnlockHeap(); |
|
346 |
|
347 //AknIconUtils::SetSize(aDimmedMask, aMask->SizeInPixels(), aScaleMode); |
|
348 |
|
349 CleanupStack::PopAndDestroy(2); // bitmapDevice, bitGc |
|
350 CleanupStack::Pop(1); // aDimmedMask |
|
351 } |
|
352 |
|
353 } |
|
354 |
|
355 void CBitmapDb::SizeChanged(TSize aSize) |
|
356 { |
|
357 for (TInt i = 0; i < iBmpList.Count(); i++) |
|
358 { |
|
359 AknIconUtils::SetSize(iBmpList[i], aSize, EAspectRatioNotPreserved); |
|
360 } |
|
361 // dimmed mask can't use AknIconUtils::SetSize change its size. |
|
362 if( iBmpList[EBitmapNextDisableMask] && iBmpList[EBitmapNextMask] ) |
|
363 { |
|
364 CFbsBitmap* newMask = NULL; |
|
365 TRAP_IGNORE(CreateDimmedMaskL( newMask, iBmpList[EBitmapNextMask])); |
|
366 delete iBmpList[EBitmapNextDisableMask]; |
|
367 iBmpList[EBitmapNextDisableMask] = newMask; |
|
368 } |
|
369 } |
|
370 // End Of File |
|