|
1 /* |
|
2 * Copyright (c) 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: Implementation of HuiTextStyleManager. Handles the management |
|
15 * of Hitchcock UI Toolkit specific font styles. The |
|
16 * implementation consists only of Symbian / S60 specific |
|
17 * implementation but the interface is designed so that |
|
18 * alternative platforms can be utilized. |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 |
|
24 #include <avkon.hrh> // @todo: include proper header file |
|
25 #include <AknUtils.h> |
|
26 #include <aknappui.h> |
|
27 #include <gdi.h> |
|
28 #ifndef PUBLIC_SDK |
|
29 #include <aknlayoutscalable_avkon.cdl.h> |
|
30 #endif |
|
31 |
|
32 #include "uiacceltk/huitextstylemanager.h" |
|
33 #include "HuiS60TextStyle.h" |
|
34 #include "uiacceltk/HuiUtil.h" |
|
35 |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Creates the CHuiTextStyleManager. Sets parameters to default values. |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CHuiTextStyleManager::CHuiTextStyleManager() |
|
44 { |
|
45 |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Destroys the CHuiTextStyleManager. Makes sure all allocated resources are |
|
50 // freed. |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CHuiTextStyleManager::~CHuiTextStyleManager() |
|
54 { |
|
55 // delete the text style in the array |
|
56 for(TInt i = 0; i < iTextStyles.Count(); i++) |
|
57 { |
|
58 // need to down cast, because base class does not have |
|
59 // virtual destructor. |
|
60 THuiS60TextStyle* deletedStyle = static_cast<THuiS60TextStyle*>(iTextStyles[i]); |
|
61 delete deletedStyle; |
|
62 } |
|
63 |
|
64 // Close the array |
|
65 iTextStyles.Close(); |
|
66 } |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CHuiTextStyleManager::NewL |
|
71 // Two-phased constructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CHuiTextStyleManager* CHuiTextStyleManager::NewL() |
|
75 { |
|
76 CHuiTextStyleManager* self = NewLC(); |
|
77 CleanupStack::Pop(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CHuiTextStyleManager::NewLC |
|
84 // Two-phased constructor. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CHuiTextStyleManager* CHuiTextStyleManager::NewLC() |
|
88 { |
|
89 CHuiTextStyleManager* self = new (ELeave) CHuiTextStyleManager(); |
|
90 CleanupStack::PushL(self); |
|
91 self->ConstructL(); |
|
92 return self; |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CHuiTextStyleManager::ConstructL |
|
98 // Symbian 2nd phase constructor. |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CHuiTextStyleManager::ConstructL() |
|
102 { |
|
103 // Construct the default text style first. |
|
104 // It is the same as ENormalFont / EHuiTextStyleNormal, EHuiTextStyleMenuItem |
|
105 // Parent id -1 means no parent |
|
106 CreatePlatformTextStyleL( EAknLogicalFontPrimaryFont, -1 ); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // Creates a new text style instance. |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C TInt CHuiTextStyleManager::CreatePlatformTextStyleL(TInt aFontStyleId, TInt aParentId) |
|
114 { |
|
115 THuiS60TextStyle* style = new (ELeave) THuiS60TextStyle(aFontStyleId, aParentId); |
|
116 |
|
117 // Append the specified text style into the array of styles. |
|
118 CleanupStack::PushL( style ); |
|
119 InsertIntoArrayAndSetIdL(*style); |
|
120 CleanupStack::Pop( style ); |
|
121 |
|
122 // Return the unique ID of the text style. |
|
123 return style->Id(); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // Retuns A pointer to the requested text style. |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C THuiTextStyle* CHuiTextStyleManager::TextStyle(TInt aId) |
|
131 { |
|
132 if ( aId >= 0 && aId < iTextStyles.Count() ) |
|
133 { |
|
134 __ASSERT_DEBUG( iTextStyles[aId] , USER_INVARIANT() ); |
|
135 return iTextStyles[aId]; |
|
136 } |
|
137 |
|
138 return iTextStyles[EHuiTextStyleNormal]; |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // Creates a new text style object that is identical with the given source |
|
143 // text style. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 EXPORT_C TInt CHuiTextStyleManager::CopyTextStyleL(TInt aSourceId) |
|
147 { |
|
148 // get the source text style by the id |
|
149 const THuiTextStyle sourceStyle = *TextStyle(aSourceId); |
|
150 |
|
151 // make a copy of the source text style |
|
152 THuiTextStyle* style = new (ELeave) THuiTextStyle(sourceStyle); |
|
153 |
|
154 // Append the specified text style into the array of styles. |
|
155 CleanupStack::PushL( style ); |
|
156 InsertIntoArrayAndSetIdL(*style); |
|
157 CleanupStack::Pop( style ); |
|
158 |
|
159 // Return the unique ID of the text style. |
|
160 return style->Id(); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // Deletes text style with given ID. |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C TInt CHuiTextStyleManager::DeleteTextStyle(TInt aId) |
|
168 { |
|
169 // Cannot delete platform styles from an application. |
|
170 if ( aId >= 0 && aId <= iLastBuiltInStyleId ) |
|
171 { |
|
172 return KErrAccessDenied; |
|
173 } |
|
174 |
|
175 if ( aId >= iTextStyles.Count() ) |
|
176 { |
|
177 return KErrArgument; |
|
178 } |
|
179 // need to down cast, because base class does not have |
|
180 // virtual destructor. |
|
181 THuiS60TextStyle* deletedStyle = static_cast<THuiS60TextStyle*>(iTextStyles[aId]); |
|
182 |
|
183 if ( deletedStyle ) |
|
184 { |
|
185 delete deletedStyle; |
|
186 iTextStyles[aId] = NULL; // NULL the slot for later usage. |
|
187 } |
|
188 else |
|
189 { |
|
190 return KErrArgument; |
|
191 } |
|
192 return KErrNone; |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // Construct built-in styles. |
|
197 // these ate the preconfigured text styles enumerated in HuiSkin.h |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CHuiTextStyleManager::ConstructBuiltInStylesL() |
|
201 { |
|
202 THuiTextStyle* style; |
|
203 |
|
204 // the order here must be the same as in HuiSkin.h THuiPreconfiguredTextStyle |
|
205 |
|
206 // ENormalItalicFont / no EHuiTextStyleXxx def |
|
207 TInt normalItalicStyleId = CreatePlatformTextStyleL( EAknLogicalFontPrimaryFont, EHuiTextStyleNormal ); |
|
208 style = TextStyle(normalItalicStyleId); |
|
209 style->SetPosture(ETrue); |
|
210 |
|
211 // EHuiTextStyleMenuItem |
|
212 CreatePlatformTextStyleL( EAknLogicalFontPrimaryFont, EHuiTextStyleNormal ); |
|
213 |
|
214 // ESmallFont / EHuiTextStyleSmall |
|
215 TInt smallStyleId = CreatePlatformTextStyleL( EAknLogicalFontSecondaryFont, EHuiTextStyleNormal ); |
|
216 |
|
217 // ESmallFont EHuiTextStyleMenuSmall |
|
218 CreatePlatformTextStyleL( EAknLogicalFontSecondaryFont, smallStyleId ); |
|
219 |
|
220 // ENormalBoldFont / EHuiTextStyleMenuTitle |
|
221 TInt normalBoldStyleId = CreatePlatformTextStyleL( EAknLogicalFontPrimaryFont, EHuiTextStyleNormal ); |
|
222 style = TextStyle(normalBoldStyleId); |
|
223 style->SetStrokeWeight(ETrue); |
|
224 |
|
225 // ELargeFont / EHuiTextStyleLarge |
|
226 CreatePlatformTextStyleL( EAknLogicalFontTitleFont, EHuiTextStyleNormal ); |
|
227 |
|
228 // ESoftkeyFont / EHuiTextStyleSoftkey |
|
229 TInt softkeyStyleId = CreatePlatformTextStyleL( EAknLogicalFontTitleFont, EHuiTextStyleNormal ); |
|
230 SetSoftkeyTextStyle(softkeyStyleId); |
|
231 |
|
232 // EHuiTextStyleSupplement |
|
233 CreatePlatformTextStyleL( EAknLogicalFontPrimaryFont, EHuiTextStyleNormal ); |
|
234 |
|
235 // EHuiTextStyleTitle |
|
236 iLastBuiltInStyleId = CreatePlatformTextStyleL( EAknLogicalFontTitleFont, EHuiTextStyleNormal ); |
|
237 |
|
238 NotifyDisplaySizeChangedL(); // @todo: Why this is needed to make EHuiTextStyleSmall to look "small" instead of "normal" ??? |
|
239 } |
|
240 |
|
241 void CHuiTextStyleManager::SetSoftkeyTextStyle(TInt aTextStyleId) |
|
242 { |
|
243 // Deprecated, really |
|
244 if (!CCoeEnv::Static()) |
|
245 { |
|
246 return; |
|
247 } |
|
248 |
|
249 THuiTextStyle* style = TextStyle(aTextStyleId); |
|
250 TFontSpec spec; |
|
251 |
|
252 /// Approximate the S60 softkey font parameters |
|
253 const CFont* font = AknLayoutUtils::FontFromId(EAknLogicalFontTitleFont, NULL); |
|
254 spec = font->FontSpecInTwips(); |
|
255 spec.iHeight = 80 * spec.iHeight / 100; |
|
256 THuiFont huiFont(0, spec); |
|
257 style->SetFont(huiFont); |
|
258 } |
|
259 |
|
260 void CHuiTextStyleManager::NotifyDisplaySizeChangedL() |
|
261 { |
|
262 for(TInt i = 0; i < iLastBuiltInStyleId; i++) |
|
263 { |
|
264 THuiS60TextStyle* platformStyle = dynamic_cast<THuiS60TextStyle*>(iTextStyles[i]); |
|
265 // Assume that dynmic cast returns null if iTextStyles[i] is not THuiS60TextStyle |
|
266 if (platformStyle) |
|
267 { |
|
268 platformStyle->Init(); |
|
269 } |
|
270 } |
|
271 } |
|
272 |
|
273 void CHuiTextStyleManager::InsertIntoArrayAndSetIdL(THuiTextStyle& style) |
|
274 { |
|
275 TInt id = KErrNotFound; |
|
276 |
|
277 // try to find an empty slot |
|
278 for ( TInt i = iTextStyles.Count() - 1 ; i >= 0 && id == KErrNotFound; i-- ) |
|
279 { |
|
280 if ( !iTextStyles[i] ) |
|
281 { |
|
282 // empty found |
|
283 id = i; |
|
284 } |
|
285 } |
|
286 |
|
287 if ( id != KErrNotFound ) |
|
288 { |
|
289 // empty slot found -> utilize that |
|
290 iTextStyles[id] = &style; |
|
291 } |
|
292 else |
|
293 { |
|
294 // append |
|
295 id = iTextStyles.Count(); |
|
296 iTextStyles.AppendL(&style); |
|
297 } |
|
298 |
|
299 style.SetId( id ); |
|
300 } |