|
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: Control Implementation with utilities for slider widget. |
|
15 * |
|
16 */ |
|
17 |
|
18 // Toolkit includes |
|
19 #include <alf/alfenv.h> |
|
20 #include <alf/alfroster.h> |
|
21 #include <alf/alfdisplay.h> |
|
22 |
|
23 // Widget model includes |
|
24 #include <alf/alfwidgeteventhandler.h> |
|
25 #include <alf/alfwidgetevents.h> |
|
26 #include "alf/alfattribute.h" |
|
27 #include <alf/alfutil.h> |
|
28 #include "alf/alfmodeloperation.h" |
|
29 #include <alf/alfcontrolgroup.h> |
|
30 |
|
31 // libc includes |
|
32 #include <libc/string.h> |
|
33 #include <libc/stdlib.h> |
|
34 #include <mul/mulevent.h> |
|
35 |
|
36 //Widget includes |
|
37 |
|
38 //Internal includes |
|
39 #include "mulslidercontrol.h" |
|
40 #include "mulsliderwidget.h" |
|
41 #include "mulslidermodel.h" |
|
42 #include "imulsliderbaseelementinternal.h" |
|
43 |
|
44 //namespaces |
|
45 using namespace osncore; |
|
46 using namespace mulsliderwidget; |
|
47 |
|
48 |
|
49 namespace Alf |
|
50 { |
|
51 // --------------------------------------------------------------------------- |
|
52 // Constructor. |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 MulSliderControl::MulSliderControl(CAlfEnv& aEnv) : |
|
56 CAlfWidgetControl(aEnv) |
|
57 { |
|
58 mLayoutHeight = -1; //this means that the first draw is yet to happen. |
|
59 mLayoutWidth = -1; //this means that the first draw is yet to happen. |
|
60 mDragTactileFeedbackStarted = false; |
|
61 mEnableTactile = false; // Next statement will make it true |
|
62 mTactilefdbInstance = NULL; |
|
63 EnableTactileFeedback(true); |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // Destructor. |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 MulSliderControl::~MulSliderControl() |
|
72 { |
|
73 |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Notifies the owner that the layout of a visual has been recalculated. |
|
79 // Called only when the EAlfVisualFlagLayoutUpdateNotification flag has |
|
80 // been set for the visual. |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void MulSliderControl::VisualLayoutUpdated(CAlfVisual& aVisual) |
|
84 { |
|
85 if((mLayoutWidth == -1 && roundFloatToInt( |
|
86 aVisual.Size().ValueNow().iX) == 0) || |
|
87 (mLayoutHeight == -1 && roundFloatToInt( |
|
88 aVisual.Size().ValueNow().iY) == 0)) |
|
89 { |
|
90 //return; /*No size assigned yet*/ |
|
91 } |
|
92 else |
|
93 { |
|
94 //do nothing |
|
95 } |
|
96 |
|
97 if(mLayoutWidth == roundFloatToInt(aVisual.Size().ValueNow().iX) && |
|
98 mLayoutHeight == roundFloatToInt(aVisual.Size().ValueNow().iY)) |
|
99 { |
|
100 //return; /* No change in layout size */ |
|
101 } |
|
102 else |
|
103 { |
|
104 //do nothing |
|
105 } |
|
106 |
|
107 mLayoutWidth = roundFloatToInt(aVisual.Size().ValueNow().iX); |
|
108 mLayoutHeight = roundFloatToInt(aVisual.Size().ValueNow().iY); |
|
109 IAlfElement* baseelement = findElement ("BaseElement"); |
|
110 IMulSliderBaseElementInternal* elementInternal = |
|
111 static_cast<IMulSliderBaseElementInternal*> ( |
|
112 baseelement->makeInterface(IMulSliderBaseElementInternal::type())); |
|
113 if(elementInternal) |
|
114 { |
|
115 elementInternal->baseLayoutSizeChanged(); |
|
116 } |
|
117 else |
|
118 { |
|
119 //do nothing |
|
120 } |
|
121 } |
|
122 |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // Returns top level layout. |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 CAlfLayout* MulSliderControl::ContainerLayout( |
|
129 const CAlfControl* /*aConnected*/) const |
|
130 { |
|
131 if(VisualCount()) |
|
132 { |
|
133 //Return the root layout of the control |
|
134 return(static_cast<CAlfLayout*> (&Visual(0))); |
|
135 } |
|
136 else |
|
137 { |
|
138 return NULL; |
|
139 } |
|
140 } |
|
141 |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // From base class CAlfWidgetControl |
|
145 // Handle Alfred events. |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 AlfEventStatus MulSliderControl::handleEvent( const TAlfEvent& aEvent ) |
|
149 { |
|
150 AlfEventStatus ret = EEventNotHandled; |
|
151 IAlfElement *base = findElement("BaseElement"); |
|
152 if(base) |
|
153 { |
|
154 IAlfWidgetEventHandler* element = |
|
155 static_cast<IAlfWidgetEventHandler*> ( |
|
156 base->makeInterface(IAlfWidgetEventHandler::type())); |
|
157 |
|
158 if(aEvent.IsCustomEvent()) |
|
159 { |
|
160 if(aEvent.CustomParameter() == EEventMissedPointerUp) |
|
161 { |
|
162 ret = element->offerEvent(*this,aEvent); |
|
163 } |
|
164 } |
|
165 else if(aEvent.IsKeyEvent() || |
|
166 aEvent.IsPointerEvent()) |
|
167 { |
|
168 // if the type of base element is slider , then |
|
169 // convert the event to custom event |
|
170 IMulSliderBaseElementInternal* elementInternal = |
|
171 static_cast<IMulSliderBaseElementInternal*> ( |
|
172 base->makeInterface(IMulSliderBaseElementInternal::type())); |
|
173 ret = element->offerEvent(*this , aEvent); |
|
174 } |
|
175 else |
|
176 { |
|
177 } |
|
178 } |
|
179 return ret; |
|
180 } |
|
181 |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // From base class CAlfWidgetControl. |
|
185 // Notification that data is about to change in the data model. |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 void MulSliderControl::dataChanging(const AlfModelOperation& /*aOperation*/) |
|
189 {} |
|
190 |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // From class IAlfInterfaceBase. |
|
194 // Getter for interfaces provided by the list widget. |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 IAlfInterfaceBase* MulSliderControl::makeInterface(const IfId& aType) |
|
198 { |
|
199 UString param(aType.mImplementationId); |
|
200 |
|
201 return CAlfWidgetControl::makeInterface(aType); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 // removeAndDestroyElement |
|
207 // |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void MulSliderControl::removeAndDestroyElement(const IAlfElement& /*aElement*/) |
|
211 { |
|
212 // reset the variables |
|
213 mLayoutWidth = -1; |
|
214 mLayoutHeight = -1; |
|
215 |
|
216 CAlfWidgetControl::removeAndDestroyElement(*findElement("BaseElement")); |
|
217 } |
|
218 //---------------------------------------------------------------------- |
|
219 // |
|
220 //enableTactileFeedback |
|
221 //---------------------------------------------------------------------- |
|
222 void MulSliderControl::EnableTactileFeedback(bool aEnabled) |
|
223 { |
|
224 if (!mTactilefdbInstance) |
|
225 { |
|
226 mEnableTactile = aEnabled; |
|
227 mTactilefdbInstance = MTouchFeedback::Instance(); |
|
228 } |
|
229 } |
|
230 //---------------------------------------------------------------------- |
|
231 //TactileEffectOnTouch |
|
232 // |
|
233 //---------------------------------------------------------------------- |
|
234 void MulSliderControl::TactileEffectOnTouchandHold() |
|
235 { |
|
236 if (mTactilefdbInstance) |
|
237 { |
|
238 mTactilefdbInstance->InstantFeedback(ETouchFeedbackSlider); |
|
239 } |
|
240 } |
|
241 //---------------------------------------------------------------------- |
|
242 //TactileEffectOnDrag |
|
243 // |
|
244 //---------------------------------------------------------------------- |
|
245 void MulSliderControl::TactileEffectOnDrag(TAlfEvent& aEvent) |
|
246 { |
|
247 if (mTactilefdbInstance) |
|
248 { |
|
249 CCoeControl* ccoecntrl = static_cast<CCoeControl*>(Display()->ObjectProvider()); |
|
250 TInt intensity = 50; |
|
251 TTimeIntervalMicroSeconds32 timespan = 1000000; |
|
252 mTactilefdbInstance->StartFeedback(ccoecntrl,ETouchContinuousSlider,&aEvent.PointerEvent(),intensity,timespan); |
|
253 mDragTactileFeedbackStarted = true; |
|
254 } |
|
255 } |
|
256 //------------------------------------------------------------------------------- |
|
257 // |
|
258 // TactileEffectOnRelease |
|
259 //-------------------------------------------------------------------------------- |
|
260 // |
|
261 void MulSliderControl::TactileEffectOnRelease() |
|
262 { |
|
263 if (mTactilefdbInstance) |
|
264 { |
|
265 if ( mDragTactileFeedbackStarted ) |
|
266 { |
|
267 // Touch Release on Thumb after drag |
|
268 CCoeControl* ccoecntrl = static_cast<CCoeControl*>(Display()->ObjectProvider()); |
|
269 mTactilefdbInstance->StopFeedback(ccoecntrl); |
|
270 mDragTactileFeedbackStarted = false; |
|
271 } |
|
272 else |
|
273 { |
|
274 // Touch Release on thumb |
|
275 mTactilefdbInstance->InstantFeedback(ETouchFeedbackSlider); |
|
276 } |
|
277 } |
|
278 } |
|
279 }//End of namespace Alf |
|
280 //End of File |
|
281 |