diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-12-23 11:16:28 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-12-23 17:00:58 +0100 |
commit | b7570a5f9d026f7cd6f064594bd7599fe36e9a14 (patch) | |
tree | ba091454feae5ee8f9c9bf985e9ff46961493211 /svtools/source | |
parent | febb1b2861ce276ad79fccd95e9eadc9e435603c (diff) |
reorganize ToolbarUnoDispatcher to be useful for sidebar
Change-Id: If129d4832f04758705e121bff88ea7d2e45bf96b
Reviewed-on: https://gerrit.libreoffice.org/85755
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svtools/source')
-rw-r--r-- | svtools/source/uno/generictoolboxcontroller.cxx | 104 |
1 files changed, 72 insertions, 32 deletions
diff --git a/svtools/source/uno/generictoolboxcontroller.cxx b/svtools/source/uno/generictoolboxcontroller.cxx index c4e409546018..e126ec8b68a1 100644 --- a/svtools/source/uno/generictoolboxcontroller.cxx +++ b/svtools/source/uno/generictoolboxcontroller.cxx @@ -26,6 +26,7 @@ #include <com/sun/star/frame/XDispatch.hpp> #include <vcl/svapp.hxx> +#include <vcl/weld.hxx> using namespace css::awt; using namespace css::uno; @@ -53,10 +54,28 @@ GenericToolboxController::GenericToolboxController( const Reference< XComponentC const Reference< XFrame >& rFrame, ToolBox* pToolbox, sal_uInt16 nID, - const OUString& aCommand ) : - svt::ToolboxController( rxContext, rFrame, aCommand ) - , m_pToolbox( pToolbox ) - , m_nID( nID ) + const OUString& aCommand ) + : svt::ToolboxController( rxContext, rFrame, aCommand ) + , m_xToolbox( pToolbox ) + , m_nID( nID ) + , m_pToolbox(nullptr) +{ + // Initialization is done through ctor + m_bInitialized = true; + + // insert main command to our listener map + if ( !m_aCommandURL.isEmpty() ) + m_aListenerMap.emplace( aCommand, Reference< XDispatch >() ); +} + +GenericToolboxController::GenericToolboxController( const Reference< XComponentContext >& rxContext, + const Reference< XFrame >& rFrame, + weld::Toolbar& rToolbar, + const OUString& aCommand ) + : svt::ToolboxController( rxContext, rFrame, aCommand ) + , m_xToolbox( nullptr ) + , m_nID( 0 ) + , m_pToolbox(&rToolbar) { // Initialization is done through ctor m_bInitialized = true; @@ -73,8 +92,9 @@ GenericToolboxController::~GenericToolboxController() void SAL_CALL GenericToolboxController::dispose() { SolarMutexGuard aSolarMutexGuard; - m_pToolbox.clear(); + m_xToolbox.clear(); m_nID = 0; + m_pToolbox = nullptr; svt::ToolboxController::dispose(); } @@ -125,40 +145,60 @@ void GenericToolboxController::statusChanged( const FeatureStateEvent& Event ) if ( m_bDisposed ) return; - if ( !m_pToolbox ) - return; + if (m_xToolbox) + { + m_xToolbox->EnableItem( m_nID, Event.IsEnabled ); - m_pToolbox->EnableItem( m_nID, Event.IsEnabled ); + ToolBoxItemBits nItemBits = m_xToolbox->GetItemBits( m_nID ); + nItemBits &= ~ToolBoxItemBits::CHECKABLE; + TriState eTri = TRISTATE_FALSE; - ToolBoxItemBits nItemBits = m_pToolbox->GetItemBits( m_nID ); - nItemBits &= ~ToolBoxItemBits::CHECKABLE; - TriState eTri = TRISTATE_FALSE; + bool bValue; + OUString aStrValue; + ItemStatus aItemState; - bool bValue; - OUString aStrValue; - ItemStatus aItemState; + if ( Event.State >>= bValue ) + { + // Boolean, treat it as checked/unchecked + m_xToolbox->SetItemBits( m_nID, nItemBits ); + m_xToolbox->CheckItem( m_nID, bValue ); + if ( bValue ) + eTri = TRISTATE_TRUE; + nItemBits |= ToolBoxItemBits::CHECKABLE; + } + else if ( Event.State >>= aStrValue ) + { + m_xToolbox->SetItemText( m_nID, aStrValue ); + } + else if ( Event.State >>= aItemState ) + { + eTri = TRISTATE_INDET; + nItemBits |= ToolBoxItemBits::CHECKABLE; + } - if ( Event.State >>= bValue ) - { - // Boolean, treat it as checked/unchecked - m_pToolbox->SetItemBits( m_nID, nItemBits ); - m_pToolbox->CheckItem( m_nID, bValue ); - if ( bValue ) - eTri = TRISTATE_TRUE; - nItemBits |= ToolBoxItemBits::CHECKABLE; + m_xToolbox->SetItemState( m_nID, eTri ); + m_xToolbox->SetItemBits( m_nID, nItemBits ); } - else if ( Event.State >>= aStrValue ) - { - m_pToolbox->SetItemText( m_nID, aStrValue ); - } - else if ( Event.State >>= aItemState ) + + if (m_pToolbox) { - eTri = TRISTATE_INDET; - nItemBits |= ToolBoxItemBits::CHECKABLE; - } + OString sId = m_aCommandURL.toUtf8(); - m_pToolbox->SetItemState( m_nID, eTri ); - m_pToolbox->SetItemBits( m_nID, nItemBits ); + m_pToolbox->set_item_sensitive(sId, Event.IsEnabled); + + bool bValue; + OUString aStrValue; + + if ( Event.State >>= bValue ) + { + // Boolean, treat it as checked/unchecked + m_pToolbox->set_item_active( sId, bValue ); + } + else if ( Event.State >>= aStrValue ) + { + m_pToolbox->set_item_label( sId, aStrValue ); + } + } } IMPL_STATIC_LINK( GenericToolboxController, ExecuteHdl_Impl, void*, p, void ) |