|
1 /* |
|
2 * Copyright (c) 1999-2001 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <eikenv.h> |
|
19 #include <eiksrvc.h> |
|
20 #include <eikappui.h> |
|
21 #include <Lcdglue.h> |
|
22 #include <j2me/jdebug.h> |
|
23 // needed for javaregistry |
|
24 #include <javaregistryentry.h> |
|
25 #include <javaregistry.h> |
|
26 #include <javaattribute.h> |
|
27 #ifdef RD_JAVA_NGA_ENABLED |
|
28 #include <goommonitorsession.h> |
|
29 #include <goommonitorplugin.hrh> |
|
30 #endif // RD_JAVA_NGA_ENABLED |
|
31 #include "CMIDAppUi.h" |
|
32 // using CMIDApplication API for iApp |
|
33 #include "CMIDApplication.h" |
|
34 // needed for creating CMIDComponentFactory |
|
35 #include "CMIDComponentFactory.h" |
|
36 // CMIDDisplayable class for iCurrentDisplayable |
|
37 #include "CMIDDisplayable.h" |
|
38 |
|
39 #include "LcduiThread.h" |
|
40 |
|
41 #include "logger.h" |
|
42 |
|
43 using namespace java::ui; |
|
44 using namespace Java; |
|
45 |
|
46 // class CMIDAppUi |
|
47 CMIDAppUi::CMIDAppUi() : iCurrentDisplayable(NULL), |
|
48 iPendingOrientationChange(EFalse), iPauseApp(EFalse) |
|
49 { |
|
50 mJavaAppUi = java::ui::CoreUiAvkonLcdui::getInstance().getJavaAknAppUi(); |
|
51 mCoreAppUi = java::ui::CoreUiAvkonLcdui::getInstance().getJavaUiAppUi(); |
|
52 } |
|
53 |
|
54 void CMIDAppUi::ConstructL() |
|
55 { |
|
56 DEBUG("+ CMIDAppUi::ConstructL()"); |
|
57 // get uid of the midlet |
|
58 RLcdui::Get()->AttachL(this); |
|
59 DEBUG("- CMIDAppUi::ConstructL()"); |
|
60 } |
|
61 |
|
62 CMIDAppUi::~CMIDAppUi() |
|
63 { |
|
64 iDisplayables.Close(); |
|
65 RLcdui::Get()->Detach(); |
|
66 } |
|
67 |
|
68 void CMIDAppUi::SetCurrentDisplayable(CMIDDisplayable* aDisplayable) |
|
69 { |
|
70 iCurrentDisplayable = aDisplayable; |
|
71 } |
|
72 |
|
73 void CMIDAppUi::HandleCommandL(TInt aCommand) |
|
74 { |
|
75 switch (aCommand) |
|
76 { |
|
77 // Help command received (i.e. after the EStdKeyHelp button was pressed) |
|
78 case EAknCmdHelp: |
|
79 if (iCurrentDisplayable) |
|
80 { |
|
81 // Let the current displayable to process help command |
|
82 iCurrentDisplayable->HandleHelpCommandL(); |
|
83 } |
|
84 break; |
|
85 case EEikCmdExit: |
|
86 if (iObserver) |
|
87 { |
|
88 iObserver->HandleExitL(); |
|
89 } |
|
90 else |
|
91 { |
|
92 // |
|
93 // |
|
94 // |
|
95 } |
|
96 break; |
|
97 } |
|
98 } |
|
99 |
|
100 void CMIDAppUi::HandleSwitchOnEventL(CCoeControl*) |
|
101 { |
|
102 if (iObserver) |
|
103 { |
|
104 iObserver->HandleSwitchOnEventL(); |
|
105 } |
|
106 else |
|
107 { |
|
108 // |
|
109 // |
|
110 // |
|
111 } |
|
112 } |
|
113 |
|
114 void CMIDAppUi::HandleForegroundEventL(TBool aForeground) |
|
115 { |
|
116 if (iObserver) |
|
117 { |
|
118 iObserver->HandleForegroundL(aForeground); |
|
119 } |
|
120 else |
|
121 { |
|
122 // |
|
123 // |
|
124 // |
|
125 } |
|
126 } |
|
127 |
|
128 void CMIDAppUi::HandleResourceChangeL(TInt aType) |
|
129 { |
|
130 if (iObserver) |
|
131 { |
|
132 iObserver->HandleResourceChangeL(aType); |
|
133 } |
|
134 else |
|
135 { |
|
136 if (aType == KEikDynamicLayoutVariantSwitch) |
|
137 { |
|
138 // Observer not set yet. Storing it for use after it is set. |
|
139 iPendingOrientationChange= ETrue; |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 void CMIDAppUi::HandleApplicationSpecificEventL(TInt /*aType*/, const TWsEvent& /*aEvent*/) |
|
145 { |
|
146 } |
|
147 |
|
148 TBool CMIDAppUi::HandleWsEventL(const TWsEvent& aEvent, |
|
149 CCoeControl* /*aDestination*/) |
|
150 { |
|
151 |
|
152 // Intercept end-key press when the Nokia-MIDlet-no-exit JAD-attribute is defined. |
|
153 // Intercept the WS event in case of red end-key press |
|
154 if (aEvent.Type() == KAknUidValueEndKeyCloseEvent) |
|
155 { |
|
156 // If JAD attribute Nokia-MIDlet-no-exit is defined, it will be used define End-key behavior |
|
157 if (iEnv && iEnv->MidletAttributeIsSetToVal( |
|
158 LcduiMidletAttributes::KAttribNoExitKey, |
|
159 LcduiMidletAttributeValues::KTrueValue)) |
|
160 { |
|
161 return ETrue; |
|
162 } |
|
163 else |
|
164 { |
|
165 // No JAD attribute. Ask the CoreUi to shutdown the MIDlet. |
|
166 java::ui::CoreUiAvkonLcdui::getInstance().shutDownRequestFromWindowServer(); |
|
167 } |
|
168 } |
|
169 |
|
170 if (aEvent.Type() == EEventUser) |
|
171 { |
|
172 TApaSystemEvent* eventData = reinterpret_cast<TApaSystemEvent*>(aEvent.EventData()); |
|
173 if ((*eventData) == EApaSystemEventShutdown) |
|
174 { |
|
175 #ifdef RD_JAVA_NGA_ENABLED |
|
176 // Check the reason |
|
177 eventData++; |
|
178 if ((*eventData) == KGoomMemoryLowEvent) |
|
179 { |
|
180 return HandleGoomMemoryLowEventL(); |
|
181 } |
|
182 #endif // RD_JAVA_NGA_ENABLED |
|
183 // Oom or exit from task-list. Ask the CoreUi to shutdown the MIDlet. |
|
184 java::ui::CoreUiAvkonLcdui::getInstance().shutDownRequestFromWindowServer(); |
|
185 } |
|
186 } |
|
187 |
|
188 // Workaround to send pauseApp with long-press of the Menu key |
|
189 // if no event was send yet |
|
190 if (aEvent.Type() == EEventKey) |
|
191 { |
|
192 if (aEvent.Key()->iScanCode == EStdKeyApplication0 |
|
193 && aEvent.Key()->iRepeats == 1 && !iPauseApp) |
|
194 { |
|
195 if (iEnv && iEnv->MidletAttributeIsSetToVal( |
|
196 LcduiMidletAttributes::KAttribFlipClose, |
|
197 LcduiMidletAttributeValues::KPauseValue)) |
|
198 { |
|
199 iEnv->PostMidletEvent(EPause); |
|
200 SetPauseAppState(ETrue); |
|
201 } |
|
202 } |
|
203 } |
|
204 |
|
205 if (aEvent.Type() == EEventKeyUp) |
|
206 { |
|
207 |
|
208 if (aEvent.Key()->iScanCode == EStdKeyDeviceA) // if flip is opened |
|
209 { |
|
210 if (iEnv && iEnv->MidletAttributeIsSetToVal( |
|
211 LcduiMidletAttributes::KAttribFlipClose, |
|
212 LcduiMidletAttributeValues::KPauseValue)) |
|
213 |
|
214 { |
|
215 iEnv->PostMidletEvent(EStart); |
|
216 } |
|
217 } |
|
218 |
|
219 if (aEvent.Key()->iScanCode == EStdKeyDeviceB) // if flip is closed |
|
220 { |
|
221 if (iEnv && iEnv->MidletAttributeIsSetToVal( |
|
222 LcduiMidletAttributes::KAttribFlipClose, |
|
223 LcduiMidletAttributeValues::KPauseValue)) |
|
224 { |
|
225 iEnv->PostMidletEvent(EPause); |
|
226 } |
|
227 } |
|
228 } |
|
229 |
|
230 if (aEvent.Type() == EEventKeyDown) |
|
231 { |
|
232 if (iEnv) |
|
233 { |
|
234 iEnv->SetLastKeyEvent(*aEvent.Key()); |
|
235 } |
|
236 } |
|
237 |
|
238 // Handle application focus lost and notify current Displayable. |
|
239 if ((aEvent.Type() == KAknFullOrPartialForegroundLost) |
|
240 || (aEvent.Type() == EEventFocusLost)) |
|
241 { |
|
242 #ifdef RD_JAVA_NGA_ENABLED |
|
243 if (aEvent.Type() == KAknFullOrPartialForegroundLost && iObserver) |
|
244 { |
|
245 iObserver->HandleFullOrPartialForegroundL(EFalse); |
|
246 } |
|
247 #endif // RD_JAVA_NGA_ENABLED |
|
248 |
|
249 if (iCurrentDisplayable && (iDisplayables.Count() > 0)) |
|
250 { |
|
251 iCurrentDisplayable->HandleApplicationBackground(); |
|
252 } |
|
253 } |
|
254 |
|
255 // Handle input language change and notify current Displayable |
|
256 if (aEvent.Type() == KEikInputLanguageChange) |
|
257 { |
|
258 if (iCurrentDisplayable) |
|
259 { |
|
260 iCurrentDisplayable->HandleResourceChange(aEvent.Type()); |
|
261 } |
|
262 } |
|
263 |
|
264 #ifdef RD_JAVA_NGA_ENABLED |
|
265 if (aEvent.Type() == KAknFullOrPartialForegroundGained && iObserver) |
|
266 { |
|
267 iObserver->HandleFullOrPartialForegroundL(ETrue); |
|
268 } |
|
269 #endif // RD_JAVA_NGA_ENABLED |
|
270 |
|
271 return EFalse; |
|
272 } |
|
273 |
|
274 // Sets the link to MMIDEnv - used for jad attribute parsing |
|
275 void CMIDAppUi::SetEnv(MMIDEnv& aEnv) |
|
276 { |
|
277 iEnv = &aEnv; |
|
278 } |
|
279 |
|
280 void CMIDAppUi::UnSetEnv() |
|
281 { |
|
282 iEnv = 0; |
|
283 } |
|
284 |
|
285 #ifdef RD_JAVA_NGA_ENABLED |
|
286 TBool CMIDAppUi::HandleGoomMemoryLowEventL() |
|
287 { |
|
288 if (iObserver) |
|
289 { |
|
290 iObserver->HandleFreeGraphicsMemory(); |
|
291 RGOomMonitorSession session; |
|
292 User::LeaveIfError(session.Connect()); |
|
293 session.ThisAppIsNotExiting(CCoeEnv::Static()->RootWin().Identifier()); |
|
294 session.Close(); |
|
295 return ETrue; |
|
296 } |
|
297 return EFalse; |
|
298 } |
|
299 #endif // RD_JAVA_NGA_ENABLED |
|
300 |
|
301 // |
|
302 // From MLcduiPlugin |
|
303 // |
|
304 void CMIDAppUi::SetObserverL(MMIDObserver* aObserver) |
|
305 { |
|
306 iObserver = aObserver; |
|
307 if (iPendingOrientationChange) |
|
308 { |
|
309 // We have received orientation change during the construction phase. |
|
310 // Resending it again in order to ensure correct layout and |
|
311 // orientation. |
|
312 iObserver->HandleResourceChangeL(KEikDynamicLayoutVariantSwitch); |
|
313 iPendingOrientationChange = EFalse; |
|
314 } |
|
315 } |
|
316 |
|
317 // |
|
318 // From MLcduiPlugin |
|
319 // |
|
320 MMIDComponentFactory* CMIDAppUi::CreateComponentFactoryL() |
|
321 { |
|
322 return new(ELeave) CMIDComponentFactory; |
|
323 } |
|
324 |
|
325 // |
|
326 // From MLcduiPlugin |
|
327 // |
|
328 void CMIDAppUi::SetEnv(MMIDEnv* aEnv) |
|
329 { |
|
330 iEnv = aEnv; |
|
331 } |
|
332 |
|
333 RPointerArray<CMIDDisplayable>& CMIDAppUi::Displayables() |
|
334 { |
|
335 return iDisplayables; |
|
336 } |
|
337 |
|
338 void CMIDAppUi::AddToStackL(CCoeControl *aControl, TInt aPriority, TInt aStackingFlags) |
|
339 { |
|
340 JELOG2(EJavaUI); |
|
341 mJavaAppUi->AddToStackL(aControl, aPriority, aStackingFlags); |
|
342 } |
|
343 |
|
344 TRect CMIDAppUi::ApplicationRect() const |
|
345 { |
|
346 JELOG2(EJavaUI); |
|
347 return mJavaAppUi->ApplicationRect(); |
|
348 } |
|
349 |
|
350 TRect CMIDAppUi::ClientRect() const |
|
351 { |
|
352 JELOG2(EJavaUI); |
|
353 return mJavaAppUi->ClientRect(); |
|
354 } |
|
355 |
|
356 CAknToolbar* CMIDAppUi::CurrentFixedToolbar() const |
|
357 { |
|
358 JELOG2(EJavaUI); |
|
359 return mJavaAppUi->CurrentFixedToolbar(); |
|
360 } |
|
361 |
|
362 void CMIDAppUi::RemoveFromStack(CCoeControl *aControl) |
|
363 { |
|
364 JELOG2(EJavaUI); |
|
365 mJavaAppUi->RemoveFromStack(aControl); |
|
366 } |
|
367 |
|
368 CEikStatusPane* CMIDAppUi::StatusPane() |
|
369 { |
|
370 JELOG2(EJavaUI); |
|
371 return mJavaAppUi->StatusPane(); |
|
372 } |
|
373 |
|
374 void CMIDAppUi::SetPauseAppState(TBool aState) |
|
375 { |
|
376 JELOG2(EJavaUI); |
|
377 iPauseApp = aState; |
|
378 } |
|
379 |
|
380 TBool CMIDAppUi::GetPauseAppState() |
|
381 { |
|
382 JELOG2(EJavaUI); |
|
383 return iPauseApp; |
|
384 } |
|
385 |