112 |
109 |
113 iWs.Flush(); |
110 iWs.Flush(); |
114 |
111 |
115 iWs.SetFocusScreen(iScrId); |
112 iWs.SetFocusScreen(iScrId); |
116 } |
113 } |
117 |
114 |
|
115 class MWsEventObserver |
|
116 { |
|
117 public: |
|
118 virtual void PointerEvent() = 0; |
|
119 }; |
|
120 |
|
121 class CWsEventHandler : public CActive |
|
122 { |
|
123 public: |
|
124 CWsEventHandler(RWsSession& aSession, RWindow& aWindow, MWsEventObserver& aObserver); |
|
125 ~CWsEventHandler(); |
|
126 private: |
|
127 void ConstructL(); |
|
128 void RequestEvent(); |
|
129 void RunL(); |
|
130 void DoCancel(); |
|
131 private: |
|
132 RWsSession& iSession; |
|
133 RWindow& iWindow; |
|
134 MWsEventObserver& iObserver; |
|
135 }; |
|
136 |
|
137 CWsEventHandler::CWsEventHandler(RWsSession& aSession, RWindow& aWindow, MWsEventObserver& aObserver) |
|
138 : CActive(CActive::EPriorityStandard) |
|
139 , iSession(aSession) |
|
140 , iWindow(aWindow) |
|
141 , iObserver(aObserver) |
|
142 { |
|
143 RDebug::Printf("[EBT] CWsEventHandler::CWsEventHandler"); |
|
144 CActiveScheduler::Add(this); |
|
145 RequestEvent(); |
|
146 } |
|
147 |
|
148 CWsEventHandler::~CWsEventHandler() |
|
149 { |
|
150 RDebug::Printf("[EBT] CWsEventHandler::~CWsEventHandler"); |
|
151 Cancel(); |
|
152 } |
|
153 |
|
154 void CWsEventHandler::ConstructL() |
|
155 { |
|
156 CActiveScheduler::Add(this); |
|
157 RequestEvent(); |
|
158 } |
|
159 |
|
160 void CWsEventHandler::RequestEvent() |
|
161 { |
|
162 iStatus = KRequestPending; |
|
163 iSession.EventReady(&iStatus); |
|
164 SetActive(); |
|
165 } |
|
166 |
|
167 void CWsEventHandler::RunL() |
|
168 { |
|
169 if (KErrNone == iStatus.Int()) |
|
170 { |
|
171 TWsEvent event; |
|
172 iSession.GetEvent(event); |
|
173 RequestEvent(); |
|
174 switch (event.Type()) |
|
175 { |
|
176 case EEventPointer: |
|
177 iObserver.PointerEvent(); |
|
178 break; |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 void CWsEventHandler::DoCancel() |
|
184 { |
|
185 iSession.EventReadyCancel(); |
|
186 } |
|
187 |
118 class CWsApp : public CBase |
188 class CWsApp : public CBase |
|
189 , public MWsEventObserver |
119 { |
190 { |
120 public: |
191 public: |
121 static CWsApp* NewL(); |
192 static CWsApp* NewL(); |
122 ~CWsApp(); |
193 ~CWsApp(); |
123 void Start(); |
194 void Start(); |
124 void Stop(); |
195 void Stop(); |
125 |
196 |
126 private: |
197 // MWsEventObserver |
127 static TInt TimerCallBack(TAny* aApp); |
198 void PointerEvent(); |
128 |
199 |
129 private: |
200 private: |
130 CWsApp(); |
201 CWsApp(); |
131 void ConstructL(); |
202 void ConstructL(); |
132 |
203 |
133 private: |
204 private: |
134 CPeriodic* iTimer; |
|
135 CWsCanvas* iAppView; |
205 CWsCanvas* iAppView; |
|
206 CWsEventHandler* iEventHandler; |
136 CEGLRendering* iDemo; |
207 CEGLRendering* iDemo; |
137 TPoint iPos; |
208 TPoint iPos; |
138 TSize iSz; |
209 TSize iSz; |
139 TInt iScrId; |
210 TInt iScrId; |
140 }; |
211 }; |
161 * target the output of the program. By default, screen 0 is used. |
232 * target the output of the program. By default, screen 0 is used. |
162 */ |
233 */ |
163 void CWsApp::ConstructL() |
234 void CWsApp::ConstructL() |
164 { |
235 { |
165 RDebug::Printf("[EBT] CWsApp::ConstructL"); |
236 RDebug::Printf("[EBT] CWsApp::ConstructL"); |
166 |
|
167 // Set a timer to stop the application after a short time |
|
168 iTimer = CPeriodic::NewL(CActive::EPriorityIdle); |
|
169 iTimer->Start(KAppRunDuration, KAppRunDuration, TCallBack(TimerCallBack,this)); |
|
170 |
237 |
171 iScrId = KDefaultScreenNo; |
238 iScrId = KDefaultScreenNo; |
172 if (User::CommandLineLength() > 0) |
239 if (User::CommandLineLength() > 0) |
173 { |
240 { |
174 TBuf<1> arg; |
241 TBuf<1> arg; |
177 } |
244 } |
178 |
245 |
179 RDebug::Printf("[EBT] CWsApp::ConstructL 1"); |
246 RDebug::Printf("[EBT] CWsApp::ConstructL 1"); |
180 iAppView = CWsCanvas::NewL(iScrId, iPos); |
247 iAppView = CWsCanvas::NewL(iScrId, iPos); |
181 RDebug::Printf("[EBT] CWsApp::ConstructL 2"); |
248 RDebug::Printf("[EBT] CWsApp::ConstructL 2"); |
|
249 iEventHandler = new (ELeave) CWsEventHandler(iAppView->Session(), iAppView->Window(), *this); |
|
250 RDebug::Printf("[EBT] CWsApp::ConstructL 3"); |
182 iDemo = CVGLine::NewL(iAppView->Window()); |
251 iDemo = CVGLine::NewL(iAppView->Window()); |
183 RDebug::Printf("[EBT] CWsApp::ConstructL 3"); |
252 RDebug::Printf("[EBT] CWsApp::ConstructL 4"); |
184 iSz = iAppView->ScreenSize(); |
253 iSz = iAppView->ScreenSize(); |
185 RDebug::Printf("[EBT] CWsApp::ConstructL 4"); |
254 RDebug::Printf("[EBT] CWsApp::ConstructL 5"); |
186 } |
255 } |
187 |
|
188 TInt CWsApp::TimerCallBack(TAny* aApp) |
|
189 { |
|
190 RDebug::Printf("[EBT] CWsApp::TimerCallBack"); |
|
191 reinterpret_cast<CWsApp*>(aApp)->Stop(); |
|
192 return KErrNone; |
|
193 } |
|
194 |
256 |
195 void CWsApp::Start() |
257 void CWsApp::Start() |
196 { |
258 { |
197 RDebug::Printf("[EBT] CWsApp::Start"); |
259 RDebug::Printf("[EBT] CWsApp::Start"); |
198 CActiveScheduler::Start(); |
260 CActiveScheduler::Start(); |
202 { |
264 { |
203 RDebug::Printf("[EBT] CWsApp::Stop"); |
265 RDebug::Printf("[EBT] CWsApp::Stop"); |
204 CActiveScheduler::Stop(); |
266 CActiveScheduler::Stop(); |
205 } |
267 } |
206 |
268 |
|
269 void CWsApp::PointerEvent() |
|
270 { |
|
271 RDebug::Printf("[EBT] CWsApp::PointerEvent"); |
|
272 Stop(); |
|
273 } |
|
274 |
207 CWsApp::~CWsApp() |
275 CWsApp::~CWsApp() |
208 { |
276 { |
209 RDebug::Printf("[EBT] CWsApp::~CWsApp"); |
277 RDebug::Printf("[EBT] CWsApp::~CWsApp"); |
210 delete iDemo; |
278 delete iDemo; |
211 RDebug::Printf("[EBT] CWsApp::~CWsApp 1"); |
279 RDebug::Printf("[EBT] CWsApp::~CWsApp 1"); |
|
280 delete iEventHandler; |
|
281 RDebug::Printf("[EBT] CWsApp::~CWsApp 2"); |
212 delete iAppView; |
282 delete iAppView; |
213 RDebug::Printf("[EBT] CWsApp::~CWsApp 2"); |
|
214 delete iTimer; |
|
215 RDebug::Printf("[EBT] CWsApp::~CWsApp 3"); |
283 RDebug::Printf("[EBT] CWsApp::~CWsApp 3"); |
216 } |
284 } |
217 |
285 |
218 /** |
286 /** |
219 * Application second level entry point. |
287 * Application second level entry point. |