|
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 |
|
19 #include <eikenv.h> |
|
20 #include <eiksrvc.h> |
|
21 #include <eikappui.h> |
|
22 #include <Lcdglue.h> |
|
23 #include <j2me/jdebug.h> |
|
24 // needed for javaregistry |
|
25 #include <javaregistryentry.h> |
|
26 #include <javaregistry.h> |
|
27 #include <javaattribute.h> |
|
28 |
|
29 #include "CMIDAppUi.h" |
|
30 // using CMIDApplication API for iApp |
|
31 #include "CMIDApplication.h" |
|
32 // needed for creating CMIDComponentFactory |
|
33 #include "CMIDComponentFactory.h" |
|
34 // constants for repeating key events |
|
35 #include "S60LCDUICustomEvents.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 { |
|
49 mJavaAppUi = java::ui::CoreUiAvkonLcdui::getInstance().getJavaAknAppUi(); |
|
50 mCoreAppUi = java::ui::CoreUiAvkonLcdui::getInstance().getJavaUiAppUi(); |
|
51 } |
|
52 |
|
53 void CMIDAppUi::ConstructL() |
|
54 { |
|
55 DEBUG("+ CMIDAppUi::ConstructL()"); |
|
56 // get uid of the midlet |
|
57 RLcdui::Get()->AttachL(this); |
|
58 DEBUG("- CMIDAppUi::ConstructL()"); |
|
59 } |
|
60 |
|
61 CMIDAppUi::~CMIDAppUi() |
|
62 { |
|
63 iDisplayables.Close(); |
|
64 RLcdui::Get()->Detach(); |
|
65 } |
|
66 |
|
67 void CMIDAppUi::SetCurrentDisplayable(CMIDDisplayable* aDisplayable) |
|
68 { |
|
69 iCurrentDisplayable = aDisplayable; |
|
70 } |
|
71 |
|
72 void CMIDAppUi::HandleCommandL(TInt aCommand) |
|
73 { |
|
74 switch (aCommand) |
|
75 { |
|
76 // Help command received (i.e. after the EStdKeyHelp button was pressed) |
|
77 case EAknCmdHelp: |
|
78 if (iCurrentDisplayable) |
|
79 { |
|
80 // Let the current displayable to process help command |
|
81 iCurrentDisplayable->HandleHelpCommandL(); |
|
82 } |
|
83 break; |
|
84 case EEikCmdExit: |
|
85 if (iObserver) |
|
86 { |
|
87 iObserver->HandleExitL(); |
|
88 } |
|
89 else |
|
90 { |
|
91 // |
|
92 // |
|
93 // |
|
94 } |
|
95 break; |
|
96 } |
|
97 } |
|
98 |
|
99 void CMIDAppUi::HandleSwitchOnEventL(CCoeControl*) |
|
100 { |
|
101 if (iObserver) |
|
102 { |
|
103 iObserver->HandleSwitchOnEventL(); |
|
104 } |
|
105 else |
|
106 { |
|
107 // |
|
108 // |
|
109 // |
|
110 } |
|
111 } |
|
112 |
|
113 void CMIDAppUi::HandleForegroundEventL(TBool aForeground) |
|
114 { |
|
115 if (iObserver) |
|
116 { |
|
117 iObserver->HandleForegroundL(aForeground); |
|
118 } |
|
119 else |
|
120 { |
|
121 // |
|
122 // |
|
123 // |
|
124 } |
|
125 } |
|
126 |
|
127 void CMIDAppUi::HandleResourceChangeL(TInt aType) |
|
128 { |
|
129 if (iObserver) |
|
130 { |
|
131 iObserver->HandleResourceChangeL(aType); |
|
132 } |
|
133 else |
|
134 { |
|
135 // |
|
136 // |
|
137 // |
|
138 } |
|
139 } |
|
140 |
|
141 void CMIDAppUi::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& /*aEvent*/) |
|
142 { |
|
143 if (EEnableMultipleKeyPressedEvent == aType) |
|
144 { |
|
145 mCoreAppUi->glueSetKeyBlockMode(ENoKeyBlock); |
|
146 } |
|
147 else if (EDisableMultipleKeyPressedEvent == aType) |
|
148 { |
|
149 mCoreAppUi->glueSetKeyBlockMode(EDefaultBlockMode); |
|
150 } |
|
151 } |
|
152 |
|
153 TBool CMIDAppUi::HandleWsEventL(const TWsEvent& aEvent, |
|
154 CCoeControl* /*aDestination*/) |
|
155 { |
|
156 |
|
157 // Intercept end-key press when the Nokia-MIDlet-no-exit JAD-attribute is defined. |
|
158 // Intercept the WS event in case of red end-key press |
|
159 if (aEvent.Type() == KAknUidValueEndKeyCloseEvent) |
|
160 { |
|
161 // If JAD attribute Nokia-MIDlet-no-exit is defined, it will be used define End-key behavior |
|
162 if (iEnv && iEnv->MidletAttributeIsSetToVal( |
|
163 LcduiMidletAttributes::KAttribNoExitKey, |
|
164 LcduiMidletAttributeValues::KTrueValue)) |
|
165 { |
|
166 return ETrue; |
|
167 } |
|
168 else |
|
169 { |
|
170 // No JAD attribute. Ask the CoreUi to shutdown the MIDlet. |
|
171 java::ui::CoreUiAvkonLcdui::getInstance().shutDownRequestFromWindowServer(); |
|
172 } |
|
173 } |
|
174 |
|
175 if (aEvent.Type() == EEventUser) |
|
176 { |
|
177 if ((*reinterpret_cast<TApaSystemEvent*>(aEvent.EventData())) == EApaSystemEventShutdown) |
|
178 { |
|
179 // Oom or exit from task-list. Ask the CoreUi to shutdown the MIDlet. |
|
180 java::ui::CoreUiAvkonLcdui::getInstance().shutDownRequestFromWindowServer(); |
|
181 } |
|
182 } |
|
183 |
|
184 // Workaround to send pauseApp with long-press of the Menu key |
|
185 if (aEvent.Type() == EEventKey) |
|
186 { |
|
187 if (aEvent.Key()->iScanCode == EStdKeyApplication0 |
|
188 && aEvent.Key()->iRepeats == 1) |
|
189 { |
|
190 if (iEnv && iEnv->MidletAttributeIsSetToVal( |
|
191 LcduiMidletAttributes::KAttribFlipClose, |
|
192 LcduiMidletAttributeValues::KPauseValue)) |
|
193 { |
|
194 iEnv->PostMidletEvent(EPause); |
|
195 } |
|
196 } |
|
197 } |
|
198 |
|
199 if (aEvent.Type() == EEventKeyUp) |
|
200 { |
|
201 |
|
202 if (aEvent.Key()->iScanCode == EStdKeyDeviceA) // if flip is opened |
|
203 { |
|
204 if (iEnv && iEnv->MidletAttributeIsSetToVal( |
|
205 LcduiMidletAttributes::KAttribFlipClose, |
|
206 LcduiMidletAttributeValues::KPauseValue)) |
|
207 |
|
208 { |
|
209 iEnv->PostMidletEvent(EStart); |
|
210 } |
|
211 } |
|
212 |
|
213 if (aEvent.Key()->iScanCode == EStdKeyDeviceB) // if flip is closed |
|
214 { |
|
215 if (iEnv && iEnv->MidletAttributeIsSetToVal( |
|
216 LcduiMidletAttributes::KAttribFlipClose, |
|
217 LcduiMidletAttributeValues::KPauseValue)) |
|
218 { |
|
219 iEnv->PostMidletEvent(EPause); |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 if (aEvent.Type() == EEventKeyDown) |
|
225 { |
|
226 if (iEnv) |
|
227 { |
|
228 iEnv->SetLastKeyEvent(*aEvent.Key()); |
|
229 } |
|
230 } |
|
231 |
|
232 // Handle application focus lost and notify current Displayable. |
|
233 if ((aEvent.Type() == KAknFullOrPartialForegroundLost) |
|
234 || (aEvent.Type() == EEventFocusLost)) |
|
235 { |
|
236 if (iCurrentDisplayable && (iDisplayables.Count() > 0)) |
|
237 { |
|
238 iCurrentDisplayable->HandleApplicationBackground(); |
|
239 } |
|
240 } |
|
241 |
|
242 // Handle input language change and notify current Displayable |
|
243 if (aEvent.Type() == KEikInputLanguageChange) |
|
244 { |
|
245 if (iCurrentDisplayable) |
|
246 { |
|
247 iCurrentDisplayable->HandleResourceChange(aEvent.Type()); |
|
248 } |
|
249 } |
|
250 |
|
251 return EFalse; |
|
252 } |
|
253 |
|
254 // Sets the link to MMIDEnv - used for jad attribute parsing |
|
255 void CMIDAppUi::SetEnv(MMIDEnv& aEnv) |
|
256 { |
|
257 iEnv = &aEnv; |
|
258 } |
|
259 |
|
260 void CMIDAppUi::UnSetEnv() |
|
261 { |
|
262 iEnv = 0; |
|
263 } |
|
264 |
|
265 // |
|
266 // From MLcduiPlugin |
|
267 // |
|
268 void CMIDAppUi::SetObserver(MMIDObserver* aObserver) |
|
269 { |
|
270 iObserver = aObserver; |
|
271 } |
|
272 |
|
273 // |
|
274 // From MLcduiPlugin |
|
275 // |
|
276 MMIDComponentFactory* CMIDAppUi::CreateComponentFactoryL() |
|
277 { |
|
278 return new(ELeave) CMIDComponentFactory; |
|
279 } |
|
280 |
|
281 RPointerArray<CMIDDisplayable>& CMIDAppUi::Displayables() |
|
282 { |
|
283 return iDisplayables; |
|
284 } |
|
285 |
|
286 void CMIDAppUi::AddToStackL(CCoeControl *aControl, TInt aPriority, TInt aStackingFlags) |
|
287 { |
|
288 JELOG2(EJavaUI); |
|
289 mJavaAppUi->AddToStackL(aControl, aPriority, aStackingFlags); |
|
290 } |
|
291 |
|
292 TRect CMIDAppUi::ApplicationRect() const |
|
293 { |
|
294 JELOG2(EJavaUI); |
|
295 return mJavaAppUi->ApplicationRect(); |
|
296 } |
|
297 |
|
298 TRect CMIDAppUi::ClientRect() const |
|
299 { |
|
300 JELOG2(EJavaUI); |
|
301 return mJavaAppUi->ClientRect(); |
|
302 } |
|
303 |
|
304 CAknToolbar* CMIDAppUi::CurrentFixedToolbar() const |
|
305 { |
|
306 JELOG2(EJavaUI); |
|
307 return mJavaAppUi->CurrentFixedToolbar(); |
|
308 } |
|
309 |
|
310 void CMIDAppUi::RemoveFromStack(CCoeControl *aControl) |
|
311 { |
|
312 JELOG2(EJavaUI); |
|
313 mJavaAppUi->RemoveFromStack(aControl); |
|
314 } |
|
315 |
|
316 CEikStatusPane* CMIDAppUi::StatusPane() |
|
317 { |
|
318 JELOG2(EJavaUI); |
|
319 return mJavaAppUi->StatusPane(); |
|
320 } |
|
321 |