meetingrequest/mrgui/src/cmrnaviarrow.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     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:  Navigation arrow (used to replace the navipane).
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cmrnaviarrow.h"
       
    19 #include "nmrbitmapmanager.h"
       
    20 #include "cesmrviewerdialog.h"
       
    21 #include "esmricalvieweropcodes.hrh"
       
    22 
       
    23 #include <aknbutton.h>
       
    24 #include <gulicon.h>
       
    25 #include <w32std.h>
       
    26 
       
    27 #include "emailtrace.h"
       
    28 
       
    29 namespace
       
    30 {
       
    31 // Value table for 70% Transparency 
       
    32 const TInt KTransparency[256] =
       
    33     { 
       
    34     0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7,
       
    35     8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13,
       
    36     14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 19,
       
    37     19, 19, 20, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 23, 24, 24,
       
    38     24, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 29,
       
    39     30, 30, 30, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35,
       
    40     35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 40, 40, 40,
       
    41     41, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46,
       
    42     46, 46, 47, 47, 47, 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 50, 51, 51,
       
    43     51, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 56,
       
    44     57, 57, 57, 58, 58, 58, 59, 59, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62,
       
    45     62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 67, 67, 67,
       
    46     68, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 71, 72, 72, 72, 73,
       
    47     73, 73, 74, 74, 74, 74, 75, 75, 75, 76, 76, 76, 77, 77 
       
    48     };
       
    49 
       
    50 }
       
    51 
       
    52 
       
    53 // ======== MEMBER FUNCTIONS ========
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CMRNaviArrow::NewL()
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CMRNaviArrow* CMRNaviArrow::NewL( const CCoeControl* aParent, 
       
    60 		TArrowType aType,
       
    61         MESMRNaviArrowEventObserver* aObserver,
       
    62         TSize aIconSize )
       
    63     {
       
    64     FUNC_LOG;
       
    65     CMRNaviArrow* self = new (ELeave) CMRNaviArrow( aObserver, aType, aIconSize );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL( aParent);
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CMRNaviArrow::CMRNaviArrow()
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CMRNaviArrow::CMRNaviArrow( MESMRNaviArrowEventObserver* aObserver, TArrowType aType, TSize aIconSize )
       
    77     :iObserver(aObserver),
       
    78     iArrowType(aType),
       
    79     iIconSize( aIconSize )
       
    80     {
       
    81     FUNC_LOG;
       
    82     // Do nothing
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CMRNaviArrow::~CMRNaviArrow
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CMRNaviArrow::~CMRNaviArrow()
       
    90     {
       
    91     FUNC_LOG;
       
    92     delete iArrow;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CMRNaviArrow::ConstructL()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CMRNaviArrow::ConstructL( const CCoeControl* aParent )
       
   100     {
       
   101     FUNC_LOG;
       
   102     CreateWindowL( aParent );
       
   103     EnableWindowTransparency();
       
   104     InitNaviArrowsL();
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CMRNaviArrow::InitNaviArrows()
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CMRNaviArrow::InitNaviArrowsL()
       
   112     {
       
   113     FUNC_LOG;
       
   114     // Button
       
   115     // TODO: Icons id should be changed to correct one when available
       
   116     CFbsBitmap* bitMapL( NULL );
       
   117     CFbsBitmap* bitMapMaskL( NULL );
       
   118     NMRBitmapManager::TMRBitmapId bitmapId;
       
   119     if ( EMRArrowLeft == iArrowType )
       
   120     	{
       
   121     	bitmapId = NMRBitmapManager::EMRBitmapMailPre;
       
   122     	}
       
   123     else
       
   124     	{
       
   125     	bitmapId = NMRBitmapManager::EMRBitmapMailNext;
       
   126     	}
       
   127     NMRBitmapManager::GetSkinBasedBitmapLC(
       
   128     		bitmapId, bitMapL, bitMapMaskL, iIconSize );
       
   129     
       
   130     CGulIcon* transparentIconL = CreateSemiTransparentIconL(  bitMapL, bitMapMaskL );
       
   131     CleanupStack::Pop( 2 ); // bitMap, bitMapMask
       
   132     CleanupStack::PushL( transparentIconL );
       
   133     iArrow = CAknButton::NewL( transparentIconL, NULL, NULL, NULL, KNullDesC,
       
   134             KNullDesC, KAknButtonNoFrame | KAknButtonPressedDownFrame, 0 );
       
   135     CleanupStack::Pop( transparentIconL );
       
   136 
       
   137     iArrow->SetParent( this );
       
   138     iArrow->SetContainerWindowL(*this);
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CMRNaviArrow::SizeChanged
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CMRNaviArrow::SizeChanged()
       
   146     {
       
   147     FUNC_LOG;
       
   148     iArrow->SetRect( Rect() );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CMRNaviArrow::CountComponentControls()
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 TInt CMRNaviArrow::CountComponentControls() const
       
   156     {
       
   157     FUNC_LOG;
       
   158     TInt count(0);
       
   159     if( iArrow )
       
   160         {
       
   161         count++;
       
   162         }
       
   163     return count;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CMRNaviArrow::ComponentControl()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 CCoeControl* CMRNaviArrow::ComponentControl( TInt aInd ) const
       
   171     {
       
   172     FUNC_LOG;
       
   173     CCoeControl* control = NULL;
       
   174     switch ( aInd )
       
   175         {
       
   176         case 0:                              
       
   177             control = iArrow;
       
   178             break;
       
   179         default:
       
   180             break;
       
   181         }
       
   182 
       
   183     return control;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CMRNaviArrow::HandlePointerEventL()
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CMRNaviArrow::HandlePointerEventL( const TPointerEvent &aPointerEvent )
       
   191     {
       
   192     FUNC_LOG;
       
   193     CCoeControl::HandlePointerEventL(aPointerEvent);
       
   194     TESMRIcalViewerOperationType operationType;
       
   195     if ( EMRArrowLeft == iArrowType )
       
   196     	{
       
   197     	operationType = EESMRCmdMailPreviousMessage;
       
   198     	}
       
   199     else
       
   200     	{
       
   201     	operationType = EESMRCmdMailNextMessage;
       
   202     	}
       
   203     if( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   204         {
       
   205         if ( iArrow->Rect().Contains( aPointerEvent.iPosition ) )
       
   206             {
       
   207             iObserver->HandleNaviArrowEventL( operationType );
       
   208             }
       
   209         else
       
   210             {
       
   211             Parent()->HandlePointerEventL(aPointerEvent);
       
   212             }
       
   213         }
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CMRNaviArrow::SetNaviArrowStatus()
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 void CMRNaviArrow::SetNaviArrowStatus( TBool aVisible )
       
   221     {
       
   222     FUNC_LOG;
       
   223     iArrow->MakeVisible( aVisible );
       
   224     DrawDeferred();
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CMRNaviArrow::Draw()
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 void CMRNaviArrow::Draw(const TRect& /*aRect*/) const
       
   232     {
       
   233     FUNC_LOG;
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CMRNaviArrow::CreateSemiTransparentIconL()
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 CGulIcon* CMRNaviArrow::CreateSemiTransparentIconL( CFbsBitmap* aBitMap, 
       
   241                                                 CFbsBitmap* aBitMapMask )
       
   242     {
       
   243     CGulIcon* newIcon(NULL);
       
   244     
       
   245     if ( aBitMap && aBitMapMask )
       
   246         {
       
   247         newIcon = CGulIcon::NewLC();
       
   248         newIcon->SetBitmap( aBitMap );
       
   249 
       
   250         CFbsBitmap* newMask = new ( ELeave ) CFbsBitmap;        
       
   251         CleanupStack::PushL( newMask );
       
   252         
       
   253         User::LeaveIfError( newMask->Create( 
       
   254             newIcon->Bitmap()->SizeInPixels(), EGray256 ) );        
       
   255            
       
   256         CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( newMask );
       
   257         CleanupStack::PushL( bitmapDevice );
       
   258         
       
   259         CFbsBitGc* bitGc( NULL );
       
   260         User::LeaveIfError( bitmapDevice->CreateContext( bitGc ) );
       
   261         CleanupStack::PushL( bitGc );
       
   262 
       
   263         bitGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   264         bitGc->BitBlt( TPoint( 0, 0 ), aBitMapMask );
       
   265         
       
   266         newMask->LockHeap();
       
   267         TInt w = aBitMapMask->SizeInPixels().iWidth; 
       
   268         TInt h = aBitMapMask->SizeInPixels().iHeight;
       
   269         TInt dataStride = aBitMapMask->DataStride() - w; 
       
   270         unsigned char* address = (unsigned char *)newMask->DataAddress();  
       
   271         
       
   272         for ( TInt i = 0; i < h; ++i )
       
   273             {
       
   274             for ( TInt j = 0; j < w; ++j )
       
   275                 {
       
   276                 *address = KTransparency[*address];
       
   277                 ++address;
       
   278                 }
       
   279             address += dataStride;         
       
   280             }
       
   281 
       
   282         newMask->UnlockHeap();
       
   283         newIcon->SetMask( newMask );
       
   284                            
       
   285         CleanupStack::PopAndDestroy( 2 ); // bitmapDevice, bitGc
       
   286         CleanupStack::Pop( 2 ); // newIcon, newMask
       
   287         }
       
   288     
       
   289     return newIcon;
       
   290     }
       
   291 
       
   292 // End of file