00001 /* 00002 * ============================================================================== 00003 * Name : AknIconUtils.h 00004 * Part of : AknIcon 00005 * Interface : AknIcon 00006 * Description : Utility functions related to scalable icons. 00007 * 00008 * Version : 1 00009 * 00010 * Copyright (c) 2002 Nokia Corporation. 00011 * This material, including documentation and any related 00012 * computer programs, is protected by copyright controlled by 00013 * Nokia Corporation. All rights are reserved. Copying, 00014 * including reproducing, storing, adapting or translating, any 00015 * or all of this material requires the prior written consent of 00016 * Nokia Corporation. This material also contains confidential 00017 * information which may not be disclosed to others without the 00018 * prior written consent of Nokia Corporation. 00019 * ============================================================================== 00020 */ 00021 00022 00023 #ifndef AKN_ICON_UTILS_H 00024 #define AKN_ICON_UTILS_H 00025 00026 // INCLUDES 00027 #include <e32std.h> 00028 #include <gdi.h> 00029 00030 // FORWARD DECLARATIONS 00031 class CFbsBitmap; 00032 class MAknIconObserver; 00033 00034 // ENUMERATIONS 00035 enum TScaleMode 00036 { 00037 /* 00038 * Scales the icon to the maximum size that fits in the given size, 00039 * whilst preserving the aspect ratio of the icon. The sizes of the resulting 00040 * bitmaps are exactly of the given size. If the aspect ratio of 00041 * the given size differs from the aspect ratio of the icon, 00042 * the resulting bitmaps will contain an unused area. 00043 */ 00044 EAspectRatioPreserved = 0, 00045 00046 /* 00047 * Scales the icon to the maximum size that fits in the given size, 00048 * whilst preserving the aspect ratio of the icon. The resulting bitmaps 00049 * are resized so that any unused portion of the given size is not 00050 * present in them. 00051 * 00052 * This mode should be used when only the height or the width of the icon 00053 * is known and the other should be based on the aspect ratio of the icon. 00054 * The unknown dimension should be defined high enough (e.g. KMaxTInt) so 00055 * that it does not limit the scaling based on the aspect ratio of the icon. 00056 */ 00057 EAspectRatioPreservedAndUnusedSpaceRemoved = 1, 00058 00059 /* 00060 * Scales the icon exactly to the given size. Does not preserve the aspect 00061 * ratio of the icon. 00062 */ 00063 EAspectRatioNotPreserved = 2, 00064 00065 #start_since SINCE_3_1_SDK 00066 00076 EAspectRatioPreservedSlice = 3 00077 #end_since SINCE_3_1_SDK 00078 }; 00079 00080 // CLASS DECLARATIONS 00081 00085 class TAknContentDimensions 00086 { 00087 public: 00088 00092 inline TAknContentDimensions(); 00093 00100 inline TAknContentDimensions(TReal32 aWidth, TReal32 aHeight); 00101 00108 inline void SetDimensions(TReal32 aWidth, TReal32 aHeight); 00109 00116 inline void SetDimensions(const TSize& aDimensions); 00117 00118 public: 00119 00121 TReal32 iWidth; 00122 00124 TReal32 iHeight; 00125 }; 00126 00130 NONSHARABLE_CLASS(CAknIcon) : public CBase 00131 { 00132 public: 00133 00141 IMPORT_C static CAknIcon* NewL(); 00142 00146 ~CAknIcon(); 00147 00148 public: 00149 00155 IMPORT_C CFbsBitmap* Bitmap() const; 00156 00162 IMPORT_C CFbsBitmap* Mask() const; 00163 00169 IMPORT_C void SetBitmap( CFbsBitmap* aBitmap ); 00170 00176 IMPORT_C void SetMask( CFbsBitmap* aMask ); 00177 00178 private: 00179 00183 inline CAknIcon() {} 00184 00185 private: 00186 00187 CFbsBitmap* iBitmap; // owned 00188 CFbsBitmap* iMask; // owned 00189 }; 00190 00201 class MAknIconFileProvider 00202 { 00203 public: 00204 00205 enum TIconFileType 00206 { 00207 EMbmFile = 0, 00208 EMifFile = 1 00209 }; 00210 00211 public: 00212 00216 virtual ~MAknIconFileProvider() {} 00217 00233 virtual void RetrieveIconFileHandleL( 00234 RFile& aFile, const TIconFileType aType ) = 0; 00235 00248 virtual void Finished() = 0; 00249 }; 00250 00262 class AknIconUtils 00263 { 00264 public: 00265 00284 IMPORT_C static void CreateIconL( 00285 CFbsBitmap*& aBitmap, 00286 CFbsBitmap*& aMask, 00287 const TDesC& aFileName, 00288 TInt aBitmapId, 00289 TInt aMaskId ); 00290 00308 IMPORT_C static void CreateIconLC( 00309 CFbsBitmap*& aBitmap, 00310 CFbsBitmap*& aMask, 00311 const TDesC& aFileName, 00312 TInt aBitmapId, 00313 TInt aMaskId ); 00314 00328 IMPORT_C static CFbsBitmap* CreateIconL( 00329 const TDesC& aFileName, 00330 TInt aBitmapId ); 00331 00352 IMPORT_C static void CreateIconL( 00353 CFbsBitmap*& aBitmap, 00354 CFbsBitmap*& aMask, 00355 MAknIconFileProvider& aFileProvider, 00356 TInt aBitmapId, 00357 TInt aMaskId ); 00358 00378 IMPORT_C static void CreateIconLC( 00379 CFbsBitmap*& aBitmap, 00380 CFbsBitmap*& aMask, 00381 MAknIconFileProvider& aFileProvider, 00382 TInt aBitmapId, 00383 TInt aMaskId ); 00384 00400 IMPORT_C static CFbsBitmap* CreateIconL( 00401 MAknIconFileProvider& aFileProvider, 00402 TInt aBitmapId ); 00403 00426 IMPORT_C static void PreserveIconData( CFbsBitmap* aBitmap ); 00427 00436 IMPORT_C static void DestroyIconData( CFbsBitmap* aBitmap ); 00437 00453 IMPORT_C static TInt SetSize( 00454 CFbsBitmap* aBitmap, 00455 const TSize& aSize, 00456 TScaleMode aMode = EAspectRatioPreserved ); 00457 00474 IMPORT_C static TInt SetSizeAndRotation( 00475 CFbsBitmap* aBitmap, 00476 const TSize& aSize, 00477 TScaleMode aMode, 00478 TInt aAngle ); 00479 00491 IMPORT_C static void SetObserver( CFbsBitmap* aBitmap, MAknIconObserver* aObserver ); 00492 00499 IMPORT_C static const TDesC& AvkonIconFileName(); 00500 00514 IMPORT_C static void ValidateLogicalAppIconId( 00515 const TDesC& aIconFileName, 00516 TInt& aBitmapId, 00517 TInt& aMaskId ); 00518 00528 IMPORT_C static TBool IsMifFile( const TDesC& aFileName ); 00529 00540 IMPORT_C static TBool IsMifIcon( const CFbsBitmap* aBitmap ); 00541 00558 IMPORT_C static TInt GetContentDimensions( 00559 CFbsBitmap* aBitmap, 00560 TSize& aContentDimensions ); 00561 00577 IMPORT_C static TInt GetContentDimensions( 00578 CFbsBitmap* aBitmap, 00579 TAknContentDimensions& aContentDimensions ); 00580 00581 00613 IMPORT_C static CAknIcon* CreateIconL( CAknIcon* aSourceIcon ); 00614 00630 IMPORT_C static CFbsBitmap* CreateIconL( CFbsBitmap* aSourceBitmap ); 00631 00642 IMPORT_C static void SetIconColor( CFbsBitmap* aBitmap, const TRgb aColor ); 00643 00644 #start_since SINCE_3_1_SDK 00645 00668 IMPORT_C static void ExcludeFromCache( CFbsBitmap* aBitmap ); 00669 #end_since SINCE_3_1_SDK 00670 00671 #start_since SINCE_3_1_SDK 00672 00684 IMPORT_C static void DisableCompression( CFbsBitmap* aBitmap ); 00685 #end_since SINCE_3_1_SDK 00686 00691 static void ScaleBitmapL( 00692 const TRect& aTrgRect, 00693 CFbsBitmap* aTrgBitmap, 00694 CFbsBitmap* aSrcBitmap ); 00695 00714 static void RotateAndScaleBitmapL( 00715 const TRect& aTrgRect, 00716 CFbsBitmap* aTrgBitmap, 00717 CFbsBitmap* aSrcBitmap, 00718 TInt aAngle ); 00719 00720 private: 00721 00730 static TBool IsAknBitmap( const CFbsBitmap* aBitmap ); 00731 00735 static void CreateIconLC( 00736 CFbsBitmap*& aBitmap, 00737 CFbsBitmap*& aMask, 00738 const TDesC& aFileName, 00739 TInt aBitmapId, 00740 TInt aMaskId, 00741 MAknIconFileProvider* aFileProvider ); 00742 00747 static void CreateIconLC( 00748 CFbsBitmap*& aBitmap, 00749 CFbsBitmap*& aMask, 00750 const TDesC& aFileName, 00751 TInt aBitmapId, 00752 TInt aMaskId, 00753 RFile& aFile ); 00754 00755 private: 00756 00757 AknIconUtils(); 00758 }; 00759 00760 #include "AknIconUtils.inl" 00761 // AKN_ICON_UTILS_H 00762 #endif 00763 00764 // End of File