uifw/EikStd/coctlsrc/aknbitmapresourceitem.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Bitmap resource item
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <AknUtils.h>
       
    21 #include <fbs.h>
       
    22 
       
    23 #include "aknbitmapresourceitem.h"
       
    24 
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // Two-phased constructor.
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CAknBitmapResourceItem* CAknBitmapResourceItem::NewL( TInt aId )
       
    33     {
       
    34     CAknBitmapResourceItem* self = 
       
    35         new ( ELeave ) CAknBitmapResourceItem( aId );
       
    36     return self;
       
    37     }
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Destructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CAknBitmapResourceItem::~CAknBitmapResourceItem()
       
    45     {
       
    46     delete iBitmap;
       
    47     delete iBitmapMask;
       
    48     }
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Used to fetch the bitmaps (resources) this item holds. The ownership of the
       
    53 // bitmaps changes with this method call, so caller must take care of 
       
    54 // the destruction of the bitmaps.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 TBool CAknBitmapResourceItem::GetBitmaps( CFbsBitmap*& aBitmap,
       
    58                                          CFbsBitmap*& aMask )
       
    59     {
       
    60     if ( iBitmap && iBitmapMask )
       
    61         {
       
    62         aBitmap = iBitmap;
       
    63         aMask = iBitmapMask;
       
    64 
       
    65         // not owned anymore by this item -> set pointers to null
       
    66         iBitmap = 0;
       
    67         iBitmapMask = 0;
       
    68         return ETrue;
       
    69         }
       
    70     return EFalse;
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Sets the bitmaps of this item. The ownership of the parameter bitmaps 
       
    76 // does not change with this method call, instead new bitmaps are created with
       
    77 // parameter bitmaps handles. So caller must take care of the parameter 
       
    78 // bitmaps destruction.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CAknBitmapResourceItem::SetBitmapsL( CFbsBitmap* aBitmap,
       
    82                                          CFbsBitmap* aMask )
       
    83     {
       
    84     delete iBitmap;
       
    85     delete iBitmapMask;
       
    86     iBitmap = 0;
       
    87     iBitmapMask = 0;
       
    88 
       
    89     iBitmap = new ( ELeave ) CFbsBitmap;
       
    90     iBitmap->Duplicate( aBitmap->Handle() );
       
    91     iBitmapMask = new ( ELeave ) CFbsBitmap;
       
    92     iBitmapMask->Duplicate( aMask->Handle() );
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Duplicates the item and the resources it holds and 
       
    98 // returns the created resource item.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 MAknResourceItem* CAknBitmapResourceItem::DuplicateL()
       
   102     {
       
   103     CAknBitmapResourceItem* newItem = CAknBitmapResourceItem::NewL( iId );
       
   104     newItem->SetBitmapsL( iBitmap, iBitmapMask );
       
   105     return newItem;
       
   106     }
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Returns the resource item id.
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 TInt CAknBitmapResourceItem::Id() const
       
   114     {
       
   115     return iId;
       
   116     }
       
   117 
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // Returns ETrue if the aType resource change applies to this resource item. 
       
   121 // Otherwise EFalse.
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 TBool CAknBitmapResourceItem::Invalidate( TInt aType )
       
   125     {
       
   126     TBool invalidate = EFalse;
       
   127     switch ( aType )
       
   128         {
       
   129         case KAknsMessageSkinChange:
       
   130         case KEikDynamicLayoutVariantSwitch:
       
   131             invalidate = ETrue;
       
   132             break;
       
   133         default:
       
   134             invalidate = EFalse;
       
   135         }
       
   136     return invalidate;
       
   137     }
       
   138 
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // C++ default constructor can NOT contain any code that might leave.
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 CAknBitmapResourceItem::CAknBitmapResourceItem( TInt aId ) 
       
   145     : iBitmap( 0 ), iBitmapMask( 0 ), iId( aId )
       
   146     {
       
   147     }