|
1 /* |
|
2 * Copyright (c) 2006 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: Control group |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "alf/alfcontrolgroup.h" |
|
21 #include "alfcontrolgroupsubsession.h" |
|
22 #include "alf/alfcontrol.h" |
|
23 #include "alf/alfenv.h" |
|
24 #include "alfclient.h" |
|
25 #include "alf/alftransformation.h" |
|
26 |
|
27 #include <uiacceltk/HuiUtil.h> |
|
28 |
|
29 // used flags |
|
30 enum TAlfControlGroupFlags |
|
31 { |
|
32 EAlfControlGroupAllowInput = 0x01 |
|
33 }; |
|
34 |
|
35 // private data |
|
36 struct CAlfControlGroup::TPrivateData |
|
37 { |
|
38 RAlfControlGroupSubSession iControlGroupSubSession; // Owned |
|
39 TUint iFlags; // Owned. |
|
40 TInt iResourceId; // Owned. |
|
41 CAlfEnv* iEnv; // Not owned. |
|
42 RPointerArray<CAlfControl> iControls; // Owned. |
|
43 CAlfTransformation* iTransform; // Owned. |
|
44 CAlfDisplay* iBoundDisplay; // Not owned. |
|
45 }; |
|
46 |
|
47 // ======== MEMBER FUNCTIONS ======== |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // Constructor |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CAlfControlGroup::CAlfControlGroup() |
|
54 { |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // ConstructL |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 void CAlfControlGroup::ConstructL(TInt aResourceId, CAlfEnv& aEnv) |
|
63 { |
|
64 iData = new (ELeave) TPrivateData; |
|
65 |
|
66 User::LeaveIfError( |
|
67 iData->iControlGroupSubSession.Open(aEnv.Client(), aResourceId) ); |
|
68 |
|
69 iData->iFlags = EAlfControlGroupAllowInput; |
|
70 iData->iEnv = &aEnv; |
|
71 //iData->iOpacity.Set(1.0); |
|
72 iData->iResourceId = aResourceId; |
|
73 iData->iTransform = NULL; |
|
74 iData->iBoundDisplay = NULL; |
|
75 } |
|
76 |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Destructor |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CAlfControlGroup::~CAlfControlGroup() |
|
83 { |
|
84 if ( iData ) |
|
85 { |
|
86 iData->iControls.ResetAndDestroy(); |
|
87 |
|
88 delete iData->iTransform; |
|
89 iData->iTransform = NULL; |
|
90 |
|
91 iData->iControlGroupSubSession.Close(); |
|
92 } |
|
93 |
|
94 delete iData; |
|
95 iData = NULL; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // Returns server side handle |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 TInt CAlfControlGroup::Identifier() const |
|
103 { |
|
104 return iData->iControlGroupSubSession.SubSessionHandle(); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Binds this control group to the given display. |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CAlfControlGroup::BindDisplay(CAlfDisplay* aDisplay) |
|
112 { |
|
113 iData->iBoundDisplay = aDisplay; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Returns ID. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C TInt CAlfControlGroup::ResourceId() const |
|
121 { |
|
122 return iData->iResourceId; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Appends a control |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 EXPORT_C void CAlfControlGroup::AppendL(CAlfControl* aControl) |
|
130 { |
|
131 TInt err = KErrNone; |
|
132 |
|
133 User::LeaveIfError( iData->iControls.Append(aControl) ); |
|
134 |
|
135 // Update server side: |
|
136 err = iData->iControlGroupSubSession.Append( aControl->Identifier() ); |
|
137 if ( err != KErrNone ) |
|
138 { |
|
139 iData->iControls.Remove( iData->iControls.Count()-1 ); |
|
140 User::LeaveIfError( err ); |
|
141 } |
|
142 |
|
143 // Show the appended control if the control group was shown. |
|
144 if ( iData->iBoundDisplay ) |
|
145 { |
|
146 TRAP( err, aControl->ShowL( *iData->iBoundDisplay )); |
|
147 } |
|
148 |
|
149 // If a leave occurred remove the control from client and server side control group. |
|
150 if ( err != KErrNone ) |
|
151 { |
|
152 iData->iControlGroupSubSession.Remove( aControl->Identifier() ); |
|
153 iData->iControls.Remove( iData->iControls.Count()-1 ); |
|
154 User::LeaveIfError( err ); |
|
155 } |
|
156 |
|
157 // Everything OK. |
|
158 aControl->SetControlGroup(*this); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // Removes a control |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C TInt CAlfControlGroup::Remove(CAlfControl* aControl) |
|
166 { |
|
167 // Update server side: |
|
168 TInt err = iData->iControlGroupSubSession.Remove( aControl->Identifier() ); |
|
169 |
|
170 // Update own array if server side is OK. |
|
171 if ( err == KErrNone ) |
|
172 { |
|
173 // If found on the server side, we must find it also from the client side. |
|
174 TInt index = iData->iControls.Find(aControl); |
|
175 __ASSERT_DEBUG( index != KErrNotFound, USER_INVARIANT() ); |
|
176 if(index != KErrNotFound) |
|
177 { |
|
178 iData->iControls.Remove(index); |
|
179 } |
|
180 else |
|
181 { |
|
182 err = KErrNotFound; |
|
183 } |
|
184 } |
|
185 else |
|
186 { |
|
187 // If we cannot find it from the server side, we must not find it on the client side. |
|
188 __ASSERT_DEBUG( iData->iControls.Find(aControl) == KErrNotFound , USER_INVARIANT() ); |
|
189 } |
|
190 |
|
191 if ( err == KErrNone ) |
|
192 { |
|
193 CAlfControlGroup* dummy = NULL; |
|
194 aControl->SetControlGroup(*dummy); |
|
195 |
|
196 // Hide the control, if this control group has been visible |
|
197 if( iData->iBoundDisplay ) |
|
198 { |
|
199 aControl->Hide( *iData->iBoundDisplay ); |
|
200 } |
|
201 } |
|
202 |
|
203 return err; |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // Accepts input? |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 EXPORT_C TBool CAlfControlGroup::AcceptInput() const |
|
211 { |
|
212 return iData->iFlags&EAlfControlGroupAllowInput; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // Set accepts input |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 EXPORT_C void CAlfControlGroup::SetAcceptInput(TBool aAcceptInput) |
|
220 { |
|
221 if ( aAcceptInput ) |
|
222 { |
|
223 iData->iFlags|=EAlfControlGroupAllowInput; |
|
224 } |
|
225 else |
|
226 { |
|
227 iData->iFlags&=~EAlfControlGroupAllowInput; |
|
228 } |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Finds control by ID |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 EXPORT_C CAlfControl* CAlfControlGroup::FindControl(TInt aId, TBool aUserId) const |
|
236 { |
|
237 for(TInt i = 0; i < iData->iControls.Count(); ++i) |
|
238 { |
|
239 if( (aUserId? |
|
240 iData->iControls[i]->Id(): |
|
241 iData->iControls[i]->Identifier()) |
|
242 == aId) |
|
243 { |
|
244 return iData->iControls[i]; |
|
245 } |
|
246 } |
|
247 return NULL; |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // Returns control count. |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C TInt CAlfControlGroup::Count() const |
|
255 { |
|
256 return iData->iControls.Count(); |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // Returns indexed control |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 EXPORT_C CAlfControl& CAlfControlGroup::Control(TInt aIndex) const |
|
264 { |
|
265 return *iData->iControls[aIndex]; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // Enables transformation. |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 EXPORT_C void CAlfControlGroup::EnableTransformationL(TBool aIsTransformed) |
|
273 { |
|
274 if ( aIsTransformed && iData->iTransform ) |
|
275 { |
|
276 // Already enabled |
|
277 return; |
|
278 } |
|
279 |
|
280 if ( !aIsTransformed && !iData->iTransform ) |
|
281 { |
|
282 // Already disabled |
|
283 return; |
|
284 } |
|
285 |
|
286 if ( aIsTransformed ) |
|
287 { |
|
288 iData->iTransform = CAlfTransformation::NewL(*iData->iEnv); |
|
289 } |
|
290 |
|
291 // use the server handle from the transformation object if present |
|
292 TInt transformationHandle = |
|
293 iData->iTransform ? |
|
294 iData->iTransform->ServerHandle() : |
|
295 0 ; |
|
296 |
|
297 // send the message to the server |
|
298 TInt err = iData->iControlGroupSubSession.EnableTransformation( |
|
299 transformationHandle, |
|
300 aIsTransformed ); |
|
301 |
|
302 if ( err == KErrNone && !aIsTransformed ) |
|
303 { |
|
304 delete iData->iTransform; |
|
305 iData->iTransform = NULL; |
|
306 } |
|
307 |
|
308 if ( err != KErrNone ) |
|
309 { |
|
310 delete iData->iTransform; |
|
311 iData->iTransform = NULL; |
|
312 User::Leave( err ); |
|
313 } |
|
314 } |
|
315 |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // Returns is transformation enabled |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 EXPORT_C TBool CAlfControlGroup::IsTransformed() const |
|
322 { |
|
323 return iData->iTransform != 0; |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // Returns transformation |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 EXPORT_C CAlfTransformation& CAlfControlGroup::Transformation() |
|
331 { |
|
332 __ASSERT_ALWAYS( iData->iTransform, USER_INVARIANT() ); |
|
333 return *iData->iTransform; |
|
334 } |
|
335 |