uifw/EikStd/coctlsrc/aknitemactionmenu.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2009 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: Item action menu.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <aknappui.h>
       
    19 #include <akncollection.h>
       
    20 #include <aknitemactionmenu.h>
       
    21 #include <aknlistquerydialog.h>
       
    22 #include <aknstyluspopupmenu.h>
       
    23 #include <AknTasHook.h>
       
    24 #include <avkon.rsg>
       
    25 #include <eikmenub.h>
       
    26 #include <eikpanic.h>
       
    27 
       
    28 #include "akncollectionobserver.h"
       
    29 #include "aknitemactionmenudata.h"
       
    30 #include "aknitemactionmenuregister.h"
       
    31 
       
    32 /**
       
    33  * Index for invalid list index.
       
    34  */
       
    35 const TInt KInvalidListIndex( -1 );
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CAknItemActionMenu::NewL
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CAknItemActionMenu* CAknItemActionMenu::NewL(
       
    42         MAknCollection& aCollection )
       
    43     {
       
    44     CAknItemActionMenu* self = CAknItemActionMenu::NewLC( aCollection );
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CAknItemActionMenu::NewLC
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CAknItemActionMenu* CAknItemActionMenu::NewLC( MAknCollection& aCollection )
       
    55     {
       
    56     CAknItemActionMenu* self = new ( ELeave ) CAknItemActionMenu();
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aCollection );
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CAknItemActionMenu::~CAknItemActionMenu
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CAknItemActionMenu::~CAknItemActionMenu()
       
    68     {
       
    69     AKNTASHOOK_REMOVE();
       
    70     delete iPopupMenu;
       
    71     delete iMenuPane;
       
    72     delete iMenuData;
       
    73     iStates.Close();
       
    74     iObservers.Close();
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CAknItemActionMenu::RegisterCollectionL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 EXPORT_C CAknItemActionMenu* CAknItemActionMenu::RegisterCollectionL(
       
    83         MAknCollection& aCollection )
       
    84     {
       
    85     return AknItemActionMenuRegister::RegisterCollectionL( aCollection );
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CAknItemActionMenu::RemoveCollection
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C void CAknItemActionMenu::RemoveCollection(
       
    94         MAknCollection& aCollection )
       
    95     {
       
    96     for ( TInt i = 0; i < iStates.Count(); i++ )
       
    97         {
       
    98         MAknCollection* state( iStates[ i ] );
       
    99         if ( state == &aCollection )
       
   100             {
       
   101             iStates.Remove( i );
       
   102             break;
       
   103             }
       
   104         }
       
   105     UnregisterMenu(); 
       
   106     }
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CAknItemActionMenu::InitMenuL
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C TBool CAknItemActionMenu::InitMenuL()
       
   114     {
       
   115     iMenuData->Reset();
       
   116     if ( !iMenuBar )
       
   117         {
       
   118         AknItemActionMenuRegister::RegisterItemActionMenuL( *this );
       
   119         }
       
   120     if ( iMenuBar )
       
   121         {
       
   122         if ( iMenuPane )
       
   123             {
       
   124             delete iMenuPane;
       
   125             iMenuPane = NULL;
       
   126             }
       
   127         iMenuPane = iMenuBar->PopulateItemActionMenuL( *this );
       
   128         }
       
   129     else
       
   130         {
       
   131         return EFalse;
       
   132         }
       
   133 
       
   134     return iMenuData->Count();
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CAknItemActionMenu::ShowMenuL
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C void CAknItemActionMenu::ShowMenuL(
       
   143         const TPoint& aPosition,
       
   144         TUint /*aFlags*/ )
       
   145     {
       
   146     if ( iMenuData->Count() )
       
   147         {
       
   148         if ( !iPopupMenu )
       
   149             {
       
   150             iPopupMenu = CAknStylusPopUpMenu::NewL( this, TPoint() );
       
   151             }
       
   152         iPopupMenu->Clear();
       
   153         iMenuData->AddMenuItemsToStylusPopupMenuL( iPopupMenu );
       
   154         iPopupMenu->SetPosition(
       
   155                 aPosition,
       
   156                 CAknStylusPopUpMenu::EPositionTypeRightBottom );
       
   157         iPopupMenu->ShowMenu();
       
   158         }
       
   159     }
       
   160 
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CAknItemActionMenu::CollectionChanged
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C void CAknItemActionMenu::CollectionChanged(
       
   167         MAknCollection& aCollection )
       
   168     {
       
   169     if ( iObservers.Count() && iStates.Find( &aCollection ) != KErrNotFound )
       
   170         {
       
   171         TBool collectionVisible( aCollection.CollectionState()
       
   172                 & MAknCollection::EStateCollectionVisible );
       
   173         NotifyChangeToActiveObserver( collectionVisible );
       
   174         }
       
   175     }
       
   176 
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CAknItemActionMenu::AddCollectionStateL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CAknItemActionMenu::AddCollectionStateL(
       
   183         MAknCollection& aCollection )
       
   184     {
       
   185     if ( iStates.Find( &aCollection ) == KErrNotFound )
       
   186         {
       
   187         iStates.InsertL( &aCollection, 0 );
       
   188         }
       
   189     }
       
   190 
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CAknItemActionMenu::SetMenuBar
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CAknItemActionMenu::SetMenuBar(
       
   197         MEikMenuObserver* aMenuObserver,
       
   198         CEikMenuBar* aMenuBar )
       
   199     {
       
   200     iMenuBarObserver = aMenuObserver;
       
   201     iMenuBar = aMenuBar;
       
   202     }
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // CAknItemActionMenu::CollectionHighlightVisible
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 TBool CAknItemActionMenu::CollectionHighlightVisible() const
       
   210     {
       
   211     TBool highlightVisible( ETrue );
       
   212     for ( TInt i = 0; i < iStates.Count(); i++ )
       
   213         {
       
   214         MAknCollection* state( iStates[ i ] );
       
   215         if ( state->CollectionState() &
       
   216                 MAknCollection::EStateCollectionVisible )
       
   217             {
       
   218             highlightVisible = state->CollectionState()
       
   219                 & MAknCollection::EStateHighlightVisible;
       
   220             break;
       
   221             }
       
   222         }
       
   223     return highlightVisible;
       
   224     }
       
   225 
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CAknItemActionMenu::CollectionSoftkeyVisible
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 TBool CAknItemActionMenu::CollectionSoftkeyVisible(
       
   232         TBool aVisibleCollection ) const
       
   233     {
       
   234     TBool softkeyVisible( ETrue );
       
   235     for ( TInt i = 0; i < iStates.Count(); i++ )
       
   236         {
       
   237         TInt state( iStates[ i ]->CollectionState() );
       
   238         if ( !aVisibleCollection
       
   239                 || state & MAknCollection::EStateCollectionVisible )
       
   240             {
       
   241             if ( state & MAknCollection::EStateMultipleSelection
       
   242                     || state & MAknCollection::EStateViewOnly )
       
   243                 {
       
   244                 softkeyVisible = ETrue;
       
   245                 }
       
   246             else
       
   247                 {
       
   248                 softkeyVisible =
       
   249                     state & MAknCollection::EStateHighlightVisible;
       
   250                 }
       
   251             break;
       
   252             }
       
   253         }
       
   254     return softkeyVisible;
       
   255     }
       
   256 
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // CAknItemActionMenu::MenuData
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 CAknItemActionMenuData& CAknItemActionMenu::MenuData()
       
   263     {
       
   264     return *iMenuData;
       
   265     }
       
   266 
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CAknItemActionMenu::RegisterCollectionObserverL
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CAknItemActionMenu::RegisterCollectionObserverL(
       
   273         MAknCollectionObserver& aObserver )
       
   274     {
       
   275     if ( iObservers.Find( &aObserver ) == KErrNotFound )
       
   276         {
       
   277         iObservers.InsertL( &aObserver, 0 );
       
   278         aObserver.SetItemActionMenu( this );
       
   279         }
       
   280     }
       
   281 
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CAknItemActionMenu::RemoveCollectionObserver
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CAknItemActionMenu::RemoveCollectionObserver(
       
   288         MAknCollectionObserver& aObserver )
       
   289     {
       
   290     TInt index( iObservers.Find( &aObserver ) );
       
   291     if ( index != KErrNotFound )
       
   292         {
       
   293         iObservers.Remove( index );
       
   294         UnregisterMenu(); 
       
   295         }
       
   296     }
       
   297 
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CAknItemActionMenu::CollectionCount
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 TInt CAknItemActionMenu::CollectionCount() const
       
   304     {
       
   305     return iStates.Count();
       
   306     }
       
   307 
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // CAknItemActionMenu::CAknItemActionMenu
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 CAknItemActionMenu::CAknItemActionMenu()
       
   314     : iPopupMenu( NULL ),
       
   315     iMenuBarObserver( NULL ),
       
   316     iMenuBar( NULL ),
       
   317     iMenuPane( NULL ),
       
   318     iMenuData( NULL )
       
   319     {
       
   320     AKNTASHOOK_ADD( this, "CAknItemActionMenu" );
       
   321     }
       
   322 
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // CAknItemActionMenu::ConstructL
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CAknItemActionMenu::ConstructL( MAknCollection& aCollection )
       
   329     {
       
   330     AddCollectionStateL( aCollection );
       
   331     iMenuData = CAknItemActionMenuData::NewL();
       
   332     }
       
   333 
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CAknItemActionMenu::LaunchSubMenuQueryL
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 TInt CAknItemActionMenu::LaunchSubMenuQueryL( const TDesC& aHeading )
       
   340     {
       
   341     TInt selectedIndex( KInvalidListIndex );
       
   342     if ( iMenuData->Count() )
       
   343         {
       
   344         CAknListQueryDialog* queryDialog
       
   345             = new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
   346         queryDialog->PrepareLC( R_AVKON_ITEM_ACTION_SUB_MENU_QUERY );
       
   347         MDesCArray* itemArray = iMenuData->MenuItemsForQueryDialogL();
       
   348         queryDialog->SetItemTextArray( itemArray );
       
   349         queryDialog->SetOwnershipType( ELbmOwnsItemArray );
       
   350         if ( aHeading != KNullDesC && queryDialog->QueryHeading() )
       
   351             {
       
   352             queryDialog->QueryHeading()->SetTextL( aHeading );
       
   353             }
       
   354         queryDialog->RunLD();
       
   355         }
       
   356     return ++selectedIndex;
       
   357     }
       
   358 
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // CAknItemActionMenu::NotifyChangeToActiveObserver
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CAknItemActionMenu::NotifyChangeToActiveObserver(
       
   365         TBool aCollectionVisible )
       
   366     {
       
   367     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   368         {
       
   369         MAknCollectionObserver* observer( iObservers[ i ] );
       
   370         if ( observer->Active() )
       
   371             {
       
   372             observer->CollectionChanged( aCollectionVisible );
       
   373             break;
       
   374             }
       
   375         }
       
   376     }
       
   377 
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // CAknItemActionMenu::SetEmphasis
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 void CAknItemActionMenu::SetEmphasis(
       
   384         CCoeControl* /*aMenuControl*/,
       
   385         TBool /*aEmphasis*/ )
       
   386     {
       
   387     }
       
   388 
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // CAknItemActionMenu::ProcessCommandL
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 void CAknItemActionMenu::ProcessCommandL( TInt aCommandId )
       
   395     {
       
   396     MAknCollection* informState ( NULL );
       
   397     // Store collection state before sending the command
       
   398     for ( TInt i = 0; i < iStates.Count(); i++ )
       
   399         {
       
   400         MAknCollection* state( iStates[ i ] );
       
   401         if ( state->CollectionState()
       
   402                 & MAknCollection::EStateCollectionVisible )
       
   403             {
       
   404             informState = state;
       
   405             break;
       
   406             }
       
   407         }       
       
   408     
       
   409     if ( aCommandId > 0 )
       
   410         {
       
   411         TInt cascadeId( iMenuData->MenuItemCascadeId( aCommandId ) );
       
   412         if ( cascadeId && iMenuPane )
       
   413             {
       
   414             TMenuItemTextBuf text = iMenuData->MenuItemText( aCommandId );
       
   415             iMenuData->Reset();
       
   416             iMenuPane->AddCascadeMenuItemsToActionMenuL(
       
   417                     cascadeId, EFalse, *iMenuData );
       
   418             aCommandId = LaunchSubMenuQueryL( text );
       
   419             }
       
   420                 
       
   421         if ( aCommandId > 0 && iMenuBarObserver )
       
   422             {
       
   423             iProcessingCommand = ETrue; 
       
   424             iMenuBarObserver->ProcessCommandL(
       
   425                     iMenuData->MenuItemCommandId( aCommandId ) );
       
   426             iProcessingCommand = EFalse; 
       
   427             }
       
   428         }
       
   429     // Inform collection that submenu was closed
       
   430     if ( iStates.Find( informState ) != KErrNotFound ) 
       
   431         {
       
   432         informState->ItemActionMenuClosed();
       
   433         }
       
   434     UnregisterMenu(); 
       
   435     }
       
   436 
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // CAknItemActionMenu::UnregisterMenu
       
   440 // ---------------------------------------------------------------------------
       
   441 //
       
   442 void CAknItemActionMenu::UnregisterMenu()
       
   443     {
       
   444     if ( !iProcessingCommand && !iStates.Count() && !iObservers.Count() )
       
   445         {
       
   446         delete iPopupMenu;
       
   447         iPopupMenu = NULL;
       
   448         delete iMenuPane;
       
   449         iMenuPane = NULL;
       
   450         AknItemActionMenuRegister::UnregisterItemActionMenu( *this );
       
   451         }
       
   452     }
       
   453 
       
   454 // End of File