uifw/AvKon/src/aknglobalpopupprioritycontroller.cpp
changeset 0 2f259fa3e83a
child 38 c52421ed5f07
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2007 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:  System for managing global popup window priorities
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "aknglobalpopupprioritycontroller.h"
       
    20 #include "AknPopupFader.h"
       
    21 #include <eikenv.h>
       
    22 #include <e32hashtab.h>
       
    23 #include <coecntrl.h>
       
    24 #include <eikappui.h>
       
    25 
       
    26 const TUid KAknGlobalPopupPriorityControllerStaticId = { 0x102835a0 };
       
    27 const TInt KAknGlobalPopupPriorityControllerMaxStack = 10;
       
    28 
       
    29 const TInt KControlStackSleepFlags = ECoeStackFlagRefusesAllKeys|ECoeStackFlagRefusesFocus;
       
    30 
       
    31 enum TGppcPanic
       
    32     {
       
    33     EGppcPanic_DontSupportMultipleSubPopups,
       
    34     EGppcPanic_DontSupportMultipleParents
       
    35     };
       
    36 
       
    37 void GppcPanic(TGppcPanic aReason)
       
    38     {
       
    39     _LIT(KReason, "AknGppc");
       
    40     User::Panic(KReason, aReason);
       
    41     }
       
    42 
       
    43 
       
    44 // hash an identity functions required by RHashMap
       
    45 template<typename T>
       
    46 TUint32 GeneralPtrHash(T* const & aPtr)
       
    47     {
       
    48     return DefaultHash::Integer((TInt)aPtr);
       
    49     }
       
    50 
       
    51 template<typename T>
       
    52 TBool GeneralPtrIdentity(T* const & aP1, T* const & aP2)
       
    53     {
       
    54     return aP1 == aP2;
       
    55     }
       
    56 
       
    57 
       
    58 NONSHARABLE_CLASS(CAknGlobalPopupPriorityController) : public CCoeStatic
       
    59     {
       
    60 public:
       
    61     static void CreateInstanceL();
       
    62     static CAknGlobalPopupPriorityController* Instance();
       
    63 
       
    64     void AllowGlobalPopups(TBool aAllow);
       
    65     void SetPopupPriorityL(CCoeControl* aPopup, TInt aPriority);
       
    66     void RemovePopup(CCoeControl* aPopup);
       
    67     void ShowPopup(CCoeControl* aPopup, TBool aShow);
       
    68     void SetRootWinOrdinalPosition(TInt aOrdinalPosition);
       
    69     void AddSubPopupL(CCoeControl* aPopup, CCoeControl* aSubPopup);
       
    70     void AddPopupToControlStackL(CCoeControl* aPopup,TInt aPriority,TInt aStackingFlags);
       
    71     void FadeBehindPopupL(CCoeControl* aPopup, MAknFadedComponent* aFadedComponent);
       
    72     void RouseSleepingPopup(CCoeControl* aPopup, TBool aRoused);
       
    73 
       
    74     TBool GlobalPopupsAllowed();
       
    75 private:
       
    76     CAknGlobalPopupPriorityController();
       
    77     ~CAknGlobalPopupPriorityController();
       
    78     void ConstructL();
       
    79 
       
    80     TInt PopupPriority(CCoeControl* aPopup) const;
       
    81     TBool AddToStack(CCoeControl* aPopup);
       
    82     TBool RemoveFromStack(CCoeControl* aPopup);
       
    83     void SetWindowGroupPriority();
       
    84     void SetPopupWindowPositions(CCoeControl* aPopup, TInt aWindowPos);
       
    85     void SetPopupChainKeyPositionsL(CCoeControl* aPopup);
       
    86     void SetPopupKeyPositionsL(CCoeControl* aPopup);
       
    87     CCoeControl* RootPopup(CCoeControl* aTip) const;
       
    88     CCoeControl* TopPopup() const;
       
    89     TBool PopupIsShown(CCoeControl* aPopup) const;
       
    90     void DoFadeBehindPopup(CCoeControl* aPopup);
       
    91     TInt MinChainWindowPosition(CCoeControl* aPopup) const;
       
    92 
       
    93 private:
       
    94     struct TPopupInfo
       
    95         {
       
    96     public:
       
    97         TPopupInfo();
       
    98 
       
    99     public:
       
   100         TInt iPopupPriority;
       
   101         TInt iControlStackPriority;
       
   102         TInt iControlStackFlags;
       
   103         CCoeControl* iSubPopup;     // not owned
       
   104         CCoeControl* iParent;       // not owned
       
   105         MAknFadedComponent* iFadedComponent;    // not owned
       
   106         };
       
   107 
       
   108 private:
       
   109     TPopupInfo* PopupInfo(CCoeControl* aPopup);
       
   110     const TPopupInfo* PopupInfo(CCoeControl* aPopup) const;
       
   111     TPopupInfo& PopupInfoL(CCoeControl* aPopup);
       
   112 
       
   113 private:
       
   114     RHashMap<CCoeControl*, TPopupInfo> iPopupInfoMap;
       
   115     // The stack of currently shown popups (the CCoeControls are not owned)
       
   116     RArray<CCoeControl*> iShownStack;
       
   117     TBool iGlobalPopupsAllowed;
       
   118     TInt iOrdinalPosition;
       
   119     CEikAppUi* iAppUi;  // not owned
       
   120     };
       
   121 
       
   122 
       
   123 CAknGlobalPopupPriorityController::TPopupInfo::TPopupInfo()
       
   124 : iPopupPriority(0), iControlStackPriority(KErrNotFound), iControlStackFlags(0), iSubPopup(NULL), iParent(NULL), iFadedComponent(NULL)
       
   125     {
       
   126     }
       
   127 
       
   128 
       
   129 void CAknGlobalPopupPriorityController::CreateInstanceL()
       
   130     {
       
   131     if (!CAknGlobalPopupPriorityController::Instance())
       
   132         {
       
   133         CAknGlobalPopupPriorityController* self = new(ELeave) CAknGlobalPopupPriorityController(); // CCoeEnv takes ownership immediately
       
   134         self->ConstructL();
       
   135         }
       
   136     }
       
   137 
       
   138 CAknGlobalPopupPriorityController* CAknGlobalPopupPriorityController::Instance()
       
   139     {
       
   140     return static_cast<CAknGlobalPopupPriorityController*>(CCoeEnv::Static(KAknGlobalPopupPriorityControllerStaticId));
       
   141     }
       
   142 
       
   143 void CAknGlobalPopupPriorityController::AllowGlobalPopups(TBool aAllow)
       
   144     {
       
   145     iGlobalPopupsAllowed = aAllow;
       
   146     SetWindowGroupPriority();
       
   147     CCoeControl* top = TopPopup();
       
   148     if (top)
       
   149         {
       
   150         TRAP_IGNORE(SetPopupChainKeyPositionsL(top));
       
   151         DoFadeBehindPopup(top);
       
   152         }
       
   153     }
       
   154 
       
   155 TBool CAknGlobalPopupPriorityController::GlobalPopupsAllowed()
       
   156     {
       
   157     return iGlobalPopupsAllowed;
       
   158     }
       
   159 
       
   160 void CAknGlobalPopupPriorityController::SetPopupPriorityL(CCoeControl* aPopup, TInt aPriority)
       
   161     {
       
   162     PopupInfoL(aPopup).iPopupPriority = aPriority;
       
   163 
       
   164     // Update the active popup stack
       
   165     if (PopupIsShown(aPopup))
       
   166         {
       
   167         ShowPopup(aPopup, ETrue);
       
   168         }
       
   169     }
       
   170 
       
   171 void CAknGlobalPopupPriorityController::RemovePopup(CCoeControl* aPopup)
       
   172     {
       
   173     // Update the active popup stack
       
   174     if (PopupIsShown(aPopup))
       
   175         {
       
   176         ShowPopup(aPopup, EFalse);
       
   177         }
       
   178 
       
   179     // Remove sub-popup from parent
       
   180     TPopupInfo* info = PopupInfo(aPopup);
       
   181     if (info && info->iParent)
       
   182         {
       
   183         TPopupInfo* pInfo = PopupInfo(info->iParent);
       
   184         if (pInfo)
       
   185             pInfo->iSubPopup = NULL;
       
   186         }
       
   187 
       
   188     // Remove the popup and sub popups from the map
       
   189     CCoeControl* popup = aPopup;
       
   190     while (popup)
       
   191         {
       
   192         CCoeControl* next = NULL;
       
   193         TPopupInfo* info = PopupInfo(popup);
       
   194         if (info)
       
   195             next = info->iSubPopup;
       
   196         iPopupInfoMap.Remove(popup);
       
   197         popup = next;
       
   198         }
       
   199     }
       
   200 
       
   201 TInt CAknGlobalPopupPriorityController::PopupPriority(CCoeControl* aPopup) const
       
   202     {
       
   203     const TPopupInfo* info = PopupInfo(aPopup);
       
   204     return info ? info->iPopupPriority : 0;
       
   205     }
       
   206 
       
   207 void CAknGlobalPopupPriorityController::ShowPopup(CCoeControl* aPopup, TBool aShow)
       
   208     {
       
   209     // update the stack
       
   210     CCoeControl* oldTop = TopPopup();
       
   211     if (aShow)
       
   212         {
       
   213         AddToStack(aPopup);
       
   214         TRAP_IGNORE(SetPopupChainKeyPositionsL(aPopup));
       
   215         }
       
   216     else
       
   217         {
       
   218         RemoveFromStack(aPopup);
       
   219         }
       
   220     DoFadeBehindPopup(aPopup);
       
   221     CCoeControl* newTop = TopPopup();
       
   222 
       
   223     // update the top popup
       
   224     if (oldTop != newTop)
       
   225         {
       
   226         // set window group priority
       
   227         SetWindowGroupPriority();
       
   228 
       
   229         // an existing popup is now top
       
   230         if (newTop != aPopup)
       
   231             {
       
   232             TRAP_IGNORE(SetPopupChainKeyPositionsL(newTop));
       
   233             DoFadeBehindPopup(newTop);
       
   234             }
       
   235         }
       
   236     }
       
   237 
       
   238 void CAknGlobalPopupPriorityController::SetRootWinOrdinalPosition(TInt aOrdinalPosition)
       
   239     {
       
   240     iOrdinalPosition = aOrdinalPosition;
       
   241     }
       
   242 
       
   243 void CAknGlobalPopupPriorityController::SetWindowGroupPriority()
       
   244     {
       
   245     TInt newPriority;
       
   246     if (iShownStack.Count() > 0 && iGlobalPopupsAllowed)
       
   247         {
       
   248         CCoeControl* topPopup = iShownStack[0];
       
   249         TInt priority = PopupPriority(topPopup);
       
   250         newPriority = ECoeWinPriorityAlwaysAtFront + priority;
       
   251         }
       
   252     else
       
   253         {
       
   254         newPriority = ECoeWinPriorityNeverAtFront;
       
   255         }
       
   256     CEikonEnv::Static()->RootWin().SetOrdinalPosition(iOrdinalPosition, newPriority);
       
   257     }
       
   258 
       
   259 TBool CAknGlobalPopupPriorityController::AddToStack(CCoeControl* aPopup)
       
   260     {
       
   261     // remove it from the stack if already there
       
   262     TInt priorPos = iShownStack.Find(aPopup);
       
   263     if (priorPos != KErrNotFound)
       
   264         {
       
   265         iShownStack.Remove(priorPos);
       
   266         }
       
   267 
       
   268     // stack size is limited, do not add new items if it would cause overflow
       
   269     TInt count = iShownStack.Count();
       
   270     if (count >= KAknGlobalPopupPriorityControllerMaxStack)
       
   271         {
       
   272         return EFalse;
       
   273         }
       
   274 
       
   275     // insert it at correct position in the stack
       
   276     // also calculate min and max window z-order position
       
   277     TInt priority = PopupPriority(aPopup);
       
   278     TInt insertPos = -1;
       
   279     TInt minWindowPosition = 0;
       
   280     TInt maxWindowPosition = KMaxTInt;
       
   281     for (TInt ii=0; ii<count; ii++)
       
   282         {
       
   283         CCoeControl* stacked = iShownStack[ii];
       
   284         TInt shownPriority = PopupPriority(stacked);
       
   285         if (priority >= shownPriority)
       
   286             {
       
   287             maxWindowPosition = MinChainWindowPosition(stacked);
       
   288             iShownStack.Insert(aPopup, ii); // will not fail because overflow is already checked
       
   289             insertPos = ii;
       
   290             break;
       
   291             }
       
   292         minWindowPosition = stacked->DrawableWindow()->OrdinalPosition();
       
   293         }
       
   294     if (insertPos == -1)
       
   295         {
       
   296         insertPos = count;
       
   297         iShownStack.Append(aPopup); // will not fail because overflow is already checked
       
   298         }
       
   299 
       
   300     // set popup window z-order position, if necessary
       
   301     // it should be behind any higher priority popup and infront
       
   302     // of any lower priority popup
       
   303     TInt popupWindowPosition = aPopup->DrawableWindow()->OrdinalPosition();
       
   304     if (popupWindowPosition < minWindowPosition)
       
   305         popupWindowPosition = minWindowPosition+1;
       
   306     else if (popupWindowPosition > maxWindowPosition)
       
   307         popupWindowPosition = maxWindowPosition;
       
   308     SetPopupWindowPositions(aPopup, popupWindowPosition);
       
   309 
       
   310     // return true (top changed) if top item was moved or added
       
   311     return priorPos == 0 || insertPos == 0;
       
   312     }
       
   313 
       
   314 void CAknGlobalPopupPriorityController::SetPopupWindowPositions(
       
   315         CCoeControl* aPopup, TInt aWindowPos)
       
   316     {
       
   317     TBool isSub = EFalse;
       
   318     while (aPopup)
       
   319         {
       
   320         TInt currentPos = aPopup->DrawableWindow()->OrdinalPosition();
       
   321         if (isSub && currentPos < aWindowPos)
       
   322             {
       
   323             // adjust one forward, so that we don't go behind the parent window
       
   324             aWindowPos--;
       
   325             }
       
   326 
       
   327         aPopup->DrawableWindow()->SetOrdinalPosition(aWindowPos);
       
   328         const TPopupInfo* info = PopupInfo(aPopup);
       
   329         if (info)
       
   330             {
       
   331             aPopup = info->iSubPopup;
       
   332             }
       
   333         else
       
   334             {
       
   335             aPopup = NULL;
       
   336             }
       
   337         isSub = ETrue;
       
   338         }
       
   339     }
       
   340 
       
   341 void CAknGlobalPopupPriorityController::SetPopupChainKeyPositionsL(CCoeControl* aPopup)
       
   342     {
       
   343     bool top = aPopup == TopPopup();
       
   344     while (aPopup)
       
   345         {
       
   346         const TPopupInfo* info = PopupInfo(aPopup);
       
   347         CCoeControl* next = NULL;
       
   348         if (info && info->iControlStackPriority != KErrNotFound)
       
   349             {
       
   350             next = info->iSubPopup;
       
   351             iAppUi->RemoveFromStack(aPopup);
       
   352             TInt flags = top ? info->iControlStackFlags : KControlStackSleepFlags;
       
   353             iAppUi->AddToStackL(aPopup, info->iControlStackPriority, flags);
       
   354             }
       
   355         aPopup = next;
       
   356         }
       
   357     }
       
   358 
       
   359 void CAknGlobalPopupPriorityController::SetPopupKeyPositionsL(CCoeControl* aPopup)
       
   360     {
       
   361     bool top = RootPopup(aPopup) == TopPopup();
       
   362     const TPopupInfo* info = PopupInfo(aPopup);
       
   363     if (info && info->iControlStackPriority != KErrNotFound)
       
   364         {
       
   365         iAppUi->RemoveFromStack(aPopup);
       
   366         TInt flags = top ? info->iControlStackFlags : KControlStackSleepFlags;
       
   367         iAppUi->AddToStackL(aPopup, info->iControlStackPriority, flags);
       
   368         }
       
   369     }
       
   370 
       
   371 TBool CAknGlobalPopupPriorityController::RemoveFromStack(CCoeControl* aPopup)
       
   372     {
       
   373     // only if it's already in the stack
       
   374     TInt pos = iShownStack.Find(aPopup);
       
   375     if (pos == KErrNotFound)
       
   376         {
       
   377         return EFalse;
       
   378         }
       
   379     else
       
   380         {
       
   381         iShownStack.Remove(pos);
       
   382         return pos == 0;
       
   383         }
       
   384     }
       
   385 
       
   386 CAknGlobalPopupPriorityController::CAknGlobalPopupPriorityController()
       
   387 : CCoeStatic(KAknGlobalPopupPriorityControllerStaticId),
       
   388   iPopupInfoMap(THashFunction32<CCoeControl*>(&GeneralPtrHash), TIdentityRelation<CCoeControl*>(&GeneralPtrIdentity)),
       
   389   iGlobalPopupsAllowed(EFalse),
       
   390   iAppUi(CEikonEnv::Static()->EikAppUi())
       
   391     {
       
   392     }
       
   393 
       
   394 CAknGlobalPopupPriorityController::~CAknGlobalPopupPriorityController()
       
   395     {
       
   396     iPopupInfoMap.Close();
       
   397     iShownStack.Close();
       
   398     }
       
   399 
       
   400 void CAknGlobalPopupPriorityController::ConstructL()
       
   401     {
       
   402     iShownStack.Reserve(KAknGlobalPopupPriorityControllerMaxStack);
       
   403     }
       
   404 
       
   405 CAknGlobalPopupPriorityController::TPopupInfo* CAknGlobalPopupPriorityController::PopupInfo(CCoeControl* aPopup)
       
   406     {
       
   407     TPopupInfo* info = iPopupInfoMap.Find(aPopup);
       
   408     return info;
       
   409     }
       
   410 
       
   411 const CAknGlobalPopupPriorityController::TPopupInfo* CAknGlobalPopupPriorityController::PopupInfo(CCoeControl* aPopup) const
       
   412     {
       
   413     const TPopupInfo* info = iPopupInfoMap.Find(aPopup);
       
   414     return info;
       
   415     }
       
   416 
       
   417 CAknGlobalPopupPriorityController::TPopupInfo& CAknGlobalPopupPriorityController::PopupInfoL(CCoeControl* aPopup)
       
   418     {
       
   419     TPopupInfo* info = PopupInfo(aPopup);
       
   420     if (info)
       
   421         return *info;
       
   422     iPopupInfoMap.InsertL(aPopup, TPopupInfo());
       
   423     return *PopupInfo(aPopup);
       
   424     }
       
   425 
       
   426 void CAknGlobalPopupPriorityController::AddSubPopupL(CCoeControl* aPopup, CCoeControl* aSubPopup)
       
   427     {
       
   428     // Below 3 rows of calling PopupInfoL() look like a little uncomfortable,
       
   429     // because PopupInfoL will add new element in its hash map. 
       
   430     // So, a new element may be inserted when calling PopupInfoL(aSubPopup).
       
   431     // It may will lead to the change of aPopup address returned from the first calling PopupInfoL(aPopup).
       
   432     // So, we need to get the parent reference again.
       
   433     PopupInfoL(aPopup);
       
   434     TPopupInfo& sub = PopupInfoL(aSubPopup);
       
   435     TPopupInfo& parent = PopupInfoL(aPopup);
       
   436     
       
   437     __ASSERT_DEBUG(parent.iSubPopup == NULL || parent.iSubPopup == aSubPopup, GppcPanic(EGppcPanic_DontSupportMultipleSubPopups));
       
   438     __ASSERT_DEBUG(sub.iParent == NULL || sub.iParent == aPopup, GppcPanic(EGppcPanic_DontSupportMultipleParents));
       
   439     parent.iSubPopup = aSubPopup;
       
   440     sub.iParent = aPopup;
       
   441     // put it at the same window position as its parent
       
   442     aSubPopup->DrawableWindow()->SetOrdinalPosition(aPopup->DrawableWindow()->OrdinalPosition());
       
   443     }
       
   444 
       
   445 
       
   446 void CAknGlobalPopupPriorityController::AddPopupToControlStackL(CCoeControl* aPopup,TInt aPriority,TInt aStackingFlags)
       
   447     {
       
   448     TPopupInfo& info = PopupInfoL(aPopup);
       
   449     info.iControlStackPriority = aPriority;
       
   450     info.iControlStackFlags = aStackingFlags;
       
   451     SetPopupKeyPositionsL(aPopup);
       
   452     }
       
   453 
       
   454 CCoeControl* CAknGlobalPopupPriorityController::RootPopup(CCoeControl* aTip) const
       
   455     {
       
   456     const TPopupInfo* info;
       
   457     info = PopupInfo(aTip);
       
   458     while (info && info->iParent)
       
   459         {
       
   460         aTip = info->iParent;
       
   461         info = PopupInfo(aTip);
       
   462         }
       
   463 
       
   464 
       
   465     return aTip;
       
   466     }
       
   467 
       
   468 CCoeControl* CAknGlobalPopupPriorityController::TopPopup() const
       
   469     {
       
   470     if (iShownStack.Count() > 0 && iGlobalPopupsAllowed)
       
   471         return iShownStack[0];
       
   472     else
       
   473         return NULL;
       
   474     }
       
   475 
       
   476 TBool CAknGlobalPopupPriorityController::PopupIsShown(CCoeControl* aPopup) const
       
   477     {
       
   478     TInt pos = iShownStack.Find(aPopup);
       
   479     return pos != KErrNotFound;
       
   480     }
       
   481 
       
   482 void CAknGlobalPopupPriorityController::FadeBehindPopupL(CCoeControl* aPopup, MAknFadedComponent* aFadedComponent)
       
   483     {
       
   484     TPopupInfo& info = PopupInfoL(aPopup);
       
   485     info.iFadedComponent = aFadedComponent;
       
   486     DoFadeBehindPopup(aPopup);
       
   487     }
       
   488 
       
   489 void CAknGlobalPopupPriorityController::DoFadeBehindPopup(CCoeControl* aPopup)
       
   490     {
       
   491     TBool top = aPopup == TopPopup();
       
   492     TPopupInfo* info = PopupInfo(aPopup);
       
   493     if (!info || !info->iFadedComponent)
       
   494         return;
       
   495     TAknPopupFader fader;
       
   496     fader.FadeBehindPopup(info->iFadedComponent, aPopup, top);
       
   497     }
       
   498 
       
   499 void CAknGlobalPopupPriorityController::RouseSleepingPopup(CCoeControl* aPopup, TBool aRoused)
       
   500     {
       
   501     TInt pri = ECoeStackPriorityDialog;
       
   502     TInt flags = 0;
       
   503     TPopupInfo* info = PopupInfo(aPopup);
       
   504     if (info)
       
   505         {
       
   506         pri = info->iControlStackPriority;
       
   507         flags = info->iControlStackFlags;
       
   508         }
       
   509     if (aRoused)
       
   510         flags = flags & ~KControlStackSleepFlags;
       
   511     else
       
   512         flags = flags | KControlStackSleepFlags;
       
   513     TRAP_IGNORE(AddPopupToControlStackL(aPopup, pri, flags));
       
   514     }
       
   515 
       
   516 TInt CAknGlobalPopupPriorityController::MinChainWindowPosition(CCoeControl* aPopup) const
       
   517     {
       
   518     TInt pos = aPopup->DrawableWindow()->OrdinalPosition();
       
   519     const TPopupInfo* info = PopupInfo(aPopup);
       
   520     while (info && info->iSubPopup)
       
   521         {
       
   522         aPopup = info->iSubPopup;
       
   523         pos = Min(pos, aPopup->DrawableWindow()->OrdinalPosition());
       
   524         info = PopupInfo(aPopup);
       
   525         }
       
   526     return pos;
       
   527     }
       
   528 
       
   529 
       
   530 EXPORT_C void AknGlobalPopupPriorityController::EnablePriorityControlL()
       
   531     {
       
   532     CAknGlobalPopupPriorityController::CreateInstanceL();
       
   533     }
       
   534 
       
   535 EXPORT_C void AknGlobalPopupPriorityController::AllowGlobalPopups(TBool aAllow)
       
   536     {
       
   537     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   538     if (instance)
       
   539         instance->AllowGlobalPopups(aAllow);
       
   540     }
       
   541 
       
   542 EXPORT_C TBool AknGlobalPopupPriorityController::GlobalPopupsAllowed()
       
   543     {
       
   544     TBool globalPopupsAllowed = ETrue;
       
   545     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   546     if (instance)
       
   547         globalPopupsAllowed = instance->GlobalPopupsAllowed();
       
   548     return globalPopupsAllowed;
       
   549     }
       
   550 
       
   551 EXPORT_C void AknGlobalPopupPriorityController::SetPopupPriorityL(CCoeControl& aPopup, TInt aPriority)
       
   552     {
       
   553     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   554     if (instance)
       
   555         instance->SetPopupPriorityL(&aPopup, aPriority);
       
   556     }
       
   557 
       
   558 EXPORT_C void AknGlobalPopupPriorityController::RemovePopupPriority(CCoeControl& aPopup)
       
   559     {
       
   560     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   561     if (instance)
       
   562         instance->RemovePopup(&aPopup);
       
   563     }
       
   564 
       
   565 EXPORT_C void AknGlobalPopupPriorityController::ShowPopup(CCoeControl& aPopup, TBool aShow)
       
   566     {
       
   567     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   568     if (instance)
       
   569         instance->ShowPopup(&aPopup, aShow);
       
   570     }
       
   571 
       
   572 EXPORT_C void AknGlobalPopupPriorityController::SetRootWinOrdinalPosition(TInt aOrdinalPosition)
       
   573     {
       
   574     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   575     if (instance)
       
   576         instance->SetRootWinOrdinalPosition(aOrdinalPosition);
       
   577     }
       
   578 
       
   579 EXPORT_C void AknGlobalPopupPriorityController::AddSubPopupL(CCoeControl& aPopup, CCoeControl& aSubPopup)
       
   580     {
       
   581     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   582     if (instance)
       
   583         instance->AddSubPopupL(&aPopup, &aSubPopup);
       
   584     }
       
   585 
       
   586 EXPORT_C void AknGlobalPopupPriorityController::AddPopupToControlStackL(CCoeControl& aPopup,TInt aPriority,TInt aStackingFlags)
       
   587     {
       
   588     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   589     if (instance)
       
   590         instance->AddPopupToControlStackL(&aPopup, aPriority, aStackingFlags);
       
   591     else
       
   592         {
       
   593         CEikAppUi* appUi = CEikonEnv::Static()->EikAppUi();
       
   594         if (appUi)
       
   595             {
       
   596             appUi->RemoveFromStack(&aPopup);
       
   597             appUi->AddToStackL(&aPopup, aPriority, aStackingFlags);
       
   598             }
       
   599         }
       
   600     }
       
   601 
       
   602 EXPORT_C void AknGlobalPopupPriorityController::RouseSleepingPopup(CCoeControl& aPopup, TBool aRoused)
       
   603     {
       
   604     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   605     if (instance)
       
   606         instance->RouseSleepingPopup(&aPopup, aRoused);
       
   607     else
       
   608         CEikonEnv::Static()->RouseSleepingDialog(&aPopup, aRoused);
       
   609     }
       
   610 
       
   611 EXPORT_C void AknGlobalPopupPriorityController::FadeBehindPopup(CCoeControl& aPopup, TAknPopupFader& aFader, MAknFadedComponent& aFadedComponent, TBool aFade)
       
   612     {
       
   613     CAknGlobalPopupPriorityController* instance = CAknGlobalPopupPriorityController::Instance();
       
   614     if (instance)
       
   615         {
       
   616         TRAP_IGNORE(instance->FadeBehindPopupL(&aPopup, &aFadedComponent));
       
   617         }
       
   618     else
       
   619         {
       
   620         aFader.FadeBehindPopup(&aFadedComponent, &aPopup, aFade);
       
   621         }
       
   622     }