|
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 attributesetters for anchorlayout. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //includes |
|
21 |
|
22 //widget model includes |
|
23 #include "alf/alfattributecontainer.h" |
|
24 #include "alf/alfattributevaluetype.h" |
|
25 #include "alf/alfattribute.h" |
|
26 #include "alf/alfanchorlayoutattributesetter.h" |
|
27 #include <alf/alfvisualexception.h> |
|
28 #include <alf/alfdataexception.h> |
|
29 #include <alf/alfattributeexception.h> |
|
30 |
|
31 |
|
32 //osn includes |
|
33 #include <osn/ustring.h> |
|
34 |
|
35 //alf includes |
|
36 #include <alf/alfenv.h> |
|
37 #include <alf/alfanchorlayout.h> |
|
38 #include <alf/alftexture.h> |
|
39 #include <alf/alfeventhandler.h> |
|
40 #include <alf/alfevent.h> |
|
41 |
|
42 //dui includes |
|
43 #include "alf/attrproperty.h" |
|
44 |
|
45 //other includes |
|
46 #include <libc/string.h> |
|
47 #include <utf.h> |
|
48 |
|
49 |
|
50 |
|
51 //namespaces |
|
52 |
|
53 using namespace osncore; |
|
54 |
|
55 using namespace duiuimodel::anchorlayoutinput; |
|
56 |
|
57 using namespace duiuimodel::layoutattributes; |
|
58 |
|
59 using namespace duiuimodel::anchor; |
|
60 |
|
61 using namespace duiuimodel::metric; |
|
62 |
|
63 namespace Alf |
|
64 { |
|
65 |
|
66 bool isMultivalueDataAchment ( TAlfAnchorAttachmentOrigin val ) |
|
67 { |
|
68 return ( val == EAlfAnchorAttachmentOriginNone|| |
|
69 val == EAlfAnchorAttachmentOriginTopLeft || |
|
70 val == EAlfAnchorAttachmentOriginTopCenter || |
|
71 val == EAlfAnchorAttachmentOriginTopRight || |
|
72 val == EAlfAnchorAttachmentOriginCenterLeft || |
|
73 val == EAlfAnchorAttachmentOriginCenter || |
|
74 val == EAlfAnchorAttachmentOriginCenterRight || |
|
75 val == EAlfAnchorAttachmentOriginBottomLeft || |
|
76 val == EAlfAnchorAttachmentOriginBottomCenter || |
|
77 val == EAlfAnchorAttachmentOriginBottomRight ); |
|
78 } |
|
79 |
|
80 typedef void ( *pFunc ) ( AlfContainer* aCont, AlfAttribute* aAttrib, IAlfMap* aData ); |
|
81 |
|
82 void addToAnchortypecont ( AlfContainer* aCont, AlfAttribute* aAttrib, IAlfMap* aData ) |
|
83 { |
|
84 |
|
85 if ( aData ) |
|
86 { |
|
87 IAlfVariantType* dataX = aData->item ( UString(aAttrib->getDataField() )); |
|
88 |
|
89 if ( dataX && dataX->type() == IAlfVariantType::EInt ) |
|
90 { |
|
91 aCont->addItem ( new ( EMM ) AlfVariantType ( dataX->integer() ) ); |
|
92 } |
|
93 } |
|
94 else |
|
95 { |
|
96 aCont->addItem ( new ( EMM ) AlfVariantType ( aAttrib->intValue() ) ); |
|
97 } |
|
98 |
|
99 } |
|
100 |
|
101 void addToAttachmentcont ( AlfContainer* aCont, AlfAttribute* aAttrib, IAlfMap* aData ) |
|
102 { |
|
103 |
|
104 if ( aData ) |
|
105 { |
|
106 IAlfVariantType* dataX = aData->item ( UString(aAttrib->getDataField())); |
|
107 |
|
108 if ( dataX && dataX->type() == IAlfVariantType::EInt ) |
|
109 { |
|
110 aCont->addItem ( new ( EMM ) AlfVariantType ( dataX->integer() ) ); |
|
111 } |
|
112 } |
|
113 else |
|
114 { |
|
115 aCont->addItem ( new ( EMM ) AlfVariantType ( aAttrib->intValue() ) ); |
|
116 } |
|
117 } |
|
118 |
|
119 void addToMagnitudecont ( AlfContainer* aCont, AlfAttribute* aAttrib, IAlfMap* aData ) |
|
120 { |
|
121 |
|
122 if ( aData ) |
|
123 { |
|
124 IAlfVariantType* dataX = aData->item ( UString(aAttrib->getDataField()) ); |
|
125 |
|
126 if ( dataX != NULL && dataX->type() == IAlfVariantType::EMap ) |
|
127 { |
|
128 IAlfVariantType* valueX = dataX->map()->item ( UString("value")); |
|
129 IAlfVariantType* unitX = dataX->map()->item ( UString("unit")); |
|
130 auto_ptr<AlfContainer> value ( new ( EMM ) AlfContainer() ); |
|
131 auto_ptr<AlfVariantType> vtype1(new ( EMM ) AlfVariantType ( valueX->real() )); |
|
132 value->addItem ( vtype1.get() ); |
|
133 vtype1.release(); |
|
134 auto_ptr<AlfVariantType> vtype2(new ( EMM ) AlfVariantType ( unitX->integer() )); |
|
135 value->addItem ( vtype2.get() ); |
|
136 vtype2.release(); |
|
137 aCont->addItem ( value.release() ); |
|
138 |
|
139 } |
|
140 else if ( dataX != NULL && dataX->type() == IAlfVariantType::EReal ) |
|
141 { |
|
142 auto_ptr<AlfContainer> value ( new ( EMM ) AlfContainer() ); |
|
143 auto_ptr<AlfVariantType> vtype1(new ( EMM ) AlfVariantType ( dataX->real() )); |
|
144 value->addItem ( vtype1.get() ); |
|
145 vtype1.release(); |
|
146 auto_ptr<AlfVariantType> vtype2( new ( EMM ) AlfVariantType ( aAttrib->unit() ) ); |
|
147 |
|
148 value->addItem (vtype2.get()); |
|
149 vtype2.release(); |
|
150 aCont->addItem ( value.release() ); |
|
151 } |
|
152 } |
|
153 else |
|
154 { |
|
155 auto_ptr<AlfContainer> value ( new ( EMM ) AlfContainer() ); |
|
156 auto_ptr<AlfVariantType> vtype1( new ( EMM ) AlfVariantType ( aAttrib->realValue() ) ); |
|
157 value->addItem (vtype1.get()); |
|
158 vtype1.release(); |
|
159 auto_ptr<AlfVariantType> vtype2( new ( EMM ) AlfVariantType ( aAttrib->unit() ) ); |
|
160 |
|
161 value->addItem (vtype2.get()); |
|
162 vtype2.release(); |
|
163 aCont->addItem ( value.release() ); |
|
164 |
|
165 } |
|
166 |
|
167 } |
|
168 |
|
169 void addToTextstylecont ( AlfContainer* /*aCont*/, AlfAttribute* /*aAttrib*/, IAlfMap* /*aData*/ ) |
|
170 { |
|
171 } |
|
172 |
|
173 struct anchormap |
|
174 { |
|
175 const char* name; |
|
176 pFunc addToContainer; |
|
177 AlfContainer* pData; |
|
178 }; |
|
179 |
|
180 // ======== MEMBER FUNCTIONS ======== |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // Constructor. |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 OSN_EXPORT AlfAnchorLayoutAttributeSetter::AlfAnchorLayoutAttributeSetter() |
|
187 { |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // Destructor. |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 OSN_EXPORT AlfAnchorLayoutAttributeSetter::~AlfAnchorLayoutAttributeSetter() |
|
195 { |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // Sets Attribute Value. Delegates based on attribute Category. |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 OSN_EXPORT void AlfAnchorLayoutAttributeSetter::setAttributeValue ( |
|
203 CAlfVisual &aVisual, |
|
204 AlfAttributeContainer* aContainer, |
|
205 IAlfMap* aData ) |
|
206 { |
|
207 |
|
208 CAlfAnchorLayout* layout = dynamic_cast<CAlfAnchorLayout*> ( &aVisual ); |
|
209 |
|
210 if ( !layout ) |
|
211 { |
|
212 ALF_THROW ( AlfVisualException, EInvalidVisual, |
|
213 "AlfAnchorLayoutAttributeSetter" ) |
|
214 } |
|
215 |
|
216 AlfCommonLayoutAttributeSetter::setAttributeValue(aVisual, |
|
217 aContainer, aData); |
|
218 } |
|
219 |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // Deprecated |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 OSN_EXPORT TAlfCommand* AlfAnchorLayoutAttributeSetter::createCommand ( CAlfVisual& /*aVisual*/, |
|
226 AlfAttributeContainer* /*aContainer*/, IAlfMap* /*aData*/, |
|
227 int /*aTransitionTime*/, CAlfVisual* /*aRefVisual*/ ) |
|
228 { |
|
229 //deprecated |
|
230 TAlfCommand* cmd = NULL; |
|
231 return cmd; |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // Sends a command to Env |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 OSN_EXPORT void AlfAnchorLayoutAttributeSetter::createAndSendCommands ( |
|
239 CAlfVisual& aVisual, |
|
240 AlfAttributeContainer* aContainer, |
|
241 CAlfVisual* aRefVisual ) |
|
242 { |
|
243 //no animatable attributes in grid layout. |
|
244 AlfCommonLayoutAttributeSetter::createAndSendCommands ( aVisual, aContainer, aRefVisual ); |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // Sets dynamic attributes to visual |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 void AlfAnchorLayoutAttributeSetter::handleDynamicAttribute ( CAlfVisual &aVisual, AlfAttribute& aAttr, AlfAttributeContainer& aContainer ) |
|
252 { |
|
253 //no dynamic attributes in anchor layout. |
|
254 AlfCommonLayoutAttributeSetter::handleDynamicAttribute(aVisual, aAttr, aContainer); |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // Sets static attributes to visual |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 void AlfAnchorLayoutAttributeSetter::handleStaticAttribute ( |
|
262 CAlfVisual &aVisual, AlfAttribute& aAttr, AlfAttributeContainer& aContainer ) |
|
263 { |
|
264 if (!doHandleStaticAttribute(aVisual, aAttr, aContainer, NULL)) |
|
265 { |
|
266 AlfCommonLayoutAttributeSetter::handleStaticAttribute(aVisual, aAttr, aContainer); |
|
267 } |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // Sets static attributes to visual |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 bool AlfAnchorLayoutAttributeSetter::doHandleStaticAttribute( CAlfVisual &aVisual, |
|
275 AlfAttribute& aAttr, AlfAttributeContainer& aContainer, IAlfMap* aData ) |
|
276 { |
|
277 bool handled = true; |
|
278 const char* attrName = aAttr.name(); |
|
279 CAlfAnchorLayout* layout = dynamic_cast<CAlfAnchorLayout*> ( &aVisual ); |
|
280 if(!layout) |
|
281 { |
|
282 return false; |
|
283 } |
|
284 |
|
285 if ( !strcmp ( attrName, KChildOrdinal )||!strcmp ( attrName, KAttachmentOrdinal ) |
|
286 || !strcmp ( attrName, KAnchorType )||!strcmp ( attrName, KAttachmentOrigin ) |
|
287 ||!strcmp ( attrName, KMagnitude )||!strcmp ( attrName, KTextStyleId ) ) |
|
288 { |
|
289 AlfAttribute& attachmentordinal = aContainer.getAttributeByName ( KAttachmentOrdinal ); |
|
290 AlfAttribute& aAttrChildOrdinal = aContainer.getAttributeByName ( KChildOrdinal ); |
|
291 float ordianal=0; |
|
292 float attachordinalval=-1; |
|
293 if(aData) |
|
294 { |
|
295 IAlfVariantType* data = aData->item ( UString(aAttrChildOrdinal.getDataField()) ); |
|
296 |
|
297 if ( data && data->type() == IAlfVariantType::EReal ) |
|
298 { |
|
299 ordianal=data->real(); |
|
300 } |
|
301 data = aData->item ( UString(attachmentordinal.getDataField()) ); |
|
302 if ( data && data->type() == IAlfVariantType::EReal ) |
|
303 { |
|
304 attachordinalval=data->real(); |
|
305 } |
|
306 } |
|
307 else |
|
308 { |
|
309 ordianal=aAttrChildOrdinal.realValue(); |
|
310 attachordinalval=attachmentordinal.realValue(); |
|
311 } |
|
312 auto_ptr<AlfContainer> anchortypecont ( new ( EMM ) AlfContainer() ); |
|
313 auto_ptr<AlfContainer> attachmentorigincont ( new ( EMM ) AlfContainer() ); |
|
314 auto_ptr<AlfContainer> magnitudecont ( new ( EMM ) AlfContainer() ); |
|
315 auto_ptr<AlfContainer> textstyleidcont ( new ( EMM ) AlfContainer() ); |
|
316 |
|
317 anchormap maptable[] = |
|
318 { |
|
319 {KAnchorType, addToAnchortypecont, NULL}, |
|
320 {KAttachmentOrigin, addToAttachmentcont, NULL}, |
|
321 {KMagnitude, addToMagnitudecont, NULL}, |
|
322 {KTextStyleId, addToTextstylecont, NULL} |
|
323 }; |
|
324 unsigned int tableCount = sizeof ( maptable ) / sizeof ( anchormap ); |
|
325 maptable[0].pData = anchortypecont.get(); |
|
326 maptable[1].pData = attachmentorigincont.get(); |
|
327 maptable[2].pData = magnitudecont.get(); |
|
328 maptable[3].pData = textstyleidcont.get(); |
|
329 |
|
330 unsigned int attrCount = aContainer.attributeCount(); |
|
331 |
|
332 for ( int i = 0;i < attrCount;i++ ) |
|
333 { |
|
334 for ( int j = 0;j < tableCount;j++ ) |
|
335 { |
|
336 if ( !strcmp ( maptable[j].name, aContainer.getAttribute ( i ).name() ) ) |
|
337 { |
|
338 maptable[j].addToContainer ( maptable[j].pData, &aContainer.getAttribute ( i ), aData ); |
|
339 aContainer.getAttribute ( i ).setDirty(false); |
|
340 } |
|
341 } |
|
342 } |
|
343 |
|
344 unsigned int totalApitocall = attachmentorigincont->count(); |
|
345 |
|
346 unsigned int magnitudeindex = 0; |
|
347 |
|
348 for ( int counter = 0;counter < totalApitocall;counter++ ) |
|
349 { |
|
350 IAlfVariantType* Origin = attachmentorigincont->item ( counter ); |
|
351 TAlfAnchorAttachmentOrigin value = static_cast<TAlfAnchorAttachmentOrigin> ( Origin->integer() ); |
|
352 |
|
353 if ( isMultivalueDataAchment ( value ) ) |
|
354 { |
|
355 IAlfVariantType* aType = anchortypecont->item ( counter ); |
|
356 TAlfAnchorType type = static_cast<TAlfAnchorType> ( aType->integer() ); |
|
357 |
|
358 if ( type == EAlfAnchorTypeNone ) |
|
359 { |
|
360 IAlfContainer* magCont1 = static_cast<IAlfContainer*> ( magnitudecont->item ( magnitudeindex ) ); |
|
361 IAlfContainer* magCont2 = static_cast<IAlfContainer*> ( magnitudecont->item ( magnitudeindex + 1 ) ); |
|
362 IAlfContainer* magCont3 = static_cast<IAlfContainer*> ( magnitudecont->item ( magnitudeindex + 2 ) ); |
|
363 IAlfContainer* magCont4 = static_cast<IAlfContainer*> ( magnitudecont->item ( magnitudeindex + 3 ) ); |
|
364 |
|
365 TAlfMetric metric1 ( magCont1->item ( 0 )->real(), magCont1->item ( 1 )->integer() ); |
|
366 TAlfMetric metric2 ( magCont2->item ( 0 )->real(), magCont2->item ( 1 )->integer() ); |
|
367 TAlfMetric metric3 ( magCont3->item ( 0 )->real(), magCont3->item ( 1 )->integer() ); |
|
368 TAlfMetric metric4 ( magCont4->item ( 0 )->real(), magCont4->item ( 1 )->integer() ); |
|
369 TAlfBoxMetric boxmetric ( metric1, metric2, metric3, metric4 ); |
|
370 int err=layout->Attach ( ordianal, boxmetric, value, attachordinalval ); |
|
371 if(err!=KErrNone) |
|
372 { |
|
373 ALF_THROW ( AlfVisualException, err, "Anchor Attach Failed" ) |
|
374 } |
|
375 magnitudeindex += 4; |
|
376 } |
|
377 else |
|
378 { |
|
379 IAlfContainer* magCont1 = static_cast<IAlfContainer*> ( magnitudecont->item ( magnitudeindex ) ); |
|
380 IAlfContainer* magCont2 = static_cast<IAlfContainer*> ( magnitudecont->item ( magnitudeindex + 1 ) ); |
|
381 |
|
382 TAlfMetric metric1 ( magCont1->item ( 0 )->real(), magCont1->item ( 1 )->integer() ); |
|
383 TAlfMetric metric2 ( magCont2->item ( 0 )->real(), magCont2->item ( 1 )->integer() ); |
|
384 |
|
385 |
|
386 |
|
387 TAlfXYMetric xymetric ( metric1, metric2 ); |
|
388 |
|
389 int err=layout->Attach ( ordianal, type, xymetric, value, attachordinalval ); |
|
390 if(err!=KErrNone) |
|
391 { |
|
392 ALF_THROW ( AlfVisualException, err, "Anchor Attach Failed" ) |
|
393 } |
|
394 |
|
395 magnitudeindex += 2; |
|
396 } |
|
397 } |
|
398 else |
|
399 { |
|
400 IAlfVariantType* typeVar = anchortypecont->item ( counter ); |
|
401 TAlfAnchorType type = static_cast<TAlfAnchorType> ( typeVar->integer() ); |
|
402 IAlfContainer* magCont1 = static_cast<IAlfContainer*> ( magnitudecont->item ( magnitudeindex ) ); |
|
403 |
|
404 TAlfMetric metric ( magCont1->item ( 0 )->real(), magCont1->item ( 1 )->integer() ); |
|
405 |
|
406 |
|
407 int err=layout->Attach ( ordianal, type, metric, value, attachordinalval ); |
|
408 if(err!=KErrNone) |
|
409 { |
|
410 ALF_THROW ( AlfVisualException, err, "Anchor Attach Failed" ) |
|
411 } |
|
412 |
|
413 magnitudeindex++; |
|
414 } |
|
415 } |
|
416 |
|
417 attachmentordinal.setDirty(false); |
|
418 aAttrChildOrdinal.setDirty(false); |
|
419 } |
|
420 else |
|
421 { |
|
422 handled = false; |
|
423 } |
|
424 |
|
425 return handled; |
|
426 } |
|
427 |
|
428 |
|
429 // --------------------------------------------------------------------------- |
|
430 // Sets dynamic attributes to visual from data |
|
431 // --------------------------------------------------------------------------- |
|
432 // |
|
433 void AlfAnchorLayoutAttributeSetter::handleDynamicDataAttribute ( CAlfVisual &aVisual, AlfAttribute& aAttr, AlfAttributeContainer& aContainer, IAlfMap* aData ) |
|
434 { |
|
435 AlfCommonLayoutAttributeSetter::handleDynamicDataAttribute ( aVisual, aAttr, aContainer, aData ); |
|
436 } |
|
437 |
|
438 // --------------------------------------------------------------------------- |
|
439 // Sets static attributes to visual from data |
|
440 // --------------------------------------------------------------------------- |
|
441 // |
|
442 void AlfAnchorLayoutAttributeSetter::handleStaticDataAttribute ( CAlfVisual &aVisual, AlfAttribute& aAttr, AlfAttributeContainer& aContainer, IAlfMap* aData ) |
|
443 { |
|
444 if (!doHandleStaticAttribute(aVisual, aAttr, aContainer, aData)) |
|
445 { |
|
446 AlfCommonLayoutAttributeSetter::handleStaticDataAttribute(aVisual, aAttr, aContainer, aData); |
|
447 } |
|
448 } |
|
449 |
|
450 } // namespace Alf |
|
451 |
|
452 // End of file |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |