|
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 <f32file.h> |
|
17 #include <s32stor.h> |
|
18 #include <s32file.h> |
|
19 #include <coemain.h> |
|
20 #include "coepriv.h" |
|
21 #include "COETLS.H" |
|
22 #include "COEFEP.H" // class FepName |
|
23 #include "coepanic.h" |
|
24 #include "coever.h" |
|
25 #include <coecntrl.h> |
|
26 #include <coeerror.h> |
|
27 #include "coeenvextra.h" |
|
28 #include <barsread.h> |
|
29 #include <bautils.h> |
|
30 #include <viewcli.h> |
|
31 #include <coeaui.h> |
|
32 #include <hal.h> |
|
33 #include "coedatastorage.h" |
|
34 #include <coefontprovider.h> |
|
35 #include <centralrepository.h> |
|
36 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
37 #include <viewclipartner.h> |
|
38 #endif |
|
39 #include "coescheduler.h" |
|
40 #include "coeerrorconsts.h" |
|
41 #include "coedefkeys.h" |
|
42 |
|
43 |
|
44 //#define CONE_SHOW_TRACE |
|
45 |
|
46 #ifdef CONE_SHOW_TRACE |
|
47 void ShowTrace(TRefByValue<const TDesC> aFmt,...) |
|
48 { |
|
49 RDebug::Print(aFmt); |
|
50 } |
|
51 #else |
|
52 void ShowTrace(TRefByValue<const TDesC> /*aFmt*/,...) |
|
53 { |
|
54 } |
|
55 #endif |
|
56 |
|
57 /** |
|
58 ROM-patchable constant for turning the automatic setting of the CCoeControl's |
|
59 parent-pointer on or off. Only available in Symbian OS 9.3 and 9.4. |
|
60 @publishedPartner |
|
61 */ |
|
62 //#if !defined(SYMBIAN_WSERV_AND_CONE_MULTIPLE_SCREENS) |
|
63 EXPORT_C extern const TInt KCoeSetControlParentByDefault = ETrue; // Used in CCoeControlStaticSettings::ParentByDefault() |
|
64 //#endif |
|
65 |
|
66 _LIT(KSystemFont,"Arial"); |
|
67 |
|
68 const TInt KDefaultScreenNumber = 0 ; // If no startup screen is defined at construction use this. |
|
69 |
|
70 GLDEF_C void Panic(TCoePanic aPanic) |
|
71 { |
|
72 _LIT(KPanicCone,"CONE"); |
|
73 User::Panic(KPanicCone,aPanic); |
|
74 } |
|
75 |
|
76 |
|
77 LOCAL_C TBool IsHandleValid(TUint aHandle) |
|
78 { |
|
79 return (aHandle&3)==0; |
|
80 } |
|
81 |
|
82 // |
|
83 // Synchronously notifies focus observers of a focus change so |
|
84 // they can be reset after they receive a focus change event |
|
85 // |
|
86 // @since 6.1 |
|
87 // |
|
88 EXPORT_C void CCoeEnv::SyncNotifyFocusObserversOfChangeInFocus() |
|
89 { |
|
90 iExtra->iHighPriorityActive->NotifyFocusObserversOfChangeInFocus(); |
|
91 iExtra->iHighPriorityActive->Cancel(); |
|
92 } |
|
93 |
|
94 |
|
95 // |
|
96 // Class CCoeScheduler |
|
97 // |
|
98 |
|
99 EXPORT_C CCoeScheduler::CCoeScheduler(CCoeEnv* aCoeEnv) |
|
100 /** Constructor taking a pointer to the control environment. |
|
101 |
|
102 @param aCoeEnv The control environment. */ |
|
103 { |
|
104 iCoeEnv=aCoeEnv; |
|
105 iFlush=ETrue; // Set the default flushing behaviour to flush automatically |
|
106 } |
|
107 |
|
108 EXPORT_C void CCoeScheduler::WaitForAnyRequest() |
|
109 /** Waits for an asynchronous request to complete. */ |
|
110 { |
|
111 iCoeEnv->DoFlush(); |
|
112 CBaActiveScheduler::WaitForAnyRequest(); |
|
113 } |
|
114 |
|
115 EXPORT_C void CCoeScheduler::DisplayError(TInt aError) const |
|
116 /** Displays an application-defined error message. |
|
117 |
|
118 @param aError An error code. */ |
|
119 { |
|
120 iCoeEnv->HandleError(aError); |
|
121 } |
|
122 |
|
123 TBool CCoeScheduler::Flush() const |
|
124 { |
|
125 return iFlush; |
|
126 } |
|
127 |
|
128 void CCoeScheduler::SetFlush(TBool aFlush) |
|
129 { |
|
130 iFlush=aFlush; |
|
131 } |
|
132 |
|
133 EXPORT_C void CCoeScheduler::Reserved_1() |
|
134 { |
|
135 } |
|
136 |
|
137 EXPORT_C void CCoeScheduler::Reserved_2() |
|
138 { |
|
139 } |
|
140 |
|
141 // |
|
142 // Class CCoeEnv |
|
143 // |
|
144 EXPORT_C TBool CCoeEnv::DisableShutdownChecks() const |
|
145 { |
|
146 return iEnvFlags&ENoShutdownChecks; |
|
147 } |
|
148 |
|
149 inline TUint CCoeEnv::InitialHandleCount() const |
|
150 {return (iEnvFlags&0xffff0000)>>16;} |
|
151 |
|
152 TInt CCoeEnv::SupportedPointers() const |
|
153 { |
|
154 return iExtra->iSupportedPointers; |
|
155 } |
|
156 |
|
157 const TInt KErrorContextTextLength=80; |
|
158 const TInt KErrorTextLength=80; |
|
159 |
|
160 EXPORT_C CCoeEnv::CCoeEnv() : CActive(EActivePriorityWsEvents) |
|
161 /** Default constructor. |
|
162 |
|
163 Note - Construction of the CCoeEnv is not complete |
|
164 until ConstructL() has been called. |
|
165 |
|
166 This function raises a CONE 2 panic if the application already owns a CCoeEnv. */ |
|
167 { |
|
168 TInt error=KErrNone; |
|
169 #ifdef _DEBUG |
|
170 HAL::SEntry* pE=NULL; |
|
171 TInt entries=0; |
|
172 if (error==KErrNone) |
|
173 error=HAL::GetAll(entries, pE); |
|
174 |
|
175 User::Free(pE); |
|
176 SetInitialHandleCount(); |
|
177 #endif |
|
178 __ASSERT_ALWAYS(!TheCoe(),Panic(ECoePanicEnvironmentAlreadyExists)); |
|
179 if (error==KErrNone) |
|
180 error=SetTheCoe(this); |
|
181 __UHEAP_MARK; |
|
182 |
|
183 iCleanup=CTrapCleanup::New(); |
|
184 if ((iCleanup==NULL) && (error==KErrNone)) |
|
185 error=KErrNoMemory; |
|
186 |
|
187 if (error!=KErrNone) |
|
188 { |
|
189 iExtra=REINTERPRET_CAST(CCoeEnvExtra*, error); |
|
190 iEnvFlags|=EExtraPointerIsErrorCode; |
|
191 } |
|
192 } |
|
193 |
|
194 EXPORT_C void CCoeEnv::ExecuteD() |
|
195 /** Launches the application and destroys the control environment. */ |
|
196 { |
|
197 Execute(); |
|
198 DestroyEnvironment(); |
|
199 } |
|
200 |
|
201 EXPORT_C void CCoeEnv::Execute() |
|
202 /** Launches the application without destroying the control environment. |
|
203 |
|
204 This function starts the active scheduler owned by the CCoeEnv, enabling the |
|
205 application to start receiving events from the window server. It forms the |
|
206 outer loop of all Control Environment applications. */ |
|
207 { |
|
208 iEnvFlags|=ESchedulerIsRunning; |
|
209 TRAPD(exitCondition,CActiveScheduler::Start()); |
|
210 __ASSERT_ALWAYS((exitCondition==KLeaveExit) || (exitCondition==KErrNone), Panic(ECoePanicLeaveWithoutTrap)); |
|
211 PrepareToExit(); |
|
212 } |
|
213 |
|
214 EXPORT_C void CCoeEnv::PrepareToExit() |
|
215 /** Prepares for exiting the application. |
|
216 |
|
217 The function is called from ExecuteD() after the active scheduler's wait loop |
|
218 terminates, but before the environment is destroyed. */ |
|
219 { |
|
220 if (iAppUi) |
|
221 iAppUi->PrepareToExit(); |
|
222 } |
|
223 |
|
224 EXPORT_C void CCoeEnv::RunL() |
|
225 { |
|
226 switch (iStatus.Int()) |
|
227 { |
|
228 case KErrNone: |
|
229 break; |
|
230 case KErrCancel: |
|
231 case KErrServerTerminated: |
|
232 return; |
|
233 default: |
|
234 Panic(ECoePanicWservBlindCommandFailed); |
|
235 } |
|
236 TWsEvent event; |
|
237 iWsSession.GetEvent(event); |
|
238 RequestEventNotification(); //Request now so that WSERV has time to respond (on SMP systems) before the return to the Active Scheduler |
|
239 const TUint handle=event.Handle(); |
|
240 if (handle) |
|
241 { |
|
242 CCoeControl* const window=IsHandleValid(handle)? reinterpret_cast<CCoeControl*>(handle) : NULL; |
|
243 iLastEvent=event; |
|
244 iAppUi->MonitorWsEvent(event); |
|
245 //coverity[var_deref_model] |
|
246 //Passing a NULL value of window to this function is allowed because the window is not always dereferenced by this function. |
|
247 //The window will not be NULL if it is to be dereferenced by this function. |
|
248 iAppUi->HandleWsEventL(event,window); |
|
249 } |
|
250 } |
|
251 |
|
252 EXPORT_C void CCoeEnv::SimulateKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
253 /** Simulates a key event. |
|
254 |
|
255 This function calls CCoeAppUi::HandleWsEventL() to process the event |
|
256 as if it had arrived from the window server. |
|
257 |
|
258 @param aKeyEvent The key event. |
|
259 @param aType The event type. */ |
|
260 { |
|
261 TWsEvent event; |
|
262 *event.Key()=aKeyEvent; |
|
263 event.SetType(aType); |
|
264 event.SetTimeNow(); |
|
265 iLastEvent=event; |
|
266 iAppUi->HandleWsEventL(event,NULL); |
|
267 } |
|
268 |
|
269 EXPORT_C void CCoeEnv::DoCancel() |
|
270 { |
|
271 iWsSession.EventReadyCancel(); |
|
272 } |
|
273 |
|
274 EXPORT_C void CCoeEnv::SuppressNextFlush() |
|
275 /** Suppresses the next flush of the active scheduler queue. |
|
276 |
|
277 It prevents the active scheduler automatically flushing its window server |
|
278 session the next time that a non-CCoeEnv object runs. After the active object |
|
279 has run, the active scheduler reverts back to its normal behaviour, flushing |
|
280 after each non-CCoeEnv RunL(). */ |
|
281 { |
|
282 static_cast<CCoeScheduler*>(CActiveScheduler::Current())->SetFlush(EFalse); |
|
283 } |
|
284 |
|
285 void CCoeEnv::DoFlush() |
|
286 /** Flush WSERV's command buffer */ |
|
287 { |
|
288 CCoeScheduler* coeScheduler=static_cast<CCoeScheduler*>(CActiveScheduler::Current()); |
|
289 if (coeScheduler->Flush()) |
|
290 iWsSession.Flush(); |
|
291 else |
|
292 coeScheduler->SetFlush(ETrue); |
|
293 } |
|
294 |
|
295 void CCoeEnv::RequestEventNotification() |
|
296 /** Asks WSERV to give notification when an event is waiting */ |
|
297 { |
|
298 iWsSession.EventReady(&iStatus); |
|
299 SetActive(); |
|
300 } |
|
301 |
|
302 CVwsSessionWrapper* CCoeEnv::InitViewServerSessionL(MVwsSessionWrapperObserver& aObserver) |
|
303 { |
|
304 if (!(iExtra->iVwsSession)) |
|
305 { |
|
306 iExtra->iVwsSession=CVwsSessionWrapper::NewL(aObserver); |
|
307 } |
|
308 return iExtra->iVwsSession; |
|
309 } |
|
310 |
|
311 EXPORT_C void CCoeEnv::HandleError(TInt /*aErrorValue*/) |
|
312 /** Handles an application-defined error message. |
|
313 |
|
314 This function allows application-defined error messages to be called from |
|
315 functions within the control framework's active scheduler. It has an empty |
|
316 default implementation. |
|
317 |
|
318 It is called when a leave occurs in CCoeEnv::RunL(), and also when ReadResource() |
|
319 fails. |
|
320 |
|
321 @param aErrorValue KErrNone or another error code. */ |
|
322 { |
|
323 } |
|
324 |
|
325 EXPORT_C void CCoeEnv::BringOwnerToFront() |
|
326 /** Brings the application's owning window group to the front of the screen and |
|
327 gives it keyboard focus. |
|
328 |
|
329 This is done by giving the owning window group an ordinal position of zero. */ |
|
330 { |
|
331 if (iRootWin.WsHandle()) // else initialization hasn't got that far yet |
|
332 iRootWin.SetOrdinalPosition(KOrdinalPositionSwitchToOwningWindow); |
|
333 } |
|
334 |
|
335 EXPORT_C void CCoeEnv::DestroyEnvironment() |
|
336 /** Deletes several resources owned by the CCoeEnv object. |
|
337 |
|
338 This includes; the app UI, the system graphics context, and the active object |
|
339 which receives redraw events. It also closes the window group, the connection |
|
340 to the window server, and the connection to the file server. |
|
341 |
|
342 The function is called from ExecuteD() when the active scheduler's wait loop |
|
343 terminates. */ |
|
344 { |
|
345 iExtra->iControlState = EFalse; |
|
346 DestroyEnvironmentStatic(); |
|
347 DestroyEnvironmentEnd(); |
|
348 delete this; |
|
349 } |
|
350 |
|
351 /** @internalTechnology */ |
|
352 EXPORT_C void CCoeEnv::DestroyEnvironmentStatic() |
|
353 { |
|
354 BringOwnerToFront(); |
|
355 const TBool extraIsNonNull=(!(iEnvFlags&EExtraPointerIsErrorCode) && (iExtra!=NULL)); |
|
356 if (extraIsNonNull) |
|
357 { |
|
358 CCoeEnvExtra::DestroyFep(iExtra->iFep); |
|
359 |
|
360 // Delete all CCoeStatics with positive destruction priority |
|
361 TDblQueIter<CCoeStatic> iter(iExtra->iCoeStaticList); |
|
362 iter.SetToFirst(); |
|
363 CCoeStatic* coeStatic = NULL; |
|
364 while (((coeStatic=iter++)!=NULL) && (coeStatic->DestructionPriority()>=0)) |
|
365 { |
|
366 delete coeStatic; |
|
367 } |
|
368 } |
|
369 } |
|
370 |
|
371 /** @internalTechnology */ |
|
372 EXPORT_C void CCoeEnv::DestroyEnvironmentEnd() |
|
373 { |
|
374 const TBool extraIsNonNull=(!(iEnvFlags&EExtraPointerIsErrorCode) && (iExtra!=NULL)); |
|
375 delete(iAppUi); // must be destroyed before the iExtra observers |
|
376 iAppUi=NULL; |
|
377 if (extraIsNonNull) |
|
378 { |
|
379 delete iExtra->iFepTracker; // this must be deleted *before* the CCoeDataStorage object - the latter is deleted by one of the CCoeStatic objects (with negative destruction priority) below |
|
380 |
|
381 // Delete all CCoeStatics with negative destruction priority |
|
382 TDblQueIter<CCoeStatic> iter(iExtra->iCoeStaticList); |
|
383 iter.SetToFirst(); |
|
384 CCoeStatic* coeStatic = NULL; |
|
385 while ((coeStatic=iter++)!=NULL) |
|
386 { |
|
387 delete coeStatic; |
|
388 } |
|
389 DeleteArrayOfScreensItems(); |
|
390 delete iExtra->iRedrawer; |
|
391 delete iExtra->iFepLoader; |
|
392 delete iExtra->iVwsSession; |
|
393 delete iExtra->iDefaultFontProvider; |
|
394 delete iExtra->iDefaultTextDrawer; |
|
395 } |
|
396 delete(iSystemGc); |
|
397 ReleaseScreenFont(CONST_CAST(CFont*,iNormalFont)); |
|
398 DestroyScreen(); // this is a virtual function so it must be called here rather than in CCoeEnv's destructor |
|
399 iRootWin.Close(); |
|
400 Cancel(); |
|
401 } |
|
402 |
|
403 #if defined(_DEBUG) |
|
404 |
|
405 template <class T, class R> |
|
406 TInt FindAllThreadHandles(T& aFindHandle) |
|
407 { |
|
408 _LIT(KFormatString,"%S::*"); |
|
409 RThread t; |
|
410 TFullName name; |
|
411 const TFullName threadName=t.FullName(); |
|
412 name.Format(KFormatString,&threadName); |
|
413 aFindHandle.Find(name); |
|
414 TInt count=0; |
|
415 FOREVER |
|
416 { |
|
417 const TInt r=aFindHandle.Next(name); |
|
418 if (r!=KErrNone) |
|
419 break; |
|
420 count++; |
|
421 ShowTrace(_L("%S"), &name); |
|
422 } |
|
423 return count; |
|
424 } |
|
425 |
|
426 void IdentifyOpenHandles1() |
|
427 { |
|
428 TFindSemaphore sem; |
|
429 ShowTrace(_L("Finding open semaphores...")); |
|
430 FindAllThreadHandles<TFindSemaphore, RSemaphore>(sem); |
|
431 } |
|
432 |
|
433 void IdentifyOpenHandles2() |
|
434 { |
|
435 TFindMutex mux; |
|
436 ShowTrace(_L("Finding open mutexes...")); |
|
437 FindAllThreadHandles<TFindMutex, RMutex>(mux); |
|
438 } |
|
439 |
|
440 void IdentifyOpenHandles3() |
|
441 { |
|
442 TFindChunk fchunk; |
|
443 ShowTrace(_L("Finding open chunks...")); |
|
444 FindAllThreadHandles<TFindChunk, RChunk>(fchunk); |
|
445 } |
|
446 |
|
447 void IdentifyOpenHandles4() |
|
448 { |
|
449 TFindLogicalDevice fldev; |
|
450 ShowTrace(_L("Finding open logical devices...")); |
|
451 FindAllThreadHandles<TFindLogicalDevice, RDevice>(fldev); |
|
452 } |
|
453 |
|
454 LOCAL_C void IdentifyOpenHandles() |
|
455 { |
|
456 ShowTrace(_L("Open handles found during thread %Lu shutdown"), RThread().Id().Id()); // %Lu is used for a TUint64 |
|
457 IdentifyOpenHandles1(); |
|
458 IdentifyOpenHandles2(); |
|
459 IdentifyOpenHandles3(); |
|
460 IdentifyOpenHandles4(); |
|
461 ShowTrace(_L("Finished attempts to identify handles")); |
|
462 Panic(ECoePanicHandleNotClosed); |
|
463 } |
|
464 |
|
465 #endif |
|
466 |
|
467 EXPORT_C CCoeEnv::~CCoeEnv() |
|
468 /** Destructor. |
|
469 |
|
470 This function deletes any resources owned by the CCoeEnv that were not deleted |
|
471 by DestroyEnvironment(). */ |
|
472 { |
|
473 if (!(iEnvFlags&EExtraPointerIsErrorCode) && (iExtra!=NULL)) |
|
474 { |
|
475 delete iExtra->iHighPriorityActive; |
|
476 #if defined(_DEBUG) |
|
477 if (iResourceFileArray!=NULL) |
|
478 { |
|
479 for (TInt i=iResourceFileArray->Count()-1; i>=0; --i) |
|
480 { |
|
481 ShowTrace(_L("Resource file with offset 0x%08x has been leaked (search for the 4 most significant hexadecimal digits of this number in epoc32\\include\\*.RSG to find out which resource file)"), (*iResourceFileArray)[i].Offset()); |
|
482 } |
|
483 __ASSERT_DEBUG(iResourceFileArray->Count()==0,Panic(ECoePanicResourceFileNotDeleted)); |
|
484 } |
|
485 #endif |
|
486 __ASSERT_DEBUG(iExtra->iResFileAccessCount.Count()==0,Panic(ECoePanicResourceFileNotDeleted)); |
|
487 iExtra->iResFileAccessCount.Close(); |
|
488 delete iExtra; // can only be done when iAppUi has been destroyed as destroying iAppUi may destroy some controls owned by the control stack, and these controls may call SetFocus when they are destroyed, SetFocus internally referencing iExtra->iNumberOfNestedSetFocusCalls |
|
489 } |
|
490 DestroyAllResourceFiles(); |
|
491 delete iScreen; |
|
492 delete CActiveScheduler::Current(); |
|
493 delete iErrorText; |
|
494 delete iErrorContextText; |
|
495 delete iCleanup; |
|
496 __ASSERT_DEBUG(DisableShutdownChecks() || (iWsSession.Handle()==KNullHandle) || (iWsSession.ResourceCount()==0),Panic(ECoePanicWservResourceNotFreed)); |
|
497 iWsSession.Close(); |
|
498 // Checks that less than 1 file is open. 1 file may be open because the RFbs keeps one file cached. |
|
499 // A defect has been raised to change this. |
|
500 __ASSERT_DEBUG(DisableShutdownChecks() || (iFsSession.Handle()==KNullHandle) || (iFsSession.ResourceCount()<=1),Panic(ECoePanicF32ResourceNotFreed)); |
|
501 iFsSession.Close(); |
|
502 REComSession::FinalClose(); |
|
503 #if defined(_DEBUG) |
|
504 if (!DisableShutdownChecks()) |
|
505 { |
|
506 __UHEAP_MARKEND; |
|
507 TInt processHandleCount=0; |
|
508 TInt threadHandleCount=0; |
|
509 RThread().HandleCount(processHandleCount,threadHandleCount); |
|
510 const TInt initialHandleCount=InitialHandleCount(); |
|
511 if (threadHandleCount>initialHandleCount && initialHandleCount<KMaxTInt16) |
|
512 { |
|
513 IdentifyOpenHandles(); |
|
514 } |
|
515 } |
|
516 #endif |
|
517 FreeTheCoe(); |
|
518 } |
|
519 |
|
520 EXPORT_C void CCoeEnv::DestroyScreen() |
|
521 /** Destroys the screen device. |
|
522 |
|
523 By default this function simply deletes the screen device owned by this CCoeEnv. |
|
524 However, this function may be overridden by subclasses. |
|
525 |
|
526 This function is called by DestroyEnvironment(). */ |
|
527 { // subclassers can do more |
|
528 } |
|
529 |
|
530 EXPORT_C CCoeAppUi* CCoeEnv::SetAppUi(CCoeAppUi* aAppUi) |
|
531 /** Sets the application's user interface object. |
|
532 |
|
533 Standard GUI applications do not need to call this function, as the framework |
|
534 sets the app UI, during start up, to be the CEikAppUi-derived object created |
|
535 by the application. |
|
536 |
|
537 @param aAppUi The app UI for this application. |
|
538 @return The app UI previously owned by this application, or NULL if this is |
|
539 the first time its app UI has been set. */ |
|
540 { |
|
541 CCoeAppUi* previous=iAppUi; |
|
542 iAppUi=aAppUi; |
|
543 if (previous==NULL) // i.e. we've only just set the app ui for the first time |
|
544 { |
|
545 UpdateStatic(aAppUi); |
|
546 } |
|
547 return(previous); |
|
548 } |
|
549 |
|
550 EXPORT_C void CCoeEnv::ConstructL() |
|
551 /** Completes construction of the CCoeEnv object. |
|
552 |
|
553 It calls the other ConstructL() overload specifying ETrue as the initial |
|
554 focus state. */ |
|
555 { |
|
556 ConstructL(ETrue); |
|
557 } |
|
558 |
|
559 EXPORT_C void CCoeEnv::ConstructL(TBool aInitialFocusState) |
|
560 /** Completes construction of the CCoeEnv. |
|
561 |
|
562 It is called by the other overload, with aInitialFocusState set to ETrue. |
|
563 |
|
564 |
|
565 @param aInitialFocusState Window group initial focus state. If ETrue, keyboard |
|
566 focus is enabled, otherwise keyboard focus is disabled. */ |
|
567 { |
|
568 ConstructL( aInitialFocusState, KDefaultScreenNumber ) ; |
|
569 } |
|
570 |
|
571 /** Completes construction of the CCoeEnv. |
|
572 It can be called by the previous overload. It calls the next overload, setting |
|
573 the default window group ID to 0 which is not a valid ID |
|
574 |
|
575 @param aInitialFocusState Window group initial focus state. If ETrue, keyboard |
|
576 focus is enabled, otherwise keyboard focus is disabled. |
|
577 @param aDefaultScreenNumber The default screen number should be zero.*/ |
|
578 EXPORT_C void CCoeEnv::ConstructL( TBool aInitialFocusState, TInt aDefaultScreenNumber ) // Added May 04 support for Multiple Screens |
|
579 |
|
580 { |
|
581 ConstructL(aInitialFocusState, aDefaultScreenNumber, 0); // 0 is not a valid window group ID |
|
582 } |
|
583 |
|
584 /** Completes construction of the CCoeEnv. |
|
585 |
|
586 All of the previous ConstructL() overloads end up at this method. |
|
587 |
|
588 This function creates an active scheduler, and adds active objects to it for |
|
589 standard and redraw events. The active scheduler is not started, however, |
|
590 and no events are received, until ExecuteD() is called. It also does the following: |
|
591 |
|
592 - creates a connection to the window server. |
|
593 |
|
594 - creates a connection to the file server so that the control environment can |
|
595 access resource files |
|
596 |
|
597 - creates a screen device, the application's window group, a standard font, |
|
598 and a graphics context (the system GC). |
|
599 |
|
600 The window group is constructed with the initial focus state aInitialFocusState, |
|
601 which automatically takes keyboard focus when it is created. |
|
602 |
|
603 @param aInitialFocusState Window group initial focus state. If ETrue, keyboard |
|
604 focus is enabled, otherwise keyboard focus is disabled. |
|
605 @param aDefaultScreenNumber The default screen number |
|
606 @param aWindowGroupID The window group ID which will be set as the parent |
|
607 */ |
|
608 EXPORT_C void CCoeEnv::ConstructL(TBool aInitialFocusState, TInt aDefaultScreenNumber, TInt aWindowGroupID ) |
|
609 { |
|
610 if (iEnvFlags&EExtraPointerIsErrorCode) |
|
611 { |
|
612 User::LeaveIfError(REINTERPRET_CAST(TInt, iExtra)); |
|
613 } |
|
614 iExtra=new(ELeave) CCoeEnvExtra; |
|
615 iExtra->ConstructL(); |
|
616 iErrorText=new(ELeave) TBuf<KErrorTextLength>; |
|
617 iErrorContextText=new(ELeave) TBuf<KErrorContextTextLength>; |
|
618 CreateActiveSchedulerL(); |
|
619 CActiveScheduler::Add(this); |
|
620 ConnectToFileServerL(); |
|
621 ConnectToWindowServerL(); |
|
622 InitScreenL( aDefaultScreenNumber); // Modified May 04 support for Multiple Screens. |
|
623 InitRootWindowL(aInitialFocusState, aWindowGroupID); |
|
624 InitSystemFontsL(); |
|
625 InitSystemGcL(); |
|
626 PopulateArrayOfScreenItemsL(); |
|
627 iExtra->iRedrawer=new(ELeave) CCoeRedrawer(iWsSession); |
|
628 iExtra->iFepTracker=CCoeFepTracker::NewL(*this); |
|
629 iExtra->iFepLoader=CCoeFepLoader::NewL(*this, iExtra->iFepLoader); |
|
630 iExtra->iHighPriorityActive=CCoeEnvExtra::CHighPriorityActive::NewL(*iExtra); |
|
631 |
|
632 iExtra->iDefaultFontProvider = CCoeFontProvider::NewL(); |
|
633 User::LeaveIfNull( iExtra->iDefaultTextDrawer = CCoePlainTextDrawer::New(KRgbBlack) ); |
|
634 iExtra->iDefaultTextDrawer->SetReusable( ETrue ); |
|
635 // iExtra->iAppStartupInstrumentationEventIdBase is set in SetAppStartupInstrumentationEventIdBaseL |
|
636 RequestEventNotification(); |
|
637 } |
|
638 |
|
639 void CCoeEnv::CreateActiveSchedulerL() |
|
640 { |
|
641 CActiveScheduler::Install(new(ELeave) CCoeScheduler(this)); |
|
642 } |
|
643 |
|
644 void CCoeEnv::ConnectToFileServerL() |
|
645 { |
|
646 User::LeaveIfError(iFsSession.Connect()); |
|
647 } |
|
648 |
|
649 void CCoeEnv::ConnectToWindowServerL() |
|
650 { |
|
651 User::LeaveIfError(iWsSession.Connect(iFsSession)); |
|
652 } |
|
653 |
|
654 void CCoeEnv::InitScreenL( TInt aDefaultScreenNumber ) |
|
655 { |
|
656 iScreen=new(ELeave) CWsScreenDevice(iWsSession); |
|
657 User::LeaveIfError(iScreen->Construct( aDefaultScreenNumber )); |
|
658 } |
|
659 |
|
660 void CCoeEnv::InitRootWindowL(TBool aInitialFocusState, TInt aWindowGroupID) |
|
661 { |
|
662 iRootWin=RWindowGroup(iWsSession); |
|
663 if (aWindowGroupID) |
|
664 { |
|
665 User::LeaveIfError(iRootWin.ConstructChildApp(aWindowGroupID, (TUint32)this, aInitialFocusState)); |
|
666 } |
|
667 else |
|
668 { |
|
669 User::LeaveIfError(iRootWin.Construct((TUint32)this, aInitialFocusState)); |
|
670 } |
|
671 } |
|
672 |
|
673 EXPORT_C void CCoeEnv::InitSystemFontsL() |
|
674 // Hard-coded font is only used for test code |
|
675 /** Initialises the system fonts. |
|
676 |
|
677 This function is called by ConstructL() during the construction of a CCoeEnv. |
|
678 The default implementation creates only the normal control environment font, |
|
679 but this function may be overridden to create other fonts. */ |
|
680 { |
|
681 TFontSpec spec(KSystemFont,200); // 10 points |
|
682 iNormalFont=CreateScreenFontL(spec); |
|
683 } |
|
684 |
|
685 void CCoeEnv::InitSystemGcL() |
|
686 { |
|
687 iSystemGc=CreateGcL(); |
|
688 } |
|
689 |
|
690 EXPORT_C CWindowGc* CCoeEnv::CreateGcL() |
|
691 /** Fully constructs a new graphics context. |
|
692 |
|
693 CCoeEnv calls this function during construction to create the system graphics |
|
694 context, which can be accessed using SystemGc(). Hence the system graphics |
|
695 context is always available. |
|
696 |
|
697 @return A new graphics context. |
|
698 @see SystemGc() */ |
|
699 { |
|
700 CGraphicsContext* temp; |
|
701 User::LeaveIfError(iScreen->CreateContext(temp)); |
|
702 return((CWindowGc*)temp); |
|
703 } |
|
704 |
|
705 EXPORT_C CFbsFont* CCoeEnv::CreateDeviceFontL(CGraphicsDevice* aDevice,const TFontSpec& aFontSpec) |
|
706 /** Creates a font for the specified graphics device. |
|
707 |
|
708 If you wish to use the default screen device as the graphics device, use |
|
709 CreateScreenFontL() instead of this function. |
|
710 |
|
711 This function calls GetNearestFontToMaxHeightInTwips() on the graphics device |
|
712 given by aDevice, passing it the font defined by aFontSpec. |
|
713 |
|
714 All fonts created by this function should be released using |
|
715 MGraphicsDeviceMap::ReleaseFont(), when they are no longer required. |
|
716 |
|
717 Note that the font will not be scaled automatically when the control's zoom factor |
|
718 is changed using CCoeControl::SetZoomFactor(). This is also the case for NormalFont(), |
|
719 CEikonEnv::LegendFont(), CEikonEnv::TitleFont(), CEikonEnv::AnnotationFont(), |
|
720 CEikonEnv::DenseFont(). |
|
721 |
|
722 To avoid this problem, and also make resource management much easier, it is highly |
|
723 recommended to use CCoeControl::ScreenFont() instead. |
|
724 |
|
725 @see CCoeEnv::CreateScreenFontL() |
|
726 @see CCoeControl::ScreenFont() |
|
727 @see CCoeFontProvider |
|
728 |
|
729 @param aDevice The graphics device for which to create the font. |
|
730 @param aFontSpec The font specification. |
|
731 @return The new font. */ |
|
732 { |
|
733 CFont* ret; |
|
734 User::LeaveIfError(aDevice->GetNearestFontToMaxHeightInTwips(ret,aFontSpec,aFontSpec.iHeight)); |
|
735 return((CFbsFont*)ret); |
|
736 } |
|
737 |
|
738 EXPORT_C CFbsFont* CCoeEnv::CreateScreenFontL(const TFontSpec& aFontSpec) |
|
739 /** Creates a font for the default graphics device, based on the specified TFontSpec. |
|
740 |
|
741 All fonts created using this function should be released using ReleaseScreenFont() |
|
742 when they are no longer required. |
|
743 |
|
744 Note that the font will not be scaled automatically when the zoom factor is changed |
|
745 using CCoeControl::SetZoomFactor(). This is also the case for NormalFont(), |
|
746 CEikonEnv::LegendFont(), CEikonEnv::TitleFont(), CEikonEnv::AnnotationFont(), |
|
747 CEikonEnv::DenseFont(). |
|
748 |
|
749 To avoid this problem, and also make resource management much easier, it is highly |
|
750 recommended to use CCoeControl::ScreenFont() instead. |
|
751 |
|
752 @see CCoeControl::ScreenFont() |
|
753 @see CCoeFontProvider |
|
754 |
|
755 @param aFontSpec The font specification. |
|
756 @return The new font. */ |
|
757 { |
|
758 return(CreateDeviceFontL(iScreen,aFontSpec)); |
|
759 } |
|
760 |
|
761 EXPORT_C void CCoeEnv::ReleaseScreenFont(CFont* aFont) const |
|
762 /** Frees all resources used by the font. |
|
763 |
|
764 This function should be used to release a font when the font is no longer |
|
765 required. Fonts are created using CreateScreenFontL(). |
|
766 |
|
767 @param aFont The font to be released. */ |
|
768 { |
|
769 if (aFont) |
|
770 iScreen->ReleaseFont(aFont); |
|
771 } |
|
772 |
|
773 EXPORT_C void CCoeEnv::Flush(TTimeIntervalMicroSeconds32 aDelay) |
|
774 /** Flushes the client-side window server buffer. |
|
775 |
|
776 The function does this by first calling RWsSession::Flush(), and then User::After(aDelay), |
|
777 which puts the current process in a sleep state for the time interval |
|
778 given by aDelay. |
|
779 |
|
780 @param aDelay Delay for which to sleep the current process after flushing |
|
781 the window server buffer. By default the delay is zero. */ |
|
782 { |
|
783 iWsSession.Flush(); |
|
784 User::After(aDelay); |
|
785 } |
|
786 |
|
787 EXPORT_C TBool CCoeEnv::IsWservEventPending() const |
|
788 /** Tests if there is a standard event waiting to be processed. |
|
789 |
|
790 Note: standard events are all window server events except redraw and priority |
|
791 key events. |
|
792 |
|
793 @return ETrue if a standard event is pending. EFalse if no standard event |
|
794 is pending. */ |
|
795 { |
|
796 return(iStatus.Int()!=KRequestPending); |
|
797 } |
|
798 |
|
799 EXPORT_C TBool CCoeEnv::IsRedrawEventPending() const |
|
800 /** Tests if there is a redraw event waiting to be processed. |
|
801 |
|
802 @return ETrue if a redraw event is pending. EFalse if no redraw event is pending. */ |
|
803 { |
|
804 return(iExtra->iRedrawer->iStatus.Int()!=KRequestPending); |
|
805 } |
|
806 |
|
807 EXPORT_C void CCoeEnv::ReadResourceAsDes8(TDes8& aDes,TInt aResourceId) const |
|
808 /** Reads a resource into an 8 bit descriptor. |
|
809 |
|
810 The descriptor must be long enough to contain the entire resource. No memory |
|
811 is allocated by this function. |
|
812 |
|
813 If the read fails the function sets an error condition and performs any cleanup |
|
814 required. The error condition causes the GUI to launch an alert window. |
|
815 Deprecated: use CCoeEnv::ReadResourceAsDes8L() instead. |
|
816 |
|
817 @deprecated |
|
818 @param aDes On return, contains the read resource. |
|
819 @param aResourceId The numeric ID of the resource to be read. |
|
820 @see RResourceFile::ReadL() |
|
821 @see KErrCoeFailedToReadFromProgDisk */ |
|
822 { |
|
823 aDes.Zero(); |
|
824 RResourceFile& rf=ResourceFileForId(aResourceId); |
|
825 TRAPD(err,rf.ReadL(aDes,aResourceId)); |
|
826 if (err==KErrNoMemory) |
|
827 { |
|
828 CBaActiveScheduler::DisplayExtendedError(KUidConeDll,KErrNoMemory); |
|
829 } |
|
830 else if (err!=KErrNone) |
|
831 { |
|
832 CBaActiveScheduler::DisplayExtendedError(KUidConeDll,KErrCoeFailedToReadFromProgDisk); |
|
833 } |
|
834 } |
|
835 |
|
836 EXPORT_C void CCoeEnv::ReadResourceAsDes8L(TDes8& aDes,TInt aResourceId) const |
|
837 /** Reads a resource into an 8 bit descriptor. |
|
838 |
|
839 The descriptor must be long enough to contain the entire resource. |
|
840 The method leaves if an error occurs when reading from the resource file. |
|
841 |
|
842 @param aDes On return, contains the read resource. |
|
843 @param aResourceId The numeric ID of the resource to be read. */ |
|
844 { |
|
845 RResourceFile& rf=ResourceFileForId(aResourceId); |
|
846 rf.ReadL(aDes,aResourceId); |
|
847 } |
|
848 |
|
849 EXPORT_C void CCoeEnv::ReadResourceAsDes16(TDes16& aDes,TInt aResourceId) const |
|
850 /** Reads a resource into a 16 bit descriptor. |
|
851 |
|
852 The descriptor must be long enough to contain the entire resource. No memory |
|
853 is allocated by this function. |
|
854 |
|
855 If the read fails the function sets an error condition and performs any cleanup |
|
856 required. The error condition causes the GUI to launch an alert window. |
|
857 Deprecated: use CCoeEnv::ReadResourceAsDes16L() instead. |
|
858 |
|
859 @deprecated |
|
860 @param aDes On return, contains the read resource. |
|
861 @param aResourceId The numeric ID of the resource to be read. |
|
862 @see RResourceFile::ReadL() |
|
863 @see KErrCoeFailedToReadFromProgDisk */ |
|
864 { |
|
865 aDes.Zero(); |
|
866 // Reading Unicode string |
|
867 RResourceFile& rf=ResourceFileForId(aResourceId); |
|
868 TPtr8 readBuffer((TText8* ) aDes.Ptr(),aDes.MaxSize()); |
|
869 TRAPD(err,rf.ReadL(readBuffer,aResourceId)); |
|
870 __ASSERT_DEBUG((readBuffer.Length()%2)==0||(err==KErrNone),Panic(ECoePanicWrongResourceFormat)); |
|
871 aDes.SetLength((readBuffer.Length()+1)>>1); |
|
872 |
|
873 if (err==KErrNoMemory) |
|
874 { |
|
875 CBaActiveScheduler::DisplayExtendedError(KUidConeDll,KErrNoMemory); |
|
876 } |
|
877 else if (err!=KErrNone) |
|
878 { |
|
879 CBaActiveScheduler::DisplayExtendedError(KUidConeDll,KErrCoeFailedToReadFromProgDisk); |
|
880 } |
|
881 } |
|
882 |
|
883 EXPORT_C void CCoeEnv::ReadResourceAsDes16L(TDes16& aDes,TInt aResourceId) const |
|
884 /** Reads a resource into a 16 bit descriptor. |
|
885 |
|
886 The descriptor must be long enough to contain the entire resource. |
|
887 The method leaves if an error occurs when reading from the resource file. |
|
888 |
|
889 @param aDes On return, contains the read resource. |
|
890 @param aResourceId The numeric ID of the resource to be read. */ |
|
891 { |
|
892 RResourceFile& rf=ResourceFileForId(aResourceId); |
|
893 TPtr8 readBuffer((TText8* ) aDes.Ptr(),aDes.MaxSize()); |
|
894 rf.ReadL(readBuffer,aResourceId); |
|
895 __ASSERT_DEBUG((readBuffer.Length()%2)==0,Panic(ECoePanicWrongResourceFormat)); |
|
896 aDes.SetLength((readBuffer.Length()+1)>>1); |
|
897 } |
|
898 |
|
899 EXPORT_C HBufC8* CCoeEnv::AllocReadResourceAsDes8L(TInt aResourceId) const |
|
900 /** Reads a resource into an 8 bit heap buffer, allocating the buffer. |
|
901 |
|
902 The calling program must destroy the heap descriptor when it is no longer |
|
903 needed. |
|
904 |
|
905 @param aResourceId The numeric ID of the resource to be read. |
|
906 @return Pointer to a heap descriptor containing the resource data. |
|
907 @see RResourceFile::AllocReadL() */ |
|
908 { |
|
909 RResourceFile& rf=ResourceFileForId(aResourceId); |
|
910 return(rf.AllocReadL(aResourceId)); |
|
911 } |
|
912 |
|
913 EXPORT_C HBufC16* CCoeEnv::AllocReadResourceAsDes16L(TInt aResourceId) const |
|
914 /** Reads a resource into a 16 bit heap buffer, allocating the buffer. |
|
915 |
|
916 The calling program must destroy the heap descriptor when it is no longer |
|
917 needed. |
|
918 |
|
919 @param aResourceId The numeric ID of the resource to be read. |
|
920 @return Pointer to a heap descriptor containing the resource data. */ |
|
921 { |
|
922 RResourceFile& rf=ResourceFileForId(aResourceId); |
|
923 HBufC8* readBuffer=rf.AllocReadLC(aResourceId); |
|
924 __ASSERT_DEBUG((readBuffer->Length()%2)==0,Panic(ECoePanicWrongResourceFormat)); |
|
925 const TPtrC16 ptrReadBuffer((TText16*) readBuffer->Ptr(),(readBuffer->Length()+1)>>1); |
|
926 HBufC16* textBuffer=HBufC16::NewL(ptrReadBuffer.Length()); |
|
927 *textBuffer=ptrReadBuffer; |
|
928 CleanupStack::PopAndDestroy(); |
|
929 return textBuffer; |
|
930 } |
|
931 |
|
932 EXPORT_C HBufC8* CCoeEnv::AllocReadResourceAsDes8LC(TInt aResourceId) const |
|
933 /** Reads a resource into an 8 bit heap buffer, allocating the buffer and pushing |
|
934 it onto the cleanup stack. |
|
935 |
|
936 The calling program must destroy the heap descriptor when it is no longer |
|
937 needed. |
|
938 |
|
939 @param aResourceId The numeric ID of the resource to be read. |
|
940 @return Pointer to a heap descriptor containing the resource data. |
|
941 @see RResourceFile::AllocReadL() */ |
|
942 { |
|
943 RResourceFile& rf=ResourceFileForId(aResourceId); |
|
944 return(rf.AllocReadLC(aResourceId)); |
|
945 } |
|
946 |
|
947 EXPORT_C HBufC16* CCoeEnv::AllocReadResourceAsDes16LC(TInt aResourceId) const |
|
948 /** Reads a resource into a 16 bit heap buffer, allocating the buffer and pushing |
|
949 it onto the cleanup stack. |
|
950 |
|
951 The calling program must destroy the heap descriptor when it is no longer |
|
952 needed. |
|
953 |
|
954 @param aResourceId The numeric ID of the resource to be read. |
|
955 @return Pointer to a heap descriptor containing the resource data. |
|
956 @see RResourceFile::AllocReadL() */ |
|
957 { |
|
958 // Reading Unicode string |
|
959 HBufC16* textBuffer=AllocReadResourceAsDes16L(aResourceId); |
|
960 CleanupStack::PushL(textBuffer); |
|
961 return textBuffer; |
|
962 } |
|
963 |
|
964 EXPORT_C void CCoeEnv::CreateResourceReaderLC(TResourceReader& aReader,TInt aResourceId) const |
|
965 /** Reads a resource from a resource file and sets its resource reader. |
|
966 |
|
967 The resource reader can subsequently be used to read resource data from the |
|
968 resource. The resource reader is also placed on the cleanup stack. |
|
969 |
|
970 Note: the GUI framework passes a resource reader as an argument to |
|
971 CCoeControl::ConstructFromResourceL(), with the resource reader's buffer already |
|
972 set to contain the relevant resource for that control. |
|
973 |
|
974 @param aReader The resource reader. |
|
975 @param aResourceId The numeric ID of the resource to be read. */ |
|
976 { |
|
977 RResourceFile& rf=ResourceFileForId(aResourceId); |
|
978 HBufC8* resource=rf.AllocReadLC(aResourceId); |
|
979 aReader.SetBuffer(resource); |
|
980 } |
|
981 |
|
982 EXPORT_C TInt CCoeEnv::AddResourceFileL(const TDesC& aFileName) |
|
983 /** Adds the specified resource file to the list maintained by CCoeEnv. |
|
984 |
|
985 Resource files are access counted so AddResourceFileL() can be called several |
|
986 times for the same resource file. However, care should be taken to call DeleteResourceFile() |
|
987 for each resource file added to the list. |
|
988 |
|
989 @param aFileName The resource file name. |
|
990 @return The offset value defined for this resource file. |
|
991 @panic CONE 15 The resource file has no NAME statement (i.e. has no offset). |
|
992 @see RResourceFile::Offset() |
|
993 @see ResourceFileVersionNumber() */ |
|
994 { |
|
995 if (!iResourceFileArray) |
|
996 iResourceFileArray=new(ELeave) CArrayFixFlat<RResourceFile>(2); // granularity of 2 |
|
997 RResourceFile resourceFile; |
|
998 resourceFile.OpenL(iFsSession,aFileName); |
|
999 CleanupClosePushL(resourceFile); |
|
1000 resourceFile.ConfirmSignatureL(ResourceFileVersionNumber()); |
|
1001 TInt offset=resourceFile.Offset(); |
|
1002 if (!offset) |
|
1003 Panic(ECoePanicResourceFileHasNullName); |
|
1004 TInt count=iResourceFileArray->Count(); |
|
1005 while (count--) |
|
1006 { |
|
1007 TInt previousOffset=(*iResourceFileArray)[count].Offset(); |
|
1008 if (offset==previousOffset) |
|
1009 break; |
|
1010 } |
|
1011 if (count>=0) |
|
1012 { |
|
1013 ++iExtra->iResFileAccessCount[count]; |
|
1014 resourceFile.Close(); |
|
1015 } |
|
1016 else |
|
1017 { |
|
1018 iResourceFileArray->AppendL(resourceFile); |
|
1019 const TInt error=iExtra->iResFileAccessCount.Append(1); |
|
1020 if (error!=KErrNone) |
|
1021 { |
|
1022 iResourceFileArray->Delete(iResourceFileArray->Count()-1); |
|
1023 User::Leave(error); |
|
1024 } |
|
1025 } |
|
1026 CleanupStack::Pop(); // resourceFile |
|
1027 return(offset); |
|
1028 } |
|
1029 |
|
1030 EXPORT_C void CCoeEnv::DeleteResourceFile(TInt aOffset) |
|
1031 /** Deletes the specified resource file from the list maintained by CCoeEnv. |
|
1032 |
|
1033 @param aOffset The offset value defined for the resource file to delete. |
|
1034 @panic CONE 13 The specified resource file does not exist in the list. */ |
|
1035 { |
|
1036 if (!aOffset) |
|
1037 return; |
|
1038 TInt count=iResourceFileArray->Count(); |
|
1039 while (count--) |
|
1040 { |
|
1041 RResourceFile& data=(*iResourceFileArray)[count]; |
|
1042 if (data.Offset()==aOffset) |
|
1043 { |
|
1044 if (--iExtra->iResFileAccessCount[count]==0) |
|
1045 { |
|
1046 data.Close(); |
|
1047 iResourceFileArray->Delete(count); |
|
1048 iExtra->iResFileAccessCount.Remove(count); |
|
1049 } |
|
1050 return; |
|
1051 } |
|
1052 } |
|
1053 Panic(ECoePanicUnknownResourceFile); |
|
1054 } |
|
1055 |
|
1056 RResourceFile& CCoeEnv::ResourceFileForId(TInt aResourceId) const |
|
1057 { |
|
1058 RResourceFile* resourceptr=NULL; |
|
1059 TRAPD(err, resourceptr=DoResourceFileForIdL(aResourceId)); |
|
1060 if(err!=KErrNone) |
|
1061 { |
|
1062 Panic(ECoePanicNoResourceFileForId); |
|
1063 } |
|
1064 return *resourceptr; |
|
1065 } |
|
1066 |
|
1067 RResourceFile* CCoeEnv::DoResourceFileForIdL(TInt aResourceId) const |
|
1068 { |
|
1069 TInt count=iResourceFileArray->Count(); |
|
1070 FOREVER |
|
1071 { |
|
1072 if (!count--) |
|
1073 Panic(ECoePanicNoResourceFileForId); |
|
1074 RResourceFile& resourceFile=(*iResourceFileArray)[count]; |
|
1075 if (resourceFile.OwnsResourceIdL(aResourceId)) |
|
1076 return &resourceFile; |
|
1077 } |
|
1078 } |
|
1079 |
|
1080 |
|
1081 void CCoeEnv::DestroyAllResourceFiles() |
|
1082 { |
|
1083 if (!iResourceFileArray) |
|
1084 return; |
|
1085 TInt count=iResourceFileArray->Count(); |
|
1086 while (count--) |
|
1087 { |
|
1088 RResourceFile& resourceFile=(*iResourceFileArray)[count]; |
|
1089 resourceFile.Close(); |
|
1090 } |
|
1091 delete(iResourceFileArray); |
|
1092 } |
|
1093 |
|
1094 EXPORT_C CDesC8ArrayFlat* CCoeEnv::ReadDesC8ArrayResourceL(TInt aResourceId) |
|
1095 /** Reads a resource into an 8 bit descriptor array. |
|
1096 |
|
1097 @param aResourceId The numeric ID of the resource to be read. |
|
1098 @return A pointer to the descriptor array containing the resource data. |
|
1099 @see TResourceReader::ReadDesC8ArrayL() */ |
|
1100 { |
|
1101 TResourceReader reader; |
|
1102 CreateResourceReaderLC(reader,aResourceId); |
|
1103 CDesC8ArrayFlat* array=reader.ReadDesC8ArrayL(); |
|
1104 CleanupStack::PopAndDestroy(); |
|
1105 return(array); |
|
1106 } |
|
1107 |
|
1108 EXPORT_C CDesC16ArrayFlat* CCoeEnv::ReadDesC16ArrayResourceL(TInt aResourceId) |
|
1109 /** Reads a resource into a 16 bit descriptor array. |
|
1110 |
|
1111 Ownership of the array is transferred to the caller. |
|
1112 |
|
1113 @param aResourceId The numeric ID of the resource to be read. |
|
1114 @return A pointer to the descriptor array containing the resource data. |
|
1115 @see TResourceReader::ReadDesC16ArrayL() */ |
|
1116 { |
|
1117 // Reading array of Unicode descriptors |
|
1118 TResourceReader reader; |
|
1119 CreateResourceReaderLC(reader,aResourceId); |
|
1120 CDesC16ArrayFlat* array=reader.ReadDesC16ArrayL(); |
|
1121 CleanupStack::PopAndDestroy(); |
|
1122 return(array); |
|
1123 } |
|
1124 |
|
1125 EXPORT_C void CCoeEnv::Format128(TDes& aDes,TInt aResourceId,...) |
|
1126 /** Reads a 128 byte resource into a formatted string. |
|
1127 |
|
1128 The format of the string is given by the variable argument list. |
|
1129 The unformatted resource data must not be longer than 128 bytes. |
|
1130 If it is, you should use Format256() instead. |
|
1131 |
|
1132 @param aDes On return, contains the formatted resource data. |
|
1133 @param aResourceId The numeric ID of the resource to be read. |
|
1134 @param ... Formatting information. */ |
|
1135 { |
|
1136 TBuf<128> formatString; |
|
1137 ReadResource(formatString,aResourceId); |
|
1138 VA_LIST list; |
|
1139 VA_START(list,aResourceId); |
|
1140 aDes.FormatList(formatString,list); |
|
1141 } |
|
1142 |
|
1143 EXPORT_C void CCoeEnv::Format256(TDes& aDes,TInt aResourceId,...) |
|
1144 /** Reads a 256 byte resource into a formatted string. |
|
1145 |
|
1146 The format of the string is given by the variable argument |
|
1147 list. The unformatted resource data must not be longer than 256 bytes. |
|
1148 |
|
1149 @param aDes On return, contains the formatted resource data. |
|
1150 @param aResourceId The numeric ID of the resource to be read. |
|
1151 @param ... Formatting information. */ |
|
1152 { |
|
1153 TBuf<256> formatString; |
|
1154 ReadResource(formatString,aResourceId); |
|
1155 VA_LIST list; |
|
1156 VA_START(list,aResourceId); |
|
1157 aDes.FormatList(formatString,list); |
|
1158 } |
|
1159 |
|
1160 EXPORT_C TInt CCoeEnv::ResourceFileVersionNumber() const |
|
1161 /** Gets the resource file version number. |
|
1162 |
|
1163 The function is intended to be replaced in a derived class. It should return |
|
1164 a defined constant which should correspond to the version number of resource |
|
1165 files used by the application. It is implemented by the standard GUI framework. |
|
1166 |
|
1167 AddResourceFileL() uses this function to verify that the application is not |
|
1168 using an out of date resource file. An out of date resource file causes AddResourceFileL() |
|
1169 to leave with error code KErrBaflWrongResourceFileSignature. |
|
1170 |
|
1171 @return The resource file version number. */ |
|
1172 { |
|
1173 return(0); |
|
1174 } |
|
1175 |
|
1176 EXPORT_C void CCoeEnv::LeaveWithErrorText(const TDesC& aMsg,const TDesC* aContextText) |
|
1177 /** Triggers a dialog which will display the error message |
|
1178 |
|
1179 @param aMsg The error message. |
|
1180 @param aContextText The error context text. */ |
|
1181 { |
|
1182 BaflUtils::CopyWithTruncation(ErrorText(),aMsg); |
|
1183 TDes& errContextText=ErrorContextText(); |
|
1184 errContextText.Zero(); |
|
1185 if (aContextText) |
|
1186 BaflUtils::CopyWithTruncation(errContextText,*aContextText); |
|
1187 User::Leave(KErrExtendedWithText); // Leave with a code of KErrExtendedWithText |
|
1188 } |
|
1189 |
|
1190 EXPORT_C TVersion CCoeEnv::Version() |
|
1191 /** Gets the version number of the UI Control Framework API. |
|
1192 |
|
1193 @deprecated |
|
1194 @return The version number, comprising major, minor and build numbers. */ |
|
1195 { // static |
|
1196 return(TVersion(KCoeMajorVersionNumber,KCoeMinorVersionNumber,KCoeBuildVersionNumber)); |
|
1197 } |
|
1198 |
|
1199 EXPORT_C CCoeEnv* CCoeEnv::Static() |
|
1200 /** Gets a pointer to a CCoeEnv which can be used to access CCoeEnv's functions. |
|
1201 |
|
1202 It allows application code to access CCoeEnv's functions even where there |
|
1203 is no direct access to a CCoeEnv object. |
|
1204 |
|
1205 For example: |
|
1206 |
|
1207 @code |
|
1208 CCoeEnv::Static()->CreateResourceReaderLC(aReader, aResourceId); |
|
1209 @endcode |
|
1210 @return The pointer for accessing CCoeEnv's functions. */ |
|
1211 { // static |
|
1212 return(TheCoe()); |
|
1213 } |
|
1214 |
|
1215 EXPORT_C void CCoeEnv::AddObserverOfLoadedFepL(MCoeObserverOfLoadedFep& aObserverOfLoadedFep) |
|
1216 /** Adds the specified MCoeObserverOfLoadedFep to the loaded FEP list. |
|
1217 |
|
1218 This enables objects to be notified when a front-end processor is loaded. |
|
1219 |
|
1220 @param aObserverOfLoadedFep The loaded FEP observer to be added to the list. */ |
|
1221 { |
|
1222 iExtra->AddObserverOfLoadedFepL(aObserverOfLoadedFep); |
|
1223 } |
|
1224 |
|
1225 EXPORT_C void CCoeEnv::RemoveObserverOfLoadedFep(MCoeObserverOfLoadedFep& aObserverOfLoadedFep) |
|
1226 /** Removes the specified loaded FEP observer. |
|
1227 |
|
1228 @param aObserverOfLoadedFep The FEP observer to be removed. */ |
|
1229 { |
|
1230 iExtra->RemoveObserverOfLoadedFep(aObserverOfLoadedFep); |
|
1231 } |
|
1232 |
|
1233 EXPORT_C void CCoeEnv::AddFocusObserverL(MCoeFocusObserver& aFocusObserver) |
|
1234 /** Adds the specified MCoeFocusObserver to the focus observer list. |
|
1235 |
|
1236 @param aFocusObserver The focus observer to be added to the list. |
|
1237 @panic CONE 18 aFocusObserver is NULL. |
|
1238 @panic CONE 21 aFocusObserver has already been added to the list. */ |
|
1239 { |
|
1240 iExtra->AddFocusObserverL(aFocusObserver); |
|
1241 } |
|
1242 |
|
1243 EXPORT_C void CCoeEnv::RemoveFocusObserver(MCoeFocusObserver& aFocusObserver) |
|
1244 /** Removes the specified focus observer. |
|
1245 |
|
1246 @param aFocusObserver The focus observer to be removed. |
|
1247 @see AddFocusObserverL() */ |
|
1248 { |
|
1249 iExtra->RemoveFocusObserver(aFocusObserver); |
|
1250 } |
|
1251 |
|
1252 void CCoeEnv::NotifyFocusObserversOfDestructionOfFocusedItem() |
|
1253 { |
|
1254 iExtra->NotifyFocusObserversOfDestructionOfFocusedItem(); // this enables focus observers to *immediately* NULL any pointers to the object being destroyed |
|
1255 QueueNotificationToFocusObserversOfChangeInFocus(); // this enables focus observers to pick up the newly focused control, once the things being destoyed has completely been destroyed |
|
1256 } |
|
1257 |
|
1258 EXPORT_C void CCoeEnv::AddForegroundObserverL(MCoeForegroundObserver& aForegroundObserver) |
|
1259 /** Adds the specified MCoeForegroundObserver to the foreground observer list. |
|
1260 |
|
1261 @param aForegroundObserver The foreground observer to be added to the list. |
|
1262 @panic CONE 18 aForegroundObserver is NULL. |
|
1263 @panic CONE 21 aForegroundObserver has already been added to the list. */ |
|
1264 { |
|
1265 iExtra->AddForegroundObserverL(aForegroundObserver); |
|
1266 } |
|
1267 |
|
1268 EXPORT_C void CCoeEnv::RemoveForegroundObserver(MCoeForegroundObserver& aForegroundObserver) |
|
1269 /** Removes the specified foreground observer. |
|
1270 |
|
1271 @param aForegroundObserver The foreground observer to be removed. |
|
1272 @see AddForegroundObserverL() */ |
|
1273 { |
|
1274 iExtra->RemoveForegroundObserver(aForegroundObserver); |
|
1275 } |
|
1276 |
|
1277 void CCoeEnv::NotifyForegroundObserversOfGainingForeground() |
|
1278 { |
|
1279 iExtra->NotifyForegroundObserversOfGainingForeground(); |
|
1280 } |
|
1281 |
|
1282 void CCoeEnv::NotifyForegroundObserversOfLosingForeground() |
|
1283 { |
|
1284 iExtra->NotifyForegroundObserversOfLosingForeground(); |
|
1285 } |
|
1286 |
|
1287 EXPORT_C void CCoeEnv::AddResourceChangeObserverL(MCoeResourceChangeObserver& aResourceChangeObserver) |
|
1288 /** Adds the specified MCoeResourceChangeObserver to the resource |
|
1289 change observer list. |
|
1290 |
|
1291 @param aResourceChangeObserver The resource change observer to be added to the list. */ |
|
1292 { |
|
1293 iExtra->AddResourceChangeObserverL(aResourceChangeObserver); |
|
1294 } |
|
1295 |
|
1296 EXPORT_C void CCoeEnv::RemoveResourceChangeObserver(MCoeResourceChangeObserver& aResourceChangeObserver) |
|
1297 /** Removes the specified resource change observer. |
|
1298 |
|
1299 @param aResourceChangeObserver The resource change observer to be removed. */ |
|
1300 { |
|
1301 iExtra->RemoveResourceChangeObserver(aResourceChangeObserver); |
|
1302 } |
|
1303 |
|
1304 void CCoeEnv::NotifyResourceObserversOfChangeInResource() |
|
1305 { |
|
1306 iExtra->NotifyResourceObserversOfChangeInResource(); |
|
1307 } |
|
1308 |
|
1309 EXPORT_C void CCoeEnv::AddMessageObserverL(MCoeMessageObserver& aMessageObserver) |
|
1310 /** Adds the specified MCoeMessageObserver to the message observer list. |
|
1311 |
|
1312 @param aMessageObserver The message observer to be added to the list. |
|
1313 @see RemoveMessageObserver() */ |
|
1314 { |
|
1315 iExtra->AddMessageObserverL(aMessageObserver); |
|
1316 } |
|
1317 |
|
1318 EXPORT_C void CCoeEnv::RemoveMessageObserver(MCoeMessageObserver& aMessageObserver) |
|
1319 /** Removes the specified MCoeMessageObserver from the message observer list. |
|
1320 |
|
1321 @param aMessageObserver The message observer to be removed from the list. |
|
1322 @see AddMessageObserverL() */ |
|
1323 { |
|
1324 iExtra->RemoveMessageObserver(aMessageObserver); |
|
1325 } |
|
1326 |
|
1327 EXPORT_C void CCoeEnv::AddMessageMonitorObserverL(MCoeMessageMonitorObserver& aMessageMonitorObserver) |
|
1328 /** Adds the specified MCoeMessageMonitorObserver to the message observer list |
|
1329 @param aMessageMonitorObserver The visibility change observer to be added to the list. */ |
|
1330 { |
|
1331 iExtra->AddMessageMonitorObserverL(aMessageMonitorObserver); |
|
1332 } |
|
1333 |
|
1334 EXPORT_C void CCoeEnv::RemoveMessageMonitorObserver(MCoeMessageMonitorObserver& aMessageMonitorObserver) |
|
1335 /** Removes the specified MCoeMessageMonitorObserver. |
|
1336 @param aMessageMonitorObserver The visibility change observer to be removed. */ |
|
1337 { |
|
1338 iExtra->RemoveMessageMonitorObserver(aMessageMonitorObserver); |
|
1339 } |
|
1340 |
|
1341 void CCoeEnv::NotifyMessageMonitorObserversOfEvent(const TWsEvent& aEvent) |
|
1342 { |
|
1343 /**Passes control of this function to the CCoeExtra class*/ |
|
1344 iExtra->NotifyMessageMonitorObserversOfEvent(aEvent); |
|
1345 } |
|
1346 |
|
1347 EXPORT_C void CCoeEnv::AddFepObserverL(MCoeFepObserver& aFepObserver) |
|
1348 /** Adds the specified MCoeFepObserver to the FEP observer list. |
|
1349 |
|
1350 @param aFepObserver The FEP observer to be added to the list. |
|
1351 @panic CONE 18 aFepObserver is NULL. |
|
1352 @panic CONE 21 aFepObserver has already been added to the list. */ |
|
1353 { |
|
1354 iExtra->AddFepObserverL(aFepObserver); |
|
1355 } |
|
1356 |
|
1357 EXPORT_C void CCoeEnv::RemoveFepObserver(MCoeFepObserver& aFepObserver) |
|
1358 /** Removes the specified FEP observer. |
|
1359 |
|
1360 @param aFepObserver The FEP observer to be removed. |
|
1361 @see AddFepObserverL() */ |
|
1362 { |
|
1363 iExtra->RemoveFepObserver(aFepObserver); |
|
1364 } |
|
1365 |
|
1366 EXPORT_C void CCoeEnv::ForEachFepObserverCall(TCoeFepObserverFunction aFepObserverFunction) |
|
1367 /** Calls the specified function for each FEP observer. |
|
1368 |
|
1369 This function is called for each MCoeFepObserver object that has been registered. |
|
1370 FEP observers are registered by calling CCoeEnv::AddFepObserverL(). |
|
1371 |
|
1372 @param aFepObserverFunction The function to be called. */ |
|
1373 { |
|
1374 iExtra->ForEachFepObserverCall(aFepObserverFunction); |
|
1375 } |
|
1376 |
|
1377 TInt CCoeEnv::AppStartupInstrumentationEventIdBase() |
|
1378 /** @internalComponent */ |
|
1379 { |
|
1380 return iExtra->iAppStartupInstrumentationEventIdBase; |
|
1381 } |
|
1382 |
|
1383 EXPORT_C void CCoeEnv::SetAppStartupInstrumentationEventIdBaseL(TInt aAppStartupInstrumentationEventIdBase) |
|
1384 /** @internalTechnology */ |
|
1385 { |
|
1386 iExtra->iAppStartupInstrumentationEventIdBase=aAppStartupInstrumentationEventIdBase; |
|
1387 } |
|
1388 |
|
1389 void CCoeEnv::EnsureCorrectFepIsLoadedL() |
|
1390 { |
|
1391 // Called to load the initial FEP when CCoeEnv is constructed. |
|
1392 CRepository& repository=CCoeDataStorage::GetL(*this).FepFrameworkRepositoryL(); |
|
1393 TBool loadDefaultFep=ETrue; |
|
1394 TBuf<16> fepId; |
|
1395 TInt error=repository.Get(ERepositoryKey_DynamicFepId, fepId); |
|
1396 if ((error!=KErrNotFound) && (fepId.Length()>0)) |
|
1397 { |
|
1398 User::LeaveIfError(error); |
|
1399 // Use the currently installed FEP. |
|
1400 TRAP(error, EnsureSpecifiedFepIsLoadedL(FepName::UidFromNameL(fepId))); |
|
1401 if (error==KErrNone) |
|
1402 { |
|
1403 loadDefaultFep=EFalse; |
|
1404 } |
|
1405 if (error==KErrNoMemory) // if it's any other error, we'll ignore it and just try to load the default FEP instead (below) |
|
1406 { |
|
1407 User::Leave(error); |
|
1408 } |
|
1409 } |
|
1410 if (loadDefaultFep) |
|
1411 { |
|
1412 User::LeaveIfError(repository.Get(ERepositoryKey_DefaultFepId, fepId)); |
|
1413 EnsureSpecifiedFepIsLoadedL(FepName::UidFromNameL(fepId)); // call this even if fep.Length()==0 |
|
1414 } |
|
1415 } |
|
1416 |
|
1417 EXPORT_C CCoeFep* CCoeEnv::Fep() const |
|
1418 /** Gets a pointer to the currently loaded FEP. |
|
1419 |
|
1420 @return The currently loaded FEP, or NULL if none is currently loaded. */ |
|
1421 { |
|
1422 return iExtra->iFep.iFep; |
|
1423 } |
|
1424 |
|
1425 EXPORT_C TUid CCoeEnv::FepUid() const |
|
1426 /** Gets the UID of the currently loaded FEP. |
|
1427 |
|
1428 @return The UID of the currently loaded FEP. Zero if none is currently loaded. */ |
|
1429 { |
|
1430 return iExtra->iFep.iFepUid; |
|
1431 } |
|
1432 |
|
1433 void CCoeEnv::QueueNotificationToFocusObserversOfChangeInFocus() |
|
1434 { |
|
1435 iExtra->iHighPriorityActive->QueueNotificationToFocusObserversOfChangeInFocus(); |
|
1436 } |
|
1437 |
|
1438 TInt CCoeEnv::FocusObserverNotificationIdentifier() const |
|
1439 { |
|
1440 return iExtra->iHighPriorityActive->FocusObserverNotificationIdentifier(); |
|
1441 } |
|
1442 |
|
1443 TBool CCoeEnv::FocusObserverNotificationIsStillPending(TInt aFocusObserverNotificationIdentifier) const |
|
1444 { |
|
1445 return iExtra->iHighPriorityActive->FocusObserverNotificationIsStillPending(aFocusObserverNotificationIdentifier); |
|
1446 } |
|
1447 |
|
1448 /** @internalTechnology*/ |
|
1449 void CCoeEnv::RefetchPixelMappingL() |
|
1450 { |
|
1451 CCoeFontProvider* fontProvider = iExtra->iDefaultFontProvider; |
|
1452 if(fontProvider) |
|
1453 { |
|
1454 fontProvider->RefetchPixelMappingL(); |
|
1455 } |
|
1456 } |
|
1457 |
|
1458 /** |
|
1459 This function returns the default text drawer. |
|
1460 @return The default text drawer. |
|
1461 */ |
|
1462 EXPORT_C CCoeTextDrawerBase& CCoeEnv::DefaultTextDrawer() const |
|
1463 { |
|
1464 return *iExtra->iDefaultTextDrawer; |
|
1465 } |
|
1466 |
|
1467 EXPORT_C TTypeUid::Ptr CCoeEnv::MopSupplyObject(TTypeUid /*aId*/) |
|
1468 /** Retrieves an object of the same type as that encapsulated in aId. |
|
1469 |
|
1470 This function is used to allow to ask owners for access to |
|
1471 other objects that they own. |
|
1472 |
|
1473 Other than in the case where NULL is returned, the object returned must be |
|
1474 of the same object type - that is, the ETypeId member of the object pointed |
|
1475 to by the pointer returned by this function must be equal to the iUid member |
|
1476 of aId. |
|
1477 |
|
1478 @param aId An encapsulated object type ID. |
|
1479 @return Encapsulates the pointer to the object provided. Note that the encapsulated |
|
1480 pointer may be NULL. */ |
|
1481 { |
|
1482 return TTypeUid::Null(); |
|
1483 } |
|
1484 |
|
1485 /** |
|
1486 Sets the zoom factor of all controls currently on the control stack. |
|
1487 |
|
1488 @see CCoeControl::SetZoomFactor() |
|
1489 @publishedPartner |
|
1490 @released |
|
1491 */ |
|
1492 EXPORT_C void CCoeEnv::SetZoomFactor(const TZoomFactor& aZoomFactor) |
|
1493 { |
|
1494 iExtra->iZoomFactor=aZoomFactor; |
|
1495 iAppUi->HandleStackedControlsResourceChange(KUidValueCoeZoomChangeEvent); |
|
1496 } |
|
1497 |
|
1498 /** |
|
1499 Returns the zoom factor last set by calling CCoeEnv::SetZoomFactor(). |
|
1500 |
|
1501 @publishedPartner |
|
1502 @released |
|
1503 */ |
|
1504 EXPORT_C TZoomFactor CCoeEnv::ZoomFactor() const |
|
1505 { |
|
1506 return iExtra->iZoomFactor; |
|
1507 } |
|
1508 |
|
1509 EXPORT_C CWindowGc* CCoeEnv::SwapSystemGc(CWindowGc* aGc) |
|
1510 /** Sets the new system graphics context. |
|
1511 |
|
1512 The function returns a pointer to the old system graphics context. |
|
1513 |
|
1514 @param aGc The new graphics context. |
|
1515 @return A pointer to the old graphics context. |
|
1516 @panic CONE 27 aGc is NULL. */ |
|
1517 { |
|
1518 __ASSERT_ALWAYS(aGc,Panic(ECoePanicNullGc)); |
|
1519 CWindowGc* gc=iSystemGc; |
|
1520 iSystemGc=aGc; |
|
1521 return gc; |
|
1522 } |
|
1523 |
|
1524 EXPORT_C CCoeStatic* CCoeEnv::Static(TUid aUid) |
|
1525 /** Gets a pointer to the specified CCoeStatic derived class. |
|
1526 |
|
1527 If no match is found it will return NULL. |
|
1528 |
|
1529 This function might be used to allow a CCoeStatic derived class to get a handle |
|
1530 on itself. |
|
1531 |
|
1532 Note: ownership of the object remains with CCoeEnv in all cases. |
|
1533 |
|
1534 @param aUid The UID of the CCoeStatic derived class. |
|
1535 @return A pointer to the CCoeStatic derived object. NULL if no match is |
|
1536 found. */ |
|
1537 { // static |
|
1538 CCoeEnv* env=CCoeEnv::Static(); |
|
1539 return env->FindStatic (aUid); |
|
1540 } |
|
1541 |
|
1542 // |
|
1543 // Gets a pointer to the specified <code>CCoeStatic</code> derived class. |
|
1544 // |
|
1545 // If no match is found it will simply return a NULL.This function might |
|
1546 // be used to allow a <code>CCoeStatic</code> derived class to get a |
|
1547 // handle on itself.Note:Ownership of the object remains with |
|
1548 // <code>CCoeEnv</code> in all cases. |
|
1549 // |
|
1550 // @since 7.0s |
|
1551 // @param "TUid aUid" |
|
1552 // The UID of the <code>CCoeStatic</code> derived class. |
|
1553 // @return "CCoeStatic*" |
|
1554 // A pointer to the <code>CCoeStatic</code> derived |
|
1555 // objects. NULL - If no match is found. |
|
1556 // |
|
1557 EXPORT_C CCoeStatic* CCoeEnv::FindStatic(TUid aUid) |
|
1558 { |
|
1559 TDblQueIter<CCoeStatic> iter(iExtra->iCoeStaticList); |
|
1560 CCoeStatic* obj=NULL; |
|
1561 iter.SetToFirst(); |
|
1562 while ((obj=iter++)!=NULL) |
|
1563 { |
|
1564 if (obj->iCsUid==aUid) |
|
1565 { |
|
1566 if ((obj->CsScope()!=CCoeStatic::EApp) || (obj->CsAppUi()==AppUi())) |
|
1567 { |
|
1568 return obj; |
|
1569 } |
|
1570 } |
|
1571 } |
|
1572 return obj; |
|
1573 } |
|
1574 |
|
1575 // |
|
1576 // Add aStatic to CCoeEnv, transferring ownership at the end of the function. |
|
1577 // Should only be called once for an object of each uid. |
|
1578 // |
|
1579 void CCoeEnv::AddStatic(CCoeStatic* aStatic) |
|
1580 { |
|
1581 iExtra->iCoeStaticList.Add(*aStatic); |
|
1582 } |
|
1583 |
|
1584 void CCoeEnv::UpdateStatic(CCoeAppUi* aNewAppUi) |
|
1585 { |
|
1586 TDblQueIter<CCoeStatic> iter(iExtra->iCoeStaticList); |
|
1587 CCoeStatic* obj=NULL; |
|
1588 iter.SetToFirst(); |
|
1589 while ((obj=iter++)!=NULL) |
|
1590 { |
|
1591 if (obj->CsScope()==CCoeStatic::EApp) |
|
1592 { |
|
1593 obj->SetCsAppUi(aNewAppUi); |
|
1594 } |
|
1595 } |
|
1596 } |
|
1597 |
|
1598 EXPORT_C void CCoeEnv::DisableExitChecks(TBool aDisable) |
|
1599 /** Disables exit checks on kernel resources. Affects debug builds only. |
|
1600 |
|
1601 CCoeEnv checks for kernel resources on exit (e.g. open file handles). |
|
1602 These checks may be too strict for some applications, such as a web browser, |
|
1603 so this function is provided to disable them. |
|
1604 |
|
1605 CCoeEnv also checks on heap allocation and window server resources on exit. |
|
1606 |
|
1607 @param aDisable True to disable resource checking, false to enable it.*/ |
|
1608 { |
|
1609 if (aDisable) |
|
1610 iEnvFlags|=ENoShutdownChecks; |
|
1611 else |
|
1612 iEnvFlags&=~ENoShutdownChecks; |
|
1613 } |
|
1614 |
|
1615 EXPORT_C void CCoeEnv::InputCapabilitiesChanged() |
|
1616 /** Notifies all focus observers (FEPs) that a change has been made to the input |
|
1617 capabilities of the focused control. */ |
|
1618 { |
|
1619 QueueNotificationToFocusObserversOfChangeInFocus(); |
|
1620 } |
|
1621 |
|
1622 /** |
|
1623 @internalTechnology |
|
1624 */ |
|
1625 EXPORT_C void CCoeEnv::GetMessageNotifyingObserversLC(TUint32 aClientHandleOfTargetWindowGroup, TUid& aMessageUid, TPtr8& aMessageParameters, const TWsEvent& aMessageEvent) |
|
1626 { |
|
1627 User::LeaveIfError(iWsSession.FetchMessage(aMessageUid, aMessageParameters, aMessageEvent)); |
|
1628 CleanupStack::PushL((TAny*)aMessageParameters.Ptr()); |
|
1629 iExtra->NotifyMessageObserversOfMessageL(aClientHandleOfTargetWindowGroup, aMessageUid, aMessageParameters); |
|
1630 } |
|
1631 |
|
1632 void CCoeEnv::SetInitialHandleCount() |
|
1633 { |
|
1634 TInt processHandleCount=0; |
|
1635 TInt threadHandleCount=0; |
|
1636 RThread().HandleCount(processHandleCount,threadHandleCount); |
|
1637 if (threadHandleCount>KMaxTInt16) |
|
1638 threadHandleCount=KMaxTInt16; |
|
1639 iEnvFlags|=(threadHandleCount<<16); |
|
1640 } |
|
1641 |
|
1642 EXPORT_C void CCoeEnv::Reserved_1() |
|
1643 { |
|
1644 } |
|
1645 |
|
1646 EXPORT_C void CCoeEnv::Reserved_2() |
|
1647 { |
|
1648 } |
|
1649 |
|
1650 EXPORT_C TInt CCoeEnv::RunError(TInt aError) |
|
1651 { |
|
1652 return CActive::RunError(aError); |
|
1653 } |
|
1654 |
|
1655 /** |
|
1656 Checks if the given resource is owned by one of the resource files in |
|
1657 the list maintained by CCoeEnv. |
|
1658 @publishedAll |
|
1659 @released |
|
1660 @since 9.0 |
|
1661 @param aResourceId The ID of the resource. |
|
1662 @return ETrue if resource is available, EFalse otherwise. |
|
1663 */ |
|
1664 EXPORT_C TBool CCoeEnv::IsResourceAvailableL(TInt aResourceId) const |
|
1665 { |
|
1666 TInt count = iResourceFileArray->Count(); |
|
1667 for (TInt ii=0; ii<count; ii++) |
|
1668 { |
|
1669 RResourceFile& resFile = iResourceFileArray->At(ii); |
|
1670 if (resFile.OwnsResourceIdL(aResourceId)) |
|
1671 { |
|
1672 return ETrue; |
|
1673 } |
|
1674 } |
|
1675 return EFalse; |
|
1676 } |
|
1677 |
|
1678 /** |
|
1679 This function returns the default font provider. |
|
1680 @return The default font provider. |
|
1681 */ |
|
1682 EXPORT_C const CCoeFontProvider& CCoeEnv::DefaultFontProvider() const |
|
1683 { |
|
1684 return *iExtra->iDefaultFontProvider; |
|
1685 } |
|
1686 |
|
1687 /** |
|
1688 This function returns the screen device with this particular screen number. |
|
1689 @param aScreenNumber |
|
1690 @return the screen device with this particular screen number. |
|
1691 */ |
|
1692 EXPORT_C CWsScreenDevice* CCoeEnv::ScreenDevice(TInt aScreenNumber) const |
|
1693 { |
|
1694 __ASSERT_DEBUG(((aScreenNumber>=0) && (aScreenNumber < iExtra->iArrayOfScreenItems.Count())),Panic(ECoePanicInvalidScreenNumber)); |
|
1695 return iExtra->iArrayOfScreenItems[aScreenNumber]->ScreenDevice(); |
|
1696 } |
|
1697 |
|
1698 /** |
|
1699 This function returns the window group associated with the screen device that bears this particular screen number. |
|
1700 @param aScreenNumber |
|
1701 @return the window group associated with the screen device that bears this particular screen number. |
|
1702 |
|
1703 */ |
|
1704 EXPORT_C RWindowGroup* CCoeEnv::RootWin(TInt aScreenNumber) const |
|
1705 { |
|
1706 __ASSERT_DEBUG(((aScreenNumber>=0) && (aScreenNumber < iExtra->iArrayOfScreenItems.Count())),Panic(ECoePanicInvalidScreenNumber)); |
|
1707 return iExtra->iArrayOfScreenItems[aScreenNumber]->WindowGroup(); |
|
1708 } |
|
1709 |
|
1710 /** |
|
1711 This function initializes an array of TScreenItems. Each SScreenItem object contains a pointer to a screen device and a window group |
|
1712 The first entry in this array points to the default screen device and window group. |
|
1713 The default screen device is the primary screen device in the system. |
|
1714 */ |
|
1715 void CCoeEnv::PopulateArrayOfScreenItemsL() |
|
1716 { |
|
1717 TInt numScreens(0); |
|
1718 numScreens = iWsSession.NumberOfScreens(); |
|
1719 //Initialise the first entry with the default screen device and default window group |
|
1720 //The default screen number is always 0 |
|
1721 CCoeEnvExtra::CScreenItem* defaultScreenItem = new(ELeave) CCoeEnvExtra::CScreenItem(iScreen,&iRootWin); |
|
1722 CleanupStack::PushL(defaultScreenItem); |
|
1723 iExtra->iArrayOfScreenItems.AppendL(defaultScreenItem); |
|
1724 CleanupStack::Pop(defaultScreenItem); |
|
1725 |
|
1726 for(TInt i=1;i<numScreens;i++) |
|
1727 { |
|
1728 CWsScreenDevice* screenDevice =new(ELeave) CWsScreenDevice(iWsSession); |
|
1729 CleanupStack::PushL(screenDevice); |
|
1730 User::LeaveIfError(screenDevice->Construct(i)); |
|
1731 RWindowGroup* windowGroup = new(ELeave) RWindowGroup(iWsSession); |
|
1732 CleanupStack::PushL(windowGroup); |
|
1733 User::LeaveIfError(windowGroup->Construct((TUint32)screenDevice, EFalse,screenDevice)); |
|
1734 CCoeEnvExtra::CScreenItem* screenItem = new(ELeave) CCoeEnvExtra::CScreenItem(screenDevice,windowGroup); |
|
1735 CleanupStack::Pop(2,screenDevice); // ownership of screenDevice and windowGroup goes to screenItem |
|
1736 CleanupStack::PushL(screenItem); |
|
1737 iExtra->iArrayOfScreenItems.AppendL(screenItem); |
|
1738 CleanupStack::Pop(screenItem); |
|
1739 } |
|
1740 } |
|
1741 |
|
1742 /** |
|
1743 This function deletes the array of TScreenItems |
|
1744 */ |
|
1745 void CCoeEnv::DeleteArrayOfScreensItems() |
|
1746 { |
|
1747 if(iExtra && iExtra->iArrayOfScreenItems.Count() > 0) |
|
1748 { |
|
1749 iExtra->iArrayOfScreenItems[0]->SetScreenDevice(0); |
|
1750 iExtra->iArrayOfScreenItems[0]->SetWindowGroup(0); |
|
1751 iExtra->iArrayOfScreenItems.ResetAndDestroy(); |
|
1752 } |
|
1753 } |
|
1754 |
|
1755 |
|
1756 /** |
|
1757 Return an error code if something failed during early c'tor construction. |
|
1758 @internalTechnology |
|
1759 */ |
|
1760 EXPORT_C TInt CCoeEnv::CoeEnvConstructorError() const |
|
1761 { |
|
1762 return (iEnvFlags&EExtraPointerIsErrorCode ? reinterpret_cast<TInt>(iExtra) : KErrNone); |
|
1763 } |
|
1764 |
|
1765 /** |
|
1766 Return the status of the report control state change. |
|
1767 @internalTechnology |
|
1768 */ |
|
1769 TBool CCoeEnv::ControlStateChange() |
|
1770 { return iExtra->iControlState; } |
|
1771 |
|
1772 |
|
1773 // MCoeObserverOfLoadedFep |
|
1774 EXPORT_C MCoeObserverOfLoadedFep::MCoeObserverOfLoadedFep() |
|
1775 { |
|
1776 } |
|
1777 EXPORT_C void MCoeObserverOfLoadedFep::MCoeObserverOfLoadedFep_Reserved_1() |
|
1778 { |
|
1779 } |
|
1780 |
|
1781 EXPORT_C void MCoeObserverOfLoadedFep::MCoeObserverOfLoadedFep_Reserved_2() |
|
1782 { |
|
1783 } |
|
1784 |
|
1785 // MCoeFocusObserver |
|
1786 EXPORT_C MCoeFocusObserver::MCoeFocusObserver() |
|
1787 { |
|
1788 } |
|
1789 EXPORT_C void MCoeFocusObserver::MCoeFocusObserver_Reserved_1() |
|
1790 { |
|
1791 } |
|
1792 |
|
1793 EXPORT_C void MCoeFocusObserver::MCoeFocusObserver_Reserved_2() |
|
1794 { |
|
1795 } |
|
1796 |
|
1797 // MCoeResourceObserver |
|
1798 EXPORT_C MCoeResourceChangeObserver::MCoeResourceChangeObserver() |
|
1799 { |
|
1800 } |
|
1801 EXPORT_C void MCoeResourceChangeObserver::MCoeResourceChangeObserver_Reserved_1() |
|
1802 { |
|
1803 } |
|
1804 |
|
1805 EXPORT_C void MCoeResourceChangeObserver::MCoeResourceChangeObserver_Reserved_2() |
|
1806 { |
|
1807 } |
|
1808 // MCoeForegroundObserver |
|
1809 EXPORT_C MCoeForegroundObserver::MCoeForegroundObserver() |
|
1810 { |
|
1811 } |
|
1812 EXPORT_C void MCoeForegroundObserver::MCoeForegroundObserver_Reserved_1() |
|
1813 { |
|
1814 } |
|
1815 |
|
1816 EXPORT_C void MCoeForegroundObserver::MCoeForegroundObserver_Reserved_2() |
|
1817 { |
|
1818 } |
|
1819 |
|
1820 // MCoeMessageObserver |
|
1821 EXPORT_C MCoeMessageObserver::MCoeMessageObserver() |
|
1822 { |
|
1823 } |
|
1824 EXPORT_C void MCoeMessageObserver::MCoeMessageObserver_Reserved_1() |
|
1825 { |
|
1826 } |
|
1827 |
|
1828 EXPORT_C void MCoeMessageObserver::MCoeMessageObserver_Reserved_2() |
|
1829 { |
|
1830 } |
|
1831 |
|
1832 |
|
1833 // MCoeMessageMonitorObserver |
|
1834 |
|
1835 EXPORT_C void MCoeMessageMonitorObserver::MCoeMessageMonitorObserver_Reserved_1() |
|
1836 { |
|
1837 } |
|
1838 |
|
1839 EXPORT_C void MCoeMessageMonitorObserver::MCoeMessageMonitorObserver_Reserved_2() |
|
1840 { |
|
1841 } |
|
1842 |
|
1843 |
|
1844 // CCoeStatic |
|
1845 EXPORT_C CCoeStatic::CCoeStatic() |
|
1846 { |
|
1847 } |
|
1848 |
|
1849 EXPORT_C CCoeStatic::~CCoeStatic() |
|
1850 /** Destructor. */ |
|
1851 { |
|
1852 iCsLink.Deque(); |
|
1853 } |
|
1854 |
|
1855 EXPORT_C CCoeStatic::CCoeStatic(TUid aUid,TScope aScope) |
|
1856 /** Constructor specifying a unique UID and the scope of the object. |
|
1857 |
|
1858 @param aUid The unique UID. |
|
1859 @param The scope of access to the object. By default, the object can be accessed |
|
1860 from anywhere in the thread (EThread). */ |
|
1861 { |
|
1862 DoConstruction(aUid,EDefaultDestructionPriority,aScope); |
|
1863 } |
|
1864 |
|
1865 EXPORT_C CCoeStatic::CCoeStatic(TUid aUid,TInt aDestructionPriority,TScope aScope) |
|
1866 /** Constructor specifying a unique UID and the destruction priority and scope of the object. |
|
1867 |
|
1868 @param aUid The unique UID. |
|
1869 @param aDestructionPriority Priority determining the order of destruction relative to other |
|
1870 CCoeStatic-derived objects. The higher the destruction-priority of the object, the earlier that |
|
1871 object is deleted. Objects with a positive destruction-priority are destroyed before the CCoeAppUi |
|
1872 object is destroyed. Objects with a negative destruction-priority are destroyed after the CCoeAppUi |
|
1873 object is destroyed. |
|
1874 @param aScope The scope of access to the object. By default, the object can be accessed |
|
1875 from anywhere in the thread (EThread). */ |
|
1876 { |
|
1877 DoConstruction(aUid,aDestructionPriority,aScope); |
|
1878 } |
|
1879 |
|
1880 void CCoeStatic::DoConstruction(const TUid& aUid,TInt aDestructionPriority,TScope aScope) |
|
1881 { |
|
1882 __ASSERT_ALWAYS(aUid!=KNullUid,Panic(ECoePanicNullObjectUid)); |
|
1883 __ASSERT_ALWAYS(CCoeEnv::Static(aUid)==NULL,Panic(ECoePanicDuplicateObjectUid)); |
|
1884 iCsLink.iPriority=aDestructionPriority; |
|
1885 iCsUid=aUid; |
|
1886 CCoeEnv* env = CCoeEnv::Static(); |
|
1887 iCsAppUiAndScope=0; |
|
1888 if (aScope==EApp) |
|
1889 { |
|
1890 iCsAppUiAndScope=(REINTERPRET_CAST(TUint,env->AppUi())|0x1u); |
|
1891 } |
|
1892 env->AddStatic(this); |
|
1893 } |
|
1894 |
|
1895 void CCoeStatic::SetCsAppUi(CCoeAppUi* aAppUi) |
|
1896 { |
|
1897 const TUint scopeFlag=(iCsAppUiAndScope&0x1u); |
|
1898 iCsAppUiAndScope=(REINTERPRET_CAST(TUint,aAppUi)|scopeFlag); |
|
1899 } |
|
1900 |
|
1901 CCoeAppUi* CCoeStatic::CsAppUi() const |
|
1902 { |
|
1903 return REINTERPRET_CAST(CCoeAppUi*, iCsAppUiAndScope&~0x1u); |
|
1904 } |
|
1905 |
|
1906 CCoeStatic::TScope CCoeStatic::CsScope() const |
|
1907 { |
|
1908 return (iCsAppUiAndScope&0x1u)? EApp: EThread; |
|
1909 } |
|
1910 |
|
1911 IMPORT_C void PanicStub1(); |
|
1912 EXPORT_C void PanicStub1() |
|
1913 { |
|
1914 Panic(ECoePanicExportNotSupported); |
|
1915 } |
|
1916 EXPORT_C void CCoeStatic::CCoeStatic_Reserved1() |
|
1917 { |
|
1918 } |
|
1919 |
|
1920 EXPORT_C void CCoeStatic::CCoeStatic_Reserved2() |
|
1921 { |
|
1922 } |