diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2016-10-25 01:23:42 +0300 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2016-10-27 11:05:38 +0300 |
commit | 074449ee349ccfe67466fb1aa63f96e8792334aa (patch) | |
tree | 99fb8c03abe2c802d0d2fe35c7f1b44f0d43c2c3 | |
parent | e59013d6e95846fbc8066bdd8ef3b4b132043e45 (diff) |
GenericPopupToolbarController: deal with main command being disabled
Try to set another command from the dropdown, if there is any
enabled. Otherwise give up and disable the button altogether.
Change-Id: I7fa46a946826056d04851faee9c7ad85f00c3678
-rw-r--r-- | framework/source/uielement/popuptoolbarcontroller.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/framework/source/uielement/popuptoolbarcontroller.cxx b/framework/source/uielement/popuptoolbarcontroller.cxx index acf28d161583..e3a840d5dd69 100644 --- a/framework/source/uielement/popuptoolbarcontroller.cxx +++ b/framework/source/uielement/popuptoolbarcontroller.cxx @@ -264,6 +264,12 @@ public: GenericPopupToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Sequence< css::uno::Any >& rxArgs ); + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rxArgs ) throw ( css::uno::Exception, css::uno::RuntimeException, std::exception ) override; + + // XStatusListener + virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException, std::exception ) override; + // XServiceInfo virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException) override; @@ -316,6 +322,46 @@ css::uno::Sequence<OUString> GenericPopupToolbarController::getSupportedServiceN return {"com.sun.star.frame.ToolbarController"}; } +void GenericPopupToolbarController::initialize( const css::uno::Sequence< css::uno::Any >& rxArgs ) + throw ( css::uno::Exception, css::uno::RuntimeException, std::exception ) +{ + PopupMenuToolbarController::initialize( rxArgs ); + if ( m_bReplaceWithLast ) + // Create early, so we can use the menu is statusChanged method. + createPopupMenuController(); +} + +void GenericPopupToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent ) + throw ( css::uno::RuntimeException, std::exception ) +{ + SolarMutexGuard aGuard; + + if ( m_bReplaceWithLast && !rEvent.IsEnabled && m_xPopupMenu.is() ) + { + Menu* pVclMenu = VCLXMenu::GetImplementation( m_xPopupMenu )->GetMenu(); + + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if ( getToolboxId( nId, &pToolBox ) && pToolBox->IsItemEnabled( nId ) ) + { + pVclMenu->Activate(); + pVclMenu->Deactivate(); + } + + for ( sal_uInt16 i = 0; i < pVclMenu->GetItemCount(); ++i ) + { + sal_uInt16 nItemId = pVclMenu->GetItemId( i ); + if ( nItemId && pVclMenu->IsItemEnabled( nItemId ) && !pVclMenu->GetPopupMenu( nItemId ) ) + { + functionExecuted( pVclMenu->GetItemCommand( nItemId ) ); + return; + } + } + } + + PopupMenuToolbarController::statusChanged( rEvent ); +} + void GenericPopupToolbarController::functionExecuted( const OUString& rCommand ) { if ( m_bReplaceWithLast ) |