|
1 /* |
|
2 * Copyright (c) 2002 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 // AKNSHUT.CPP |
|
19 // |
|
20 // Copyright (c) 1997-2001 Symbian Ltd. All rights reserved. |
|
21 // |
|
22 |
|
23 // |
|
24 // CAknShutter |
|
25 // |
|
26 |
|
27 #include "aknshut.h" |
|
28 #include <eikenv.h> |
|
29 #include "aknViewAppUi.h" |
|
30 #include <basched.h> |
|
31 #include <coemain.h> |
|
32 #include <uikon.hrh> |
|
33 #include "aknview.h" |
|
34 #include <oommonitorsession.h> |
|
35 |
|
36 #include<aknenv.h> |
|
37 #include<eikapp.h> |
|
38 #include<akntranseffect.h> |
|
39 #include"transitionmanager.h" |
|
40 #include <akntoolbar.h> |
|
41 #include <AknPriv.hrh> |
|
42 |
|
43 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
44 #include <uikon/eikenvinterface.h> |
|
45 #endif |
|
46 |
|
47 |
|
48 class CKludgeScheduler : public CBaActiveScheduler |
|
49 { |
|
50 public: |
|
51 inline TInt PublicLevel() const { return Level(); } |
|
52 }; |
|
53 |
|
54 const TInt KMaxNumEscKeysToSend=50; |
|
55 |
|
56 |
|
57 CAknShutter::CAknShutter(CEikonEnv& aEikEnv, CAknAppUi* aBaseAppUi) |
|
58 :CActive(EActivePriorityWsEvents+1), |
|
59 iEikEnv(aEikEnv), |
|
60 iBaseAppUi(aBaseAppUi), |
|
61 iStartLevel(StartLevel()), |
|
62 iCount(0) |
|
63 { |
|
64 CActiveScheduler::Add(this); |
|
65 } |
|
66 |
|
67 TInt CAknShutter::StartLevel() |
|
68 { |
|
69 return ((CKludgeScheduler*)CActiveScheduler::Current())->PublicLevel(); |
|
70 } |
|
71 |
|
72 CAknShutter::~CAknShutter() |
|
73 { |
|
74 Cancel(); |
|
75 } |
|
76 |
|
77 void CAknShutter::DoCancel() |
|
78 { |
|
79 } |
|
80 |
|
81 void CAknShutter::Queue() |
|
82 { |
|
83 if (!IsActive()) |
|
84 { |
|
85 TRequestStatus *pS=(&iStatus); |
|
86 User::RequestComplete(pS,0); |
|
87 SetActive(); |
|
88 } |
|
89 } |
|
90 |
|
91 void CAknShutter::RunL() |
|
92 { |
|
93 if (iCount++>KMaxNumEscKeysToSend) |
|
94 { |
|
95 Stop(); // give up |
|
96 return; |
|
97 } |
|
98 TInt startLevel=StartLevel(); |
|
99 if (startLevel>iStartLevel) |
|
100 { |
|
101 Stop(); // give up: application has put up some query dialog |
|
102 return; |
|
103 } |
|
104 iStartLevel=startLevel; |
|
105 CEikAppUi* appUi=iEikEnv.EikAppUi(); |
|
106 if (iBaseAppUi != appUi && appUi->ContainerAppUi()) |
|
107 { |
|
108 // embedded app will not be going through a view transition, so send |
|
109 // events to the app UI. |
|
110 if (appUi->IsDisplayingMenuOrDialog()) |
|
111 { |
|
112 Queue(); // before any call to CActiveScheduler::Start() from below |
|
113 TKeyEvent key; |
|
114 key.iRepeats=0; |
|
115 key.iCode=EKeyEscape; |
|
116 key.iModifiers=0; |
|
117 key.iScanCode = EStdKeyNull; |
|
118 iEikEnv.SimulateKeyEventL(key, EEventKey); |
|
119 } |
|
120 else |
|
121 { |
|
122 Queue(); // before any call to CActiveScheduler::Start() from below |
|
123 appUi->StopDisplayingMenuBar(); |
|
124 appUi->HandleCommandL(EEikCmdExit); |
|
125 } |
|
126 } |
|
127 else if (IsDisplayingMenuOrDialog()) |
|
128 { |
|
129 Queue(); // before any call to CActiveScheduler::Start() from below |
|
130 TKeyEvent key; |
|
131 key.iRepeats=0; |
|
132 key.iCode=EKeyEscape; |
|
133 key.iModifiers=0; |
|
134 key.iScanCode = EStdKeyNull; |
|
135 SimulateKeyEventL(key); |
|
136 } |
|
137 else if (iEikEnv.EikAppUi()->IsDisplayingMenuOrDialog()) |
|
138 { // app ui control stack check - only works in view shutter, already checked in app shutter |
|
139 Queue(); // before any call to CActiveScheduler::Start() from below |
|
140 TKeyEvent key; |
|
141 key.iRepeats=0; |
|
142 key.iCode=EKeyEscape; |
|
143 key.iModifiers=0; |
|
144 key.iScanCode = EStdKeyNull; |
|
145 iEikEnv.SimulateKeyEventL(key,EEventKey); |
|
146 } |
|
147 else |
|
148 { // shut menus |
|
149 StopDisplayingMenuBar(); |
|
150 ExitL(); |
|
151 Stop(); // give up |
|
152 DeleteSelfIfSelfOwned(); |
|
153 return; |
|
154 } |
|
155 } |
|
156 |
|
157 void CAknShutter::DeleteSelfWhenReady() |
|
158 { |
|
159 if (!iSelfOwned) |
|
160 delete this; |
|
161 } |
|
162 |
|
163 void CAknShutter::DeleteSelfIfSelfOwned() |
|
164 { |
|
165 if (iSelfOwned) |
|
166 delete this; |
|
167 } |
|
168 |
|
169 TInt CAknShutter::RunError(TInt aError) |
|
170 { |
|
171 DeleteSelfIfSelfOwned(); |
|
172 return aError; |
|
173 } |
|
174 |
|
175 LOCAL_C CAknEnv& AknEnv(CEikonEnv& aEnv) |
|
176 { |
|
177 return static_cast<CAknEnv&>(*aEnv.Extension()); |
|
178 } |
|
179 |
|
180 |
|
181 CAknAppShutter* CAknAppShutter::NewL(CEikonEnv& aEikEnv, CAknAppUi* aBaseAppUi, CAknAppShutter** aSelfPtr) |
|
182 { |
|
183 return new(ELeave) CAknAppShutter(aEikEnv, aBaseAppUi, aSelfPtr); |
|
184 } |
|
185 |
|
186 CAknAppShutter::CAknAppShutter(CEikonEnv& aEikEnv, CAknAppUi* aBaseAppUi, CAknAppShutter** aSelfPtr) |
|
187 : CAknShutter(aEikEnv, aBaseAppUi), iSelfPtr(aSelfPtr) |
|
188 { |
|
189 } |
|
190 |
|
191 void CAknAppShutter::Start() |
|
192 { |
|
193 if(iBaseAppUi->IsForeground() && iBaseAppUi->Document() ) |
|
194 { |
|
195 //only if focused, otherwise next app HandleForeground may never come. |
|
196 AknEnv(iEikEnv).TransitionEvent(AknTransEffect::EApplicationExit, iBaseAppUi->Application()->AppDllUid()); |
|
197 } |
|
198 |
|
199 iStartLevel = StartLevel(); |
|
200 iCount = 0; |
|
201 Queue(); |
|
202 } |
|
203 |
|
204 TBool CAknAppShutter::IsDisplayingMenuOrDialog() const |
|
205 { |
|
206 return iEikEnv.EikAppUi()->IsDisplayingMenuOrDialog(); |
|
207 } |
|
208 |
|
209 void CAknAppShutter::SimulateKeyEventL(const TKeyEvent& aKeyEvent) |
|
210 { |
|
211 iEikEnv.SimulateKeyEventL(aKeyEvent,EEventKey); |
|
212 } |
|
213 |
|
214 void CAknAppShutter::StopDisplayingMenuBar() |
|
215 { |
|
216 iEikEnv.EikAppUi()->StopDisplayingMenuBar(); |
|
217 } |
|
218 |
|
219 void CAknAppShutter::ExitL() |
|
220 { |
|
221 StopDisplayingToolbar(); |
|
222 // app ui can't delete this object in destructor if it's running |
|
223 iSelfOwned = ETrue; |
|
224 CAknAppShutter** appUiSelfPtr = iSelfPtr; |
|
225 if (iSelfPtr) |
|
226 { |
|
227 ASSERT(*iSelfPtr == this); |
|
228 *iSelfPtr = NULL; |
|
229 iSelfPtr = NULL; |
|
230 } |
|
231 iEikEnv.EikAppUi()->HandleCommandL(EEikCmdExit); |
|
232 |
|
233 // If we got here, app has not closed as requested. Tell the OOM monitor |
|
234 ROomMonitorSession oomMonitor; |
|
235 if (oomMonitor.Connect() == KErrNone) |
|
236 { |
|
237 oomMonitor.ThisAppIsNotExiting(iEikEnv.RootWin().Identifier()); |
|
238 oomMonitor.Close(); |
|
239 } |
|
240 |
|
241 // also check that the app has not started another app shutter |
|
242 if (appUiSelfPtr && *appUiSelfPtr && (*appUiSelfPtr)->IsActive()) |
|
243 { |
|
244 (*appUiSelfPtr)->DeleteSelfWhenReady(); |
|
245 *appUiSelfPtr = NULL; |
|
246 } |
|
247 } |
|
248 |
|
249 void CAknAppShutter::Stop() |
|
250 { |
|
251 AknEnv(iEikEnv).TransitionEvent(KAknTransitionExitCancel); |
|
252 |
|
253 Cancel(); |
|
254 } |
|
255 |
|
256 void CAknAppShutter::StopDisplayingToolbar() |
|
257 { |
|
258 CAknAppUi* appUi = static_cast<CAknAppUi*>( iEikEnv.EikAppUi() ); |
|
259 CAknToolbar* appToolbar = 0; |
|
260 |
|
261 if ( appUi && appUi->CurrentPopupToolbar() ) |
|
262 { |
|
263 appToolbar = appUi->CurrentPopupToolbar(); |
|
264 } |
|
265 else if ( appUi && appUi->PopupToolbar() ) |
|
266 { |
|
267 appToolbar = appUi->PopupToolbar(); |
|
268 } |
|
269 |
|
270 if ( appToolbar ) |
|
271 { |
|
272 appToolbar->HandleResourceChange( KAknToolbarSetHidden ); |
|
273 } |
|
274 } |
|
275 |
|
276 CAknViewShutter::~CAknViewShutter() |
|
277 { |
|
278 iViews.Reset(); |
|
279 } |
|
280 |
|
281 CAknViewShutter* CAknViewShutter::NewL(CEikonEnv& aEikEnv, CAknAppUi* aBaseAppUi) |
|
282 { |
|
283 return new(ELeave) CAknViewShutter(aEikEnv, aBaseAppUi); |
|
284 } |
|
285 |
|
286 void CAknViewShutter::Start( const RPointerArray<CAknView>& aViews ) |
|
287 { |
|
288 iViews.Reset(); |
|
289 |
|
290 for ( TInt i = 0; i < aViews.Count(); i++ ) |
|
291 { |
|
292 TRAP_IGNORE( iViews.AppendL( aViews[i] ) ); |
|
293 } |
|
294 |
|
295 iStartLevel = StartLevel(); |
|
296 iCount = 0; |
|
297 Queue(); |
|
298 } |
|
299 |
|
300 CAknViewShutter::CAknViewShutter(CEikonEnv& aEikEnv, CAknAppUi* aBaseAppUi) |
|
301 : CAknShutter(aEikEnv, aBaseAppUi) |
|
302 { |
|
303 } |
|
304 |
|
305 TBool CAknViewShutter::IsDisplayingMenuOrDialog() const |
|
306 { |
|
307 return iEikEnv.EikAppUi()->IsDisplayingMenuOrDialog(); |
|
308 } |
|
309 |
|
310 void CAknViewShutter::SimulateKeyEventL(const TKeyEvent& aKeyEvent) |
|
311 { |
|
312 iEikEnv.SimulateKeyEventL(aKeyEvent,EEventKey); |
|
313 } |
|
314 |
|
315 void CAknViewShutter::StopDisplayingMenuBar() |
|
316 { |
|
317 for ( TInt i = 0; i < iViews.Count(); i++ ) |
|
318 { |
|
319 iViews[i]->StopDisplayingMenuBar(); |
|
320 } |
|
321 } |
|
322 |
|
323 void CAknViewShutter::ExitL() |
|
324 { |
|
325 for ( TInt i = 0; i < iViews.Count(); i++ ) |
|
326 { |
|
327 iViews[i]->AknViewDeactivated(); |
|
328 } |
|
329 } |
|
330 |
|
331 void CAknViewShutter::Stop() |
|
332 { |
|
333 Cancel(); |
|
334 } |
|
335 |
|
336 // End of File |