|
1 /* |
|
2 * Copyright (c) 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: Implementation of MPX common container Texture Manager. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <alf/alftexturemanager.h> |
|
20 #include <fbs.h> |
|
21 #include <mpxlog.h> |
|
22 #include "mpxcommoncontainertexturemanager.h" |
|
23 |
|
24 // CONSTANTS |
|
25 |
|
26 // ---------------------------------------------------------------------------- |
|
27 // Constructor. |
|
28 // ---------------------------------------------------------------------------- |
|
29 // |
|
30 CMPXCommonContainerTextureManager::CMPXCommonContainerTextureManager( |
|
31 CAlfTextureManager& aTextureManager ) |
|
32 : iTextureManager( aTextureManager ) |
|
33 { |
|
34 // Set the TextureId range. Now we can set our own ID outside this Range |
|
35 iTextureManager.SetAutomaticTextureIdRange( |
|
36 KMPXFirstAlfThumbnailTextureId, |
|
37 KMPXLastAlfThumbnailTextureId); |
|
38 } |
|
39 |
|
40 // ---------------------------------------------------------------------------- |
|
41 // Destructor |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CMPXCommonContainerTextureManager::~CMPXCommonContainerTextureManager() |
|
45 { |
|
46 iTextureArray.Close(); |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // Creates texture from the specified bitmap and mask |
|
51 // ---------------------------------------------------------------------------- |
|
52 CAlfTexture& CMPXCommonContainerTextureManager::CreateTextureL( |
|
53 TInt aItemIndex, |
|
54 TMPXItemId aItemId, |
|
55 CFbsBitmap* aBitmap, |
|
56 CFbsBitmap* aMask ) |
|
57 { |
|
58 MPX_DEBUG1("CMPXCommonContainerTextureManager::CreateTextureL(): Entering"); |
|
59 |
|
60 // store the bitmaps and the item id for the ProvideBitmapL callback |
|
61 iTextureItem.iType = EMPXTextureImage; |
|
62 iTextureItem.iItemIndex = aItemIndex; |
|
63 iTextureItem.iItemId = aItemId; |
|
64 |
|
65 // store the bitmaps for the ProvideBitmapL callback |
|
66 iTextureItem.iBitmap = aBitmap; |
|
67 iTextureItem.iMask = aMask; |
|
68 |
|
69 /// @todo if CreateTextureL leaves, we may need to delete |
|
70 // iBitmap and iMask as we transfer their |
|
71 // ownership to Alf and if a leave occurs the ownership transfer |
|
72 // might have not yet happened |
|
73 CAlfTexture& texture = iTextureManager.CreateTextureL( |
|
74 KAlfAutoGeneratedTextureId, |
|
75 this, |
|
76 EAlfTextureFlagDefault ); |
|
77 |
|
78 MPX_DEBUG1("CMPXCommonContainerTextureManager::CreateTextureL(): Exiting"); |
|
79 return texture; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // Creates icon texture from the specified bitmap and mask (not cached) |
|
84 // ---------------------------------------------------------------------------- |
|
85 CAlfTexture& CMPXCommonContainerTextureManager::CreateIconTextureL( |
|
86 TInt aIconIndex, |
|
87 CFbsBitmap* aBitmap, |
|
88 CFbsBitmap* aMask ) |
|
89 { |
|
90 MPX_DEBUG1("CMPXCommonContainerTextureManager::CreateTextureL(): Entering"); |
|
91 |
|
92 // save the icon index |
|
93 iTextureItem.iType = EMPXTextureIcon; |
|
94 iTextureItem.iItemIndex = aIconIndex; |
|
95 |
|
96 // store the bitmaps for the ProvideBitmapL callback |
|
97 iTextureItem.iBitmap = aBitmap; |
|
98 iTextureItem.iMask = aMask; |
|
99 |
|
100 /// @todo if CreateTextureL leaves, we may need to delete |
|
101 // iBitmap and iMask as we transfer their |
|
102 // ownership to Alf and if a leave occurs the ownership transfer |
|
103 // might have not yet happened |
|
104 CAlfTexture& texture = iTextureManager.CreateTextureL( |
|
105 KAlfAutoGeneratedTextureId, |
|
106 this, |
|
107 EAlfTextureFlagDefault ); |
|
108 |
|
109 MPX_DEBUG1("CMPXCommonContainerTextureManager::CreateTextureL(): Exiting"); |
|
110 return texture; |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // Updates the specified media with the results from the search |
|
115 // criteria |
|
116 // ---------------------------------------------------------------------------- |
|
117 void CMPXCommonContainerTextureManager::ProvideBitmapL( |
|
118 TInt aId, |
|
119 CFbsBitmap*& aBitmap, |
|
120 CFbsBitmap*& aBitmapMask) |
|
121 { |
|
122 MPX_DEBUG1("CMPXCommonContainerTextureManager::ProvideBitmapL(): Entering"); |
|
123 |
|
124 // store the ID |
|
125 iTextureItem.iTextureId = aId; |
|
126 // give the bitmaps to Alf, it takes ownership |
|
127 aBitmap = iTextureItem.iBitmap; |
|
128 aBitmapMask = iTextureItem.iMask; |
|
129 |
|
130 // cache the texture item |
|
131 if( iTextureItem.iType == EMPXTextureImage ) |
|
132 { |
|
133 iTextureArray.AppendL( iTextureItem ); |
|
134 } |
|
135 else // EMPXTextureIcon |
|
136 { |
|
137 iIconTextureArray.AppendL( iTextureItem ); |
|
138 } |
|
139 |
|
140 MPX_DEBUG1("CMPXCommonContainerTextureManager::ProvideBitmapL(): Exiting"); |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // Returns the texture id for the specified item |
|
145 // ---------------------------------------------------------------------------- |
|
146 TInt CMPXCommonContainerTextureManager::TextureId( TMPXItemId aItemId ) const |
|
147 { |
|
148 MPX_FUNC("CMPXCommonContainerTextureManager::TextureId()"); |
|
149 |
|
150 TInt textureId( KErrNotFound ); |
|
151 |
|
152 // Search for the texture id in the cache |
|
153 const TInt count( iTextureArray.Count() ); |
|
154 for( TInt index = 0; index < count; index++ ) |
|
155 { |
|
156 if( iTextureArray[index].iItemId == aItemId ) |
|
157 { |
|
158 textureId = iTextureArray[index].iTextureId; |
|
159 break; |
|
160 } |
|
161 } |
|
162 |
|
163 return textureId; |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // Returns the texture id for the specified icon |
|
168 // ---------------------------------------------------------------------------- |
|
169 TInt CMPXCommonContainerTextureManager::IconTextureId( TInt aIconIndex ) const |
|
170 { |
|
171 MPX_FUNC("CMPXCommonContainerTextureManager::IconTextureId()"); |
|
172 |
|
173 TInt textureId( KErrNotFound ); |
|
174 |
|
175 // Search for the texture id in the cache |
|
176 const TInt count( iIconTextureArray.Count() ); |
|
177 for( TInt index = 0; index < count; index++ ) |
|
178 { |
|
179 if( iIconTextureArray[index].iItemIndex == aIconIndex ) |
|
180 { |
|
181 textureId = iIconTextureArray[index].iTextureId; |
|
182 break; |
|
183 } |
|
184 } |
|
185 |
|
186 return textureId; |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // Clears the texture cache array |
|
191 // ---------------------------------------------------------------------------- |
|
192 void CMPXCommonContainerTextureManager::ClearCache( TMPXTextureType aType ) |
|
193 { |
|
194 MPX_FUNC("CMPXCommonContainerTextureManager::ClearCache"); |
|
195 switch ( aType ) |
|
196 { |
|
197 case EMPXTextureImage: |
|
198 iTextureArray.Reset(); |
|
199 break; |
|
200 case EMPXTextureIcon: |
|
201 iIconTextureArray.Reset(); |
|
202 break; |
|
203 case EMPXTextureNone: |
|
204 iTextureArray.Reset(); |
|
205 iIconTextureArray.Reset(); |
|
206 break; |
|
207 } |
|
208 } |
|
209 |
|
210 //End of file |