|
1 /* |
|
2 * Copyright (c) 2006 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: Text style handlers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "alftextstylehandlers.h" |
|
21 #include "alf/alfconstants.h" |
|
22 #include <uiacceltk/HuiEnv.h> |
|
23 #include <uiacceltk/huitextstylemanager.h> |
|
24 #include <gdi.h> |
|
25 |
|
26 //----------------------------------------------------------------------------- |
|
27 // Create a handler for platform, preconfigured, or cloned text style |
|
28 //----------------------------------------------------------------------------- |
|
29 TAlfTextStyleHandler::TAlfTextStyleHandler( |
|
30 MAlfInterfaceProvider& aResolver, |
|
31 TInt aId1, |
|
32 TInt aId2, |
|
33 TInt aConstructionType) |
|
34 : iResolver(aResolver), iTextStyle( NULL ) |
|
35 { |
|
36 // Retrieve the text style manager |
|
37 CHuiTextStyleManager& manager = aResolver.SharedHuiEnv()->TextStyleManager(); |
|
38 TInt id = KErrNotFound; |
|
39 |
|
40 |
|
41 switch(aConstructionType) |
|
42 { |
|
43 case EAlfPlatformTextStyleCreate: |
|
44 TRAP_IGNORE( |
|
45 { |
|
46 // Get parent text style handler |
|
47 TAlfTextStyleHandler* parentHandler = |
|
48 static_cast<TAlfTextStyleHandler*>( |
|
49 aResolver.GetInterfaceL(EAlfTextStyleHandler, aId2)); |
|
50 |
|
51 // Create a platform text style |
|
52 id = manager.CreatePlatformTextStyleL( |
|
53 aId1, |
|
54 parentHandler->TextStyleId()); |
|
55 }) |
|
56 |
|
57 iTextStyle = manager.TextStyle(id); |
|
58 break; |
|
59 |
|
60 case EAlfPreconfiguredTextStyleCreate: |
|
61 iTextStyle = manager.TextStyle(aId1); |
|
62 break; |
|
63 |
|
64 case EAlfPlatformTextStyleCopy: |
|
65 TRAP_IGNORE( |
|
66 { |
|
67 // Get parent text style handler |
|
68 TAlfTextStyleHandler* sourceHandler = |
|
69 static_cast<TAlfTextStyleHandler*>( |
|
70 aResolver.GetInterfaceL(EAlfTextStyleHandler, aId1)); |
|
71 |
|
72 // Create a platform text style |
|
73 id = manager.CopyTextStyleL(sourceHandler->TextStyleId()); |
|
74 }) |
|
75 |
|
76 iTextStyle = manager.TextStyle(id); |
|
77 break; |
|
78 |
|
79 default: |
|
80 break; |
|
81 } |
|
82 } |
|
83 |
|
84 //----------------------------------------------------------------------------- |
|
85 // |
|
86 //----------------------------------------------------------------------------- |
|
87 void TAlfTextStyleHandler::Release() |
|
88 { |
|
89 if ( iTextStyle ) |
|
90 { |
|
91 CHuiTextStyleManager& manager = iResolver.SharedHuiEnv()->TextStyleManager(); |
|
92 (void)manager.DeleteTextStyle( iTextStyle->Id() ); // ignore error |
|
93 } |
|
94 delete this; |
|
95 } |
|
96 |
|
97 //----------------------------------------------------------------------------- |
|
98 // |
|
99 //----------------------------------------------------------------------------- |
|
100 TAny* TAlfTextStyleHandler::GetInterface(const THuiInterfaceSupport& aInterface) |
|
101 { |
|
102 if(aInterface == EAlfTextStyleHandler) |
|
103 { |
|
104 return this; |
|
105 } |
|
106 return NULL; |
|
107 } |
|
108 |
|
109 //----------------------------------------------------------------------------- |
|
110 // |
|
111 //----------------------------------------------------------------------------- |
|
112 void TAlfTextStyleHandler::HandleCmdL( |
|
113 TInt aCommandId, |
|
114 const TDesC8& aInputBuffer, |
|
115 TDes8& aResponse) |
|
116 { |
|
117 switch (aCommandId) |
|
118 { |
|
119 case EAlfTextStyleSetParent: |
|
120 { |
|
121 TInt* param = (TInt*) aInputBuffer.Ptr(); |
|
122 // Get parent text style handler |
|
123 TAlfTextStyleHandler* parentHandler = |
|
124 static_cast<TAlfTextStyleHandler*>( |
|
125 iResolver.GetInterfaceL(EAlfTextStyleHandler, *param)); |
|
126 iTextStyle->SetParentId(parentHandler->TextStyleId()); |
|
127 break; |
|
128 } |
|
129 |
|
130 case EAlfTextStyleSetTextColor: |
|
131 { |
|
132 TRgb* param = (TRgb*) aInputBuffer.Ptr(); |
|
133 iTextStyle->SetTextColor(*param); |
|
134 break; |
|
135 } |
|
136 |
|
137 case EAlfTextStyleSetTextSizeInTwips: |
|
138 { |
|
139 TInt2* params = (TInt2*) aInputBuffer.Ptr(); |
|
140 iTextStyle->SetTextSizeInTwips(params->iInt1, params->iInt2); |
|
141 break; |
|
142 } |
|
143 |
|
144 case EAlfTextStyleSetTextSizeInPixels: |
|
145 { |
|
146 TInt2* params = (TInt2*) aInputBuffer.Ptr(); |
|
147 iTextStyle->SetTextSizeInPixels(params->iInt1, params->iInt2); |
|
148 break; |
|
149 } |
|
150 |
|
151 case EAlfTextStyleSetBold: |
|
152 { |
|
153 TInt* param = (TInt*) aInputBuffer.Ptr(); |
|
154 iTextStyle->SetStrokeWeight(*param); |
|
155 break; |
|
156 } |
|
157 |
|
158 case EAlfTextStyleSetItalic: |
|
159 { |
|
160 TInt* param = (TInt*) aInputBuffer.Ptr(); |
|
161 iTextStyle->SetPosture(*param); |
|
162 break; |
|
163 } |
|
164 |
|
165 case EAlfTextStyleSetUnderline: |
|
166 { |
|
167 TInt* param = (TInt*) aInputBuffer.Ptr(); |
|
168 iTextStyle->SetUnderline(*param); |
|
169 break; |
|
170 } |
|
171 |
|
172 case EAlfTextStyleSetStrikeThrough: |
|
173 { |
|
174 TInt* param = (TInt*) aInputBuffer.Ptr(); |
|
175 iTextStyle->SetStrikeThrough(*param); |
|
176 break; |
|
177 } |
|
178 |
|
179 case EAlfTextStyleTextColor: |
|
180 { |
|
181 const TRgb textColor = iTextStyle->TextColor(); |
|
182 TPckg<TRgb> resultPckg(textColor); |
|
183 aResponse = resultPckg; |
|
184 break; |
|
185 } |
|
186 |
|
187 case EAlfTextStyleSizeInTwips: |
|
188 { |
|
189 TInt* param = (TInt*) aInputBuffer.Ptr(); |
|
190 const TInt textSizeInTwips = iTextStyle->TextSizeInTwips(*param); |
|
191 TPckg<TInt> resultPckg(textSizeInTwips); |
|
192 aResponse = resultPckg; |
|
193 break; |
|
194 } |
|
195 |
|
196 case EAlfTextStyleSizeInPixels: |
|
197 { |
|
198 TInt* param = (TInt*) aInputBuffer.Ptr(); |
|
199 const TInt textSizeInPixels = iTextStyle->TextSizeInPixels(*param); |
|
200 TPckg<TInt> resultPckg(textSizeInPixels); |
|
201 aResponse = resultPckg; |
|
202 break; |
|
203 } |
|
204 |
|
205 case EAlfTextStyleIsBold: |
|
206 { |
|
207 const TBool isBold = iTextStyle->StrokeWeight(); |
|
208 TPckg<TBool> resultPckg(isBold); |
|
209 aResponse = resultPckg; |
|
210 break; |
|
211 } |
|
212 |
|
213 case EAlfTextStyleIsItalic: |
|
214 { |
|
215 const TBool isItalic = iTextStyle->Posture(); |
|
216 TPckg<TBool> resultPckg(isItalic); |
|
217 aResponse = resultPckg; |
|
218 break; |
|
219 } |
|
220 |
|
221 case EAlfTextStyleIsUnderline: |
|
222 { |
|
223 const TBool isUnderline = iTextStyle->Underline(); |
|
224 TPckg<TBool> resultPckg(isUnderline); |
|
225 aResponse = resultPckg; |
|
226 break; |
|
227 } |
|
228 |
|
229 case EAlfTextStyleIsStrikeThrough: |
|
230 { |
|
231 const TBool isStrikeThrough = iTextStyle->StrikeThrough(); |
|
232 TPckg<TBool> resultPckg(isStrikeThrough); |
|
233 aResponse = resultPckg; |
|
234 break; |
|
235 } |
|
236 |
|
237 case EAlfTextStyleGetTypeface: |
|
238 { |
|
239 TTypeface typeface; |
|
240 iTextStyle->GetTypeface( typeface ); |
|
241 TPckg<TTypeface> resultPckg(typeface); |
|
242 aResponse = resultPckg; |
|
243 break; |
|
244 } |
|
245 |
|
246 case EAlfTextStyleSetTextPaneHeightInPixels: |
|
247 { |
|
248 TInt2* params = (TInt2*) aInputBuffer.Ptr(); |
|
249 iTextStyle->SetTextPaneHeightInPixels(params->iInt1, params->iInt2); |
|
250 break; |
|
251 } |
|
252 case EAlfTextStyleServerHandle: |
|
253 { |
|
254 TInt id = iTextStyle->Id(); |
|
255 TPckg<TInt> resultPckg(id); |
|
256 aResponse = resultPckg; |
|
257 break; |
|
258 } |
|
259 |
|
260 default: |
|
261 User::Leave(KErrNotSupported); |
|
262 } |
|
263 } |
|
264 |
|
265 //----------------------------------------------------------------------------- |
|
266 // |
|
267 //----------------------------------------------------------------------------- |
|
268 TInt TAlfTextStyleHandler::TextStyleId() const |
|
269 { |
|
270 return iTextStyle->Id(); |
|
271 } |