uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiSkin.h
changeset 0 15bf7259bb7c
child 7 88b23e2e82e1
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-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:   Defines CHuiSkin abstract base class for skins. Skins are a 
       
    15 *                collection resources forming custom graphical appearance.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __HUISKIN_H__
       
    22 #define __HUISKIN_H__
       
    23 
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <gdi.h>
       
    27 #include <uiacceltk/HuiTexture.h>
       
    28 #include <uiacceltk/huitextstylemanager.h>
       
    29 
       
    30 /* Forward declarations. */
       
    31 class CHuiEnv;
       
    32 class CHuiGc;
       
    33 //class THuiFont;
       
    34 
       
    35 /** Background type suggestions.
       
    36  * 
       
    37  * These enums suggest which sort of background is under the visual,
       
    38  * in order for it to be rendered in an appropriate colour.
       
    39  * A dark background means that the text will be rendered in white, and a
       
    40  * light background means that the text will be black.*/
       
    41 enum THuiBackgroundType
       
    42     {
       
    43     /** background beneath the font is light. */
       
    44     EHuiBackgroundTypeLight,
       
    45     
       
    46     /** background beneath the font is dark. */
       
    47     EHuiBackgroundTypeDark
       
    48     };
       
    49 
       
    50 /** Element of a skin. */
       
    51 enum THuiSkinElement
       
    52     {
       
    53     /** Soft key labels. */
       
    54     EHuiSkinElementSoftKeys
       
    55     };
       
    56 
       
    57 
       
    58 /** Location specifier for an element of the skin. */
       
    59 enum THuiSkinLocation
       
    60     {
       
    61     /** Location is not determined. */
       
    62     EHuiSkinLocationNone,
       
    63 
       
    64     /** Location is in the top. */
       
    65     EHuiSkinLocationTop,
       
    66 
       
    67     /** Location is on the right. */
       
    68     EHuiSkinLocationRight,
       
    69 
       
    70     /** Location is in the bottom. */
       
    71     EHuiSkinLocationBottom,
       
    72 
       
    73     /** Location is on the left. */
       
    74     EHuiSkinLocationLeft
       
    75     };
       
    76 
       
    77 
       
    78 /**
       
    79  * Skin (texture) Resources.
       
    80  */
       
    81 enum THuiSkinTextureResource
       
    82     {
       
    83     EHuiSkinBackgroundTexture,
       
    84     EHuiSkinShadowTexture,
       
    85     EHuiSkinGlyphShadowTexture,
       
    86     EHuiSkinLineTexture
       
    87     };
       
    88     
       
    89     
       
    90 /**
       
    91  * Orientations.
       
    92  */     
       
    93 enum THuiSkinOrientation
       
    94     {
       
    95     EHuiSkinOrientationPortrait,
       
    96     EHuiSkinOrientationLandscape    
       
    97     };
       
    98 
       
    99 
       
   100 /**
       
   101  * Skin defines a collection of textures, fonts, and layout resources forming
       
   102  * custom graphical appearance for a GUI that can be applied
       
   103  * in order to suit the different tastes of different users.
       
   104  *
       
   105  * CHuiSkin is an abstract base class for all skin implementations.
       
   106  *
       
   107  * @todo  It should be possible to define a skin for each display separately.
       
   108  *        The environment can still own the skins, but each display would
       
   109  *        know the skin it is using. This way off-screen displays can look
       
   110  *        different and use different DPI (e.g., different font sizes)
       
   111  *        than on-screen displays.
       
   112  */
       
   113 NONSHARABLE_CLASS(CHuiSkin) : public CBase, public MHuiTextureContentObserver
       
   114 	{
       
   115 public:
       
   116 
       
   117 	/* Constructors and destructor. */
       
   118 
       
   119     /**
       
   120      * Constructor.
       
   121      */
       
   122     CHuiSkin(CHuiEnv& aEnv);
       
   123 
       
   124     /**
       
   125      * Second-phase constructor for skin implementations. Note that the
       
   126      * texture manager is not available when this is called, which means
       
   127      * textures and fonts cannot be loaded during the execution of this
       
   128      * method.
       
   129      */
       
   130     virtual void ConstructL() = 0;
       
   131 
       
   132 	/**
       
   133 	 * Destructor.
       
   134 	 */
       
   135 	~CHuiSkin();
       
   136 
       
   137 
       
   138 	/* Methods. */
       
   139 
       
   140 	/**
       
   141 	 * Returns the environment of the skin.
       
   142 	 */
       
   143 	inline CHuiEnv& Env()
       
   144 	    {
       
   145 	    return iEnv;
       
   146 	    }
       
   147 
       
   148     /**
       
   149      * Determines the orientation of the skin. Controls may use this to adapt 
       
   150      * their content to a specific layout orientation.
       
   151      *
       
   152      * @return  Orientation of the skin.
       
   153      */
       
   154     IMPORT_C virtual THuiSkinOrientation Orientation() const;     
       
   155 
       
   156 	/**
       
   157 	 * Determines the preferred location for an element of the skin.
       
   158 	 *
       
   159 	 * @param aElement  Element whose location to determine.
       
   160 	 *
       
   161 	 * @return Location specifier.
       
   162 	 */
       
   163 	IMPORT_C virtual THuiSkinLocation Location(THuiSkinElement aElement);
       
   164 
       
   165 	/**
       
   166 	 * Called to notify the skin that there has been a change in the display
       
   167 	 * size. This will make the skin do things like determine new font sizes.
       
   168 	 * The application should call this manually from the AppUi class.
       
   169 	 */
       
   170 	IMPORT_C virtual void NotifyDisplaySizeChangedL();
       
   171 
       
   172 	/**
       
   173 	 * Makes a graphics context current.
       
   174 	 *
       
   175 	 * @param aGc  Graphics context.
       
   176 	 */
       
   177 	IMPORT_C virtual void SetContext(CHuiGc& aGc);
       
   178 
       
   179 	/**
       
   180 	 * Returns the current graphics context.
       
   181 	 *
       
   182 	 * @return  Graphics context.
       
   183 	 */
       
   184 	IMPORT_C virtual CHuiGc& Context() const;
       
   185 
       
   186     /**
       
   187      * Returns the text color to be used with a text style on a certain
       
   188      * kind of background.
       
   189      *
       
   190      * @param aStyle           Text style.
       
   191      * @param aBackgroundType  Type of background on which text is over.
       
   192      */
       
   193     virtual TRgb StyleTextColor(THuiPreconfiguredTextStyle aStyle,
       
   194                                 THuiBackgroundType aBackgroundType) const = 0;
       
   195 
       
   196 	/**
       
   197 	 * Returns a texture corresponding the requested skin texture resource.
       
   198      *
       
   199      * If the defined texture was not yet created the function will try to
       
   200 	 * create it and leaves if creation fails.
       
   201 	 *
       
   202 	 * @param aSkinTextureResource Enum of the texture to be created.
       
   203      * @see THuiSkinTextureResource.
       
   204      * @see ReleaseTexture().
       
   205 	 * @return Reference to the skin-owned texture object.
       
   206      * @leave KErrNotSupported if invalid skin texture resource enum is provided.
       
   207 	 */
       
   208 	IMPORT_C virtual const CHuiTexture& TextureL(TInt aSkinTextureResource);
       
   209 	
       
   210 	/**
       
   211 	 * Explicit way for releasing textures from memory that are owned by this
       
   212 	 * skin. TextureL recreates the released texture if called after this.
       
   213 	 * This allows application developers to reduce amount of used texture memory on demand.
       
   214 	 *
       
   215 	 * @param aSkinTextureResource Enum of the texture to be released.
       
   216 	 * @see THuiSkinTextureResource.
       
   217 	 * @see TextureL().
       
   218 	 */
       
   219 	IMPORT_C virtual void ReleaseTexture(TInt aSkinTextureResource);
       
   220 
       
   221     /**
       
   222      * Returns a texture corresponding the requested skin texture resource.
       
   223      *
       
   224      * If the defined texture was not yet created the function will try to
       
   225      * create it and returns an error value if creation fails. If texture
       
   226      * cannot be created a blank texture is provided. Texture is passed
       
   227      * in the output parameter.
       
   228      *
       
   229      * @param aSkinTextureResource Enum of the texture to be created.
       
   230      * @see THuiSkinTextureResource.
       
   231      *
       
   232 	 * @param aOutTexture Output parameter: Reference to a texture pointer
       
   233      * where the requested texture will be stored. If texture creation fails
       
   234      * a blank texture reference is assigned to this pointer, thus there should
       
   235      * never be a situation where texture pointer is NULL or invalid.
       
   236      *
       
   237 	 * @return Error code indicating whether the texture was acquired
       
   238      * succesfully or not. KErrNone if everything went ok. KErrNoMemory if
       
   239      * allocation of the texture failed. KErrNotSupported if invalid skin
       
   240      * texture id is provided.
       
   241 	 */
       
   242     IMPORT_C virtual TInt GetTexture(TInt aSkinTextureResource,
       
   243                                      const CHuiTexture*& aOutTexture);
       
   244                                      
       
   245                                      
       
   246 public:
       
   247 
       
   248     /* Implementation of MHuiTextureContentObserver. */
       
   249     
       
   250     IMPORT_C void TextureContentUploaded(CHuiTexture& aTexture);
       
   251 
       
   252     IMPORT_C void TextureContentReleased(CHuiTexture& aTexture);
       
   253     
       
   254     IMPORT_C void RestoreTextureContentL(CHuiTexture& aTexture);
       
   255 
       
   256 
       
   257 protected:
       
   258 
       
   259     virtual void SkinExtension(const TUid& aExtensionUid, TAny** aExtensionParameters);
       
   260 
       
   261 private:
       
   262 
       
   263     /* Private methods. */
       
   264 
       
   265 	/**
       
   266 	 * Returns a texture corresponding the requested skin texture resource.
       
   267      *
       
   268      * If the defined texture was not yet created the function will try to
       
   269 	 * create it and leaves if creation fails.
       
   270 	 *
       
   271 	 * @param aSkinTextureResource Enum of the texture to be created.
       
   272 	 * @param aForcedPrepare Content of texture always recreated.
       
   273 	 *
       
   274 	 *
       
   275      * @see THuiSkinTextureResource.
       
   276      * @see ReleaseTexture().
       
   277 	 * @return Reference to the skin-owned texture object.
       
   278      * @leave KErrNotSupported if invalid skin texture resource enum is provided.
       
   279 	 */
       
   280     const CHuiTexture& TextureL(TInt aSkinTextureId, TBool aForcedPrepare);
       
   281 
       
   282     /**
       
   283      * Prepares a shadow texture
       
   284      */
       
   285     void PrepareShadowTextureL(CHuiTexture& aTexture);
       
   286 
       
   287     /**
       
   288      * Prepares a glyph shadow texture
       
   289      */
       
   290     void PrepareGlyphShadowTextureL(CHuiTexture& aTexture);
       
   291 
       
   292     /**
       
   293      * Prepares a line texture
       
   294      */
       
   295     void PrepareLineTextureL(CHuiTexture& aTexture);
       
   296 
       
   297 
       
   298 private:
       
   299 
       
   300     /** Environment. */
       
   301     CHuiEnv& iEnv;
       
   302 
       
   303     /** Current graphics context. */
       
   304     CHuiGc* iGc;
       
   305 
       
   306     /** Texture used for drawing shadows. */
       
   307     CHuiTexture* iShadowTexture;
       
   308 
       
   309     /** Texture used for soft lines. */
       
   310     CHuiTexture* iLineTexture;
       
   311 
       
   312     /** Texture used for text glyph shadows (managed). */
       
   313     CHuiTexture* iGlyphShadowTexture;
       
   314 
       
   315 	};
       
   316 
       
   317 #endif  // __HUISKIN_H__