messagingappbase/msgeditor/mediacontrolsrc/MsgIconControl.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 icon control
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "MsgIconControl.h"
       
    23 
       
    24 #include <gulicon.h>
       
    25 #include <AknUtils.h>
       
    26 #include <AknsUtils.h>
       
    27 #include <AknBitmapAnimation.h>
       
    28 #include <aknlayoutscalable_apps.cdl.h>
       
    29 
       
    30 // ==========================================================
       
    31 
       
    32 // EXTERNAL DATA STRUCTURES
       
    33 
       
    34 // EXTERNAL FUNCTION PROTOTYPES
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // MACROS
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 
       
    46 // ================= MEMBER FUNCTIONS =======================
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CMsgIconControl::CMsgIconControl
       
    50 //
       
    51 // Constructor
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CMsgIconControl::CMsgIconControl() :
       
    55     iFileBitmapId( KErrNotFound ),
       
    56     iFileMaskId( KErrNotFound )
       
    57     {
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CMsgIconControl::ConstructL
       
    62 //
       
    63 // Constructor
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 void CMsgIconControl::ConstructL( const CCoeControl& aParent )
       
    67     {
       
    68     SetContainerWindowL( aParent );
       
    69     MakeVisible( EFalse );
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CMsgIconControl::NewL
       
    74 //
       
    75 // Constructor
       
    76 // ---------------------------------------------------------
       
    77 //
       
    78 CMsgIconControl* CMsgIconControl::NewL( const CCoeControl& aParent )
       
    79     {
       
    80     CMsgIconControl* self = new( ELeave ) CMsgIconControl;
       
    81     
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL( aParent );
       
    84     CleanupStack::Pop( self );
       
    85     
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------
       
    90 // CMsgIconControl::NewL
       
    91 //
       
    92 // Destructor
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 CMsgIconControl::~CMsgIconControl()
       
    96     {
       
    97     delete iIcon;
       
    98     delete iFileName;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // CMsgIconControl::SetIcon
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 void CMsgIconControl::SetIcon( CGulIcon* aIcon )
       
   106     {
       
   107     delete iIcon;
       
   108     iIcon = aIcon; 
       
   109     
       
   110     if ( iIcon == NULL )
       
   111         {
       
   112         iFileBitmapId = KErrNotFound;
       
   113         iFileMaskId = KErrNotFound;
       
   114         }
       
   115     }
       
   116     
       
   117 // ---------------------------------------------------------
       
   118 // CMsgIconControl::LoadIconL
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 void CMsgIconControl::LoadIconL( const TAknsItemID& aId,
       
   122                                  const TDesC& aFileName,
       
   123                                  const TInt aFileBitmapId,
       
   124                                  const TInt aFileMaskId )
       
   125     {
       
   126     delete iIcon;
       
   127     iIcon = NULL;
       
   128     
       
   129     iIcon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   130                                        aId,
       
   131                                        aFileName,
       
   132                                        aFileBitmapId,
       
   133                                        aFileMaskId );
       
   134     
       
   135     if ( aFileBitmapId != iFileBitmapId )
       
   136         {
       
   137         delete iFileName;
       
   138         iFileName = NULL;
       
   139     
       
   140         iFileName = aFileName.AllocL();
       
   141     
       
   142         iSkinId = aId;
       
   143     
       
   144         iFileBitmapId = aFileBitmapId;
       
   145         iFileMaskId = aFileMaskId;
       
   146         
       
   147         // New bitmap. Force size setting. Not propably needed by kept here
       
   148         // so that functionality would be the same.
       
   149         SetSize( TSize() );
       
   150         }
       
   151     else
       
   152         {
       
   153         // Icon reloaded. Set old size.
       
   154         SetBitmapSizeL( iSize );
       
   155         }
       
   156     }
       
   157 
       
   158 
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // CMsgIconControl::BitmapSize
       
   162 //
       
   163 // Return the size of the icon
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 void CMsgIconControl::SetBitmapSizeL( const TSize& aSize )
       
   167     {    
       
   168     if ( iIcon )
       
   169         {
       
   170         User::LeaveIfError( AknIconUtils::SetSize( iIcon->Bitmap(), aSize ) );
       
   171         SetSize( aSize );
       
   172         }
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------
       
   176 // CMsgIconControl::BitmapSize
       
   177 //
       
   178 // Return the size of the icon
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 TSize CMsgIconControl::BitmapSize()
       
   182     {
       
   183     TSize size( 0, 0 );
       
   184     if ( iIcon )
       
   185         {
       
   186         size = iIcon->Bitmap()->SizeInPixels();
       
   187         }
       
   188     return size;
       
   189     }
       
   190     
       
   191 // ---------------------------------------------------------
       
   192 // CMsgIconControl::IconBitmapId
       
   193 // ---------------------------------------------------------
       
   194 //
       
   195 TInt CMsgIconControl::IconBitmapId() const
       
   196     {
       
   197     return iFileBitmapId;
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------
       
   201 // CMsgIconControl::IconBitmapId
       
   202 // ---------------------------------------------------------
       
   203 //
       
   204 void CMsgIconControl::HandleResourceChange( TInt aType )
       
   205     {
       
   206     if ( aType == KAknsMessageSkinChange )
       
   207         {
       
   208         // Reload the current icon.
       
   209         TRAP_IGNORE( LoadIconL( iSkinId,
       
   210                                 *iFileName,
       
   211                                 iFileBitmapId,
       
   212                                 iFileMaskId ) );
       
   213         }
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------
       
   217 // CMsgIconControl::Draw
       
   218 //
       
   219 // Draw the icon
       
   220 // ---------------------------------------------------------
       
   221 //
       
   222 void CMsgIconControl::Draw( const TRect& aRect ) const
       
   223     {
       
   224     if ( iIcon && iIcon->Bitmap() )
       
   225         {
       
   226         //Intersection of the drawing rect and icon rect
       
   227         TRect i = Rect();
       
   228         i.Intersection( aRect );
       
   229         
       
   230         //Top left corner of the intersection
       
   231         TPoint tL2 = i.iTl;
       
   232 
       
   233         //The relative part of the icon rect to be drawn
       
   234         i.Move( -Position().iX, -Position().iY );
       
   235 
       
   236         if ( iIcon->Mask() )
       
   237             {
       
   238             SystemGc().BitBltMasked( 
       
   239                 tL2, 
       
   240                 iIcon->Bitmap(), 
       
   241                 i, 
       
   242                 iIcon->Mask(), 
       
   243                 ETrue );
       
   244             }
       
   245         else
       
   246             {
       
   247             SystemGc().BitBlt( 
       
   248                 tL2, 
       
   249                 iIcon->Bitmap(), 
       
   250                 i );
       
   251             }
       
   252         }
       
   253     }
       
   254 
       
   255 //  End of File