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: This class implements common attribute setters. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <libc/string.h> |
|
20 #include <utf.h> |
|
21 |
|
22 #include <osn/ustring.h> |
|
23 #include <stdexcept> |
|
24 #include "alf/attrproperty.h" |
|
25 |
|
26 #include "alf/alfattribute.h" |
|
27 #include "alf/alfcommonattributesetter.h" |
|
28 #include <alf/alfvisual.h> |
|
29 #include <alf/alfattributeexception.h> |
|
30 #include "alf/alfattributecontainer.h" |
|
31 |
|
32 using namespace duiuimodel::commonattributes; |
|
33 |
|
34 namespace Alf |
|
35 { |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Constructor. |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 OSN_EXPORT AlfCommonAttributeSetter::AlfCommonAttributeSetter() |
|
44 { |
|
45 mDoDirtycheck=false; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Destructor. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 OSN_EXPORT AlfCommonAttributeSetter::~AlfCommonAttributeSetter() |
|
53 { |
|
54 |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Returns the type of the attribute setter. |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 OSN_EXPORT SetterType AlfCommonAttributeSetter::setterType() |
|
62 { |
|
63 return ECustomAttributeSetter; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Sets an attribute value in the target visual immediately |
|
68 // without a transition. |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 OSN_EXPORT void AlfCommonAttributeSetter::setAttributeValue( |
|
72 CAlfVisual &aVisual, |
|
73 AlfAttributeContainer* aContainer, |
|
74 IAlfMap* aData) |
|
75 { |
|
76 if (!aContainer) |
|
77 { |
|
78 ALF_THROW ( AlfAttributeException, EInvalidAttribute, |
|
79 "AlfCommonAttributeSetter" ) |
|
80 } |
|
81 |
|
82 unsigned int attrCount = aContainer->attributeCount(); |
|
83 for (int i=0; i<attrCount; ++i) |
|
84 { |
|
85 AlfAttribute& attr = aContainer->getAttribute(i); |
|
86 const char* attrName = attr.name(); |
|
87 |
|
88 if (attr.category() == AlfAttribute::EStaticData) |
|
89 { |
|
90 handleStaticDataAttribute(aVisual, attr, *aContainer, aData); |
|
91 } |
|
92 else if (attr.category() == AlfAttribute::EDynamicData) |
|
93 { |
|
94 handleDynamicDataAttribute(aVisual, attr, *aContainer, aData); |
|
95 } |
|
96 else if (attr.category() == AlfAttribute::EStatic) |
|
97 { |
|
98 if ((mDoDirtycheck&&attr.isDirty())||!mDoDirtycheck) |
|
99 { |
|
100 handleStaticAttribute(aVisual, attr, *aContainer); |
|
101 } |
|
102 attr.setDirty(false); |
|
103 |
|
104 } |
|
105 else if (attr.category() == AlfAttribute::EDynamic) |
|
106 { |
|
107 if ((mDoDirtycheck&&attr.isDirty())||!mDoDirtycheck) |
|
108 { |
|
109 handleDynamicAttribute(aVisual, attr, *aContainer); |
|
110 } |
|
111 attr.setDirty(false); |
|
112 |
|
113 } |
|
114 } |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // Creates a command to change the value of an attribute in the target visual. |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 OSN_EXPORT TAlfCommand* AlfCommonAttributeSetter::createCommand( |
|
122 CAlfVisual& /*aVisual*/, AlfAttributeContainer* /*aContainer*/, |
|
123 IAlfMap* /*aData*/, int /*aTransitionTime*/, CAlfVisual* /*aRefVisual*/) |
|
124 { |
|
125 // No need to implement. |
|
126 TAlfCommand* cmd = 0; |
|
127 return cmd; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // Creates commands to change the given attribute values in the target visual. |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 OSN_EXPORT void AlfCommonAttributeSetter::createAndSendCommands( |
|
135 CAlfVisual& /*aVisual*/, AlfAttributeContainer* /*aContainer*/, |
|
136 CAlfVisual* /*aRefVisual*/) |
|
137 { |
|
138 // No need to implement. |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // Getter for interfaces provided by the element classes. |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 OSN_EXPORT IAlfInterfaceBase* AlfCommonAttributeSetter::makeInterface( |
|
146 const IfId& aType) |
|
147 { |
|
148 UString param(aType.mImplementationId); |
|
149 if (param == IAlfAttributeSetter::type().mImplementationId) |
|
150 { |
|
151 return this; |
|
152 } |
|
153 return NULL; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // Converts text between Unicode (UCS-2) and the Unicode transformation |
|
158 // format UTF-8. |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 HBufC* AlfCommonAttributeSetter::convertToUnicodeFromUtf8( |
|
162 const TPtrC8& aSrc) const |
|
163 { |
|
164 HBufC* desValue = 0; |
|
165 TRAPD( err, desValue = CnvUtfConverter::ConvertToUnicodeFromUtf8L(aSrc)) |
|
166 if (err != KErrNone) |
|
167 { |
|
168 ALF_THROW(AlfAttributeException, err,"AlfCommonAttributeSetter") |
|
169 } |
|
170 return desValue; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // Sets a value of a static attribute to target visual immediately |
|
175 // without a transition. |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void AlfCommonAttributeSetter::handleStaticAttribute( |
|
179 CAlfVisual& aVisual, AlfAttribute& aAttr, |
|
180 AlfAttributeContainer& /*aContainer*/) |
|
181 { |
|
182 const char* attrName = aAttr.name(); |
|
183 if (!strcmp(attrName, KId)) |
|
184 { |
|
185 const char* val = aAttr.stringValue().getUtf8(); |
|
186 TPtrC8 src((TUint8*)val); |
|
187 TRAPD(err, aVisual.SetTagL( src )); |
|
188 if (err) |
|
189 { |
|
190 ALF_THROW(AlfAttributeException, err, |
|
191 "AlfCommonAttributeSetter") |
|
192 } |
|
193 } |
|
194 } |
|
195 // --------------------------------------------------------------------------- |
|
196 // Sets a dynamic attribute value in the target visual using transitions |
|
197 // defined in attributes. |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void AlfCommonAttributeSetter::handleDynamicAttribute( |
|
201 CAlfVisual& /*aVisual*/, AlfAttribute& /*aAttr*/, |
|
202 AlfAttributeContainer& /*aContainer*/) |
|
203 { |
|
204 //nothing to do |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // Sets a value for static data attribute in the target visual |
|
209 // immediately without a transition using data in map. |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 void AlfCommonAttributeSetter::handleStaticDataAttribute( |
|
213 CAlfVisual& /*aVisual*/, AlfAttribute& /*aAttr*/, |
|
214 AlfAttributeContainer& /*aContainer*/, IAlfMap* /*aData*/) |
|
215 { |
|
216 //nothing to do |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Sets a value for dynamic data attribute value in the target visual |
|
221 // using transitions and data in map. |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 void AlfCommonAttributeSetter::handleDynamicDataAttribute( |
|
225 CAlfVisual& /*aVisual*/, AlfAttribute& /*aAttr*/, |
|
226 AlfAttributeContainer& /*aContainer*/, IAlfMap* /*aData*/) |
|
227 { |
|
228 //nothing to do |
|
229 } |
|
230 |
|
231 OSN_EXPORT void AlfCommonAttributeSetter::enableDirtyCheck(bool aCheck) |
|
232 { |
|
233 mDoDirtycheck=aCheck; |
|
234 } |
|
235 } // Alf |
|