uifw/EikStd/coctlsrc/aknitemactionmenuregister.cpp
branchRCL_3
changeset 8 71dd06cfe933
parent 6 9f56a4e1b8ab
child 10 3d340a0166ff
equal deleted inserted replaced
7:08e69e956a8c 8:71dd06cfe933
    69     _AKNTRACE_FUNC_EXIT;
    69     _AKNTRACE_FUNC_EXIT;
    70     }
    70     }
    71 
    71 
    72 
    72 
    73 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
       
    74 // AknItemActionMenuRegister::RemoveConstructingMenuBarOwner
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C void AknItemActionMenuRegister::RemoveConstructingMenuBarOwner( 
       
    78         MObjectProvider* aMenuBarOwner )
       
    79     {
       
    80     _AKNTRACE_FUNC_ENTER;
       
    81 
       
    82     if ( AppUiSingleClickCompatible() )
       
    83         {
       
    84         AknItemActionMenuRegister* instance( Instance() );
       
    85 
       
    86         if ( instance )
       
    87             {
       
    88             instance->DoRemoveConstructingMenuBarOwner( aMenuBarOwner );
       
    89             }
       
    90         }
       
    91 
       
    92     _AKNTRACE_FUNC_EXIT;
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
    74 // AknItemActionMenuRegister::RegisterCollectionL
    97 // AknItemActionMenuRegister::RegisterCollectionL
    75 // ---------------------------------------------------------------------------
    98 // ---------------------------------------------------------------------------
    76 //
    99 //
    77 CAknItemActionMenu* AknItemActionMenuRegister::RegisterCollectionL(
   100 CAknItemActionMenu* AknItemActionMenuRegister::RegisterCollectionL(
    78         MAknCollection& aCollectionState )
   101         MAknCollection& aCollectionState, MObjectProvider* aMenuBarOwner )
    79     {
   102     {
    80     _AKNTRACE_FUNC_ENTER;
   103     _AKNTRACE_FUNC_ENTER;
    81 
   104 
    82     CAknItemActionMenu* menu( NULL );
   105     CAknItemActionMenu* menu( NULL );
    83     if ( AppUiSingleClickCompatible() )
   106     if ( AppUiSingleClickCompatible() )
    84         {
   107         {
    85         AknItemActionMenuRegister* instance( Instance() );
   108         AknItemActionMenuRegister* instance( Instance() );
    86         if ( instance )
   109         if ( instance )
    87             {
   110             {
    88             menu = instance->DoRegisterCollectionL( aCollectionState );
   111             menu = instance->DoRegisterCollectionL( 
       
   112                     aCollectionState, aMenuBarOwner );
    89             }
   113             }
    90         }
   114         }
    91 
   115 
    92     _AKNTRACE_FUNC_EXIT;
   116     _AKNTRACE_FUNC_EXIT;
    93     return menu;
   117     return menu;
   318 // ---------------------------------------------------------------------------
   342 // ---------------------------------------------------------------------------
   319 // AknItemActionMenuRegister::DoRegisterCollectionL
   343 // AknItemActionMenuRegister::DoRegisterCollectionL
   320 // ---------------------------------------------------------------------------
   344 // ---------------------------------------------------------------------------
   321 //
   345 //
   322 CAknItemActionMenu* AknItemActionMenuRegister::DoRegisterCollectionL(
   346 CAknItemActionMenu* AknItemActionMenuRegister::DoRegisterCollectionL(
   323         MAknCollection& aCollectionState )
   347         MAknCollection& aCollectionState, MObjectProvider* aMenuBarOwner )
   324     {
   348     {
   325     _AKNTRACE_FUNC_ENTER;
   349     _AKNTRACE_FUNC_ENTER;
   326     
   350     
   327     CAknItemActionMenu* menu( NULL );
   351     CAknItemActionMenu* menu( NULL );
   328     CEikMenuBar* menuBar = FindCurrentMenuBarL();
   352     CEikMenuBar* menuBar = NULL;
       
   353     
       
   354     if ( aMenuBarOwner )
       
   355         {
       
   356         aMenuBarOwner->MopGetObject( menuBar );
       
   357         }
       
   358 
       
   359     if ( !menuBar )
       
   360         {
       
   361         menuBar = FindCurrentMenuBar();
       
   362         }
   329     menu = RegisterStateToItemActionMenuL( menuBar, aCollectionState );
   363     menu = RegisterStateToItemActionMenuL( menuBar, aCollectionState );
   330 
   364 
   331     _AKNTRACE_FUNC_EXIT;
   365     _AKNTRACE_FUNC_EXIT;
   332 
   366 
   333     return menu;
   367     return menu;
   446 void AknItemActionMenuRegister::DoRegisterCollectionObserverL(
   480 void AknItemActionMenuRegister::DoRegisterCollectionObserverL(
   447         MAknCollectionObserver& aObserver )
   481         MAknCollectionObserver& aObserver )
   448     {
   482     {
   449     _AKNTRACE_FUNC_ENTER;
   483     _AKNTRACE_FUNC_ENTER;
   450 
   484 
   451     CEikMenuBar* menuBar = FindCurrentMenuBarL();
   485     CEikMenuBar* menuBar = FindCurrentMenuBar();
   452     if ( !menuBar || !iRegisterArray->RegisterCollectionObserverL(
   486     if ( !menuBar || !iRegisterArray->RegisterCollectionObserverL(
   453             *menuBar, aObserver ) )
   487             *menuBar, aObserver ) )
   454         {
   488         {
   455         TAknUnregisteredObserverData newData( menuBar, 
   489         TAknUnregisteredObserverData newData( menuBar, 
   456                 aObserver, Owner() );
   490                 aObserver, Owner() );
   749     return menu;
   783     return menu;
   750     }
   784     }
   751 
   785 
   752 
   786 
   753 // ---------------------------------------------------------------------------
   787 // ---------------------------------------------------------------------------
   754 // AknItemActionMenuRegister::FindCurrentMenuBarL
   788 // AknItemActionMenuRegister::FindCurrentMenuBar
   755 // ---------------------------------------------------------------------------
   789 // ---------------------------------------------------------------------------
   756 //
   790 //
   757 CEikMenuBar* AknItemActionMenuRegister::FindCurrentMenuBarL()
   791 CEikMenuBar* AknItemActionMenuRegister::FindCurrentMenuBar()
   758     {
   792     {
   759     _AKNTRACE_FUNC_ENTER;
   793     _AKNTRACE_FUNC_ENTER;
   760 
   794 
   761     CAknAppUi* appUi = AppUI();
   795     CAknAppUi* appUi = AppUI();
   762     CEikonEnv* eikonEnv( CEikonEnv::Static() );
   796     CEikonEnv* eikonEnv( CEikonEnv::Static() );
   763     TBool isConstructingDialog( EFalse );
       
   764     CEikMenuBar* menuBar( NULL );
   797     CEikMenuBar* menuBar( NULL );
   765     
   798     
   766     // If overriding menubar owner is set then it's the one to obey. If the
   799     // If overriding menubar owner is set then it's the one to obey. If the
   767     // overriding menubar owner doesn't supply a menubar object then there
   800     // overriding menubar owner doesn't supply a menubar object then there
   768     // isn't proper one available.
   801     // isn't proper one available.
   769     if ( iOverridingMenuBarOwner )
   802     if ( iOverridingMenuBarOwner )
   770         {
   803         {
   771         _AKNTRACE_FUNC_EXIT;
   804         _AKNTRACE_FUNC_EXIT;
   772         return OverridingObjectMenuBar();
   805         return OverridingObjectMenuBar();
   773         }
   806         }
   774     
   807 
   775     // Check if there is existing constructing dialog
   808     // by default choose the current constructing menubar owner
   776     if ( iMenuBarOwner )
   809     if ( iMenuBarOwner )
   777         {
   810         {
   778         CEikDialog* dialog( NULL );
   811         menuBar = ConstructingObjectMenuBar();
   779         iMenuBarOwner->MopGetObjectNoChaining( dialog );
   812         }
   780         if ( dialog )
   813     else
   781             {
       
   782             isConstructingDialog = ETrue;
       
   783             }
       
   784         }
       
   785     // No constructing dialog
       
   786     if ( !isConstructingDialog )
       
   787         {
   814         {
   788         // Fetch pointer to dialog that is currently displayed
   815         // Fetch pointer to dialog that is currently displayed
   789         menuBar = DialogMenuBar( appUi );
   816         menuBar = DialogMenuBar( appUi );
       
   817 
   790         // No dialog - pointer to active view menu bar
   818         // No dialog - pointer to active view menu bar
   791         if ( !menuBar )
   819         if ( !menuBar )
   792             {
   820             {
   793             menuBar = ViewMenuBar( appUi );
   821             menuBar = ViewMenuBar( appUi );
   794             }
   822             }
   795         }
       
   796     
       
   797     // Fetch pointer to constructing object menu bar
       
   798     if ( !menuBar )
       
   799         {
       
   800         menuBar = ConstructingObjectMenuBar();
       
   801         }
   823         }
   802 
   824 
   803     // Finally, if no luck with others, fetch pointer to appUi menu bar.
   825     // Finally, if no luck with others, fetch pointer to appUi menu bar.
   804     if ( !menuBar && eikonEnv )
   826     if ( !menuBar && eikonEnv )
   805         {
   827         {
   899         if ( dialog )
   921         if ( dialog )
   900             {
   922             {
   901             iIsConstructingDialog = ETrue; 
   923             iIsConstructingDialog = ETrue; 
   902             }
   924             }
   903         }
   925         }
   904     else if ( !aMenuBarOwner && iIsConstructingDialog )
   926     
   905         {
   927     iMenuBarOwner = aMenuBarOwner;
   906         // When setting constructing menubar owner to NULL from a dialog check
   928     }
   907         // if there is item with the same menubar owner in iUnregisteredMenus 
   929 
   908         // and try to find correct menubar for it.
   930 
   909         for ( TInt i = 0; i < iUnregisteredMenus.Count(); i++ )
   931 // ---------------------------------------------------------------------------
   910             {
   932 // AknItemActionMenuRegister::DoRemoveConstructingMenuBarOwner
   911             TAknUnregisteredMenuData& data( iUnregisteredMenus[ i ] );
   933 // ---------------------------------------------------------------------------
   912             if ( data.iOwner == iMenuBarOwner ) 
   934 //
       
   935 void AknItemActionMenuRegister::DoRemoveConstructingMenuBarOwner( 
       
   936         MObjectProvider* aMenuBarOwner )
       
   937     {
       
   938     TInt i = 0;
       
   939     
       
   940     // set all references to removed menubar owner to NULL
       
   941     while ( i  < iUnregisteredMenus.Count() )
       
   942         {
       
   943         TAknUnregisteredMenuData& data( iUnregisteredMenus[i] );
       
   944 
       
   945         if ( data.iOwner == iMenuBarOwner ) 
       
   946             {
       
   947             data.iOwner = iMenuBarOwner = NULL;
       
   948             
       
   949             // When setting constructing menubar owner to NULL from a dialog
       
   950             // check if there is item with the same menubar owner in 
       
   951             // iUnregisteredMenus and try to find correct menubar for it.
       
   952             if ( iIsConstructingDialog )
   913                 {
   953                 {
   914                 data.iOwner = iMenuBarOwner = NULL; 
   954                 CEikMenuBar* menuBar = FindCurrentMenuBar(); 
   915                 CEikMenuBar* menuBar = FindCurrentMenuBarL(); 
   955 
   916                 if ( menuBar )
   956                 if ( menuBar )
   917                     {
   957                     {
   918                     AddRegisterEntryL( *menuBar, *data.iMenu );
   958                     TRAP_IGNORE( AddRegisterEntryL( *menuBar, *data.iMenu ) );
   919                     iUnregisteredMenus.Remove( i );
   959                     iUnregisteredMenus.Remove( i );
       
   960                     continue;
   920                     }
   961                     }
   921                 iIsConstructingDialog = EFalse; 
       
   922                 return; 
       
   923                 }
   962                 }
   924             }
   963             }
   925         }
   964         
   926     iMenuBarOwner = aMenuBarOwner;
   965         ++i;
   927     }
   966         }
       
   967     
       
   968     // NULL also possible references in unregistered observers
       
   969     for ( i = 0; i < iUnregisteredObservers.Count(); ++i )
       
   970         {
       
   971         TAknUnregisteredObserverData& data( iUnregisteredObservers[i] );
       
   972         
       
   973         if ( data.iOwner == aMenuBarOwner )
       
   974             {
       
   975             data.iOwner = NULL;
       
   976             }
       
   977         }
       
   978     
       
   979     if ( iMenuBarOwner == aMenuBarOwner )
       
   980         {
       
   981         iIsConstructingDialog = EFalse; 
       
   982         iMenuBarOwner = NULL;
       
   983         }
       
   984     }
       
   985 
   928 
   986 
   929 // ---------------------------------------------------------------------------
   987 // ---------------------------------------------------------------------------
   930 // AknItemActionMenuRegister::TAknUnregisteredObserverData
   988 // AknItemActionMenuRegister::TAknUnregisteredObserverData
   931 // ::TAknUnregisteredObserverData
   989 // ::TAknUnregisteredObserverData
   932 // ---------------------------------------------------------------------------
   990 // ---------------------------------------------------------------------------