emailuis/uicomponents/inc/fscontrolbutton.h
changeset 0 8466d47a6819
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 Button component.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_FSCONTROLBUTTON_H
       
    20 #define C_FSCONTROLBUTTON_H
       
    21 //<cmail> SF
       
    22 #include <alf/alfcontrol.h>
       
    23 #include <alf/alftexturemanager.h>
       
    24 #include <alf/alfgc.h>
       
    25 //</cmail>
       
    26 #include "fscontrolbuttoninterface.h"
       
    27 
       
    28 class CAlfDeckLayout;
       
    29 class CAlfTexture;
       
    30 class CFsControlButtonModel;
       
    31 class MFsControlButtonObserver;
       
    32 class CFsControlButtonVisualiser;
       
    33 class CFsTextStyleManager;
       
    34 
       
    35 /**
       
    36  *  Main class for ControlButton component
       
    37  *  Control class of ControlButton component.
       
    38  *
       
    39  *  @code
       
    40  *
       
    41  *  @endcode
       
    42  *
       
    43  *  @lib fs_generic.lib
       
    44   */
       
    45 NONSHARABLE_CLASS( CFsControlButton ) :
       
    46     public CAlfControl,
       
    47     public MFsControlButtonInterface
       
    48     {
       
    49 
       
    50 public:
       
    51 
       
    52     /**
       
    53      * Two-phased constructor.
       
    54      *
       
    55      * @param aEnv huitk environment instance.
       
    56      * @param aParent parent control.
       
    57      * @param aId unique id of the button.
       
    58      * @param aType Button type.
       
    59      * @param aStartPoint Starting point of the button.
       
    60      * @param aParentLayout layout of the button.
       
    61      * @param aTextStyleManager Text style manager.
       
    62      */
       
    63     static CFsControlButton* NewL(
       
    64         CAlfEnv& aEnv,
       
    65         MFsControlButtonObserver& aParent,
       
    66         TInt aId,
       
    67         TFsControlButtonType aType,
       
    68         TRect& aStartPoint,
       
    69         CAlfDeckLayout& aParentLayout,
       
    70         CFsTextStyleManager* aTextStyleManager );
       
    71 
       
    72     /**
       
    73      * Destructor.
       
    74      */
       
    75     virtual ~CFsControlButton();
       
    76 
       
    77 
       
    78     /**
       
    79      * Retrieves button's visualiser.
       
    80      *
       
    81      * @return visualiser of the button.
       
    82      */
       
    83     CFsControlButtonVisualiser* Visualiser();
       
    84 
       
    85     /**
       
    86      * Set the layout position index on controlbar.
       
    87      *
       
    88      * @param aLayoutPos New layout position on controlbar.
       
    89      */
       
    90     void SetParentIndex( TInt aLayoutPos );
       
    91 
       
    92     /**
       
    93      * Sets focus to control button.
       
    94      *
       
    95      * @param aState state of focus.
       
    96      */
       
    97     void SetFocus( TBool aState = ETrue );
       
    98 
       
    99     /**
       
   100      * Refresh the button's position.
       
   101      */
       
   102     void RefreshButtonPosition( TSize& aParentSize );
       
   103 
       
   104 // from base class CAlfControl
       
   105 
       
   106     virtual TBool OfferEventL( const TAlfEvent& aEvent );
       
   107 
       
   108 // from base class MFsControlButtonInterface
       
   109 
       
   110     /**
       
   111      * From MFsControlButtonInterface.
       
   112      * Sets first line of text in button.
       
   113      *
       
   114      * @param aLabel text to be set.
       
   115      * @param aContent Specifies the text row.
       
   116      */
       
   117     virtual void SetTextL( const TDesC& aLabel, TFsButtonContent aContent );
       
   118 
       
   119     /**
       
   120      * From MFsControlButtonInterface.
       
   121      * Sets visualiser for the button. Ownership of the new visualiser is
       
   122      * gained.
       
   123      *
       
   124      * @param aVisualiser New visualiser to be used to draw button.
       
   125      */
       
   126     virtual void SetVisualiserL( CFsControlButtonVisualiser* aVisualiser );
       
   127 
       
   128     /**
       
   129      * From MFsControlButtonInterface.
       
   130      * Retrieves id of the button.
       
   131      *
       
   132      * @return id of the button.
       
   133      */
       
   134     virtual TInt Id() const;
       
   135 
       
   136     /**
       
   137      * From MFsControlButtonInterface.
       
   138      * Sets icon in the button.
       
   139      *
       
   140      * @param aIcon icon to be added.
       
   141      * @param aWhich specifies which icon is to be added, A or B.
       
   142      */
       
   143     virtual void SetIconL(
       
   144         CAlfTexture& aIcon,
       
   145         TFsControlButtonElem aWhich = ECBElemIconA );
       
   146 
       
   147     /**
       
   148      * From MFsControlButtonInterface.
       
   149      * Sets width of the button.
       
   150      *
       
   151      * @param aWidth width of the button.
       
   152      */
       
   153     virtual void SetWidth( TInt aWidth );
       
   154 
       
   155     // <cmail> Platform layout changes
       
   156     /**
       
   157      * @see MFsControlButtonInterface::SetSize
       
   158      */
       
   159     virtual void SetSize( const TSize& aSize );
       
   160     // </cmail> Platform layout changes
       
   161 
       
   162     /**
       
   163      * From MFsControlButtonInterface.
       
   164      * Set auto size mode for button.
       
   165      * Defines how the buttons size is changed.
       
   166      *
       
   167      * @param aAutoSizeMode new mode.
       
   168      */
       
   169     virtual void SetAutoSizeMode(
       
   170         MFsControlButtonInterface::TFsAutoSizeMode aAutoSizeMode );
       
   171 
       
   172     /**
       
   173      * From MFsControlButtonInterface.
       
   174      * Checks if button has focus.
       
   175      *
       
   176      * @return ETrue if focused, EFalse otherwise.
       
   177      */
       
   178     virtual TBool IsFocused() const;
       
   179 
       
   180     // <cmail> Platform layout changes
       
   181     /**
       
   182      * From MFsControlButtonInterface.
       
   183      * Sets position of the button (top left point).
       
   184      *
       
   185      * @param aTlPoint coordinates of top left point.
       
   186      */
       
   187     virtual void SetPos( const TPoint& aTlPoint );
       
   188     // </cmail> Platform layout changes
       
   189 
       
   190     /**
       
   191      * From MFsControlButtonInterface.
       
   192      * Retrieves position of button.
       
   193      *
       
   194      * @return  position of button.
       
   195      */
       
   196     virtual const TAlfTimedPoint Pos() const;
       
   197 
       
   198     /**
       
   199      * From MFsControlButtonInterface.
       
   200      * Retrieves size of button.
       
   201      *
       
   202      * @return size of button.
       
   203      */
       
   204     virtual const TAlfTimedPoint Size() const;
       
   205 
       
   206     /**
       
   207      * From MFsControlButtonInterface.
       
   208      * Sets component to button which will be triggered when button
       
   209      * is pressed.
       
   210      *
       
   211      * @param aComponent component to be set.
       
   212      */
       
   213     virtual void SetTriggeredComponent( MFsTriggeredComponent& aComponent );
       
   214 
       
   215     /**
       
   216      * From MFsControlButtonInterface.
       
   217      * Clears triggered component. No more events to triggered
       
   218      * component are sent.
       
   219      */
       
   220     virtual void ClearTriggeredComponent();
       
   221 
       
   222     /**
       
   223      * From MFsControlButtonInterface.
       
   224      * Sets alignment of element.
       
   225      *
       
   226      * @param aButtonElem element to be aligned.
       
   227      * @param aHAlign horizontal alignment of element.
       
   228      * @param aVAlign vertical alignment of element.
       
   229      */
       
   230     virtual void SetElemAlignL( TFsControlButtonElem aButtonElem,
       
   231                        TAlfAlignHorizontal aHAlign,
       
   232                        TAlfAlignVertical aVAlign );
       
   233 
       
   234     /**
       
   235      * From MFsControlButtonInterface.
       
   236      * Sets dimm state of the button.
       
   237      *
       
   238      * @param aDimmed dimm state of the the button.
       
   239      */
       
   240     virtual void SetDimmed( TBool aDimmed = ETrue );
       
   241 
       
   242     /**
       
   243      * From MFsControlButtonInterface.
       
   244      * Checks dimm state of the button.
       
   245      *
       
   246      * @return ETrue if dimmed, EFalse otherwise.
       
   247      */
       
   248     virtual TBool IsDimmed() const;
       
   249 
       
   250     /**
       
   251      * From MFsControlButtonInterface.
       
   252      * Shows (enables) button.
       
   253      */
       
   254     virtual void ShowButtonL();
       
   255 
       
   256     /**
       
   257      * From MFsControlButtonInterface.
       
   258      * Hides (disables) button.
       
   259      */
       
   260     virtual void HideButton();
       
   261 
       
   262     /**
       
   263      * From MFsControlButtonInterface.
       
   264      * Checks if button is visible (enabled).
       
   265      *
       
   266      * @return ETrue if enabled, EFalse otherwise.
       
   267      */
       
   268     virtual TBool IsVisible() const;
       
   269 
       
   270     /**
       
   271      * From MFsControlButtonInterface.
       
   272      * Sets bar's background image. Ownership of the object is transfered.
       
   273      *
       
   274      * @param aImage Background image brush.
       
   275      */
       
   276     virtual void SetBackgroundImageL( CAlfImageBrush* aImage );
       
   277 
       
   278     /**
       
   279      * From MFsControlButtonInterface.
       
   280      * Sets button's background color.
       
   281      *
       
   282      * @param aColor color of background.
       
   283      */
       
   284     virtual void SetBackgroundColor( const TRgb& aColor );
       
   285 
       
   286     /**
       
   287      * From MFsControlButtonInterface.
       
   288      * Clears button's background color. Button is transparent.
       
   289      */
       
   290     virtual void ClearBackgroundColor();
       
   291 
       
   292     /**
       
   293      * From MFsControlButtonInterface.
       
   294      * Clears button's background image.
       
   295      */
       
   296     virtual void ClearBackgroundImage();
       
   297 
       
   298     /**
       
   299      * From MFsControlButtonInterface.
       
   300      * Retrieves text from control button.
       
   301      *
       
   302      * @param aContent Specifies the text row.
       
   303      * @return text on control button.
       
   304      */
       
   305     virtual TPtrC Text( TFsButtonContent aContent ) const;
       
   306 
       
   307     /**
       
   308      * From MFsControlButtonInterface.
       
   309      * Set new height for the button text.
       
   310      *
       
   311      * @param aTextHeight Height in pixels.
       
   312      */
       
   313     virtual void SetTextHeight( const TInt aTextHeight );
       
   314 
       
   315     /**
       
   316      * From MFsControlButtonInterface.
       
   317      * Change the current font.
       
   318      *
       
   319      * @param aFont Font specification.
       
   320      */
       
   321     virtual void SetTextFontL( const TFontSpec& aFont );
       
   322 
       
   323     /**
       
   324      * From MFsControlButtonInterface.
       
   325      * Set button's text color when it's not focused or dimmed.
       
   326      *
       
   327      * @param aColor New color.
       
   328      */
       
   329     virtual void SetNormalTextColor( const TRgb& aColor );
       
   330 
       
   331     /**
       
   332      * From MFsControlButtonInterface.
       
   333      * Set button's text color when it's focused.
       
   334      *
       
   335      * @param aColor New color.
       
   336      */
       
   337     virtual void SetFocusedTextColor( const TRgb& aColor );
       
   338 
       
   339     /**
       
   340      * From MFsControlButtonInterface.
       
   341      * Set button's text color when it's dimmed.
       
   342      *
       
   343      * @param aColor New color.
       
   344      */
       
   345     virtual void SetDimmedTextColor( const TRgb& aColor );
       
   346 
       
   347     /**
       
   348      * From MFsControlButtonInterface.
       
   349      * Retrieves control button type.
       
   350      *
       
   351      * @return control button type.
       
   352      */
       
   353     virtual TFsControlButtonType ControlButtonType() const;
       
   354 
       
   355 // <cmail> Touch
       
   356     virtual CAlfControl* AsAlfControl();
       
   357 // </cmail>
       
   358 
       
   359     /**
       
   360      * Enables focus drawing for item and draws it.
       
   361      * NOTE: Do not change focus state. Item might be focused altough
       
   362      *       selector is not visible.
       
   363      * @param aShow If ETrue visibility of focus is drawn if
       
   364      *              EFalse visibility of focus is hidden.
       
   365      */
       
   366     void MakeFocusVisible( TBool aShow );
       
   367 
       
   368 private:
       
   369 
       
   370     /**
       
   371      * Constructor.
       
   372      *
       
   373      * @param aParent parent control.
       
   374      * @param aParentLayout If given, has the parent layout.
       
   375      */
       
   376     CFsControlButton( MFsControlButtonObserver& aParent,
       
   377         CAlfDeckLayout& aParentLayout );
       
   378 
       
   379     /**
       
   380      * Constructs and initializes button control.
       
   381      *
       
   382      * @param aEnv Environment.
       
   383      * @param aId unique id of the button.
       
   384      * @param aType type of the button.
       
   385      * @param aStartPoint Starting point of the button.
       
   386      * @param aTextStyleManager Text style manager.
       
   387      */
       
   388     void ConstructL(
       
   389         CAlfEnv& aEnv,
       
   390         TInt aId,
       
   391         TFsControlButtonType aType,
       
   392         TRect& aStartPoint,
       
   393         CFsTextStyleManager* aTextStyleManager );
       
   394 
       
   395     /**
       
   396      * Starts to listen unhandled pointer events.
       
   397      *
       
   398      * @param aGrab ETrue adds pointer event observer if EFalse removes it.
       
   399      */
       
   400     void GrabPointerEvents( TBool aGrab );
       
   401 
       
   402 private: // data
       
   403 
       
   404     /**
       
   405      * Parent of button.
       
   406      * Not own.
       
   407      */
       
   408     MFsControlButtonObserver& iParent;
       
   409 
       
   410     /**
       
   411      * Button's model.
       
   412      * Own.
       
   413      */
       
   414     CFsControlButtonModel* iModel;
       
   415 
       
   416     /**
       
   417      * Button's visualiser.
       
   418      * Own.
       
   419      */
       
   420     CFsControlButtonVisualiser* iVisualiser;
       
   421 
       
   422     /**
       
   423      * Component triggered by button.
       
   424      * Not own.
       
   425      */
       
   426     MFsTriggeredComponent* iTriggeredComponent;
       
   427 
       
   428     /**
       
   429      * Flag for visibility state changed from hidden to visible.
       
   430      */
       
   431     TBool iWasHidden;
       
   432 
       
   433     /**
       
   434      * Parent layout.
       
   435      */
       
   436     CAlfDeckLayout& iParentLayout;
       
   437 
       
   438     /**
       
   439      * Flag that states if event was received after touch event.
       
   440      */
       
   441     TBool iTouchPressed;
       
   442 
       
   443     };
       
   444 
       
   445 #endif // C_FSCONTROLBUTTON_H