[Libreoffice-commits] core.git: framework/inc framework/Library_fwk.mk framework/source solenv/clang-format

Maxim Monastirsky (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 20 14:43:33 UTC 2020


 framework/Library_fwk.mk                            |    1 
 framework/inc/uielement/addonstoolbarmanager.hxx    |   64 --
 framework/inc/uielement/addonstoolbarwrapper.hxx    |    1 
 framework/inc/uielement/toolbarmanager.hxx          |   12 
 framework/source/uielement/addonstoolbarmanager.cxx |  430 --------------------
 framework/source/uielement/addonstoolbarwrapper.cxx |   14 
 framework/source/uielement/toolbarmanager.cxx       |  171 +++++--
 solenv/clang-format/excludelist                     |    2 
 8 files changed, 132 insertions(+), 563 deletions(-)

New commits:
commit 37892578e97ea0f0c948116d639797060ac5f21f
Author:     Maxim Monastirsky <momonasmon at gmail.com>
AuthorDate: Thu Aug 20 12:07:24 2020 +0300
Commit:     Maxim Monastirsky <momonasmon at gmail.com>
CommitDate: Thu Aug 20 16:42:52 2020 +0200

    Base addon toolbars on the regular ToolBarManager
    
    ToolBarManager already supported addon buttons because of the
    toolbar merging feature. Besides the cleanup, this gives access to
    addon devs to all toolbar features like aliases or style buttons.
    
    Change-Id: I7adf830ac71c7f5354a924d60a531d8001e37571
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101071
    Tested-by: Jenkins
    Reviewed-by: Maxim Monastirsky <momonasmon at gmail.com>

diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk
index 12434b7a4b74..754090d5512f 100644
--- a/framework/Library_fwk.mk
+++ b/framework/Library_fwk.mk
@@ -175,7 +175,6 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
     framework/source/uiconfiguration/uicategorydescription \
     framework/source/uiconfiguration/uiconfigurationmanager \
     framework/source/uiconfiguration/windowstateconfiguration \
-    framework/source/uielement/addonstoolbarmanager \
     framework/source/uielement/addonstoolbarwrapper \
     framework/source/uielement/buttontoolbarcontroller \
     framework/source/uielement/comboboxtoolbarcontroller \
diff --git a/framework/inc/uielement/addonstoolbarmanager.hxx b/framework/inc/uielement/addonstoolbarmanager.hxx
deleted file mode 100644
index d13c3f14b58a..000000000000
--- a/framework/inc/uielement/addonstoolbarmanager.hxx
+++ /dev/null
@@ -1,64 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef INCLUDED_FRAMEWORK_INC_UIELEMENT_ADDONSTOOLBARMANAGER_HXX
-#define INCLUDED_FRAMEWORK_INC_UIELEMENT_ADDONSTOOLBARMANAGER_HXX
-
-#include <uielement/toolbarmanager.hxx>
-
-#include <com/sun/star/frame/XFrame.hpp>
-
-#include <rtl/ustring.hxx>
-
-class ToolBox;
-
-namespace framework
-{
-
-class AddonsToolBarManager final : public ToolBarManager
-{
-    public:
-        AddonsToolBarManager( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
-                              const css::uno::Reference< css::frame::XFrame >& rFrame,
-                              const OUString& rResourceName,
-                              ToolBox* pToolBar );
-        virtual ~AddonsToolBarManager() override;
-
-        // XComponent
-        void SAL_CALL dispose() override;
-
-        virtual void RefreshImages() override;
-        using ToolBarManager::FillToolbar;
-        void FillToolbar( const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& rAddonToolbar );
-
-    private:
-        DECL_LINK(Click, ToolBox *, void);
-        DECL_LINK(DoubleClick, ToolBox *, void);
-        DECL_LINK(Select, ToolBox *, void);
-        DECL_LINK(StateChanged, StateChangedType const *, void );
-        DECL_LINK(DataChanged, DataChangedEvent const *, void );
-
-        virtual bool MenuItemAllowed( sal_uInt16 ) const override;
-};
-
-}
-
-#endif // INCLUDED_FRAMEWORK_INC_UIELEMENT_ADDONSTOOLBARMANAGER_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/inc/uielement/addonstoolbarwrapper.hxx b/framework/inc/uielement/addonstoolbarwrapper.hxx
index 6d6fee13f4c4..2970ce6d13fa 100644
--- a/framework/inc/uielement/addonstoolbarwrapper.hxx
+++ b/framework/inc/uielement/addonstoolbarwrapper.hxx
@@ -28,7 +28,6 @@
 namespace framework
 {
 
-class AddonsToolBarManager;
 class AddonsToolBarWrapper final : public UIElementWrapperBase
 {
     public:
diff --git a/framework/inc/uielement/toolbarmanager.hxx b/framework/inc/uielement/toolbarmanager.hxx
index 8f3eb4c2b2eb..d77ae16312aa 100644
--- a/framework/inc/uielement/toolbarmanager.hxx
+++ b/framework/inc/uielement/toolbarmanager.hxx
@@ -57,7 +57,7 @@ typedef ::cppu::WeakImplHelper<
            css::ui::XUIConfigurationListener
         > ToolbarManager_Base;
 
-class ToolBarManager : public ToolbarManager_Base
+class ToolBarManager final : public ToolbarManager_Base
 {
     public:
         ToolBarManager( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
@@ -85,8 +85,9 @@ class ToolBarManager : public ToolbarManager_Base
         void SAL_CALL removeEventListener( const css::uno::Reference< XEventListener >& xListener ) override;
 
         void CheckAndUpdateImages();
-        virtual void RefreshImages();
+        void RequestImages();
         void FillToolbar( const css::uno::Reference< css::container::XIndexAccess >& rToolBarData );
+        void FillAddonToolbar( const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& rAddonToolbar );
         void FillOverflowToolbar( ToolBox const * pParent );
         void notifyRegisteredControllers( const OUString& aUIElementName, const OUString& aCommand );
         void Destroy();
@@ -107,7 +108,7 @@ class ToolBarManager : public ToolbarManager_Base
             css::uno::Reference< css::awt::XWindow >            xWindow;
         };
 
-    protected:
+    private:
         DECL_LINK(Click, ToolBox *, void);
         DECL_LINK(DropdownClick, ToolBox *, void);
         DECL_LINK(DoubleClick, ToolBox *, void);
@@ -123,8 +124,6 @@ class ToolBarManager : public ToolbarManager_Base
         DECL_LINK( OverflowEventListener, VclWindowEvent&, void );
         DECL_STATIC_LINK( ToolBarManager, ExecuteHdl_Impl, void*, void );
 
-        virtual bool MenuItemAllowed( sal_uInt16 ) const;
-
         void AddCustomizeMenuItems(ToolBox const * pToolBar);
         void InitImageManager();
         void RemoveControllers();
@@ -134,7 +133,7 @@ class ToolBarManager : public ToolbarManager_Base
         void UpdateController( const css::uno::Reference< css::frame::XToolbarController >& xController);
         //end
         void AddFrameActionListener();
-        void RequestImages();
+        void RefreshImages();
         ToolBoxItemBits ConvertStyleToToolboxItemBits( sal_Int32 nStyle );
         css::uno::Reference< css::frame::XModel > GetModelFromFrame() const;
         bool IsPluginMode() const;
@@ -142,7 +141,6 @@ class ToolBarManager : public ToolbarManager_Base
         void setToolBarImage(const Image& _aImage,const CommandToInfoMap::const_iterator& _pIter);
         void impl_elementChanged(bool _bRemove,const css::ui::ConfigurationEvent& Event );
 
-    protected:
         typedef std::unordered_map< sal_uInt16, css::uno::Reference< css::frame::XStatusListener > >  ToolBarControllerMap;
         typedef ::std::vector< css::uno::Reference< css::frame::XSubToolbarController > >             SubToolBarControllerVector;
         typedef std::unordered_map<OUString, SubToolBarControllerVector>                                                SubToolBarToSubToolBarControllerMap;
diff --git a/framework/source/uielement/addonstoolbarmanager.cxx b/framework/source/uielement/addonstoolbarmanager.cxx
deleted file mode 100644
index 9a850e0bc39e..000000000000
--- a/framework/source/uielement/addonstoolbarmanager.cxx
+++ /dev/null
@@ -1,430 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <uielement/addonstoolbarmanager.hxx>
-#include <uielement/toolbarmerger.hxx>
-
-#include <classes/resource.hxx>
-#include <framework/addonsoptions.hxx>
-
-#include <com/sun/star/frame/ModuleManager.hpp>
-#include <com/sun/star/frame/XToolbarController.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/ui/DockingArea.hpp>
-#include <com/sun/star/util/XUpdatable.hpp>
-#include <comphelper/propertysequence.hxx>
-#include <o3tl/safeint.hxx>
-#include <toolkit/helper/vclunohelper.hxx>
-
-#include <svtools/miscopt.hxx>
-#include <vcl/event.hxx>
-#include <vcl/svapp.hxx>
-#include <vcl/toolbox.hxx>
-#include <vcl/settings.hxx>
-#include <vcl/commandinfoprovider.hxx>
-
-//  namespaces
-
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::awt;
-using namespace ::com::sun::star::beans;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::frame;
-using namespace ::com::sun::star::util;
-using namespace ::com::sun::star::container;
-using namespace ::com::sun::star::ui;
-
-namespace framework
-{
-
-AddonsToolBarManager::AddonsToolBarManager( const Reference< XComponentContext >& rxContext,
-                                const Reference< XFrame >& rFrame,
-                                const OUString& rResourceName,
-                                ToolBox* pToolBar ) :
-    ToolBarManager( rxContext, rFrame, rResourceName, pToolBar )
-{
-    m_pToolBar->SetMenuType( ToolBoxMenuType::ClippedItems );
-    m_pToolBar->SetSelectHdl( LINK( this, AddonsToolBarManager, Select) );
-    m_pToolBar->SetClickHdl( LINK( this, AddonsToolBarManager, Click ) );
-    m_pToolBar->SetDoubleClickHdl( LINK( this, AddonsToolBarManager, DoubleClick ) );
-    m_pToolBar->SetStateChangedHdl( LINK( this, AddonsToolBarManager, StateChanged ) );
-    m_pToolBar->SetDataChangedHdl( LINK( this, AddonsToolBarManager, DataChanged ) );
-}
-
-AddonsToolBarManager::~AddonsToolBarManager()
-{
-}
-
-static bool IsCorrectContext( const OUString& rModuleIdentifier, const OUString& aContextList )
-{
-    if ( aContextList.isEmpty() )
-        return true;
-
-    if ( !rModuleIdentifier.isEmpty() )
-    {
-        sal_Int32 nIndex = aContextList.indexOf( rModuleIdentifier );
-        return ( nIndex >= 0 );
-    }
-
-    return false;
-}
-
-static Image RetrieveImage( Reference< css::frame::XFrame > const & rFrame,
-                            const OUString& aImageId,
-                            const OUString& aURL,
-                            bool bBigImage
-)
-{
-    vcl::ImageType eImageType = vcl::ImageType::Size16;
-    if (bBigImage)
-        eImageType = vcl::ImageType::Size26;
-
-    if ( !aImageId.isEmpty() )
-    {
-        Image aImage(framework::AddonsOptions().GetImageFromURL(aImageId, bBigImage));
-        if ( !!aImage )
-            return aImage;
-        else
-            aImage = vcl::CommandInfoProvider::GetImageForCommand(aImageId, rFrame, eImageType);
-        if ( !!aImage )
-            return aImage;
-    }
-
-    Image aImage(framework::AddonsOptions().GetImageFromURL(aURL, bBigImage));
-    if ( !aImage )
-        aImage = vcl::CommandInfoProvider::GetImageForCommand(aImageId, rFrame, eImageType);
-
-    return aImage;
-}
-
-// XComponent
-void SAL_CALL AddonsToolBarManager::dispose()
-{
-    Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
-
-    {
-        // Remove addon specific data from toolbar items.
-        SolarMutexGuard g;
-        for ( ToolBox::ImplToolItems::size_type n = 0; n < m_pToolBar->GetItemCount(); n++ )
-        {
-            sal_uInt16 nId( m_pToolBar->GetItemId( n ) );
-
-            if ( nId > 0 )
-            {
-                AddonsParams* pRuntimeItemData = static_cast<AddonsParams*>(m_pToolBar->GetItemData( nId ));
-                delete pRuntimeItemData;
-                m_pToolBar->SetItemData( nId, nullptr );
-            }
-        }
-    }
-
-    // Base class will destroy our m_pToolBar member
-    ToolBarManager::dispose();
-}
-
-bool AddonsToolBarManager::MenuItemAllowed( sal_uInt16 nId ) const
-{
-    return ( nId != MENUITEM_TOOLBAR_VISIBLEBUTTON ) &&
-           ( nId != MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR );
-}
-
-void AddonsToolBarManager::RefreshImages()
-{
-    bool  bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
-    for ( ToolBox::ImplToolItems::size_type nPos = 0; nPos < m_pToolBar->GetItemCount(); nPos++ )
-    {
-        sal_uInt16 nId( m_pToolBar->GetItemId( nPos ) );
-
-        if ( nId > 0 )
-        {
-            OUString aCommandURL = m_pToolBar->GetItemCommand( nId );
-            OUString aImageId;
-            AddonsParams* pRuntimeItemData = static_cast<AddonsParams*>(m_pToolBar->GetItemData( nId ));
-            if ( pRuntimeItemData )
-                aImageId  = pRuntimeItemData->aImageId;
-
-            m_pToolBar->SetItemImage(
-                nId,
-                RetrieveImage( m_xFrame, aImageId, aCommandURL, bBigImages )
-            );
-        }
-    }
-    m_pToolBar->SetToolboxButtonSize( bBigImages ? ToolBoxButtonSize::Large : ToolBoxButtonSize::Small );
-    ::Size aSize = m_pToolBar->CalcWindowSizePixel();
-    m_pToolBar->SetOutputSizePixel( aSize );
-}
-
-void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue > >& rAddonToolbar )
-{
-    SolarMutexGuard g;
-
-    if ( m_bDisposed )
-        return;
-
-    sal_uInt16 nId( 1 );
-
-    RemoveControllers();
-
-    m_pToolBar->Clear();
-    m_aControllerMap.clear();
-
-    OUString aModuleIdentifier;
-    try
-    {
-        Reference< XModuleManager2 > xModuleManager = ModuleManager::create( m_xContext );
-        aModuleIdentifier = xModuleManager->identify( m_xFrame );
-    }
-    catch ( const Exception& )
-    {
-    }
-
-    sal_uInt32  nElements( 0 );
-    bool    bAppendSeparator( false );
-    Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar );
-    for ( const Sequence< PropertyValue >& rSeq : rAddonToolbar )
-    {
-        OUString   aURL;
-        OUString   aTitle;
-        OUString   aImageId;
-        OUString   aContext;
-        OUString   aTarget;
-        OUString   aControlType;
-        sal_uInt16 nWidth( 0 );
-
-        ToolBarMerger::ConvertSequenceToValues( rSeq, aURL, aTitle, aImageId, aTarget, aContext, aControlType, nWidth );
-
-        if ( IsCorrectContext( aModuleIdentifier, aContext ))
-        {
-            if ( aURL == "private:separator" ) // toolbox item separator
-            {
-                ToolBox::ImplToolItems::size_type nCount = m_pToolBar->GetItemCount();
-                if ( nCount > 0 && ( m_pToolBar->GetItemType( nCount-1 ) != ToolBoxItemType::SEPARATOR ) && nElements > 0 )
-                {
-                    nElements = 0;
-                    m_pToolBar->InsertSeparator();
-                }
-            }
-            else
-            {
-                ToolBox::ImplToolItems::size_type nCount = m_pToolBar->GetItemCount();
-                if ( bAppendSeparator && nCount > 0 && ( m_pToolBar->GetItemType( nCount-1 ) != ToolBoxItemType::SEPARATOR ))
-                {
-                    // We have to append a separator first if the last item is not a separator
-                    m_pToolBar->InsertSeparator();
-                }
-                bAppendSeparator = false;
-
-
-                m_pToolBar->InsertItem( nId, aTitle );
-
-                OUString aShortcut(vcl::CommandInfoProvider::GetCommandShortcut(aURL, m_xFrame));
-                if (!aShortcut.isEmpty())
-                    m_pToolBar->SetQuickHelpText(nId, aTitle + " (" + aShortcut + ")");
-
-                // don't setup images yet, AddonsToolbarWrapper::populateImages does that.
-
-                // Create TbRuntimeItemData to hold additional information we will need in the future
-                AddonsParams* pRuntimeItemData = new AddonsParams;
-                pRuntimeItemData->aImageId  = aImageId;
-                pRuntimeItemData->aControlType = aControlType;
-                pRuntimeItemData->nWidth    = nWidth;
-                m_pToolBar->SetItemData( nId, pRuntimeItemData );
-                m_pToolBar->SetItemCommand( nId, aURL );
-
-                Reference< XStatusListener > xController;
-
-                bool bMustBeInit( true );
-
-                // Support external toolbar controller for add-ons!
-                if ( m_xToolbarControllerFactory.is() &&
-                     m_xToolbarControllerFactory->hasController( aURL, m_aModuleIdentifier ))
-                {
-                    uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence(
-                    {
-                        {"ModuleIdentifier", uno::Any(m_aModuleIdentifier)},
-                        {"Frame", uno::Any(m_xFrame)},
-                        {"ServiceManager", uno::Any(Reference<XMultiServiceFactory>(m_xContext->getServiceManager(), UNO_QUERY_THROW))},
-                        {"ParentWindow", uno::Any(xToolbarWindow)},
-                        {"ItemId", uno::Any(sal_Int32( nId ))}
-                    }));
-                    try
-                    {
-                        xController.set( m_xToolbarControllerFactory->createInstanceWithArgumentsAndContext(
-                                            aURL, aArgs, m_xContext ),
-                                         UNO_QUERY );
-                    }
-                    catch ( uno::Exception& )
-                    {
-                    }
-                    bMustBeInit = false; // factory called init already!
-                }
-                else
-                {
-                    ::cppu::OWeakObject* pController = ToolBarMerger::CreateController( m_xContext, m_xFrame, m_pToolBar, aURL, nId, nWidth, aControlType );
-                    xController.set( pController, UNO_QUERY );
-                }
-
-                // insert controller to the map
-                m_aControllerMap[nId] = xController;
-
-                Reference< XInitialization > xInit( xController, UNO_QUERY );
-                if ( xInit.is() && bMustBeInit )
-                {
-                    PropertyValue aPropValue;
-                    Sequence< Any > aArgs( 3 );
-                    aPropValue.Name = "Frame";
-                    aPropValue.Value <<= m_xFrame;
-                    aArgs[0] <<= aPropValue;
-                    aPropValue.Name = "CommandURL";
-                    aPropValue.Value <<= aURL;
-                    aArgs[1] <<= aPropValue;
-                    aPropValue.Name = "ServiceManager";
-                    aPropValue.Value <<= Reference<XMultiServiceFactory>(m_xContext->getServiceManager(), UNO_QUERY_THROW);
-                    aArgs[2] <<= aPropValue;
-                    try
-                    {
-                        xInit->initialize( aArgs );
-                    }
-                    catch ( const uno::Exception& )
-                    {
-                    }
-                }
-
-                // Request an item window from the toolbar controller and set it at the VCL toolbar
-                Reference< XToolbarController > xTbxController( xController, UNO_QUERY );
-                if ( xTbxController.is() && xToolbarWindow.is() )
-                {
-                    Reference< XWindow > xWindow = xTbxController->createItemWindow( xToolbarWindow );
-                    if ( xWindow.is() )
-                    {
-                        VclPtr<vcl::Window> pItemWin = VCLUnoHelper::GetWindow( xWindow );
-                        if ( pItemWin )
-                        {
-                            WindowType nType = pItemWin->GetType();
-                            if ( nType == WindowType::LISTBOX || nType == WindowType::MULTILISTBOX || nType == WindowType::COMBOBOX )
-                                pItemWin->SetAccessibleName( m_pToolBar->GetItemText( nId ) );
-                            m_pToolBar->SetItemWindow( nId, pItemWin );
-                        }
-                    }
-                }
-
-                // Notify controller implementation to its listeners. Controller is now usable from outside.
-                Reference< XUpdatable > xUpdatable( xController, UNO_QUERY );
-                if ( xUpdatable.is() )
-                {
-                    try
-                    {
-                        xUpdatable->update();
-                    }
-                    catch ( const uno::Exception& )
-                    {
-                    }
-                }
-
-                ++nId;
-                ++nElements;
-            }
-        }
-    }
-
-    AddFrameActionListener();
-}
-
-IMPL_LINK_NOARG(AddonsToolBarManager, Click, ToolBox *, void)
-{
-    if ( m_bDisposed )
-        return;
-
-    sal_uInt16 nId( m_pToolBar->GetCurItemId() );
-    ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
-    if ( pIter != m_aControllerMap.end() )
-    {
-        Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
-
-        if ( xController.is() )
-            xController->click();
-    }
-}
-
-IMPL_LINK_NOARG(AddonsToolBarManager, DoubleClick, ToolBox *, void)
-{
-    if ( m_bDisposed )
-        return;
-
-    sal_uInt16 nId( m_pToolBar->GetCurItemId() );
-    ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
-    if ( pIter != m_aControllerMap.end() )
-    {
-        Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
-
-        if ( xController.is() )
-            xController->doubleClick();
-    }
-}
-
-IMPL_LINK_NOARG(AddonsToolBarManager, Select, ToolBox *, void)
-{
-    if ( m_bDisposed )
-        return;
-
-    sal_Int16   nKeyModifier( static_cast<sal_Int16>(m_pToolBar->GetModifier()) );
-    sal_uInt16      nId( m_pToolBar->GetCurItemId() );
-    ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
-    if ( pIter != m_aControllerMap.end() )
-    {
-        Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
-
-        if ( xController.is() )
-            xController->execute( nKeyModifier );
-    }
-}
-
-IMPL_LINK( AddonsToolBarManager, StateChanged, StateChangedType const *, pStateChangedType, void )
-{
-    if ( *pStateChangedType == StateChangedType::ControlBackground )
-    {
-        CheckAndUpdateImages();
-    }
-}
-
-IMPL_LINK( AddonsToolBarManager, DataChanged, DataChangedEvent const *, pDataChangedEvent, void )
-{
-    if ((( pDataChangedEvent->GetType() == DataChangedEventType::SETTINGS )   ||
-        (  pDataChangedEvent->GetType() == DataChangedEventType::DISPLAY  ))  &&
-        ( pDataChangedEvent->GetFlags() & AllSettingsFlags::STYLE        ))
-    {
-        CheckAndUpdateImages();
-    }
-
-    for ( ToolBox::ImplToolItems::size_type nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos )
-    {
-        const sal_uInt16 nId = m_pToolBar->GetItemId(nPos);
-        vcl::Window* pWindow = m_pToolBar->GetItemWindow( nId );
-        if ( pWindow )
-        {
-            const DataChangedEvent& rDCEvt( *pDataChangedEvent );
-            pWindow->DataChanged( rDCEvt );
-        }
-    }
-}
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/uielement/addonstoolbarwrapper.cxx b/framework/source/uielement/addonstoolbarwrapper.cxx
index 5d08fb5c7224..04193ac336c0 100644
--- a/framework/source/uielement/addonstoolbarwrapper.cxx
+++ b/framework/source/uielement/addonstoolbarwrapper.cxx
@@ -18,7 +18,7 @@
  */
 
 #include <uielement/addonstoolbarwrapper.hxx>
-#include <uielement/addonstoolbarmanager.hxx>
+#include <uielement/toolbarmanager.hxx>
 
 #include <com/sun/star/lang/DisposedException.hpp>
 #include <com/sun/star/ui/UIElementType.hpp>
@@ -97,7 +97,7 @@ void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArgument
 
     // Create VCL based toolbar which will be filled with settings data
     VclPtr<ToolBox> pToolBar;
-    AddonsToolBarManager* pToolBarManager = nullptr;
+    ToolBarManager* pToolBarManager = nullptr;
     {
         SolarMutexGuard aSolarMutexGuard;
         VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
@@ -107,7 +107,7 @@ void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArgument
 
             pToolBar = VclPtr<ToolBox>::Create( pWindow, nStyles );
             pToolBar->SetLineSpacing(true);
-            pToolBarManager = new AddonsToolBarManager( m_xContext, xFrame, m_aResourceURL, pToolBar );
+            pToolBarManager = new ToolBarManager( m_xContext, xFrame, m_aResourceURL, pToolBar );
             m_xToolBarManager.set( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
         }
     }
@@ -117,7 +117,7 @@ void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArgument
         if ( m_aConfigData.hasElements() && pToolBar && pToolBarManager )
         {
             // Fill toolbar with container contents
-            pToolBarManager->FillToolbar( m_aConfigData );
+            pToolBarManager->FillAddonToolbar( m_aConfigData );
             pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
             pToolBar->EnableCustomize();
             ::Size aActSize( pToolBar->GetSizePixel() );
@@ -138,7 +138,7 @@ Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface()
 
     if ( m_xToolBarManager.is() )
     {
-        AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
+        ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
         if ( pToolBarManager )
         {
             vcl::Window* pWindow = pToolBarManager->GetToolBar();
@@ -159,10 +159,10 @@ void AddonsToolBarWrapper::populateImages()
 
     if ( m_xToolBarManager.is() )
     {
-        AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
+        ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
         if (pToolBarManager)
         {
-            pToolBarManager->RefreshImages();
+            pToolBarManager->RequestImages();
             m_bCreatedImages = true;
         }
     }
diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx
index 009c4d75fbd3..738792c6e653 100644
--- a/framework/source/uielement/toolbarmanager.cxx
+++ b/framework/source/uielement/toolbarmanager.cxx
@@ -131,6 +131,20 @@ sal_Int16 getCurrentImageType()
     return nImageType;
 }
 
+bool IsCorrectContext( const OUString& rModuleIdentifier, const OUString& aContextList )
+{
+    if ( aContextList.isEmpty() )
+        return true;
+
+    if ( !rModuleIdentifier.isEmpty() )
+    {
+        sal_Int32 nIndex = aContextList.indexOf( rModuleIdentifier );
+        return ( nIndex >= 0 );
+    }
+
+    return false;
+}
+
 } // end anonymous namespace
 
 //  XInterface, XTypeProvider, XServiceInfo
@@ -726,7 +740,18 @@ void ToolBarManager::CreateControllers()
             pController = CreateToolBoxController( m_xFrame, m_pToolBar, nId, aCommandURL );
             if ( !pController )
             {
-                if ( m_pToolBar->GetItemData( nId ) != nullptr )
+
+                if ( aCommandURL.startsWith( ".uno:StyleApply?" ) )
+                {
+                    xController.set( new StyleToolbarController( m_xContext, m_xFrame, aCommandURL ));
+                    m_pToolBar->SetItemBits( nId, m_pToolBar->GetItemBits( nId ) | ToolBoxItemBits::CHECKABLE );
+                }
+                else if ( aCommandURL.startsWith( "private:resource/" ) )
+                {
+                    xController.set( m_xContext->getServiceManager()->createInstanceWithContext(
+                        "com.sun.star.comp.framework.GenericPopupToolbarController", m_xContext ), UNO_QUERY );
+                }
+                else if ( m_pToolBar->GetItemData( nId ) != nullptr )
                 {
                     // retrieve additional parameters
                     OUString aControlType = static_cast< AddonsParams* >( m_pToolBar->GetItemData( nId ))->aControlType;
@@ -743,16 +768,6 @@ void ToolBarManager::CreateControllers()
 
                     xController = xStatusListener;
                 }
-                else if ( aCommandURL.startsWith( ".uno:StyleApply?" ) )
-                {
-                    xController.set( new StyleToolbarController( m_xContext, m_xFrame, aCommandURL ));
-                    m_pToolBar->SetItemBits( nId, m_pToolBar->GetItemBits( nId ) | ToolBoxItemBits::CHECKABLE );
-                }
-                else if ( aCommandURL.startsWith( "private:resource/menubar/" ) )
-                {
-                    xController.set( m_xContext->getServiceManager()->createInstanceWithContext(
-                        "com.sun.star.comp.framework.GenericPopupToolbarController", m_xContext ), UNO_QUERY );
-                }
                 else
                 {
                     xController.set(
@@ -1162,6 +1177,86 @@ void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContaine
     }
 }
 
+void ToolBarManager::FillAddonToolbar( const Sequence< Sequence< PropertyValue > >& rAddonToolbar )
+{
+    SolarMutexGuard g;
+
+    if ( m_bDisposed )
+        return;
+
+    InitImageManager();
+
+    RemoveControllers();
+
+    // reset and fill command map
+    m_pToolBar->Clear();
+    m_aControllerMap.clear();
+    m_aCommandMap.clear();
+
+    sal_uInt16 nId( 1 );
+    CommandInfo aCmdInfo;
+    for ( const Sequence< PropertyValue >& rSeq : rAddonToolbar )
+    {
+        OUString   aURL;
+        OUString   aTitle;
+        OUString   aImageId;
+        OUString   aContext;
+        OUString   aTarget;
+        OUString   aControlType;
+        sal_uInt16 nWidth( 0 );
+
+        ToolBarMerger::ConvertSequenceToValues( rSeq, aURL, aTitle, aImageId, aTarget, aContext, aControlType, nWidth );
+
+        if ( IsCorrectContext( m_aModuleIdentifier, aContext ) )
+        {
+            if ( aURL == "private:separator" )
+            {
+                ToolBox::ImplToolItems::size_type nCount = m_pToolBar->GetItemCount();
+                if ( nCount > 0 && m_pToolBar->GetItemType( nCount-1 ) != ToolBoxItemType::SEPARATOR )
+                    m_pToolBar->InsertSeparator();
+            }
+            else
+            {
+                m_pToolBar->InsertItem( nId, aTitle );
+
+                OUString aShortcut(vcl::CommandInfoProvider::GetCommandShortcut(aURL, m_xFrame));
+                if (!aShortcut.isEmpty())
+                    m_pToolBar->SetQuickHelpText(nId, aTitle + " (" + aShortcut + ")");
+
+                // Create AddonsParams to hold additional information we will need in the future
+                AddonsParams* pRuntimeItemData = new AddonsParams;
+                pRuntimeItemData->aImageId = aImageId;
+                pRuntimeItemData->aControlType = aControlType;
+                pRuntimeItemData->nWidth = nWidth;
+                m_pToolBar->SetItemData( nId, pRuntimeItemData );
+                m_pToolBar->SetItemCommand( nId, aURL );
+
+                // Fill command map. It stores all our commands and from what
+                // image manager we got our image. So we can decide if we have to use an
+                // image from a notification message.
+                auto pIter = m_aCommandMap.emplace( aURL, aCmdInfo );
+                if ( pIter.second )
+                {
+                    aCmdInfo.nId = nId;
+                    pIter.first->second.nId = nId;
+                }
+                else
+                {
+                    pIter.first->second.aIds.push_back( nId );
+                }
+                ++nId;
+            }
+        }
+    }
+
+    // Don't setup images yet, AddonsToolbarWrapper::populateImages does that.
+    // (But some controllers might need an image at the toolbar at creation time!)
+    CreateControllers();
+
+    // Notify controllers that they are now correctly initialized and can start listening.
+    UpdateControllers();
+}
+
 void ToolBarManager::FillOverflowToolbar( ToolBox const * pParent )
 {
     CommandInfo aCmdInfo;
@@ -1385,11 +1480,6 @@ bool ToolBarManager::IsPluginMode() const
     return bPluginMode;
 }
 
-bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const
-{
-    return true;
-}
-
 void ToolBarManager::AddCustomizeMenuItems(ToolBox const * pToolBar)
 {
     // No config menu entries if command ".uno:ConfigureDialog" is not enabled
@@ -1420,56 +1510,35 @@ void ToolBarManager::AddCustomizeMenuItems(ToolBox const * pToolBar)
 
     VclPtr<PopupMenu> xVisibleItemsPopupMenu;
 
-    if (MenuItemAllowed(MENUITEM_TOOLBAR_VISIBLEBUTTON))
+    if (!m_aResourceName.startsWith("private:resource/toolbar/addon_"))
     {
         pMenu->InsertItem(MENUITEM_TOOLBAR_VISIBLEBUTTON, FwkResId(STR_TOOLBAR_VISIBLE_BUTTONS));
         xVisibleItemsPopupMenu = VclPtr<PopupMenu>::Create();
         pMenu->SetPopupMenu(MENUITEM_TOOLBAR_VISIBLEBUTTON, xVisibleItemsPopupMenu);
-    }
 
-    if (MenuItemAllowed(MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR) && m_pToolBar->IsCustomize())
-    {
-        pMenu->InsertItem(MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, FwkResId(STR_TOOLBAR_CUSTOMIZE_TOOLBAR));
-        pMenu->SetItemCommand(MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, ".uno:ConfigureToolboxVisible");
-    }
-
-    if (nGroupLen != pMenu->GetItemCount())
-    {
+        if (m_pToolBar->IsCustomize())
+        {
+            pMenu->InsertItem(MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, FwkResId(STR_TOOLBAR_CUSTOMIZE_TOOLBAR));
+            pMenu->SetItemCommand(MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, ".uno:ConfigureToolboxVisible");
+        }
         pMenu->InsertSeparator();
-        nGroupLen = pMenu->GetItemCount();
     }
 
     if (pToolBar->IsFloatingMode())
     {
-        if (MenuItemAllowed(MENUITEM_TOOLBAR_DOCKTOOLBAR))
-        {
-            pMenu->InsertItem(MENUITEM_TOOLBAR_DOCKTOOLBAR, FwkResId(STR_TOOLBAR_DOCK_TOOLBAR));
-            pMenu->SetAccelKey(MENUITEM_TOOLBAR_DOCKTOOLBAR, vcl::KeyCode(KEY_F10, true, true, false, false));
-        }
+        pMenu->InsertItem(MENUITEM_TOOLBAR_DOCKTOOLBAR, FwkResId(STR_TOOLBAR_DOCK_TOOLBAR));
+        pMenu->SetAccelKey(MENUITEM_TOOLBAR_DOCKTOOLBAR, vcl::KeyCode(KEY_F10, true, true, false, false));
     }
     else
     {
-        if (MenuItemAllowed(MENUITEM_TOOLBAR_UNDOCKTOOLBAR))
-        {
-            pMenu->InsertItem(MENUITEM_TOOLBAR_UNDOCKTOOLBAR, FwkResId(STR_TOOLBAR_UNDOCK_TOOLBAR));
-            pMenu->SetAccelKey(MENUITEM_TOOLBAR_UNDOCKTOOLBAR, vcl::KeyCode(KEY_F10, true, true, false, false));
-        }
-    }
-
-    if (MenuItemAllowed(MENUITEM_TOOLBAR_DOCKALLTOOLBAR))
-        pMenu->InsertItem(MENUITEM_TOOLBAR_DOCKALLTOOLBAR, FwkResId(STR_TOOLBAR_DOCK_ALL_TOOLBARS));
-
-    if (nGroupLen != pMenu->GetItemCount())
-    {
-        pMenu->InsertSeparator();
-        nGroupLen = pMenu->GetItemCount();
+        pMenu->InsertItem(MENUITEM_TOOLBAR_UNDOCKTOOLBAR, FwkResId(STR_TOOLBAR_UNDOCK_TOOLBAR));
+        pMenu->SetAccelKey(MENUITEM_TOOLBAR_UNDOCKTOOLBAR, vcl::KeyCode(KEY_F10, true, true, false, false));
     }
 
-    if (MenuItemAllowed(MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION))
-        pMenu->InsertItem(MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, FwkResId(STR_TOOLBAR_LOCK_TOOLBAR));
-
-    if (MenuItemAllowed(MENUITEM_TOOLBAR_CLOSE))
-        pMenu->InsertItem(MENUITEM_TOOLBAR_CLOSE, FwkResId(STR_TOOLBAR_CLOSE_TOOLBAR));
+    pMenu->InsertItem(MENUITEM_TOOLBAR_DOCKALLTOOLBAR, FwkResId(STR_TOOLBAR_DOCK_ALL_TOOLBARS));
+    pMenu->InsertSeparator();
+    pMenu->InsertItem(MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, FwkResId(STR_TOOLBAR_LOCK_TOOLBAR));
+    pMenu->InsertItem(MENUITEM_TOOLBAR_CLOSE, FwkResId(STR_TOOLBAR_CLOSE_TOOLBAR));
 
     if (m_pToolBar->IsCustomize())
     {
diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist
index 66f37795aa41..f080951b0d8c 100644
--- a/solenv/clang-format/excludelist
+++ b/solenv/clang-format/excludelist
@@ -4914,7 +4914,6 @@ framework/inc/uiconfiguration/imagemanager.hxx
 framework/inc/uiconfiguration/imagetype.hxx
 framework/inc/uiconfiguration/moduleimagemanager.hxx
 framework/inc/uiconfiguration/windowstateproperties.hxx
-framework/inc/uielement/addonstoolbarmanager.hxx
 framework/inc/uielement/addonstoolbarwrapper.hxx
 framework/inc/uielement/buttontoolbarcontroller.hxx
 framework/inc/uielement/comboboxtoolbarcontroller.hxx
@@ -5101,7 +5100,6 @@ framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
 framework/source/uiconfiguration/uicategorydescription.cxx
 framework/source/uiconfiguration/uiconfigurationmanager.cxx
 framework/source/uiconfiguration/windowstateconfiguration.cxx
-framework/source/uielement/addonstoolbarmanager.cxx
 framework/source/uielement/addonstoolbarwrapper.cxx
 framework/source/uielement/buttontoolbarcontroller.cxx
 framework/source/uielement/comboboxtoolbarcontroller.cxx


More information about the Libreoffice-commits mailing list