15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include "xnbitmap.h" |
19 #include "xnbitmap.h" |
20 #include "xnnewsticker.h" |
|
21 #include "xntype.h" |
20 #include "xntype.h" |
22 #include "xnmenu.h" |
|
23 #include "xnmenuadapter.h" |
|
24 #include "xnuiengineappif.h" |
|
25 |
21 |
26 #include <imageconversion.h> |
|
27 #include <gulicon.h> |
22 #include <gulicon.h> |
28 |
23 |
29 #include "imagetransactionelement.h" |
24 #include "imagetransactionelement.h" |
30 #include "xmluicontrollerpanic.h" |
25 #include "xmluicontrollerpanic.h" |
31 #include "aixmluiutils.h" |
26 #include "aixmluiutils.h" |
32 #include "xnuiengineappif.h" |
|
33 |
27 |
34 using namespace AiXmlUiController; |
28 using namespace AiXmlUiController; |
35 using namespace XnImageInterface; |
29 using namespace XnImageInterface; |
36 using namespace ContentAccess; |
|
37 |
30 |
38 namespace AiXmlUiController |
31 namespace AiXmlUiController |
39 { |
32 { |
40 |
33 |
41 TBool IsNodeVisible( CXnNodeAppIf& aNode ) |
|
42 { |
|
43 CXnProperty* propVisibility = aNode.GetPropertyL( XnPropertyNames::style::common::KVisibility );; |
|
44 |
|
45 if( propVisibility ) |
|
46 { |
|
47 const TDesC8& visibility = propVisibility->StringValue(); |
|
48 |
|
49 if( visibility == XnPropertyNames::style::common::visibility::KHidden ) |
|
50 { |
|
51 return EFalse; |
|
52 } |
|
53 } |
|
54 |
|
55 CXnProperty* propDisplay = aNode.GetPropertyL( XnPropertyNames::style::common::KDisplay ); |
|
56 |
|
57 if( propDisplay ) |
|
58 { |
|
59 const TDesC8& display = propDisplay->StringValue(); |
|
60 |
|
61 if( display == XnPropertyNames::style::common::display::KNone ) |
|
62 { |
|
63 return EFalse; |
|
64 } |
|
65 } |
|
66 |
|
67 CXnProperty* propDisabled = aNode.GetPropertyL( XnPropertyNames::common::KDisabled ); |
|
68 |
|
69 if( propDisabled ) |
|
70 { |
|
71 const TDesC8& disabled = propDisabled->StringValue(); |
|
72 |
|
73 if( disabled == XnPropertyNames::KTrue ) |
|
74 { |
|
75 return EFalse; |
|
76 } |
|
77 } |
|
78 return ETrue; |
|
79 } |
|
80 /** |
|
81 * Uses CImageDecoder to decode images asynchronously. |
|
82 * When decoding is done, it tries to find target and set |
|
83 * image into element. Destroys itself at end of RunL method. |
|
84 */ |
|
85 class CKamikazeImageDecoder: public CActive |
|
86 { |
|
87 public: |
|
88 static CKamikazeImageDecoder* NewL( |
|
89 RFile& aFile, const TDesC8& aNodeId, |
|
90 const TDesC8& aNodeNs, TXnUiEngineAppIf& aUiEngine); |
|
91 ~CKamikazeImageDecoder(); |
|
92 public: |
|
93 /** |
|
94 * Start decoding and forget instance. |
|
95 * Destroyes itself. |
|
96 */ |
|
97 void DecodeLD(); |
|
98 private: |
|
99 // from CActive |
|
100 void DoCancel(); |
|
101 void RunL(); |
|
102 private: |
|
103 void ConstructL(RFile& aFile, const TDesC8& aNodeId,const TDesC8& aNodeNs); |
|
104 CKamikazeImageDecoder(TXnUiEngineAppIf& aUiEngine); |
|
105 void SetImageL(); |
|
106 private: |
|
107 /** |
|
108 * Image decoder. Own. |
|
109 */ |
|
110 CImageDecoder* iDecoder; |
|
111 /** |
|
112 * Target node id |
|
113 */ |
|
114 HBufC8* iNodeId; |
|
115 /** |
|
116 * Target node namespace |
|
117 */ |
|
118 HBufC8* iNodeNs; |
|
119 /** |
|
120 * Provides services to find target |
|
121 */ |
|
122 TXnUiEngineAppIf& iUiEngine; |
|
123 /** |
|
124 * Icon. Own. |
|
125 */ |
|
126 CGulIcon* iIcon; |
|
127 }; |
|
128 |
|
129 CKamikazeImageDecoder* CKamikazeImageDecoder::NewL( |
|
130 RFile& aFile, |
|
131 const TDesC8& aNodeId, |
|
132 const TDesC8& aNodeNs, |
|
133 TXnUiEngineAppIf& aUiEngine) |
|
134 { |
|
135 CKamikazeImageDecoder* p = new (ELeave)CKamikazeImageDecoder(aUiEngine); |
|
136 CleanupStack::PushL(p); |
|
137 p->ConstructL(aFile,aNodeId,aNodeNs); |
|
138 CleanupStack::Pop(p); |
|
139 return p; |
|
140 } |
|
141 |
|
142 CKamikazeImageDecoder::CKamikazeImageDecoder(TXnUiEngineAppIf& aUiEngine): |
|
143 CActive(CActive::EPriorityStandard ), iUiEngine(aUiEngine) |
|
144 { |
|
145 CActiveScheduler::Add( this ); |
|
146 } |
|
147 |
|
148 CKamikazeImageDecoder::~CKamikazeImageDecoder() |
|
149 { |
|
150 Cancel(); |
|
151 delete iDecoder; |
|
152 delete iNodeId; |
|
153 delete iNodeNs; |
|
154 delete iIcon; |
|
155 } |
|
156 |
|
157 void CKamikazeImageDecoder::ConstructL( |
|
158 RFile& aFile, |
|
159 const TDesC8& aNodeId, |
|
160 const TDesC8& aNodeNs) |
|
161 { |
|
162 // Create new decoder for file |
|
163 iDecoder = CImageDecoder::FileNewL( aFile, EView ); |
|
164 iNodeId = aNodeId.AllocL(); |
|
165 iNodeNs = aNodeNs.AllocL(); |
|
166 iIcon = CGulIcon::NewL(); |
|
167 } |
|
168 |
|
169 void CKamikazeImageDecoder::DecodeLD() |
|
170 { |
|
171 TFrameInfo frameInfo = iDecoder->FrameInfo(0); |
|
172 CFbsBitmap* bitmap = new( ELeave ) CFbsBitmap; |
|
173 iIcon->SetBitmap( bitmap ); |
|
174 |
|
175 User::LeaveIfError( bitmap->Create( frameInfo.iOverallSizeInPixels, |
|
176 frameInfo.iFrameDisplayMode ) ); |
|
177 |
|
178 CFbsBitmap* mask(0); |
|
179 if ( frameInfo.iFlags & TFrameInfo::ETransparencyPossible ) |
|
180 { |
|
181 mask = new( ELeave ) CFbsBitmap; |
|
182 iIcon->SetMask( mask ); |
|
183 User::LeaveIfError( mask->Create( frameInfo.iOverallSizeInPixels, |
|
184 ( ( frameInfo.iFlags & TFrameInfo::EAlphaChannel ) |
|
185 ? EGray256 : EGray2 ) ) ); |
|
186 } |
|
187 |
|
188 if(iIcon->Mask()) |
|
189 { |
|
190 iDecoder->Convert( &iStatus, *bitmap, *mask ); |
|
191 } |
|
192 else |
|
193 { |
|
194 iDecoder->Convert( &iStatus, *bitmap ); |
|
195 } |
|
196 SetActive(); |
|
197 } |
|
198 |
|
199 void CKamikazeImageDecoder::DoCancel() |
|
200 { |
|
201 iDecoder->Cancel(); |
|
202 } |
|
203 |
|
204 void CKamikazeImageDecoder::SetImageL() |
|
205 { |
|
206 |
|
207 // Find target |
|
208 CXnNodeAppIf* node = iUiEngine.FindNodeByIdL(*iNodeId,*iNodeNs); |
|
209 if(!node) |
|
210 { |
|
211 return; |
|
212 } |
|
213 |
|
214 const TDesC8& type = node->Type()->Type(); |
|
215 |
|
216 if ( type == XnImageInterface::MXnImageInterface::Type() ) |
|
217 { |
|
218 MXnImageInterface* imageIntr = NULL; |
|
219 if ( !XnComponentInterface::MakeInterfaceL( imageIntr, *node ) ) |
|
220 { |
|
221 return; |
|
222 } |
|
223 // Set new bitmaps. Ownership is transferred to MXnImageInterface |
|
224 iIcon->SetBitmapsOwnedExternally( ETrue ); |
|
225 imageIntr->SetContentBitmaps( iIcon->Bitmap(), iIcon->Mask() ); |
|
226 |
|
227 } |
|
228 // Menu softkey icons |
|
229 else if ( ( ( type == KXnMenuItem || type == KXnMenu ) && |
|
230 IsNodeVisible( *node ) ) || |
|
231 type == XnPropertyNames::softkey::KNodeName ) |
|
232 { |
|
233 CXnNodeAppIf* menuBar = node->ParentL(); |
|
234 |
|
235 XnMenuInterface::MXnMenuInterface::TSoftKeyPosition softkeyPosition = |
|
236 XnMenuInterface::MXnMenuInterface::ELeft; |
|
237 |
|
238 CXnProperty* property = |
|
239 node->GetPropertyL( XnPropertyNames::softkey::KTypeAttribute ); |
|
240 if ( property && property->StringValue() == XnPropertyNames::softkey::type::KRight ) |
|
241 { |
|
242 softkeyPosition = XnMenuInterface::MXnMenuInterface::ERight; |
|
243 } |
|
244 else if ( property && property->StringValue() == XnPropertyNames::softkey::type::KLeft ) |
|
245 { |
|
246 softkeyPosition = XnMenuInterface::MXnMenuInterface::ELeft; |
|
247 } |
|
248 else // Image can be published only to RSK or LSK |
|
249 { |
|
250 return; |
|
251 } |
|
252 |
|
253 XnMenuInterface::MXnMenuInterface* menuIf = NULL; |
|
254 |
|
255 XnComponentInterface::MakeInterfaceL( menuIf, *menuBar ); |
|
256 if ( menuIf ) |
|
257 { |
|
258 // Use black mask and preserver aspect ratio |
|
259 |
|
260 menuIf->SetSoftKeyImageL( iIcon->Bitmap(), |
|
261 iIcon->Mask(), |
|
262 softkeyPosition, |
|
263 node, |
|
264 ETrue, |
|
265 ETrue ); |
|
266 iIcon->SetBitmapsOwnedExternally( ETrue ); |
|
267 } |
|
268 if( menuBar ) |
|
269 { |
|
270 iUiEngine.RefreshMenuL(); |
|
271 } |
|
272 } |
|
273 |
|
274 } |
|
275 |
|
276 void CKamikazeImageDecoder::RunL() |
|
277 { |
|
278 CleanupStack::PushL(this); |
|
279 if(iStatus == KErrNone) |
|
280 { |
|
281 SetImageL(); |
|
282 iUiEngine.RenderUIL(); |
|
283 } |
|
284 CleanupStack::PopAndDestroy(this); |
|
285 } |
|
286 |
|
287 // ======== MEMBER FUNCTIONS ======== |
34 // ======== MEMBER FUNCTIONS ======== |
288 |
35 |
289 CImageTransactionElement::CImageTransactionElement( |
36 CImageTransactionElement::CImageTransactionElement( |
290 AiUtility::CContentPriorityMap& aContentPriorityMap) |
37 AiUtility::CContentPriorityMap& aContentPriorityMap) |
291 : CTransactionElement(aContentPriorityMap) |
38 : CTransactionElement(aContentPriorityMap) |
292 { |
39 { |
293 } |
40 } |
294 |
41 |
295 CImageTransactionElement* CImageTransactionElement::NewL( |
42 CImageTransactionElement* CImageTransactionElement::NewL( |
296 AiUtility::CContentPriorityMap& aContentPriorityMap) |
43 AiUtility::CContentPriorityMap& aContentPriorityMap) |
297 { |
44 { |
298 CImageTransactionElement* self = new( ELeave ) CImageTransactionElement( |
45 CImageTransactionElement* self = |
299 aContentPriorityMap ); |
46 new( ELeave ) CImageTransactionElement( aContentPriorityMap ); |
|
47 |
300 return self; |
48 return self; |
301 } |
49 } |
302 |
50 |
303 CImageTransactionElement::~CImageTransactionElement() |
51 CImageTransactionElement::~CImageTransactionElement() |
304 { |
52 { |
305 delete iNewIcon; |
53 delete iIcon; |
306 delete iImageDecoder; |
|
307 } |
54 } |
308 |
55 |
309 void CImageTransactionElement::InitializeL( CXnNodeAppIf& aTarget, |
56 void CImageTransactionElement::InitializeL( CXnNodeAppIf& aTarget, |
310 CGulIcon* aIcon ) |
57 CGulIcon* aIcon ) |
311 { |
58 { |
312 CheckTypeL( aTarget ); |
|
313 |
|
314 LeaveIfNull( aIcon, KErrArgument ); |
59 LeaveIfNull( aIcon, KErrArgument ); |
315 |
60 |
|
61 CheckTypeL( aTarget ); |
316 SetTarget( aTarget ); |
62 SetTarget( aTarget ); |
317 iNewIcon = aIcon; |
63 |
|
64 iIcon = aIcon; |
|
65 iFilename = KNullDesC(); |
318 } |
66 } |
319 |
67 |
320 void CImageTransactionElement::InitializeL( CXnNodeAppIf& aTarget, |
68 void CImageTransactionElement::InitializeL( CXnNodeAppIf& aTarget, |
321 RFile& aFile ) |
69 RFile& aFile ) |
322 { |
70 { |
323 CheckTypeL( aTarget ); |
71 CheckTypeL( aTarget ); |
324 |
72 SetTarget( aTarget ); |
325 const TDesC8* nodeId = &KNullDesC8; |
73 |
|
74 iFilename = KNullDesC(); |
326 |
75 |
327 CXnProperty* property = aTarget.GetPropertyL(XnPropertyNames::common::KId); |
76 aFile.FullName( iFilename ); |
328 if(property) |
|
329 { |
|
330 nodeId = &property->StringValue(); |
|
331 } |
|
332 if ( iImageDecoder ) |
|
333 { |
|
334 delete iImageDecoder; |
|
335 iImageDecoder = NULL; |
|
336 } |
|
337 iImageDecoder = CKamikazeImageDecoder::NewL( |
|
338 aFile,*nodeId,aTarget.Namespace(),*aTarget.UiEngineL()); |
|
339 |
77 |
340 SetTarget( aTarget ); |
78 delete iIcon; |
|
79 iIcon = NULL; |
341 } |
80 } |
342 |
81 |
|
82 void CImageTransactionElement::UpdateDataL() |
|
83 { |
|
84 const TDesC8& type( Target().Type()->Type() ); |
|
85 |
|
86 if ( type == XnImageInterface::MXnImageInterface::Type() ) |
|
87 { |
|
88 MXnImageInterface* image( NULL ); |
|
89 XnComponentInterface::MakeInterfaceL( image, Target() ); |
|
90 |
|
91 LeaveIfNull( image, KErrNotSupported ); |
343 |
92 |
344 void CImageTransactionElement::UpdateDataL() |
93 if ( iIcon ) |
345 { |
94 { |
346 if ( iImageDecoder ) |
95 // Set new bitmaps. Ownership is transferred to MXnImageInterface |
347 { |
96 iIcon->SetBitmapsOwnedExternally( ETrue ); |
348 iImageDecoder->DecodeLD(); |
97 |
349 iImageDecoder = NULL; // self destroy |
98 image->SetContentBitmaps( iIcon->Bitmap(), iIcon->Mask() ); |
|
99 } |
|
100 else if ( iFilename != KNullDesC() ) |
|
101 { |
|
102 image->SetContentBitmaps( iFilename ); |
|
103 } |
350 } |
104 } |
351 else |
|
352 { |
|
353 __ASSERT_DEBUG( iNewIcon, Panic( EBitmapNull ) ); |
|
354 |
|
355 const TDesC8& type = LeaveIfNull( Target().Type(), KErrNotSupported )->Type(); |
|
356 |
|
357 if ( type == XnImageInterface::MXnImageInterface::Type() ) |
|
358 { |
|
359 MXnImageInterface* imageIntr = NULL; |
|
360 if ( !XnComponentInterface::MakeInterfaceL( imageIntr, Target() ) ) |
|
361 { |
|
362 User::Leave( KErrNotSupported ); |
|
363 } |
|
364 // Set new bitmaps. Ownership is transferred to MXnImageInterface |
|
365 iNewIcon->SetBitmapsOwnedExternally( ETrue ); |
|
366 imageIntr->SetContentBitmaps( iNewIcon->Bitmap(), iNewIcon->Mask() ); |
|
367 } |
|
368 // Menu softkey icons |
|
369 else if ( ( ( type == KXnMenuItem || type == KXnMenu ) && |
|
370 IsNodeVisible( Target() ) ) || |
|
371 type == XnPropertyNames::softkey::KNodeName ) |
|
372 { |
|
373 CXnNodeAppIf* menuBar = Target().ParentL(); |
|
374 |
|
375 XnMenuInterface::MXnMenuInterface::TSoftKeyPosition softkeyPosition = |
|
376 XnMenuInterface::MXnMenuInterface::ELeft; |
|
377 |
|
378 CXnProperty* property = |
|
379 Target().GetPropertyL( XnPropertyNames::softkey::KTypeAttribute ); |
|
380 if ( property && property->StringValue() == XnPropertyNames::softkey::type::KRight ) |
|
381 { |
|
382 softkeyPosition = XnMenuInterface::MXnMenuInterface::ERight; |
|
383 } |
|
384 else if ( property && property->StringValue() == XnPropertyNames::softkey::type::KLeft ) |
|
385 { |
|
386 softkeyPosition = XnMenuInterface::MXnMenuInterface::ELeft; |
|
387 } |
|
388 else // Image can be published only to RSK or LSK |
|
389 { |
|
390 delete iNewIcon; |
|
391 iNewIcon = NULL; |
|
392 User::Leave( KErrNotSupported ); |
|
393 } |
|
394 |
|
395 XnMenuInterface::MXnMenuInterface* menuIf = NULL; |
|
396 |
|
397 XnComponentInterface::MakeInterfaceL( menuIf, *menuBar ); |
|
398 if ( menuIf ) |
|
399 { |
|
400 // Use black mask and preserver aspect ratio |
|
401 TRAPD(err, |
|
402 menuIf->SetSoftKeyImageL( iNewIcon->Bitmap(), |
|
403 iNewIcon->Mask(), |
|
404 softkeyPosition, |
|
405 &Target(), |
|
406 ETrue, |
|
407 ETrue ) |
|
408 ); |
|
409 // Menuinterface takes ownership |
|
410 if ( err == KErrNone ) |
|
411 { |
|
412 iNewIcon->SetBitmapsOwnedExternally( ETrue ); |
|
413 } |
|
414 if( menuBar ) |
|
415 { |
|
416 menuBar->UiEngineL()->RefreshMenuL(); |
|
417 } |
|
418 } |
|
419 } |
|
420 else |
|
421 { |
|
422 User::Leave( KErrNotSupported ); |
|
423 } |
|
424 } |
|
425 |
|
426 delete iNewIcon; |
|
427 iNewIcon = NULL; |
|
428 |
105 |
429 UpdateContentPriorityL(); |
106 UpdateContentPriorityL(); |
430 } |
107 } |
431 |
108 |
432 void CImageTransactionElement::Reset() |
109 void CImageTransactionElement::Reset() |
433 { |
110 { |
434 if ( iImageDecoder ) |
|
435 { |
|
436 delete iImageDecoder; |
|
437 iImageDecoder = NULL; |
|
438 } |
|
439 |
|
440 CTransactionElement::Reset(); |
111 CTransactionElement::Reset(); |
441 |
112 |
442 delete iNewIcon; |
113 iFilename = KNullDesC(); |
443 iNewIcon = NULL; |
114 |
|
115 delete iIcon; |
|
116 iIcon = NULL; |
444 } |
117 } |
445 |
118 |
446 TBool CImageTransactionElement::IsSupported( CXnNodeAppIf& aTarget ) |
119 TBool CImageTransactionElement::IsSupported( CXnNodeAppIf& aTarget ) |
447 { |
120 { |
448 // Get type info |
121 // Get type info |
449 CXnType* typeInfo = aTarget.Type(); |
122 CXnType* typeInfo( aTarget.Type() ); |
450 |
123 |
451 if ( !typeInfo ) |
124 if ( !typeInfo ) |
452 { |
125 { |
453 return EFalse; |
126 return EFalse; |
454 } |
127 } |
455 |
128 |
456 const TDesC8& type = typeInfo->Type(); |
129 const TDesC8& type( typeInfo->Type() ); |
457 |
130 |
458 // image element and newsticker supported |
131 // image element and newsticker supported |
459 return ( type == XnImageInterface::MXnImageInterface::Type() || |
132 return ( type == XnImageInterface::MXnImageInterface::Type() ); |
460 type == XnNewstickerInterface::MXnNewstickerInterface::Type() || |
|
461 type == XnMenuInterface::MXnMenuInterface::Type() || |
|
462 type == KXnMenuItem || |
|
463 type == KXnMenu || |
|
464 type == XnPropertyNames::softkey::KNodeName ); |
|
465 } |
133 } |
466 |
134 |
467 void CImageTransactionElement::CheckTypeL( CXnNodeAppIf& aTarget ) |
135 void CImageTransactionElement::CheckTypeL( CXnNodeAppIf& aTarget ) |
468 { |
136 { |
469 if ( !IsSupported( aTarget ) ) |
137 if ( !IsSupported( aTarget ) ) |
470 { |
138 { |
471 User::Leave( KErrNotSupported ); |
139 User::Leave( KErrNotSupported ); |
472 } |
140 } |
473 } |
141 } |
474 } // ns |
142 } // ns |
|
143 |
|
144 // End of file |