|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #if !defined(__GULUTIL_H__) |
|
17 #define __GULUTIL_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <badesca.h> |
|
21 #include <gdi.h> |
|
22 #include <gulbordr.h> |
|
23 #include <gulftflg.hrh> |
|
24 |
|
25 /** |
|
26 @publishedAll |
|
27 @released |
|
28 */ |
|
29 const TUint KTextUtilClipEndChar=0x2026; |
|
30 |
|
31 /** |
|
32 @publishedAll |
|
33 @released |
|
34 */ |
|
35 const TUint KColumnListSeparator='\t'; |
|
36 |
|
37 class CFont; |
|
38 class CFbsFont; |
|
39 class CWsScreenDevice; |
|
40 class TResourceReader; |
|
41 class CColorArray; |
|
42 class CGraphicsDevice; |
|
43 class RWsSession; |
|
44 class CColorList; |
|
45 template <class T> class CArrayFix; |
|
46 |
|
47 |
|
48 class TMargins8 |
|
49 /** A set of margins stored as 8 bit integer values which can represent |
|
50 either pixels or twips between -128 and +127. |
|
51 |
|
52 @publishedAll |
|
53 @released */ |
|
54 { |
|
55 public : |
|
56 /** Left margin in twips or pixels. */ |
|
57 TInt8 iLeft; |
|
58 /** Right margin in twips or pixels. */ |
|
59 TInt8 iRight; |
|
60 /** Top margin in twips or pixels. */ |
|
61 TInt8 iTop; |
|
62 /** Bottom margin in twips or pixels. */ |
|
63 TInt8 iBottom; |
|
64 public : |
|
65 IMPORT_C TMargins8(); |
|
66 IMPORT_C TMargins8(TInt8 aLeft, TInt8 aTop, TInt8 aRight, TInt8 aBottom); |
|
67 IMPORT_C void SetAllValuesTo(TInt aCommonValue); |
|
68 IMPORT_C TRect InnerRect(const TRect& aOuterRect) const; |
|
69 IMPORT_C TRect OuterRect(const TRect& aInnerRect) const; |
|
70 IMPORT_C TSize SizeDelta() const; |
|
71 }; |
|
72 |
|
73 |
|
74 class DrawUtils |
|
75 /** Provides static functions for drawing text in a rectangle. |
|
76 |
|
77 @publishedAll |
|
78 @released */ |
|
79 { |
|
80 public: |
|
81 IMPORT_C static void DrawText(CGraphicsContext& aGc,const TDesC& aString,const TRect& aBox,TInt aBaseLineOffset, |
|
82 CGraphicsContext::TTextAlign aHoriz,TInt aMargin,const CFont* aFont); |
|
83 IMPORT_C static void DrawBetweenRects(CGraphicsContext& aGc,const TRect& aOuterRect,const TRect& aInnerRect); |
|
84 IMPORT_C static void ClearBetweenRects(CGraphicsContext& aGc,const TRect& aOuterRect,const TRect& aInnerRect); |
|
85 }; |
|
86 |
|
87 |
|
88 class TextUtils |
|
89 /** Provides static functions for truncating and aligning text strings. |
|
90 |
|
91 @publishedAll |
|
92 @released */ |
|
93 { |
|
94 public: |
|
95 IMPORT_C static void ClipToFit(TDes& aBuffer,const CFont& aFont,TInt aMaxWidthInPixels,TChar aAlternativeEnd=KTextUtilClipEndChar); |
|
96 IMPORT_C static TInt ColumnText(TPtrC& aColumnText,TInt aColumn,const TDesC* aSourceText,TChar aColumnSeparator=KColumnListSeparator); |
|
97 IMPORT_C static void TruncateToNumChars(TDes& aBuffer, TInt numChars); |
|
98 }; |
|
99 |
|
100 class FontUtils |
|
101 /** Provides static functions for getting information about the fonts supported by a graphics |
|
102 device. |
|
103 |
|
104 @publishedAll |
|
105 @released */ |
|
106 { |
|
107 public: |
|
108 IMPORT_C static void GetAvailableFontsL(const CGraphicsDevice& aDevice,CDesCArray& aFontNameList, |
|
109 TInt aFonts=EGulNoSymbolFonts); |
|
110 IMPORT_C static TInt TypefaceAttributes(const CGraphicsDevice& aDevice,const TDesC& aTypefaceName); |
|
111 IMPORT_C static TInt GetAvailableHeightsInTwipsL(const CGraphicsDevice& aDevice,const TDesC& aTypefaceName, |
|
112 CArrayFix<TInt>& aHeightList); |
|
113 IMPORT_C static TInt GetAvailableHeightsInTwipsAndPointsL(const CGraphicsDevice& aDevice,const TDesC& aTypefaceName, |
|
114 CArrayFix<TInt>& aTwipsList,CDesCArray& aPointsList); |
|
115 IMPORT_C static TInt PointsFromTwips(TInt aTwips); |
|
116 IMPORT_C static TInt TwipsFromPoints(TInt aPoints); |
|
117 IMPORT_C static TInt TwipsFromPoints(const TDesC& aPoints); |
|
118 IMPORT_C static TInt IndexOfNearestHeight(CArrayFix<TInt>& aTwipsList,TInt aHeight); |
|
119 }; |
|
120 |
|
121 |
|
122 class ResourceUtils |
|
123 /** Provides static functions for resource reading. |
|
124 |
|
125 All functions use pre-initialised resource reader objects to read information |
|
126 from resource files. |
|
127 |
|
128 @publishedAll |
|
129 @released |
|
130 @see CCoeEnv::CreateResourceReaderLC() */ |
|
131 { |
|
132 public: |
|
133 IMPORT_C static CFbsFont* CreateNamedScreenFontL(TResourceReader& aResourceReader,CWsScreenDevice& aScreenDevice); |
|
134 IMPORT_C static CFbsFont* CreateNamedScreenFontInPixelsL(TResourceReader& aResourceReader,CWsScreenDevice& aScreenDevice); |
|
135 IMPORT_C static CFbsFont* CreateScreenFontL(TResourceReader& aResourceReader,CWsScreenDevice& aScreenDevice); |
|
136 inline static TInt8 ReadTInt8L(TResourceReader& aReader); |
|
137 inline static TInt16 ReadTInt16L(TResourceReader& aReader); |
|
138 inline static TInt32 ReadTInt32L(TResourceReader& aReader); |
|
139 IMPORT_C static void PopulateColorArrayL(CColorArray& aColors,TResourceReader& aReader); |
|
140 private: |
|
141 enum TResourceTypeInt { EResourceInt8,EResourceInt16,EResourceInt32 }; |
|
142 private: |
|
143 IMPORT_C static TInt32 ReadResourceIntL(TResourceReader& aReader,TResourceTypeInt aSize); |
|
144 }; |
|
145 |
|
146 class ColorUtils |
|
147 /** Provides static functions for manipulating colours. |
|
148 |
|
149 @publishedAll |
|
150 @released |
|
151 @see TDisplayMode */ |
|
152 { |
|
153 public: |
|
154 /** The orientation of a bitmap. */ |
|
155 enum TBitmapOrientation |
|
156 { |
|
157 /** The bitmap is vertical. */ |
|
158 EBitmapOrientationVertical, |
|
159 /** The bitmap is horizontal. */ |
|
160 EBitmapOrientationHorizontal |
|
161 }; |
|
162 public: |
|
163 IMPORT_C static TRgb ColorAdjust(TRgb aColor,TInt aPercentage); |
|
164 IMPORT_C static void CreateGradientBitmapL(CFbsBitmap& aBitmap, const RWsSession& aWs, TInt aBreadth, |
|
165 TBitmapOrientation aOrientation, TRgb aStartColor, TRgb aEndColor); |
|
166 IMPORT_C static CColorList* CreateSystemColorListL(RFs& aFs); |
|
167 IMPORT_C static CColorList* CreateSystemColorListL(RFs& aFs,const CColorList& aColorList); |
|
168 IMPORT_C static void UpdateSystemColorListL(RFs& aFs,CColorList& aColorList); |
|
169 IMPORT_C static void GetRgbDerivedBorderColors(TGulBorder::TColors& aBorderColors,TRgb aBackgroundColor,TDisplayMode aMode); |
|
170 IMPORT_C static TRgb RgbDarkerColor(TRgb aRgb,TDisplayMode aMode); |
|
171 IMPORT_C static TRgb RgbMidDarkerColor(TRgb aRgb,TDisplayMode aMode); |
|
172 IMPORT_C static TRgb RgbLighterColor(TRgb aRgb,TDisplayMode aMode); |
|
173 }; |
|
174 |
|
175 |
|
176 class TFindWidthOfWidestTextItem |
|
177 /** Finds the width in pixels of the widest item in a range of indexed text items. |
|
178 |
|
179 This is the base class for several classes used to get the maximum width for |
|
180 date and time components. |
|
181 |
|
182 Derived classes should override the pure virtual methods to supply an appropriate |
|
183 range of items. |
|
184 |
|
185 @publishedAll |
|
186 @released */ |
|
187 { |
|
188 protected: |
|
189 /** Default constructor. */ |
|
190 inline TFindWidthOfWidestTextItem() {} |
|
191 public: |
|
192 IMPORT_C TInt MaximumWidthInPixels(const CFont& aFont) const; |
|
193 private: |
|
194 /** Gets the first and last index in the range of items. |
|
195 |
|
196 @param aFirstIndex On return, the first index. |
|
197 @param aLastIndex On return, the last index. |
|
198 @publishedAll |
|
199 @released */ |
|
200 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const=0; |
|
201 /** Gets the text item at the specfied index. |
|
202 |
|
203 @param aText On return, the indexed text item. |
|
204 @param aIndex The index. |
|
205 @publishedAll |
|
206 @released */ |
|
207 virtual void GetTextItem(TDes& aText, TInt aIndex) const=0; |
|
208 }; |
|
209 |
|
210 |
|
211 class TFindWidthOfWidestDigit : public TFindWidthOfWidestTextItem |
|
212 /** Finds the width in pixels of the widest digit, when displayed in a specified |
|
213 font. |
|
214 |
|
215 After construction, call MaximumWidthInPixels(), defined in the base class, |
|
216 specifying the font. |
|
217 |
|
218 @publishedAll |
|
219 @released */ |
|
220 { |
|
221 public: |
|
222 IMPORT_C TFindWidthOfWidestDigit(); |
|
223 private: |
|
224 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; |
|
225 virtual void GetTextItem(TDes& aText, TInt aIndex) const; |
|
226 }; |
|
227 |
|
228 class TFindWidthOfWidestDigitType : public TFindWidthOfWidestTextItem |
|
229 /** |
|
230 @publishedAll |
|
231 @released |
|
232 */ |
|
233 { |
|
234 public: |
|
235 IMPORT_C TFindWidthOfWidestDigitType(TDigitType aDigitType); |
|
236 private: |
|
237 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; |
|
238 virtual void GetTextItem(TDes& aText, TInt aIndex) const; |
|
239 |
|
240 private: |
|
241 TDigitType iDigitType; |
|
242 }; |
|
243 |
|
244 class TFindWidthOfWidestAmPmName : public TFindWidthOfWidestTextItem |
|
245 /** Finds the width in pixels of the widest Am or Pm text, when displayed in a specified |
|
246 font. |
|
247 |
|
248 After construction, call MaximumWidthInPixels(), defined in the base class, |
|
249 specifying the font. |
|
250 |
|
251 @publishedAll |
|
252 @released |
|
253 @see TAmPmName */ |
|
254 { |
|
255 public: |
|
256 IMPORT_C TFindWidthOfWidestAmPmName(); |
|
257 private: |
|
258 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; |
|
259 virtual void GetTextItem(TDes& aText, TInt aIndex) const; |
|
260 }; |
|
261 |
|
262 class TFindWidthOfWidestAbbreviatedDayName : public TFindWidthOfWidestTextItem |
|
263 /** Finds the width in pixels of the widest abbreviated day name (for instance Mon, Tue) |
|
264 when displayed in a specified font. |
|
265 |
|
266 After construction, call MaximumWidthInPixels(), defined in the base class, |
|
267 specifying the font. |
|
268 |
|
269 @publishedAll |
|
270 @released |
|
271 @see TDayNameAbb */ |
|
272 { |
|
273 public: |
|
274 IMPORT_C TFindWidthOfWidestAbbreviatedDayName(); |
|
275 private: |
|
276 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; |
|
277 virtual void GetTextItem(TDes& aText, TInt aIndex) const; |
|
278 }; |
|
279 |
|
280 |
|
281 class TFindWidthOfWidestDayName : public TFindWidthOfWidestTextItem |
|
282 /** Finds the width in pixels of the widest day name, when displayed in a specified |
|
283 font. |
|
284 |
|
285 After construction, call MaximumWidthInPixels(), defined in the base class, |
|
286 specifying the font. |
|
287 |
|
288 @publishedAll |
|
289 @released */ |
|
290 { |
|
291 public: |
|
292 IMPORT_C TFindWidthOfWidestDayName(); |
|
293 private: |
|
294 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; |
|
295 virtual void GetTextItem(TDes& aText, TInt aIndex) const; |
|
296 }; |
|
297 |
|
298 |
|
299 class TFindWidthOfWidestAbbreviatedMonthName : public TFindWidthOfWidestTextItem |
|
300 /** Finds the width in pixels of the widest abbreviated month name (for instance Jan, Feb), |
|
301 when displayed in a specified font. |
|
302 |
|
303 After construction, call MaximumWidthInPixels(), defined in the base class, |
|
304 specifying the font. |
|
305 |
|
306 @publishedAll |
|
307 @released */ |
|
308 { |
|
309 public: |
|
310 IMPORT_C TFindWidthOfWidestAbbreviatedMonthName(); |
|
311 private: |
|
312 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; |
|
313 virtual void GetTextItem(TDes& aText, TInt aIndex) const; |
|
314 }; |
|
315 |
|
316 class TFindWidthOfWidestMonthName : public TFindWidthOfWidestTextItem |
|
317 /** Finds the width in pixels of the widest month name, when displayed in a specified |
|
318 font. |
|
319 |
|
320 After construction, call MaximumWidthInPixels(), defined in the base class, |
|
321 specifying the font. |
|
322 |
|
323 @publishedAll |
|
324 @released */ |
|
325 { |
|
326 public: |
|
327 IMPORT_C TFindWidthOfWidestMonthName(); |
|
328 private: |
|
329 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; |
|
330 virtual void GetTextItem(TDes& aText, TInt aIndex) const; |
|
331 }; |
|
332 |
|
333 class TFindWidthOfWidestDateSuffix : public TFindWidthOfWidestTextItem |
|
334 /** Finds the width in pixels of the widest date suffix (for instance st, nd), |
|
335 when displayed in a specified font. |
|
336 |
|
337 After construction, call MaximumWidthInPixels(), defined in the base class, |
|
338 specifying the font. |
|
339 |
|
340 @publishedAll |
|
341 @released */ |
|
342 { |
|
343 public: |
|
344 IMPORT_C TFindWidthOfWidestDateSuffix(); |
|
345 private: |
|
346 virtual void GetFirstAndLastIndex(TInt& aFirstIndex, TInt& aLastIndex) const; |
|
347 virtual void GetTextItem(TDes& aText, TInt aIndex) const; |
|
348 }; |
|
349 |
|
350 // class ResourceUtils |
|
351 inline TInt8 ResourceUtils::ReadTInt8L(TResourceReader& aReader) |
|
352 /** Reads an 8 bit signed integer from a resource. |
|
353 |
|
354 @param aReader Resource reader to use to read the integer. |
|
355 @return The 8 bit signed integer. */ |
|
356 { return((TInt8)ReadResourceIntL(aReader,EResourceInt8)); } |
|
357 inline TInt16 ResourceUtils::ReadTInt16L(TResourceReader& aReader) |
|
358 /** Reads a 16 bit signed integer from a resource. |
|
359 |
|
360 @param aReader Resource reader to use to read the integer. |
|
361 @return The 16 bit signed integer. */ |
|
362 { return((TInt16)ReadResourceIntL(aReader,EResourceInt16)); } |
|
363 inline TInt32 ResourceUtils::ReadTInt32L(TResourceReader& aReader) |
|
364 /** Reads a 32 bit signed integer from a resource. |
|
365 |
|
366 @param aReader Resource reader to use to read the integer. |
|
367 @return The 32 bit signed integer. */ |
|
368 { return((TInt32)ReadResourceIntL(aReader,EResourceInt32)); } |
|
369 |
|
370 #endif |
|
371 |