|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Phonebook 2 icon factory. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <CPbk2IconFactory.h> |
|
20 |
|
21 // Phonebook2 |
|
22 #include "CPbk2IconInfo.h" |
|
23 #include <RPbk2LocalizedResourceFile.h> |
|
24 #include <Pbk2DataCaging.hrh> |
|
25 #include <Pbk2CommonUi.rsg> |
|
26 #include <CPbk2IconInfoContainer.h> |
|
27 |
|
28 // System includes |
|
29 #include <AknUtils.h> |
|
30 #include <aknlayoutscalable_avkon.cdl.h> |
|
31 #include <AknsUtils.h> |
|
32 #include <aknenv.h> |
|
33 #include <barsread.h> |
|
34 #include <gulicon.h> |
|
35 |
|
36 #include <CPbk2ServiceManager.h> |
|
37 #include <MPbk2ApplicationServices.h> |
|
38 #include <CPbk2ApplicationServices.h> |
|
39 // Debugging headers |
|
40 #include <Pbk2Debug.h> |
|
41 |
|
42 /// Unnamed namespace for local definitions |
|
43 namespace { |
|
44 |
|
45 _LIT( KPbk2CommonUiResFile, "Pbk2CommonUi.rsc" ); |
|
46 |
|
47 /** |
|
48 * Creates a bitmap from given icon info using Avkon services. |
|
49 * |
|
50 * @param aSkin Skin instance. |
|
51 * @param aBitmap Created bitmap. |
|
52 * @param aMask Created mask. |
|
53 * @param aIconInfo Icon information. |
|
54 */ |
|
55 void CreateBitmapsLC( |
|
56 MAknsSkinInstance* aSkin, |
|
57 CFbsBitmap*& aBitmap, |
|
58 CFbsBitmap*& aMask, |
|
59 const CPbk2IconInfo& aIconInfo ) |
|
60 { |
|
61 //Instantiate external bitmaps. We use rather graceful approach because we're |
|
62 //handling external bitmaps. So if problems we don't leave and paralyse system |
|
63 //but just try to continue if possible. |
|
64 if (aIconInfo.IsIconExternal() ) |
|
65 { |
|
66 //Check external bitmaps really exist |
|
67 if(!aIconInfo.ExternalBitmap() || !aIconInfo.ExternalMask()) |
|
68 { |
|
69 User::Leave(KErrBadHandle); |
|
70 } |
|
71 |
|
72 //Calculate size for external icon |
|
73 TSize size = aIconInfo.ExternalIconSize(); |
|
74 |
|
75 //Try to instantiate ext bitmaps if not yet done, otherwise duplicating fails |
|
76 if(!aIconInfo.ExternalBitmap()->Handle()) |
|
77 { |
|
78 CFbsBitmap* tmp = const_cast<CFbsBitmap*>(aIconInfo.ExternalBitmap()); |
|
79 AknIconUtils::SetSize( tmp, size ); |
|
80 tmp = const_cast<CFbsBitmap*>(aIconInfo.ExternalMask()); |
|
81 AknIconUtils::SetSize( tmp, size ); |
|
82 } |
|
83 |
|
84 //Create bitmaps and try to duplicate their handles to point to external bitmaps |
|
85 aBitmap = new( ELeave ) CFbsBitmap(); |
|
86 CleanupStack::PushL( aBitmap ); |
|
87 aMask = new( ELeave ) CFbsBitmap(); |
|
88 CleanupStack::PushL( aMask ); |
|
89 aBitmap->Duplicate( aIconInfo.ExternalBitmap()->Handle() ); |
|
90 aMask->Duplicate( aIconInfo.ExternalMask()->Handle() ); |
|
91 |
|
92 //Try always to set size as ext icon may have been used by some other app too. |
|
93 AknIconUtils::SetSize( aBitmap, size ); |
|
94 AknIconUtils::SetSize( aMask, size ); |
|
95 return; |
|
96 } |
|
97 |
|
98 if ( aIconInfo.ColorId() == KAknsIIDNone ) |
|
99 { |
|
100 AknsUtils::CreateIconLC( |
|
101 aSkin, aIconInfo.SkinId(), aBitmap, aMask, |
|
102 aIconInfo.MbmFileName(), |
|
103 aIconInfo.IconId(), aIconInfo.MaskId() ); |
|
104 } |
|
105 else |
|
106 { |
|
107 AknsUtils::CreateColorIconLC( |
|
108 aSkin, aIconInfo.SkinId(), |
|
109 aIconInfo.ColorId(), aIconInfo.ColorIndex(), |
|
110 aBitmap, aMask, |
|
111 aIconInfo.MbmFileName(), |
|
112 aIconInfo.IconId(), aIconInfo.MaskId(), |
|
113 AKN_LAF_COLOR_STATIC( aIconInfo.DefaultColorIndex() ) ); |
|
114 } |
|
115 } |
|
116 |
|
117 /** |
|
118 * Creates a bitmap from given icon info using Avkon services. |
|
119 * |
|
120 * @param aSkin Skin instance. |
|
121 * @param aBitmap Created bitmap. |
|
122 * @param aMask Created mask. |
|
123 * @param aIconInfo Icon information. |
|
124 */ |
|
125 void CreateBitmapsL( |
|
126 MAknsSkinInstance* aSkin, |
|
127 CFbsBitmap*& aBitmap, |
|
128 CFbsBitmap*& aMask, |
|
129 const CPbk2IconInfo& aIconInfo ) |
|
130 { |
|
131 CreateBitmapsLC( aSkin, aBitmap, aMask, aIconInfo ); |
|
132 CleanupStack::Pop( 2 ); // bitmap, mask |
|
133 } |
|
134 |
|
135 } /// namespace |
|
136 |
|
137 // -------------------------------------------------------------------------- |
|
138 // CPbk2IconFactory::CPbk2IconFactory |
|
139 // -------------------------------------------------------------------------- |
|
140 // |
|
141 CPbk2IconFactory::CPbk2IconFactory( |
|
142 const CPbk2IconInfoContainer* aIconContainer ) : |
|
143 iIconContainer( aIconContainer ) |
|
144 { |
|
145 } |
|
146 |
|
147 // -------------------------------------------------------------------------- |
|
148 // CPbk2IconFactory::~CPbk2IconFactory |
|
149 // -------------------------------------------------------------------------- |
|
150 // |
|
151 CPbk2IconFactory::~CPbk2IconFactory() |
|
152 { |
|
153 delete iAllIconsContainer; |
|
154 Release( iAppServices ); |
|
155 } |
|
156 |
|
157 // -------------------------------------------------------------------------- |
|
158 // CPbk2IconFactory::NewLC |
|
159 // -------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C CPbk2IconFactory* CPbk2IconFactory::NewL() |
|
162 { |
|
163 CPbk2IconFactory* self = NewLC(); |
|
164 CleanupStack::Pop( self ); |
|
165 return self; |
|
166 } |
|
167 |
|
168 // -------------------------------------------------------------------------- |
|
169 // CPbk2IconFactory::NewLC |
|
170 // -------------------------------------------------------------------------- |
|
171 // |
|
172 EXPORT_C CPbk2IconFactory* CPbk2IconFactory::NewLC() |
|
173 { |
|
174 CPbk2IconFactory* self = new( ELeave ) CPbk2IconFactory( NULL ); |
|
175 CleanupStack::PushL( self ); |
|
176 self->ConstructL(); |
|
177 return self; |
|
178 } |
|
179 |
|
180 // -------------------------------------------------------------------------- |
|
181 // CPbk2IconFactory::NewL |
|
182 // -------------------------------------------------------------------------- |
|
183 // |
|
184 EXPORT_C CPbk2IconFactory* CPbk2IconFactory::NewL( |
|
185 const CPbk2IconInfoContainer& aIconContainer ) |
|
186 { |
|
187 CPbk2IconFactory* self = NewLC( aIconContainer ); |
|
188 CleanupStack::Pop( self ); |
|
189 return self; |
|
190 } |
|
191 |
|
192 // -------------------------------------------------------------------------- |
|
193 // CPbk2IconFactory::NewLC |
|
194 // -------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C CPbk2IconFactory* CPbk2IconFactory::NewLC( |
|
197 const CPbk2IconInfoContainer& aIconContainer ) |
|
198 { |
|
199 CPbk2IconFactory* self = new( ELeave ) |
|
200 CPbk2IconFactory( &aIconContainer ); |
|
201 CleanupStack::PushL( self ); |
|
202 return self; |
|
203 } |
|
204 |
|
205 // -------------------------------------------------------------------------- |
|
206 // CPbk2IconFactory::ConstructL |
|
207 // -------------------------------------------------------------------------- |
|
208 // |
|
209 void CPbk2IconFactory::ConstructL() |
|
210 { |
|
211 CCoeEnv& coeEnv = *CCoeEnv::Static(); |
|
212 |
|
213 RPbk2LocalizedResourceFile resFile( coeEnv ); |
|
214 resFile.OpenLC( KPbk2RomFileDrive, |
|
215 KDC_RESOURCE_FILES_DIR, KPbk2CommonUiResFile ); |
|
216 |
|
217 TResourceReader reader; |
|
218 coeEnv.CreateResourceReaderLC( reader, R_PBK2_ICON_INFO_ARRAY ); |
|
219 |
|
220 iAllIconsContainer = CPbk2IconInfoContainer::NewL( reader ); |
|
221 |
|
222 //Calculate preferred size for xsp service icons |
|
223 TRect mainPane; |
|
224 AknLayoutUtils::LayoutMetricsRect( |
|
225 AknLayoutUtils::EMainPane, mainPane ); |
|
226 TAknLayoutRect listLayoutRect; |
|
227 listLayoutRect.LayoutRect( |
|
228 mainPane, |
|
229 AknLayoutScalable_Avkon::list_single_graphic_pane_g1(0).LayoutLine() ); |
|
230 TSize size(listLayoutRect.Rect().Size()); |
|
231 |
|
232 // Add xsp service icons2 |
|
233 if ( !iAppServices ) |
|
234 { |
|
235 iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
236 } |
|
237 CPbk2ServiceManager& servMan( iAppServices->ServiceManager()); |
|
238 |
|
239 const CPbk2ServiceManager::RServicesArray& services = servMan.Services(); |
|
240 TUid uid; |
|
241 uid.iUid = KPbk2ServManId; |
|
242 for ( TInt i = 0; i < services.Count(); i++ ) |
|
243 { |
|
244 const CPbk2ServiceManager::TService& service = services[i]; |
|
245 if ( service.iBitmapId && service.iBitmap ) |
|
246 { |
|
247 TPbk2IconId id = TPbk2IconId( uid, services[i].iBitmapId ); |
|
248 CPbk2IconInfo* info = CPbk2IconInfo::NewLC( |
|
249 id, services[i].iBitmap, services[i].iMask, size ); |
|
250 iAllIconsContainer->AppendIconL(info); |
|
251 CleanupStack::Pop(info); |
|
252 } |
|
253 } |
|
254 |
|
255 CleanupStack::PopAndDestroy( 2 ); // resFile, reader |
|
256 iIconContainer = iAllIconsContainer; |
|
257 } |
|
258 |
|
259 // -------------------------------------------------------------------------- |
|
260 // CPbk2IconFactory::CreateIconL |
|
261 // -------------------------------------------------------------------------- |
|
262 // |
|
263 EXPORT_C CGulIcon* CPbk2IconFactory::CreateIconL( |
|
264 const TPbk2IconId& aIconId ) const |
|
265 { |
|
266 CGulIcon* icon = CreateIconLC( aIconId ); |
|
267 if ( icon ) |
|
268 { |
|
269 CleanupStack::Pop( icon ); |
|
270 } |
|
271 return icon; |
|
272 } |
|
273 |
|
274 // -------------------------------------------------------------------------- |
|
275 // CPbk2IconFactory::CreateIconLC |
|
276 // -------------------------------------------------------------------------- |
|
277 // |
|
278 EXPORT_C CGulIcon* CPbk2IconFactory::CreateIconLC( |
|
279 const TPbk2IconId& aIconId ) const |
|
280 { |
|
281 CGulIcon* icon = CGulIcon::NewLC(); |
|
282 |
|
283 const CPbk2IconInfo* iconInfo = iIconContainer->Find( aIconId ); |
|
284 |
|
285 if ( !iconInfo ) |
|
286 { |
|
287 return icon; |
|
288 } |
|
289 |
|
290 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
291 ("CPbk2IconInfoContainer::LoadBitmapL icon found")); |
|
292 |
|
293 icon->SetBitmapsOwnedExternally(EFalse); |
|
294 |
|
295 CFbsBitmap* bitmap = NULL; |
|
296 CFbsBitmap* mask = NULL; |
|
297 |
|
298 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
299 ("CPbk2IconInfoContainer::LoadBitmapL about to create icon")); |
|
300 |
|
301 CreateBitmapsL( AknsUtils::SkinInstance(), |
|
302 bitmap, mask, *iconInfo ); |
|
303 |
|
304 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
305 ( "CPbk2IconInfoContainer::LoadBitmapL icon create done" ) ); |
|
306 |
|
307 icon->SetBitmap(bitmap); |
|
308 icon->SetMask(mask); |
|
309 |
|
310 return icon; |
|
311 } |
|
312 |
|
313 // -------------------------------------------------------------------------- |
|
314 // CPbk2IconFactory::CreateIconL |
|
315 // -------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C void CPbk2IconFactory::CreateIconL( const TPbk2IconId& aIconId, |
|
318 MAknsSkinInstance& aSkin, CFbsBitmap*& aBitmap, CFbsBitmap*& aMask ) |
|
319 { |
|
320 CreateIconLC( aIconId, aSkin, aBitmap, aMask ); |
|
321 CleanupStack::Pop( 2 ); // aBitmap, aMask |
|
322 } |
|
323 |
|
324 // -------------------------------------------------------------------------- |
|
325 // CPbk2IconFactory::CreateIconLC |
|
326 // -------------------------------------------------------------------------- |
|
327 // |
|
328 EXPORT_C void CPbk2IconFactory::CreateIconLC( const TPbk2IconId& aIconId, |
|
329 MAknsSkinInstance& aSkin, CFbsBitmap*& aBitmap, CFbsBitmap*& aMask ) |
|
330 { |
|
331 const CPbk2IconInfo* iconInfo = iIconContainer->Find( aIconId ); |
|
332 if ( iconInfo ) |
|
333 { |
|
334 CreateBitmapsLC( &aSkin, aBitmap, aMask, *iconInfo ); |
|
335 } |
|
336 else |
|
337 { |
|
338 User::Leave( KErrNotFound ); |
|
339 } |
|
340 } |
|
341 |
|
342 // -------------------------------------------------------------------------- |
|
343 // CPbk2IconFactory::CreateImageL |
|
344 // -------------------------------------------------------------------------- |
|
345 // |
|
346 EXPORT_C CEikImage* CPbk2IconFactory::CreateImageL( |
|
347 const TPbk2IconId& aIconId ) const |
|
348 { |
|
349 CEikImage* image = CreateImageLC( aIconId ); |
|
350 if ( image ) |
|
351 { |
|
352 CleanupStack::Pop( image ); |
|
353 } |
|
354 return image; |
|
355 } |
|
356 |
|
357 // -------------------------------------------------------------------------- |
|
358 // CPbk2IconFactory::CreateImageLC |
|
359 // -------------------------------------------------------------------------- |
|
360 // |
|
361 EXPORT_C CEikImage* CPbk2IconFactory::CreateImageLC( |
|
362 const TPbk2IconId& aIconId ) const |
|
363 { |
|
364 CEikImage* image = NULL; |
|
365 const CPbk2IconInfo* iconInfo = iIconContainer->Find( aIconId ); |
|
366 if ( iconInfo ) |
|
367 { |
|
368 image = new(ELeave) CEikImage; |
|
369 CleanupStack::PushL( image ); |
|
370 |
|
371 CFbsBitmap* bitmap = NULL; |
|
372 CFbsBitmap* mask = NULL; |
|
373 |
|
374 CreateBitmapsL( AknsUtils::SkinInstance(), |
|
375 bitmap, mask, *iconInfo ); |
|
376 |
|
377 image->SetBitmap( bitmap ); |
|
378 image->SetMask( mask ); |
|
379 } |
|
380 |
|
381 return image; |
|
382 } |
|
383 |
|
384 // -------------------------------------------------------------------------- |
|
385 // CPbk2IconFactory::AppendIconL |
|
386 // -------------------------------------------------------------------------- |
|
387 // |
|
388 EXPORT_C void CPbk2IconFactory::AppendIconL( |
|
389 CPbk2IconInfo* aIconInfo ) |
|
390 { |
|
391 if( !iAllIconsContainer ) |
|
392 { |
|
393 ConstructL(); |
|
394 } |
|
395 |
|
396 iAllIconsContainer->AppendIconL(aIconInfo); |
|
397 iIconContainer = iAllIconsContainer; |
|
398 } |
|
399 |
|
400 // End of File |