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: File implements the atrributesetters for the flowlayout. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //includes |
|
21 |
|
22 //widget model includes |
|
23 #include "alf/alfattributecontainer.h" |
|
24 #include "alf/alfattribute.h" |
|
25 #include "alf/alfflowlayoutattributesetter.h" |
|
26 #include <alf/alfvisualexception.h> |
|
27 #include <alf/alfdataexception.h> |
|
28 #include <alf/alfattributeexception.h> |
|
29 |
|
30 //osn includes |
|
31 #include <osn/ustring.h> |
|
32 |
|
33 //alf includes |
|
34 #include <alf/alfvisual.h> |
|
35 #include <alf/alfflowlayout.h> |
|
36 |
|
37 //dui includes |
|
38 #include "alf/attrproperty.h" |
|
39 |
|
40 //other includes |
|
41 #include <libc/string.h> |
|
42 |
|
43 |
|
44 |
|
45 //namespaces |
|
46 using namespace osncore; |
|
47 using namespace duiuimodel::layoutattributes; |
|
48 |
|
49 namespace Alf |
|
50 { |
|
51 |
|
52 // ======== MEMBER FUNCTIONS ======== |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // Constructor. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 OSN_EXPORT AlfFlowLayoutAttributeSetter::AlfFlowLayoutAttributeSetter() |
|
59 { |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Destructor. |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 OSN_EXPORT AlfFlowLayoutAttributeSetter::~AlfFlowLayoutAttributeSetter() |
|
67 { |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Sets Attribute Value. Delegates based on attribute Category. |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 OSN_EXPORT void AlfFlowLayoutAttributeSetter::setAttributeValue ( |
|
75 CAlfVisual &aVisual, |
|
76 AlfAttributeContainer* aContainer, |
|
77 IAlfMap* aData ) |
|
78 { |
|
79 // Ensure that the visual is a flow layout |
|
80 CAlfFlowLayout* flowLayout = dynamic_cast<CAlfFlowLayout*>(&aVisual); |
|
81 if (!flowLayout) |
|
82 { |
|
83 ALF_THROW ( AlfVisualException, EInvalidVisual, "AlfFlowLayoutAttributeSetter"); |
|
84 } |
|
85 AlfCommonLayoutAttributeSetter::setAttributeValue(aVisual, |
|
86 aContainer, aData); |
|
87 } |
|
88 // --------------------------------------------------------------------------- |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 OSN_EXPORT TAlfCommand* AlfFlowLayoutAttributeSetter::createCommand( |
|
92 CAlfVisual& /*aVisual*/, AlfAttributeContainer* /*aContainer*/, |
|
93 IAlfMap* /*aData*/, int /*aTransitionTime*/, CAlfVisual* /*aRefVisual*/) |
|
94 { |
|
95 TAlfCommand* cmd = 0; |
|
96 return cmd; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 OSN_EXPORT void AlfFlowLayoutAttributeSetter::createAndSendCommands( |
|
103 CAlfVisual& aVisual, |
|
104 AlfAttributeContainer* aContainer, |
|
105 CAlfVisual* aRefVisual ) |
|
106 { |
|
107 // Flow layout does not have any specific API which takes timed value. |
|
108 // So, call the base class implementation. It goes through its loop and |
|
109 // checks if there are attributes that it handles. |
|
110 AlfCommonLayoutAttributeSetter::createAndSendCommands(aVisual,aContainer, |
|
111 aRefVisual); |
|
112 } |
|
113 |
|
114 void AlfFlowLayoutAttributeSetter::handleDynamicDataAttribute ( |
|
115 CAlfVisual& aVisual, AlfAttribute& aAttr, |
|
116 AlfAttributeContainer& aContainer, IAlfMap* aData) |
|
117 { |
|
118 // Flow Layout does not have any specific dynamic attribute, so call the |
|
119 // base class implementation. It goes through its loop and checks if there |
|
120 // are attributes that it handles. |
|
121 AlfCommonLayoutAttributeSetter::handleDynamicDataAttribute(aVisual, aAttr, |
|
122 aContainer, aData); |
|
123 } |
|
124 |
|
125 void AlfFlowLayoutAttributeSetter::handleStaticDataAttribute( |
|
126 CAlfVisual &aVisual, AlfAttribute& aAttr, |
|
127 AlfAttributeContainer& aContainer, IAlfMap* aData) |
|
128 { |
|
129 if (!aData) ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfFlowLayoutAttributeSetter" ) |
|
130 |
|
131 const char* dataField = aAttr.getDataField(); |
|
132 if ( !dataField ) ALF_THROW ( AlfDataException, EInvalidAttribute, "AlfFlowLayoutAttributeSetter" ) |
|
133 |
|
134 IAlfVariantType* data = aData->item ( UString(dataField)); |
|
135 if (data) |
|
136 { |
|
137 const char* attrName = aAttr.name(); |
|
138 CAlfFlowLayout* flowLayout = dynamic_cast<CAlfFlowLayout*>(&aVisual); |
|
139 if (!flowLayout) |
|
140 { |
|
141 ALF_THROW ( AlfVisualException, EInvalidVisual, "AlfFlowLayoutAttributeSetter"); |
|
142 } |
|
143 |
|
144 if (!strcmp(attrName,flow::KFlowDirection)) |
|
145 { |
|
146 if (data->type() == IAlfVariantType::EInt) |
|
147 { |
|
148 int direction = data->integer(); |
|
149 flowLayout->SetFlowDirection( |
|
150 (CAlfFlowLayout::TFlowDirection)direction); |
|
151 } |
|
152 else |
|
153 { |
|
154 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfFlowLayoutAttributeSetter"); |
|
155 } |
|
156 } |
|
157 else if (!strcmp(attrName,flow::KLayoutMode)) |
|
158 { |
|
159 if (data->type() == IAlfVariantType::EInt) |
|
160 { |
|
161 int layoutMode = data->integer(); |
|
162 flowLayout->SetMode(layoutMode); |
|
163 } |
|
164 else |
|
165 { |
|
166 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfFlowLayoutAttributeSetter"); |
|
167 } |
|
168 } |
|
169 else if (!strcmp(attrName,flow::KLayoutCentering)) |
|
170 { |
|
171 if (data->type() == IAlfVariantType::EBool) |
|
172 { |
|
173 TBool layoutCentering = data->boolean(); |
|
174 flowLayout->SetCentering(layoutCentering); |
|
175 } |
|
176 else |
|
177 { |
|
178 ALF_THROW ( AlfDataException, EInvalidVariantDataType, "AlfFlowLayoutAttributeSetter"); |
|
179 } |
|
180 } |
|
181 else |
|
182 { |
|
183 // Call the base class implementation . |
|
184 // It goes through its loop and checks if there are attributes |
|
185 // that it handles. |
|
186 AlfCommonLayoutAttributeSetter::handleStaticDataAttribute(aVisual, |
|
187 aAttr, aContainer, aData); |
|
188 } |
|
189 } |
|
190 return; |
|
191 } |
|
192 |
|
193 void AlfFlowLayoutAttributeSetter::handleDynamicAttribute( |
|
194 CAlfVisual &aVisual, AlfAttribute& aAttr, |
|
195 AlfAttributeContainer& aContainer) |
|
196 { |
|
197 // Flow Layout does not have any specific dynamic attribute, so call the |
|
198 // base class implementation also. It goes through its loop and checks if |
|
199 // there are attributes that it handles. |
|
200 AlfCommonLayoutAttributeSetter::handleDynamicAttribute(aVisual, aAttr, |
|
201 aContainer); |
|
202 } |
|
203 |
|
204 void AlfFlowLayoutAttributeSetter::handleStaticAttribute( |
|
205 CAlfVisual& aVisual, AlfAttribute& aAttr, |
|
206 AlfAttributeContainer& aContainer) |
|
207 { |
|
208 CAlfFlowLayout* flowLayout = dynamic_cast<CAlfFlowLayout*>(&aVisual); |
|
209 if (!flowLayout) |
|
210 { |
|
211 ALF_THROW ( AlfVisualException, EInvalidVisual, "AlfFlowLayoutAttributeSetter"); |
|
212 } |
|
213 |
|
214 const char* attrName = aAttr.name(); |
|
215 |
|
216 if (!strcmp(attrName, flow::KFlowDirection)) |
|
217 { |
|
218 if(aAttr.type() == AlfAttributeValueType::EInt) |
|
219 { |
|
220 int direction = aAttr.intValue(); |
|
221 flowLayout->SetFlowDirection( |
|
222 (CAlfFlowLayout::TFlowDirection)direction); |
|
223 } |
|
224 else |
|
225 { |
|
226 ALF_THROW ( AlfAttributeException, EInvalidAttributeValue, "AlfFlowLayoutAttributeSetter"); |
|
227 } |
|
228 } |
|
229 else if (!strcmp(attrName, flow::KLayoutMode)) |
|
230 { |
|
231 if (aAttr.type() == AlfAttributeValueType::EInt) |
|
232 { |
|
233 int layoutMode = aAttr.intValue(); |
|
234 flowLayout->SetMode(layoutMode); |
|
235 } |
|
236 else |
|
237 { |
|
238 ALF_THROW ( AlfAttributeException, EInvalidAttributeValue, "AlfFlowLayoutAttributeSetter"); |
|
239 } |
|
240 } |
|
241 else if (!strcmp(attrName, flow::KLayoutCentering)) |
|
242 { |
|
243 if (aAttr.type() == AlfAttributeValueType::EInt) |
|
244 { |
|
245 int layoutCentering = aAttr.intValue(); |
|
246 TBool flag=ETrue; //Assume true for any non-zero value. |
|
247 if (0==layoutCentering) flag=EFalse; |
|
248 flowLayout->SetCentering(flag); |
|
249 } |
|
250 else |
|
251 { |
|
252 ALF_THROW ( AlfAttributeException, EInvalidAttributeValue, "AlfFlowLayoutAttributeSetter"); |
|
253 } |
|
254 } |
|
255 else // Call the base class implementation also. |
|
256 // It goes through the same loop again and checks if there are |
|
257 // attributes that it handles. |
|
258 { |
|
259 AlfCommonLayoutAttributeSetter::handleStaticAttribute(aVisual, aAttr, |
|
260 aContainer); |
|
261 } |
|
262 return; |
|
263 } |
|
264 |
|
265 } // Alf |
|
266 |
|
267 |
|