Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / svtools / toolboxcontroller.hxx
blob276b9106011cf6eb6c1082cfeb0b6d54de87bc95
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
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>
39 #include <unordered_map>
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; }
47 class ToolBox;
49 namespace weld
51 class Builder;
52 class Toolbar;
55 namespace svt
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;
64 class SVT_DLLPUBLIC ToolboxController :
65 public ToolboxController_Base,
66 public ::comphelper::OMutexAndBroadcastHelper,
67 public ::comphelper::OPropertyContainer,
68 public ::comphelper::OPropertyArrayUsageHelper< ToolboxController >
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;
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;
83 void updateStatus( const OUString& aCommandURL );
84 void updateStatus();
86 // XInterface
87 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) 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;
92 // XInitialization
93 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
95 // XUpdatable
96 virtual void SAL_CALL update() override;
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 >& aListener ) override;
103 // XEventListener
104 using cppu::OPropertySetHelper::disposing;
105 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
107 // XStatusListener
108 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override = 0;
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;
126 const OUString& getCommandURL() const { return m_aCommandURL; }
127 const OUString& getModuleName() const { return m_sModuleName; }
129 void dispatchCommand( const OUString& sCommandURL, const css::uno::Sequence< css::beans::PropertyValue >& rArgs, const OUString &rTarget = OUString() );
131 void enable( bool bEnable );
133 bool IsInSidebar() const { return m_bSidebar; }
135 protected:
136 bool getToolboxId( ToolBoxItemId& rItemId, ToolBox** ppToolBox );
137 struct Listener
139 Listener( css::util::URL _aURL, css::uno::Reference< css::frame::XDispatch > _xDispatch ) :
140 aURL(std::move( _aURL )), xDispatch(std::move( _xDispatch )) {}
142 css::util::URL aURL;
143 css::uno::Reference< css::frame::XDispatch > xDispatch;
146 struct DispatchInfo
148 css::uno::Reference< css::frame::XDispatch > mxDispatch;
149 const css::util::URL maURL;
150 const css::uno::Sequence< css::beans::PropertyValue > maArgs;
152 DispatchInfo( css::uno::Reference< css::frame::XDispatch > xDispatch,
153 css::util::URL aURL,
154 const css::uno::Sequence< css::beans::PropertyValue >& rArgs )
155 : mxDispatch(std::move( xDispatch ))
156 , maURL(std::move( aURL ))
157 , maArgs( rArgs )
161 DECL_DLLPRIVATE_STATIC_LINK( ToolboxController, ExecuteHdl_Impl, void*, void );
163 typedef std::unordered_map< OUString,
164 css::uno::Reference< css::frame::XDispatch > > URLToDispatchMap;
166 // methods to support status forwarder, known by the old sfx2 toolbox controller implementation
167 void addStatusListener( const OUString& aCommandURL );
168 void removeStatusListener( const OUString& aCommandURL );
169 void bindListener();
170 void unbindListener();
172 // TODO remove
173 const css::uno::Reference< css::util::XURLTransformer >& getURLTransformer() const { return m_xUrlTransformer;}
174 // TODO remove
175 const css::uno::Reference< css::awt::XWindow >& getParent() const { return m_xParentWindow;}
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
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;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */