emailuis/uicomponents/inc/fscontrolbuttonvisualiser.h
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     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:  Visualiser class of the button.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_FSCONTROLBUTTONVISUALISER_H
       
    20 #define C_FSCONTROLBUTTONVISUALISER_H
       
    21 
       
    22 #include <gdi.h>
       
    23 //<cmail> SF
       
    24 #include <alf/alfgc.h>
       
    25 #include <alf/alftexturemanager.h>
       
    26 //</cmail>
       
    27 #include "fscontrolbuttonconst.h"
       
    28 
       
    29 class CAlfControl;
       
    30 class CAlfVisual;
       
    31 class CAlfLayout;
       
    32 class CAlfBrush;
       
    33 class CAlfFrameBrush;
       
    34 class CAlfTextVisual;
       
    35 class CAlfGridLayout;
       
    36 class CAlfDeckLayout;
       
    37 class CAlfAnchorLayout;
       
    38 class CAlfImageVisual;
       
    39 class TAlfTextStyle;
       
    40 class TAlfTimedPoint;
       
    41 class CAlfTexture;
       
    42 class CAlfGradientBrush;
       
    43 class CAlfImageBrush;
       
    44 class CAlfShadowBorderBrush;
       
    45 class CFsControlButtonModel;
       
    46 class CFsControlButtonLayoutData;
       
    47 class CFsTextStyleManager;
       
    48 class TCharFormat;
       
    49 
       
    50 /**
       
    51  *  Visualiser class of the button.
       
    52  *
       
    53  *  @code
       
    54  *
       
    55  *  @endcode
       
    56  *
       
    57  *  @lib fs_generic.lib
       
    58  */
       
    59 class CFsControlButtonVisualiser : public CBase,
       
    60     public MAlfTextureLoadingCompletedObserver
       
    61     {
       
    62 
       
    63 public:
       
    64 
       
    65     /**
       
    66      * Two-phased constructor..
       
    67      */
       
    68     static CFsControlButtonVisualiser* NewL(
       
    69         CAlfControl& aParent,
       
    70         CAlfDeckLayout& aParentLayout,
       
    71         CFsTextStyleManager* aTextStyleManager );
       
    72 
       
    73     /**
       
    74      * Destructor.
       
    75      */
       
    76     IMPORT_C virtual ~CFsControlButtonVisualiser();
       
    77 
       
    78     /**
       
    79      * Attaches model to visualiser.
       
    80      *
       
    81      * @param aButtonModel button's model.
       
    82      */
       
    83     IMPORT_C virtual void InitializeL( CFsControlButtonModel& aButtonModel );
       
    84 
       
    85     /**
       
    86      * Called when the colors etc should be refreshed
       
    87      */
       
    88     virtual void UpdateVisualThemeL();
       
    89     
       
    90     /**
       
    91      * Refreshes button on the display.
       
    92      */
       
    93     IMPORT_C virtual void Refresh();
       
    94 
       
    95     /**
       
    96      * Refreshes button on the display placing it at specified point.
       
    97      *
       
    98      * @param aStartAt start point of the buton.
       
    99      */
       
   100     IMPORT_C virtual void Refresh( TPoint aStartAt );
       
   101 
       
   102     /**
       
   103      * Retrieves end X coordinate of the button.
       
   104      *
       
   105      * @return X coordinate of the bottom right point of the button.
       
   106      */
       
   107     TInt GetBottomRight() const;
       
   108 
       
   109     /**
       
   110      * Retrieves position of the button.
       
   111      *
       
   112      * @return start point of the button.
       
   113      */
       
   114     const TAlfTimedPoint Pos() const;
       
   115 
       
   116     /**
       
   117      * Retrieves size of the button.
       
   118      *
       
   119      * @return size of the button.
       
   120      */
       
   121     const TAlfTimedPoint Size() const;
       
   122 
       
   123     /**
       
   124      * Sets background image of the button. Ownership of the object is transfered.
       
   125      *
       
   126      * @param aImage Image brush that is used at background.
       
   127      */
       
   128     IMPORT_C virtual void SetBackgroundImageL( CAlfImageBrush* aImage );
       
   129 
       
   130     /**
       
   131      * Sets button's background color.
       
   132      *
       
   133      * @param aColor background color to be set.
       
   134      */
       
   135     IMPORT_C virtual void SetBackgroundColor( const TRgb& aColor );
       
   136 
       
   137     /**
       
   138      * Clears button's background color. Button is transparent.
       
   139      */
       
   140     IMPORT_C virtual void ClearBackgroundColor();
       
   141 
       
   142     /**
       
   143      * Clears button's background image.
       
   144      */
       
   145     IMPORT_C virtual void ClearBackgroundImage();
       
   146 
       
   147     /**
       
   148      * Sets alignment of element of the button.
       
   149      *
       
   150      * @param aButtonElem element to be aligned.
       
   151      * @param aHAlign horizontal alignement of element.
       
   152      * @param aVAlign vertical alignement of element.
       
   153      */
       
   154     IMPORT_C virtual void SetElemAlignL(
       
   155         TFsControlButtonElem aButtonElem,
       
   156         TAlfAlignHorizontal aHAlign,
       
   157         TAlfAlignVertical aVAlign );
       
   158 
       
   159     /**
       
   160      * Set new height for the button text.
       
   161      * Setting a negative or zero value changes the value back to default.
       
   162      *
       
   163      * @param aTextHeight Height in pixels.
       
   164      */
       
   165     IMPORT_C virtual void SetTextHeight( const TInt aTextHeight );
       
   166 
       
   167     /**
       
   168      * Change the current font.
       
   169      *
       
   170      * @param aFontSpec Font specification.
       
   171      */
       
   172     IMPORT_C virtual void SetTextFontL( const TFontSpec& aFontSpec );
       
   173 
       
   174     /**
       
   175      * Updates element content from the model.
       
   176      *
       
   177      * @param aButtonElem element to be updated.
       
   178      */
       
   179     IMPORT_C virtual void UpdateElementL( TFsControlButtonElem aButtonElem );
       
   180 
       
   181     /**
       
   182      * Retrieves width of the button.
       
   183      *
       
   184      * @return width of the button.
       
   185      */
       
   186     TInt Width() const;
       
   187 
       
   188     /**
       
   189      * Updates size of button.
       
   190      */
       
   191     IMPORT_C virtual void UpdateButtonSize();
       
   192 
       
   193     /**
       
   194      * Retrieves the background layout of the button.
       
   195      *
       
   196      * @return Background layout of the button.
       
   197      */
       
   198     CAlfLayout* Layout();
       
   199 
       
   200     /**
       
   201      * Retrieves the content layout of the button.
       
   202      *
       
   203      * @return Content layout of the button.
       
   204      */
       
   205     CAlfLayout* ContentLayout();
       
   206 
       
   207     /**
       
   208      * Enables button.
       
   209      */
       
   210     IMPORT_C virtual void ShowL();
       
   211 
       
   212     /**
       
   213      * Disables button.
       
   214      */
       
   215     IMPORT_C virtual void Hide();
       
   216 
       
   217     /**
       
   218      * Checks if button is visible or not.
       
   219      *
       
   220      * @return ETrue if visible, EFalse if hidden.
       
   221      */
       
   222     TBool IsVisible() const;
       
   223 
       
   224     /**
       
   225      * Sets parent layout.
       
   226      *
       
   227      * @param aParentLayout layout of parent control.
       
   228      */
       
   229     void SetParentLayoutL( CAlfDeckLayout* aParentLayout );
       
   230 
       
   231     /**
       
   232      * Sets parent control.
       
   233      *
       
   234      * @param aParentControl parent control.
       
   235      */
       
   236     void SetParentControlL( CAlfControl* aParentControl );
       
   237 
       
   238     /**
       
   239      * Assign a new text style manager.
       
   240      *
       
   241      * @param aTextStyleManager New text style manager.
       
   242      */
       
   243     void SetTextStyleManager( CFsTextStyleManager* aTextStyleManager );
       
   244 
       
   245     /**
       
   246      * Update elemets after texture loading is completed.
       
   247      *
       
   248      * @param aTexture Reference to the texture that has been loaded.
       
   249      * @param aTextureId Id of the texture in the texture manager. Can be used
       
   250      * to identify the loaded texture, provided that an id was assigned to the
       
   251      * texture.
       
   252      * @param aErrorCode KErrNone if the load was successful, otherwise one of
       
   253      * the system-wide error codes indicating reason why the texture loading
       
   254      * failed.
       
   255      */
       
   256     IMPORT_C virtual void TextureLoadingCompleted(
       
   257         CAlfTexture& aTexture, TInt aTextureId, TInt aErrorCode );
       
   258 
       
   259     /**
       
   260      * Enables focus drawing for item and draws it.
       
   261      * NOTE: Do not change focus state. Item might be focused altough
       
   262      *       selector is not visible.
       
   263      * @param aShow If ETrue visibility of focus is drawn if
       
   264      *              EFalse visibility of focus is hidden.
       
   265      */
       
   266     void MakeFocusVisible( TBool aShow );
       
   267 
       
   268 protected:
       
   269 
       
   270     /**
       
   271      * Sets colors and bitmaps for drawing button in "focused" state.
       
   272      */
       
   273     IMPORT_C virtual void PrepareDrawFocused();
       
   274 
       
   275     /**
       
   276      * Sets colors and bitmaps for drawing button in "normal
       
   277      * (no focus, enabled)" state.
       
   278      */
       
   279     IMPORT_C virtual void PrepareDrawNormal();
       
   280 
       
   281     /**
       
   282      * Sets colors and bitmaps for drawing button in "dimmed" state.
       
   283      */
       
   284     IMPORT_C virtual void PrepareDrawDimmed();
       
   285 
       
   286 protected:
       
   287 
       
   288     /**
       
   289      * Constructor.
       
   290      *
       
   291      * @param aParent parent control.
       
   292      * @param aParentLayout layout of parent control.
       
   293      * @param aTextStyleManager Text style manager.
       
   294      */
       
   295     IMPORT_C CFsControlButtonVisualiser(
       
   296         CAlfControl& aParent,
       
   297         CAlfDeckLayout& aParentLayout,
       
   298         CFsTextStyleManager* aTextStyleManager );
       
   299 
       
   300     /**
       
   301      * Constructor.
       
   302      */
       
   303     IMPORT_C CFsControlButtonVisualiser();
       
   304 
       
   305     /**
       
   306      * Second phase constructor.
       
   307      */
       
   308     IMPORT_C virtual void ConstructL();
       
   309 
       
   310     /**
       
   311      * Creates needed visuals for specified button type.
       
   312      */
       
   313     IMPORT_C virtual void CreateButtonVisualsL();
       
   314 
       
   315     /**
       
   316      * Calculates button size according to content.
       
   317      *
       
   318      * @return size of button.
       
   319      */
       
   320     IMPORT_C virtual TInt CalculateButtonSize();
       
   321 
       
   322     /**
       
   323      * Updates position of button.
       
   324      */
       
   325     void UpdateButtonPos();
       
   326 
       
   327     /**
       
   328      * Updates size of columns in grid layouter for button's elements.
       
   329      *
       
   330      * @param aButtonType type of button.
       
   331      */
       
   332     IMPORT_C virtual void UpdateElementsSizeL(
       
   333         TFsControlButtonType aButtonType );
       
   334 
       
   335     /**
       
   336      * Sets text styles for specified button type.
       
   337      */
       
   338     IMPORT_C virtual void UpdateTextStyles();
       
   339 
       
   340     /**
       
   341      * Sets alignment of specified image of the button.
       
   342      *
       
   343      * @param aImage image to be aligned.
       
   344      * @param aHAlign horizontal alignement of element.
       
   345      * @param aVAlign vertical alignement of element.
       
   346      */
       
   347     IMPORT_C virtual void SetImageAlign( CAlfImageVisual* aImage,
       
   348                                          TAlfAlignHorizontal aHAlign,
       
   349                                          TAlfAlignVertical aVAlign );
       
   350 
       
   351     /**
       
   352      * Sets alignment of specified text of the button.
       
   353      *
       
   354      * @param aText text to be aligned.
       
   355      * @param aHAlign horizontal alignement of element.
       
   356      * @param aVAlign vertical alignement of element.
       
   357      */
       
   358     IMPORT_C virtual void SetTextAlign( CAlfTextVisual* aText,
       
   359                                         TAlfAlignHorizontal aHAlign,
       
   360                                         TAlfAlignVertical aVAlign );
       
   361 
       
   362     /**
       
   363      * Updates bar layout.
       
   364      */
       
   365     void UpdateBarLayout();
       
   366 
       
   367     /**
       
   368      * Resolve the character format from current text visual.
       
   369      *
       
   370      * @param aCharFormat Place holder for resolved character format.
       
   371      * @param aTextVisual Text visual.
       
   372      */
       
   373     void ResolveCharFormat(
       
   374         TCharFormat& aCharFormat,
       
   375         CAlfTextVisual* aTextVisual );
       
   376 
       
   377 protected: // data
       
   378 
       
   379     /**
       
   380      * Parent control.
       
   381      * Not own.
       
   382      */
       
   383     CAlfControl*    iParent;
       
   384 
       
   385     /**
       
   386      * Model of the button.
       
   387      * Not owned.
       
   388      */
       
   389     CFsControlButtonModel* iButtonModel;
       
   390 
       
   391     /**
       
   392      * Layout of the button control.
       
   393      * Owned (because of possibility to change visualiser -
       
   394      * old one has to be removed from parent and layout tree).
       
   395      */
       
   396     CAlfLayout* iButtonLayout;
       
   397 
       
   398     /**
       
   399      * Layout for button content.
       
   400      * Not own.
       
   401      */
       
   402     CAlfLayout* iButtonContentLayout;
       
   403 
       
   404     /**
       
   405      * Visual for first line of text.
       
   406      * Not own.
       
   407      */
       
   408     CAlfTextVisual* iLabelFirstLine;
       
   409 
       
   410     /**
       
   411      * Visual for second line of text.
       
   412      * Not own.
       
   413      */
       
   414     CAlfTextVisual* iLabelSecondLine;
       
   415 
       
   416     /**
       
   417      * Height of the button's text in pixels.
       
   418      */
       
   419     TInt iTextHeight;
       
   420 
       
   421     /**
       
   422      * Font specification.
       
   423      * Owned.
       
   424      */
       
   425     TFontSpec* iTextFontSpec;
       
   426 
       
   427     /**
       
   428      * Flag to determine if the text size has been changed.
       
   429      */
       
   430     TBool iTextHeightSet;
       
   431 
       
   432     /**
       
   433      * Visual for the A icon.
       
   434      * Not own.
       
   435      */
       
   436     CAlfImageVisual* iIconA;
       
   437 
       
   438     /**
       
   439      * Container for icon A.
       
   440      * Not own.
       
   441      */
       
   442     CAlfLayout* iIconAContainer;
       
   443 
       
   444     /**
       
   445      * Visual for the B icon.
       
   446      * Not own.
       
   447      */
       
   448     CAlfImageVisual* iIconB;
       
   449 
       
   450     /**
       
   451      * Container for icon B.
       
   452      * Not own.
       
   453      */
       
   454     CAlfLayout* iIconBContainer;
       
   455 
       
   456     /**
       
   457      * Background color.
       
   458      * Owned.
       
   459      */
       
   460     CAlfGradientBrush* iBgColorBrush;
       
   461 
       
   462     /**
       
   463      * Brush with background image.
       
   464      * Owned.
       
   465      */
       
   466     CAlfBrush* iBgBrush;
       
   467 
       
   468     /**
       
   469      * Default brush for background. Owned.
       
   470      */
       
   471     CAlfFrameBrush* iDefaultBgBrush;
       
   472 
       
   473 	/**
       
   474 	 * ETrue if default theme background is used
       
   475 	 */
       
   476     TBool iUseDefaultBackground;
       
   477     
       
   478     /**
       
   479      * Brush for shadowed button borders.
       
   480      * Owned.
       
   481      */
       
   482     CAlfShadowBorderBrush* iShadowBorderBrush;
       
   483 
       
   484     /**
       
   485      * Layout of the parent control.
       
   486      * Not owned.
       
   487      */
       
   488     CAlfDeckLayout* iParentLayout;
       
   489 
       
   490     /**
       
   491      * Flag for recalculate positions of icons.
       
   492      */
       
   493     TBool iUpdateIconsAlign;
       
   494 
       
   495     /**
       
   496      * First draw.
       
   497      */
       
   498     TBool iFirstDraw;
       
   499 
       
   500     /**
       
   501      * Horizontal alignement of A icon.
       
   502      */
       
   503     TAlfAlignHorizontal iAIconHAlign;
       
   504 
       
   505     /**
       
   506      * Vertical alignement of A icon.
       
   507      */
       
   508     TAlfAlignVertical iAIconVAlign;
       
   509 
       
   510     /**
       
   511      * Horizontal alignement of B icon.
       
   512      */
       
   513     TAlfAlignHorizontal iBIconHAlign;
       
   514 
       
   515     /**
       
   516      * Vertical alignement of B icon.
       
   517      */
       
   518     TAlfAlignVertical iBIconVAlign;
       
   519 
       
   520     /**
       
   521      * Flag for visible/hidden state.
       
   522      */
       
   523     TBool iVisible;
       
   524 
       
   525     /**
       
   526      * Visual for button pane.
       
   527      * Not own.
       
   528      */
       
   529     CAlfVisual* iButtonPane;
       
   530 
       
   531     /**
       
   532      * Background color.
       
   533      */
       
   534     TRgb iBackgroundColor;
       
   535 
       
   536     /**
       
   537      * Text style manager.
       
   538      * Not own.
       
   539      */
       
   540     CFsTextStyleManager* iTextStyleManager;
       
   541 
       
   542     /**
       
   543      * States that can focus been drawn.
       
   544      */
       
   545     TBool iDrawFocus;
       
   546 
       
   547     /**
       
   548      * Show dropdown shadow for buttons  
       
   549      */
       
   550     TBool iShowShadow;
       
   551     };
       
   552 
       
   553 
       
   554 #endif // C_FSCONTROLBUTTONVISUALISER_H