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: Attribute setter implementation for mulimage visual. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Class header |
|
20 #include "../inc/mulimagevisualattributesetter.h" |
|
21 |
|
22 // Alf headers |
|
23 #include "alf/alfattribute.h" |
|
24 #include <alf/alfattributeexception.h> |
|
25 #include <alf/alfvisualexception.h> |
|
26 #include "alf/alfattributecontainer.h" |
|
27 #include <alf/alfimagevisual.h> |
|
28 #include <alf/alftexture.h> |
|
29 #include <alf/alfenv.h> |
|
30 #include <alf/alfdataexception.h> |
|
31 #include <alf/alfdisplay.h> |
|
32 #include <alf/alfbrusharray.h> |
|
33 #include <alf/alfframebrush.h> |
|
34 #include <alf/alfimageloaderutil.h> |
|
35 #include <alf/alfbitmapprovider.h> |
|
36 #include <alf/alfresourcepool.h> //for resource pooling |
|
37 #include <alf/alfwidgetenvextension.h> //for resource pooling |
|
38 // Osn headers |
|
39 #include <osn/ustring.h> |
|
40 #include <osn/alfptrvector.h> |
|
41 //#include <osn/osnlogicerror.h> |
|
42 // Std headers |
|
43 #include <libc/string.h> |
|
44 #include <utf.h> |
|
45 // DUI headers |
|
46 #include "alf/attrproperty.h" |
|
47 |
|
48 //for logs |
|
49 #include "mullog.h" |
|
50 #include "mulutility.h" |
|
51 |
|
52 using namespace osncore; |
|
53 |
|
54 using namespace duiuimodel::imagevisualattributes; |
|
55 using namespace duiuimodel::commonvisualattributes; |
|
56 using namespace duiuimodel::layoutattributes; |
|
57 |
|
58 namespace Alf |
|
59 { |
|
60 |
|
61 class MulImageVisualAttributeSetterImpl |
|
62 { |
|
63 public: |
|
64 MulImageVisualAttributeSetterImpl(); |
|
65 ~MulImageVisualAttributeSetterImpl(); |
|
66 public: |
|
67 //Keep track of loaded texture for imagevisuals. |
|
68 //Texture manager doesn't unload the texture from memory untill Env is deleted. |
|
69 //Hence need to unload them once attribute setter is deleted. |
|
70 AlfPtrVector<CAlfTexture> mLoadedTextures; |
|
71 //Env needed to access TextureManager while unloading textures. |
|
72 CAlfEnv* mEnv; |
|
73 }; |
|
74 |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // Constructor |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 MulImageVisualAttributeSetterImpl::MulImageVisualAttributeSetterImpl() |
|
81 { |
|
82 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetterImpl::MulImageVisualAttributeSetterImpl"); |
|
83 //Do not delete textures here as they may be in use by the visuals that have not been deleted. |
|
84 mLoadedTextures.setAutoDelete (false); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // Destructor |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 MulImageVisualAttributeSetterImpl::~MulImageVisualAttributeSetterImpl() |
|
92 { |
|
93 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetterImpl::~MulImageVisualAttributeSetterImpl"); |
|
94 //Unload all loaded textures created by this attributesetter to free up the memory. |
|
95 for (int i =0; i<mLoadedTextures.count ();i++) |
|
96 { |
|
97 CAlfTexture* texture = mLoadedTextures[i]; |
|
98 mEnv->TextureManager().UnloadTexture (texture->Id ()); |
|
99 } |
|
100 mLoadedTextures.clear (); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Constructor |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 OSN_EXPORT MulImageVisualAttributeSetter::MulImageVisualAttributeSetter() |
|
108 { |
|
109 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::MulImageVisualAttributeSetter"); |
|
110 mImpl.reset(new (EMM) MulImageVisualAttributeSetterImpl()); |
|
111 mImageAttrSetter.reset(new (EMM) AlfImageVisualAttributeSetter()); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Destructor |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 OSN_EXPORT MulImageVisualAttributeSetter::~MulImageVisualAttributeSetter() |
|
119 { |
|
120 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::~MulImageVisualAttributeSetter"); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // Sets Attribute Value. Delegates based on attribute Category. |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 OSN_EXPORT void MulImageVisualAttributeSetter::setAttributeValue ( |
|
128 CAlfVisual &aVisual, |
|
129 AlfAttributeContainer* aContainer, |
|
130 IAlfMap* aData ) |
|
131 { |
|
132 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::setAttributeValue"); |
|
133 mData = aData; |
|
134 CAlfImageVisual* imageVisual = dynamic_cast<CAlfImageVisual*>(&aVisual); |
|
135 if (!imageVisual) |
|
136 { |
|
137 ALF_THROW ( AlfVisualException, EInvalidVisual, "AlfImageVisualAttributeSetter") |
|
138 } |
|
139 AlfCommonVisualAttributeSetter::setAttributeValue(aVisual,aContainer, aData); |
|
140 } |
|
141 // --------------------------------------------------------------------------- |
|
142 // HandleStaticDataAttribute |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 void MulImageVisualAttributeSetter::handleStaticDataAttribute( |
|
146 CAlfVisual &aVisual, AlfAttribute& aAttr, |
|
147 AlfAttributeContainer& aContainer, IAlfMap* aData) |
|
148 { |
|
149 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::handleStaticDataAttribute"); |
|
150 CAlfImageVisual* imageVisual = dynamic_cast<CAlfImageVisual*>(&aVisual); |
|
151 if ( !imageVisual) |
|
152 { |
|
153 ALF_THROW ( AlfVisualException, EInvalidVisual, "CAlfImageVisualAttributeSetter") |
|
154 } |
|
155 |
|
156 if ( !aData) ALF_THROW ( AlfDataException, EInvalidVariantDataType, "CAlfTextVisualAttributeSetter" ) |
|
157 |
|
158 const char* dataField = aAttr.getDataField (); |
|
159 if ( !dataField) ALF_THROW ( AlfDataException, EInvalidAttribute, "CAlfTextVisualAttributeSetter" ) |
|
160 |
|
161 IAlfVariantType* data = aData->item (UString( dataField )); |
|
162 const char* attrName = aAttr.name (); |
|
163 if ( data) |
|
164 { |
|
165 if( !strcmp(attrName, KImagePath)) |
|
166 { |
|
167 if ( data->type ()== IAlfVariantType::EString) |
|
168 { |
|
169 if ( IsSVGImage (data->string ())) |
|
170 { |
|
171 LoadImageFromSvg(data->string (),*imageVisual); |
|
172 } |
|
173 else if (MulUtility::IsPoolResource(data->string ())) |
|
174 { |
|
175 //using resource pooling mechanism for image visual |
|
176 ResourcePool& pool = AlfWidgetEnvExtension::resourcePool(imageVisual->Env()); |
|
177 imageVisual->SetImage(pool.getImageResource((data->string ().getUtf8()))); |
|
178 } |
|
179 else |
|
180 { |
|
181 //AlfImageVisualAttributeSetter::handleStaticDataAttribute(aVisual,aAttr,aContainer,aData); |
|
182 mImageAttrSetter->setAttributeValue(aVisual,&aContainer,aData); |
|
183 } |
|
184 } |
|
185 else if ( data->type ()== IAlfVariantType::EInt) |
|
186 { |
|
187 LoadImageFromTexture(data->integer(),*imageVisual); |
|
188 } |
|
189 } |
|
190 else if( !strcmp(attrName, KSecondaryImagePath)) |
|
191 { |
|
192 if ( data->type ()== IAlfVariantType::EString) |
|
193 { |
|
194 if ( IsSVGImage (data->string ())) |
|
195 { |
|
196 LoadImageFromSvg(data->string (),*imageVisual); |
|
197 } |
|
198 else if (MulUtility::IsPoolResource(data->string ())) |
|
199 { |
|
200 //using resource pooling mechanism for image visual |
|
201 ResourcePool& pool1 = AlfWidgetEnvExtension::resourcePool(imageVisual->Env()); |
|
202 imageVisual->SetImage(pool1.getImageResource((data->string ().getUtf8()))); |
|
203 } |
|
204 else |
|
205 { |
|
206 mImageAttrSetter->setAttributeValue(aVisual,&aContainer,aData); |
|
207 } |
|
208 } |
|
209 else if ( data->type ()== IAlfVariantType::EInt) |
|
210 { |
|
211 LoadImageFromTexture(data->integer(),*imageVisual); |
|
212 } |
|
213 } |
|
214 else |
|
215 { |
|
216 mImageAttrSetter->setAttributeValue(aVisual,&aContainer,aData); |
|
217 } |
|
218 } |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // handleStaticAttribute |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void MulImageVisualAttributeSetter::handleStaticAttribute( CAlfVisual& aVisual, |
|
226 AlfAttribute& aAttr, |
|
227 AlfAttributeContainer& aContainer ) |
|
228 { |
|
229 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::handleStaticAttribute"); |
|
230 CAlfImageVisual* imageVisual = dynamic_cast<CAlfImageVisual*>(&aVisual); |
|
231 if ( !imageVisual) |
|
232 { |
|
233 ALF_THROW ( AlfVisualException, EInvalidVisual, "AlfImageVisualAttributeSetter") |
|
234 } |
|
235 |
|
236 const char* attrName = aAttr.name (); |
|
237 if( !strcmp(attrName, KImagePath)) |
|
238 { |
|
239 if ( IsSVGImage ( aAttr.stringValue())) |
|
240 { |
|
241 LoadImageFromSvg( aAttr.stringValue(),*imageVisual); |
|
242 } |
|
243 |
|
244 else |
|
245 { |
|
246 mImageAttrSetter->setAttributeValue(aVisual,&aContainer,mData); |
|
247 } |
|
248 } |
|
249 else if( !strcmp(attrName, KSecondaryImagePath)) |
|
250 { |
|
251 if ( IsSVGImage (aAttr.stringValue())) |
|
252 { |
|
253 LoadImageFromSvg(aAttr.stringValue(),*imageVisual); |
|
254 } |
|
255 |
|
256 else |
|
257 { |
|
258 mImageAttrSetter->setAttributeValue(aVisual,&aContainer,mData); |
|
259 } |
|
260 } |
|
261 else |
|
262 { |
|
263 mImageAttrSetter->setAttributeValue(aVisual,&aContainer,mData); |
|
264 } |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // handleDynamicDataAttribute |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void MulImageVisualAttributeSetter::handleDynamicDataAttribute(CAlfVisual &aVisual, |
|
272 AlfAttribute& /*aAttr*/, |
|
273 AlfAttributeContainer& aContainer, |
|
274 IAlfMap* aData) |
|
275 { |
|
276 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::handleDynamicDataAttribute"); |
|
277 mImageAttrSetter->setAttributeValue(aVisual,&aContainer,aData); |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // handleDynamicDataAttribute |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 void MulImageVisualAttributeSetter::handleDynamicAttribute(CAlfVisual &aVisual, |
|
285 AlfAttribute& /*aAttr*/, |
|
286 AlfAttributeContainer& aContainer) |
|
287 { |
|
288 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::handleDynamicAttribute"); |
|
289 mImageAttrSetter->setAttributeValue(aVisual,&aContainer,mData); |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // IsSVGImage |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 OSN_EXPORT bool MulImageVisualAttributeSetter::IsSVGImage(const UString& aImagePath) |
|
297 { |
|
298 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::IsSVGImage"); |
|
299 TPtrC8 src((TUint8*)aImagePath.getUtf8()); |
|
300 HBufC* srcBuf = HBufC::NewLC(src.Length()); |
|
301 |
|
302 srcBuf->Des().Copy(src); |
|
303 srcBuf->Des().LowerCase(); |
|
304 |
|
305 _LIT(KSvgFile,".svg"); |
|
306 |
|
307 bool retval = ( KErrNotFound != srcBuf->FindC(KSvgFile)); |
|
308 |
|
309 CleanupStack::PopAndDestroy( srcBuf ); |
|
310 |
|
311 return retval; |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // LoadImageFromSvg |
|
316 // --------------------------------------------------------------------------- |
|
317 // |
|
318 OSN_EXPORT void MulImageVisualAttributeSetter::LoadImageFromSvg(const UString& aSvgFilePath, |
|
319 CAlfImageVisual& aImageVisual ) |
|
320 { |
|
321 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::LoadImageFromSvg"); |
|
322 TPtrC8 src((TUint8*)aSvgFilePath.getUtf8()); |
|
323 HBufC* imagePath = CnvUtfConverter::ConvertToUnicodeFromUtf8L (src); |
|
324 CleanupStack::PushL( imagePath ); |
|
325 |
|
326 CAlfImageLoaderUtil imgLoaderUtil; |
|
327 imgLoaderUtil.SetSize (TSize (50, 50)); |
|
328 |
|
329 MAlfBitmapProvider* iSvgBitMapProv= imgLoaderUtil.CreateSVGImageLoaderL (*imagePath); |
|
330 CAlfTexture &texture = aImageVisual.Env().TextureManager().CreateTextureL ( |
|
331 KAlfAutoGeneratedTextureId, |
|
332 iSvgBitMapProv, |
|
333 EAlfTextureFlagDefault); |
|
334 |
|
335 aImageVisual.SetScaleMode (CAlfImageVisual::EScaleFit); |
|
336 aImageVisual.SetImage (TAlfImage (texture)); |
|
337 |
|
338 CleanupStack::PopAndDestroy(imagePath); |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // LoadImageFromTexture |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 OSN_EXPORT void MulImageVisualAttributeSetter::LoadImageFromTexture( int aTextureId, |
|
346 CAlfImageVisual& aImageVisual ) |
|
347 { |
|
348 MUL_LOG_INFO("aakash::CMulImageVisualAttributeSetter::LoadImageFromTexture"); |
|
349 //Seems like the Env's Texture Manager is not returning a copy. And When Env gets deleted the texture is destroyed |
|
350 //So ownership is not with the client |
|
351 const CAlfTexture* texture = aImageVisual.Env().TextureManager().Texture (aTextureId); |
|
352 if(!texture) |
|
353 { |
|
354 ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfImageVisualAttributeSetter" ) |
|
355 } |
|
356 aImageVisual.SetImage (TAlfImage (*texture)); |
|
357 } |
|
358 |
|
359 |
|
360 }// Alf |
|