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: Implements common attributesetters for layout. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "alf/alfattribute.h" |
|
21 #include "alf/alfcommonlayoutattributesetter.h" |
|
22 #include "alf/alfattributevaluetype.h" |
|
23 #include <alf/alfvisual.h> |
|
24 #include <alf/alflayout.h> |
|
25 #include <alf/alfattributeexception.h> |
|
26 #include "alf/alfattributecontainer.h" |
|
27 #include <libc/string.h> |
|
28 #include <osn/ustring.h> |
|
29 #include "alf/attrproperty.h" |
|
30 #include <alf/alfexception.h> |
|
31 #include <alf/alfdataexception.h> |
|
32 #include <alf/alfvisualexception.h> |
|
33 #include <e32cmn.h> |
|
34 #include <utf.h> |
|
35 |
|
36 using namespace osncore; |
|
37 |
|
38 using namespace duiuimodel::layoutattributes; |
|
39 |
|
40 namespace Alf |
|
41 { |
|
42 |
|
43 static void throwIfNot ( bool aBoolean ) |
|
44 { |
|
45 if ( !aBoolean ) |
|
46 { |
|
47 ALF_THROW ( AlfAttributeException, EInvalidAttribute,"CAlfCommonlayoutAttributeSetter") |
|
48 } |
|
49 } |
|
50 |
|
51 // ======== MEMBER FUNCTIONS ======== |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Constructor. |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 OSN_EXPORT AlfCommonLayoutAttributeSetter::AlfCommonLayoutAttributeSetter() |
|
58 { |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Destructor. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 OSN_EXPORT AlfCommonLayoutAttributeSetter::~AlfCommonLayoutAttributeSetter() |
|
66 { |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Sets Attribute Value. Delegates based on attribute Category. |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 OSN_EXPORT void AlfCommonLayoutAttributeSetter::setAttributeValue ( |
|
74 CAlfVisual &aVisual, |
|
75 AlfAttributeContainer* aContainer, |
|
76 IAlfMap* aData ) |
|
77 { |
|
78 CAlfLayout* layout = dynamic_cast<CAlfLayout*> ( &aVisual ); |
|
79 |
|
80 if ( !layout ) |
|
81 { |
|
82 ALF_THROW ( AlfVisualException, EInvalidVisual, |
|
83 "AlfCommonLayoutAttributeSetter" ) |
|
84 } |
|
85 |
|
86 AlfCommonVisualAttributeSetter::setAttributeValue(aVisual, |
|
87 aContainer, aData); |
|
88 } |
|
89 |
|
90 void AlfCommonLayoutAttributeSetter::handleStaticDataAttribute ( CAlfVisual &aVisual, AlfAttribute& aAttr, |
|
91 AlfAttributeContainer& aContainer, IAlfMap* aData ) |
|
92 { |
|
93 |
|
94 if ( aData ) |
|
95 { |
|
96 CAlfLayout* layout = dynamic_cast<CAlfLayout*> ( &aVisual ); |
|
97 if(!layout) |
|
98 { |
|
99 return; |
|
100 } |
|
101 |
|
102 const char* attrName = aAttr.name(); |
|
103 |
|
104 if ( !strcmp ( attrName, KBaseUnitX ) ) |
|
105 { |
|
106 IAlfVariantType* dataX = aData->item ( UString(aAttr.getDataField()) ); |
|
107 AlfAttribute& attrY = aContainer.getAttributeByName ( KBaseUnitY ); |
|
108 |
|
109 IAlfVariantType* dataY = aData->item ( UString(attrY.getDataField())); |
|
110 |
|
111 if (dataX!=NULL&&dataX->type() == IAlfVariantType::EMap&& |
|
112 dataY!=NULL&&dataY->type() == IAlfVariantType::EMap) |
|
113 { |
|
114 IAlfVariantType* valueX=((IAlfMap*)dataX)->item(UString("value")); |
|
115 IAlfVariantType* unitX=((IAlfMap*)dataX)->item(UString("unit")); |
|
116 IAlfVariantType* valueY=((IAlfMap*)dataY)->item(UString("value")); |
|
117 IAlfVariantType* unitY=((IAlfMap*)dataY)->item(UString("unit")); |
|
118 |
|
119 TAlfMetric xMetric ( valueX->real(), (TAlfUnit)unitX->integer() ); |
|
120 TAlfMetric yMetric ( valueX->real(), (TAlfUnit)unitX->integer()); |
|
121 TAlfXYMetric xyMetric ( xMetric, yMetric ); |
|
122 layout->SetBaseUnit( xyMetric ); |
|
123 } |
|
124 else if (dataX!=NULL&&dataX->type() == IAlfVariantType::EReal&& |
|
125 dataY!=NULL&&dataY->type() == IAlfVariantType::EReal) |
|
126 { |
|
127 TAlfMetric xMetric ( (float)dataX->real() ); |
|
128 TAlfMetric yMetric ( (float)dataY->real()); |
|
129 TAlfXYMetric xyMetric ( xMetric, yMetric ); |
|
130 layout->SetBaseUnit( xyMetric ); |
|
131 } |
|
132 } |
|
133 else if ( !strcmp ( attrName, KBaseUnitY ) ) |
|
134 { |
|
135 //we have handled it |
|
136 } |
|
137 |
|
138 else if ( !strcmp ( attrName, KUpdateLayoutTime ) ) |
|
139 { |
|
140 IAlfVariantType* data = aData->item (UString(aAttr.getDataField()) ); |
|
141 |
|
142 if ( data && data->type() == IAlfVariantType::EInt ) |
|
143 { |
|
144 layout->SetTransitionTime ( data->integer() ); |
|
145 } |
|
146 else if ( data && data->type() == IAlfVariantType::EReal ) |
|
147 { |
|
148 layout->SetTransitionTime ( ( int ) data->real() ); |
|
149 } |
|
150 } |
|
151 else if ( !strcmp ( attrName, KTransitionTime ) ) |
|
152 { |
|
153 IAlfVariantType* data = aData->item (UString(aAttr.getDataField()) ); |
|
154 |
|
155 if ( data && data->type() == IAlfVariantType::EInt ) |
|
156 { |
|
157 layout->SetTransitionTime ( data->integer() ); |
|
158 } |
|
159 else if ( data && data->type() == IAlfVariantType::EReal ) |
|
160 { |
|
161 layout->SetTransitionTime ( ( int ) data->real() ); |
|
162 } |
|
163 } |
|
164 else if ( !strcmp ( attrName, KAutomaticLocaleMirroring ) ) |
|
165 { |
|
166 IAlfVariantType* data = aData->item (UString(aAttr.getDataField()) ); |
|
167 throwIfNot ( data != NULL && data->type() == IAlfVariantType::EString ); |
|
168 |
|
169 if ( !strcmp ( data->string().getUtf8(), "true" ) ) |
|
170 layout->SetFlag ( EAlfVisualFlagAutomaticLocaleMirroringEnabled ); |
|
171 else if ( !strcmp ( data->string().getUtf8(), "false" ) ) |
|
172 layout->ClearFlag ( EAlfVisualFlagAutomaticLocaleMirroringEnabled ); |
|
173 } |
|
174 else if ( !strcmp ( attrName, KInnerPaddingHoriz ) ) |
|
175 { |
|
176 IAlfVariantType* dataX = aData->item (UString(aAttr.getDataField()) ); |
|
177 AlfAttribute& attrY = aContainer.getAttributeByName ( KInnerPaddingVertical ); |
|
178 |
|
179 IAlfVariantType* dataY = aData->item ( UString(attrY.getDataField() )); |
|
180 |
|
181 if (dataX&&dataX->type() == IAlfVariantType::EMap&&dataY |
|
182 &&dataY->type()== IAlfVariantType::EMap) |
|
183 { |
|
184 IAlfVariantType* valueX=((IAlfMap*)dataX)->item(UString("value")); |
|
185 IAlfVariantType* unitX=((IAlfMap*)dataX)->item(UString("unit")); |
|
186 IAlfVariantType* valueY=((IAlfMap*)dataY)->item(UString("value")); |
|
187 IAlfVariantType* unitY=((IAlfMap*)dataY)->item(UString("unit")); |
|
188 |
|
189 TAlfMetric xMetric ( valueX->real(), (TAlfUnit)unitX->integer() ); |
|
190 TAlfMetric yMetric ( valueX->real(), (TAlfUnit)unitX->integer()); |
|
191 TAlfXYMetric xyMetric ( xMetric, yMetric ); |
|
192 layout->SetInnerPadding( xyMetric ); |
|
193 } |
|
194 if ( dataX&&dataX->type() == IAlfVariantType::EReal&&dataY |
|
195 &&dataY->type()== IAlfVariantType::EReal) |
|
196 { |
|
197 TAlfMetric xMetric ( dataX->real(),EAlfUnitPixel ); |
|
198 TAlfMetric yMetric ( dataY->real() ,EAlfUnitPixel); |
|
199 TAlfXYMetric xyMetric ( xMetric, yMetric ); |
|
200 layout->SetInnerPadding( xyMetric ); |
|
201 } |
|
202 } |
|
203 else if ( !strcmp ( attrName, KInnerPaddingVertical ) ) |
|
204 { |
|
205 // we have handled it |
|
206 } |
|
207 else if ( !strcmp ( attrName, KScrolling ) ) |
|
208 { |
|
209 IAlfVariantType* data = aData->item ( UString(aAttr.getDataField() )); |
|
210 |
|
211 throwIfNot ( data != NULL && data->type() == IAlfVariantType::EString ); |
|
212 |
|
213 if ( !strcmp ( data->string().getUtf8(), "true" ) ) |
|
214 { |
|
215 TRAPD(err,layout->EnableScrollingL()) |
|
216 throwIfNot(err!=KErrNone); |
|
217 } |
|
218 |
|
219 else |
|
220 { |
|
221 TRAPD(err,layout->EnableScrollingL(false)) |
|
222 throwIfNot(err!=KErrNone); |
|
223 } |
|
224 } |
|
225 else if ( !strcmp ( attrName, KLayoutScrollOffsetX ) ) |
|
226 { |
|
227 IAlfVariantType* dataX = aData->item ( UString(aAttr.getDataField() )); |
|
228 throwIfNot ( dataX != NULL && dataX->type() == IAlfVariantType::EReal ); |
|
229 |
|
230 AlfAttribute& attrY = aContainer.getAttributeByName ( KLayoutScrollOffsetY ); |
|
231 IAlfVariantType* dataY = aData->item (UString( attrY.getDataField() )); |
|
232 throwIfNot ( dataY != NULL && dataY->type() == IAlfVariantType::EReal ); |
|
233 |
|
234 TAlfTimedPoint point ( dataX->real(), dataY->real() ); |
|
235 layout->SetScrollOffset ( point ); |
|
236 } |
|
237 else if ( !strcmp ( attrName, KLayoutScrollOffsetY ) ) |
|
238 { |
|
239 // we have handled it |
|
240 } |
|
241 else |
|
242 { |
|
243 AlfCommonVisualAttributeSetter::handleStaticDataAttribute( aVisual, aAttr, aContainer, aData); |
|
244 } |
|
245 } |
|
246 } |
|
247 |
|
248 void AlfCommonLayoutAttributeSetter::handleDynamicDataAttribute ( CAlfVisual &aVisual, AlfAttribute& aAttr, |
|
249 AlfAttributeContainer& aContainer, IAlfMap* aData ) |
|
250 { |
|
251 AlfCommonVisualAttributeSetter::handleDynamicDataAttribute( aVisual, aAttr, aContainer, aData); |
|
252 } |
|
253 |
|
254 void AlfCommonLayoutAttributeSetter::handleStaticAttribute ( CAlfVisual &aVisual, AlfAttribute& aAttr, |
|
255 AlfAttributeContainer& aContainer) |
|
256 { |
|
257 CAlfLayout* layout = dynamic_cast<CAlfLayout*> ( &aVisual ); |
|
258 if(!layout) |
|
259 { |
|
260 return; |
|
261 } |
|
262 const char* attrName = aAttr.name(); |
|
263 |
|
264 if ( !strcmp ( attrName, KBaseUnitX )||!strcmp ( attrName, KBaseUnitY ) ) |
|
265 { |
|
266 AlfAttribute& attrX = aContainer.getAttributeByName ( KBaseUnitX ); |
|
267 AlfAttribute& attrY = aContainer.getAttributeByName ( KBaseUnitY ); |
|
268 TAlfMetric xMetric ( attrX.realValue(), attrX.unit() ); |
|
269 TAlfMetric yMetric ( attrY.realValue(), attrY.unit() ); |
|
270 TAlfXYMetric xyMetric ( xMetric, yMetric ); |
|
271 layout->SetBaseUnit ( xyMetric ); |
|
272 attrX.setDirty(false); |
|
273 attrY.setDirty(false); |
|
274 } |
|
275 else if ( !strcmp ( attrName, KUpdateLayoutTime ) ) |
|
276 { |
|
277 if ( aAttr.type() == AlfAttributeValueType::EInt ) |
|
278 { |
|
279 layout->SetTransitionTime ( aAttr.intValue() ); |
|
280 } |
|
281 else if ( aAttr.type() == AlfAttributeValueType::EFloat ) |
|
282 { |
|
283 layout->SetTransitionTime ( ( int ) aAttr.realValue() ); |
|
284 } |
|
285 } |
|
286 else if ( !strcmp ( attrName, KTransitionTime ) ) |
|
287 { |
|
288 if ( aAttr.type() == AlfAttributeValueType::EInt ) |
|
289 { |
|
290 layout->SetTransitionTime ( aAttr.intValue() ); |
|
291 } |
|
292 else if ( aAttr.type() == AlfAttributeValueType::EFloat ) |
|
293 { |
|
294 layout->SetTransitionTime ( ( int ) aAttr.realValue() ); |
|
295 } |
|
296 } |
|
297 else if ( !strcmp ( attrName, KAutomaticLocaleMirroring ) ) |
|
298 { |
|
299 throwIfNot ( aAttr.type() == AlfAttributeValueType::EString ); |
|
300 |
|
301 if ( !strcmp ( aAttr.stringValue().getUtf8(), "true" ) ) |
|
302 { |
|
303 layout->SetFlag ( EAlfVisualFlagAutomaticLocaleMirroringEnabled ); |
|
304 } |
|
305 else if ( !strcmp ( aAttr.stringValue().getUtf8(), "false" ) ) |
|
306 { |
|
307 layout->ClearFlag ( EAlfVisualFlagAutomaticLocaleMirroringEnabled ); |
|
308 } |
|
309 } |
|
310 else if ( !strcmp ( attrName, KInnerPaddingHoriz )||!strcmp ( attrName, KInnerPaddingVertical ) ) |
|
311 { |
|
312 AlfAttribute& attrY = aContainer.getAttributeByName ( KInnerPaddingVertical ); |
|
313 AlfAttribute& attrX= aContainer.getAttributeByName ( KInnerPaddingHoriz ); |
|
314 throwIfNot ( attrX.type() == AlfAttributeValueType::EFloat ); |
|
315 throwIfNot ( attrY.type() == AlfAttributeValueType::EFloat ); |
|
316 TAlfMetric xMetric ( attrX.realValue(), attrX.unit() ); |
|
317 TAlfMetric yMetric ( attrY.realValue(), attrY.unit() ); |
|
318 TAlfXYMetric xyMetric ( xMetric, yMetric ); |
|
319 layout->SetInnerPadding ( xyMetric ); |
|
320 attrX.setDirty(false); |
|
321 attrY.setDirty(false); |
|
322 } |
|
323 else if ( !strcmp ( attrName, KScrolling ) ) |
|
324 { |
|
325 throwIfNot ( aAttr.type() == AlfAttributeValueType::EString ); |
|
326 |
|
327 if ( !strcmp ( aAttr.stringValue().getUtf8(), "true" ) ) |
|
328 { |
|
329 TRAPD(err, layout->EnableScrollingL () ); |
|
330 throwIfNot (err==KErrNone); |
|
331 } |
|
332 else |
|
333 { |
|
334 TRAPD(err, layout->EnableScrollingL ( false ) ); |
|
335 throwIfNot (err==KErrNone); |
|
336 } |
|
337 } |
|
338 else if ( !strcmp ( attrName, KLayoutScrollOffsetX )||!strcmp ( attrName, KLayoutScrollOffsetY ) ) |
|
339 { |
|
340 AlfAttribute& attrY = aContainer.getAttributeByName ( KLayoutScrollOffsetY ); |
|
341 AlfAttribute& attrX = aContainer.getAttributeByName ( KLayoutScrollOffsetX ); |
|
342 |
|
343 TAlfTimedPoint point ( attrX.realValue(), attrY.realValue() ); |
|
344 |
|
345 layout->SetScrollOffset ( point ); |
|
346 attrX.setDirty(false); |
|
347 attrY.setDirty(false); |
|
348 } |
|
349 else |
|
350 { |
|
351 AlfCommonVisualAttributeSetter::handleStaticAttribute(aVisual, aAttr, aContainer); |
|
352 } |
|
353 } |
|
354 |
|
355 void AlfCommonLayoutAttributeSetter::handleDynamicAttribute( CAlfVisual &aVisual, AlfAttribute& aAttr, |
|
356 AlfAttributeContainer& aContainer) |
|
357 { |
|
358 AlfCommonVisualAttributeSetter::handleDynamicAttribute( |
|
359 aVisual, aAttr, aContainer); |
|
360 } |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // --------------------------------------------------------------------------- |
|
364 // |
|
365 OSN_EXPORT TAlfCommand* AlfCommonLayoutAttributeSetter::createCommand ( |
|
366 CAlfVisual& aVisual, AlfAttributeContainer* aContainer, |
|
367 IAlfMap* aData, int aTransitionTime, CAlfVisual* aRefVisual ) |
|
368 { |
|
369 TAlfCommand* cmd = 0; |
|
370 cmd = AlfCommonVisualAttributeSetter::createCommand ( |
|
371 aVisual, |
|
372 aContainer, |
|
373 aData, |
|
374 aTransitionTime, |
|
375 aRefVisual ); |
|
376 return cmd; |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 OSN_EXPORT void AlfCommonLayoutAttributeSetter::createAndSendCommands ( |
|
383 CAlfVisual& aVisual, |
|
384 AlfAttributeContainer* aContainer, |
|
385 CAlfVisual* aRefVisual ) |
|
386 { |
|
387 |
|
388 unsigned int attrCount = aContainer->attributeCount(); |
|
389 |
|
390 for ( int i = 0; i < attrCount; ++i ) |
|
391 { |
|
392 AlfAttribute* attrib = & ( aContainer->getAttribute ( i ) ); |
|
393 const char* attrName = attrib->name(); |
|
394 |
|
395 if (strcmp ( attrName, KBaseUnitX )&&strcmp ( attrName, KBaseUnitY ) |
|
396 &&strcmp ( attrName, KUpdateLayoutTime )&&strcmp ( attrName, KTransitionTime ) |
|
397 &&strcmp ( attrName, KAutomaticLocaleMirroring )&&strcmp ( attrName, KInnerPaddingHoriz ) |
|
398 &&strcmp ( attrName, KInnerPaddingVertical )) |
|
399 { |
|
400 // Call the base class implementation also. |
|
401 // It goes through the same loop again and checks if there are attributes |
|
402 // that it handles. |
|
403 AlfCommonVisualAttributeSetter::createAndSendCommands ( |
|
404 aVisual, |
|
405 aContainer, |
|
406 aRefVisual ); |
|
407 } |
|
408 } |
|
409 } |
|
410 |
|
411 |
|
412 } // Alf |
|