Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/svtools/toolboxcontroller.hxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#pragma once
21
22
#include <svtools/svtdllapi.h>
23
#include <com/sun/star/beans/PropertyValue.hpp>
24
#include <com/sun/star/frame/XStatusListener.hpp>
25
#include <com/sun/star/frame/XToolbarController.hpp>
26
#include <com/sun/star/lang/XInitialization.hpp>
27
#include <com/sun/star/util/XUpdatable.hpp>
28
#include <com/sun/star/uno/Sequence.hxx>
29
#include <cppuhelper/implbase.hxx>
30
#include <comphelper/multicontainer2.hxx>
31
#include <comphelper/broadcasthelper.hxx>
32
#include <comphelper/proparrhlp.hxx>
33
#include <comphelper/propertycontainer.hxx>
34
#include <cppuhelper/propshlp.hxx>
35
#include <tools/link.hxx>
36
#include <utility>
37
#include <vcl/toolboxid.hxx>
38
39
#include <unordered_map>
40
41
namespace com :: sun :: star :: frame { class XDispatch; }
42
namespace com :: sun :: star :: frame { class XFrame; }
43
namespace com :: sun :: star :: frame { class XLayoutManager; }
44
namespace com :: sun :: star :: uno { class XComponentContext; }
45
namespace com :: sun :: star :: util { class XURLTransformer; }
46
47
class ToolBox;
48
49
namespace weld
50
{
51
    class Builder;
52
    class Toolbar;
53
}
54
55
namespace svt
56
{
57
58
typedef cppu::WeakImplHelper<
59
        css::frame::XStatusListener, css::frame::XToolbarController,
60
        css::lang::XInitialization, css::util::XUpdatable,
61
        css::lang::XComponent >
62
    ToolboxController_Base;
63
64
class SVT_DLLPUBLIC ToolboxController :
65
                          public ToolboxController_Base,
66
                          public ::comphelper::OMutexAndBroadcastHelper,
67
                          public ::comphelper::OPropertyContainer,
68
                          public ::comphelper::OPropertyArrayUsageHelper< ToolboxController >
69
{
70
    private:
71
        bool  m_bSupportVisible;
72
    public:
73
        ToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
74
                           const css::uno::Reference< css::frame::XFrame >& xFrame,
75
                           OUString aCommandURL );
76
        ToolboxController();
77
        virtual ~ToolboxController() override;
78
79
        css::uno::Reference< css::frame::XFrame > getFrameInterface() const;
80
        const css::uno::Reference< css::uno::XComponentContext >& getContext() const;
81
        css::uno::Reference< css::frame::XLayoutManager > getLayoutManager() const;
82
83
        void updateStatus( const OUString& rCommandURL );
84
        void updateStatus();
85
86
        // XInterface
87
        virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& rType ) override;
88
        virtual void SAL_CALL acquire() noexcept override;
89
        virtual void SAL_CALL release() noexcept override;
90
        virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
91
92
        // XInitialization
93
        virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) override;
94
95
        // XUpdatable
96
        virtual void SAL_CALL update() override;
97
98
        // XComponent
99
        virtual void SAL_CALL dispose() override;
100
        virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
101
        virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rListener ) override;
102
103
        // XEventListener
104
        using cppu::OPropertySetHelper::disposing;
105
        virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
106
107
        // XStatusListener
108
        virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override = 0;
109
110
        // XToolbarController
111
        virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
112
        virtual void SAL_CALL click() override;
113
        virtual void SAL_CALL doubleClick() override;
114
        virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() override;
115
        virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
116
        // OPropertySetHelper
117
        virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override;
118
        virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any& rConvertedValue, css::uno::Any& rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue) override;
119
        // XPropertySet
120
        virtual css::uno::Reference< css::beans::XPropertySetInfo>  SAL_CALL getPropertySetInfo() override;
121
        virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
122
        // OPropertyArrayUsageHelper
123
        virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
124
125
126
0
        const OUString& getCommandURL() const { return  m_aCommandURL; }
127
0
        const OUString& getModuleName() const { return m_sModuleName; }
128
129
        void dispatchCommand( const OUString& sCommandURL, const css::uno::Sequence< css::beans::PropertyValue >& rArgs, const OUString &rTarget = OUString() );
130
131
        void enable( bool bEnable );
132
133
0
        bool IsInSidebar() const { return m_bSidebar; }
134
135
    protected:
136
        bool getToolboxId( ToolBoxItemId& rItemId, ToolBox** ppToolBox );
137
        struct Listener
138
        {
139
            Listener( css::util::URL _aURL, css::uno::Reference< css::frame::XDispatch > _xDispatch ) :
140
0
                aURL(std::move( _aURL )), xDispatch(std::move( _xDispatch )) {}
141
142
            css::util::URL aURL;
143
            css::uno::Reference< css::frame::XDispatch > xDispatch;
144
        };
145
146
        struct DispatchInfo
147
        {
148
            css::uno::Reference< css::frame::XDispatch > mxDispatch;
149
            const css::util::URL maURL;
150
            const css::uno::Sequence< css::beans::PropertyValue > maArgs;
151
152
            DispatchInfo( css::uno::Reference< css::frame::XDispatch > xDispatch,
153
                          css::util::URL aURL,
154
                          const css::uno::Sequence< css::beans::PropertyValue >& rArgs )
155
0
                : mxDispatch(std::move( xDispatch ))
156
0
                , maURL(std::move( aURL ))
157
0
                , maArgs( rArgs )
158
0
                {}
159
        };
160
161
        DECL_DLLPRIVATE_STATIC_LINK( ToolboxController, ExecuteHdl_Impl, void*, void );
162
163
        typedef std::unordered_map< OUString,
164
                                    css::uno::Reference< css::frame::XDispatch > > URLToDispatchMap;
165
166
        // methods to support status forwarder, known by the old sfx2 toolbox controller implementation
167
        void addStatusListener( const OUString& rCommandURL );
168
        void removeStatusListener( const OUString& rCommandURL );
169
        void bindListener();
170
        void unbindListener();
171
172
        // TODO remove
173
0
        const css::uno::Reference< css::util::XURLTransformer >& getURLTransformer() const { return m_xUrlTransformer;}
174
        // TODO remove
175
0
        const css::uno::Reference< css::awt::XWindow >& getParent() const { return m_xParentWindow;}
176
177
        bool                                                      m_bInitialized,
178
                                                                  m_bDisposed,
179
                                                                  m_bSidebar;
180
        ToolBoxItemId                                             m_nToolBoxId;
181
        css::uno::Reference< css::frame::XFrame >                 m_xFrame;
182
        css::uno::Reference< css::uno::XComponentContext >        m_xContext;
183
        OUString                                                  m_aCommandURL;
184
        URLToDispatchMap                                          m_aListenerMap;
185
        comphelper::OMultiTypeInterfaceContainerHelper2           m_aListenerContainer;   /// container for ALL Listener
186
187
        css::uno::Reference< css::awt::XWindow >                  m_xParentWindow;
188
        css::uno::Reference< css::util::XURLTransformer >         m_xUrlTransformer;
189
        OUString                                                  m_sModuleName;
190
        weld::Toolbar*                                            m_pToolbar;
191
        weld::Builder*                                            m_pBuilder;
192
};
193
194
}
195
196
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */