emailuis/uicomponents/inc/fscontrolbar.h
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Main class for Control Bar component.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_FSCONTROLBAR_H
       
    20 #define C_FSCONTROLBAR_H
       
    21 
       
    22 //<cmail> SF
       
    23 #include <alf/alfcontrol.h>
       
    24 #include <alf/alfenv.h>
       
    25 //</cmail>
       
    26 
       
    27 #include "fscontrolbuttonobserver.h"
       
    28 #include "fscontrolbarobserver.h"
       
    29 #include "fscontrolbuttonconst.h"
       
    30 
       
    31 class MFsControlButtonInterface;
       
    32 class CFsControlButton;
       
    33 class CFsControlBarModel;
       
    34 class CFsControlBarVisualiser;
       
    35 class CAlfTexture;
       
    36 class CAlfBrush;
       
    37 class CFsTextStyleManager;
       
    38 
       
    39 /**  default value for focusing control bar  */
       
    40 const TInt KFocusFirstFocusableButton = -1;
       
    41 
       
    42 /**  value for current focused button - no button is focused  */
       
    43 const TInt KNoButtonFocused = -1;
       
    44 
       
    45 
       
    46 /**
       
    47  *  Main class for ControlBar component
       
    48  *  Control class of ControlBar component.
       
    49  *
       
    50  *  @code
       
    51  *
       
    52  *  @endcode
       
    53  *
       
    54  *  @lib fs_generic.lib
       
    55  */
       
    56 NONSHARABLE_CLASS( CFsControlBar ) :
       
    57     public CAlfControl,
       
    58     public MFsControlButtonObserver,
       
    59     public MAlfActionObserver
       
    60     {
       
    61 
       
    62 public:
       
    63 
       
    64     /**
       
    65      * Two-phased constructor.
       
    66      *
       
    67      * @param aEnv huitk environment instance.
       
    68      */
       
    69     IMPORT_C static CFsControlBar* NewL( CAlfEnv& aEnv );
       
    70 
       
    71     /**
       
    72      * Two-phased constructor.
       
    73      *
       
    74      * @param aEnv huitk environment instance.
       
    75      */
       
    76     IMPORT_C static CFsControlBar* NewLC( CAlfEnv& aEnv );
       
    77 
       
    78     /**
       
    79      * Destructor
       
    80      */
       
    81     virtual ~CFsControlBar();
       
    82 
       
    83     /**
       
    84      * Adds button with specified id and layout to control bar.
       
    85      *
       
    86      * @param aId unique id of button.
       
    87      * @param aType type of button.
       
    88      */
       
    89     IMPORT_C void AddButtonL( TInt aId, TFsControlButtonType aType );
       
    90 
       
    91     /**
       
    92      * Adds button with specified layout to control bar and return id.
       
    93      *
       
    94      * @param aType type of button.
       
    95      * @return unique id of button.
       
    96      */
       
    97     IMPORT_C TInt AddButtonL( TFsControlButtonType aType );
       
    98 
       
    99     /**
       
   100      * Removes button with specified button (and all data it contains)
       
   101      * from control bar
       
   102      *
       
   103      * @param aId id of button to be removed.
       
   104      * @return KErrNotFound if button's id doesn't exist, otherwise KErrNone.
       
   105      */
       
   106     IMPORT_C TInt RemoveButtonL( TInt aId );
       
   107 
       
   108     /**
       
   109      * Retrieves button with specified id from control bar.
       
   110      *
       
   111      * @param aId id of button to be retrieved.
       
   112      * @return button with specified id.
       
   113      */
       
   114     IMPORT_C MFsControlButtonInterface* ButtonById( TInt aId );
       
   115 
       
   116     /**
       
   117      * Change focused state.
       
   118      * When focus is gained it is set to the first focusable button.
       
   119      *
       
   120      * @param aFocused ETrue to set the focus to the first button otherwise
       
   121      * EFalse to lose the focus.
       
   122      */
       
   123     IMPORT_C void SetFocusL( TBool aFocused = ETrue );
       
   124 
       
   125     /**
       
   126      * Sets focus to specified button.
       
   127      *
       
   128      * @param aButtonId id of button to set focus on.
       
   129      */
       
   130     IMPORT_C void SetFocusByIdL( TInt aButtonId );
       
   131 
       
   132     /**
       
   133      * Gets focused button or NULL if not focused.
       
   134      *
       
   135      * @return focused button or NULL if bar not focused.
       
   136      */
       
   137     IMPORT_C MFsControlButtonInterface* GetFocusedButton() const;
       
   138 
       
   139     /**
       
   140      * Sets height of the bar in pixels.
       
   141      *
       
   142      * @param aHeight new height of the bar.
       
   143      */
       
   144     IMPORT_C void SetHeightL( TInt aHeight );
       
   145 
       
   146     /**
       
   147      * Retrieves height of the bar in pixels.
       
   148      *
       
   149      * @return height of the bar in pixels.
       
   150      */
       
   151     IMPORT_C TInt Height() const;
       
   152 
       
   153     /**
       
   154      * Sets width of the bar in pixels.
       
   155      *
       
   156      * @param aWidth new width of the bar.
       
   157      */
       
   158     IMPORT_C void SetWidthL( TInt aWidth );
       
   159 
       
   160     /**
       
   161      * Retrieves width of the bar in pixels.
       
   162      *
       
   163      * @return width of the bar in pixels.
       
   164      */
       
   165     IMPORT_C TInt Width() const;
       
   166 
       
   167     /**
       
   168      * Sets controlbar's background color.
       
   169      *
       
   170      * @param aColor color of background.
       
   171      */
       
   172     IMPORT_C void SetBackgroundColor( const TRgb& aColor );
       
   173 
       
   174     /**
       
   175      * Clear controlbar's background color. It becomes transparent.
       
   176      */
       
   177     IMPORT_C void ClearBackgroundColor();
       
   178 
       
   179     /**
       
   180      * Sets bar's background image.
       
   181      *
       
   182      * @param aImage background image.
       
   183      */
       
   184     IMPORT_C void SetBackgroundImageL( CAlfTexture& aImage );
       
   185 
       
   186     /**
       
   187      * Clears bar's background image.
       
   188      */
       
   189     IMPORT_C void ClearBackgroundImage();
       
   190 
       
   191     /**
       
   192      * Adds additional observer for the bar events.
       
   193      *
       
   194      * @param aObserver observer of bar's events.
       
   195      */
       
   196     IMPORT_C void AddObserverL( MFsControlBarObserver& aObserver );
       
   197 
       
   198     /**
       
   199      * Removes specified observer from the bar events.
       
   200      *
       
   201      * @param aObserver observer to be removed.
       
   202      */
       
   203     IMPORT_C void RemoveObserver( MFsControlBarObserver& aObserver );
       
   204 
       
   205     /**
       
   206      * Sets transition time for selector.
       
   207      *
       
   208      * @param aTransitionTime transition time in miliseconds.
       
   209      */
       
   210     IMPORT_C void SetSelectorTransitionTimeL( TInt aTransitionTime );
       
   211 
       
   212     /**
       
   213      * Sets selector's image and opacity.
       
   214      * Ownership of the brush is gained.
       
   215      *
       
   216      * @param aSelectorBrush New selector brush.
       
   217      * @param aOpacity Selector's opacity.
       
   218      */
       
   219     IMPORT_C void SetSelectorImageL(
       
   220         CAlfBrush* aSelectorBrush, TReal32 aOpacity = 1.0 );
       
   221 
       
   222     /**
       
   223      * Retrieves amount of space in pixels from specified point to the end
       
   224      * of the screen.
       
   225      *
       
   226      * @return Controlbar visual.
       
   227      */
       
   228     IMPORT_C CAlfVisual* Visual();
       
   229 
       
   230     /**
       
   231      * Resolve the area reserved for requested layout slot.
       
   232      *
       
   233      * @param aIndex Index of requested layout slot. Indexing starts from one.
       
   234      * @return Size and position of requested layout item.
       
   235      */
       
   236     static TRect GetLayoutRect( TInt aIndex );
       
   237 
       
   238     // <cmail> Touch
       
   239     /**
       
   240      * Disable or enable touch input
       
   241      */
       
   242     IMPORT_C void EnableTouch(TBool aEnabled);
       
   243     // </cmail>
       
   244 
       
   245     /**
       
   246      * Hides or shows selector.
       
   247      * NOTE: Do not change focus.
       
   248      *
       
   249      * @param aShow if ETrue selector is shown.
       
   250      * @param aFromTouch if method is called after touch event.
       
   251      */
       
   252     IMPORT_C void MakeSelectorVisible( TBool aShow, TBool aFromTouch = EFalse );
       
   253 
       
   254 // from base class MAlfActionObserver
       
   255 
       
   256     /**
       
   257      * From MAlfActionObserver.
       
   258      * Called by the scheduler when an action command is executed.
       
   259      *
       
   260      * @param aActionCommand The command that is being executed.
       
   261      */
       
   262     virtual void HandleActionL( const TAlfActionCommand& aActionCommand );
       
   263 
       
   264 protected:
       
   265 
       
   266 // from base class CAlfControl
       
   267 
       
   268     /**
       
   269      * From CAlfControl.
       
   270      * Notifies the owner that the layout of a visual has been recalculated.
       
   271      * Called only when the EAlfVisualFlagLayoutUpdateNotification flag has
       
   272      * been set for the visual.
       
   273      *
       
   274      * @param aVisual  Visual that has been laid out.
       
   275      */
       
   276     virtual void VisualLayoutUpdated( CAlfVisual& aVisual );
       
   277 
       
   278     /**
       
   279      * From CAlfControl.
       
   280      * Called when an input event is being offered to the control.
       
   281      *
       
   282      * @param aEvent Event to be handled.
       
   283      * @return <code>ETrue</code>, if the event was handled. Otherwise
       
   284      * <code>EFalse</code>.
       
   285      */
       
   286     virtual TBool OfferEventL( const TAlfEvent& aEvent );
       
   287 
       
   288 // from base class MFsControlButtonObserver
       
   289 
       
   290     /**
       
   291      * From MFsControlButtonObserver.
       
   292      * Invoked when one of button from control bar is pressed.
       
   293      *
       
   294      * @param aEvent event type from button.
       
   295      * @param aButtonId pressed button id.
       
   296      */
       
   297     virtual TBool HandleButtonEvent(
       
   298         TFsControlButtonEvent aEvent, TInt aButtonId );
       
   299 
       
   300 private:
       
   301 
       
   302     /**
       
   303      * Constructor.
       
   304      *
       
   305      * @param aEnv huitk environment instance.
       
   306      * @param aParent parent control to which events will be sent.
       
   307      */
       
   308     CFsControlBar();
       
   309 
       
   310     /**
       
   311      * Constructs and initializes bar control.
       
   312      */
       
   313     void ConstructL( CAlfEnv& aEnv );
       
   314 
       
   315     /**
       
   316      * Sends event to observers.
       
   317      *
       
   318      * @param aEvent event sent to observers
       
   319      * @param aData additional data sent with event
       
   320      */
       
   321     void NotifyObservers(
       
   322         MFsControlBarObserver::TFsControlBarEvent aEvent,
       
   323         TInt aData = -1 );
       
   324 
       
   325     /**
       
   326      * Changes focus to another button or looses focus from control bar.
       
   327      *
       
   328      * @param aButton pointer to button which schould be focused.
       
   329      * If NULL focus is lost by the control bar.
       
   330      */
       
   331     void ChangeFocusL( CFsControlButton* aButton );
       
   332 
       
   333     /**
       
   334      * Sets needed variables when bar loses focus.
       
   335      *
       
   336      * @param aLooseFocusEvent cause of focus lost.
       
   337      */
       
   338     void LooseFocus(
       
   339         MFsControlBarObserver::TFsControlBarEvent aLooseFocusEvent );
       
   340 
       
   341 private: // data
       
   342 
       
   343     /**
       
   344      * Control bar's model
       
   345      * Own.
       
   346      */
       
   347     CFsControlBarModel* iModel;
       
   348 
       
   349     /**
       
   350      * Control bar's visualiser
       
   351      * Own.
       
   352      */
       
   353     CFsControlBarVisualiser* iVisualiser;
       
   354 
       
   355     /**
       
   356      * Selected button index.
       
   357      */
       
   358     TInt iSelectedButton;
       
   359 
       
   360     /**
       
   361      * Collection of additional Observers.
       
   362      */
       
   363     RPointerArray< MFsControlBarObserver > iObservers;
       
   364 
       
   365     /**
       
   366      * Last screen width.
       
   367      */
       
   368     TInt iLastScreenWidth;
       
   369 
       
   370     /**
       
   371      * Text style manager.
       
   372      * Own.
       
   373      */
       
   374     CFsTextStyleManager* iTextStyleManager;
       
   375 
       
   376     // <cmail> Touch
       
   377     /**
       
   378      * Control touch
       
   379      */
       
   380     TBool iTouchEnabled;
       
   381     TBool iTouchWasEnabled;
       
   382     // </cmail>
       
   383 
       
   384 
       
   385     };
       
   386 
       
   387 
       
   388 #endif // C_FSCONTROLBAR_H