|
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: Provides a way of sending asynchronous |
|
15 * requests from mmapi (JSR-135) to lcdui |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // Using CCoeControl |
|
21 #include <coecntrl.h> |
|
22 // Using MUiEventConsumer |
|
23 #include <reflcdui.h> |
|
24 // Using debug macros. |
|
25 #include <j2me/jdebug.h> |
|
26 |
|
27 #include "CMIDToLcduiObserver.h" |
|
28 |
|
29 |
|
30 // Event queue size |
|
31 const TInt KMaxQueueSlots = 30; |
|
32 |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // CMIDToLcduiObserver::CMIDToLcduiObserver |
|
36 // Constructor. |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CMIDToLcduiObserver::CMIDToLcduiObserver(): |
|
40 CActive(EPriorityStandard) |
|
41 { |
|
42 // Create mutex |
|
43 iEventQueue.CreateLocal(KMaxQueueSlots); |
|
44 |
|
45 // Install self to Active scheduler |
|
46 CActiveScheduler::Add(this); |
|
47 |
|
48 iEventQueue.NotifyDataAvailable(iStatus); |
|
49 SetActive(); |
|
50 } |
|
51 |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CMIDToLcduiObserver::~CMIDToLcduiObserver |
|
55 // Destructor. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CMIDToLcduiObserver::~CMIDToLcduiObserver() |
|
59 { |
|
60 // Unregister all controls |
|
61 iRegisteredControls.Reset(); |
|
62 |
|
63 // Cancel the active object |
|
64 Cancel(); |
|
65 |
|
66 // Close the mutex |
|
67 iEventQueue.Close(); |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CMIDToLcduiObserver::RegisterControl |
|
73 // Allows a control to be used during event processing. |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 #ifdef RD_JAVA_NGA_ENABLED |
|
77 void CMIDToLcduiObserver::RegisterControl( |
|
78 CCoeControl& aControl, MDirectContainer* aCallbackContainer /*= NULL*/) |
|
79 #else |
|
80 void CMIDToLcduiObserver::RegisterControl(CCoeControl& aControl) |
|
81 #endif |
|
82 { |
|
83 TInt index = iRegisteredControls.Find(&aControl); |
|
84 |
|
85 // Append the control only if it have not been added yet |
|
86 if (index == KErrNotFound) |
|
87 { |
|
88 if (iRegisteredControls.Append(&aControl) != KErrNone) |
|
89 { |
|
90 // Appending of control failed |
|
91 DEBUG("CMIDToLcduiObserver::RegisterControl - Append failed"); |
|
92 } |
|
93 |
|
94 #ifdef RD_JAVA_NGA_ENABLED |
|
95 if (aCallbackContainer) |
|
96 { |
|
97 TToLcduiEventData data; |
|
98 data.iType = ENotifyContentAdded; |
|
99 data.iContainer = aCallbackContainer; |
|
100 data.iControl = &aControl; |
|
101 data.iConsumer = NULL; |
|
102 iEventQueue.Send(data); |
|
103 } |
|
104 #endif |
|
105 } |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CMIDToLcduiObserver::UnregisterControl |
|
111 // Removes a control from the list of controls allowed |
|
112 // to be used in event processing. |
|
113 // Events which works with this control will be ignored. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void CMIDToLcduiObserver::UnregisterControl(CCoeControl& aControl) |
|
117 { |
|
118 TInt index = iRegisteredControls.Find(&aControl); |
|
119 |
|
120 if (index != KErrNotFound) |
|
121 { |
|
122 iRegisteredControls.Remove(index); |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CMIDToLcduiObserver::FlushControl |
|
129 // Asynchronously flushes the control's graphics content on screen. |
|
130 // The call may origin in other than lcdui thread. |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CMIDToLcduiObserver::FlushControl( |
|
134 CCoeControl& aControl, |
|
135 const TRect& aRect) |
|
136 { |
|
137 // Can run in non lcdui thread |
|
138 |
|
139 // Prepare event data |
|
140 TToLcduiEventData data; |
|
141 data.iType = EFlushEvent; |
|
142 data.iRect = aRect; |
|
143 data.iControl = &aControl; |
|
144 |
|
145 // Add event to the queue |
|
146 iEventQueue.Send(data); |
|
147 } |
|
148 |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CMIDToLcduiObserver::InvokeDSAResourcesCallback |
|
152 // Asynchronously invokes aConsumer->MdcDSAResourcesCallback |
|
153 // from lcdui thread. |
|
154 // The call may origin in other than lcdui thread. |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CMIDToLcduiObserver::InvokeDSAResourcesCallback( |
|
158 CCoeControl& aControl, |
|
159 MUiEventConsumer& aConsumer) |
|
160 { |
|
161 // Can run in non lcdui thread |
|
162 |
|
163 // Prepare event data |
|
164 TToLcduiEventData data; |
|
165 data.iType = EDSAResourcesCallbackEvent; |
|
166 data.iControl = &aControl; |
|
167 data.iConsumer = &aConsumer; |
|
168 |
|
169 // Add event to the queue |
|
170 iEventQueue.Send(data); |
|
171 } |
|
172 |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // CMIDToLcduiObserver::InvokeUICallback |
|
176 // Asynchronously invokes aConsumer->MdcUICallback |
|
177 // from lcdui thread. |
|
178 // The call may origin in other than lcdui thread. |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CMIDToLcduiObserver::InvokeUICallback( |
|
182 MUiEventConsumer& aConsumer, |
|
183 TInt aCallbackId) |
|
184 { |
|
185 // Can run in non lcdui thread |
|
186 |
|
187 // Prepare event data |
|
188 TToLcduiEventData data; |
|
189 data.iType = EUICallbackEvent; |
|
190 data.iConsumer = &aConsumer; |
|
191 data.iId = aCallbackId; |
|
192 |
|
193 // Add event to the queue |
|
194 iEventQueue.Send(data); |
|
195 } |
|
196 |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // CMIDToLcduiObserver::RunL |
|
200 // Handles an active object’s request completion event. |
|
201 // Processes the first available event in queue. |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 void CMIDToLcduiObserver::RunL() |
|
205 { |
|
206 TToLcduiEventData data; |
|
207 |
|
208 // Get the event |
|
209 iEventQueue.Receive(data); |
|
210 |
|
211 // Process the event |
|
212 switch (data.iType) |
|
213 { |
|
214 case EFlushEvent: |
|
215 DoFlushControl(data.iControl, data.iRect); |
|
216 break; |
|
217 case EDSAResourcesCallbackEvent: |
|
218 DoInvokeDSAResourcesCallback(data.iControl, data.iConsumer); |
|
219 break; |
|
220 case EUICallbackEvent: |
|
221 DoInvokeUICallback(data.iConsumer, data.iId); |
|
222 break; |
|
223 #ifdef RD_JAVA_NGA_ENABLED |
|
224 case ENotifyContentAdded: |
|
225 DoInvokeNotifyContentAdded(data.iControl, data.iContainer); |
|
226 break; |
|
227 #endif |
|
228 } |
|
229 |
|
230 iEventQueue.NotifyDataAvailable(iStatus); |
|
231 SetActive(); |
|
232 } |
|
233 |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // CMIDToLcduiObserver::DoCancel |
|
237 // Implements cancellation of an outstanding request. |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 void CMIDToLcduiObserver::DoCancel() |
|
241 { |
|
242 iEventQueue.CancelDataAvailable(); |
|
243 } |
|
244 |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CMIDToLcduiObserver::DoFlushControl |
|
248 // Processes the event invoked by FlushControl. |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 void CMIDToLcduiObserver::DoFlushControl( |
|
252 CCoeControl* aControl, |
|
253 const TRect& aRect) |
|
254 { |
|
255 TInt index = iRegisteredControls.Find(aControl); |
|
256 |
|
257 if (index != KErrNotFound) |
|
258 { |
|
259 TPoint relativePos = |
|
260 aControl->Position() - aControl->PositionRelativeToScreen(); |
|
261 TRect rectToDraw = aRect; |
|
262 rectToDraw.Move(relativePos); |
|
263 aControl->DrawNow(rectToDraw); |
|
264 } |
|
265 } |
|
266 |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // CMIDToLcduiObserver::DoInvokeDSAResourcesCallback |
|
270 // Processes the event invoked by InvokeDSAResourcesCallback. |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 void CMIDToLcduiObserver::DoInvokeDSAResourcesCallback( |
|
274 CCoeControl* aControl, |
|
275 MUiEventConsumer *aConsumer) |
|
276 { |
|
277 TInt index = iRegisteredControls.Find(aControl); |
|
278 |
|
279 if (index != KErrNotFound) |
|
280 { |
|
281 RWsSession& session = aControl->ControlEnv()->WsSession(); |
|
282 CWsScreenDevice* device = aControl->ControlEnv()->ScreenDevice(); |
|
283 RDrawableWindow* window = aControl->DrawableWindow(); |
|
284 |
|
285 aConsumer->MdcDSAResourcesCallback(session, *device, *window); |
|
286 } |
|
287 } |
|
288 |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // CMIDToLcduiObserver::DoInvokeUICallback |
|
292 // Processes the event invoked by InvokeUICallback. |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void CMIDToLcduiObserver::DoInvokeUICallback( |
|
296 MUiEventConsumer *aConsumer, |
|
297 TInt aCallbackId) |
|
298 { |
|
299 aConsumer->MdcUICallback(aCallbackId); |
|
300 } |
|
301 |
|
302 #ifdef RD_JAVA_NGA_ENABLED |
|
303 // --------------------------------------------------------------------------- |
|
304 // CMIDToLcduiObserver::DoInvokeNotifyContentAdded |
|
305 // --------------------------------------------------------------------------- |
|
306 void CMIDToLcduiObserver::DoInvokeNotifyContentAdded( |
|
307 CCoeControl* aControl, |
|
308 MDirectContainer *aContainer) |
|
309 { |
|
310 TInt index = iRegisteredControls.Find(aControl); |
|
311 if (index != KErrNotFound) |
|
312 { |
|
313 aContainer->MdcNotifyContentAdded(); |
|
314 } |
|
315 } |
|
316 #endif |