|
1 /* |
|
2 * Copyright (c) 2002-2004 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: Xuikon property list |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 #include "xnpropertylist.h" |
|
20 #include "xnproperty.h" |
|
21 #include "xnproperty.h" |
|
22 #include "xnpropertycomparator.h" |
|
23 #include "xncomparator.h" |
|
24 #include "xnmap.h" |
|
25 #include "xndomproperty.h" |
|
26 #include "xndompropertyvalue.h" |
|
27 #include "xnpanic.h" |
|
28 |
|
29 // LOCAL CONSTANTS AND MACROS |
|
30 _LIT8( KPseudoClassFocus, "focus" ); |
|
31 _LIT8( KPseudoClassPassiveFocus, "passivefocus" ); |
|
32 _LIT8( KPseudoClassHold, "hold" ); |
|
33 _LIT8( KPseudoClassHover, "hover" ); |
|
34 _LIT8( KPseudoClassLink, "link" ); |
|
35 _LIT8( KPseudoClassVisited, "visited" ); |
|
36 _LIT8( KPseudoClassActive, "active" ); |
|
37 _LIT8( KPseudoClassEdit, "edit" ); |
|
38 _LIT8( KPseudoClassPressedDown, "presseddown" ); |
|
39 |
|
40 // LOCAL FUNCTION PROTOTYPES |
|
41 static const TDesC8& PseudoClassName( |
|
42 CXnDomProperty::TPseudoClass aPseudoClass ); |
|
43 static CXnDomProperty::TPseudoClass PseudoClassFromName( |
|
44 const TDesC8& aName ); |
|
45 static TInt FindPseudoClass( |
|
46 const RArray< CXnDomProperty::TPseudoClass >& aArray, |
|
47 const TDesC8& aPseudoClass ); |
|
48 |
|
49 // ============================= LOCAL FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // PseudoClassName |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 static const TDesC8& PseudoClassName( CXnDomProperty::TPseudoClass aPseudoClass ) |
|
56 { |
|
57 switch ( aPseudoClass ) |
|
58 { |
|
59 case CXnDomProperty::EFocus: |
|
60 return KPseudoClassFocus; |
|
61 case CXnDomProperty::EPassiveFocus: |
|
62 return KPseudoClassPassiveFocus; |
|
63 case CXnDomProperty::EHold: |
|
64 return KPseudoClassHold; |
|
65 case CXnDomProperty::EHover: |
|
66 return KPseudoClassHover; |
|
67 case CXnDomProperty::ELink: |
|
68 return KPseudoClassLink; |
|
69 case CXnDomProperty::EVisited: |
|
70 return KPseudoClassVisited; |
|
71 case CXnDomProperty::EActive: |
|
72 return KPseudoClassActive; |
|
73 case CXnDomProperty::EEdit: |
|
74 return KPseudoClassEdit; |
|
75 case CXnDomProperty::EPressedDown: |
|
76 return KPseudoClassPressedDown; |
|
77 default: |
|
78 return KNullDesC8; |
|
79 } |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // PseudoClassFromName |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 static CXnDomProperty::TPseudoClass PseudoClassFromName( const TDesC8& aName ) |
|
87 { |
|
88 if ( aName == KPseudoClassFocus ) |
|
89 { |
|
90 return CXnDomProperty::EFocus; |
|
91 } |
|
92 else if ( aName == KPseudoClassPassiveFocus ) |
|
93 { |
|
94 return CXnDomProperty::EPassiveFocus; |
|
95 } |
|
96 else if ( aName == KPseudoClassHold ) |
|
97 { |
|
98 return CXnDomProperty::EHold; |
|
99 } |
|
100 else if ( aName == KPseudoClassHover ) |
|
101 { |
|
102 return CXnDomProperty::EHover; |
|
103 } |
|
104 else if ( aName == KPseudoClassLink ) |
|
105 { |
|
106 return CXnDomProperty::ELink; |
|
107 } |
|
108 else if ( aName == KPseudoClassVisited ) |
|
109 { |
|
110 return CXnDomProperty::EVisited; |
|
111 } |
|
112 else if ( aName == KPseudoClassActive ) |
|
113 { |
|
114 return CXnDomProperty::EActive; |
|
115 } |
|
116 else if ( aName == KPseudoClassEdit ) |
|
117 { |
|
118 return CXnDomProperty::EEdit; |
|
119 } |
|
120 else if ( aName == KPseudoClassPressedDown ) |
|
121 { |
|
122 return CXnDomProperty::EPressedDown; |
|
123 } |
|
124 return CXnDomProperty::ENone; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // FindPseudoClass |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 static TInt FindPseudoClass( |
|
132 const RArray< CXnDomProperty::TPseudoClass >& aArray, |
|
133 const TDesC8& aPseudoClass ) |
|
134 { |
|
135 for ( TInt i = aArray.Count() - 1; i >= 0; --i ) |
|
136 { |
|
137 CXnDomProperty::TPseudoClass item = aArray[i]; |
|
138 if ( PseudoClassName( item ) == aPseudoClass ) |
|
139 { |
|
140 return i; |
|
141 } |
|
142 } |
|
143 return KErrNotFound; |
|
144 } |
|
145 |
|
146 // ============================ MEMBER FUNCTIONS =============================== |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CXnPropertyList::NewL() |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 CXnPropertyList* CXnPropertyList::NewL() |
|
153 { |
|
154 CXnPropertyList* self = new ( ELeave ) CXnPropertyList; |
|
155 CleanupStack::PushL( self ); |
|
156 self->ConstructL(); |
|
157 CleanupStack::Pop();//self |
|
158 return self; |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CXnPropertyList::~CXnPropertyList() |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 CXnPropertyList::~CXnPropertyList() |
|
166 { |
|
167 delete iMap; |
|
168 |
|
169 iCurrentPseudoClasses.Reset(); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CXnPropertyList::CXnPropertyList() |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 CXnPropertyList::CXnPropertyList() |
|
177 { |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CXnPropertyList::ConstructL() |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CXnPropertyList::ConstructL() |
|
185 { |
|
186 iMap = CXnMap::NewL( new ( ELeave ) TXnPropertyComparator ); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CXnPropertyList::SetPropertyL |
|
191 // Set a property. |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CXnPropertyList::SetPropertyL( CXnProperty* aProperty ) |
|
195 { |
|
196 CXnPropertyKey key; |
|
197 key.iString = &( aProperty->Property()->Name() ); |
|
198 key.iPseudoClass = aProperty->Property()->PseudoClass(); |
|
199 |
|
200 CXnProperty* tmp = static_cast< CXnProperty* >( iMap->Get( key ) ); |
|
201 if ( tmp == aProperty ) |
|
202 { |
|
203 return; |
|
204 } |
|
205 TBool replaced = EFalse; |
|
206 for ( TInt i = ( iMap->Container() ).Count() - 1; i >= 0; --i ) |
|
207 { |
|
208 tmp = static_cast< CXnProperty* >( ( iMap->Container() )[i] ); |
|
209 if ( aProperty->Property()->PseudoClass() == CXnDomProperty::ENone ) |
|
210 { |
|
211 const TDesC8& tmpName = tmp->Property()->Name(); |
|
212 const TDesC8& propertyName = aProperty->Property()->Name(); |
|
213 if ( tmpName == propertyName ) |
|
214 { |
|
215 if ( tmp->Property()->PseudoClass() != CXnDomProperty::ENone ) |
|
216 { |
|
217 TBool pseudoMatch = EFalse; |
|
218 for ( TInt j = iCurrentPseudoClasses.Count() - 1; j >= 0; --j ) |
|
219 { |
|
220 CXnDomProperty::TPseudoClass pseudoClass = |
|
221 iCurrentPseudoClasses[j]; |
|
222 if ( tmp->Property()->PseudoClass() == pseudoClass ) |
|
223 { |
|
224 pseudoMatch = ETrue; |
|
225 break; |
|
226 } |
|
227 } |
|
228 if ( !pseudoMatch ) |
|
229 { |
|
230 continue; |
|
231 } |
|
232 CXnProperty* newProperty = aProperty->CloneL(); |
|
233 CleanupStack::PushL( newProperty ); |
|
234 newProperty->Property()->SetPseudoClass( |
|
235 tmp->Property()->PseudoClass() ); |
|
236 // add new object |
|
237 if ( ( iMap->Container()).Append( newProperty ) != KErrNone ) |
|
238 { |
|
239 User::Leave( KXnErrAddingProperyToListFailed ); |
|
240 } |
|
241 CleanupStack::Pop( newProperty ); |
|
242 } |
|
243 if ( ( iMap->Container() ).Append( aProperty )!= KErrNone ) |
|
244 { |
|
245 User::Leave( KXnErrAddingProperyToListFailed_2 ); |
|
246 } |
|
247 replaced = ETrue; |
|
248 // remove old object |
|
249 delete tmp; |
|
250 ( iMap->Container() ).Remove( i ); |
|
251 } |
|
252 } |
|
253 else |
|
254 { |
|
255 const TDesC8& tmpName = tmp->Property()->Name(); |
|
256 const TDesC8& propertyName = aProperty->Property()->Name(); |
|
257 if ( tmp->Property()->PseudoClass() != CXnDomProperty::ENone && |
|
258 tmp->Property()->PseudoClass() == aProperty->Property()->PseudoClass() && |
|
259 tmpName == propertyName ) |
|
260 { |
|
261 if ( ( iMap->Container() ).Append( aProperty )!= KErrNone ) |
|
262 { |
|
263 User::Leave( KXnErrAddingProperyToListFailed_3 ); |
|
264 } |
|
265 replaced = ETrue; |
|
266 // remove old object |
|
267 delete tmp; |
|
268 ( iMap->Container() ).Remove( i ); |
|
269 } |
|
270 } |
|
271 } |
|
272 if ( replaced ) |
|
273 { |
|
274 return; |
|
275 } |
|
276 if ( aProperty->Property()->PseudoClass() != CXnDomProperty::ENone ) |
|
277 { |
|
278 for ( TInt i = iCurrentPseudoClasses.Count() - 1; i >= 0; --i ) |
|
279 { |
|
280 CXnDomProperty::TPseudoClass pseudoClass = iCurrentPseudoClasses[i]; |
|
281 CXnProperty* newProperty = aProperty->CloneL(); |
|
282 CleanupStack::PushL( newProperty ); |
|
283 newProperty->Property()->SetPseudoClass( pseudoClass ); |
|
284 // add new object |
|
285 User::LeaveIfError( ( iMap->Container() ).Append( newProperty ) ); |
|
286 if ( ( iMap->Container() ).Append( newProperty )!= KErrNone ) |
|
287 { |
|
288 User::Leave( KXnErrAddingProperyToListFailed_4 ); |
|
289 } |
|
290 CleanupStack::Pop( newProperty ); |
|
291 } |
|
292 } |
|
293 if ( ( iMap->Container() ).Append( aProperty )!= KErrNone ) |
|
294 { |
|
295 User::Leave( KXnErrAddingProperyToListFailed_5 ); |
|
296 } |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CXnPropertyList::GetProperty |
|
301 // Gets a property. |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 CXnProperty* CXnPropertyList::GetProperty( const TDesC8& aKey ) const |
|
305 { |
|
306 CXnPropertyKey key; |
|
307 key.iString = &aKey; |
|
308 for ( TInt i = iCurrentPseudoClasses.Count() - 1; i >= 0; --i ) |
|
309 { |
|
310 key.iPseudoClass = iCurrentPseudoClasses[i]; |
|
311 CXnProperty* property = static_cast< CXnProperty* >( iMap->Get( key ) ); |
|
312 if ( property ) |
|
313 { |
|
314 return property; |
|
315 } |
|
316 } |
|
317 |
|
318 key.iPseudoClass = CXnDomProperty::ENone; |
|
319 CXnProperty* property = static_cast< CXnProperty* >( iMap->Get( key ) ); |
|
320 if ( property ) |
|
321 { |
|
322 return property; |
|
323 } |
|
324 return NULL; |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CXnPropertyList::SetPseudoClassL |
|
329 // Set a pseudoclass |
|
330 // ----------------------------------------------------------------------------- |
|
331 // |
|
332 TBool CXnPropertyList::SetStateL( const TDesC8& aState ) |
|
333 { |
|
334 if ( FindPseudoClass( iCurrentPseudoClasses, aState ) < 0 ) |
|
335 { |
|
336 User::LeaveIfError( iCurrentPseudoClasses.Append( |
|
337 PseudoClassFromName( aState ) ) ); |
|
338 return ETrue; |
|
339 } |
|
340 return EFalse; |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CXnPropertyList::IsStateSet |
|
345 // Check whether a state is set or not |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 TBool CXnPropertyList::IsStateSet( const TDesC8& aState ) |
|
349 { |
|
350 if ( FindPseudoClass( iCurrentPseudoClasses, aState ) < 0 ) |
|
351 { |
|
352 return EFalse; |
|
353 } |
|
354 return ETrue; |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CXnPropertyList::UnsetPseudoClass |
|
359 // Unset a pseudoclass |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 TBool CXnPropertyList::UnsetState( const TDesC8& aState ) |
|
363 { |
|
364 TInt index = FindPseudoClass( iCurrentPseudoClasses, aState ); |
|
365 if ( index < 0 ) |
|
366 { |
|
367 return EFalse; |
|
368 } |
|
369 iCurrentPseudoClasses.Remove( index ); |
|
370 return ETrue; |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CXnPropertyList::CloneL |
|
375 // Clone the list |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 CXnPropertyList* CXnPropertyList::CloneL() |
|
379 { |
|
380 CXnPropertyList* clone = CXnPropertyList::NewL(); |
|
381 CleanupStack::PushL( clone ); |
|
382 TInt count = iCurrentPseudoClasses.Count(); |
|
383 for ( TInt i = 0; i < count; ++i ) |
|
384 { |
|
385 User::LeaveIfError( clone->iCurrentPseudoClasses.Append( |
|
386 iCurrentPseudoClasses[i] ) ); |
|
387 } |
|
388 clone->iMap = CXnMap::NewL( new ( ELeave ) TXnPropertyComparator ); |
|
389 count = iMap->Container().Count(); |
|
390 for ( TInt i = 0; i < count; ++i ) |
|
391 { |
|
392 User::LeaveIfError( clone->iMap->Container().Append( |
|
393 static_cast< CXnProperty* >( iMap->Container()[i] )->CloneL() ) ); |
|
394 } |
|
395 CleanupStack::Pop( clone ); |
|
396 return clone; |
|
397 } |