|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "coeenvextra.h" |
|
17 #include "coepanic.h" |
|
18 #include <fepplugin.h> // Needed only for deletion of iFepPlugIn member in CCoeEnvExtra::TFep |
|
19 #include <hal.h> |
|
20 #include "coedefkeys.h" |
|
21 |
|
22 // |
|
23 // Class CCoeEnvExtra |
|
24 // |
|
25 |
|
26 CCoeEnvExtra::CCoeEnvExtra() |
|
27 :iResFileAccessCount(2), |
|
28 iCoeStaticList(_FOFF(CCoeStatic,iCsLink)), |
|
29 iControlState(ETrue), |
|
30 iArrayOfObserversOfLoadedFep(2), |
|
31 iArrayOfFocusObservers(2), |
|
32 iArrayOfForegroundObservers(2), |
|
33 iArrayOfMessageObservers(2), |
|
34 iArrayOfFepObservers(2), |
|
35 iArrayOfResourceChangeObservers(2), |
|
36 iArrayOfMessageMonitorObservers(2) |
|
37 |
|
38 { |
|
39 } |
|
40 |
|
41 void CCoeEnvExtra::ConstructL() |
|
42 { |
|
43 // Short-circuit op. |
|
44 if( (KErrNone != HAL::Get( HALData::EPointerNumberOfPointers, iSupportedPointers)) |
|
45 || (0 == iSupportedPointers) ) |
|
46 { |
|
47 iSupportedPointers = 1; |
|
48 } |
|
49 else if( iSupportedPointers > KConeMaxSupportedPointers ) |
|
50 { |
|
51 User::Leave( KErrTooBig ); |
|
52 } |
|
53 } |
|
54 |
|
55 CCoeEnvExtra::~CCoeEnvExtra() |
|
56 { |
|
57 iArrayOfObserversOfLoadedFep.Close(); |
|
58 iArrayOfFocusObservers.Close(); |
|
59 iArrayOfForegroundObservers.Close(); |
|
60 iArrayOfMessageObservers.Close(); |
|
61 iArrayOfFepObservers.Close(); |
|
62 iArrayOfResourceChangeObservers.Close(); |
|
63 iArrayOfMessageMonitorObservers.Close(); |
|
64 } |
|
65 |
|
66 void CCoeEnvExtra::HandleChangeInLoadedFep() |
|
67 { |
|
68 for (TInt i=iArrayOfObserversOfLoadedFep.Count()-1; i>=0; --i) |
|
69 { |
|
70 static_cast<MCoeObserverOfLoadedFep*>(iArrayOfObserversOfLoadedFep[i])->HandleChangeInLoadedFep(); |
|
71 } |
|
72 } |
|
73 |
|
74 void CCoeEnvExtra::NotifyFocusObserversOfChangeInFocus() |
|
75 { |
|
76 for (TInt i=iArrayOfFocusObservers.Count()-1; i>=0; --i) |
|
77 { |
|
78 static_cast<MCoeFocusObserver*>(iArrayOfFocusObservers[i])->HandleChangeInFocus(); |
|
79 } |
|
80 } |
|
81 |
|
82 void CCoeEnvExtra::NotifyFocusObserversOfDestructionOfFocusedItem() |
|
83 { |
|
84 for (TInt i=iArrayOfFocusObservers.Count()-1; i>=0; --i) |
|
85 { |
|
86 static_cast<MCoeFocusObserver*>(iArrayOfFocusObservers[i])->HandleDestructionOfFocusedItem(); |
|
87 } |
|
88 } |
|
89 |
|
90 void CCoeEnvExtra::NotifyForegroundObserversOfGainingForeground() |
|
91 { |
|
92 for (TInt i=iArrayOfForegroundObservers.Count()-1; i>=0; --i) |
|
93 { |
|
94 static_cast<MCoeForegroundObserver*>(iArrayOfForegroundObservers[i])->HandleGainingForeground(); |
|
95 } |
|
96 } |
|
97 |
|
98 void CCoeEnvExtra::NotifyForegroundObserversOfLosingForeground() |
|
99 { |
|
100 for (TInt i=iArrayOfForegroundObservers.Count()-1; i>=0; --i) |
|
101 { |
|
102 static_cast<MCoeForegroundObserver*>(iArrayOfForegroundObservers[i])->HandleLosingForeground(); |
|
103 } |
|
104 } |
|
105 |
|
106 void CCoeEnvExtra::NotifyResourceObserversOfChangeInResource() |
|
107 { |
|
108 for (TInt i=iArrayOfResourceChangeObservers.Count()-1; i>=0; --i) |
|
109 { |
|
110 static_cast<MCoeResourceChangeObserver*>(iArrayOfResourceChangeObservers[i])->HandleResourceChange(); |
|
111 } |
|
112 } |
|
113 |
|
114 void CCoeEnvExtra::NotifyMessageObserversOfMessageL(TUint32 aClientHandleOfTargetWindowGroup, const TUid& aMessageUid, const TDesC8& aMessageParameters) |
|
115 { |
|
116 TInt error=KErrNone; |
|
117 TInt previousErr=KErrNone; |
|
118 //Make this variable "volatile" to prevent the compiler putting it in a register |
|
119 volatile TInt i=iArrayOfMessageObservers.Count()-1; |
|
120 // Using two for loops like this optimizes the normal (no leave) case so that there is only one TRAP, but means that all message observers will get a chance to run, regardless of whether one of them leaves. |
|
121 for (; i>=0; --i) |
|
122 { |
|
123 TRAP(error, |
|
124 for (; i>=0; --i) |
|
125 { |
|
126 static_cast<MCoeMessageObserver*>(iArrayOfMessageObservers[i])->HandleMessageL(aClientHandleOfTargetWindowGroup, aMessageUid, aMessageParameters); // ignore the return value of HandleMessageL (which is just there in case it is needed in the future) |
|
127 } |
|
128 ); |
|
129 if(previousErr==KErrNone) |
|
130 { |
|
131 previousErr=error; //Propagate the first error value if message observer leaves. |
|
132 } |
|
133 } |
|
134 User::LeaveIfError(previousErr); |
|
135 } |
|
136 |
|
137 void CCoeEnvExtra::NotifyMessageMonitorObserversOfEvent(const TWsEvent &aEvent) |
|
138 /**Systematically passes received window visibility events to the registered observers in sequence |
|
139 */ |
|
140 { |
|
141 for (TInt i=iArrayOfMessageMonitorObservers.Count()-1; i>=0; --i) |
|
142 { |
|
143 static_cast<MCoeMessageMonitorObserver*>(iArrayOfMessageMonitorObservers[i])->MonitorWsMessage(aEvent); |
|
144 } |
|
145 } |
|
146 |
|
147 void CCoeEnvExtra::ForEachFepObserverCall(TCoeFepObserverFunction aFepObserverFunction) |
|
148 { |
|
149 for (TInt i=iArrayOfFepObservers.Count()-1; i>=0; --i) |
|
150 { |
|
151 (*aFepObserverFunction)(*(MCoeFepObserver*)iArrayOfFepObservers[i]); |
|
152 } |
|
153 } |
|
154 |
|
155 void CCoeEnvExtra::DestroyFep(TAny* aFep) |
|
156 { |
|
157 DestroyFep(*(CCoeEnvExtra::TFep*)aFep); |
|
158 } |
|
159 |
|
160 void CCoeEnvExtra::DestroyFep(TFep& aFep) |
|
161 { |
|
162 delete (CBase*)aFep.iFep; |
|
163 aFep.iFep=NULL; |
|
164 aFep.iFepUid=KNullUid; |
|
165 delete aFep.iFepPlugIn; |
|
166 aFep.iFepPlugIn = NULL; |
|
167 } |
|
168 |
|
169 void CCoeEnvExtra::AddObserverL(RArray<TAny*>& aArrayOfObservers, TAny* aObserver) |
|
170 { |
|
171 __ASSERT_ALWAYS(aObserver!=NULL, Panic(ECoePanicIllegalNullParameter3)); |
|
172 for (TInt i=aArrayOfObservers.Count()-1; i>=0; --i) |
|
173 { |
|
174 __ASSERT_ALWAYS(aArrayOfObservers[i]!=aObserver, Panic(ECoePanicFocusObserverHasAlreadyBeenAdded)); |
|
175 } |
|
176 User::LeaveIfError(aArrayOfObservers.Append(aObserver)); |
|
177 } |
|
178 |
|
179 void CCoeEnvExtra::RemoveObserver(RArray<TAny*>& aArrayOfObservers, const TAny* aObserver) |
|
180 { |
|
181 __ASSERT_ALWAYS(aObserver!=NULL, Panic(ECoePanicIllegalNullParameter4)); |
|
182 for (TInt i=aArrayOfObservers.Count()-1; i>=0; --i) |
|
183 { |
|
184 if (aArrayOfObservers[i]==aObserver) |
|
185 { |
|
186 aArrayOfObservers.Remove(i); |
|
187 break; |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 // |
|
193 // Class CCoeEnvExtra::CHighPriorityActive |
|
194 // |
|
195 |
|
196 CCoeEnvExtra::CHighPriorityActive* CCoeEnvExtra::CHighPriorityActive::NewL(CCoeEnvExtra& aCoeEnvExtra) |
|
197 { |
|
198 return new(ELeave) CHighPriorityActive(aCoeEnvExtra); |
|
199 } |
|
200 |
|
201 CCoeEnvExtra::CHighPriorityActive::~CHighPriorityActive() |
|
202 { |
|
203 Cancel(); |
|
204 } |
|
205 |
|
206 void CCoeEnvExtra::CHighPriorityActive::QueueNotificationToFocusObserversOfChangeInFocus() |
|
207 { |
|
208 if (!IsActive()) |
|
209 { |
|
210 TRequestStatus* requestStatus=&iStatus; |
|
211 User::RequestComplete(requestStatus, KErrNone); |
|
212 SetActive(); |
|
213 } |
|
214 } |
|
215 |
|
216 TInt CCoeEnvExtra::CHighPriorityActive::FocusObserverNotificationIdentifier() const |
|
217 { |
|
218 __ASSERT_DEBUG(IsActive(), Panic(ECoePanicFocusObserverNotificationIsNotPending)); |
|
219 return iFocusObserverNotificationIdentifier; |
|
220 } |
|
221 |
|
222 TBool CCoeEnvExtra::CHighPriorityActive::FocusObserverNotificationIsStillPending(TInt aFocusObserverNotificationIdentifier) const |
|
223 { |
|
224 return IsActive() && (iFocusObserverNotificationIdentifier==aFocusObserverNotificationIdentifier); |
|
225 } |
|
226 |
|
227 CCoeEnvExtra::CHighPriorityActive::CHighPriorityActive(CCoeEnvExtra& aCoeEnvExtra) |
|
228 :CActive(EActivePriorityWsEvents+50), // this priority must be greater than CCoeFep::CHighPriorityActive's priority (a FEPBASE class) so that FEPs receive notification of any change in focus (resulting from them calling HandleStartOfTransactionL) *before* any deferred function (i.e. one overriding MDeferredFunctionCall::ExecuteFunctionL) is called - this is necessary as the deferred function may depend on the deferred capabilities of the newly focused control (e.g. for inline editing) |
|
229 iCoeEnvExtra(aCoeEnvExtra), |
|
230 iFocusObserverNotificationIdentifier(0) |
|
231 { |
|
232 CActiveScheduler::Add(this); |
|
233 } |
|
234 |
|
235 void CCoeEnvExtra::CHighPriorityActive::DoCancel() |
|
236 { |
|
237 } |
|
238 |
|
239 void CCoeEnvExtra::CHighPriorityActive::RunL() |
|
240 { |
|
241 NotifyFocusObserversOfChangeInFocus(); |
|
242 } |
|
243 |
|
244 void CCoeEnvExtra::CHighPriorityActive::NotifyFocusObserversOfChangeInFocus() |
|
245 { |
|
246 iCoeEnvExtra.NotifyFocusObserversOfChangeInFocus(); |
|
247 ++iFocusObserverNotificationIdentifier; |
|
248 } |
|
249 |
|
250 /** Default Constructor for TScreenItem |
|
251 */ |
|
252 CCoeEnvExtra::CScreenItem::CScreenItem(CWsScreenDevice* aScreenDevice, RWindowGroup* aWindowGroup) |
|
253 :iScreenDevice(aScreenDevice),iWindowGroup(aWindowGroup) |
|
254 { |
|
255 } |
|
256 |
|
257 CCoeEnvExtra::CScreenItem::~CScreenItem() |
|
258 { |
|
259 delete iScreenDevice; |
|
260 if (iWindowGroup) |
|
261 iWindowGroup->Close(); |
|
262 delete iWindowGroup; |
|
263 } |
|
264 |
|
265 /** |
|
266 @return The screen device |
|
267 */ |
|
268 CWsScreenDevice* CCoeEnvExtra::CScreenItem::ScreenDevice() |
|
269 { |
|
270 return iScreenDevice; |
|
271 } |
|
272 |
|
273 /** |
|
274 @return The window group |
|
275 */ |
|
276 RWindowGroup* CCoeEnvExtra::CScreenItem::WindowGroup() |
|
277 { |
|
278 return iWindowGroup; |
|
279 } |
|
280 |
|
281 /** |
|
282 This function is used only to set the value of iArrayOfScreenItems's first entry's iScreenDevice to NULL. |
|
283 The data to which the first entry points to cannot be deleted in DeleteArrayOfScreensItems. |
|
284 */ |
|
285 void CCoeEnvExtra::CScreenItem::SetScreenDevice(CWsScreenDevice* aScreenDevice) |
|
286 { |
|
287 iScreenDevice = aScreenDevice; |
|
288 } |
|
289 |
|
290 /** |
|
291 This function is used only to set the value of iArrayOfScreenItems's first entry's iWindowGroup to NULL. |
|
292 The data to which the first entry points to cannot be deleted in DeleteArrayOfScreensItems. |
|
293 */ |
|
294 void CCoeEnvExtra::CScreenItem::SetWindowGroup(RWindowGroup* aWindowGroup) |
|
295 { |
|
296 iWindowGroup = aWindowGroup; |
|
297 } |
|
298 |