|
1 /* |
|
2 * Copyright (c) 2003-2006 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: SmilDefaultRenderer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <smilregioninterface.h> |
|
22 #include <data_caging_path_literals.hrh> |
|
23 #include <gulicon.h> |
|
24 |
|
25 #include <AknsUtils.h> |
|
26 #include <AknsConstants.h> |
|
27 |
|
28 #include "SmilDefaultRenderer.h" |
|
29 |
|
30 #include <uniutils.mbg> |
|
31 _LIT( KUniUtilsBitmapFile, "uniutils.mbm" ); |
|
32 |
|
33 #ifdef DEFAULT_DEBUG |
|
34 #include "SmilMediaLogging.h" |
|
35 #endif |
|
36 |
|
37 // LOCAL FUNCTION PROTOTYPES |
|
38 |
|
39 // LOCAL CONSTANTS |
|
40 |
|
41 // ==================== LOCAL FUNCTIONS ==================== |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CSmilDefaultRenderer::CSmilDefaultRenderer |
|
47 // C++ constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // --------------------------------------------------------- |
|
50 CSmilDefaultRenderer::CSmilDefaultRenderer( MSmilMedia* aMedia, |
|
51 DRMCommon& aDrmCommon, |
|
52 CDRMHelper& aDrmHelper ) : |
|
53 CSmilMediaRendererBase( EMsgMediaUnknown, aMedia, aDrmCommon, aDrmHelper ) |
|
54 { |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // CSmilDefaultRenderer::ConstructL |
|
59 // Symbian 2nd phase constructor can leave. Retrieves the correct |
|
60 // icon for this media type depending on the situation. If correct |
|
61 // mediatype is not detected then blank default renderer is created. |
|
62 // Icon size is retrived from LAF if scalable LAF is present. |
|
63 // Current icon size & position is defined on MMS LAF but we |
|
64 // only use the size so we can use that value.Icon is drawn |
|
65 // on its original size or scaled so that aspect ratio is kept |
|
66 // and icon is shown as large as possible. |
|
67 // --------------------------------------------------------- |
|
68 void CSmilDefaultRenderer::ConstructL( RFile& aFileHandle, |
|
69 TBool aDRMError, |
|
70 TMsgMediaType aMediaType ) |
|
71 { |
|
72 #ifdef DEFAULT_DEBUG |
|
73 SMILUILOGGER_WRITE_TIMESTAMP( " --------------------------------" ); |
|
74 SMILUILOGGER_ENTERFN( "[SMILUI] Default: ConstructL" ); |
|
75 SMILUILOGGER_WRITEF( _L("[SMILUI] Default: aDRMError=%d"), aDRMError ); |
|
76 SMILUILOGGER_WRITEF( _L("[SMILUI] Default: aMediaType=%d"), aMediaType ); |
|
77 #endif |
|
78 |
|
79 BaseConstructL( aFileHandle ); |
|
80 |
|
81 TParse fileParse; |
|
82 fileParse.Set( KUniUtilsBitmapFile, &KDC_APP_BITMAP_DIR, NULL ); |
|
83 |
|
84 TAknsItemID itemID( KAknsIIDNone ); |
|
85 TInt bitmapIndex( -1 ); |
|
86 TInt maskIndex( 0 ); |
|
87 |
|
88 TBool sendingAllowed( ETrue ); |
|
89 if ( aDRMError ) |
|
90 { |
|
91 sendingAllowed = SendingDrmFileAllowedL( aFileHandle ); |
|
92 } |
|
93 |
|
94 switch ( aMediaType ) |
|
95 { |
|
96 case EMsgMediaImage: |
|
97 { |
|
98 if ( aDRMError ) |
|
99 { |
|
100 if ( sendingAllowed ) |
|
101 { |
|
102 itemID = KAknsIIDQgnGrafMmsImageDrm; |
|
103 bitmapIndex = EMbmUniutilsQgn_graf_mms_image_drm; |
|
104 maskIndex = EMbmUniutilsQgn_graf_mms_image_drm_mask; |
|
105 } |
|
106 else |
|
107 { |
|
108 itemID = KAknsIIDQgnGrafMmsImageDrmInvalidSendForbid; |
|
109 bitmapIndex = EMbmUniutilsQgn_graf_mms_image_drm_invalid_send_forbid; |
|
110 maskIndex = EMbmUniutilsQgn_graf_mms_image_drm_invalid_send_forbid_mask; |
|
111 } |
|
112 } |
|
113 else |
|
114 { |
|
115 itemID = KAknsIIDQgnGrafMmsImageCorrupted; |
|
116 bitmapIndex = EMbmUniutilsQgn_graf_mms_image_corrupted; |
|
117 maskIndex = EMbmUniutilsQgn_graf_mms_image_corrupted_mask; |
|
118 } |
|
119 break; |
|
120 } |
|
121 case EMsgMediaVideo: |
|
122 { |
|
123 if ( aDRMError ) |
|
124 { |
|
125 if ( sendingAllowed ) |
|
126 { |
|
127 itemID = KAknsIIDQgnGrafMmsVideoDrm; |
|
128 bitmapIndex = EMbmUniutilsQgn_graf_mms_video_drm; |
|
129 maskIndex = EMbmUniutilsQgn_graf_mms_video_drm_mask; |
|
130 } |
|
131 else |
|
132 { |
|
133 itemID = KAknsIIDQgnGrafMmsVideoDrmInvalidSendForbid; |
|
134 bitmapIndex = EMbmUniutilsQgn_graf_mms_video_drm_invalid_send_forbid; |
|
135 maskIndex = EMbmUniutilsQgn_graf_mms_video_drm_invalid_send_forbid_mask; |
|
136 } |
|
137 } |
|
138 else |
|
139 { |
|
140 itemID = KAknsIIDQgnGrafMmsVideoCorrupted; |
|
141 bitmapIndex = EMbmUniutilsQgn_graf_mms_video_corrupted; |
|
142 maskIndex = EMbmUniutilsQgn_graf_mms_video_corrupted_mask; |
|
143 } |
|
144 break; |
|
145 } |
|
146 case EMsgMediaSvg: |
|
147 { |
|
148 if ( aDRMError ) |
|
149 { |
|
150 if ( sendingAllowed ) |
|
151 { |
|
152 itemID = KAknsIIDQgnGrafMmsPresDrmInvalidSend; |
|
153 bitmapIndex = EMbmUniutilsQgn_graf_mms_pres_drm_invalid_send; |
|
154 maskIndex = EMbmUniutilsQgn_graf_mms_pres_drm_invalid_send_mask; |
|
155 } |
|
156 else |
|
157 { |
|
158 itemID = KAknsIIDQgnGrafMmsPresDrmInvalidSendForbid; |
|
159 bitmapIndex = EMbmUniutilsQgn_graf_mms_pres_drm_invalid_send_forbid; |
|
160 maskIndex = EMbmUniutilsQgn_graf_mms_pres_drm_invalid_send_forbid_mask; |
|
161 } |
|
162 } |
|
163 else |
|
164 { |
|
165 itemID = KAknsIIDQgnGrafMmsPresCorrupted; |
|
166 bitmapIndex = EMbmUniutilsQgn_graf_mms_pres_corrupted; |
|
167 maskIndex = EMbmUniutilsQgn_graf_mms_pres_corrupted_mask; |
|
168 } |
|
169 break; |
|
170 } |
|
171 default: |
|
172 { |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 if ( bitmapIndex != -1 ) |
|
178 { |
|
179 TSize regionSize( iMedia->GetRectangle().Size() ); |
|
180 |
|
181 #ifdef DEFAULT_DEBUG |
|
182 SMILUILOGGER_WRITEF( _L("[SMILUI] Default: regionSize=%d %d"), regionSize.iWidth, regionSize.iHeight ); |
|
183 #endif |
|
184 |
|
185 iIcon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(), |
|
186 itemID, |
|
187 fileParse.FullName(), |
|
188 bitmapIndex, |
|
189 maskIndex ); |
|
190 |
|
191 TSize originalSize( RetrieveIconSize() ); |
|
192 |
|
193 TSize iconSize; |
|
194 |
|
195 if ( originalSize.iHeight > regionSize.iHeight || |
|
196 originalSize.iWidth > regionSize.iWidth ) |
|
197 { |
|
198 iconSize = CalculateIconFitSize( regionSize, originalSize ); |
|
199 } |
|
200 else |
|
201 { |
|
202 iconSize = originalSize; |
|
203 } |
|
204 |
|
205 iIconRect.SetRect( CalculateIconCenterPosition( regionSize, iconSize ), iconSize ); |
|
206 |
|
207 #ifdef DEFAULT_DEBUG |
|
208 SMILUILOGGER_WRITEF( _L("[SMILUI] Default: iIconRect=%d %d"), |
|
209 iIconRect.Size().iWidth, |
|
210 iIconRect.Size().iHeight ); |
|
211 #endif |
|
212 |
|
213 User::LeaveIfError( AknIconUtils::SetSize( iIcon->Bitmap(), iIconRect.Size() ) ); |
|
214 } |
|
215 |
|
216 #ifdef DEFAULT_DEBUG |
|
217 SMILUILOGGER_LEAVEFN( "[SMILUI] Default: ConstructL" ); |
|
218 #endif |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // CSmilDefaultRenderer::NewL |
|
223 // Static constructor. |
|
224 // --------------------------------------------------------- |
|
225 CSmilDefaultRenderer* CSmilDefaultRenderer::NewL( RFile& aFileHandle, |
|
226 MSmilMedia* aMedia, |
|
227 DRMCommon& aDrmCommon, |
|
228 CDRMHelper& aDrmHelper, |
|
229 TMsgMediaType aMediaType, |
|
230 TBool aDRMError ) |
|
231 { |
|
232 CSmilDefaultRenderer* self = new(ELeave) CSmilDefaultRenderer( aMedia, |
|
233 aDrmCommon, |
|
234 aDrmHelper ); |
|
235 |
|
236 CleanupStack::PushL( self ); |
|
237 self->ConstructL( aFileHandle, aDRMError, aMediaType ); |
|
238 CleanupStack::Pop( self ); |
|
239 |
|
240 return self; |
|
241 } |
|
242 |
|
243 |
|
244 // --------------------------------------------------------- |
|
245 // CSmilDefaultRenderer::~CSmilDefaultRenderer |
|
246 // Destructor |
|
247 // --------------------------------------------------------- |
|
248 CSmilDefaultRenderer::~CSmilDefaultRenderer() |
|
249 { |
|
250 delete iIcon; |
|
251 |
|
252 // Not owned |
|
253 iMedia = NULL; //For LINT |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------- |
|
257 // CSmilDefaultRenderer::IsVisual |
|
258 // Default icon is visual (i.e. draws something to the screen. |
|
259 // (other items were commented in a header). |
|
260 // --------------------------------------------------------- |
|
261 // |
|
262 TBool CSmilDefaultRenderer::IsVisual() const |
|
263 { |
|
264 return ETrue; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // CSmilDefaultRenderer::IntrinsicWidth |
|
269 // (other items were commented in a header). |
|
270 // --------------------------------------------------------- |
|
271 // |
|
272 TInt CSmilDefaultRenderer::IntrinsicWidth() const |
|
273 { |
|
274 return iMedia->GetRectangle().Size().iWidth; |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------- |
|
278 // CSmilDefaultRenderer::IntrinsicHeight |
|
279 // (other items were commented in a header). |
|
280 // --------------------------------------------------------- |
|
281 // |
|
282 TInt CSmilDefaultRenderer::IntrinsicHeight() const |
|
283 { |
|
284 return iMedia->GetRectangle().Size().iHeight; |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------- |
|
288 // CSmilDefaultRenderer::IntrinsicDuration |
|
289 // Returns zero as default icon is static. |
|
290 // (other items were commented in a header). |
|
291 // --------------------------------------------------------- |
|
292 // |
|
293 TSmilTime CSmilDefaultRenderer::IntrinsicDuration() const |
|
294 { |
|
295 return 0; |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------- |
|
299 // CSmilDefaultRenderer::Draw |
|
300 // Performs the drawing of the icon to specific place and size. |
|
301 // Transition effects are not supported with default renderer. |
|
302 // (other items were commented in a header). |
|
303 // --------------------------------------------------------- |
|
304 // |
|
305 void CSmilDefaultRenderer::Draw( CGraphicsContext& aGc, |
|
306 const TRect& /*aRect*/, |
|
307 CSmilTransitionFilter* /*aTransitionFilter*/, |
|
308 const MSmilFocus* aFocus ) |
|
309 { |
|
310 #ifdef DEFAULT_DEBUG |
|
311 SMILUILOGGER_ENTERFN( "[SMILUI] Default: Draw" ); |
|
312 #endif |
|
313 |
|
314 if ( iVisible ) |
|
315 { |
|
316 if ( iIcon ) |
|
317 { |
|
318 //Top left corner of bitmap should be in this coordinate |
|
319 TPoint tlc( iMedia->GetRectangle().iTl ); |
|
320 tlc += iIconRect.iTl; |
|
321 |
|
322 // Source rectangle. |
|
323 TRect sourceRect( TPoint( 0, 0 ), iIconRect.Size() ); |
|
324 |
|
325 // Cast graphics context to CFbsBitGc |
|
326 CBitmapContext* tmpBitmapContext = static_cast<CBitmapContext*>( &aGc ); |
|
327 |
|
328 #ifdef DEFAULT_DEBUG |
|
329 SMILUILOGGER_WRITEF( _L("[SMILUI] Default: tlc=%d %d"), |
|
330 tlc.iX, |
|
331 tlc.iY ); |
|
332 SMILUILOGGER_WRITEF( _L("[SMILUI] Default: sourceRect=%d %d %d %d"), |
|
333 sourceRect.iTl.iX, |
|
334 sourceRect.iTl.iY, |
|
335 sourceRect.iBr.iX, |
|
336 sourceRect.iBr.iY ); |
|
337 #endif |
|
338 |
|
339 if ( iIcon->Mask() ) |
|
340 { |
|
341 tmpBitmapContext->BitBltMasked( tlc, |
|
342 iIcon->Bitmap(), |
|
343 sourceRect, |
|
344 iIcon->Mask(), |
|
345 EFalse ); |
|
346 } |
|
347 else |
|
348 { |
|
349 tmpBitmapContext->BitBlt( tlc, |
|
350 iIcon->Bitmap(), |
|
351 sourceRect ); |
|
352 } |
|
353 } |
|
354 |
|
355 DrawFocus( aGc, aFocus ); |
|
356 } |
|
357 |
|
358 #ifdef DEFAULT_DEBUG |
|
359 SMILUILOGGER_LEAVEFN( "[SMILUI] Default: Draw" ); |
|
360 #endif |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------- |
|
364 // CSmilDefaultRenderer::PrepareMediaL |
|
365 // (other items were commented in a header). |
|
366 // --------------------------------------------------------- |
|
367 // |
|
368 void CSmilDefaultRenderer::PrepareMediaL() |
|
369 { |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------- |
|
373 // CSmilDefaultRenderer::SeekMediaL |
|
374 // (other items were commented in a header). |
|
375 // --------------------------------------------------------- |
|
376 // |
|
377 void CSmilDefaultRenderer::SeekMediaL( const TSmilTime& /*aTime*/ ) |
|
378 { |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------- |
|
382 // CSmilDefaultRenderer::ShowMediaL |
|
383 // Sets renderer visible and draws it to the screen. |
|
384 // (other items were commented in a header). |
|
385 // --------------------------------------------------------- |
|
386 // |
|
387 void CSmilDefaultRenderer::ShowMediaL() |
|
388 { |
|
389 #ifdef DEFAULT_DEBUG |
|
390 SMILUILOGGER_ENTERFN( "[SMILUI] Default: ShowMediaL" ); |
|
391 #endif |
|
392 |
|
393 if ( !iVisible ) |
|
394 { |
|
395 iVisible = ETrue; |
|
396 iMedia->Redraw(); |
|
397 } |
|
398 |
|
399 #ifdef DEFAULT_DEBUG |
|
400 SMILUILOGGER_LEAVEFN( "[SMILUI] Default: ShowMediaL" ); |
|
401 #endif |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------- |
|
405 // CSmilDefaultRenderer::HideMedia |
|
406 // Hides the renderer and redraws the occupied area. |
|
407 // (other items were commented in a header). |
|
408 // --------------------------------------------------------- |
|
409 // |
|
410 void CSmilDefaultRenderer::HideMedia() |
|
411 { |
|
412 #ifdef DEFAULT_DEBUG |
|
413 SMILUILOGGER_ENTERFN( "[SMILUI] Default: HideMedia" ); |
|
414 #endif |
|
415 |
|
416 if ( iVisible ) |
|
417 { |
|
418 iVisible = EFalse; |
|
419 iMedia->Redraw(); |
|
420 } |
|
421 |
|
422 #ifdef DEFAULT_DEBUG |
|
423 SMILUILOGGER_LEAVEFN( "[SMILUI] Default: HideMedia" ); |
|
424 #endif |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------- |
|
428 // CSmilDefaultRenderer::FreezeMedia |
|
429 // (other items were commented in a header). |
|
430 // --------------------------------------------------------- |
|
431 // |
|
432 void CSmilDefaultRenderer::FreezeMedia() |
|
433 { |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------- |
|
437 // CSmilDefaultRenderer::ResumeMedia |
|
438 // (other items were commented in a header). |
|
439 // --------------------------------------------------------- |
|
440 // |
|
441 void CSmilDefaultRenderer::ResumeMedia() |
|
442 { |
|
443 } |
|
444 |
|
445 // --------------------------------------------------------- |
|
446 // CSmilDefaultRenderer::Close |
|
447 // Deletes the renderer. |
|
448 // (other items were commented in a header). |
|
449 // --------------------------------------------------------- |
|
450 // |
|
451 void CSmilDefaultRenderer::Close() |
|
452 { |
|
453 delete this; |
|
454 } |
|
455 |
|
456 // ---------------------------------------------------------------------------- |
|
457 // CSmilDefaultRenderer::CalculateIconFitSize |
|
458 // Calculates correct icon size so that icon aspect ratio is preserved |
|
459 // and it is shown fully on region as large as possible). |
|
460 // ---------------------------------------------------------------------------- |
|
461 // |
|
462 TSize CSmilDefaultRenderer::CalculateIconFitSize( const TSize& aRegion, |
|
463 const TSize& aIcon ) const |
|
464 { |
|
465 TSize result; |
|
466 |
|
467 if ( aIcon.iWidth != 0 && |
|
468 aIcon.iHeight != 0 ) |
|
469 { |
|
470 TInt targetWidth = aRegion.iWidth; |
|
471 TInt scaledWidth = aRegion.iHeight * aIcon.iWidth / aIcon.iHeight; |
|
472 |
|
473 if ( targetWidth < scaledWidth ) |
|
474 { |
|
475 result.iWidth = aRegion.iWidth; |
|
476 result.iHeight = aIcon.iHeight * aRegion.iWidth / aIcon.iWidth; |
|
477 } |
|
478 else |
|
479 { |
|
480 result.iWidth = aIcon.iWidth * aRegion.iHeight / aIcon.iHeight; |
|
481 result.iHeight = aRegion.iHeight; |
|
482 } |
|
483 } |
|
484 |
|
485 return result; |
|
486 } |
|
487 |
|
488 // ---------------------------------------------------------------------------- |
|
489 // CSmilDefaultRenderer::CalculateIconCenterPosition |
|
490 // Calculates correct icon position inside overall renderer region so that |
|
491 // icon is centeralized according height and width. |
|
492 // ---------------------------------------------------------------------------- |
|
493 // |
|
494 TPoint CSmilDefaultRenderer::CalculateIconCenterPosition( const TSize& aRegion, |
|
495 const TSize& aIcon ) const |
|
496 { |
|
497 return TPoint( ( aRegion.iWidth - aIcon.iWidth ) / 2, |
|
498 ( aRegion.iHeight - aIcon.iHeight ) / 2 ); |
|
499 } |
|
500 |
|
501 |
|
502 // End of File |