resourcepool/inc/alfresourcepoolimpl.h
branchRCL_3
changeset 19 4ea6f81c838a
parent 17 514d98f21c43
child 20 0e9bb658ef58
equal deleted inserted replaced
17:514d98f21c43 19:4ea6f81c838a
     1 /*
       
     2 * Copyright (c) 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:  Implementation of the resource pool
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef ALF_RESOURCEPOOL_IMPL_H
       
    20 #define ALF_RESOURCEPOOL_IMPL_H
       
    21 
       
    22 #include <alf/alfimage.h>
       
    23 #include <alf/alfmetric.h>
       
    24 #include <alf/alfimageloaderutil.h>
       
    25 #include <osn/ustring.h>
       
    26 #include <osn/alfptrvector.h>
       
    27 #include <vector>
       
    28 
       
    29 #include "alf/alfresourcepool.h"
       
    30 
       
    31 class CAlfTextureManager;
       
    32 
       
    33 
       
    34 
       
    35 namespace Alf 
       
    36 {
       
    37 //Forward declaration
       
    38 
       
    39 
       
    40 using namespace osncore;
       
    41 
       
    42 /**
       
    43  *  ?one_line_short_description
       
    44  *  ?more_complete_description
       
    45  *
       
    46  *  @code
       
    47  *   ?good_class_usage_example(s)
       
    48  *  @endcode
       
    49  *
       
    50  *  @lib ?library
       
    51  *  @since S60 ?S60_version *** for example, S60 v3.0
       
    52  */
       
    53 class ResourcePoolImpl
       
    54     {
       
    55 private:
       
    56 
       
    57     enum ImageResourceType
       
    58         {
       
    59         imageResourceTypeSkin,
       
    60         imageResourceTypeFileSVG,
       
    61         imageResourceTypeFileOther
       
    62         };
       
    63         
       
    64     struct ResourceInstanceData
       
    65         {
       
    66         ResourceInstanceData(): mTextureId(0), mImageLoaderUtil(0), mAutoSizeTexture(false) {}
       
    67         ~ResourceInstanceData() { delete mImageLoaderUtil; }
       
    68         
       
    69         int mTextureId;
       
    70         CAlfAutoSizeImageLoaderUtil* mImageLoaderUtil;
       
    71         bool mAutoSizeTexture;
       
    72         };
       
    73 
       
    74     struct ImageResource
       
    75         {
       
    76         ImageResource();
       
    77         virtual ~ImageResource();
       
    78         
       
    79         Utf8* mTag;
       
    80         ImageResourceType mType;
       
    81         AlfPtrVector<ResourceInstanceData> mLoadedTextures;
       
    82         TAlfXYMetric mInitialSizeHint;
       
    83         ResourcePool::AspectRatio mAspectRatio;
       
    84         int mReferenceCount;
       
    85         TAlfTextureFlags mFlag;
       
    86         };
       
    87         
       
    88     struct SkinImageResource : public ImageResource
       
    89         {
       
    90         int mSkinIdMajor;
       
    91         int mSkinIdMinor;
       
    92         UString mFallBackFileName;
       
    93         int mFallBackIndex;
       
    94         int mFallBackMaskIndex;
       
    95         };
       
    96         
       
    97     struct FileImageResource : public ImageResource
       
    98         {
       
    99         UString mFileName;
       
   100         };
       
   101 public:
       
   102 
       
   103     ResourcePoolImpl( 
       
   104         CAlfTextureManager& aTextureManager ,
       
   105         ResourcePool* aParentPool );
       
   106     ~ResourcePoolImpl();
       
   107 
       
   108     void createLogicalImageResource( const Utf8* aTag );
       
   109     
       
   110     void createThemeImageResource( 
       
   111         const Utf8* aTag,
       
   112         const UString& aThemeDefinition );
       
   113     
       
   114     void createFileImageResource( 
       
   115         const Utf8* aTag,
       
   116         const UString& aFileName ,TAlfTextureFlags aFlag);
       
   117      
       
   118     void deleteImageResource( const Utf8* aTag );
       
   119     
       
   120     bool hasImageResource( const Utf8* aTag ) const;
       
   121       
       
   122     void setInitialSize( 
       
   123         const Utf8* aTag, 
       
   124         const TAlfXYMetric& aInitialSizeHint );
       
   125         
       
   126     void setAspectRatio( 
       
   127         const Utf8* aTag, 
       
   128         ResourcePool::AspectRatio aAspectRatio );
       
   129 
       
   130     TAlfImage getImageResource( const Utf8* aTag );
       
   131 
       
   132     TAlfImage getImageResource( 
       
   133         const Utf8* aTag, 
       
   134         const TAlfXYMetric& aSizeHint );
       
   135 
       
   136 private:
       
   137     ImageResource* findResource( const Utf8* aTag ) const;
       
   138     int findResourceIndex( const Utf8* aTag ) const;
       
   139     void DetermineSkinInstanceL( const Utf8* aTag, TAknsItemID& aSkinItemID ) const;
       
   140     TSize determineSizeInPixels( const TAlfXYMetric& aSize );
       
   141     void determineSkinId( const UString& aNumberString, int& aSkinItem );
       
   142     TAlfImage CreateSkinImageResourceL(SkinImageResource& aSkinImageResource, const TAlfXYMetric& aSizeHint);
       
   143     TAlfImage CreateFileImageResourceL(FileImageResource& aFileImageResource, const TAlfXYMetric& aSizeHint ,TAlfTextureFlags aFlag);
       
   144     TAlfImage CreateSVGImageResourceL(FileImageResource& aSVGImageResource, const TAlfXYMetric& aSizeHint);
       
   145     
       
   146     static bool areSizesCloseEnough( const TSize& aSize1, const TSize& aSize2 );
       
   147 private:
       
   148 
       
   149     CAlfTextureManager& mTextureManager;
       
   150     ResourcePool* mParentPool;
       
   151 
       
   152     AlfPtrVector<ImageResource> mResources; // use hash table instead?
       
   153     };
       
   154     
       
   155 } // namespace Alf
       
   156 
       
   157 #endif // ALF_RESOURCEPOOL_IMPL_H