uifw/AvKon/src/akndialog.cpp
changeset 0 2f259fa3e83a
child 8 71dd06cfe933
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 // AknDialog.cpp
       
    19 //
       
    20 // Copyright (c) 2001 Symbian Ltd.  All rights reserved.
       
    21 //
       
    22 
       
    23 #include <AknDialog.h>
       
    24 #include <eikmenub.h>
       
    25 #include <eikenv.h>
       
    26 #include <aknappui.h>
       
    27 #include "aknenv.h"
       
    28 #include <eikcapc.h>
       
    29 #include <eikdialogext.h>
       
    30 #include <avkon.hrh>
       
    31 #include <avkon.rsg>
       
    32 #include <aknsoundsystem.h>
       
    33 #include "aknitemactionmenuregister.h"
       
    34 
       
    35 #include <AknsDrawUtils.h>
       
    36 #include <AknsFrameBackgroundControlContext.h>
       
    37 #include "AknUtils.h"
       
    38 
       
    39 #include <skinlayout.cdl.h>
       
    40 using namespace SkinLayout;
       
    41 
       
    42 
       
    43 
       
    44 class CAknDialogAttributes: public CBase
       
    45 	{
       
    46 public:
       
    47 	~CAknDialogAttributes()
       
    48 		{
       
    49 		delete iBgContext;
       
    50 		delete iBrushAndPenContext;
       
    51 		}
       
    52 public: // data
       
    53 	TInt iAknDialogFlags;
       
    54 	CAknsFrameBackgroundControlContext* iBgContext;	
       
    55     CCoeBrushAndPenContext* iBrushAndPenContext;
       
    56 	TRect iOuterRect;
       
    57 	TRect iInnerRect;
       
    58 	TBool iNeedsUpdate;
       
    59 	};
       
    60 
       
    61 /**
       
    62  * Constructor 
       
    63  */
       
    64 EXPORT_C CAknDialog::CAknDialog() 
       
    65 	{
       
    66 	}
       
    67 
       
    68 
       
    69 /**
       
    70  * Creates a menu using a menu resource.
       
    71  * A menu resource MUST be specified - this function will Panic otherwise.  If a menu is not required use CEikDialog!
       
    72  */
       
    73 EXPORT_C void CAknDialog::ConstructL(TInt aMenuTitleResourceId)
       
    74 	{
       
    75     if ( !iAttributes ) 
       
    76         {
       
    77 		AttributesL();        
       
    78 		}
       
    79 	
       
    80 	CreateMenuBarL(aMenuTitleResourceId);
       
    81 	
       
    82 	iAttributes->iAknDialogFlags &= ~EAknDialogFlagNotConstructed;
       
    83 	}
       
    84 
       
    85 /**
       
    86  *
       
    87  */
       
    88 EXPORT_C CAknDialog::~CAknDialog() 
       
    89 	{
       
    90     AknItemActionMenuRegister::SetConstructingMenuBarOwnerL( NULL );
       
    91 
       
    92     if ( iCoeEnv->AppUi() && iAttributes )
       
    93 		if (iAttributes->iAknDialogFlags&EAknDialogFlagDefaultSounds) // return original sound stack
       
    94 			{
       
    95 			iAvkonAppUiBase->KeySounds()->PopContext();
       
    96 			}
       
    97 
       
    98 	if (iMenuBar) 
       
    99 		{
       
   100 		if ( iAttributes )
       
   101 			{
       
   102 			iAttributes->iAknDialogFlags |= EAknDialogFlagDialogDeleted;
       
   103 			}
       
   104 		HideMenu();
       
   105 		iEikonEnv->EikAppUi()->RemoveFromStack(iMenuBar);
       
   106 		delete iMenuBar;
       
   107 		}
       
   108 	delete iAttributes;
       
   109 	}
       
   110 
       
   111 EXPORT_C void CAknDialog::PrepareLC(TInt aResourceId)
       
   112 	{ 
       
   113 	if (!iMenuBar)
       
   114 		{
       
   115 		// PrepareLC has to keep ownership of "this".
       
   116 		CleanupStack::PushL(this);	
       
   117 		CreateMenuBarL(R_AVKON_DIALOG_EMPTY_MENUBAR); // empty menu bar
       
   118 		CleanupStack::Pop(this);
       
   119 		}
       
   120 	CEikDialog::PrepareLC(aResourceId);
       
   121 	}
       
   122 
       
   123 EXPORT_C TInt CAknDialog::RunLD()
       
   124 	{
       
   125 	return CEikDialog::RunLD();
       
   126 	}
       
   127 
       
   128 /**
       
   129  * Swap the Application menu with the Form's menu before displaying
       
   130  *
       
   131  */
       
   132 EXPORT_C TInt CAknDialog::ExecuteLD(TInt aResourceId) 
       
   133 	{
       
   134     if ( iCoeEnv->AppUi() ) // Enable default tones while dialog / form is on screen
       
   135         {
       
   136         CleanupStack::PushL(this);
       
   137 		if (!iAttributes)
       
   138 			{
       
   139 			AttributesL();
       
   140 			iAttributes->iAknDialogFlags |= EAknDialogFlagNotConstructed; // Way to indicate to SetEmphasis that other members are  not accessible
       
   141 			}
       
   142 
       
   143         iAvkonAppUiBase->KeySounds()->PushContextL(R_AVKON_DEFAULT_SKEY_LIST);
       
   144         iAttributes->iAknDialogFlags |= EAknDialogFlagDefaultSounds;
       
   145         CleanupStack::Pop();
       
   146         }
       
   147 
       
   148 	return ( CEikDialog::ExecuteLD(aResourceId) );	
       
   149     }
       
   150 
       
   151 /**
       
   152  *From MEikMenuObserver
       
   153  * (called when menu is cancelled)
       
   154  * Called also from destructor ( EAknDialogFlagDialogDeleted is set)
       
   155  */
       
   156 EXPORT_C void CAknDialog::SetEmphasis(CCoeControl* aMenuControl,TBool aEmphasis)
       
   157 	{
       
   158 	if (!iAttributes 
       
   159 		|| iAttributes->iAknDialogFlags & EAknDialogFlagNotConstructed
       
   160 		|| iAttributes->iAknDialogFlags & EAknDialogFlagDialogDeleted)
       
   161 		return;
       
   162 
       
   163 	CEikAppUi* appUi = iEikonEnv->EikAppUi();
       
   164 	appUi->RemoveFromStack(aMenuControl);
       
   165     // Remove focus from aMenuControl because AppUi's RemoveFromStack won't do
       
   166     // that.
       
   167     aMenuControl->SetFocus( EFalse );
       
   168 	TRAP_IGNORE(appUi->AddToStackL(aMenuControl, aEmphasis ? ECoeStackPriorityDialog : ECoeStackPriorityMenu));
       
   169 	appUi->UpdateStackedControlFlags(this, aEmphasis ? ECoeStackFlagRefusesFocus : 0, ECoeStackFlagRefusesFocus);
       
   170 	appUi->UpdateStackedControlFlags(aMenuControl, aEmphasis ? 0 : ECoeStackFlagRefusesFocus, ECoeStackFlagRefusesFocus);
       
   171 	appUi->HandleStackChanged();
       
   172 	}
       
   173 
       
   174 /**
       
   175  * This function intialiases the items on the menu.  It's used to disable and enable menu items and may be
       
   176  * over ridden to add new ones.
       
   177  * NOTE that it might be called with the 'wrong' ResourceId so it must do a check and not assume.
       
   178  *
       
   179  */
       
   180 EXPORT_C void CAknDialog::DynInitMenuPaneL(TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/) 
       
   181 	{
       
   182 	}
       
   183 
       
   184 /**
       
   185  *From MEikCommandObserver
       
   186  */
       
   187 EXPORT_C void CAknDialog::ProcessCommandL(TInt /* aCommandId */)
       
   188 	{
       
   189 	HideMenu();
       
   190 	}
       
   191 
       
   192 
       
   193 /**
       
   194  * From CCoeControl
       
   195  *
       
   196  * If MMC is supported always process user input (MMC PIN requester does not seem
       
   197  * to have focus when it pops up)
       
   198  */
       
   199 EXPORT_C TKeyResponse CAknDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) 
       
   200 	{
       
   201 	if (IsFocused() ||
       
   202 		(aType == EEventKey && aKeyEvent.iCode == EKeyEscape)
       
   203 		)
       
   204 		return (CEikDialog::OfferKeyEventL(aKeyEvent, aType));
       
   205 	else
       
   206 		return EKeyWasNotConsumed;
       
   207 	}
       
   208 
       
   209 
       
   210 
       
   211 /**
       
   212  *
       
   213  * From CEikDialog - If there is an Options key then pops up menu, otherwise exits.  Override this if necessary.
       
   214  */
       
   215 EXPORT_C TBool CAknDialog::OkToExitL(TInt aButtonId) 
       
   216 	{
       
   217 	TBool retVal;
       
   218 
       
   219 	if (iMenuBar)
       
   220 		HideMenu();
       
   221 	
       
   222 	if (aButtonId == EAknSoftkeyOptions)
       
   223 		{
       
   224 		DisplayMenuL();
       
   225 		retVal = EFalse;
       
   226 		}
       
   227 	else 
       
   228 		{
       
   229 		retVal = ETrue;
       
   230 		}
       
   231 
       
   232 	if (aButtonId == EAknSoftkeyMark || aButtonId == EAknSoftkeyUnmark)
       
   233 		{
       
   234 		retVal = EFalse;
       
   235 		}
       
   236 
       
   237 	return retVal;
       
   238 	}
       
   239 
       
   240 
       
   241 /**
       
   242  * 
       
   243  */
       
   244 EXPORT_C void CAknDialog::DisplayMenuL() 
       
   245 	{
       
   246 	iMenuBar->TryDisplayMenuBarL();
       
   247 	}
       
   248 
       
   249 /**
       
   250  * 
       
   251  */
       
   252 EXPORT_C void CAknDialog::HideMenu() 
       
   253 	{
       
   254 	iMenuBar->StopDisplayingMenuBar();
       
   255 	}
       
   256 
       
   257 EXPORT_C void CAknDialog::FocusChanged(TDrawNow aDrawNow)
       
   258 	{
       
   259 	if (!iAttributes || iAttributes->iAknDialogFlags & EAknDialogFlagDialogDeleted)
       
   260 		return;
       
   261 	TInt controlID = IdOfFocusControl();
       
   262 	if (controlID)
       
   263 		Line(controlID)->SetFocus(IsFocused(), aDrawNow);			
       
   264 	}
       
   265 
       
   266 /**
       
   267  * 
       
   268  */
       
   269 EXPORT_C TBool CAknDialog::MenuShowing() const
       
   270 	{
       
   271 	return iMenuBar->IsDisplayed();
       
   272 	}
       
   273 
       
   274 
       
   275 EXPORT_C void CAknDialog::Reserved_MtsmPosition()
       
   276 	{
       
   277 	}
       
   278 
       
   279 EXPORT_C void CAknDialog::Reserved_MtsmObject()
       
   280 	{
       
   281 	}
       
   282 
       
   283 EXPORT_C void CAknDialog::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   284     {
       
   285     CEikDialog::HandlePointerEventL(aPointerEvent);
       
   286     }   
       
   287 
       
   288 EXPORT_C void* CAknDialog::ExtensionInterface( TUid /*aInterface*/ ) 
       
   289     { 
       
   290     return NULL;
       
   291     }
       
   292 
       
   293 void CAknDialog::CreateMenuBarL(TInt aMenuTitleResourceId)
       
   294 	{
       
   295 	if (iMenuBar)
       
   296 		{
       
   297 		// just replace the content if it doesn't already exist
       
   298 		iMenuBar->TitleArray()->ResetAndDestroy();
       
   299 		iMenuBar->SetMenuTitleResourceId(aMenuTitleResourceId);
       
   300 		}
       
   301 	else
       
   302 		{
       
   303 		CEikMenuBar* newMenuBar = new (ELeave) CEikMenuBar();
       
   304 		CleanupStack::PushL(newMenuBar);
       
   305 		newMenuBar->ConstructL(this, NULL, aMenuTitleResourceId);
       
   306 		iEikonEnv->EikAppUi()->AddToStackL(newMenuBar,ECoeStackPriorityMenu,ECoeStackFlagRefusesFocus);
       
   307 		iMenuBar=newMenuBar;
       
   308 		CleanupStack::Pop(); // now owned by this Dialog.
       
   309 		}
       
   310 
       
   311     AknItemActionMenuRegister::SetConstructingMenuBarOwnerL( this );
       
   312 	}
       
   313 
       
   314 //
       
   315 // UpdateBgContext is done here because we dont want to create huge icons 
       
   316 // always when dialog is launched. The icon is anyway used only when
       
   317 // queries are used, so deferring its creation to MopSupplyObject;
       
   318 // this saves considerable amount of time and memory for non-popup
       
   319 // dialogs. SetFrameRects renders the qsn_fr_popup, so deferring that call.
       
   320 //
       
   321 static void UpdateBgContext(CAknDialogAttributes &aAttrs)
       
   322 	{
       
   323 	if (aAttrs.iNeedsUpdate)
       
   324 		{
       
   325 		TRect outerRect = aAttrs.iOuterRect;
       
   326 		TRect innerRect = aAttrs.iInnerRect;
       
   327 		aAttrs.iBgContext->SetFrameRects( outerRect, innerRect );
       
   328 		aAttrs.iNeedsUpdate = EFalse;
       
   329 		}
       
   330 	}
       
   331 
       
   332 EXPORT_C TTypeUid::Ptr CAknDialog::MopSupplyObject(TTypeUid aId)
       
   333 	{	
       
   334 	// Must test on the type of dialog before supplying an object
       
   335 	if ( Extension() ) { 
       
   336 	    if ( aId.iUid == MAknsControlContext::ETypeId && 
       
   337 		    Extension()->LayoutCategory() == CEikDialogExtension::EPopupLayout )
       
   338 			    {
       
   339 		    if (!iAttributes)
       
   340 			    {
       
   341 			    TRAPD( err, AttributesL() );
       
   342 			    if ( err )
       
   343 				    {
       
   344 				    delete iAttributes;
       
   345 				    iAttributes = 0;
       
   346 				    return CEikDialog::MopSupplyObject(aId);
       
   347 				    }
       
   348 			    else
       
   349 				    {
       
   350 				    iAttributes->iAknDialogFlags |= EAknDialogFlagNotConstructed; // Way to indicate to SetEmphasis that other members are  not accessible
       
   351 				    }
       
   352 			    }
       
   353 			UpdateBgContext(*iAttributes);
       
   354 		    return MAknsControlContext::SupplyMopObject(aId, iAttributes->iBgContext );
       
   355 		    }
       
   356         }
       
   357 	if (aId.iUid == CEikMenuBar::ETypeId)
       
   358 		return aId.MakePtr(iMenuBar);
       
   359 	else
       
   360 		return CEikDialog::MopSupplyObject(aId);
       
   361 	}
       
   362 
       
   363 EXPORT_C void CAknDialog::Draw(const TRect& aRect) const
       
   364 	{
       
   365 
       
   366 		CEikDialog::Draw(aRect); // Frame drawing done in eikdialog
       
   367 	}
       
   368 	
       
   369 EXPORT_C void CAknDialog::SizeChanged()
       
   370 	{
       
   371 	if (iAttributes)
       
   372 		{
       
   373 		TRect windowRect = Rect();
       
   374 	
       
   375 		TAknLayoutRect topLeft;
       
   376         topLeft.LayoutRect(windowRect, Popup_windows_skin_placing__frame_general__Line_2());
       
   377 
       
   378 		TAknLayoutRect bottomRight;
       
   379         bottomRight.LayoutRect(windowRect, Popup_windows_skin_placing__frame_general__Line_5());
       
   380 
       
   381 		TRect outerRect = TRect(topLeft.Rect().iTl, bottomRight.Rect().iBr);
       
   382 		TRect innerRect = TRect(topLeft.Rect().iBr, bottomRight.Rect().iTl);
       
   383 
       
   384 		iAttributes->iOuterRect = outerRect;
       
   385 		iAttributes->iInnerRect = innerRect;
       
   386 		iAttributes->iNeedsUpdate = ETrue;
       
   387 		iAttributes->iBgContext->SetParentPos( PositionRelativeToScreen() );
       
   388 		}
       
   389 	CEikDialog::SizeChanged();
       
   390 	}
       
   391 
       
   392 EXPORT_C void CAknDialog::CEikDialog_Reserved_1()
       
   393 	{
       
   394 	}
       
   395 	
       
   396 EXPORT_C void CAknDialog::CEikDialog_Reserved_2()
       
   397 	{
       
   398 	}
       
   399 
       
   400 EXPORT_C void CAknDialog::CAknDialog_Reserved()
       
   401 	{
       
   402 	}
       
   403 
       
   404 CAknDialogAttributes* CAknDialog::AttributesL()
       
   405 	{
       
   406 	if ( !iAttributes )
       
   407 		{
       
   408 		iAttributes = new (ELeave) CAknDialogAttributes();
       
   409         
       
   410 		TRect windowRect = Rect();
       
   411 	
       
   412 		TAknLayoutRect topLeft;
       
   413         topLeft.LayoutRect(windowRect, Popup_windows_skin_placing__frame_general__Line_2());
       
   414 
       
   415 		TAknLayoutRect bottomRight;
       
   416 		bottomRight.LayoutRect(windowRect, ELayoutEmpty, 169, ELayoutEmpty, ELayoutEmpty, 2, 7,7);
       
   417         bottomRight.LayoutRect(windowRect, Popup_windows_skin_placing__frame_general__Line_5());
       
   418 
       
   419         TRect outerRect = TRect(topLeft.Rect().iTl, bottomRight.Rect().iBr);
       
   420 		TRect innerRect = TRect(topLeft.Rect().iBr, bottomRight.Rect().iTl);
       
   421 
       
   422 		iAttributes->iBgContext = CAknsFrameBackgroundControlContext::NewL(
       
   423 				KAknsIIDQsnFrPopup, outerRect, innerRect, ETrue );
       
   424 
       
   425 
       
   426 		if ( &Window() )
       
   427 			iAttributes->iBgContext->SetParentPos( PositionRelativeToScreen() );
       
   428 		}
       
   429 	
       
   430 	return iAttributes; 
       
   431 	}
       
   432 
       
   433 // end of CAknDialog