mpxplugins/viewplugins/views/inc/mpxbutton.h
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 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:  Push-button in Common Playback View.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CMPXBUTTON_H
       
    21 #define CMPXBUTTON_H
       
    22 
       
    23 
       
    24 // INCLUDES
       
    25 #include "mpxcommonplaybackviewdefs.h"
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class CGulIcon;
       
    29 class CWindowGc;
       
    30 class CAknKeySoundSystem;
       
    31 class MAknsControlContext;
       
    32 class MMPXPlaybackViewLayout;
       
    33 
       
    34 NONSHARABLE_STRUCT( TMPXButtonInfo )
       
    35     {
       
    36     TInt iState;
       
    37     CGulIcon* iBitmap;
       
    38     TInt iEnterCommand;
       
    39     TInt iExitCommand;
       
    40     TInt iLongEnterCommand;
       
    41     TInt iLongExitCommand;
       
    42     };
       
    43 
       
    44 // CLASS DECLARATION
       
    45 
       
    46 /**
       
    47  * Observer interface to receive commands from button presses.
       
    48  *
       
    49  *  @lib mpxplaybackview.dll
       
    50  *  @since S60 v3.0
       
    51  */
       
    52 NONSHARABLE_CLASS( MMPXButtonCmdObserver )
       
    53     {
       
    54     public:
       
    55         /**
       
    56          * Handle a button command.
       
    57          * @param aCommand Command id, as specified in the button constructor.
       
    58          */
       
    59         virtual void HandleButtonCommandL( TInt aCommand ) = 0;
       
    60 
       
    61     };
       
    62 
       
    63 
       
    64 /**
       
    65 *  Push-button in Playback View. This class encapsulates the graphics,
       
    66 *  state (pushed, dimmed, highlighted), and layout information of the button.
       
    67 *  The button calls the HandleButtonCommandL() function for the observer
       
    68 *  object when it is pushed.
       
    69 *
       
    70 *  @lib MusicPlayer.app
       
    71 *  @since 3.0
       
    72 */
       
    73 NONSHARABLE_CLASS( CMPXButton ) : public CBase
       
    74     {
       
    75     public:  // Constructors and destructor
       
    76         /**
       
    77         * Two-phased constructor.
       
    78         * @since 3.0
       
    79         * @param aButtonId   Id for the button (determines layout and graphics)
       
    80         * @param aObserver   Pointer to an object implementing the
       
    81         *                    MMPlayerButtonCmdObserver interface.
       
    82         * @param aLayout     Layout for this view
       
    83         * @return New CMPlayerButton instance.
       
    84         */
       
    85         static CMPXButton* NewL(
       
    86             TMPXPbvButton aButtonId,
       
    87             MMPXButtonCmdObserver* aObserver,
       
    88             MMPXPlaybackViewLayout* aLayout );
       
    89 
       
    90         /**
       
    91         * Two-phased constructor.
       
    92         * @since 3.0
       
    93         * @param aButtonId   Id for the button (determines layout and graphics)
       
    94         * @param aObserver   Pointer to an object implementing the
       
    95         *                    MMPlayerButtonCmdObserver interface.
       
    96         * @param aLayout     Layout for this view
       
    97         * @return New CMPlayerButton instance.
       
    98         */
       
    99         static CMPXButton* NewLC(
       
   100             TMPXPbvButton aButtonId,
       
   101             MMPXButtonCmdObserver* aObserver,
       
   102             MMPXPlaybackViewLayout* aLayout );
       
   103 
       
   104         /**
       
   105         * Destructor.
       
   106         */
       
   107         virtual ~CMPXButton();
       
   108 
       
   109     public: // New functions
       
   110         
       
   111         /**
       
   112         * Adds a new state to this button
       
   113         * @since 3.0
       
   114         * @param aState         ID of the state
       
   115         * @param aEnterCommand  Command ID to execute when it enters this state
       
   116         * @param aExitCommand   Command ID to execute whne it exits this state
       
   117         * @param aLongEnterCommand  Command ID executes on a long press
       
   118         * @param aLongExitCommand   Command ID to execute after a long press
       
   119         */
       
   120         void AddStateL( 
       
   121             TInt aState,
       
   122             TInt aEnterCommand,
       
   123             TInt aExitCommand,
       
   124             TInt aLongEnterCommand,
       
   125             TInt aLongExitCommand );
       
   126         
       
   127         /**
       
   128         * Get the id of the button.
       
   129         * @since 3.0
       
   130         * @return Button id (as specified in NewL())
       
   131         */
       
   132         TMPXPbvButton Id() const;
       
   133 
       
   134         /**
       
   135         * Hide/show this button
       
   136         * @since 3.0
       
   137         * @param aVisible  ETrue if this button is to be visible
       
   138         */
       
   139         void MakeVisible( TBool aVisible );
       
   140 
       
   141         /**
       
   142         * Get the visibility status of the button.
       
   143         * @since 3.0
       
   144         * @return ETrue if this button is visible
       
   145         */
       
   146         TBool IsVisible() const;
       
   147         
       
   148         /**
       
   149         * Set the state of this button
       
   150         * @since 3.0
       
   151         * @param aState     New state to set to
       
   152         * @param aNotifyExit Whether or not to notify observer of the
       
   153         *                    exit command of previous state
       
   154         * @param aNotifyEnter Whether or not to notify observer of the
       
   155         *                     enter command of the new state
       
   156         */
       
   157         void SetButtonState( TInt aState,   
       
   158                              TBool aNotifyExit=EFalse,
       
   159                              TBool aNotifyEnter=EFalse );
       
   160                 
       
   161         /**
       
   162         * Get the current state of the button
       
   163         * @since 3.0
       
   164         * @return State of the button
       
   165         */
       
   166         TInt CurrentState() const;
       
   167         
       
   168         /**
       
   169         * Draw the button according to its current state.
       
   170         * @since 3.0
       
   171         * @param aGc   Graphics context to draw to
       
   172         * @param aRect Dirty rectangle. Drawing can be clipped inside this
       
   173         *              rectangle.
       
   174         */
       
   175         void RedrawRect(CBitmapContext& aGc, const TRect& aRect) const;
       
   176 
       
   177         /**
       
   178         * Reload graphics.
       
   179         * @since 3.0
       
   180         * @param aParentRect New parent rectangle
       
   181         */
       
   182         void ReloadIconsL(const TRect& aParentRect);
       
   183 
       
   184         /**
       
   185         * Set background bitmap
       
   186         * @since 3.0
       
   187         * @param aBackground       Pointer to the skin background control
       
   188         *                          context. Ownership not transferred.
       
   189         */
       
   190         void SetBackground(MAknsControlContext* aBackground);
       
   191 
       
   192         /**
       
   193         * Get the redraw flag.
       
   194         * @since 3.0
       
   195         * @return ETrue if this button needs to be redrawn
       
   196         */
       
   197         TBool NeedRedraw() const;
       
   198 
       
   199         /**
       
   200         * Clear the redraw flag.
       
   201         * @since 3.0
       
   202         */
       
   203         void ClearRedrawFlag();
       
   204 
       
   205     private: // New functions
       
   206         /**
       
   207         * By default Symbian 2nd phase constructor is private.
       
   208         */
       
   209         void ConstructL();
       
   210 
       
   211         /**
       
   212         * C++ constructor
       
   213         */
       
   214         CMPXButton(
       
   215             TMPXPbvButton aButtonId,
       
   216             MMPXButtonCmdObserver* aObserver,
       
   217             MMPXPlaybackViewLayout* aLayout );
       
   218 
       
   219         /**
       
   220         * Load the bitmap and mask for given state.
       
   221         * @return CGulIcon containing bitmap and mask
       
   222         */
       
   223         CGulIcon* LoadIconL( TInt aState );
       
   224 
       
   225         /**
       
   226         * Free all icons
       
   227         */
       
   228         void FreeIcons();
       
   229 
       
   230         /**
       
   231         * Create a more translucent version of the mask to be used
       
   232         * when the button is dimmed.
       
   233         */
       
   234         void CreateTmpDimmedMaskL();
       
   235 
       
   236         /**
       
   237         * Handle long press event.
       
   238         */
       
   239         void HandleLongPress();
       
   240 
       
   241         /**
       
   242         * Callback for long-press timer
       
   243         */
       
   244         static TInt TimerCallback(TAny* aPtr);
       
   245 
       
   246     private:     // Data
       
   247         TMPXPbvButton iButtonId;
       
   248         TInt iCurrentStateIndex;
       
   249         RPointerArray<TMPXButtonInfo> iButtonArray; // owned
       
   250         MMPXButtonCmdObserver* iObserver; // not owned
       
   251         
       
   252         TRect iParentRect;
       
   253         TRect iRect;
       
   254 
       
   255         TBool iVisible;
       
   256         TBool iIsLongPress;
       
   257 
       
   258         CPeriodic* iTimer; // owned
       
   259 
       
   260         MAknsControlContext* iBackground; // not owned
       
   261 
       
   262         TBool iNeedRedraw;
       
   263 
       
   264         CAknKeySoundSystem* iKeySoundSystem;  // not owned
       
   265         TBool iSelectionKeySilent;
       
   266         MMPXPlaybackViewLayout* iLayout;    // not owned
       
   267     };
       
   268 
       
   269 #endif      // CMPXBUTTON_H
       
   270 
       
   271 // End of File