phonebookui/Phonebook/PbkUI/src/CPbkAppViewBase.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 *       Provides Phonebook Application view methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <CPbkAppViewBase.h>     // This class' declaration
       
    22 
       
    23 #include "CPbkDocumentBase.h"
       
    24 #include <CPbkAppUiBase.h>
       
    25 #include <CPbkAiwInterestArray.h>
       
    26 #include <CPbkAppGlobalsbase.h>
       
    27 
       
    28 #include <akntitle.h>			// CAknTitlePane
       
    29 #include <akncontext.h>			// CAknContextPane
       
    30 #include <eikmenub.h>			// CEikMenuBar
       
    31 #include <eikapp.h>				// CEikApplication
       
    32 
       
    33 
       
    34 // MACROS
       
    35 #undef TEST_CPbkAppViewBase  // define this to turn testing on for this class
       
    36 
       
    37 
       
    38 // ENUMERATIONS
       
    39 
       
    40 /**
       
    41  * Testing mode bit flags for class CPbkAppViewBase.
       
    42  */
       
    43 enum
       
    44     {
       
    45     /// Alloc test CPbkAppViewBase::ProcessCommandL(TInt).
       
    46     ETestModeAllocFailureProcessCommandL = 1
       
    47     };
       
    48 
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 
       
    52 EXPORT_C CPbkAppViewBase::CPbkAppViewBase()
       
    53     {
       
    54     }
       
    55 
       
    56 EXPORT_C CPbkAppViewBase::~CPbkAppViewBase()
       
    57     {
       
    58     ClosePopup();
       
    59     }
       
    60 
       
    61 EXPORT_C TUid CPbkAppViewBase::ApplicationUid() const
       
    62     {
       
    63     return AppUi()->Application()->AppDllUid();
       
    64     }
       
    65 
       
    66 EXPORT_C CPbkAppUiBase* CPbkAppViewBase::PbkAppUi() const
       
    67     {
       
    68     // Explicit cast: the app ui must always be of type CPbkAppUiBase
       
    69     return static_cast<CPbkAppUiBase*>(CAknView::AppUi());
       
    70     }
       
    71 
       
    72 EXPORT_C CPbkContactEngine* CPbkAppViewBase::Engine() const
       
    73     {
       
    74     return PbkAppUi()->PbkDocument()->Engine();
       
    75     }
       
    76 
       
    77 EXPORT_C CAknTitlePane* CPbkAppViewBase::TitlePane() const
       
    78     {
       
    79     return static_cast<CAknTitlePane*>
       
    80 		(GetStatusPaneControlSafely(EEikStatusPaneUidTitle));
       
    81     }
       
    82 
       
    83 EXPORT_C CAknContextPane* CPbkAppViewBase::ContextPane() const
       
    84     {
       
    85     return static_cast<CAknContextPane*>
       
    86 		(GetStatusPaneControlSafely(EEikStatusPaneUidContext));
       
    87     }
       
    88 
       
    89 EXPORT_C TBool CPbkAppViewBase::HandleCommandKeyL
       
    90         (const TKeyEvent& /*aKeyEvent*/, 
       
    91         TEventCode /*aType*/)
       
    92     {
       
    93     return EFalse;
       
    94     }
       
    95 
       
    96 EXPORT_C CPbkViewState* CPbkAppViewBase::GetViewStateLC() const
       
    97     {
       
    98     return NULL;
       
    99     }
       
   100 
       
   101 
       
   102 EXPORT_C void CPbkAppViewBase::LaunchPopupMenuL
       
   103         (TInt aResourceId)
       
   104     {
       
   105     ClosePopup();
       
   106     iPopup=new(ELeave) CEikMenuBar;
       
   107     TRAPD(err,DoLaunchPopupL(aResourceId));
       
   108     if (err)
       
   109         {
       
   110         ClosePopup();
       
   111         User::Leave(err);
       
   112         }
       
   113     }
       
   114 
       
   115 EXPORT_C void CPbkAppViewBase::HandleCommandL
       
   116         (TInt aCommand)
       
   117     {
       
   118     // No command handling in this class, just forward to app ui.
       
   119     AppUi()->HandleCommandL(aCommand);
       
   120     }
       
   121 
       
   122 EXPORT_C void CPbkAppViewBase::DynInitMenuPaneL
       
   123         (TInt aResourceId,
       
   124         CEikMenuPane* aMenuPane)
       
   125     {
       
   126     // No menu updating in this class, just forward to app ui.
       
   127     AppUi()->DynInitMenuPaneL(aResourceId, aMenuPane);
       
   128     }
       
   129 
       
   130 EXPORT_C void CPbkAppViewBase::ProcessCommandL
       
   131         (TInt aCommand)
       
   132     {
       
   133     // Close popup menu if open
       
   134     if (iPopup)
       
   135         {
       
   136         iPopup->StopDisplayingMenuBar();
       
   137 	    ClosePopup();
       
   138         }
       
   139 
       
   140 #ifdef TEST_CPbkAppViewBase
       
   141     if (iTestMode & ETestModeAllocFailureProcessCommandL)
       
   142         {
       
   143         switch (aCommand)
       
   144             {
       
   145             // Don't run the test for these commands
       
   146             case EEikCmdExit:				// FALLTHROUGH
       
   147             case EAknCmdExit:				// FALLTHROUGH
       
   148             case EAknSoftkeyOptions:		// FALLTHROUGH
       
   149 				{
       
   150                 break;
       
   151 				}
       
   152 
       
   153             default:
       
   154                 {
       
   155                 // Testing is one-shot -> turn it off
       
   156                 iTestMode &= ~(ETestModeAllocFailureProcessCommandL);
       
   157                 // Run ProcessCommandL in an alloc test loop
       
   158                 TInt error = KErrNone;
       
   159                 TInt allocFail = 0;
       
   160                 do
       
   161                     {
       
   162                     User::__DbgSetAllocFail(RHeap::EUser, RHeap::EDeterministic, ++allocFail);
       
   163                     TRAP(error, CAknView::ProcessCommandL(aCommand));
       
   164                     User::__DbgSetAllocFail(RHeap::EUser,RHeap::ENone,1);
       
   165                     }
       
   166                 while (error == KErrNoMemory);
       
   167                 if (error == KErrNone)
       
   168                     {
       
   169                     RDebug::Print(_L("CPbkAppViewBase::ProcessCommandL(%d) executed after %d alloc failures."), 
       
   170                         aCommand, allocFail);
       
   171                     }
       
   172                 else
       
   173                     {
       
   174                     // Some other leave than out of memory occured
       
   175                     User::Leave(error);
       
   176                     }
       
   177                 return;
       
   178                 }
       
   179             }
       
   180         }
       
   181 #endif // TEST_CPbkAppViewBase
       
   182 
       
   183     // Call base class
       
   184     CAknView::ProcessCommandL(aCommand);
       
   185     }
       
   186 
       
   187 EXPORT_C TBool CPbkAppViewBase::PbkProcessKeyEventL
       
   188         (const TKeyEvent& aKeyEvent, 
       
   189         TEventCode aType)
       
   190     {
       
   191 #ifdef TEST_CPbkAppViewBase
       
   192     // Check for special debugging keys
       
   193     if (aKeyEvent.iCode=='m' && (aKeyEvent.iModifiers & EModifierFunc))
       
   194         {
       
   195         // Turn alloc testing on for the next command
       
   196         iTestMode |= ETestModeAllocFailureProcessCommandL;
       
   197         RDebug::Print(_L("CPbkAppViewBase::PbkProcessKeyEventL(): Alloc failure testing turned on"));
       
   198         iEikonEnv->InfoMsg(_L("Alloc failure testing ON"));
       
   199         return ETrue;
       
   200         }
       
   201 #endif // TEST_CPbkAppViewBase
       
   202 
       
   203     // Offer key first to self. Derived class may override HandleCommandKeyL
       
   204     if (HandleCommandKeyL(aKeyEvent, aType))
       
   205         {
       
   206         return ETrue;
       
   207         }
       
   208     else
       
   209         {
       
   210         // Key event is not handled by me, offer it to the default handler.
       
   211         return PbkAppUi()->PbkProcessKeyEventL(aKeyEvent, aType);
       
   212         }
       
   213     }
       
   214 
       
   215 void CPbkAppViewBase::DoLaunchPopupL
       
   216         (TInt aResourceId)
       
   217     {
       
   218     iPopup->ConstructL(this, 0, aResourceId);
       
   219     AppUi()->AddToViewStackL(*this, iPopup, ECoeStackPriorityMenu, ECoeStackFlagRefusesFocus);
       
   220     iPopup->TryDisplayMenuBarL();
       
   221     }
       
   222 
       
   223 /**
       
   224  * Returns status pane control if present.
       
   225  * @param aCtrlId   id of the status pane control.
       
   226  * @return  control with aPaneId if present in status pane, 
       
   227             NULL otherwise.
       
   228  */
       
   229 CCoeControl* CPbkAppViewBase::GetStatusPaneControlSafely
       
   230         (TInt aPaneId) const
       
   231     {
       
   232     const TUid paneUid = { aPaneId };
       
   233     CEikStatusPane* statusPane = StatusPane();
       
   234     if (statusPane && statusPane->PaneCapabilities(paneUid).IsPresent())
       
   235         {
       
   236 		CCoeControl* control = NULL;
       
   237         // ControlL shouldn't leave because the pane is present
       
   238 		TRAPD(err, control = statusPane->ControlL(paneUid));
       
   239 		if (err != KErrNone)
       
   240 			{
       
   241 			return NULL;
       
   242 			}
       
   243 		else
       
   244 			{
       
   245 			return control;
       
   246 			}
       
   247         }
       
   248     return NULL;
       
   249     }
       
   250 
       
   251 /**
       
   252  * Removes the popup from the view stack and deletes it.
       
   253  */
       
   254 void CPbkAppViewBase::ClosePopup()
       
   255     {
       
   256     if (iPopup)
       
   257 		{
       
   258 		AppUi()->RemoveFromViewStack(*this, iPopup);
       
   259 		delete(iPopup);
       
   260 		iPopup=NULL;
       
   261 		}
       
   262     }
       
   263 
       
   264 EXPORT_C void CPbkAppViewBase::CreateInterestItemAndAttachL(
       
   265         TInt aInterestId,
       
   266         TInt aMenuResourceId,
       
   267         TInt aInterestResourceId,
       
   268         TBool aAttachBaseServiceInterest)
       
   269     {
       
   270     if (!iAiwInterestArray)
       
   271         {
       
   272         iAiwInterestArray =
       
   273             CPbkAppGlobalsBase::InstanceL()->AiwInterestArrayL(*Engine());
       
   274         }
       
   275 
       
   276     // Delegate to the interest array
       
   277     iAiwInterestArray->CreateInterestItemAndAttachL(
       
   278         aInterestId, aMenuResourceId,
       
   279         aInterestResourceId, aAttachBaseServiceInterest);
       
   280     }
       
   281 
       
   282 //  End of File