From 074449ee349ccfe67466fb1aa63f96e8792334aa Mon Sep 17 00:00:00 2001 From: Maxim Monastirsky Date: Tue, 25 Oct 2016 01:23:42 +0300 Subject: 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 --- .../source/uielement/popuptoolbarcontroller.cxx | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'framework') 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 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 ) -- cgit