26
|
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*/)
|
|
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 |
}
|
|
95 |
|
|
96 |
|
|
97 |
// ---------------------------------------------------------------------------
|
|
98 |
// CMIDToLcduiObserver::UnregisterControl
|
|
99 |
// Removes a control from the list of controls allowed
|
|
100 |
// to be used in event processing.
|
|
101 |
// Events which works with this control will be ignored.
|
|
102 |
// ---------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
void CMIDToLcduiObserver::UnregisterControl(CCoeControl& aControl)
|
|
105 |
{
|
|
106 |
TInt index = iRegisteredControls.Find(&aControl);
|
|
107 |
|
|
108 |
if (index != KErrNotFound)
|
|
109 |
{
|
|
110 |
iRegisteredControls.Remove(index);
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
// ---------------------------------------------------------------------------
|
|
116 |
// CMIDToLcduiObserver::FlushControl
|
|
117 |
// Asynchronously flushes the control's graphics content on screen.
|
|
118 |
// The call may origin in other than lcdui thread.
|
|
119 |
// ---------------------------------------------------------------------------
|
|
120 |
//
|
|
121 |
void CMIDToLcduiObserver::FlushControl(
|
|
122 |
CCoeControl& aControl,
|
|
123 |
const TRect& aRect)
|
|
124 |
{
|
|
125 |
// Can run in non lcdui thread
|
|
126 |
|
|
127 |
// Prepare event data
|
|
128 |
TToLcduiEventData data;
|
|
129 |
data.iType = EFlushEvent;
|
|
130 |
data.iRect = aRect;
|
|
131 |
data.iControl = &aControl;
|
|
132 |
|
|
133 |
// Add event to the queue
|
|
134 |
iEventQueue.Send(data);
|
|
135 |
}
|
|
136 |
|
|
137 |
|
|
138 |
// ---------------------------------------------------------------------------
|
|
139 |
// CMIDToLcduiObserver::InvokeDSAResourcesCallback
|
|
140 |
// Asynchronously invokes aConsumer->MdcDSAResourcesCallback
|
|
141 |
// from lcdui thread.
|
|
142 |
// The call may origin in other than lcdui thread.
|
|
143 |
// ---------------------------------------------------------------------------
|
|
144 |
//
|
|
145 |
void CMIDToLcduiObserver::InvokeDSAResourcesCallback(
|
|
146 |
CCoeControl& aControl,
|
|
147 |
MUiEventConsumer& aConsumer)
|
|
148 |
{
|
|
149 |
// Can run in non lcdui thread
|
|
150 |
|
|
151 |
// Prepare event data
|
|
152 |
TToLcduiEventData data;
|
|
153 |
data.iType = EDSAResourcesCallbackEvent;
|
|
154 |
data.iControl = &aControl;
|
|
155 |
data.iConsumer = (void*)&aConsumer;
|
|
156 |
|
|
157 |
// Add event to the queue
|
|
158 |
iEventQueue.Send(data);
|
|
159 |
}
|
|
160 |
|
|
161 |
|
|
162 |
// ---------------------------------------------------------------------------
|
|
163 |
// CMIDToLcduiObserver::InvokeUICallback
|
|
164 |
// Asynchronously invokes aConsumer->MdcUICallback
|
|
165 |
// from lcdui thread.
|
|
166 |
// The call may origin in other than lcdui thread.
|
|
167 |
// ---------------------------------------------------------------------------
|
|
168 |
//
|
|
169 |
void CMIDToLcduiObserver::InvokeUICallback(
|
|
170 |
MUiEventConsumer& aConsumer,
|
|
171 |
TInt aCallbackId)
|
|
172 |
{
|
|
173 |
// Can run in non lcdui thread
|
|
174 |
|
|
175 |
// Prepare event data
|
|
176 |
TToLcduiEventData data;
|
|
177 |
data.iType = EUICallbackEvent;
|
|
178 |
data.iConsumer = (void*)&aConsumer;
|
|
179 |
data.iId = aCallbackId;
|
|
180 |
|
|
181 |
// Add event to the queue
|
|
182 |
iEventQueue.Send(data);
|
|
183 |
}
|
|
184 |
|
|
185 |
|
|
186 |
// ---------------------------------------------------------------------------
|
|
187 |
// CMIDToLcduiObserver::RunL
|
|
188 |
// Handles an active object’s request completion event.
|
|
189 |
// Processes the first available event in queue.
|
|
190 |
// ---------------------------------------------------------------------------
|
|
191 |
//
|
|
192 |
void CMIDToLcduiObserver::RunL()
|
|
193 |
{
|
|
194 |
TToLcduiEventData data;
|
|
195 |
|
|
196 |
// Get the event
|
|
197 |
iEventQueue.Receive(data);
|
|
198 |
|
|
199 |
// Process the event
|
|
200 |
switch (data.iType)
|
|
201 |
{
|
|
202 |
case EFlushEvent:
|
|
203 |
DoFlushControl(data.iControl, data.iRect);
|
|
204 |
break;
|
|
205 |
case EDSAResourcesCallbackEvent:
|
|
206 |
DoInvokeDSAResourcesCallback(data.iControl, (MUiEventConsumer*)data.iConsumer);
|
|
207 |
break;
|
|
208 |
case EUICallbackEvent:
|
|
209 |
DoInvokeUICallback((MUiEventConsumer*)data.iConsumer, data.iId);
|
|
210 |
break;
|
|
211 |
case ELcduiEvent:
|
|
212 |
DoInvokeLcduiEvent((MMIDLcduiEventConsumer*)data.iConsumer,data.iId);
|
|
213 |
break;
|
|
214 |
#ifdef RD_JAVA_NGA_ENABLED
|
|
215 |
case ENotifyContentAdded:
|
|
216 |
DoInvokeNotifyContentAdded(data.iControl, data.iContainer);
|
|
217 |
break;
|
|
218 |
#endif
|
|
219 |
}
|
|
220 |
|
|
221 |
iEventQueue.NotifyDataAvailable(iStatus);
|
|
222 |
SetActive();
|
|
223 |
}
|
|
224 |
|
|
225 |
|
|
226 |
// ---------------------------------------------------------------------------
|
|
227 |
// CMIDToLcduiObserver::DoCancel
|
|
228 |
// Implements cancellation of an outstanding request.
|
|
229 |
// ---------------------------------------------------------------------------
|
|
230 |
//
|
|
231 |
void CMIDToLcduiObserver::DoCancel()
|
|
232 |
{
|
|
233 |
iEventQueue.CancelDataAvailable();
|
|
234 |
}
|
|
235 |
|
|
236 |
|
|
237 |
// ---------------------------------------------------------------------------
|
|
238 |
// CMIDToLcduiObserver::DoFlushControl
|
|
239 |
// Processes the event invoked by FlushControl.
|
|
240 |
// ---------------------------------------------------------------------------
|
|
241 |
//
|
|
242 |
void CMIDToLcduiObserver::DoFlushControl(
|
|
243 |
CCoeControl* aControl,
|
|
244 |
const TRect& aRect)
|
|
245 |
{
|
|
246 |
TInt index = iRegisteredControls.Find(aControl);
|
|
247 |
|
|
248 |
if (index != KErrNotFound)
|
|
249 |
{
|
|
250 |
TPoint relativePos =
|
|
251 |
aControl->Position() - aControl->PositionRelativeToScreen();
|
|
252 |
TRect rectToDraw = aRect;
|
|
253 |
rectToDraw.Move(relativePos);
|
|
254 |
aControl->DrawNow(rectToDraw);
|
|
255 |
}
|
|
256 |
}
|
|
257 |
|
|
258 |
|
|
259 |
// ---------------------------------------------------------------------------
|
|
260 |
// CMIDToLcduiObserver::DoInvokeDSAResourcesCallback
|
|
261 |
// Processes the event invoked by InvokeDSAResourcesCallback.
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
void CMIDToLcduiObserver::DoInvokeDSAResourcesCallback(
|
|
265 |
CCoeControl* aControl,
|
|
266 |
MUiEventConsumer *aConsumer)
|
|
267 |
{
|
|
268 |
TInt index = iRegisteredControls.Find(aControl);
|
|
269 |
|
|
270 |
if (index != KErrNotFound)
|
|
271 |
{
|
|
272 |
RWsSession& session = aControl->ControlEnv()->WsSession();
|
|
273 |
CWsScreenDevice* device = aControl->ControlEnv()->ScreenDevice();
|
|
274 |
RDrawableWindow* window = aControl->DrawableWindow();
|
|
275 |
|
|
276 |
aConsumer->MdcDSAResourcesCallback(session, *device, *window);
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
void CMIDToLcduiObserver::DoInvokeLcduiEvent(
|
|
281 |
MMIDLcduiEventConsumer* aConsumer,
|
|
282 |
TInt aCallbackId)
|
|
283 |
{
|
|
284 |
if (aConsumer)
|
|
285 |
{
|
|
286 |
aConsumer->HandleLcduiEvent(aCallbackId);
|
|
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 |
|
|
303 |
#ifdef RD_JAVA_NGA_ENABLED
|
|
304 |
// ---------------------------------------------------------------------------
|
|
305 |
// CMIDToLcduiObserver::DoInvokeNotifyContentAdded
|
|
306 |
// ---------------------------------------------------------------------------
|
|
307 |
void CMIDToLcduiObserver::DoInvokeNotifyContentAdded(
|
|
308 |
CCoeControl* aControl,
|
|
309 |
MDirectContainer *aContainer)
|
|
310 |
{
|
|
311 |
TInt index = iRegisteredControls.Find(aControl);
|
|
312 |
if (index != KErrNotFound)
|
|
313 |
{
|
|
314 |
aContainer->MdcNotifyContentAdded();
|
|
315 |
}
|
|
316 |
}
|
|
317 |
#endif
|
|
318 |
|
|
319 |
// ---------------------------------------------------------------------------
|
|
320 |
// CSwtDcObserver::InvokeDcEvent
|
|
321 |
// Asynchronously sends an event into a consumer.
|
|
322 |
// The call may origin in other than eswt thread.
|
|
323 |
// ---------------------------------------------------------------------------
|
|
324 |
//
|
|
325 |
void CMIDToLcduiObserver::InvokeLcduiEvent(
|
|
326 |
MMIDLcduiEventConsumer& aConsumer,
|
|
327 |
TInt aCallbackId)
|
|
328 |
{
|
|
329 |
// Can run in non lcdui thread
|
|
330 |
|
|
331 |
// Prepare event data
|
|
332 |
TToLcduiEventData data;
|
|
333 |
data.iType = ELcduiEvent;
|
|
334 |
data.iConsumer = (void*)&aConsumer;
|
|
335 |
data.iId = aCallbackId;
|
|
336 |
|
|
337 |
// Add event to the queue
|
|
338 |
iEventQueue.Send(data);
|
|
339 |
}
|
|
340 |
|