|
1 /* |
|
2 * Copyright (c) 2005 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 * Provides CPostcardController class methods |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <s32file.h> // for RFileReadStream |
|
23 #include <data_caging_path_literals.hrh> |
|
24 |
|
25 #include <gulicon.h> // CGulIcon |
|
26 |
|
27 #include <AknIndicatorContainer.h> |
|
28 #include <AknLayout.lag> // AKN_LAYOUT_WINDOW_screen |
|
29 #include <aknenv.h> // for EditingStateIndicator |
|
30 #include <AknsConstants.h> // For skinnable icons |
|
31 #include <AknsBasicBackgroundControlContext.h> // For skin stuff, too |
|
32 #include <AknsDrawUtils.h> |
|
33 #include <applayout.cdl.h> // LAF |
|
34 #include <aknlayoutscalable_apps.cdl.h> |
|
35 #include <avkon.rsg> |
|
36 #include <AknsUtils.h> // For CreateIconL |
|
37 #include <AknUtils.h> // For AknLayoutUtils |
|
38 #include <AknIconUtils.h> // For AknIconUtils |
|
39 #include <postcard.mbg> // For Postcard icons |
|
40 |
|
41 #include "PostcardController.h" |
|
42 #include "PostcardLaf.h" |
|
43 #include "PostcardPointerObserver.h" |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CPostcardController::NewL( ) |
|
47 // --------------------------------------------------------- |
|
48 |
|
49 CPostcardController* CPostcardController::NewL( CPostcardDocument& aDocument |
|
50 #ifdef RD_SCALABLE_UI_V2 |
|
51 , MPocaPointerEventObserver& aObserver |
|
52 #endif |
|
53 ) |
|
54 { |
|
55 CPostcardController* self = new ( ELeave ) CPostcardController( aDocument |
|
56 #ifdef RD_SCALABLE_UI_V2 |
|
57 , aObserver |
|
58 #endif |
|
59 ); |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL( ); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // CPostcardController::ConstructL |
|
68 // --------------------------------------------------------- |
|
69 void CPostcardController::ConstructL( ) |
|
70 { |
|
71 CreateWindowL( ); |
|
72 LoadIconsL( ); |
|
73 RefreshCoordinates( ); |
|
74 |
|
75 TRect rectForSkin = PostcardLaf::RelativeMainPostcardPane( ); |
|
76 |
|
77 iBgContext = CAknsBasicBackgroundControlContext::NewL( |
|
78 KAknsIIDQsnBgAreaMainMessage, rectForSkin, EFalse ); |
|
79 |
|
80 // We don't want to flash image side at startup. |
|
81 iFocusedItem = EPostcardNone; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // CPostcardController::CPostcardController() |
|
86 // --------------------------------------------------------- |
|
87 CPostcardController::CPostcardController( CPostcardDocument& aDocument |
|
88 #ifdef RD_SCALABLE_UI_V2 |
|
89 , MPocaPointerEventObserver& aObserver |
|
90 #endif |
|
91 ) : |
|
92 iDocument( aDocument ) |
|
93 #ifdef RD_SCALABLE_UI_V2 |
|
94 , iEventObserver( aObserver ) |
|
95 #endif |
|
96 { |
|
97 #ifdef RD_SCALABLE_UI_V2 |
|
98 iPenEnabled = AknLayoutUtils::PenEnabled(); |
|
99 #endif |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------- |
|
103 // CPostcardController::~CPostcardController() |
|
104 // --------------------------------------------------------- |
|
105 CPostcardController::~CPostcardController( ) |
|
106 { |
|
107 delete iFrontBg; |
|
108 delete iInsertImageBg; |
|
109 delete iImage; |
|
110 delete iInsertImage; |
|
111 |
|
112 delete iBgBg; |
|
113 delete iStamp; |
|
114 delete iEmptyGreetingFocused; |
|
115 delete iEmptyGreeting; |
|
116 delete iGreeting; |
|
117 delete iEmptyAddressFocused; |
|
118 delete iEmptyAddress; |
|
119 delete iAddress; |
|
120 |
|
121 if( iGreetingLines ) |
|
122 { |
|
123 iGreetingLines->ResetAndDestroy( ); |
|
124 delete iGreetingLines; |
|
125 } |
|
126 if( iRecipientLines ) |
|
127 { |
|
128 iRecipientLines->ResetAndDestroy( ); |
|
129 delete iRecipientLines; |
|
130 } |
|
131 |
|
132 delete iUpperArrow; |
|
133 delete iLowerArrow; |
|
134 |
|
135 delete iBgContext; |
|
136 |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------- |
|
140 // CPostcardController::ActivateL( ) |
|
141 // --------------------------------------------------------- |
|
142 void CPostcardController::ActivateL( ) |
|
143 { |
|
144 SetRect( PostcardLaf::MainPostcardPane( ) ); |
|
145 SizeChanged(); |
|
146 MakeVisible( ETrue ); |
|
147 SetFocus( ETrue ); |
|
148 CCoeControl::ActivateL(); |
|
149 DrawNow( ); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------- |
|
153 // CPostcardController::CountComponentControls() const |
|
154 // --------------------------------------------------------- |
|
155 TInt CPostcardController::CountComponentControls( ) const |
|
156 { |
|
157 return 0; |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------- |
|
161 // CPostcardController::ComponentControl(TInt aIndex) const |
|
162 // --------------------------------------------------------- |
|
163 CCoeControl* CPostcardController::ComponentControl( TInt /*aIndex*/ ) const |
|
164 { |
|
165 return NULL; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CPostcardController::Draw(const TRect& aRect) const |
|
170 // --------------------------------------------------------- |
|
171 void CPostcardController::Draw( const TRect& /*aRect*/ ) const |
|
172 { |
|
173 // Lets draw the skin stuff + bg stuff first |
|
174 DrawBackground( ); |
|
175 |
|
176 // Now we draw the real content |
|
177 switch ( iFocusedItem ) |
|
178 { |
|
179 case EPostcardImage: |
|
180 DrawImageSide(); |
|
181 break; |
|
182 |
|
183 case EPostcardText: |
|
184 case EPostcardRecipient: |
|
185 DrawTextSide(); |
|
186 break; |
|
187 |
|
188 case EPostcardNone: |
|
189 default: |
|
190 break; |
|
191 } |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------- |
|
195 // CPostcardController::DrawBackground( ) const |
|
196 // --------------------------------------------------------- |
|
197 void CPostcardController::DrawBackground( ) const |
|
198 { |
|
199 CWindowGc& gc = SystemGc(); |
|
200 TRect rect( PostcardLaf::RelativeMainPostcardPane( ) ); |
|
201 |
|
202 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
203 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this ); |
|
204 |
|
205 if( !AknsDrawUtils::Background( skin, cc, this, gc, rect ) ) |
|
206 { |
|
207 // clear entire header area. |
|
208 gc.SetBrushColor( AKN_LAF_COLOR( 0 ) ); |
|
209 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
210 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
211 gc.DrawRect( rect ); |
|
212 } |
|
213 |
|
214 gc.SetBrushStyle(CGraphicsContext::ENullBrush); // To ensure masking |
|
215 |
|
216 // Background image |
|
217 if( iFocusedItem == EPostcardImage ) |
|
218 { |
|
219 DrawIcon( iImage?*iFrontBg:*iInsertImageBg,iFrontBgC); |
|
220 } |
|
221 else if ( iFocusedItem == EPostcardRecipient || |
|
222 iFocusedItem == EPostcardText ) |
|
223 { |
|
224 DrawIcon( *iBgBg, iBgBgC ); |
|
225 } |
|
226 |
|
227 if ( iFocusedItem != EPostcardNone ) // Prevents unnecessary drawing of arrows at startup. |
|
228 { |
|
229 DrawScrollArrows(); |
|
230 } |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------- |
|
234 // CPostcardController::DrawImageSide( ) const |
|
235 // --------------------------------------------------------- |
|
236 void CPostcardController::DrawImageSide( ) const |
|
237 { |
|
238 // Draw focused image / insert icon |
|
239 if( iImage ) |
|
240 { // Lets resize the image rect for the image |
|
241 TRect imageRect = iImageC; |
|
242 TSize imageSize = iImage->Bitmap()->SizeInPixels(); |
|
243 TSize rectSize = imageRect.Size( ); |
|
244 |
|
245 // Image size matches the screen rectangle size unless |
|
246 // there has been a layout switch. In that case DrawBitmap() |
|
247 // is used to scale bitmap to a screen. Otherwise image is |
|
248 // drawn using BitBlt. |
|
249 TInt diffX = rectSize.iWidth - imageSize.iWidth; |
|
250 TInt diffY = rectSize.iHeight - imageSize.iHeight; |
|
251 const TInt KMaxDiff = 2; |
|
252 if( Abs( diffX ) > KMaxDiff && Abs( diffY ) > KMaxDiff ) |
|
253 { |
|
254 const TInt KScaling = 1024; |
|
255 // Adjust screen rectangle so that it matches the image x/y ratio |
|
256 TInt newWidth = rectSize.iWidth * KScaling; |
|
257 TInt newHeight = |
|
258 ( imageSize.iHeight * newWidth ) / imageSize.iWidth; |
|
259 if ( newHeight > rectSize.iHeight * KScaling ) |
|
260 { |
|
261 newHeight = rectSize.iHeight * KScaling; |
|
262 newWidth = |
|
263 ( imageSize.iWidth * newHeight ) / imageSize.iHeight; |
|
264 } |
|
265 imageRect.Shrink( ( rectSize.iWidth - newWidth / KScaling ) / 2, |
|
266 ( rectSize.iHeight - newHeight / KScaling ) / 2 ); |
|
267 TRect srcRect( iImage->Bitmap()->SizeInPixels() ); |
|
268 SystemGc().DrawBitmap( imageRect, iImage->Bitmap(), srcRect ); |
|
269 } |
|
270 else |
|
271 { |
|
272 TInt deltaX = diffX > 0 ? ( diffX + 1 ) / 2 : 0; |
|
273 TInt deltaY = diffY > 0 ? ( diffY + 1 ) / 2 : 0; |
|
274 imageRect.Shrink( deltaX, deltaY ); |
|
275 DrawIcon( *iImage, imageRect ); |
|
276 } |
|
277 } |
|
278 else |
|
279 { |
|
280 DrawIcon( *iInsertImage, iInsertImageC ); |
|
281 } |
|
282 } |
|
283 |
|
284 |
|
285 // --------------------------------------------------------- |
|
286 // CPostcardController::DrawTextSide( ) const |
|
287 // --------------------------------------------------------- |
|
288 void CPostcardController::DrawTextSide( ) const |
|
289 { |
|
290 // Draw stamp |
|
291 DrawIcon( *iStamp, iStampC ); |
|
292 // Draw possible greeting and address bitmaps |
|
293 if( iGreeting ) |
|
294 { |
|
295 DrawIcon( *iGreeting, iGreetingC ); |
|
296 } |
|
297 if( iAddress ) |
|
298 { |
|
299 DrawIcon( *iAddress, iAddressC ); |
|
300 } |
|
301 // Draw focus lines |
|
302 DrawFocus( ); |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------- |
|
306 // CPostcardController::DrawIcon() |
|
307 // --------------------------------------------------------- |
|
308 void CPostcardController::DrawIcon( const CGulIcon& aIcon, const TRect& aRect ) const |
|
309 { |
|
310 if ( aIcon.Mask( ) ) |
|
311 { |
|
312 SystemGc( ).BitBltMasked( aRect.iTl, aIcon.Bitmap( ), aRect.Size( ) , aIcon.Mask( ), EFalse ); // was EFalse |
|
313 } |
|
314 else |
|
315 { |
|
316 SystemGc( ).BitBlt( aRect.iTl, aIcon.Bitmap( ), aRect.Size( ) ); |
|
317 } |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CPostcardController::DrawScrollArrows() |
|
322 // --------------------------------------------------------------------------- |
|
323 void CPostcardController::DrawScrollArrows() const |
|
324 { |
|
325 // Scroll arrows. Behaviour depends on whether we are in editor or |
|
326 // viewer mode. |
|
327 if ( iDocument.MessageType() != EPostcardSent ) |
|
328 { |
|
329 DrawIcon( iFocusedItem != EPostcardImage? *iLowerArrow : *iUpperArrow, |
|
330 iFocusedItem != EPostcardImage? iLowerArrowC : iUpperArrowC ); |
|
331 } |
|
332 else |
|
333 { |
|
334 DrawIcon( iFocusedItem != EPostcardImage? *iUpperArrow : *iLowerArrow, |
|
335 iFocusedItem != EPostcardImage? iUpperArrowC : iLowerArrowC ); |
|
336 } |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------- |
|
340 // CPostcardController::ReLoadIconsL() |
|
341 // --------------------------------------------------------- |
|
342 void CPostcardController::ReLoadIconsL( ) |
|
343 { |
|
344 // Delete old ones, since new skin might have new icons. |
|
345 delete iFrontBg; |
|
346 iFrontBg = NULL; |
|
347 delete iInsertImageBg; |
|
348 iInsertImageBg = NULL; |
|
349 delete iInsertImage; |
|
350 iInsertImage = NULL; |
|
351 delete iBgBg; |
|
352 iBgBg = NULL; |
|
353 delete iStamp; |
|
354 iStamp = NULL; |
|
355 delete iEmptyGreetingFocused; |
|
356 iEmptyGreetingFocused = NULL; |
|
357 delete iEmptyGreeting; |
|
358 iEmptyGreeting = NULL; |
|
359 delete iEmptyAddressFocused; |
|
360 iEmptyAddressFocused = NULL; |
|
361 delete iEmptyAddress; |
|
362 iEmptyAddress = NULL; |
|
363 delete iUpperArrow; |
|
364 iUpperArrow = NULL; |
|
365 delete iLowerArrow; |
|
366 iLowerArrow = NULL; |
|
367 |
|
368 if ( iBgContext ) |
|
369 { |
|
370 delete iBgContext; |
|
371 iBgContext = NULL; |
|
372 |
|
373 TRect rectForSkin = PostcardLaf::RelativeMainPostcardPane(); |
|
374 |
|
375 iBgContext = CAknsBasicBackgroundControlContext::NewL( |
|
376 KAknsIIDQsnBgAreaMainMessage, rectForSkin, EFalse ); |
|
377 |
|
378 } |
|
379 |
|
380 // Load icons from active skin context. |
|
381 LoadIconsL(); |
|
382 // Set size and position for the icons. |
|
383 RefreshCoordinates(); |
|
384 // Draw again, since icons or background context might have changed. |
|
385 DrawDeferred(); |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------- |
|
389 // CPostcardController::LoadIconsL() |
|
390 // --------------------------------------------------------- |
|
391 void CPostcardController::LoadIconsL( ) |
|
392 { |
|
393 |
|
394 TParse parseDrive; |
|
395 parseDrive.Set( iDocument.AppFullName( ), NULL, NULL ); |
|
396 TPtrC drive = parseDrive.Drive( ); |
|
397 |
|
398 TParse parse; |
|
399 parse.Set( KPostcardMifFile, &KDC_APP_BITMAP_DIR, NULL ); |
|
400 |
|
401 TFileName fileName( parse.FullName( ) ); |
|
402 fileName.Insert( 0, drive ); |
|
403 |
|
404 iFrontBg = DoLoadIconL( |
|
405 KAknsIIDQgnGrafMmsPostcardFront, |
|
406 fileName, |
|
407 EMbmPostcardQgn_graf_mms_postcard_front, |
|
408 EMbmPostcardQgn_graf_mms_postcard_front_mask |
|
409 ); |
|
410 iInsertImageBg = DoLoadIconL( |
|
411 KAknsIIDQgnGrafMmsPostcardInsertImageBg, |
|
412 fileName, |
|
413 EMbmPostcardQgn_graf_mms_postcard_insert_image_bg, |
|
414 EMbmPostcardQgn_graf_mms_postcard_insert_image_bg_mask |
|
415 ); |
|
416 iInsertImage = DoLoadIconL( |
|
417 KAknsIIDQgnGrafMmsInsertImage, |
|
418 fileName, |
|
419 EMbmPostcardQgn_graf_mms_insert_image, |
|
420 EMbmPostcardQgn_graf_mms_insert_image |
|
421 ); |
|
422 |
|
423 iBgBg = DoLoadIconL( |
|
424 KAknsIIDQgnGrafMmsPostcardBack, |
|
425 fileName, |
|
426 EMbmPostcardQgn_graf_mms_postcard_back, |
|
427 EMbmPostcardQgn_graf_mms_postcard_back_mask |
|
428 ); |
|
429 iStamp = DoLoadIconL( |
|
430 KAknsIIDQgnIndiMmsPostcardStamp, |
|
431 fileName, |
|
432 EMbmPostcardQgn_indi_mms_postcard_stamp, |
|
433 EMbmPostcardQgn_indi_mms_postcard_stamp_mask |
|
434 ); |
|
435 iEmptyGreetingFocused = DoLoadIconL( |
|
436 KAknsIIDQgnPropMmsPostcardGreetingActive, |
|
437 fileName, |
|
438 EMbmPostcardQgn_prop_mms_postcard_greeting_active, |
|
439 EMbmPostcardQgn_prop_mms_postcard_greeting_active_mask |
|
440 ); |
|
441 iEmptyGreeting = DoLoadIconL( |
|
442 KAknsIIDQgnPropMmsPostcardGreetingInactive, |
|
443 fileName, |
|
444 EMbmPostcardQgn_prop_mms_postcard_greeting_inactive, |
|
445 EMbmPostcardQgn_prop_mms_postcard_greeting_inactive_mask |
|
446 ); |
|
447 iEmptyAddressFocused = DoLoadIconL( |
|
448 KAknsIIDQgnPropMmsPostcardAddressActive, |
|
449 fileName, |
|
450 EMbmPostcardQgn_prop_mms_postcard_address_active, |
|
451 EMbmPostcardQgn_prop_mms_postcard_address_active_mask |
|
452 ); |
|
453 iEmptyAddress = DoLoadIconL( |
|
454 KAknsIIDQgnPropMmsPostcardAddressInactive, |
|
455 fileName, |
|
456 EMbmPostcardQgn_prop_mms_postcard_address_inactive, |
|
457 EMbmPostcardQgn_prop_mms_postcard_address_inactive_mask |
|
458 ); |
|
459 |
|
460 iUpperArrow = DoLoadIconL( |
|
461 KAknsIIDQgnIndiMmsPostcardUp, |
|
462 fileName, |
|
463 EMbmPostcardQgn_indi_mms_postcard_up, |
|
464 EMbmPostcardQgn_indi_mms_postcard_up_mask |
|
465 ); |
|
466 iLowerArrow = DoLoadIconL( |
|
467 KAknsIIDQgnIndiMmsPostcardDown, |
|
468 fileName, |
|
469 EMbmPostcardQgn_indi_mms_postcard_down, |
|
470 EMbmPostcardQgn_indi_mms_postcard_down_mask |
|
471 ); |
|
472 // AppUi fills the other member icon variables |
|
473 } |
|
474 |
|
475 // --------------------------------------------------------- |
|
476 // CPostcardController::DoLoadIconLC() |
|
477 // --------------------------------------------------------- |
|
478 // |
|
479 CGulIcon* CPostcardController::DoLoadIconL( |
|
480 const TAknsItemID& aId, |
|
481 const TDesC& aFileName, |
|
482 const TInt aFileBitmapId, |
|
483 const TInt aFileMaskId ) |
|
484 { |
|
485 CGulIcon* icon = NULL; |
|
486 icon = AknsUtils::CreateGulIconL( |
|
487 AknsUtils::SkinInstance(), |
|
488 aId, |
|
489 aFileName, |
|
490 aFileBitmapId, |
|
491 aFileMaskId |
|
492 ); |
|
493 |
|
494 return icon; |
|
495 } |
|
496 |
|
497 // --------------------------------------------------------- |
|
498 // CPostcardController::RefreshCoordinates |
|
499 // --------------------------------------------------------- |
|
500 void CPostcardController::RefreshCoordinates( ) |
|
501 { |
|
502 // Read the new coordinates from LAF and sets the sizes |
|
503 SetRect( PostcardLaf::MainPostcardPane( ) ); |
|
504 |
|
505 iFrontBgC = PostcardLaf::FrontBackground( ); |
|
506 AknIconUtils::SetSize( iFrontBg->Bitmap(), iFrontBgC.Size( ), EAspectRatioNotPreserved ); |
|
507 AknIconUtils::SetSize( iInsertImageBg->Bitmap( ), iFrontBgC.Size( ), EAspectRatioNotPreserved ); |
|
508 iInsertImageC = PostcardLaf::InsertImageIcon( ); |
|
509 AknIconUtils::SetSize( iInsertImage->Bitmap(), iInsertImageC.Size( ), EAspectRatioNotPreserved ); |
|
510 iInsertImageBgC = PostcardLaf::FrontBackgroundWithoutImage( ); |
|
511 iImageC = PostcardLaf::Image( ); |
|
512 |
|
513 iBgBgC = PostcardLaf::BackBackground( ); |
|
514 AknIconUtils::SetSize( iBgBg->Bitmap(), iBgBgC.Size( ), EAspectRatioNotPreserved ); |
|
515 iStampC = PostcardLaf::Stamp( ); |
|
516 AknIconUtils::SetSize( iStamp->Bitmap(), iStampC.Size( ), EAspectRatioNotPreserved ); |
|
517 iGreetingC = PostcardLaf::GreetingText( ); |
|
518 AknIconUtils::SetSize( iEmptyGreeting->Bitmap(), iGreetingC.Size( ), EAspectRatioNotPreserved ); |
|
519 AknIconUtils::SetSize( iEmptyGreetingFocused->Bitmap(), iGreetingC.Size( ), EAspectRatioNotPreserved ); |
|
520 iAddressC = PostcardLaf::Address( ); |
|
521 AknIconUtils::SetSize( iEmptyAddress->Bitmap(), iAddressC.Size( ), EAspectRatioNotPreserved ); |
|
522 AknIconUtils::SetSize( iEmptyAddressFocused->Bitmap(), iAddressC.Size( ), EAspectRatioNotPreserved ); |
|
523 |
|
524 iUpperArrowC = PostcardLaf::UpperArrow( ); |
|
525 AknIconUtils::SetSize( iUpperArrow->Bitmap(), iUpperArrowC.Size( ), EAspectRatioNotPreserved ); |
|
526 iLowerArrowC = PostcardLaf::LowerArrow( ); |
|
527 AknIconUtils::SetSize( iLowerArrow->Bitmap(), iLowerArrowC.Size( ), EAspectRatioNotPreserved ); |
|
528 |
|
529 if ( iBgContext ) |
|
530 { |
|
531 iBgContext->SetRect( PostcardLaf::RelativeMainPostcardPane( ) ); |
|
532 } |
|
533 } |
|
534 |
|
535 // --------------------------------------------------------- |
|
536 // CPostcardController::Frontpage |
|
537 // --------------------------------------------------------- |
|
538 TBool CPostcardController::Frontpage( ) |
|
539 { |
|
540 return iFocusedItem==EPostcardImage?ETrue:EFalse; |
|
541 } |
|
542 |
|
543 // --------------------------------------------------------- |
|
544 // CPostcardController::IsFocused( ) |
|
545 // --------------------------------------------------------- |
|
546 TBool CPostcardController::IsFocused( TPostcardPart& aPart ) |
|
547 { |
|
548 return iFocusedItem==aPart?ETrue:EFalse; |
|
549 } |
|
550 |
|
551 // --------------------------------------------------------- |
|
552 // CPostcardController::SetFocused( ) |
|
553 // --------------------------------------------------------- |
|
554 void CPostcardController::SetFocused( TPostcardPart aPart ) |
|
555 { |
|
556 iFocusedItem = aPart; |
|
557 } |
|
558 |
|
559 // --------------------------------------------------------- |
|
560 // CPostcardController::Focused( ) |
|
561 // --------------------------------------------------------- |
|
562 TPostcardPart CPostcardController::Focused( ) |
|
563 { |
|
564 return iFocusedItem; |
|
565 } |
|
566 |
|
567 // --------------------------------------------------------- |
|
568 // CPostcardController::SetBitmap( ) |
|
569 // --------------------------------------------------------- |
|
570 void CPostcardController::SetBitmap( TPostcardPart aPart, CGulIcon* aIcon ) |
|
571 { |
|
572 switch( aPart ) |
|
573 { |
|
574 case EPostcardImage: |
|
575 { |
|
576 delete iImage; |
|
577 iImage = aIcon; |
|
578 break; |
|
579 } |
|
580 case EPostcardText: |
|
581 { |
|
582 delete iGreeting; |
|
583 iGreeting = aIcon; |
|
584 break; |
|
585 } |
|
586 case EPostcardRecipient: |
|
587 { |
|
588 delete iAddress; |
|
589 iAddress = aIcon; |
|
590 break; |
|
591 } |
|
592 default: |
|
593 break; |
|
594 } |
|
595 } |
|
596 |
|
597 // --------------------------------------------------------- |
|
598 // CPostcardController::RemoveBitmap( ) |
|
599 // --------------------------------------------------------- |
|
600 void CPostcardController::RemoveBitmap( TPostcardPart aPart ) |
|
601 { |
|
602 switch( aPart ) |
|
603 { |
|
604 case EPostcardImage: |
|
605 { |
|
606 delete iImage; |
|
607 iImage = NULL; |
|
608 break; |
|
609 } |
|
610 case EPostcardText: |
|
611 { |
|
612 delete iGreeting; |
|
613 iGreeting = NULL; |
|
614 break; |
|
615 } |
|
616 case EPostcardRecipient: |
|
617 { |
|
618 delete iAddress; |
|
619 iAddress = NULL; |
|
620 break; |
|
621 } |
|
622 default: |
|
623 break; |
|
624 } |
|
625 } |
|
626 |
|
627 // --------------------------------------------------------- |
|
628 // CPostcardController::Move( ) |
|
629 // --------------------------------------------------------- |
|
630 void CPostcardController::Move( TInt aScanCode ) |
|
631 { |
|
632 TBool mirrored = AknLayoutUtils::LayoutMirrored(); |
|
633 switch ( aScanCode ) |
|
634 { |
|
635 case EStdKeyLeftArrow: |
|
636 MoveHorizontally( mirrored?ETrue:EFalse ); |
|
637 break; |
|
638 case EStdKeyRightArrow: |
|
639 MoveHorizontally( mirrored?EFalse:ETrue ); |
|
640 break; |
|
641 case EStdKeyUpArrow: |
|
642 MoveVertically( ETrue ); |
|
643 break; |
|
644 case EStdKeyDownArrow: |
|
645 MoveVertically( EFalse ); |
|
646 break; |
|
647 default: // no operation |
|
648 break; |
|
649 } |
|
650 } |
|
651 |
|
652 // --------------------------------------------------------- |
|
653 // CPostcardController::MoveHorizontally( ) |
|
654 // --------------------------------------------------------- |
|
655 void CPostcardController::MoveHorizontally( TBool aRight ) |
|
656 { |
|
657 if( Focused( ) == EPostcardImage ) |
|
658 { |
|
659 return; // can not move horizontally in the image side |
|
660 } |
|
661 if( Focused( ) == EPostcardText && aRight ) |
|
662 { |
|
663 SetFocused( EPostcardRecipient ); |
|
664 DrawDeferred( ); |
|
665 } |
|
666 else if( Focused( ) == EPostcardRecipient && !aRight ) |
|
667 { |
|
668 SetFocused( EPostcardText ); |
|
669 DrawDeferred( ); |
|
670 } |
|
671 } |
|
672 |
|
673 // --------------------------------------------------------- |
|
674 // CPostcardController::MoveVertically( ) |
|
675 // --------------------------------------------------------- |
|
676 void CPostcardController::MoveVertically( TBool aUp ) |
|
677 { |
|
678 // Behaviour depends on whether we are in editor or |
|
679 // viewer mode. |
|
680 if ( iDocument.MessageType() != EPostcardSent ) |
|
681 { |
|
682 if( Focused( ) == EPostcardImage && aUp ) |
|
683 { |
|
684 SetFocused( EPostcardRecipient ); |
|
685 DrawDeferred( ); |
|
686 } |
|
687 else if( Focused( ) != EPostcardImage && !aUp ) |
|
688 { |
|
689 SetFocused( EPostcardImage ); |
|
690 DrawDeferred( ); |
|
691 } |
|
692 } |
|
693 else |
|
694 { |
|
695 if( Focused( ) == EPostcardImage && !aUp ) |
|
696 { |
|
697 SetFocused( EPostcardRecipient ); |
|
698 DrawDeferred( ); |
|
699 } |
|
700 else if( Focused( ) != EPostcardImage && aUp ) |
|
701 { |
|
702 SetFocused( EPostcardImage ); |
|
703 DrawDeferred( ); |
|
704 } |
|
705 } |
|
706 } |
|
707 |
|
708 // --------------------------------------------------------- |
|
709 // CPostcardController::MopSupplyObject |
|
710 // |
|
711 // --------------------------------------------------------- |
|
712 // |
|
713 TTypeUid::Ptr CPostcardController::MopSupplyObject( TTypeUid aId ) |
|
714 { |
|
715 if ( aId.iUid == MAknsControlContext::ETypeId && iBgContext) |
|
716 { |
|
717 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
718 } |
|
719 |
|
720 return CCoeControl::MopSupplyObject( aId ); |
|
721 } |
|
722 |
|
723 #ifdef RD_SCALABLE_UI_V2 |
|
724 // --------------------------------------------------------- |
|
725 // CPostcardController::HandlePointerEventL |
|
726 // |
|
727 // --------------------------------------------------------- |
|
728 // |
|
729 void CPostcardController::HandlePointerEventL( |
|
730 const TPointerEvent& aPointerEvent ) |
|
731 { |
|
732 if ( AknLayoutUtils::PenEnabled() ) |
|
733 { |
|
734 struct TPocaHitTarget |
|
735 { |
|
736 const TRect CPostcardController::* iRect; // pointer to a member |
|
737 TPocaPointerEvent iEvent; |
|
738 TInt iTapType; // tap types the target is interested in |
|
739 }; |
|
740 |
|
741 TPocaHitTarget backArrow; |
|
742 TPocaHitTarget frontArrow; |
|
743 |
|
744 |
|
745 // Construct image and text side hit target arrays. Notice that |
|
746 // editor and viewer handles navigation arrow differently. |
|
747 if ( iDocument.MessageType() == EPostcardSent ) |
|
748 { |
|
749 // In viewer, image side has arrow down. |
|
750 backArrow.iRect = &CPostcardController::iUpperArrowC; |
|
751 backArrow.iEvent = EPocaPointerEventUpIcon; |
|
752 backArrow.iTapType = EPocaPointerEventTypeSingleDown; |
|
753 |
|
754 frontArrow.iRect = &CPostcardController::iLowerArrowC; |
|
755 frontArrow.iEvent = EPocaPointerEventDownIcon; |
|
756 frontArrow.iTapType = EPocaPointerEventTypeSingleDown; |
|
757 } |
|
758 else |
|
759 { |
|
760 // In editor, image side has arrow up. |
|
761 backArrow.iRect = &CPostcardController::iLowerArrowC; |
|
762 backArrow.iEvent = EPocaPointerEventDownIcon; |
|
763 backArrow.iTapType = EPocaPointerEventTypeSingleDown; |
|
764 |
|
765 frontArrow.iRect = &CPostcardController::iUpperArrowC; |
|
766 frontArrow.iEvent = EPocaPointerEventUpIcon; |
|
767 frontArrow.iTapType = EPocaPointerEventTypeSingleDown; |
|
768 } |
|
769 |
|
770 // Front (image) side hit test targets |
|
771 const TPocaHitTarget frontTargets[] = |
|
772 { |
|
773 frontArrow, |
|
774 {&CPostcardController::iFrontBgC, EPocaPointerEventFrontBg, |
|
775 EPocaPointerEventTypeSingleUp }, |
|
776 {NULL} // end marker |
|
777 }; |
|
778 // Back (address) side hit test targets |
|
779 const TPocaHitTarget backTargets[] = |
|
780 { |
|
781 backArrow, |
|
782 {&CPostcardController::iGreetingC, EPocaPointerEventGreeting, |
|
783 EPocaPointerEventTypeSingleDown }, |
|
784 {&CPostcardController::iAddressC, EPocaPointerEventAddress, |
|
785 EPocaPointerEventTypeSingleDown }, |
|
786 {NULL} // end marker |
|
787 }; |
|
788 |
|
789 TPocaPointerEventType tapType = EPocaPointerEventTypeNone; |
|
790 // Check it was button1 |
|
791 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
792 { |
|
793 tapType = EPocaPointerEventTypeSingleDown; |
|
794 } |
|
795 else if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
796 { |
|
797 tapType = EPocaPointerEventTypeSingleUp; |
|
798 } |
|
799 |
|
800 if ( tapType == EPocaPointerEventTypeNone ) |
|
801 { |
|
802 return; |
|
803 } |
|
804 |
|
805 // Do hit testing on targets |
|
806 TBool hit = EFalse; |
|
807 const TPocaHitTarget* target = iFocusedItem == EPostcardImage ? |
|
808 frontTargets : backTargets; |
|
809 for( ; target->iRect && !hit; target++ ) |
|
810 { |
|
811 hit = (this->*target->iRect).Contains( aPointerEvent.iPosition ); |
|
812 |
|
813 if ( hit ) |
|
814 { |
|
815 // There was a pointer event hitting one of our targets |
|
816 // Check that we have a valid tap and relay event to |
|
817 // observer. |
|
818 |
|
819 if ( target->iTapType & tapType) |
|
820 { |
|
821 iEventObserver.PocaPointerEventL( target->iEvent, tapType ); |
|
822 } |
|
823 } |
|
824 } |
|
825 } |
|
826 } |
|
827 #endif // RD_SCALABLE_UI_V2 |
|
828 |
|
829 // --------------------------------------------------------- |
|
830 // CPostcardController::DrawFocus |
|
831 // |
|
832 // --------------------------------------------------------- |
|
833 // |
|
834 void CPostcardController::DrawFocus( ) const |
|
835 { |
|
836 CWindowGc& gc = SystemGc(); |
|
837 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
838 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
839 |
|
840 if( iFocusedItem == EPostcardText ) |
|
841 { |
|
842 gc.SetBrushColor( AKN_LAF_COLOR(210) ); |
|
843 } |
|
844 else |
|
845 { |
|
846 gc.SetBrushColor( AKN_LAF_COLOR(86) ); |
|
847 } |
|
848 for ( TInt i = 0; i < iGreetingLines->Count( ); i++ ) |
|
849 { |
|
850 TRect rect = *( iGreetingLines->At( i ) ); |
|
851 if( iFocusedItem == EPostcardText ) |
|
852 { |
|
853 rect.iBr.iY += 1; // Increase the height by one when focused |
|
854 } |
|
855 // 1-pixel-high rects are not drawn so in that case use DrawLine |
|
856 if( rect.iBr.iY > rect.iTl.iY ) |
|
857 { |
|
858 gc.DrawRect( rect ); |
|
859 } |
|
860 else |
|
861 { |
|
862 gc.DrawRect( rect ); |
|
863 } |
|
864 } |
|
865 if( iFocusedItem == EPostcardRecipient ) |
|
866 { |
|
867 gc.SetBrushColor( AKN_LAF_COLOR(210) ); |
|
868 } |
|
869 else |
|
870 { |
|
871 gc.SetBrushColor( AKN_LAF_COLOR(86) ); |
|
872 } |
|
873 for ( TInt i = 0; i < iRecipientLines->Count( ); i++ ) |
|
874 { |
|
875 TRect rect = *( iRecipientLines->At( i ) ); |
|
876 if( iFocusedItem == EPostcardRecipient ) |
|
877 { |
|
878 rect.iBr.iY += 1; // Increase the height by one when focused |
|
879 } |
|
880 // 1-pixel-high rects are not drawn so in that case use DrawLine |
|
881 if( rect.iBr.iY > rect.iTl.iY ) |
|
882 { |
|
883 gc.DrawRect( rect ); |
|
884 } |
|
885 else |
|
886 { |
|
887 gc.DrawRect( rect ); |
|
888 } |
|
889 } |
|
890 } |
|
891 |
|
892 // --------------------------------------------------------- |
|
893 // CPostcardController::SetGreetingLines |
|
894 // |
|
895 // --------------------------------------------------------- |
|
896 void CPostcardController::SetGreetingLines( CArrayPtrFlat<TRect>& aGreetingLines ) |
|
897 { |
|
898 if( iGreetingLines ) |
|
899 { |
|
900 iGreetingLines->ResetAndDestroy( ); |
|
901 delete iGreetingLines; |
|
902 iGreetingLines = NULL; |
|
903 } |
|
904 iGreetingLines = &aGreetingLines; |
|
905 } |
|
906 |
|
907 // --------------------------------------------------------- |
|
908 // CPostcardController::SetRecipientLines |
|
909 // |
|
910 // --------------------------------------------------------- |
|
911 void CPostcardController::SetRecipientLines( CArrayPtrFlat<TRect>& aRecipientLines ) |
|
912 { |
|
913 if( iRecipientLines ) |
|
914 { |
|
915 iRecipientLines->ResetAndDestroy( ); |
|
916 delete iRecipientLines; |
|
917 iRecipientLines = NULL; |
|
918 } |
|
919 iRecipientLines = &aRecipientLines; |
|
920 } |
|
921 |
|
922 // End of File |