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 #include "tswindowgroupsobserver.h" |
|
18 #include <apgwgnam.h> |
|
19 |
|
20 const int KOrdinalPositionNoZOrder(-1); |
|
21 // ----------------------------------------------------------------------------- |
|
22 // |
|
23 // ----------------------------------------------------------------------------- |
|
24 // |
|
25 CTsWindowGroupsMonitor* CTsWindowGroupsMonitor::NewL(MTsResourceManager &resources) |
|
26 { |
|
27 CTsWindowGroupsMonitor* self = new (ELeave) CTsWindowGroupsMonitor(resources); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CTsWindowGroupsMonitor::CTsWindowGroupsMonitor(MTsResourceManager &resources) |
|
39 : |
|
40 CActive(EPriorityStandard), |
|
41 mResources(resources) |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CTsWindowGroupsMonitor::ConstructL() |
|
51 { |
|
52 |
|
53 // Initial window group |
|
54 mWg = RWindowGroup (mResources.WsSession()); |
|
55 User::LeaveIfError (mWg.Construct ((TUint32)&mWg, EFalse)); |
|
56 mWg.SetOrdinalPosition (KOrdinalPositionNoZOrder); |
|
57 mWg.EnableReceiptOfFocus (EFalse); |
|
58 |
|
59 // Hide window |
|
60 CApaWindowGroupName* wn = CApaWindowGroupName::NewLC(mResources.WsSession()); |
|
61 wn->SetHidden (ETrue); |
|
62 wn->SetWindowGroupName (mWg); |
|
63 CleanupStack::PopAndDestroy (wn); |
|
64 |
|
65 // Window group change event |
|
66 User::LeaveIfError (mWg.EnableGroupListChangeEvents()); |
|
67 Subscribe(); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CTsWindowGroupsMonitor::~CTsWindowGroupsMonitor() |
|
75 { |
|
76 CActive::Cancel(); |
|
77 mWg.Close(); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CTsWindowGroupsMonitor::SubscribeL(MTsWindowGroupsObserver &observer) |
|
85 { |
|
86 const TInt offset(mObservers.Find(&observer)); |
|
87 KErrNotFound == offset ? mObservers.InsertL(&observer, 0) : |
|
88 User::Leave(KErrAlreadyExists); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CTsWindowGroupsMonitor::Cancel(MTsWindowGroupsObserver & observer) |
|
96 { |
|
97 const TInt offset(mObservers.Find(&observer)); |
|
98 if (KErrNotFound != offset) { |
|
99 mObservers.Remove(offset); |
|
100 } |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CTsWindowGroupsMonitor::RunL() |
|
108 { |
|
109 User::LeaveIfError(iStatus.Int()); |
|
110 ProvideEventL(); |
|
111 Subscribe(); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CTsWindowGroupsMonitor::DoCancel() |
|
119 { |
|
120 if (IsActive()) { |
|
121 mResources.WsSession().EventReadyCancel(); |
|
122 } |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 TInt CTsWindowGroupsMonitor::RunError(TInt error) |
|
130 { |
|
131 if (!IsActive() && KErrCancel != error) { |
|
132 Subscribe(); |
|
133 } |
|
134 return KErrNone; |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CTsWindowGroupsMonitor::Subscribe() |
|
142 { |
|
143 mResources.WsSession().EventReady( &iStatus ); |
|
144 SetActive(); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CTsWindowGroupsMonitor::ProvideEventL() |
|
152 { |
|
153 TWsEvent wsEvent; |
|
154 mResources.WsSession().GetEvent(wsEvent); |
|
155 for (TInt iter(0); iter < mObservers.Count(); ++iter) { |
|
156 ProvideEventL(wsEvent, *mObservers[iter]); |
|
157 } |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CTsWindowGroupsMonitor::ProvideEventL(TWsEvent event, |
|
165 MTsWindowGroupsObserver &observer) |
|
166 { |
|
167 RArray<RWsSession::TWindowGroupChainInfo> wgInfo; |
|
168 CleanupClosePushL(wgInfo); |
|
169 switch(event.Type()) { |
|
170 case EEventWindowGroupListChanged: |
|
171 User::LeaveIfError(mResources.WsSession().WindowGroupList(0, &wgInfo)); |
|
172 observer.HandleWindowGroupChanged(mResources, wgInfo.Array()); |
|
173 break; |
|
174 } |
|
175 CleanupStack::PopAndDestroy(&wgInfo); |
|
176 } |
|