|
1 /* |
|
2 * Copyright (c) 2009 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: Wrapper class to communicate physics related data. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <aknphysics.h> |
|
20 #include "CMIDPhysicsWrapper.h" |
|
21 #include <w32std.h> |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // GetInstanceImpl |
|
25 //---------------------------------------------------------------------------- |
|
26 // |
|
27 EXPORT_C MMIDLcduiPhysicsInterface* GetInstanceImpl(CCoeControl* aParent, MMIDLcduiPhysicsObserver* aObserver) |
|
28 { |
|
29 MMIDLcduiPhysicsInterface* interface = 0; |
|
30 TRAP_IGNORE(interface = CMIDPhysicsWrapper::NewL(aParent, aObserver)); |
|
31 return interface; |
|
32 } |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CMIDPhysicsWrapper::CMIDPhysicsWrapper |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CMIDPhysicsWrapper::CMIDPhysicsWrapper() |
|
41 { |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CMIDPhysicsWrapper::ConstructL |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 void CMIDPhysicsWrapper::ConstructL(CCoeControl* aParent, MMIDLcduiPhysicsObserver* aObserver) |
|
49 { |
|
50 iParent = aParent; |
|
51 iObserver = aObserver; |
|
52 iPhysics = CAknPhysics::NewL(*this, iParent); |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CMIDPhysicsWrapper::NewL |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 |
|
60 CMIDPhysicsWrapper* CMIDPhysicsWrapper::NewL(CCoeControl* aParent, MMIDLcduiPhysicsObserver* aObserver) |
|
61 { |
|
62 CMIDPhysicsWrapper* self = new(ELeave) CMIDPhysicsWrapper; |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(aParent, aObserver); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CMIDPhysicsWrapper::~CMIDPhysicsWrapper |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 |
|
74 CMIDPhysicsWrapper::~CMIDPhysicsWrapper() |
|
75 { |
|
76 delete iPhysics; |
|
77 } |
|
78 |
|
79 |
|
80 TBool CMIDPhysicsWrapper::FeatureEnabled() |
|
81 { |
|
82 return CAknPhysics::FeatureEnabled(); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CMIDPhysicsWrapper::InitPhysicsL |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CMIDPhysicsWrapper::InitPhysicsL(const TSize& aWorldSize, |
|
90 const TSize& aViewSize, const TBool aDirection) |
|
91 { |
|
92 if (iPhysics) |
|
93 { |
|
94 iPhysics->InitPhysicsL(aWorldSize, aViewSize, aDirection); |
|
95 } |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CMIDPhysicsWrapper::StopPhysics |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void CMIDPhysicsWrapper::StopPhysics() |
|
103 { |
|
104 if (iPhysics) |
|
105 { |
|
106 iPhysics->StopPhysics(); |
|
107 iPhysics->ResetFriction(); |
|
108 } |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CMIDPhysicsWrapper::ResetFriction |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CMIDPhysicsWrapper::ResetFriction() |
|
116 { |
|
117 if (iPhysics) |
|
118 { |
|
119 iPhysics->ResetFriction(); |
|
120 } |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CMIDPhysicsWrapper::StartFlick |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 TBool CMIDPhysicsWrapper::StartFlick(const TPoint& aLength, TTime aDuration) |
|
128 { |
|
129 if (iPhysics) |
|
130 { |
|
131 TPoint drag(aLength); |
|
132 return iPhysics->StartPhysics(drag, aDuration); |
|
133 } |
|
134 |
|
135 PhysicEmulationEnded(); |
|
136 return EFalse; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // CMIDPhysicsWrapper::HighlightDelay |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 TInt CMIDPhysicsWrapper::HighlightTimeout() const |
|
144 { |
|
145 if (iPhysics) |
|
146 { |
|
147 return iPhysics->HighlightTimeout(); |
|
148 } |
|
149 else |
|
150 { |
|
151 return 0; |
|
152 } |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CMIDPhysicsWrapper::DragThreshold |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CMIDPhysicsWrapper::DragThreshold() const |
|
160 { |
|
161 if (iPhysics) |
|
162 { |
|
163 return iPhysics->DragThreshold(); |
|
164 } |
|
165 else |
|
166 { |
|
167 return 0; |
|
168 } |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // CMIDPhysicsWrapper::SetPanningPosition |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 void CMIDPhysicsWrapper::RegisterPanningPosition(const TPoint& aPosition) |
|
176 { |
|
177 if (iPhysics) |
|
178 { |
|
179 iPhysics->RegisterPanningPosition(aPosition); |
|
180 } |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CMIDPhysicsWrapper::ViewPositionChanged |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CMIDPhysicsWrapper::ViewPositionChanged(const TPoint& aNewPosition, TBool aDrawNow, TUint aFlags) |
|
188 { |
|
189 if (!iPhysics) |
|
190 { |
|
191 return; |
|
192 } |
|
193 |
|
194 if (iParent && iObserver) |
|
195 { |
|
196 iObserver->ViewPositionChanged(aNewPosition, aDrawNow, aFlags); |
|
197 } |
|
198 } |
|
199 |
|
200 void CMIDPhysicsWrapper::ViewPositionChanged(const TPoint& aNewPosition) |
|
201 { |
|
202 if (!iPhysics) |
|
203 { |
|
204 return; |
|
205 } |
|
206 |
|
207 if (iParent && iObserver) |
|
208 { |
|
209 iObserver->ViewPositionChanged(aNewPosition, ETrue, 0); |
|
210 } |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CMIDPhysicsWrapper::PhysicEmulationEnded |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CMIDPhysicsWrapper::PhysicEmulationEnded() |
|
218 { |
|
219 if (iParent && iObserver) |
|
220 { |
|
221 iObserver->PhysicEmulationEnded(); |
|
222 } |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------------------------- |
|
226 // CMIDPhysicsWrapper::ViewPosition |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 TPoint CMIDPhysicsWrapper::ViewPosition() const |
|
230 { |
|
231 if (iObserver) |
|
232 { |
|
233 return iObserver->ViewPosition(); |
|
234 } |
|
235 else |
|
236 { |
|
237 // Must return something |
|
238 return TPoint(0,0); |
|
239 } |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // CMIDPhysicsWrapper::CanBeStopped |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 TBool CMIDPhysicsWrapper::CanBeStopped() const |
|
247 { |
|
248 if (iPhysics) |
|
249 { |
|
250 return iPhysics->OngoingPhysicsAction() != |
|
251 CAknPhysics::EAknPhysicsActionBouncing; |
|
252 } |
|
253 else |
|
254 { |
|
255 return ETrue; |
|
256 } |
|
257 } |