|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <w32std.h>// key event |
|
19 #include <apgwgnam.h>// for CApaWindowGroupName |
|
20 #include <apgtask.h> |
|
21 #include <coedef.h> |
|
22 #include <f32file.h> |
|
23 #include <flogger.h> |
|
24 #include <e32property.h> |
|
25 #include <startupdomainpskeys.h> |
|
26 |
|
27 #include "tsbackstepping.h" |
|
28 |
|
29 const TUid KHSUid = {0x20022f35}; |
|
30 const int KOrdinalPositionNoZOrder(-1); |
|
31 |
|
32 |
|
33 /** |
|
34 * CTsBackstepping::NewL |
|
35 * two phase constructor |
|
36 */ |
|
37 EXPORT_C CTsBackstepping* CTsBackstepping::NewL(RWsSession &session) |
|
38 { |
|
39 RDebug::Print(_L("CTsBackstepping::NewL")); |
|
40 CTsBackstepping* self = CTsBackstepping::NewLC(session); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 /** |
|
46 * CTsBackstepping::NewLC |
|
47 * two phase constructor |
|
48 */ |
|
49 EXPORT_C CTsBackstepping* CTsBackstepping::NewLC(RWsSession &session) |
|
50 { |
|
51 CTsBackstepping* self = new (ELeave) CTsBackstepping(session); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 /** |
|
58 * CTsBackstepping::CTsBackstepping |
|
59 * constructor |
|
60 */ |
|
61 CTsBackstepping::CTsBackstepping(RWsSession &session) |
|
62 :CActive(EPriorityStandard), |
|
63 mWsSession(session) |
|
64 { |
|
65 CActiveScheduler::Add(this); |
|
66 } |
|
67 |
|
68 |
|
69 /** |
|
70 * CTsBackstepping::~CTsBackstepping |
|
71 * deconstructor |
|
72 */ |
|
73 EXPORT_C CTsBackstepping::~CTsBackstepping() |
|
74 { |
|
75 RDebug::Print(_L("CTsBackstepping::~CTsBackstepping")); |
|
76 // Cancel AO |
|
77 Cancel(); |
|
78 // Close opened session |
|
79 mWg.Close(); |
|
80 |
|
81 } |
|
82 |
|
83 /** |
|
84 * CTsBackstepping::ConstructL |
|
85 * two phase constructor |
|
86 */ |
|
87 void CTsBackstepping::ConstructL () |
|
88 { |
|
89 RDebug::Print(_L("CTsBackstepping::ConstructL")); |
|
90 // Initial window group |
|
91 mWg = RWindowGroup (mWsSession); |
|
92 User::LeaveIfError (mWg.Construct ((TUint32)&mWg, EFalse)); |
|
93 mWg.SetOrdinalPosition (KOrdinalPositionNoZOrder); |
|
94 mWg.EnableReceiptOfFocus (EFalse); |
|
95 |
|
96 // Hide window |
|
97 CApaWindowGroupName* wn = CApaWindowGroupName::NewLC (mWsSession); |
|
98 wn->SetHidden (ETrue); |
|
99 wn->SetWindowGroupName (mWg); |
|
100 CleanupStack::PopAndDestroy (wn); |
|
101 |
|
102 // Window group change event |
|
103 User::LeaveIfError (mWg.EnableGroupListChangeEvents()); |
|
104 |
|
105 TRAP_IGNORE(AnalyseWindowStackL());//not critical operation |
|
106 Subscribe(); |
|
107 } |
|
108 |
|
109 /** |
|
110 * CTsBackstepping::RunL |
|
111 * called for handling events from window server |
|
112 */ |
|
113 void CTsBackstepping::RunL() |
|
114 { |
|
115 User::LeaveIfError(iStatus.Int()); |
|
116 TWsEvent wsEvent; |
|
117 mWsSession.GetEvent (wsEvent); |
|
118 if (EEventWindowGroupListChanged == wsEvent.Type()) { |
|
119 RDebug::Print(_L("CTsBackstepping::RunL : EEventWindowGroupListChanged")); |
|
120 AnalyseWindowStackL (); |
|
121 } |
|
122 Subscribe(); |
|
123 } |
|
124 |
|
125 /** |
|
126 * CTsBackstepping::DoCancel |
|
127 * Handling RunL errors. |
|
128 */ |
|
129 TInt CTsBackstepping::RunError(TInt error) |
|
130 { |
|
131 if (!IsActive() && KErrCancel != error) { |
|
132 Subscribe(); |
|
133 } |
|
134 return KErrNone; |
|
135 } |
|
136 |
|
137 /** |
|
138 * CTsBackstepping::DoCancel |
|
139 * Stopping active object |
|
140 */ |
|
141 void CTsBackstepping::DoCancel () |
|
142 { |
|
143 if (IsActive()) { |
|
144 mWsSession.EventReadyCancel(); |
|
145 } |
|
146 } |
|
147 |
|
148 /** |
|
149 * CTsBackstepping::ActivateListeningL |
|
150 * Starts listening to Window session events |
|
151 */ |
|
152 void CTsBackstepping::Subscribe() |
|
153 { |
|
154 RDebug::Print(_L("CTsBackstepping::Subscribe")); |
|
155 // and start listening |
|
156 iStatus = KRequestPending; |
|
157 mWsSession.EventReady( &iStatus ); |
|
158 SetActive(); |
|
159 } |
|
160 |
|
161 /** |
|
162 * CTsBackstepping::AnalyseWindowStackL |
|
163 * Analyzes window stack and move homescreen to proper position |
|
164 */ |
|
165 void CTsBackstepping::AnalyseWindowStackL () |
|
166 { |
|
167 RDebug::Print(_L("CTsBackstepping::GetWindowCaption")); |
|
168 |
|
169 RArray<RWsSession::TWindowGroupChainInfo> windowGroups; |
|
170 CleanupClosePushL(windowGroups); |
|
171 |
|
172 CApaWindowGroupName *windowGroupName = CApaWindowGroupName::NewLC(mWsSession ); |
|
173 //update window group list |
|
174 mWsSession.WindowGroupList( &windowGroups ); |
|
175 |
|
176 TInt count(windowGroups.Count()); |
|
177 TInt pos(0); |
|
178 TInt whereToJump(1); |
|
179 for (TInt i=0; i<count; i++) {//iterate through list and give debug info |
|
180 const RWsSession::TWindowGroupChainInfo& info = windowGroups[i]; |
|
181 windowGroupName->ConstructFromWgIdL(info.iId); |
|
182 if (windowGroupName->AppUid() != TUid::Null()) { |
|
183 // find the window group id and check that it has no parent |
|
184 if ( info.iParentId <= 0 ) { |
|
185 RDebug::Print( _L("CTsBackstepping::GetWindowCaption wgid:%d is standalone view"), info.iId); |
|
186 //check if it is homescreen |
|
187 if (windowGroupName->AppUid() == KHSUid) { |
|
188 RDebug::Print(_L("CTsBackstepping::GetWindowCaption Homescreen position = %d ; list:%d/%d"), pos, i, count); |
|
189 if (pos <= 1) {// HS is in foreground or second in line - do nothing |
|
190 RDebug::Print(_L("CTsBackstepping::nothing to be done - it will stop checking here")); |
|
191 } else {//we should move homescreen to be second (ommit embeded views) from top |
|
192 RDebug::Print(_L("CTsBackstepping::moving homescreen to be second from top")); |
|
193 RDebug::Print(_L("CTsBackstepping::whereToJump = %d"), whereToJump); |
|
194 mWsSession.SetWindowGroupOrdinalPosition(info.iId, whereToJump); |
|
195 } |
|
196 // and break |
|
197 break; |
|
198 } |
|
199 pos++; |
|
200 } else { |
|
201 // only embeded items for first standalone launch should be counted |
|
202 if (!pos) { |
|
203 ++whereToJump; |
|
204 } |
|
205 RDebug::Print(_L("CTsBackstepping::GetWindowCaption wgid:%d is embedded view"), info.iId); |
|
206 } |
|
207 } |
|
208 } |
|
209 CleanupStack::PopAndDestroy(windowGroupName); |
|
210 CleanupStack::PopAndDestroy(&windowGroups); |
|
211 } |
|
212 |
|
213 // end of file |