|
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 title pane picture factory. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "Pbk2TitlePanePictureFactory.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2UIExtensionManager.h" |
|
23 #include "MPbk2UIExtensionIconSupport.h" |
|
24 #include <CPbk2IconArray.h> |
|
25 #include <CPbk2StoreProperty.h> |
|
26 #include <CPbk2StorePropertyArray.h> |
|
27 #include <CPbk2StoreViewDefinition.h> |
|
28 #include <Pbk2UIControls.rsg> |
|
29 |
|
30 // Virtual Phonebook |
|
31 #include <CVPbkContactViewDefinition.h> |
|
32 #include <MVPbkContactStore.h> |
|
33 #include <MVPbkContactStoreProperties.h> |
|
34 #include <MVPbkStoreContact.h> |
|
35 #include <VPbkContactView.hrh> |
|
36 |
|
37 // System includes |
|
38 #include <AknIconUtils.h> |
|
39 #include <aknlayoutscalable_avkon.cdl.h> |
|
40 #include <akntitle.h> |
|
41 #include <AknUtils.h> |
|
42 #include <barsread.h> |
|
43 #include <gulicon.h> |
|
44 |
|
45 |
|
46 /// Unnamed namespace for local definitions |
|
47 namespace { |
|
48 |
|
49 /** |
|
50 * Creates icon array. |
|
51 * |
|
52 * @return Icon array. |
|
53 */ |
|
54 CPbk2IconArray* CreateIconArrayLC() |
|
55 { |
|
56 CPbk2IconArray* iconArray = NULL; |
|
57 TResourceReader reader; |
|
58 CCoeEnv::Static()-> |
|
59 CreateResourceReaderLC( reader, R_PBK2_CONTACT_LIST_ICONS ); |
|
60 |
|
61 // Create icon array |
|
62 iconArray = CPbk2IconArray::NewL( reader ); |
|
63 CleanupStack::PopAndDestroy(); // reader |
|
64 CleanupStack::PushL( iconArray ); |
|
65 |
|
66 // Add icons from UI extensions |
|
67 CPbk2UIExtensionManager* extManager = |
|
68 CPbk2UIExtensionManager::InstanceL(); |
|
69 extManager->PushL(); |
|
70 extManager->IconSupportL().AppendExtensionIconsL( *iconArray ); |
|
71 |
|
72 CleanupStack::PopAndDestroy( extManager ); |
|
73 |
|
74 return iconArray; |
|
75 } |
|
76 |
|
77 } /// namespace |
|
78 |
|
79 |
|
80 // -------------------------------------------------------------------------- |
|
81 // Pbk2TitlePanePictureFactory::CreateTitlePanePictureL |
|
82 // -------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C CEikImage* Pbk2TitlePanePictureFactory::CreateTitlePanePictureLC |
|
85 ( const MVPbkStoreContact* aContact, |
|
86 CPbk2StorePropertyArray& aStoreProperties ) |
|
87 { |
|
88 CEikImage* image = new ( ELeave ) CEikImage; |
|
89 CleanupStack::PushL( image ); |
|
90 |
|
91 CPbk2IconArray* iconArray = CreateIconArrayLC(); |
|
92 |
|
93 // Get icon index |
|
94 TInt index = KErrNotFound; |
|
95 TVPbkContactStoreUriPtr uri = |
|
96 aContact->ParentStore().StoreProperties().Uri(); |
|
97 const CPbk2StoreProperty* |
|
98 storeProperty = aStoreProperties.FindProperty( uri ); |
|
99 |
|
100 if( storeProperty ) |
|
101 { |
|
102 TArray<const CPbk2StoreViewDefinition*> |
|
103 views = storeProperty->Views(); |
|
104 TInt count = views.Count(); |
|
105 TInt i = 0; |
|
106 for( i = 0; i < count && index == KErrNotFound; i++ ) |
|
107 { |
|
108 if( views[i]->ViewDefinition().Type() == EVPbkContactsView ) |
|
109 { |
|
110 const TPbk2IconId& id = views[i]->ViewItemIconId(); |
|
111 index = iconArray->FindIcon( id ); |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 if( index >= 0 ) |
|
117 { |
|
118 // Get pointers to bitmaps in array |
|
119 CFbsBitmap* bitmap = iconArray->At( index )->Bitmap(); |
|
120 CFbsBitmap* mask = iconArray->At( index )->Mask(); |
|
121 |
|
122 // Calculate icon size |
|
123 TRect mainPane; |
|
124 AknLayoutUtils::LayoutMetricsRect( |
|
125 AknLayoutUtils::ETitlePane, mainPane ); |
|
126 TAknLayoutRect titleIconPaneLayoutRect; |
|
127 titleIconPaneLayoutRect.LayoutRect( |
|
128 mainPane, |
|
129 AknLayoutScalable_Avkon::title_pane_g2( 0 ).LayoutLine() ); |
|
130 TSize iconSize = titleIconPaneLayoutRect.Rect().Size(); |
|
131 User::LeaveIfError( AknIconUtils::SetSize( bitmap, iconSize ) ); |
|
132 |
|
133 // Create duplicates of the icon to be used |
|
134 CFbsBitmap* pBitmap = new( ELeave ) CFbsBitmap(); |
|
135 CleanupStack::PushL( pBitmap ); |
|
136 User::LeaveIfError( pBitmap->Duplicate( bitmap->Handle() ) ); |
|
137 CFbsBitmap* pMask = new( ELeave ) CFbsBitmap(); |
|
138 CleanupStack::PushL( pMask ); |
|
139 User::LeaveIfError( pMask->Duplicate( mask->Handle() ) ); |
|
140 CleanupStack::Pop( 2 ); // pBitmap, pMask |
|
141 |
|
142 // Transfer ownership to the image |
|
143 image->SetBitmap( pBitmap ); |
|
144 image->SetMask( pMask ); |
|
145 } |
|
146 |
|
147 CleanupStack::PopAndDestroy( iconArray ); |
|
148 return image; |
|
149 } |
|
150 |
|
151 // End of File |