mobilemessaging/postcard/postcardsrc/PostcardController.cpp
changeset 79 2981cb3aa489
equal deleted inserted replaced
25:84d9eb65b26f 79:2981cb3aa489
       
     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 = DoLoadIconforUpandDownarrowL(
       
   461         KAknsIIDQgnIndiMmsPostcardUp,
       
   462         fileName, 
       
   463         EMbmPostcardQgn_indi_mms_postcard_up,
       
   464         EMbmPostcardQgn_indi_mms_postcard_up_mask
       
   465         );
       
   466     iLowerArrow = DoLoadIconforUpandDownarrowL(
       
   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     
       
   486     
       
   487     CGulIcon* icon = NULL;
       
   488     
       
   489    
       
   490     icon = AknsUtils::CreateGulIconL(
       
   491         AknsUtils::SkinInstance(),
       
   492         aId,
       
   493         aFileName,
       
   494         aFileBitmapId,
       
   495         aFileMaskId
       
   496         );  
       
   497     
       
   498     return icon;
       
   499      
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------
       
   503 // CPostcardController::DoLoadIconforUpandDownarrowL()
       
   504 // ---------------------------------------------------------
       
   505 //
       
   506 CGulIcon* CPostcardController::DoLoadIconforUpandDownarrowL( 
       
   507                                 const TAknsItemID& aId,
       
   508                                 const TDesC& aFileName,
       
   509                                 const TInt aFileBitmapId,
       
   510                                 const TInt aFileMaskId  )
       
   511     {
       
   512     
       
   513     CFbsBitmap* bitmap = NULL;
       
   514     CFbsBitmap* mask = NULL;
       
   515 
       
   516    
       
   517     AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(), 
       
   518                                  aId,
       
   519                                  KAknsIIDQsnIconColors,
       
   520                                  EAknsCIQsnIconColorsCG6,
       
   521                                  bitmap, 
       
   522                                  mask,
       
   523                                  aFileName, 
       
   524                                  aFileBitmapId,
       
   525                                  aFileMaskId,
       
   526                                  KRgbBlack); 
       
   527   
       
   528     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   529     CleanupStack::Pop( 2 ); // bitmap, mask
       
   530 
       
   531     return icon;
       
   532     }
       
   533 
       
   534 // ---------------------------------------------------------
       
   535 // CPostcardController::RefreshCoordinates
       
   536 // ---------------------------------------------------------
       
   537 void CPostcardController::RefreshCoordinates( )
       
   538     {
       
   539     // Read the new coordinates from LAF and sets the sizes
       
   540     SetRect( PostcardLaf::MainPostcardPane( ) );    
       
   541 
       
   542     iFrontBgC       = PostcardLaf::FrontBackground( );
       
   543     AknIconUtils::SetSize( iFrontBg->Bitmap(), iFrontBgC.Size( ), EAspectRatioNotPreserved );
       
   544     AknIconUtils::SetSize( iInsertImageBg->Bitmap( ), iFrontBgC.Size( ), EAspectRatioNotPreserved );
       
   545     iInsertImageC   = PostcardLaf::InsertImageIcon( );
       
   546     AknIconUtils::SetSize( iInsertImage->Bitmap(), iInsertImageC.Size( ), EAspectRatioNotPreserved );
       
   547     iInsertImageBgC   = PostcardLaf::FrontBackgroundWithoutImage( );
       
   548     iImageC         = PostcardLaf::Image( );
       
   549     
       
   550     iBgBgC          = PostcardLaf::BackBackground( );
       
   551     AknIconUtils::SetSize( iBgBg->Bitmap(), iBgBgC.Size( ), EAspectRatioNotPreserved );
       
   552     iStampC         = PostcardLaf::Stamp( );
       
   553     AknIconUtils::SetSize( iStamp->Bitmap(), iStampC.Size( ), EAspectRatioNotPreserved );
       
   554     iGreetingC      = PostcardLaf::GreetingText( );
       
   555     AknIconUtils::SetSize( iEmptyGreeting->Bitmap(), iGreetingC.Size( ), EAspectRatioNotPreserved );
       
   556     AknIconUtils::SetSize( iEmptyGreetingFocused->Bitmap(), iGreetingC.Size( ), EAspectRatioNotPreserved );
       
   557     iAddressC       = PostcardLaf::Address( );
       
   558     AknIconUtils::SetSize( iEmptyAddress->Bitmap(), iAddressC.Size( ), EAspectRatioNotPreserved );
       
   559     AknIconUtils::SetSize( iEmptyAddressFocused->Bitmap(), iAddressC.Size( ), EAspectRatioNotPreserved );
       
   560 
       
   561     iUpperArrowC    = PostcardLaf::UpperArrow( );
       
   562     AknIconUtils::SetSize( iUpperArrow->Bitmap(), iUpperArrowC.Size( ), EAspectRatioNotPreserved );
       
   563     iLowerArrowC    = PostcardLaf::LowerArrow( );
       
   564     AknIconUtils::SetSize( iLowerArrow->Bitmap(), iLowerArrowC.Size( ), EAspectRatioNotPreserved );
       
   565 
       
   566     if ( iBgContext )
       
   567         {
       
   568         iBgContext->SetRect( PostcardLaf::RelativeMainPostcardPane( ) );
       
   569         }
       
   570     }
       
   571 
       
   572 // ---------------------------------------------------------
       
   573 // CPostcardController::Frontpage
       
   574 // ---------------------------------------------------------
       
   575 TBool CPostcardController::Frontpage( )
       
   576     {
       
   577     return iFocusedItem==EPostcardImage?ETrue:EFalse;
       
   578     }
       
   579 
       
   580 // ---------------------------------------------------------
       
   581 // CPostcardController::IsFocused( )
       
   582 // ---------------------------------------------------------
       
   583 TBool CPostcardController::IsFocused( TPostcardPart& aPart )
       
   584     {
       
   585     return iFocusedItem==aPart?ETrue:EFalse;
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------
       
   589 // CPostcardController::SetFocused( )
       
   590 // ---------------------------------------------------------
       
   591 void CPostcardController::SetFocused( TPostcardPart aPart )
       
   592     {
       
   593     iFocusedItem = aPart;
       
   594     }
       
   595 
       
   596 // ---------------------------------------------------------
       
   597 // CPostcardController::Focused( )
       
   598 // ---------------------------------------------------------
       
   599 TPostcardPart CPostcardController::Focused( )
       
   600 	{
       
   601 	return iFocusedItem;
       
   602 	}
       
   603 
       
   604 // ---------------------------------------------------------
       
   605 // CPostcardController::SetBitmap( )
       
   606 // ---------------------------------------------------------
       
   607 void CPostcardController::SetBitmap( TPostcardPart aPart, CGulIcon* aIcon )
       
   608     {
       
   609     switch( aPart )
       
   610         {
       
   611         case EPostcardImage:
       
   612             {
       
   613             delete iImage;
       
   614             iImage = aIcon;
       
   615             break;
       
   616             }
       
   617         case EPostcardText:
       
   618             {
       
   619             delete iGreeting;
       
   620             iGreeting = aIcon;
       
   621             break;
       
   622             }
       
   623         case EPostcardRecipient:
       
   624             {
       
   625             delete iAddress;
       
   626             iAddress = aIcon;
       
   627             break;
       
   628             }
       
   629         default:
       
   630             break;
       
   631         }
       
   632     }
       
   633 
       
   634 // ---------------------------------------------------------
       
   635 // CPostcardController::RemoveBitmap( )
       
   636 // ---------------------------------------------------------
       
   637 void CPostcardController::RemoveBitmap( TPostcardPart aPart )
       
   638     {
       
   639     switch( aPart )
       
   640         {
       
   641         case EPostcardImage:
       
   642             {
       
   643             delete iImage;
       
   644             iImage = NULL;
       
   645             break;
       
   646             }
       
   647         case EPostcardText:
       
   648             {
       
   649             delete iGreeting;
       
   650             iGreeting = NULL;
       
   651             break;
       
   652             }
       
   653         case EPostcardRecipient:
       
   654             {
       
   655             delete iAddress;
       
   656             iAddress = NULL;
       
   657             break;
       
   658             }
       
   659         default:
       
   660             break;
       
   661         }
       
   662     }
       
   663 
       
   664 // ---------------------------------------------------------
       
   665 // CPostcardController::Move( )
       
   666 // ---------------------------------------------------------
       
   667 void CPostcardController::Move( TInt aScanCode )
       
   668     {
       
   669     TBool mirrored = AknLayoutUtils::LayoutMirrored();
       
   670     switch ( aScanCode )
       
   671         {
       
   672         case EStdKeyLeftArrow:
       
   673             MoveHorizontally( mirrored?ETrue:EFalse );
       
   674             break;
       
   675         case EStdKeyRightArrow:
       
   676             MoveHorizontally( mirrored?EFalse:ETrue ); 
       
   677             break;
       
   678         case EStdKeyUpArrow:    
       
   679             MoveVertically( ETrue );
       
   680             break;
       
   681         case EStdKeyDownArrow:  
       
   682             MoveVertically( EFalse );
       
   683             break;
       
   684         default: // no operation
       
   685             break;
       
   686         }    
       
   687     }
       
   688 
       
   689 // ---------------------------------------------------------
       
   690 // CPostcardController::MoveHorizontally( )
       
   691 // ---------------------------------------------------------
       
   692 void CPostcardController::MoveHorizontally( TBool aRight )
       
   693     {
       
   694     if( Focused( ) == EPostcardImage )
       
   695         {
       
   696         return; // can not move horizontally in the image side
       
   697         }
       
   698     if( Focused( ) == EPostcardText && aRight )
       
   699         {
       
   700         SetFocused( EPostcardRecipient );
       
   701         DrawDeferred( );
       
   702         }
       
   703     else if( Focused( ) == EPostcardRecipient && !aRight )
       
   704         {
       
   705         SetFocused( EPostcardText );
       
   706         DrawDeferred( );
       
   707         }
       
   708     }
       
   709 
       
   710 // ---------------------------------------------------------
       
   711 // CPostcardController::MoveVertically( )
       
   712 // ---------------------------------------------------------
       
   713 void CPostcardController::MoveVertically( TBool aUp )
       
   714     {
       
   715     // Behaviour depends on whether we are in editor or 
       
   716     // viewer mode. 
       
   717     if ( iDocument.MessageType() != EPostcardSent )
       
   718         {
       
   719         if( Focused( ) == EPostcardImage && aUp )
       
   720             {
       
   721             SetFocused( EPostcardRecipient );
       
   722             DrawDeferred( );
       
   723             }
       
   724         else if( Focused( ) != EPostcardImage && !aUp )
       
   725             {
       
   726             SetFocused( EPostcardImage );
       
   727             DrawDeferred( );
       
   728             }
       
   729         }
       
   730     else
       
   731         {
       
   732         if( Focused( ) == EPostcardImage && !aUp )
       
   733             {
       
   734             SetFocused( EPostcardRecipient );
       
   735             DrawDeferred( );
       
   736             }
       
   737         else if( Focused( ) != EPostcardImage && aUp )
       
   738             {
       
   739             SetFocused( EPostcardImage );
       
   740             DrawDeferred( );
       
   741             }
       
   742         }
       
   743     }
       
   744 
       
   745 // ---------------------------------------------------------
       
   746 // CPostcardController::MopSupplyObject
       
   747 //
       
   748 // ---------------------------------------------------------
       
   749 //
       
   750 TTypeUid::Ptr CPostcardController::MopSupplyObject( TTypeUid aId )
       
   751     {   
       
   752     if ( aId.iUid == MAknsControlContext::ETypeId && iBgContext)
       
   753         {
       
   754         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   755         }
       
   756 
       
   757     return CCoeControl::MopSupplyObject( aId );
       
   758     }
       
   759 
       
   760 #ifdef RD_SCALABLE_UI_V2
       
   761 // ---------------------------------------------------------
       
   762 // CPostcardController::HandlePointerEventL
       
   763 //
       
   764 // ---------------------------------------------------------
       
   765 //
       
   766 void CPostcardController::HandlePointerEventL(
       
   767     const TPointerEvent& aPointerEvent )
       
   768     {
       
   769     if ( AknLayoutUtils::PenEnabled() )
       
   770         {
       
   771         struct TPocaHitTarget
       
   772             {
       
   773             const TRect CPostcardController::* iRect; // pointer to a member
       
   774             TPocaPointerEvent iEvent;
       
   775             TInt iTapType; // tap types the target is interested in
       
   776             };
       
   777 
       
   778         TPocaHitTarget backArrow;
       
   779         TPocaHitTarget frontArrow;
       
   780         
       
   781         
       
   782         // Construct image and text side hit target arrays. Notice that
       
   783         // editor and viewer handles navigation arrow differently.
       
   784         if ( iDocument.MessageType() == EPostcardSent )
       
   785             {
       
   786             // In viewer, image side has arrow down.
       
   787             backArrow.iRect = &CPostcardController::iUpperArrowC;
       
   788             backArrow.iEvent = EPocaPointerEventUpIcon;
       
   789             backArrow.iTapType = EPocaPointerEventTypeSingleDown;
       
   790             
       
   791             frontArrow.iRect = &CPostcardController::iLowerArrowC;
       
   792             frontArrow.iEvent = EPocaPointerEventDownIcon;
       
   793             frontArrow.iTapType = EPocaPointerEventTypeSingleDown;
       
   794             }
       
   795         else
       
   796             {
       
   797             // In editor, image side has arrow up.
       
   798             backArrow.iRect = &CPostcardController::iLowerArrowC;
       
   799             backArrow.iEvent = EPocaPointerEventDownIcon;
       
   800             backArrow.iTapType = EPocaPointerEventTypeSingleDown;
       
   801 
       
   802             frontArrow.iRect = &CPostcardController::iUpperArrowC;
       
   803             frontArrow.iEvent = EPocaPointerEventUpIcon;
       
   804             frontArrow.iTapType = EPocaPointerEventTypeSingleDown;
       
   805             }
       
   806         
       
   807         // Front (image) side hit test targets
       
   808         const TPocaHitTarget frontTargets[] =
       
   809             {
       
   810             frontArrow,
       
   811             {&CPostcardController::iFrontBgC, EPocaPointerEventFrontBg,
       
   812                 EPocaPointerEventTypeSingleUp },
       
   813             {NULL} // end marker
       
   814             };
       
   815         // Back (address) side hit test targets
       
   816         const TPocaHitTarget backTargets[] =
       
   817             {
       
   818             backArrow,
       
   819             {&CPostcardController::iGreetingC, EPocaPointerEventGreeting,
       
   820                 EPocaPointerEventTypeSingleDown },
       
   821             {&CPostcardController::iAddressC, EPocaPointerEventAddress,
       
   822                 EPocaPointerEventTypeSingleDown },
       
   823             {NULL} // end marker
       
   824             };
       
   825 
       
   826         TPocaPointerEventType tapType = EPocaPointerEventTypeNone;
       
   827         // Check it was button1
       
   828         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   829             {
       
   830             tapType = EPocaPointerEventTypeSingleDown;
       
   831             }
       
   832         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   833             {
       
   834             tapType = EPocaPointerEventTypeSingleUp;
       
   835             }
       
   836 
       
   837         if ( tapType == EPocaPointerEventTypeNone )
       
   838             {
       
   839             return;
       
   840             }
       
   841         
       
   842         // Do hit testing on targets
       
   843         TBool hit = EFalse;
       
   844         const TPocaHitTarget* target = iFocusedItem == EPostcardImage ?
       
   845             frontTargets : backTargets;
       
   846         for( ; target->iRect && !hit; target++ )
       
   847             {
       
   848             hit = (this->*target->iRect).Contains( aPointerEvent.iPosition );
       
   849 
       
   850             if ( hit )
       
   851                 {
       
   852                 // There was a pointer event hitting one of our targets
       
   853                 // Check that we have a valid tap and relay event to
       
   854                 // observer.
       
   855 
       
   856                 if ( target->iTapType & tapType)
       
   857                     {
       
   858                     iEventObserver.PocaPointerEventL( target->iEvent, tapType );
       
   859                     }
       
   860                 }
       
   861             }
       
   862         }
       
   863     }
       
   864 #endif // RD_SCALABLE_UI_V2
       
   865 
       
   866 // ---------------------------------------------------------
       
   867 // CPostcardController::DrawFocus
       
   868 //
       
   869 // ---------------------------------------------------------
       
   870 //
       
   871 void CPostcardController::DrawFocus( ) const
       
   872     {
       
   873     CWindowGc& gc = SystemGc();
       
   874 	gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   875 	gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   876 
       
   877     if( iFocusedItem == EPostcardText )
       
   878         {
       
   879         gc.SetBrushColor( AKN_LAF_COLOR(210) );                        
       
   880         }
       
   881     else
       
   882         {
       
   883         gc.SetBrushColor( AKN_LAF_COLOR(86) );            
       
   884         }
       
   885     for ( TInt i = 0; i < iGreetingLines->Count( ); i++ )
       
   886         {
       
   887         TRect rect = *( iGreetingLines->At( i ) );
       
   888         if( iFocusedItem == EPostcardText ) 
       
   889             {
       
   890             rect.iBr.iY += 1; // Increase the height by one when focused
       
   891             }
       
   892         // 1-pixel-high rects are not drawn so in that case use DrawLine
       
   893         if( rect.iBr.iY > rect.iTl.iY )
       
   894             {
       
   895             gc.DrawRect( rect );
       
   896             }
       
   897         else
       
   898             {
       
   899             gc.DrawRect( rect );
       
   900             }
       
   901         }
       
   902     if( iFocusedItem == EPostcardRecipient )
       
   903         {
       
   904         gc.SetBrushColor( AKN_LAF_COLOR(210) );
       
   905         }
       
   906     else
       
   907         {
       
   908         gc.SetBrushColor( AKN_LAF_COLOR(86) );            
       
   909         }
       
   910     for ( TInt i = 0; i < iRecipientLines->Count( ); i++ )
       
   911         {
       
   912         TRect rect = *( iRecipientLines->At( i ) );
       
   913         if( iFocusedItem == EPostcardRecipient ) 
       
   914             {
       
   915             rect.iBr.iY += 1; // Increase the height by one when focused
       
   916             }
       
   917         // 1-pixel-high rects are not drawn so in that case use DrawLine
       
   918         if( rect.iBr.iY > rect.iTl.iY )
       
   919             {
       
   920             gc.DrawRect( rect );
       
   921             }
       
   922         else
       
   923             {
       
   924             gc.DrawRect( rect );
       
   925             }
       
   926         }
       
   927     }
       
   928 
       
   929 // ---------------------------------------------------------
       
   930 // CPostcardController::SetGreetingLines
       
   931 //
       
   932 // ---------------------------------------------------------
       
   933 void CPostcardController::SetGreetingLines( CArrayPtrFlat<TRect>& aGreetingLines )
       
   934     {
       
   935     if( iGreetingLines )
       
   936         {
       
   937         iGreetingLines->ResetAndDestroy( );
       
   938         delete iGreetingLines;
       
   939         iGreetingLines = NULL;        
       
   940         }
       
   941     iGreetingLines = &aGreetingLines;
       
   942     }
       
   943         
       
   944 // ---------------------------------------------------------
       
   945 // CPostcardController::SetRecipientLines
       
   946 //
       
   947 // ---------------------------------------------------------
       
   948 void CPostcardController::SetRecipientLines( CArrayPtrFlat<TRect>& aRecipientLines )
       
   949     {
       
   950     if( iRecipientLines )
       
   951         {
       
   952         iRecipientLines->ResetAndDestroy( );
       
   953         delete iRecipientLines;
       
   954         iRecipientLines = NULL;
       
   955         }
       
   956     iRecipientLines = &aRecipientLines;
       
   957     }
       
   958 
       
   959 // End of File