|
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: Discreet popup |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <akndiscreetpopup.h> |
|
19 #include <AknPanic.h> |
|
20 #include <AknTasHook.h> |
|
21 #include <eiksrvs.h> |
|
22 |
|
23 #include "akndiscreetpopupcontrol.h" |
|
24 #include "akndiscreetpopupserverhandler.h" |
|
25 |
|
26 const TUid KDiscreetPopupSingleton = { 537001156 }; |
|
27 const TInt KInitialPopupId( 1 ); |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CAknDiscreetPopup::~CAknDiscreetPopup |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CAknDiscreetPopup::~CAknDiscreetPopup() |
|
36 { |
|
37 if ( iUseCoeEnv ) |
|
38 { |
|
39 AKNTASHOOK_REMOVE(); |
|
40 } |
|
41 CAknDiscreetPopupControl* popup( NULL ); |
|
42 for ( TInt j = 0; j < iLocalPopups.Count(); j++ ) |
|
43 { |
|
44 popup = iLocalPopups[ j ]; |
|
45 delete popup; |
|
46 popup = NULL; |
|
47 } |
|
48 iLocalPopups.Close(); |
|
49 delete iServerHandler; |
|
50 } |
|
51 |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CAknDiscreetPopup::ShowLocalPopupL |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C TInt CAknDiscreetPopup::ShowLocalPopupL( |
|
58 const TDesC& aTitle, |
|
59 const TDesC& aText, |
|
60 CGulIcon* aIcon, |
|
61 const TAknsItemID& aSkinId, |
|
62 const TDesC& aBitmapFile, |
|
63 const TInt aBitmapId, |
|
64 const TInt aMaskId, |
|
65 const TInt aFlags, |
|
66 const TInt aCommand, |
|
67 MEikCommandObserver* aCommandObserver ) |
|
68 { |
|
69 __ASSERT_ALWAYS( CCoeEnv::Static(), Panic( EAknPanicNotSupported ) ); |
|
70 TInt popupId = 0; |
|
71 CAknDiscreetPopup* instance = InstanceL(); |
|
72 if( instance ) |
|
73 { |
|
74 popupId = instance->DoShowLocalL( aTitle, |
|
75 aText, |
|
76 aIcon, |
|
77 aSkinId, |
|
78 aBitmapFile, |
|
79 aBitmapId, |
|
80 aMaskId, |
|
81 aFlags, |
|
82 aCommand, |
|
83 aCommandObserver ); |
|
84 } |
|
85 return popupId; |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CAknDiscreetPopup::ShowLocalPopupL |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 EXPORT_C TInt CAknDiscreetPopup::ShowLocalPopupL( |
|
94 const TInt aResourceId, |
|
95 const TInt aCommand, |
|
96 MEikCommandObserver* aCommandObserver ) |
|
97 { |
|
98 __ASSERT_ALWAYS( CCoeEnv::Static(), Panic( EAknPanicNotSupported ) ); |
|
99 TInt popupId = 0; |
|
100 CAknDiscreetPopup* instance = InstanceL(); |
|
101 if( instance ) |
|
102 { |
|
103 popupId = instance->DoShowLocalL( aResourceId, KNullDesC, aCommand, aCommandObserver ); |
|
104 } |
|
105 return popupId; |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CAknDiscreetPopup::ShowGlobalPopupL |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C TInt CAknDiscreetPopup::ShowGlobalPopupL( |
|
114 const TDesC& aTitle, |
|
115 const TDesC& aText, |
|
116 const TAknsItemID& aSkinId, |
|
117 const TDesC& aBitmapFile, |
|
118 const TInt aBitmapId, |
|
119 const TInt aMaskId, |
|
120 const TInt aFlags, |
|
121 const TInt aCommandId, |
|
122 MEikCommandObserver* aCommandObserver, |
|
123 const TUid& aAppUid, |
|
124 const TUid& aViewUid ) |
|
125 { |
|
126 TInt popupId = 0; |
|
127 CAknDiscreetPopup* instance = InstanceL(); |
|
128 if ( instance ) |
|
129 { |
|
130 popupId = instance->DoShowGlobalL(aTitle, aText, aSkinId, aBitmapFile, |
|
131 aBitmapId, aMaskId, aFlags, aCommandId, aCommandObserver, aAppUid, |
|
132 aViewUid); |
|
133 } |
|
134 return popupId; |
|
135 } |
|
136 |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CAknDiscreetPopup::ShowGlobalPopupL |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C TInt CAknDiscreetPopup::ShowGlobalPopupL( |
|
143 const TInt aResourceId, |
|
144 const TDesC& aResourceFile, |
|
145 const TInt aCommandId, |
|
146 MEikCommandObserver* aCommandObserver, |
|
147 const TUid& aAppUid, |
|
148 const TUid& aViewUid ) |
|
149 { |
|
150 TInt popupId = 0; |
|
151 CAknDiscreetPopup* instance = InstanceL(); |
|
152 if( instance ) |
|
153 { |
|
154 popupId = instance->DoShowGlobalL( aResourceId, |
|
155 aResourceFile, |
|
156 aCommandId, |
|
157 aCommandObserver, |
|
158 aAppUid, |
|
159 aViewUid ); |
|
160 } |
|
161 return popupId; |
|
162 } |
|
163 |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CAknDiscreetPopup::InitL |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 EXPORT_C void CAknDiscreetPopup::InitL() |
|
170 { |
|
171 __ASSERT_ALWAYS( !CCoeEnv::Static(), Panic( EAknPanicNotSupported ) ); |
|
172 |
|
173 // Create popup instance and store it to TLS |
|
174 if ( !Dll::Tls() ) |
|
175 { |
|
176 CAknDiscreetPopup* instance = new ( ELeave ) CAknDiscreetPopup; |
|
177 CleanupStack::PushL( instance ); |
|
178 instance->ConstructL(); |
|
179 User::LeaveIfError( Dll::SetTls( instance ) ); |
|
180 CleanupStack::Pop( instance ); |
|
181 } |
|
182 } |
|
183 |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CAknDiscreetPopup::Release |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C void CAknDiscreetPopup::Release() |
|
190 { |
|
191 __ASSERT_ALWAYS( !CCoeEnv::Static(), Panic( EAknPanicNotSupported ) ); |
|
192 |
|
193 // Delete popup instance from TLS |
|
194 CAknDiscreetPopup* instance = |
|
195 static_cast<CAknDiscreetPopup*>( Dll::Tls() ); |
|
196 if ( instance ) |
|
197 { |
|
198 delete instance; |
|
199 instance = NULL; |
|
200 Dll::SetTls( NULL ); |
|
201 } |
|
202 } |
|
203 |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // CAknDiscreetPopup::CAknDiscreetPopup |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 CAknDiscreetPopup::CAknDiscreetPopup() |
|
210 { |
|
211 } |
|
212 |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // CAknDiscreetPopup::CAknDiscreetPopup |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 CAknDiscreetPopup::CAknDiscreetPopup( TBool aUseCoeEnv ) |
|
219 : CCoeStatic( KDiscreetPopupSingleton, CCoeStatic::EThread ), |
|
220 iUseCoeEnv( aUseCoeEnv ) |
|
221 { |
|
222 AKNTASHOOK_ADD( this, "CAknDiscreetPopup" ); |
|
223 } |
|
224 |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CAknDiscreetPopup::ConstructL |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CAknDiscreetPopup::ConstructL() |
|
231 { |
|
232 iServerHandler = CAknDiscreetPopupServerHandler::NewL(); |
|
233 } |
|
234 |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // CAknDiscreetPopup::InstanceL |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 CAknDiscreetPopup* CAknDiscreetPopup::InstanceL() |
|
241 { |
|
242 CAknDiscreetPopup* instance( NULL ); |
|
243 if ( CCoeEnv::Static() ) |
|
244 { |
|
245 instance = static_cast< CAknDiscreetPopup* > |
|
246 ( CCoeEnv::Static( KDiscreetPopupSingleton ) ); |
|
247 if ( !instance ) |
|
248 { |
|
249 instance = new ( ELeave ) CAknDiscreetPopup( ETrue ); |
|
250 CleanupStack::PushL( instance ); |
|
251 instance->ConstructL(); |
|
252 CleanupStack::Pop( instance ); |
|
253 } |
|
254 } |
|
255 else |
|
256 { |
|
257 instance = static_cast<CAknDiscreetPopup*>( Dll::Tls() ); |
|
258 } |
|
259 return instance; |
|
260 } |
|
261 |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CAknDiscreetPopup::DoShowLocalL |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 TInt CAknDiscreetPopup::DoShowLocalL( |
|
268 const TDesC& aTitle, |
|
269 const TDesC& aText, |
|
270 CGulIcon* aIcon, |
|
271 const TAknsItemID& aSkinId, |
|
272 const TDesC& aBitmapFile, |
|
273 const TInt& aBitmapId, |
|
274 const TInt& aMaskId, |
|
275 const TInt& aFlags, |
|
276 const TInt& aCommand, |
|
277 MEikCommandObserver* aCommandObserver ) |
|
278 { |
|
279 TInt popupId( NextPopupId() ); |
|
280 CAknDiscreetPopupControl* popup = CAknDiscreetPopupControl::NewL( |
|
281 EFalse, aTitle, aText, aIcon, aSkinId, aBitmapFile, |
|
282 aBitmapId, aMaskId, aFlags, aCommand, popupId, aCommandObserver ); |
|
283 CleanupStack::PushL( popup ); |
|
284 ShowPopupL( popup ); |
|
285 CleanupStack::Pop( popup ); |
|
286 return popupId; |
|
287 } |
|
288 |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // CAknDiscreetPopup::DoShowLocalL |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 TInt CAknDiscreetPopup::DoShowLocalL( |
|
295 const TInt& aResourceId, |
|
296 const TDesC& aResourceFile, |
|
297 const TInt& aCommand, |
|
298 MEikCommandObserver* aCommandObserver ) |
|
299 { |
|
300 TInt popupId( NextPopupId() ); |
|
301 CAknDiscreetPopupControl* popup = CAknDiscreetPopupControl::NewL( |
|
302 EFalse, aResourceId, aResourceFile, |
|
303 aCommand, popupId, aCommandObserver ); |
|
304 CleanupStack::PushL( popup ); |
|
305 ShowPopupL( popup ); |
|
306 CleanupStack::Pop( popup ); |
|
307 return popupId; |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------------------------- |
|
311 // CAknDiscreetPopup::DoShowGlobalL |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 TInt CAknDiscreetPopup::DoShowGlobalL( |
|
315 const TDesC& aTitle, |
|
316 const TDesC& aText, |
|
317 const TAknsItemID& aSkinId, |
|
318 const TDesC& aBitmapFile, |
|
319 const TInt& aBitmapId, |
|
320 const TInt& aMaskId, |
|
321 const TInt& aFlags, |
|
322 const TInt& aCommandId, |
|
323 MEikCommandObserver* aCommandObserver, |
|
324 const TUid& aAppUid, |
|
325 const TUid& aViewUid ) |
|
326 { |
|
327 TInt popupId; |
|
328 RThread thread; |
|
329 if ( thread.Name() != EIKAPPUI_SERVER_THREAD_NAME && iServerHandler ) |
|
330 { |
|
331 popupId = NextPopupId(); |
|
332 iServerHandler->LaunchGlobalPopupL( |
|
333 aTitle, |
|
334 aText, |
|
335 aSkinId, |
|
336 aBitmapFile, |
|
337 aBitmapId, |
|
338 aMaskId, |
|
339 aFlags, |
|
340 aCommandId, |
|
341 popupId, |
|
342 aCommandObserver, |
|
343 aAppUid, |
|
344 aViewUid ); |
|
345 } |
|
346 else |
|
347 { |
|
348 CGulIcon* icon = NULL; |
|
349 DoShowLocalL( aTitle, aText, icon, aSkinId, aBitmapFile, |
|
350 aBitmapId, aMaskId, aFlags, aCommandId, aCommandObserver ); |
|
351 } |
|
352 return popupId; |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // CAknDiscreetPopup::DoShowGlobalL |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 TInt CAknDiscreetPopup::DoShowGlobalL( |
|
360 const TInt& aResourceId, |
|
361 const TDesC& aResourceFile, |
|
362 const TInt& aCommandId, |
|
363 MEikCommandObserver* aCommandObserver, |
|
364 const TUid& aAppUid, |
|
365 const TUid& aViewUid ) |
|
366 { |
|
367 TInt popupId; |
|
368 RThread thread; |
|
369 if ( thread.Name() != EIKAPPUI_SERVER_THREAD_NAME && iServerHandler ) |
|
370 { |
|
371 popupId = NextPopupId(); |
|
372 iServerHandler->LaunchGlobalPopupL( |
|
373 aResourceId, |
|
374 aResourceFile, |
|
375 aCommandId, |
|
376 popupId, |
|
377 aCommandObserver, |
|
378 aAppUid, |
|
379 aViewUid ); |
|
380 } |
|
381 else |
|
382 { |
|
383 DoShowLocalL( aResourceId, aResourceFile, |
|
384 aCommandId, aCommandObserver ); |
|
385 } |
|
386 return popupId; |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // CAknDiscreetPopup::ShowPopupL |
|
391 // --------------------------------------------------------------------------- |
|
392 // |
|
393 void CAknDiscreetPopup::ShowPopupL( CAknDiscreetPopupControl* aControl ) |
|
394 { |
|
395 if ( !aControl ) |
|
396 { |
|
397 return; |
|
398 } |
|
399 |
|
400 // Inform other popups that new popup is launched |
|
401 for ( TInt i = 0; i < iLocalPopups.Count(); i++ ) |
|
402 { |
|
403 iLocalPopups[ i ]->HandleDiscreetPopupActionL( |
|
404 CAknDiscreetPopupControl::EAknDiscreetPopupAnotherLaunched ); |
|
405 } |
|
406 // Show popup and add it to popup list |
|
407 aControl->SetObserver( this ); |
|
408 aControl->HandleDiscreetPopupActionL( |
|
409 CAknDiscreetPopupControl::EAknDiscreetPopupShow ); |
|
410 iLocalPopups.AppendL( aControl ); |
|
411 } |
|
412 |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // CAknDiscreetPopup::DeletePopup |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 void CAknDiscreetPopup::DeletePopup( CAknDiscreetPopupControl* aControl ) |
|
419 { |
|
420 if ( !aControl ) |
|
421 { |
|
422 return; |
|
423 } |
|
424 |
|
425 TInt index = iLocalPopups.Find( aControl ); |
|
426 iLocalPopups.Remove( index ); |
|
427 delete aControl; |
|
428 aControl = NULL; |
|
429 } |
|
430 |
|
431 |
|
432 // --------------------------------------------------------------------------- |
|
433 // CAknDiscreetPopup::NextPopupId |
|
434 // --------------------------------------------------------------------------- |
|
435 // |
|
436 TInt CAknDiscreetPopup::NextPopupId() |
|
437 { |
|
438 TInt popupId( KInitialPopupId ); |
|
439 while ( PopupIdInUse( popupId ) ) |
|
440 { |
|
441 popupId++; |
|
442 } |
|
443 if ( iServerHandler ) |
|
444 { |
|
445 popupId = iServerHandler->CheckPopupId( popupId ); |
|
446 } |
|
447 return popupId; |
|
448 } |
|
449 |
|
450 |
|
451 // --------------------------------------------------------------------------- |
|
452 // CAknDiscreetPopup::PopupIdInUse |
|
453 // --------------------------------------------------------------------------- |
|
454 // |
|
455 TBool CAknDiscreetPopup::PopupIdInUse( const TInt& aPopupId ) |
|
456 { |
|
457 for ( TInt i = 0; i < iLocalPopups.Count(); i++ ) |
|
458 { |
|
459 if ( iLocalPopups[ i ]->PopupId() == aPopupId ) |
|
460 { |
|
461 return ETrue; |
|
462 } |
|
463 } |
|
464 return EFalse; |
|
465 } |
|
466 |
|
467 |
|
468 // --------------------------------------------------------------------------- |
|
469 // CAknDiscreetPopup::HandleControlEventL |
|
470 // --------------------------------------------------------------------------- |
|
471 // |
|
472 void CAknDiscreetPopup::HandleControlEventL( |
|
473 CCoeControl* aControl, TCoeEvent aEventType ) |
|
474 { |
|
475 if ( aEventType == EEventRequestExit || aEventType == EEventRequestCancel ) |
|
476 { |
|
477 DeletePopup( static_cast<CAknDiscreetPopupControl*>( aControl ) ); |
|
478 } |
|
479 } |
|
480 |
|
481 |