phonebookui/Phonebook2/CommonUI/src/CPbk2AppViewBase.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Phonebook 2 application view base.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <CPbk2AppViewBase.h>
       
    21 
       
    22 // Phonebook 2
       
    23 #include <CPbk2AppUiBase.h>
       
    24 #include <CPbk2DocumentBase.h>
       
    25 #include <MPbk2KeyEventHandler.h>
       
    26 #include <MPbk2ApplicationServices.h>
       
    27 
       
    28 // System includes
       
    29 #include <eikmenub.h>
       
    30 #include <eikapp.h>
       
    31 #include <barsread.h>
       
    32 #include <AknUtils.h>
       
    33 #include <aknViewAppUi.h>
       
    34 #include <aknstyluspopupmenu.h>
       
    35 
       
    36 // --------------------------------------------------------------------------
       
    37 // CPbk2AppViewBase::CPbk2AppViewBase
       
    38 // --------------------------------------------------------------------------
       
    39 //
       
    40 EXPORT_C CPbk2AppViewBase::CPbk2AppViewBase()
       
    41     {
       
    42     }
       
    43 
       
    44 // --------------------------------------------------------------------------
       
    45 // CPbk2AppViewBase::~CPbk2AppViewBase
       
    46 // --------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C CPbk2AppViewBase::~CPbk2AppViewBase()
       
    49     {
       
    50     ClosePopup();
       
    51     CloseStylusPopup();
       
    52     }
       
    53 
       
    54 // --------------------------------------------------------------------------
       
    55 // CPbk2AppViewBase::ApplicationUid
       
    56 // --------------------------------------------------------------------------
       
    57 //
       
    58 EXPORT_C TUid CPbk2AppViewBase::ApplicationUid() const
       
    59     {
       
    60     return AppUi()->Application()->AppDllUid();
       
    61     }
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CPbk2AppViewBase::ViewStateLC
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CPbk2ViewState* CPbk2AppViewBase::ViewStateLC() const
       
    68     {
       
    69     // Default implementation
       
    70     CPbk2ViewState* state = NULL;
       
    71     CleanupStack::PushL(state);
       
    72     return state;
       
    73     }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CPbk2AppViewBase::LaunchPopupMenuL
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C void CPbk2AppViewBase::LaunchPopupMenuL( TInt aResourceId )
       
    80     {
       
    81     // In future we should study if the whole menubar thingy could be
       
    82     // removed and use context menu instead since its already used
       
    83     // anyway
       
    84     
       
    85     // these are used to check if our popup or context menu is open
       
    86     TBool isPopupVisible=EFalse;
       
    87     TBool isContextVisible=MenuBar()->IsDisplayed();
       
    88     
       
    89     if (iPopup)
       
    90         {
       
    91         // check if popup is already there
       
    92         isPopupVisible=iPopup->IsDisplayed();
       
    93         // popup and context menu shouldn't be visible 
       
    94         if ((!isPopupVisible) && (!isContextVisible))
       
    95             {
       
    96             // destroy exisiting
       
    97             ClosePopup();
       
    98             // and show new popup
       
    99             CreatePopupMenuL(aResourceId);
       
   100             }
       
   101         }
       
   102     // we don't have popup
       
   103     else
       
   104         {
       
   105         // and context menu is not shown
       
   106         if (!isContextVisible)
       
   107             {
       
   108             CreatePopupMenuL(aResourceId);
       
   109             }
       
   110         }
       
   111     
       
   112     }
       
   113 
       
   114 // --------------------------------------------------------------------------
       
   115 // CPbk2AppViewBase::CreatePopupMenuL
       
   116 // --------------------------------------------------------------------------
       
   117 //
       
   118 void CPbk2AppViewBase::CreatePopupMenuL( TInt aResourceId )
       
   119     {
       
   120     iPopup = new(ELeave) CEikMenuBar;
       
   121     TRAPD(err, DoLaunchPopupL(aResourceId));
       
   122     if (err)
       
   123         {
       
   124         ClosePopup();
       
   125         User::Leave(err);
       
   126         }
       
   127     }
       
   128 
       
   129 
       
   130 
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // CPbk2AppViewBase::GetMenuFilteringFlagsL
       
   134 // --------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C TInt CPbk2AppViewBase::GetMenuFilteringFlagsL() const
       
   137     {
       
   138     MPbk2AppUi* appUi = Phonebook2::Pbk2AppUi();
       
   139 
       
   140     return ( GetViewSpecificMenuFilteringFlagsL() |
       
   141              appUi->ApplicationServices().
       
   142                 GlobalMenuFilteringFlagsL() );
       
   143     }
       
   144 
       
   145 // --------------------------------------------------------------------------
       
   146 // CPbk2AppViewBase::HandleCommandKeyL
       
   147 // --------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C TBool CPbk2AppViewBase::HandleCommandKeyL
       
   150         ( const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/ )
       
   151     {    
       
   152     return EFalse;
       
   153 	}
       
   154 
       
   155 // --------------------------------------------------------------------------
       
   156 // CPbk2AppViewBase::HandlePointerEventL
       
   157 // --------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C void CPbk2AppViewBase::HandlePointerEventL
       
   160         ( const TPointerEvent& /*aPointerEvent*/ )
       
   161     {
       
   162     // Do nothing by default
       
   163     }
       
   164 
       
   165 // --------------------------------------------------------------------------
       
   166 // CPbk2AppViewBase::HandleLongTapEventL
       
   167 // --------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C void CPbk2AppViewBase::HandleLongTapEventL(
       
   170         const TPoint& /*aPenEventLocation*/,
       
   171         const TPoint& /*aPenEventScreenLocation*/)
       
   172     {
       
   173     // Do nothing by default
       
   174     }
       
   175 
       
   176 // --------------------------------------------------------------------------
       
   177 // CPbk2AppViewBase::ProcessCommandL
       
   178 // --------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C void CPbk2AppViewBase::ProcessCommandL( TInt aCommand )
       
   181     {
       
   182     // Close popup menu if open
       
   183     ClosePopup();
       
   184 
       
   185     // Call base class
       
   186     CAknView::ProcessCommandL( aCommand );
       
   187     }
       
   188 
       
   189 // --------------------------------------------------------------------------
       
   190 // CPbk2AppViewBase::Pbk2ProcessKeyEventL
       
   191 // --------------------------------------------------------------------------
       
   192 //
       
   193 EXPORT_C TBool CPbk2AppViewBase::Pbk2ProcessKeyEventL
       
   194         ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   195     {    
       
   196     // If a menu is displayed, handle the send key event 
       
   197     // by letting the framework handle it; In practice the 
       
   198     // dailler is launched
       
   199     if (MenuBar()->MenuPane() && MenuBar()->IsDisplayed())
       
   200         {
       
   201         if ( (aType == EEventKey || aType == EEventKeyUp 
       
   202           || aType == EEventKeyDown ) && aKeyEvent.iScanCode == EStdKeyYes )
       
   203             {
       
   204             // Key event is not handled by me, offer it to the default handler
       
   205             return Phonebook2::Pbk2AppUi()->KeyEventHandler().
       
   206                 Pbk2ProcessKeyEventL( aKeyEvent, aType );
       
   207             }
       
   208         }	
       
   209 	
       
   210 	// Offer key first to self. Derived class may override HandleCommandKeyL.
       
   211     if ( HandleCommandKeyL( aKeyEvent, aType ) )
       
   212         {
       
   213         return ETrue;
       
   214         }
       
   215     else
       
   216         {
       
   217         // Ignore Send Key up and down events to prevent Dialer appearance or
       
   218 		// any other application from launhing on top of or behind the Phonebook application.
       
   219 		if ( ( aType == EEventKeyDown || aType == EEventKeyUp )
       
   220                 && aKeyEvent.iScanCode == EStdKeyYes )
       
   221                 {
       
   222                 return ETrue;
       
   223                 }
       
   224         else
       
   225             {
       
   226             // Key event is not handled by me, offer it to the default handler
       
   227             return Phonebook2::Pbk2AppUi()->KeyEventHandler().
       
   228                 Pbk2ProcessKeyEventL( aKeyEvent, aType );
       
   229             }        
       
   230         }    
       
   231     }
       
   232 
       
   233 // --------------------------------------------------------------------------
       
   234 // CPbk2AppViewBase::Pbk2ProcessPointerEventL
       
   235 // --------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CPbk2AppViewBase::Pbk2ProcessPointerEventL
       
   238         ( const TPointerEvent& aPointerEvent )
       
   239     {
       
   240     HandlePointerEventL( aPointerEvent );
       
   241     }
       
   242 
       
   243 // --------------------------------------------------------------------------
       
   244 // CPbk2AppViewBase::Pbk2HandleLongTapEventL
       
   245 // --------------------------------------------------------------------------
       
   246 //
       
   247 EXPORT_C void CPbk2AppViewBase::Pbk2HandleLongTapEventL(
       
   248         const TPoint& aPenEventLocation,
       
   249         const TPoint& aPenEventScreenLocation )
       
   250     {
       
   251     HandleLongTapEventL( aPenEventLocation, aPenEventScreenLocation );
       
   252     }
       
   253 
       
   254 // --------------------------------------------------------------------------
       
   255 // CPbk2AppViewBase::DoLaunchPopupL
       
   256 // --------------------------------------------------------------------------
       
   257 //
       
   258 void CPbk2AppViewBase::DoLaunchPopupL(TInt aResourceId)
       
   259     {
       
   260     iPopup->ConstructL(this, 0, aResourceId);
       
   261     iPopup->SetMenuType( CEikMenuBar::EMenuContext );
       
   262     AppUi()->AddToViewStackL(*this, iPopup,
       
   263         ECoeStackPriorityMenu, ECoeStackFlagRefusesFocus);
       
   264     iPopup->TryDisplayMenuBarL();
       
   265     }
       
   266 
       
   267 // --------------------------------------------------------------------------
       
   268 // CPbk2AppViewBase::ClosePopup
       
   269 // Removes the popup from the view stack and deletes it.
       
   270 // --------------------------------------------------------------------------
       
   271 //
       
   272 EXPORT_C void CPbk2AppViewBase::ClosePopup()
       
   273     {
       
   274     if ( iPopup && iPopup->MenuPane() )
       
   275         {
       
   276         iPopup->StopDisplayingMenuBar();
       
   277         AppUi()->RemoveFromViewStack(*this, iPopup);
       
   278         delete(iPopup);
       
   279         iPopup=NULL;
       
   280         }
       
   281     }
       
   282 
       
   283 // --------------------------------------------------------------------------
       
   284 // CPbk2AppViewBase::LaunchStylusPopupMenuL
       
   285 // --------------------------------------------------------------------------
       
   286 //
       
   287 EXPORT_C void CPbk2AppViewBase::LaunchStylusPopupMenuL(
       
   288         TInt aResourceId,
       
   289         const TPoint& aPoint )
       
   290     {
       
   291     CloseStylusPopup();
       
   292     TRAPD( err, DoLaunchStylusPopupL( aResourceId, aPoint ) );
       
   293     if ( err )
       
   294         {
       
   295         CloseStylusPopup();
       
   296         User::Leave( err );
       
   297         }
       
   298     }
       
   299 
       
   300 // --------------------------------------------------------------------------
       
   301 // CPbk2AppViewBase::LaunchStylusPopupMenuL
       
   302 // --------------------------------------------------------------------------
       
   303 //
       
   304 EXPORT_C CAknStylusPopUpMenu& CPbk2AppViewBase::LaunchStylusPopupMenu2L(
       
   305         TInt aResourceId,
       
   306         const TPoint& aPoint )
       
   307     {
       
   308     LaunchStylusPopupMenuL( aResourceId, aPoint );
       
   309     return *iStylusPopup;
       
   310     }
       
   311 
       
   312 // --------------------------------------------------------------------------
       
   313 // CPbk2AppViewBase::DoLaunchStylusPopupL
       
   314 // --------------------------------------------------------------------------
       
   315 //
       
   316 void CPbk2AppViewBase::DoLaunchStylusPopupL
       
   317         ( TInt aResourceId, const TPoint& aPoint )
       
   318     {
       
   319     iStylusPopup = CAknStylusPopUpMenu::NewL( this, aPoint, NULL );
       
   320     TResourceReader reader;
       
   321     iCoeEnv->CreateResourceReaderLC( reader, aResourceId );
       
   322     iStylusPopup->ConstructFromResourceL( reader );
       
   323     CleanupStack::PopAndDestroy(); // reader
       
   324 
       
   325     iStylusPopup->SetPosition( aPoint );
       
   326     
       
   327     if(IsForeground())
       
   328         {
       
   329         iStylusPopup->ShowMenu();
       
   330         }
       
   331     }
       
   332 
       
   333 // --------------------------------------------------------------------------
       
   334 // CPbk2AppViewBase::CloseStylusPopup
       
   335 // --------------------------------------------------------------------------
       
   336 //
       
   337 void CPbk2AppViewBase::CloseStylusPopup()
       
   338     {
       
   339     if ( iStylusPopup )
       
   340         {
       
   341         delete iStylusPopup;
       
   342         iStylusPopup = NULL;
       
   343         }
       
   344     }
       
   345 
       
   346 //  End of File