1 /* |
|
2 * Copyright (c) 2007, 2008 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: Implementation for slider widget. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Alfred Client includes |
|
20 #include <alf/alfenv.h> |
|
21 |
|
22 // Widget Model includes |
|
23 #include "alf/alfelement.h" |
|
24 |
|
25 // Widget Includes |
|
26 #include "imulsliderbaseelementinternal.h" |
|
27 #include <mul/mulsliderproductids.h> |
|
28 // Internal includes |
|
29 #include "mulslidervertical.h" |
|
30 #include "mulsliderwidget.h" |
|
31 #include "mulslidermodel.h" |
|
32 #include "mulslidercontrol.h" |
|
33 #include <alf/alfwidgetenvextension.h> |
|
34 using namespace mulsliderwidget; |
|
35 |
|
36 using Alf::CommonWidgetEvent; |
|
37 namespace Alf |
|
38 { |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Creator Method. |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 MulSliderWidget* MulSliderWidget :: create( |
|
45 CAlfEnv& aEnv, |
|
46 IAlfContainerWidget& aContainer, |
|
47 const char* aWidgetId, |
|
48 AlfCustomInitDataBase* aCustomData) |
|
49 { |
|
50 |
|
51 return (new( EMM ) MulSliderWidget(aEnv, |
|
52 aContainer, aWidgetId,aCustomData)); |
|
53 } |
|
54 |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // Destructor. |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 MulSliderWidget::~MulSliderWidget() |
|
61 { |
|
62 if(mSliderModel) |
|
63 { |
|
64 delete mSliderModel; |
|
65 } |
|
66 else |
|
67 { |
|
68 |
|
69 } |
|
70 } |
|
71 |
|
72 /** |
|
73 * Get the model for widget. |
|
74 * |
|
75 * @return model of the slider widget |
|
76 */ |
|
77 IMulSliderModel& MulSliderWidget::SliderModel() |
|
78 { |
|
79 return *mSliderModel; |
|
80 } |
|
81 /** |
|
82 * Set the transparency for the background of the slider widget. |
|
83 * |
|
84 * @param True, to set background as transparent |
|
85 * @param False, to set background as opaque |
|
86 */ |
|
87 void MulSliderWidget::MakeTransparent( bool aTransparent) |
|
88 { |
|
89 mElement->MakeTransparent(aTransparent); |
|
90 } |
|
91 |
|
92 /** |
|
93 * Enable/Disable key handling . |
|
94 * |
|
95 * @param aVal: True, to handle keyevents by Application |
|
96 * False, to handle keyevents as defined in the control |
|
97 */ |
|
98 void MulSliderWidget::SetHandleKeyEvent( bool aVal ) |
|
99 { |
|
100 mHandleKeyEvent = aVal; |
|
101 } |
|
102 /** |
|
103 * |
|
104 * Returns KeyEvent enable status |
|
105 * |
|
106 */ |
|
107 bool MulSliderWidget::IsKeyEnabled() |
|
108 { |
|
109 return mHandleKeyEvent; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // From class IAlfWidget. |
|
114 // Getter for the parent container. The ownership not passed. |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 IAlfContainerWidget* MulSliderWidget::parent() const |
|
118 { |
|
119 return mWidget->parent(); |
|
120 } |
|
121 |
|
122 |
|
123 // From class MAlfInterfaceBase. |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Getter for interfaces provided by the slider widget. |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 IAlfInterfaceBase* MulSliderWidget :: makeInterface(const IfId& aType) |
|
130 { |
|
131 UString param ( aType.mImplementationId ); |
|
132 |
|
133 if (param == IMulSliderWidget::type().mImplementationId) |
|
134 { |
|
135 return static_cast<IMulSliderWidget*>(this); |
|
136 } |
|
137 else if (param == IAlfWidget::type().mImplementationId) |
|
138 { |
|
139 return static_cast<IAlfWidget*>(this); |
|
140 } |
|
141 |
|
142 else |
|
143 { |
|
144 //do nothing |
|
145 } |
|
146 |
|
147 // @todo other interfaces |
|
148 return mWidget->makeInterface(aType); |
|
149 } |
|
150 |
|
151 |
|
152 // From class IAlfWidget. |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // Getter for the control. The ownership is not passed. |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 CAlfWidgetControl* MulSliderWidget :: control() const |
|
159 { |
|
160 //return mSliderControl; |
|
161 return mWidget->control(); |
|
162 } |
|
163 |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // Setter for the control. The control is owned by the Alfred environment. |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void MulSliderWidget :: setControl( |
|
170 CAlfWidgetControl* aControl, bool /*aDeletePreviousControl*/ ) |
|
171 { |
|
172 mSliderControl = aControl; |
|
173 mWidget->setControl(aControl); |
|
174 } |
|
175 |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // Getter for the model. The ownership is not passed. |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 IAlfModel* MulSliderWidget :: model() |
|
182 { |
|
183 return mSliderModel; |
|
184 } |
|
185 |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // Setter for the model. Ownership is passed and the old model is released. |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void MulSliderWidget :: setModel( IAlfModel* aModel, bool /*aTakeOwnerShip*/) |
|
192 { |
|
193 |
|
194 if(aModel==NULL) |
|
195 { |
|
196 // Destroy the visualization if Model is NULL. |
|
197 if(mElement) |
|
198 { |
|
199 // Destroy the visual tree |
|
200 mSliderControl->Visual(0).RemoveAndDestroyAllD(); |
|
201 // Removes the element from control and destroys it |
|
202 mSliderControl->removeAndDestroyElement(*((IAlfElement *)mElement)); |
|
203 mElement = NULL; |
|
204 } |
|
205 delete mSliderModel; |
|
206 mSliderModel = NULL; |
|
207 } |
|
208 else |
|
209 { |
|
210 if(mSliderModel) |
|
211 { |
|
212 delete mSliderModel; |
|
213 mSliderModel = NULL; |
|
214 } |
|
215 mSliderModel = static_cast<IMulSliderModel*>( aModel->makeInterface( |
|
216 IMulSliderModel::type())); |
|
217 MulSliderModel* sliderModel = (MulSliderModel*)mSliderModel; |
|
218 // Store the widget pointer in model |
|
219 sliderModel->storeWidget(this); |
|
220 if(mElement) |
|
221 { |
|
222 // Destroy the visual tree |
|
223 mSliderControl->Visual(0).RemoveAndDestroyAllD(); |
|
224 // Removes the element from control and destroys it |
|
225 mSliderControl->removeAndDestroyElement(*((IAlfElement *)mElement)); |
|
226 mElement = NULL; |
|
227 } |
|
228 if(mSliderModel) |
|
229 { |
|
230 sliderTemplate tmplateID = sliderModel->GetTemplate(); |
|
231 if(tmplateID != ESliderTemplateNone) |
|
232 { |
|
233 switch(tmplateID) |
|
234 { |
|
235 case ESliderTemplate3:// zoom slider |
|
236 CreateSliderElement(KSliderVerticalElement); |
|
237 break; |
|
238 case ESliderTemplate7:// progressbar |
|
239 CreateSliderElement(KSliderProgressbarElement); |
|
240 break; |
|
241 default:// rest all tempaltes are horizonatal |
|
242 CreateSliderElement(KSliderHorizontalElement); |
|
243 } |
|
244 if(mElement) |
|
245 { |
|
246 mElement->createVisualization(tmplateID); |
|
247 ShowWidget(!IsHidden()); |
|
248 } |
|
249 |
|
250 } |
|
251 } |
|
252 } |
|
253 }// End of setModel |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // Get the name of the widget instance. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 const char* MulSliderWidget :: widgetName() const |
|
260 { |
|
261 return mWidget->widgetName(); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // Sets/Releases the Focus from child widget of container. |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 void MulSliderWidget::setChildFocus(bool /*aFocus*/) |
|
269 { |
|
270 } |
|
271 |
|
272 //--------------------------------------------------------------------------- |
|
273 // Creates the presentation for the widget from XML. Destroys any existing |
|
274 // presentation. |
|
275 //--------------------------------------------------------------------------- |
|
276 // |
|
277 void MulSliderWidget::setPresentation(const char* /*aFilePath*/) |
|
278 { |
|
279 } |
|
280 |
|
281 |
|
282 //--------------------------------------------------------------------------- |
|
283 // Gets the Widget Opacity |
|
284 // |
|
285 //--------------------------------------------------------------------------- |
|
286 // |
|
287 bool MulSliderWidget::GetOpacity() |
|
288 { |
|
289 return mOpacity; |
|
290 } |
|
291 |
|
292 //--------------------------------------------------------------------------- |
|
293 // Gets the Widget Opacity |
|
294 // |
|
295 //--------------------------------------------------------------------------- |
|
296 // |
|
297 bool MulSliderWidget::IsHidden() |
|
298 { |
|
299 return !mOpacity; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // Default constructor. |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 MulSliderWidget::MulSliderWidget( |
|
307 CAlfEnv& aEnv, IAlfContainerWidget& aContainer, |
|
308 const char* aWidgetId, |
|
309 AlfCustomInitDataBase* /*aCustomData*/) |
|
310 { |
|
311 // Default widget is shown |
|
312 mOpacity = true; |
|
313 mSliderModel = NULL; |
|
314 mElement = NULL; |
|
315 mHandleKeyEvent = true; |
|
316 mWidget.reset(new(EMM) AlfWidget(aWidgetId,aContainer,aEnv)); |
|
317 // Default Imperative Construction |
|
318 // Create Control |
|
319 CAlfWidgetControl* ctrl = constructDefaultControl(aEnv); |
|
320 setControl(ctrl); |
|
321 } |
|
322 |
|
323 void MulSliderWidget::CreateSliderElement(const char* aElementId) |
|
324 { |
|
325 IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory( |
|
326 control()->Env()); |
|
327 |
|
328 IAlfElement * baseelement = widgetFactory.createElement<IAlfElement> |
|
329 ( aElementId, |
|
330 baseElementName(), |
|
331 *control(), |
|
332 NULL, |
|
333 NULL ); |
|
334 |
|
335 // Store the element pointer |
|
336 mElement = static_cast<IMulSliderBaseElementInternal*>( |
|
337 baseelement->makeInterface( |
|
338 IMulSliderBaseElementInternal::type())); |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // Construct and returns Slider Control. |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 CAlfWidgetControl *MulSliderWidget::constructDefaultControl(CAlfEnv& aEnv) |
|
346 { |
|
347 return(new(EMM) MulSliderControl(aEnv) ); |
|
348 } |
|
349 |
|
350 void MulSliderWidget::changeTemplate(int /*aTemplateId*/) |
|
351 { |
|
352 if( mSliderModel ) |
|
353 { |
|
354 if(mElement) |
|
355 { |
|
356 mSliderControl->Visual(0).RemoveAndDestroyAllD(); |
|
357 mSliderControl->removeAndDestroyElement(*((IAlfElement*)mElement)); |
|
358 // delete baseelement; |
|
359 mElement = NULL; |
|
360 } |
|
361 |
|
362 MulSliderModel* sliderModel = (MulSliderModel*)mSliderModel; |
|
363 sliderTemplate i = sliderModel->GetTemplate(); |
|
364 switch(i) |
|
365 { |
|
366 case ESliderTemplateNone :// no template id is set |
|
367 return; |
|
368 case ESliderTemplate3:// zoom slider |
|
369 CreateSliderElement(KSliderVerticalElement); |
|
370 break; |
|
371 case ESliderTemplate7:// progressbar |
|
372 CreateSliderElement(KSliderProgressbarElement); |
|
373 break; |
|
374 default:// rest aal tempaltes are horizonatal |
|
375 CreateSliderElement(KSliderHorizontalElement); |
|
376 } |
|
377 mElement->createVisualization(i); |
|
378 ShowWidget(!IsHidden()); |
|
379 } |
|
380 } |
|
381 |
|
382 void MulSliderWidget::ShowWidget(bool opacity,int aTransitionTime) |
|
383 { |
|
384 mOpacity = opacity; |
|
385 if(mElement && mSliderModel) |
|
386 { |
|
387 MulSliderModel* sliderModel = static_cast<MulSliderModel*>(mSliderModel); |
|
388 |
|
389 if( sliderModel->GetTemplate() == ESliderTemplate3 && !mOpacity) |
|
390 { |
|
391 mElement->stopEvents(); |
|
392 } |
|
393 CAlfLayout *layout = mSliderControl->ContainerLayout(NULL); |
|
394 TAlfTimedValue t1(0,aTransitionTime); |
|
395 if(opacity) |
|
396 { |
|
397 t1.SetTarget(1,aTransitionTime); |
|
398 } |
|
399 |
|
400 layout->SetOpacity(t1); |
|
401 } |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // Get the root layout of slider |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 const CAlfLayout& MulSliderWidget ::ContainerLayout() |
|
409 { |
|
410 CAlfLayout* layout = mSliderControl->ContainerLayout(NULL); |
|
411 return *layout; |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // AddEventHandler |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 void MulSliderWidget::AddEventHandler( IAlfWidgetEventHandler& aObserver) |
|
419 { |
|
420 control()->addEventHandler(&aObserver); |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------------------------- |
|
424 // RemoveEventHandler |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 void MulSliderWidget::RemoveEventHandler( IAlfWidgetEventHandler& aObserver) |
|
428 { |
|
429 control()->removeEventHandler(aObserver); |
|
430 } |
|
431 // --------------------------------------------------------------------------- |
|
432 // RemoveEventHandler |
|
433 // --------------------------------------------------------------------------- |
|
434 // |
|
435 IMulSliderBaseElementInternal* MulSliderWidget::GetSliderElement() |
|
436 { |
|
437 return mElement; |
|
438 } |
|
439 |
|
440 }//End of Alf |
|
441 |
|