uifw/AvKon/inc/AknTabGrpGraphics.h
changeset 0 2f259fa3e83a
child 51 fcdfafb36fe7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Class for drawing tab graphics.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_AKNTABGRPGRAPHICS_H
       
    20 #define C_AKNTABGRPGRAPHICS_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 
       
    25 // FORWARD DECLARATIONS
       
    26 class CFbsBitmap;
       
    27 class CFbsBitmapDevice;
       
    28 class CFbsBitGc;
       
    29 class CBitmapContext;
       
    30 class TAknWindowComponentLayout;
       
    31 
       
    32 
       
    33 /**
       
    34  * This class takes care of drawing tab graphics which are defined
       
    35  * in SVG format and are defined differently than old tab group graphics.
       
    36  * Basically this class can be used to draw a new ram bitmap which contains
       
    37  * old style tab group bitmap.
       
    38  *
       
    39  * @since 2.8
       
    40  * @lib avkon.lib
       
    41  * @internal
       
    42  */
       
    43 NONSHARABLE_CLASS( CAknTabGroupGraphics ) : public CBase
       
    44     {
       
    45 public:
       
    46 
       
    47     struct SAknTabGroupBackground
       
    48         {
       
    49         SAknTabGroupBackground() : iBitmap( NULL ), iMask( NULL ) {};
       
    50         CFbsBitmap* iBitmap;
       
    51         CFbsBitmap* iMask;
       
    52         };
       
    53 
       
    54     struct SAknTabLayout
       
    55         {
       
    56         SAknTabLayout()
       
    57         : iActive( EFalse ), iLeft(0,0,0,0), iMiddle(0,0,0,0), iRight(0,0,0,0)
       
    58         {};
       
    59 
       
    60         TBool iActive;
       
    61         TRect iLeft;
       
    62         TRect iMiddle;
       
    63         TRect iRight;
       
    64         };
       
    65 
       
    66     struct SAknTabGroupBackgroundLayout
       
    67         {
       
    68         SAknTabGroupBackgroundLayout()
       
    69         : iUse( EFalse ),
       
    70           iFirstTab(),
       
    71           iSecondTab(),
       
    72           iThirdTab(),
       
    73           iFourthTab()
       
    74         {};
       
    75 
       
    76         // This tells wheter rest of the data is valid to be used or not.
       
    77         TBool         iUse;
       
    78 
       
    79         SAknTabLayout iFirstTab;
       
    80         SAknTabLayout iSecondTab;
       
    81         SAknTabLayout iThirdTab;
       
    82         SAknTabLayout iFourthTab;
       
    83         SAknTabLayout iHiddenTabLeft;
       
    84         SAknTabLayout iHiddenTabRight;
       
    85         };
       
    86 
       
    87 public: // Constructors and destructor
       
    88 
       
    89     /**
       
    90     * Two-phased constructor.
       
    91     *
       
    92     * @return  Newly constructed object.
       
    93     */
       
    94     static CAknTabGroupGraphics* NewL();
       
    95 
       
    96     /**
       
    97     * Destructor.
       
    98     */
       
    99     virtual ~CAknTabGroupGraphics();
       
   100 
       
   101 public: // New functions
       
   102 
       
   103     /**
       
   104     * This method tells if this class is able to draw tab background or not.
       
   105     *
       
   106     * @return  @c ETrue if drawing is possible, otherwise @c EFalse.
       
   107     */
       
   108     TBool TabGroupBackgroundAvailable();
       
   109 
       
   110     /**
       
   111     * This method sets the parent rectangle which will be used in the layout
       
   112     * calculations when tab background is drawn.
       
   113     *
       
   114     * @param  aParent  Parent rectangle
       
   115     */
       
   116     void SetTabGroupBackgroundParent( TRect aParent );
       
   117 
       
   118 #if 0 // not used
       
   119     /**
       
   120     * This method draws the tab background bitmap using SVG graphics.
       
   121     * The tab combination is given as bitmap id which refers to old style
       
   122     * tab bitmaps.
       
   123     *
       
   124     * @param  aAvkonBitmapId  Bitmap index (@see avkon.mbg).
       
   125     *
       
   126     * @return  Struct which contains both the bitmap and the mask.
       
   127     *          Ownership is transferred to the caller.
       
   128     */
       
   129     CAknTabGroupGraphics::SAknTabGroupBackground CreateTabGroupBackgroundL(
       
   130         TInt aAvkonBitmapId );
       
   131         
       
   132 #endif
       
   133     /**
       
   134     * Draw modes of the tab background graphics.
       
   135     */ 
       
   136     enum TTabDrawMode
       
   137         {
       
   138         ENormal,     ///< Draws both bitmap and mask.
       
   139         EBitmapOnly, ///< Draws only the bitmaps without masks.
       
   140         EMaskOnly,   ///< Draws only the mask bitmaps.
       
   141         ENoDraw      ///< Only calculates the layouts.
       
   142         };
       
   143     
       
   144     /**
       
   145     * These values are used to specify whether "hidden" tabs are drawn to the
       
   146     * background, meaning tabs that are only partially visible on either
       
   147     * side of the tab group. Hidden tabs are drawn in touch layouts, in
       
   148     * which they are used instead of navigation arrows to indicate that there
       
   149     * are more tabs than currently visible in the tab group. They also need
       
   150     * to be drawn to the background in the tab cycle animation.
       
   151     */ 
       
   152     enum TTabsHidden
       
   153         {
       
   154         ENone,          ///< No hidden tabs.
       
   155         EOnLeftSide,    ///< Hidden tab drawn on the left side.
       
   156         EOnRightSide,   ///< Hidden tab drawn on the right side.
       
   157         EOnBothSides,   ///< Hidden tabs drawn on both sides.
       
   158         ETwoOnBothSides ///< Two hidden tabs drawn on both sides.
       
   159         };
       
   160     
       
   161     /**
       
   162     * Types of tab animations that need to be considered when drawing
       
   163     * the tab backgrounds.
       
   164     */
       
   165     enum TTabAnimationType
       
   166         {
       
   167         ENoAnimation, ///< No animation is used.
       
   168         ECycleToLeft, ///< Cycle left animation in use.
       
   169         ECycleToRight ///< Cycle right animation in use.
       
   170         };
       
   171 
       
   172     /**
       
   173     * Draws normal tab background from given parameters.
       
   174     * 
       
   175     * @param  aTabDrawMode     Mode with which the background is drawn.
       
   176     * @param  aLongTabs        Specifies whether or not long tabs are used.
       
   177     * @param  aNumberOfTabs    Number of tabs visible in the tab group (not
       
   178     *                          the total number of tabs in the tab group).
       
   179     * @param  aActiveTab       Active tab number in relation to the first tab
       
   180     *                          shown. This value can be from one to
       
   181     *                          @c aNumberOfTabs.
       
   182     * @param  aGc              Graphics context used in drawing the background.
       
   183     * @param  aLayout[in,out]  Tab group background layout used in drawing.
       
   184     *                          If the @c aLayout's @c iUse parameter is
       
   185     *                          @c EFalse, then the layout is calculated
       
   186     *                          to the @c aLayout. 
       
   187     * @param  aTabsHidden      Specifies where hidden tabs are drawn.
       
   188     * @param  aAnimation       Specifies the used animation.
       
   189     */
       
   190     void DrawTabGroupBackgroundL(
       
   191         TTabDrawMode aTabDrawMode,
       
   192         TBool aLongTabs,
       
   193         TInt aNumberOfTabs,
       
   194         TInt aActiveTab,
       
   195         CBitmapContext* aGc,
       
   196         SAknTabGroupBackgroundLayout& aLayout,
       
   197         TTabsHidden aTabsHidden,
       
   198         TTabAnimationType aAnimation = ENoAnimation ) const;
       
   199 
       
   200     /**
       
   201     * Draws narrow tab background from given parameters.
       
   202     * 
       
   203     * @param  aTabDrawMode     Mode with which the background is drawn.
       
   204     * @param  aLongTabs        Specifies whether or not long tabs are used.
       
   205     * @param  aNumberOfTabs    Number of tabs visible in the tab group (not
       
   206     *                          the total number of tabs in the tab group).
       
   207     * @param  aActiveTab       Active tab number in relation to the first tab
       
   208     *                          shown. This value can be from one to
       
   209     *                          @c aNumberOfTabs.
       
   210     * @param  aGc              Graphics context used in drawing the background.
       
   211     * @param  aLayout[in,out]  Tab group background layout used in drawing.
       
   212     *                          If the @c aLayout's @c iUse parameter is
       
   213     *                          @c EFalse, then the layout is calculated
       
   214     *                          to the @c aLayout. 
       
   215     */
       
   216     void DrawTabGroupNarrowBackgroundL(
       
   217         TTabDrawMode aTabDrawMode,
       
   218         TBool aLongTabs,
       
   219         TInt aNumberOfTabs,
       
   220         TInt aActiveTab,
       
   221         CBitmapContext* aGc,
       
   222         SAknTabGroupBackgroundLayout& aLayout ) const;
       
   223 
       
   224     /**
       
   225     * Background parts of a tab.
       
   226     */ 
       
   227     enum TTabPart
       
   228         {
       
   229         ELeft,
       
   230         EMiddle,
       
   231         ERight
       
   232         };
       
   233 
       
   234     /**
       
   235     * This function tests whether the given tab graphics was hit with a
       
   236     * pointer event or not. The result is determined using the mask graphics.
       
   237     *
       
   238     * @param  aTabComponent  Tab graphics component to test against,
       
   239     *                        this should be of type @c TTabPart.
       
   240     * @param  aTabGroupRect  Tab part's rectangle.
       
   241     * @param  aPoint         Pointer event's coordinates.
       
   242     * @param  aIsActiveTab   Whether the clicked tab is active or not.
       
   243     *
       
   244     * @return @c ETrue if the tab was hit, otherwise @c EFalse.
       
   245     */
       
   246     TBool TabClickedL( TInt aTabComponent,
       
   247                        const TRect& aTabGroupRect,
       
   248                        const TPoint& aPoint,
       
   249                        TBool aIsActiveTab );
       
   250     
       
   251     /**
       
   252     * Gets the whole tab rectangle in relation to the tab group container
       
   253     * by adding together the separate pieces of @c aLayout.
       
   254     */
       
   255     TRect TabRectFromLayout( const SAknTabLayout& aLayout );
       
   256     
       
   257     /**
       
   258     * Adjusts the tab part rectangles in the passed @c aLayout by the
       
   259     * specified x and y offsets. 
       
   260     * 
       
   261     * @param  aLayout[in,out]  Tab background layout to be adjusted.
       
   262     * @param  aXOffset         Horizontal value to move the rectangles for.
       
   263     * @param  aYOffset         Vertical value to move the rectangles for.
       
   264     */ 
       
   265     void AdjustTabLayoutRect( SAknTabLayout& aLayout, 
       
   266                               TInt aXOffset,
       
   267                               TInt aYOffset ) const;
       
   268 
       
   269 private:
       
   270 
       
   271 #if 0 //not used
       
   272     /**
       
   273     * This method draws tab group bitmap with given parameters.
       
   274     *
       
   275     * @param  aLongTabs      @c ETrue to draw long tabs.
       
   276     * @param  aNumberOfTabs  Number of tabs visible in the tab group.
       
   277     * @param  aActiveTab     Active tab index, allowed range from 1 to
       
   278     *                        @c aNumberOfTabs.
       
   279     *
       
   280     * @return  Struct which contains both the bitmap and the mask.
       
   281     *          Ownership is transferred to the caller.
       
   282     */
       
   283     CAknTabGroupGraphics::SAknTabGroupBackground CreateTabGroupBackgroundL(
       
   284         TBool aLongTabs,
       
   285         TInt aNumberOfTabs,
       
   286         TInt aActiveTab );
       
   287         
       
   288 #endif
       
   289     /**
       
   290     * C++ default constructor.
       
   291     */
       
   292     CAknTabGroupGraphics();
       
   293 
       
   294     /**
       
   295     * By default Symbian 2nd phase constructor is private.
       
   296     */
       
   297     void ConstructL();
       
   298 
       
   299     /**
       
   300     * Method to construct tab graphics from SVG.
       
   301     */
       
   302     void LoadTabGraphicsL();
       
   303 
       
   304     /**
       
   305     * Methods to extract normal layouts for tab group backgrounds
       
   306     */
       
   307     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout TwoTabBackground(
       
   308         TInt aActiveTab ) const;
       
   309 
       
   310     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout ThreeTabBackground(
       
   311         TInt aActiveTab ) const;
       
   312 
       
   313     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout FourTabBackground(
       
   314         TInt aActiveTab ) const;
       
   315 
       
   316     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout TwoLongTabBackground(
       
   317         TInt aActiveTab ) const;
       
   318 
       
   319     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout ThreeLongTabBackground(
       
   320         TInt aActiveTab ) const;
       
   321 
       
   322     /**
       
   323     * Methods to extract narrow layouts for tab group backgrounds.
       
   324     */
       
   325     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout
       
   326         TwoTabNarrowBackground( TInt aActiveTab ) const;
       
   327 
       
   328     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout
       
   329         ThreeTabNarrowBackground( TInt aActiveTab ) const;
       
   330 
       
   331     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout
       
   332         FourTabNarrowBackground( TInt aActiveTab ) const;
       
   333 
       
   334     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout
       
   335         TwoLongTabNarrowBackground( TInt aActiveTab ) const;
       
   336 
       
   337     CAknTabGroupGraphics::SAknTabGroupBackgroundLayout
       
   338         ThreeLongTabNarrowBackground( TInt aActiveTab ) const;
       
   339 
       
   340     /**
       
   341     * Methods to draw normal tab backgrounds.
       
   342     */
       
   343     void DrawTwoTabBackground( TTabDrawMode aDrawMode,
       
   344                                TInt aActiveTab,
       
   345                                CBitmapContext* aGc,
       
   346                                SAknTabGroupBackgroundLayout& aLayout ) const;
       
   347 
       
   348     void DrawThreeTabBackground( TTabDrawMode aDrawMode,
       
   349                                  TInt aActiveTab,
       
   350                                  CBitmapContext* aGc,
       
   351                                  SAknTabGroupBackgroundLayout& aLayout,
       
   352                                  TTabsHidden aTabsHidden,
       
   353                                  TTabAnimationType aAnimation = ENoAnimation ) const;
       
   354 
       
   355     void DrawFourTabBackground( TTabDrawMode aDrawMode,
       
   356                                 TInt aActiveTab,
       
   357                                 CBitmapContext* aGc,
       
   358                                 SAknTabGroupBackgroundLayout& aLayout ) const;
       
   359 
       
   360     void DrawTwoLongTabBackground(
       
   361         TTabDrawMode aDrawMode,
       
   362         TInt aActiveTab,
       
   363         CBitmapContext* aGc,
       
   364         SAknTabGroupBackgroundLayout& aLayout ) const;
       
   365 
       
   366     void DrawThreeLongTabBackground(
       
   367         TTabDrawMode aDrawMode,
       
   368         TInt aActiveTab,
       
   369         CBitmapContext* aGc,
       
   370         SAknTabGroupBackgroundLayout& aLayout ) const;
       
   371 
       
   372     /**
       
   373     * Methods to draw narrow tab backgrounds.
       
   374     */
       
   375     void DrawTwoTabNarrowBackground(
       
   376         TTabDrawMode aDrawMode,
       
   377         TInt aActiveTab,
       
   378         CBitmapContext* aGc,
       
   379         SAknTabGroupBackgroundLayout& aLayout ) const;
       
   380 
       
   381     void DrawThreeTabNarrowBackground(
       
   382         TTabDrawMode aDrawMode,
       
   383         TInt aActiveTab,
       
   384         CBitmapContext* aGc,
       
   385         SAknTabGroupBackgroundLayout& aLayout ) const;
       
   386 
       
   387     void DrawFourTabNarrowBackground(
       
   388         TTabDrawMode aDrawMode,
       
   389         TInt aActiveTab,
       
   390         CBitmapContext* aGc,
       
   391         SAknTabGroupBackgroundLayout& aLayout ) const;
       
   392 
       
   393     void DrawTwoLongTabNarrowBackground(
       
   394         TTabDrawMode aDrawMode,
       
   395         TInt aActiveTab,
       
   396         CBitmapContext* aGc,
       
   397         SAknTabGroupBackgroundLayout& aLayout ) const;
       
   398 
       
   399     void DrawThreeLongTabNarrowBackground(
       
   400         TTabDrawMode aDrawMode,
       
   401         TInt aActiveTab,
       
   402         CBitmapContext* aGc,
       
   403         SAknTabGroupBackgroundLayout& aLayout ) const;
       
   404 
       
   405     /**
       
   406     * Draws single tab graphics for an active tab.
       
   407     * 
       
   408     * @param  aDrawMode  Mode with which the background is drawn.
       
   409     * @param  aLeft      Rectangle of the left part of the tab.
       
   410     * @param  aMiddle    Rectangle of the middle part of the tab.
       
   411     * @param  aRight     Rectangle of the right part of the tab.
       
   412     * @param  aGc        Graphics context used in drawing.
       
   413     */
       
   414     void DrawActiveTab( TTabDrawMode aDrawMode,
       
   415                         TRect aLeft,
       
   416                         TRect aMiddle,
       
   417                         TRect aRight,
       
   418                         CBitmapContext* aGc ) const;
       
   419     
       
   420     /**
       
   421     * Draws single tab graphics for a passive tab.
       
   422     * 
       
   423     * @param  aDrawMode  Mode with which the background is drawn.
       
   424     * @param  aLeft      Rectangle of the left part of the tab.
       
   425     * @param  aMiddle    Rectangle of the middle part of the tab.
       
   426     * @param  aRight     Rectangle of the right part of the tab.
       
   427     * @param  aGc        Graphics context used in drawing.
       
   428     * @param  aFaded     Should the tab be drawn faded.
       
   429     */
       
   430     void DrawPassiveTab( TTabDrawMode aDrawMode,
       
   431                          TRect aLeft,
       
   432                          TRect aMiddle,
       
   433                          TRect aRight,
       
   434                          CBitmapContext* aGc,
       
   435                          TBool aFaded = EFalse ) const;
       
   436     
       
   437     /**
       
   438     * Draws single tab part graphics for a passive tab.
       
   439     * Used in drawing the hidden tab bits.
       
   440     * 
       
   441     * @param  aDrawMode  Mode with which the background is drawn.
       
   442     * @param  aTabPart   Part of the tab graphics to draw.
       
   443     * @param  aRect      Rectangle of the drawn part of the tab.
       
   444     * @param  aGc        Graphics context used in drawing.
       
   445     */
       
   446     void DrawPassiveTabBit( TTabDrawMode aDrawMode,
       
   447                             TTabPart aTabPart,
       
   448                             TRect aRect,
       
   449                             CBitmapContext* aGc ) const;
       
   450 
       
   451     /**
       
   452     * Helper methods to transform a layout line into a rectangle.
       
   453     */
       
   454     TRect RectFromLayout( TRect aParent,
       
   455                           TAknWindowComponentLayout aComponentLayout ) const;
       
   456 
       
   457     /**
       
   458     * Helper method to get the narrow tab container rect.
       
   459     */
       
   460     TRect NarrowParentRect() const;
       
   461 
       
   462 private: // Member data.
       
   463 
       
   464     CFbsBitmap*   iActiveTabLeft;
       
   465     CFbsBitmap*   iActiveTabLeftMask;
       
   466     CFbsBitmap*   iActiveTabMiddle;
       
   467     CFbsBitmap*   iActiveTabMiddleMask;
       
   468     CFbsBitmap*   iActiveTabRight;
       
   469     CFbsBitmap*   iActiveTabRightMask;
       
   470 
       
   471     CFbsBitmap*   iPassiveTabLeft;
       
   472     CFbsBitmap*   iPassiveTabLeftMask;
       
   473     CFbsBitmap*   iPassiveTabMiddle;
       
   474     CFbsBitmap*   iPassiveTabMiddleMask;
       
   475     CFbsBitmap*   iPassiveTabRight;
       
   476     CFbsBitmap*   iPassiveTabRightMask;
       
   477 
       
   478     TRect         iTabGroupBackgroundParent;
       
   479     TBool         iTabGroupBackgroundAvailable;
       
   480     };
       
   481 
       
   482 #endif // C_AKNTABGRPGRAPHICS_H
       
   483 
       
   484 // End of File