uifw/AvKon/src/aknpopupfader.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 // AknPopupFader.cpp
       
    19 //
       
    20 // Copyright (c) 1997-2001 Symbian Ltd.  All rights reserved.
       
    21 //
       
    22 
       
    23 #include "AknPopupFader.h"
       
    24 
       
    25 #include <coecntrl.h>
       
    26 #include <eikdef.h>
       
    27 #include <coemain.h>
       
    28 #include <eikon.hrh>
       
    29 #include <eikenv.h>
       
    30 #include <aknappui.h>
       
    31 #include <w32std.h>
       
    32 #include <eikdialg.h>
       
    33 #include <AknSgcc.h>
       
    34 
       
    35 const TUid KUidFadeStackTls = {0x101f760b};
       
    36 const TInt KFadeStackGranularity = 4;
       
    37 
       
    38 EXPORT_C TInt MAknFadedComponent::CountFadedComponents()
       
    39 	{
       
    40 	return 0;
       
    41 	}
       
    42 
       
    43 EXPORT_C CCoeControl* MAknFadedComponent::FadedComponent(TInt /*aIndex*/)
       
    44 	{
       
    45 	return NULL;
       
    46 	}
       
    47 
       
    48 
       
    49 NONSHARABLE_CLASS(CAknFadeStack) : public CCoeStatic, public MCoeForegroundObserver
       
    50 	{
       
    51 public:
       
    52     enum TStackPosition
       
    53         {
       
    54         EStackTop = 0,
       
    55         EStackNextToTop
       
    56         };
       
    57 public:
       
    58 	static void CreateL();
       
    59 	static CAknFadeStack* Static();
       
    60 
       
    61 	void PushPopupFaderL(MAknFadedComponent* aPopup);
       
    62 	void PopPopupFader(MAknFadedComponent* aPopup);
       
    63 
       
    64 private:
       
    65 	CAknFadeStack();
       
    66 	~CAknFadeStack();
       
    67 	void ConstructL();
       
    68 	void SetComponentFaded(MAknFadedComponent* aPopup, TBool aFade);
       
    69 	MAknFadedComponent* PopupFader(TStackPosition aPosition) const;
       
    70     TBool IsFullscreenDialog(MAknFadedComponent* aPopup);
       
    71 	void SetFade();
       
    72 	void RemovePopupFader(MAknFadedComponent* aPopup);
       
    73     void SetSystemFadeOff();
       
    74     
       
    75 private: // from MCoeForegroundObserver
       
    76 	void HandleGainingForeground();
       
    77 	void HandleLosingForeground();
       
    78 
       
    79 private:
       
    80 	CArrayFixFlat<MAknFadedComponent*>* iFadeStack;
       
    81 	TBool iIsForeground;
       
    82 	CCoeEnv* iCoeEnv;
       
    83 	TBool iSystemFaded;
       
    84 	};
       
    85 
       
    86 CAknFadeStack::CAknFadeStack()
       
    87 : CCoeStatic(KUidFadeStackTls), iCoeEnv(CCoeEnv::Static())
       
    88 	{
       
    89 	    iSystemFaded = EFalse;
       
    90 	}
       
    91 
       
    92 CAknFadeStack::~CAknFadeStack()
       
    93 	{
       
    94 	iCoeEnv->RemoveForegroundObserver(*this);
       
    95 	delete iFadeStack;
       
    96 	}
       
    97 
       
    98 void CAknFadeStack::ConstructL()
       
    99 	{
       
   100 	iFadeStack = new(ELeave) CArrayFixFlat<MAknFadedComponent*>(KFadeStackGranularity);
       
   101 	iCoeEnv->AddForegroundObserverL(*this);
       
   102 	}
       
   103 
       
   104 CAknFadeStack* CAknFadeStack::Static()
       
   105 	{
       
   106 	return static_cast<CAknFadeStack*>(CCoeEnv::Static(KUidFadeStackTls));
       
   107 	}
       
   108 
       
   109 void CAknFadeStack::CreateL()
       
   110 	{ // static
       
   111 	CAknFadeStack* self=CAknFadeStack::Static();
       
   112 	if (!self)
       
   113 		{
       
   114 		self=new(ELeave) CAknFadeStack(); // CCoeEnv takes ownership immediately
       
   115 		CleanupStack::PushL(self);
       
   116 		self->ConstructL();
       
   117 		CleanupStack::Pop();
       
   118 		}
       
   119 	}
       
   120 
       
   121 void CAknFadeStack::HandleGainingForeground()
       
   122 	{
       
   123 	iIsForeground = ETrue;
       
   124 	SetFade();
       
   125 	}
       
   126 
       
   127 void CAknFadeStack::HandleLosingForeground()
       
   128 	{
       
   129 	iIsForeground = EFalse;
       
   130 	iSystemFaded = EFalse;
       
   131     SetFade();
       
   132 	}
       
   133 
       
   134 void CAknFadeStack::PushPopupFaderL(MAknFadedComponent* aPopup)
       
   135 	{
       
   136 	RemovePopupFader(aPopup);
       
   137 	iFadeStack->AppendL(aPopup);
       
   138 	SetFade();
       
   139 	}
       
   140 
       
   141 void CAknFadeStack::PopPopupFader(MAknFadedComponent* aPopup)
       
   142 	{
       
   143 	RemovePopupFader(aPopup);
       
   144 	SetFade();
       
   145 	}
       
   146 
       
   147 void CAknFadeStack::RemovePopupFader(MAknFadedComponent* aPopup)
       
   148 	{
       
   149 	TInt end = iFadeStack->Count() - 1;
       
   150 	for (TInt ii=end; ii>=0; ii--)
       
   151 		{
       
   152 		if (iFadeStack->At(ii) == aPopup)
       
   153 			iFadeStack->Delete(ii);
       
   154 		}
       
   155 	}
       
   156 
       
   157 void CAknFadeStack::SetSystemFadeOff()
       
   158     {
       
   159     if ( iSystemFaded || CAknSgcClient::IsSystemFaded() )
       
   160         {
       
   161         CAknAppUi* appUi = iAvkonAppUi;
       
   162         TRAP_IGNORE( appUi->SetFadedL(EFalse) );
       
   163         iSystemFaded = EFalse;
       
   164         }
       
   165     }
       
   166 
       
   167 void CAknFadeStack::SetComponentFaded(MAknFadedComponent* aPopup, TBool aFade)
       
   168 	{
       
   169 	TInt count = aPopup->CountFadedComponents();
       
   170 	for (TInt ii=0; ii<count; ii++)
       
   171 		{
       
   172 		CCoeControl* control = aPopup->FadedComponent(ii);
       
   173 		//fix for TSW error EHLN-7HHFPX
       
   174 		if ( control != NULL )
       
   175 		    {
       
   176 		    control->DrawableWindow()->SetFaded(aFade, RWindowTreeNode::EFadeIncludeChildren);    
       
   177 		    }
       
   178 		}
       
   179 	}
       
   180 
       
   181 TBool CAknFadeStack::IsFullscreenDialog(MAknFadedComponent* aPopup)
       
   182 {
       
   183 	TInt count = aPopup->CountFadedComponents();
       
   184 	for (TInt ii=0; ii<count; ii++)
       
   185 		{
       
   186 		CCoeControl* control = aPopup->FadedComponent(ii);
       
   187 	    CEikDialog* dialg = NULL;
       
   188 	    //fix for TSW error EHLN-7HHFPX
       
   189 	    if ( control != NULL )
       
   190 	        {
       
   191 	        dialg = control->MopGetObjectNoChaining(dialg);
       
   192 	        if(dialg != NULL)
       
   193 	            {
       
   194 	            // is a dialog, get flags
       
   195 	            TInt flags = dialg->DialogFlags();
       
   196 	            if ((flags&EEikDialogFlagFillAppClientRect) || (flags&EEikDialogFlagFillScreen) || (flags&EEikDialogFlagNoBackgroundFade) )
       
   197 	                {
       
   198 	                return ETrue;
       
   199 	                }
       
   200 	            }    
       
   201 	        }
       
   202 		}
       
   203     return EFalse;
       
   204 }
       
   205 
       
   206 MAknFadedComponent* CAknFadeStack::PopupFader(TStackPosition aPosition) const
       
   207     {
       
   208     TInt count = iFadeStack->Count();
       
   209     return count > aPosition ? iFadeStack->At(count-1-aPosition) : NULL;
       
   210     }
       
   211 
       
   212 void CAknFadeStack::SetFade()
       
   213 	{
       
   214 	MAknFadedComponent* top = PopupFader(EStackTop);
       
   215 	CAknAppUi* appUi = iAvkonAppUi;
       
   216 
       
   217 	if (iIsForeground || appUi->IsForeground())
       
   218 		{
       
   219 		if(top) 
       
   220 		    {
       
   221 		    if(!IsFullscreenDialog(top))
       
   222 		        {
       
   223     		    if(!iSystemFaded)
       
   224 	    	        {
       
   225     		        TRAP_IGNORE( appUi->SetFadedL(ETrue) );
       
   226 	    	        iSystemFaded = ETrue;
       
   227 		            }
       
   228 		        else
       
   229     		        {
       
   230     		        // If a popup comes on top of another, system fade is not
       
   231     		        // called but the previous top popup is faded
       
   232     		        MAknFadedComponent* prevTop = PopupFader(EStackNextToTop);
       
   233                     if (prevTop)
       
   234                         {
       
   235                         SetComponentFaded(prevTop, ETrue);
       
   236                         }
       
   237 	    	        }
       
   238     			SetComponentFaded(top, EFalse);
       
   239 		        }
       
   240 		    else
       
   241 		        {
       
   242                 // Remove fading for fullscreen dialogs		            
       
   243                 SetSystemFadeOff();                		            
       
   244 	    	    }
       
   245 		    }
       
   246 		else
       
   247 		    {
       
   248             SetSystemFadeOff();
       
   249 		    }
       
   250 		}
       
   251 	else if (top)
       
   252 		{
       
   253 		SetComponentFaded(top, appUi->IsFaded());
       
   254 		}
       
   255 	}
       
   256 
       
   257 
       
   258 EXPORT_C void TAknPopupFader::FadeBehindPopup(MAknFadedComponent* aComponent,  CCoeControl* aParent, TBool aFade)
       
   259 	{
       
   260 	TRAP_IGNORE(FadeBehindPopupL(aComponent, aParent, aFade));
       
   261 	}
       
   262 
       
   263 void TAknPopupFader::FadeBehindPopupL(MAknFadedComponent* aComponent,  CCoeControl* /*aParent*/, TBool aFade)
       
   264 	{
       
   265 	CAknFadeStack* stack=CAknFadeStack::Static();
       
   266 	if (stack)
       
   267 		{
       
   268 		if (aFade)
       
   269 			{
       
   270 			stack->PushPopupFaderL(aComponent);
       
   271 			}
       
   272 		else
       
   273 			{
       
   274 			stack->PopPopupFader(aComponent);
       
   275 			}
       
   276 		}
       
   277 	}
       
   278 
       
   279 void TAknPopupFader::CreateStaticL()
       
   280 	{
       
   281 	CAknFadeStack::CreateL();
       
   282 	}
       
   283 
       
   284 // End of File