videoplayback/videoplaybackcontrols/src/mpxvideoplaybackbutton.cpp
branchRCL_3
changeset 57 befca0ec475f
equal deleted inserted replaced
56:839377eedc2b 57:befca0ec475f
       
     1 /*
       
     2 * Copyright (c) 2008 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: Button control
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Version : %version: 10 %
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <eikenv.h>
       
    24 #include <gulicon.h>
       
    25 #include <AknUtils.h>
       
    26 #include <AknIconUtils.h>
       
    27 #include <AknsDrawUtils.h>
       
    28 
       
    29 #include "mpxvideoplaybackbutton.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===================================================
       
    32 
       
    33 CMPXVideoPlaybackButton::CMPXVideoPlaybackButton()
       
    34 {
       
    35 }
       
    36 
       
    37 // -------------------------------------------------------------------------------------------------
       
    38 // CMPXVideoPlaybackButton::ConstructL()
       
    39 // Symbian 2nd phase constructor can leave.
       
    40 // -------------------------------------------------------------------------------------------------
       
    41 //
       
    42 void CMPXVideoPlaybackButton::ConstructL( CMPXVideoPlaybackControlsController* aController,
       
    43                                           TRect aRect, const TDesC &aIconPath )
       
    44 {
       
    45     MPX_DEBUG(_L("CMPXVideoPlaybackButton::ConstructL()"));
       
    46 
       
    47     iIConPath = aIconPath.AllocL();
       
    48     iController = aController;
       
    49 
       
    50     SetRect( aRect );
       
    51 }
       
    52 
       
    53 // -------------------------------------------------------------------------------------------------
       
    54 // CMPXVideoPlaybackButton::NewL()
       
    55 // Two-phased constructor.
       
    56 // -------------------------------------------------------------------------------------------------
       
    57 //
       
    58 CMPXVideoPlaybackButton*
       
    59 CMPXVideoPlaybackButton::NewL( CMPXVideoPlaybackControlsController* aController,
       
    60                                TRect aRect, const TDesC &aIconPath )
       
    61 {
       
    62     MPX_DEBUG(_L("CMPXVideoPlaybackButton::NewL()"));
       
    63 
       
    64     CMPXVideoPlaybackButton* self = new ( ELeave ) CMPXVideoPlaybackButton();
       
    65 
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL( aController, aRect, aIconPath );
       
    68     CleanupStack::Pop();
       
    69     return self;
       
    70 }
       
    71 
       
    72 // -------------------------------------------------------------------------------------------------
       
    73 // CMPXVideoPlaybackButton::~CMPXVideoPlaybackButton()
       
    74 // Destructor.
       
    75 // -------------------------------------------------------------------------------------------------
       
    76 //
       
    77 CMPXVideoPlaybackButton::~CMPXVideoPlaybackButton()
       
    78 {
       
    79     MPX_DEBUG(_L("CMPXVideoPlaybackButton::~CMPXVideoPlaybackButton()"));
       
    80 
       
    81     if ( iIConPath )
       
    82     {
       
    83         delete iIConPath;
       
    84         iIConPath = NULL;
       
    85     }
       
    86 
       
    87     if ( iDefaultButton )
       
    88     {
       
    89         delete iDefaultButton;
       
    90         iDefaultButton = NULL;
       
    91     }
       
    92 
       
    93     if ( iDimmedButton )
       
    94     {
       
    95         delete iDimmedButton;
       
    96         iDimmedButton = NULL;
       
    97     }
       
    98 
       
    99     if ( iPressedButton )
       
   100     {
       
   101         delete iPressedButton;
       
   102         iPressedButton = NULL;
       
   103     }
       
   104 }
       
   105 
       
   106 // -------------------------------------------------------------------------------------------------
       
   107 // CMPXVideoPlaybackButton::CreateDefaultButtonL()
       
   108 // -------------------------------------------------------------------------------------------------
       
   109 //
       
   110 void CMPXVideoPlaybackButton::CreateDefaultButtonL( const TAknsItemID &aID,
       
   111                                                     const TInt aFileIndex,
       
   112                                                     const TInt aFileMaskIndex )
       
   113 {
       
   114     MPX_DEBUG(_L("CMPXVideoPlaybackButton::CreateDefaultButtonL()"));
       
   115 
       
   116     if ( iDefaultButton )
       
   117     {
       
   118         delete iDefaultButton;
       
   119         iDefaultButton = NULL;
       
   120     }
       
   121 
       
   122     iDefaultButton = CreateButtonL( aID, aFileIndex, aFileMaskIndex );
       
   123 }
       
   124 
       
   125 // -------------------------------------------------------------------------------------------------
       
   126 // CMPXVideoPlaybackButton::CreateButtonL()
       
   127 // -------------------------------------------------------------------------------------------------
       
   128 //
       
   129 void CMPXVideoPlaybackButton::CreateDimmedButtonL( const TAknsItemID &aID,
       
   130                                                    const TInt aFileIndex,
       
   131                                                    const TInt aFileMaskIndex )
       
   132 {
       
   133     MPX_DEBUG(_L("CMPXVideoPlaybackButton::CreateDimmedButtonL()"));
       
   134 
       
   135     if ( iDimmedButton )
       
   136     {
       
   137         delete iDimmedButton;
       
   138         iDimmedButton = NULL;
       
   139     }
       
   140 
       
   141     iDimmedButton = CreateButtonL( aID, aFileIndex, aFileMaskIndex );
       
   142 }
       
   143 
       
   144 // -------------------------------------------------------------------------------------------------
       
   145 // CMPXVideoPlaybackButton::CreatePressedButtonL()
       
   146 // -------------------------------------------------------------------------------------------------
       
   147 //
       
   148 void CMPXVideoPlaybackButton::CreatePressedButtonL( const TAknsItemID &aID,
       
   149                                                     const TInt aFileIndex,
       
   150                                                     const TInt aFileMaskIndex )
       
   151 {
       
   152     MPX_DEBUG(_L("CMPXVideoPlaybackButton::CreatePressedButtonL()"));
       
   153 
       
   154     if ( iPressedButton )
       
   155     {
       
   156         delete iPressedButton;
       
   157         iPressedButton = NULL;
       
   158     }
       
   159 
       
   160     iPressedButton = CreateButtonL( aID, aFileIndex, aFileMaskIndex );
       
   161 }
       
   162 
       
   163 // -------------------------------------------------------------------------------------------------
       
   164 // CMPXVideoPlaybackButton::CreateButtonL()
       
   165 // -------------------------------------------------------------------------------------------------
       
   166 //
       
   167 CGulIcon* CMPXVideoPlaybackButton::CreateButtonL( const TAknsItemID &aID,
       
   168                                                   const TInt aFileIndex,
       
   169                                                   const TInt aFileMaskIndex )
       
   170 {
       
   171     MPX_DEBUG(_L("CMPXVideoPlaybackButton::CreateButtonL()"));
       
   172 
       
   173     CGulIcon* icon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   174                                                 aID,
       
   175                                                 iIConPath->Des(),
       
   176                                                 aFileIndex,
       
   177                                                 aFileMaskIndex );
       
   178 
       
   179     if ( icon )
       
   180     {
       
   181         AknIconUtils::SetSize( icon->Bitmap(),
       
   182                                Rect().Size(),
       
   183                                EAspectRatioNotPreserved );
       
   184     }
       
   185 
       
   186     return icon;
       
   187 }
       
   188 
       
   189 // -------------------------------------------------------------------------------------------------
       
   190 //   CMPXVideoPlaybackButton::Draw()
       
   191 // -------------------------------------------------------------------------------------------------
       
   192 //
       
   193 void CMPXVideoPlaybackButton::Draw( const TRect& aRect ) const
       
   194 {
       
   195     MPX_DEBUG(_L("CMPXVideoPlaybackButton::Draw()"));
       
   196 
       
   197     CWindowGc& gc = SystemGc();
       
   198     gc.SetClippingRect( aRect );
       
   199 
       
   200     if ( Window().DisplayMode() == EColor16MAP )
       
   201     {
       
   202         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   203         gc.SetBrushColor( TRgb::Color16MAP( 255 ) );
       
   204         gc.Clear( aRect );
       
   205     }
       
   206     else if ( Window().DisplayMode() == EColor16MA )
       
   207     {
       
   208         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   209         gc.SetBrushColor( TRgb::Color16MA( 0 ) );
       
   210         gc.Clear( aRect );
       
   211     }
       
   212 
       
   213     switch ( iState )
       
   214     {
       
   215         case EMPXButtonNormal:
       
   216         {
       
   217             gc.BitBltMasked( Rect().iTl,
       
   218                              iDefaultButton->Bitmap(),
       
   219                              TRect( Rect().Size() ),
       
   220                              iDefaultButton->Mask(),
       
   221                              ETrue );
       
   222             break;
       
   223         }
       
   224         case EMPXButtonDimmed:
       
   225         {
       
   226             gc.BitBltMasked( Rect().iTl,
       
   227                              iDimmedButton->Bitmap(),
       
   228                              TRect( Rect().Size() ),
       
   229                              iDimmedButton->Mask(),
       
   230                              ETrue );
       
   231             break;
       
   232         }
       
   233         case EMPXButtonPressed:
       
   234         {
       
   235             gc.BitBltMasked( Rect().iTl,
       
   236                              iPressedButton->Bitmap(),
       
   237                              TRect( Rect().Size() ),
       
   238                              iPressedButton->Mask(),
       
   239                              ETrue );
       
   240             break;
       
   241         }
       
   242     }
       
   243 }
       
   244 
       
   245 // -------------------------------------------------------------------------------------------------
       
   246 // CMPXVideoPlaybackButton::CountComponentControls()
       
   247 // -------------------------------------------------------------------------------------------------
       
   248 //
       
   249 TInt CMPXVideoPlaybackButton::CountComponentControls() const
       
   250 {
       
   251     return 0;
       
   252 }
       
   253 
       
   254 // -------------------------------------------------------------------------------------------------
       
   255 // CMPXVideoPlaybackButton::SetDimmed
       
   256 // -------------------------------------------------------------------------------------------------
       
   257 //
       
   258 void CMPXVideoPlaybackButton::SetDimmed( TBool aDimmed )
       
   259 {
       
   260     MPX_DEBUG(_L("CMPXVideoPlaybackButton::SetDimmed() (%d)"), aDimmed);
       
   261 
       
   262     if ( aDimmed && iDimmedButton )
       
   263     {
       
   264         iState = EMPXButtonDimmed;
       
   265     }
       
   266     else if ( iState == EMPXButtonDimmed )
       
   267     {
       
   268         iState = EMPXButtonNormal;
       
   269     }
       
   270 
       
   271     if ( IsVisible() )
       
   272     {
       
   273         DrawNow();
       
   274     }
       
   275 }
       
   276 
       
   277 // -------------------------------------------------------------------------------------------------
       
   278 // CMPXVideoPlaybackButton::SetPressed
       
   279 // -------------------------------------------------------------------------------------------------
       
   280 //
       
   281 void CMPXVideoPlaybackButton::SetPressed( TBool aPressed )
       
   282 {
       
   283     MPX_DEBUG(_L("CMPXVideoPlaybackButton::SetPressed() (%d)"), aPressed);
       
   284 
       
   285     if ( aPressed && iPressedButton )
       
   286     {
       
   287         iState = EMPXButtonPressed;
       
   288     }
       
   289     else if ( iState == EMPXButtonPressed )
       
   290     {
       
   291         iState = EMPXButtonNormal;
       
   292     }
       
   293 
       
   294     if ( IsVisible() )
       
   295     {
       
   296         DrawDeferred();
       
   297     }
       
   298 }
       
   299 
       
   300 //  End of File