|
1 /* |
|
2 * Copyright (c) 2005-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: |
|
15 * MsgEditor svgt UI control - a Message Editor Base control. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "MsgSvgControl.h" |
|
23 |
|
24 #include <AknDialog.h> |
|
25 #include <aknlayoutscalable_apps.cdl.h> |
|
26 |
|
27 #include <AknUtils.h> |
|
28 #include <msgsvgutils.h> |
|
29 #include <AknsDrawUtils.h> |
|
30 |
|
31 #include <gulicon.h> |
|
32 #include <MsgEditorCommon.h> |
|
33 |
|
34 #include "MsgFrameControl.h" |
|
35 #include "MsgIconControl.h" |
|
36 |
|
37 #include "MsgMediaControlLogging.h" |
|
38 |
|
39 // ========================================================== |
|
40 |
|
41 // EXTERNAL DATA STRUCTURES |
|
42 |
|
43 // EXTERNAL FUNCTION PROTOTYPES |
|
44 |
|
45 // CONSTANTS |
|
46 |
|
47 // MACROS |
|
48 |
|
49 // LOCAL CONSTANTS AND MACROS |
|
50 |
|
51 // MODULE DATA STRUCTURES |
|
52 |
|
53 // LOCAL FUNCTION PROTOTYPES |
|
54 |
|
55 // ================= MEMBER FUNCTIONS ======================= |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // CMsgSvgControl::CMsgSvgControl |
|
59 // |
|
60 // Constructor. |
|
61 // --------------------------------------------------------- |
|
62 // |
|
63 CMsgSvgControl::CMsgSvgControl( MMsgBaseControlObserver& aBaseControlObserver ) : |
|
64 CMsgMediaControl( aBaseControlObserver, EMsgComponentIdSvg, EMsgSvgControl ) |
|
65 { |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CMsgSvgControl::ConstructL |
|
70 // |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 void CMsgSvgControl::ConstructL( CMsgEditorView& aParent, MMsgAsyncControlObserver* aObserver ) |
|
74 { |
|
75 BaseConstructL( aParent, aObserver ); |
|
76 |
|
77 SetSize( CalculateControlSize( MsgEditorCommons::MsgDataPane().Size() ) ); |
|
78 |
|
79 iSvgUtils = new( ELeave ) CMsgSvgUtils; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------- |
|
83 // CMsgSvgControl::NewL |
|
84 // |
|
85 // Two-phased constructor. |
|
86 // --------------------------------------------------------- |
|
87 // |
|
88 #ifdef RD_SVGT_IN_MESSAGING |
|
89 EXPORT_C CMsgSvgControl* CMsgSvgControl::NewL( CMsgEditorView& aParent, |
|
90 MMsgAsyncControlObserver* aObserver ) |
|
91 { |
|
92 |
|
93 CMsgSvgControl* self = new( ELeave ) CMsgSvgControl( aParent ); |
|
94 |
|
95 CleanupStack::PushL( self ); |
|
96 self->ConstructL( aParent, aObserver ); |
|
97 CleanupStack::Pop( self ); |
|
98 |
|
99 return self; |
|
100 } |
|
101 #else |
|
102 EXPORT_C CMsgSvgControl* CMsgSvgControl::NewL( CMsgEditorView& /*aParent*/, |
|
103 MMsgAsyncControlObserver* /*aObserver*/ ) |
|
104 { |
|
105 User::Leave( KErrNotSupported ); |
|
106 return NULL; //getting rid of warning |
|
107 } |
|
108 #endif |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // CMsgSvgControl::~CMsgSvgControl |
|
112 // |
|
113 // Destructor |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 CMsgSvgControl::~CMsgSvgControl() |
|
117 { |
|
118 delete iSvgIndicator; |
|
119 delete iSvgUtils; |
|
120 |
|
121 iFileHandle.Close(); |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------- |
|
126 // CMsgSvgControl::LoadL |
|
127 // |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 void CMsgSvgControl::LoadL( RFile& aFileHandle ) |
|
131 { |
|
132 iFileHandle.Close(); |
|
133 User::LeaveIfError( iFileHandle.Duplicate( aFileHandle ) ); |
|
134 |
|
135 DoLoadL(); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------- |
|
139 // CMsgSvgControl::DoLoadL |
|
140 // |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 void CMsgSvgControl::DoLoadL() |
|
144 { |
|
145 TSize thumbnailSize( Size() ); |
|
146 thumbnailSize = TSize( Max( 0, thumbnailSize.iWidth - iFrame->FrameBorderSize().iWidth ), |
|
147 Max( 0, thumbnailSize.iHeight - iFrame->FrameBorderSize().iHeight ) ); |
|
148 |
|
149 // Use svgt thumbnail creation directly |
|
150 CFbsBitmap* thumbnailBitmap = new ( ELeave ) CFbsBitmap; |
|
151 CleanupStack::PushL( thumbnailBitmap ); |
|
152 |
|
153 User::LeaveIfError( thumbnailBitmap->Create( thumbnailSize, |
|
154 iCoeEnv->ScreenDevice()->DisplayMode() ) ); |
|
155 |
|
156 CFbsBitmap* thumbnailMask = new ( ELeave ) CFbsBitmap; |
|
157 CleanupStack::PushL( thumbnailMask ); |
|
158 |
|
159 User::LeaveIfError( thumbnailMask->Create( thumbnailSize, |
|
160 EGray256 ) ); |
|
161 |
|
162 CGulIcon* thumbnailIcon = CGulIcon::NewL( thumbnailBitmap, thumbnailMask ); |
|
163 CleanupStack::Pop( 2, thumbnailBitmap ); |
|
164 |
|
165 iIconControl->SetIcon( thumbnailIcon ); |
|
166 |
|
167 // Incase this is not fulfilling the requirements, it might be an |
|
168 // option to go and check for GenerateThumbnailL() in the msgcommonutils |
|
169 |
|
170 iSvgUtils->GenerateThumbnailL( iFileHandle, |
|
171 thumbnailIcon->Bitmap(), |
|
172 thumbnailIcon->Mask(), |
|
173 EFalse, |
|
174 thumbnailSize ); |
|
175 |
|
176 // Resize bitmaps to actual content size. |
|
177 thumbnailBitmap->Resize( thumbnailSize ); |
|
178 thumbnailMask->Resize( thumbnailSize ); |
|
179 |
|
180 iIconControl->SetSize( thumbnailSize ); |
|
181 iIconControl->MakeVisible( ETrue ); |
|
182 |
|
183 iFrame->SetImageSize( thumbnailSize ); |
|
184 |
|
185 if ( iSvgIndicator ) |
|
186 { |
|
187 iSvgIndicator->MakeVisible( ETrue ); |
|
188 } |
|
189 |
|
190 SetState( EMsgAsyncControlStateReady ); |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------- |
|
194 // CMsgSvgControl::Cancel |
|
195 // --------------------------------------------------------- |
|
196 // |
|
197 void CMsgSvgControl::Cancel() |
|
198 { |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CMsgSvgControl::LoadIndicatorIconL |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 EXPORT_C void CMsgSvgControl::LoadIndicatorIconL( const TAknsItemID& aId, |
|
206 const TDesC& aFileName, |
|
207 const TInt aFileBitmapId, |
|
208 const TInt aFileMaskId ) |
|
209 { |
|
210 delete iSvgIndicator; |
|
211 iSvgIndicator = NULL; |
|
212 |
|
213 iSvgIndicator = CMsgIconControl::NewL( *this ); |
|
214 iSvgIndicator->LoadIconL( aId, |
|
215 aFileName, |
|
216 aFileBitmapId, |
|
217 aFileMaskId ); |
|
218 |
|
219 TAknLayoutRect indicatorRect; |
|
220 indicatorRect.LayoutRect( MsgEditorCommons::MsgDataPane(), |
|
221 AknLayoutScalable_Apps::msg_data_pane_g7().LayoutLine() ); |
|
222 |
|
223 iSvgIndicator->SetBitmapSizeL( indicatorRect.Rect().Size() ); |
|
224 |
|
225 if ( iIconControl && |
|
226 iIconControl->IsVisible() ) |
|
227 { |
|
228 iSvgIndicator->MakeVisible( ETrue ); |
|
229 } |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------- |
|
233 // CMsgSvgControl::SetIconExtent |
|
234 // |
|
235 // Updates the icon position & size. Icon control is centered |
|
236 // to the control area. |
|
237 // --------------------------------------------------------- |
|
238 // |
|
239 void CMsgSvgControl::SetIconExtent() |
|
240 { |
|
241 if ( iSvgIndicator ) |
|
242 { |
|
243 TSize size = iSvgIndicator->BitmapSize(); |
|
244 |
|
245 TPoint position( iIconControl->Position() ); |
|
246 position.iY += iIconControl->Size().iHeight; |
|
247 position.iY -= size.iHeight; |
|
248 |
|
249 iSvgIndicator->SetExtent( position, size ); |
|
250 } |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------- |
|
254 // CMsgSvgControl::SizeChanged |
|
255 // --------------------------------------------------------- |
|
256 // |
|
257 void CMsgSvgControl::SizeChanged() |
|
258 { |
|
259 CMsgMediaControl::SizeChanged(); |
|
260 |
|
261 SetIconExtent(); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------- |
|
265 // CMsgSvgControl::ComponentControl |
|
266 // --------------------------------------------------------- |
|
267 // |
|
268 CCoeControl* CMsgSvgControl::ComponentControl( TInt aIndex ) const |
|
269 { |
|
270 CCoeControl* result = NULL; |
|
271 |
|
272 switch ( aIndex ) |
|
273 { |
|
274 case 0: |
|
275 { |
|
276 result = iFrame; |
|
277 break; |
|
278 } |
|
279 case 1: |
|
280 { |
|
281 result = iIconControl; |
|
282 break; |
|
283 } |
|
284 case 2: |
|
285 { |
|
286 result = iSvgIndicator; |
|
287 break; |
|
288 } |
|
289 default: |
|
290 { |
|
291 break; |
|
292 } |
|
293 } |
|
294 |
|
295 return result; |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------- |
|
299 // CMsgSvgControl::CountComponentControls |
|
300 // |
|
301 // --------------------------------------------------------- |
|
302 // |
|
303 TInt CMsgSvgControl::CountComponentControls() const |
|
304 { |
|
305 TInt result( 2 ); |
|
306 if ( iSvgIndicator ) |
|
307 { |
|
308 result++; |
|
309 } |
|
310 |
|
311 return result; |
|
312 } |
|
313 |
|
314 |
|
315 // --------------------------------------------------------- |
|
316 // CMsgSvgControl::Draw |
|
317 // |
|
318 // --------------------------------------------------------- |
|
319 // |
|
320 void CMsgSvgControl::Draw( const TRect& aRect ) const |
|
321 { |
|
322 if ( iSvgIndicator ) |
|
323 { |
|
324 CWindowGc& gc = SystemGc(); |
|
325 |
|
326 if ( !AknsDrawUtils::BackgroundBetweenRects( AknsUtils::SkinInstance(), |
|
327 AknsDrawUtils::ControlContext( this ), |
|
328 this, |
|
329 gc, |
|
330 aRect, |
|
331 iIconControl->Rect() ) ) |
|
332 { |
|
333 gc.SetBrushColor( AKN_LAF_COLOR( 0 ) ); |
|
334 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
335 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
336 gc.DrawRect( aRect ); |
|
337 } |
|
338 |
|
339 gc.SetBrushColor( KRgbWhite.Value() ); |
|
340 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
341 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
342 gc.DrawRect( iIconControl->Rect() ); |
|
343 } |
|
344 else |
|
345 { |
|
346 CMsgMediaControl::Draw( aRect ); |
|
347 } |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------- |
|
351 // CMsgSvgControl::Close |
|
352 // --------------------------------------------------------- |
|
353 // |
|
354 void CMsgSvgControl::Close() |
|
355 { |
|
356 SetState( EMsgAsyncControlStateIdle ); |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------- |
|
360 // CMsgSvgControl::SetAndGetSizeL |
|
361 // |
|
362 // Calculates and sets the size of the control and returns new size as |
|
363 // reference aSize. |
|
364 // --------------------------------------------------------- |
|
365 // |
|
366 void CMsgSvgControl::SetAndGetSizeL( TSize& aSize ) |
|
367 { |
|
368 aSize = CalculateControlSize( aSize ); |
|
369 SetSize( aSize ); |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------- |
|
373 // CMsgSvgControl::HandleResourceChange |
|
374 // --------------------------------------------------------- |
|
375 // |
|
376 void CMsgSvgControl::HandleResourceChange( TInt aType ) |
|
377 { |
|
378 CMsgMediaControl::HandleResourceChange( aType ); |
|
379 |
|
380 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
381 { |
|
382 SetSize( CalculateControlSize( MsgEditorCommons::MsgDataPane().Size() ) ); |
|
383 |
|
384 TRAP_IGNORE( DoLoadL() ); |
|
385 } |
|
386 } |
|
387 |
|
388 |
|
389 // --------------------------------------------------------- |
|
390 // CMsgSvgControl::PlayL |
|
391 // --------------------------------------------------------- |
|
392 // |
|
393 void CMsgSvgControl::PlayL() |
|
394 { |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------- |
|
398 // CMsgSvgControl::Stop |
|
399 // --------------------------------------------------------- |
|
400 // |
|
401 void CMsgSvgControl::Stop() |
|
402 { |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------- |
|
406 // CMsgSvgControl::PauseL |
|
407 // --------------------------------------------------------- |
|
408 // |
|
409 void CMsgSvgControl::PauseL() |
|
410 { |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------- |
|
414 // CMsgSvgControl::CalculateControlSize |
|
415 // --------------------------------------------------------- |
|
416 // |
|
417 TSize CMsgSvgControl::CalculateControlSize( TSize aProposedSize ) const |
|
418 { |
|
419 TAknLayoutRect controLayout; |
|
420 controLayout.LayoutRect( MsgEditorCommons::MsgDataPane(), |
|
421 AknLayoutScalable_Apps::msg_data_pane_g1().LayoutLine() ); |
|
422 |
|
423 TSize controlSize = controLayout.Rect().Size(); |
|
424 |
|
425 // Make sure controlSize is multiple of iBaseLine |
|
426 controlSize.iHeight = iBaseLine * ( controlSize.iHeight / iBaseLine ); |
|
427 |
|
428 if ( controlSize.iHeight > aProposedSize.iHeight ) |
|
429 { |
|
430 controlSize.iHeight = aProposedSize.iHeight; |
|
431 } |
|
432 |
|
433 if ( controlSize.iWidth > aProposedSize.iWidth ) |
|
434 { |
|
435 controlSize.iWidth = aProposedSize.iWidth; |
|
436 } |
|
437 |
|
438 return controlSize; |
|
439 } |
|
440 |
|
441 // End of File |
|
442 |