williamr@2: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #if !defined(__GULUTIL_H__) williamr@2: #define __GULUTIL_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TUint KTextUtilClipEndChar=0x2026; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TUint KColumnListSeparator='\t'; williamr@2: williamr@2: class CFont; williamr@2: class CFbsFont; williamr@2: class CWsScreenDevice; williamr@2: class TResourceReader; williamr@2: class CColorArray; williamr@2: class CGraphicsDevice; williamr@2: class RWsSession; williamr@2: class CColorList; williamr@2: template class CArrayFix; williamr@2: williamr@2: williamr@2: class TMargins8 williamr@2: /** A set of margins stored as 8 bit integer values which can represent williamr@2: either pixels or twips between -128 and +127. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public : williamr@2: /** Left margin in twips or pixels. */ williamr@2: TInt8 iLeft; williamr@2: /** Right margin in twips or pixels. */ williamr@2: TInt8 iRight; williamr@2: /** Top margin in twips or pixels. */ williamr@2: TInt8 iTop; williamr@2: /** Bottom margin in twips or pixels. */ williamr@2: TInt8 iBottom; williamr@2: public : williamr@2: IMPORT_C TMargins8(); williamr@2: IMPORT_C TMargins8(TInt8 aLeft, TInt8 aTop, TInt8 aRight, TInt8 aBottom); williamr@2: IMPORT_C void SetAllValuesTo(TInt aCommonValue); williamr@2: IMPORT_C TRect InnerRect(const TRect& aOuterRect) const; williamr@2: IMPORT_C TRect OuterRect(const TRect& aInnerRect) const; williamr@2: IMPORT_C TSize SizeDelta() const; williamr@2: }; williamr@2: williamr@2: williamr@2: class DrawUtils williamr@2: /** Provides static functions for drawing text in a rectangle. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C static void DrawText(CGraphicsContext& aGc,const TDesC& aString,const TRect& aBox,TInt aBaseLineOffset, williamr@2: CGraphicsContext::TTextAlign aHoriz,TInt aMargin,const CFont* aFont); williamr@2: IMPORT_C static void DrawBetweenRects(CGraphicsContext& aGc,const TRect& aOuterRect,const TRect& aInnerRect); williamr@2: IMPORT_C static void ClearBetweenRects(CGraphicsContext& aGc,const TRect& aOuterRect,const TRect& aInnerRect); williamr@2: }; williamr@2: williamr@2: williamr@2: class TextUtils williamr@2: /** Provides static functions for truncating and aligning text strings. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C static void ClipToFit(TDes& aBuffer,const CFont& aFont,TInt aMaxWidthInPixels,TChar aAlternativeEnd=KTextUtilClipEndChar); williamr@2: IMPORT_C static TInt ColumnText(TPtrC& aColumnText,TInt aColumn,const TDesC* aSourceText,TChar aColumnSeparator=KColumnListSeparator); williamr@2: IMPORT_C static void TruncateToNumChars(TDes& aBuffer, TInt numChars); williamr@2: }; williamr@2: williamr@2: class FontUtils williamr@2: /** Provides static functions for getting information about the fonts supported by a graphics williamr@2: device. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C static void GetAvailableFontsL(const CGraphicsDevice& aDevice,CDesCArray& aFontNameList, williamr@2: TInt aFonts=EGulNoSymbolFonts); williamr@2: IMPORT_C static TInt TypefaceAttributes(const CGraphicsDevice& aDevice,const TDesC& aTypefaceName); williamr@2: IMPORT_C static TInt GetAvailableHeightsInTwipsL(const CGraphicsDevice& aDevice,const TDesC& aTypefaceName, williamr@2: CArrayFix& aHeightList); williamr@2: IMPORT_C static TInt GetAvailableHeightsInTwipsAndPointsL(const CGraphicsDevice& aDevice,const TDesC& aTypefaceName, williamr@2: CArrayFix& aTwipsList,CDesCArray& aPointsList); williamr@2: IMPORT_C static TInt PointsFromTwips(TInt aTwips); williamr@2: IMPORT_C static TInt TwipsFromPoints(TInt aPoints); williamr@2: IMPORT_C static TInt TwipsFromPoints(const TDesC& aPoints); williamr@2: IMPORT_C static TInt IndexOfNearestHeight(CArrayFix& aTwipsList,TInt aHeight); williamr@2: }; williamr@2: williamr@2: williamr@2: class ResourceUtils williamr@2: /** Provides static functions for resource reading. williamr@2: williamr@2: All functions use pre-initialised resource reader objects to read information williamr@2: from resource files. williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: @see CCoeEnv::CreateResourceReaderLC() */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C static CFbsFont* CreateNamedScreenFontL(TResourceReader& aResourceReader,CWsScreenDevice& aScreenDevice); williamr@2: IMPORT_C static CFbsFont* CreateNamedScreenFontInPixelsL(TResourceReader& aResourceReader,CWsScreenDevice& aScreenDevice); williamr@2: IMPORT_C static CFbsFont* CreateScreenFontL(TResourceReader& aResourceReader,CWsScreenDevice& aScreenDevice); williamr@2: inline static TInt8 ReadTInt8L(TResourceReader& aReader); williamr@2: inline static TInt16 ReadTInt16L(TResourceReader& aReader); williamr@2: inline static TInt32 ReadTInt32L(TResourceReader& aReader); williamr@2: IMPORT_C static void PopulateColorArrayL(CColorArray& aColors,TResourceReader& aReader); williamr@2: private: williamr@2: enum TResourceTypeInt { EResourceInt8,EResourceInt16,EResourceInt32 }; williamr@2: private: williamr@2: IMPORT_C static TInt32 ReadResourceIntL(TResourceReader& aReader,TResourceTypeInt aSize); williamr@2: }; williamr@2: williamr@2: class ColorUtils williamr@2: /** Provides static functions for manipulating colours. williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: @see TDisplayMode */ williamr@2: { williamr@2: public: williamr@2: /** The orientation of a bitmap. */ williamr@2: enum TBitmapOrientation williamr@2: { williamr@2: /** The bitmap is vertical. */ williamr@2: EBitmapOrientationVertical, williamr@2: /** The bitmap is horizontal. */ williamr@2: EBitmapOrientationHorizontal williamr@2: }; williamr@2: public: williamr@2: IMPORT_C static TRgb ColorAdjust(TRgb aColor,TInt aPercentage); williamr@2: IMPORT_C static void CreateGradientBitmapL(CFbsBitmap& aBitmap, const RWsSession& aWs, TInt aBreadth, williamr@2: TBitmapOrientation aOrientation, TRgb aStartColor, TRgb aEndColor); williamr@2: IMPORT_C static CColorList* CreateSystemColorListL(RFs& aFs); williamr@2: IMPORT_C static CColorList* CreateSystemColorListL(RFs& aFs,const CColorList& aColorList); williamr@2: IMPORT_C static void UpdateSystemColorListL(RFs& aFs,CColorList& aColorList); williamr@2: IMPORT_C static void GetRgbDerivedBorderColors(TGulBorder::TColors& aBorderColors,TRgb aBackgroundColor,TDisplayMode aMode); williamr@2: IMPORT_C static TRgb RgbDarkerColor(TRgb aRgb,TDisplayMode aMode); williamr@2: IMPORT_C static TRgb RgbMidDarkerColor(TRgb aRgb,TDisplayMode aMode); williamr@2: IMPORT_C static TRgb RgbLighterColor(TRgb aRgb,TDisplayMode aMode); williamr@2: }; williamr@2: williamr@2: williamr@2: class TFindWidthOfWidestTextItem williamr@2: /** Finds the width in pixels of the widest item in a range of indexed text items. williamr@2: williamr@2: This is the base class for several classes used to get the maximum width for williamr@2: date and time components. williamr@2: williamr@2: Derived classes should override the pure virtual methods to supply an appropriate williamr@2: range of items. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: protected: williamr@2: /** Default constructor. */ williamr@2: inline TFindWidthOfWidestTextItem() {} williamr@2: public: williamr@2: IMPORT_C TInt MaximumWidthInPixels(const CFont& aFont) const; williamr@2: private: williamr@2: /** Gets the first and last index in the range of items. williamr@2: williamr@2: @param aFirstIndex On return, the first index. williamr@2: @param aLastIndex On return, the last index. williamr@2: @publishedAll williamr@2: @released */ williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const=0; williamr@2: /** Gets the text item at the specfied index. williamr@2: williamr@2: @param aText On return, the indexed text item. williamr@2: @param aIndex The index. williamr@2: @publishedAll williamr@2: @released */ williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const=0; williamr@2: }; williamr@2: williamr@2: williamr@2: class TFindWidthOfWidestDigit : public TFindWidthOfWidestTextItem williamr@2: /** Finds the width in pixels of the widest digit, when displayed in a specified williamr@2: font. williamr@2: williamr@2: After construction, call MaximumWidthInPixels(), defined in the base class, williamr@2: specifying the font. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TFindWidthOfWidestDigit(); williamr@2: private: williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const; williamr@2: }; williamr@2: williamr@2: class TFindWidthOfWidestDigitType : public TFindWidthOfWidestTextItem williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TFindWidthOfWidestDigitType(TDigitType aDigitType); williamr@2: private: williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const; williamr@2: williamr@2: private: williamr@2: TDigitType iDigitType; williamr@2: }; williamr@2: williamr@2: class TFindWidthOfWidestAmPmName : public TFindWidthOfWidestTextItem williamr@2: /** Finds the width in pixels of the widest Am or Pm text, when displayed in a specified williamr@2: font. williamr@2: williamr@2: After construction, call MaximumWidthInPixels(), defined in the base class, williamr@2: specifying the font. williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: @see TAmPmName */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TFindWidthOfWidestAmPmName(); williamr@2: private: williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const; williamr@2: }; williamr@2: williamr@2: class TFindWidthOfWidestAbbreviatedDayName : public TFindWidthOfWidestTextItem williamr@2: /** Finds the width in pixels of the widest abbreviated day name (for instance Mon, Tue) williamr@2: when displayed in a specified font. williamr@2: williamr@2: After construction, call MaximumWidthInPixels(), defined in the base class, williamr@2: specifying the font. williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: @see TDayNameAbb */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TFindWidthOfWidestAbbreviatedDayName(); williamr@2: private: williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const; williamr@2: }; williamr@2: williamr@2: williamr@2: class TFindWidthOfWidestDayName : public TFindWidthOfWidestTextItem williamr@2: /** Finds the width in pixels of the widest day name, when displayed in a specified williamr@2: font. williamr@2: williamr@2: After construction, call MaximumWidthInPixels(), defined in the base class, williamr@2: specifying the font. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TFindWidthOfWidestDayName(); williamr@2: private: williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const; williamr@2: }; williamr@2: williamr@2: williamr@2: class TFindWidthOfWidestAbbreviatedMonthName : public TFindWidthOfWidestTextItem williamr@2: /** Finds the width in pixels of the widest abbreviated month name (for instance Jan, Feb), williamr@2: when displayed in a specified font. williamr@2: williamr@2: After construction, call MaximumWidthInPixels(), defined in the base class, williamr@2: specifying the font. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TFindWidthOfWidestAbbreviatedMonthName(); williamr@2: private: williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const; williamr@2: }; williamr@2: williamr@2: class TFindWidthOfWidestMonthName : public TFindWidthOfWidestTextItem williamr@2: /** Finds the width in pixels of the widest month name, when displayed in a specified williamr@2: font. williamr@2: williamr@2: After construction, call MaximumWidthInPixels(), defined in the base class, williamr@2: specifying the font. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TFindWidthOfWidestMonthName(); williamr@2: private: williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const; williamr@2: }; williamr@2: williamr@2: class TFindWidthOfWidestDateSuffix : public TFindWidthOfWidestTextItem williamr@2: /** Finds the width in pixels of the widest date suffix (for instance st, nd), williamr@2: when displayed in a specified font. williamr@2: williamr@2: After construction, call MaximumWidthInPixels(), defined in the base class, williamr@2: specifying the font. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TFindWidthOfWidestDateSuffix(); williamr@2: private: williamr@2: virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; williamr@2: virtual void GetTextItem(TDes& aText, TInt aIndex) const; williamr@2: }; williamr@2: williamr@2: // class ResourceUtils williamr@2: inline TInt8 ResourceUtils::ReadTInt8L(TResourceReader& aReader) williamr@2: /** Reads an 8 bit signed integer from a resource. williamr@2: williamr@2: @param aReader Resource reader to use to read the integer. williamr@2: @return The 8 bit signed integer. */ williamr@2: { return((TInt8)ReadResourceIntL(aReader,EResourceInt8)); } williamr@2: inline TInt16 ResourceUtils::ReadTInt16L(TResourceReader& aReader) williamr@2: /** Reads a 16 bit signed integer from a resource. williamr@2: williamr@2: @param aReader Resource reader to use to read the integer. williamr@2: @return The 16 bit signed integer. */ williamr@2: { return((TInt16)ReadResourceIntL(aReader,EResourceInt16)); } williamr@2: inline TInt32 ResourceUtils::ReadTInt32L(TResourceReader& aReader) williamr@2: /** Reads a 32 bit signed integer from a resource. williamr@2: williamr@2: @param aReader Resource reader to use to read the integer. williamr@2: @return The 32 bit signed integer. */ williamr@2: { return((TInt32)ReadResourceIntL(aReader,EResourceInt32)); } williamr@2: williamr@2: #endif