LibreOffice Module svtools (master) 1
toolboxcontroller.hxx
Go to the documentation of this file.
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>
35#include <tools/link.hxx>
36#include <utility>
37#include <vcl/toolboxid.hxx>
38
39#include <unordered_map>
40
41namespace com :: sun :: star :: frame { class XDispatch; }
42namespace com :: sun :: star :: frame { class XFrame; }
43namespace com :: sun :: star :: frame { class XLayoutManager; }
44namespace com :: sun :: star :: uno { class XComponentContext; }
45namespace com :: sun :: star :: util { class XURLTransformer; }
46
47class ToolBox;
48
49namespace weld
50{
51 class Builder;
52 class Toolbar;
53}
54
55namespace svt
56{
57
58typedef cppu::WeakImplHelper<
59 css::frame::XStatusListener, css::frame::XToolbarController,
60 css::lang::XInitialization, css::util::XUpdatable,
61 css::lang::XComponent >
63
68 public ::comphelper::OPropertyArrayUsageHelper< ToolboxController >
69{
70 private:
72 public:
73 ToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
74 const css::uno::Reference< css::frame::XFrame >& xFrame,
75 OUString aCommandURL );
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& aCommandURL );
84 void updateStatus();
85
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;
91
92 // XInitialization
93 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) 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 >& aListener ) 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 const OUString& getCommandURL() const { return m_aCommandURL; }
127 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 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 aURL(std::move( _aURL )), xDispatch(std::move( _xDispatch )) {}
141
142 css::util::URL aURL;
143 css::uno::Reference< css::frame::XDispatch > xDispatch;
144 };
145
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 : mxDispatch(std::move( xDispatch ))
156 , maURL(std::move( aURL ))
157 , maArgs( rArgs )
158 {}
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& aCommandURL );
168 void removeStatusListener( const OUString& aCommandURL );
169 void bindListener();
170 void unbindListener();
171
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;}
176
181 css::uno::Reference< css::frame::XFrame > m_xFrame;
182 css::uno::Reference< css::uno::XComponentContext > m_xContext;
186
187 css::uno::Reference< css::awt::XWindow > m_xParentWindow;
188 css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer;
192};
193
194}
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::awt::XWindow > m_xParentWindow
container for ALL Listener
URLToDispatchMap m_aListenerMap
DECL_DLLPRIVATE_STATIC_LINK(ToolboxController, ExecuteHdl_Impl, void *, void)
const OUString & getModuleName() const
comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerContainer
const css::uno::Reference< css::util::XURLTransformer > & getURLTransformer() const
const css::uno::Reference< css::awt::XWindow > & getParent() const
std::unordered_map< OUString, css::uno::Reference< css::frame::XDispatch > > URLToDispatchMap
css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer
ToolboxController(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &xFrame, OUString aCommandURL)
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Reference< css::frame::XFrame > m_xFrame
Reference< XDispatch > xDispatch
URL aURL
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
Type
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
cppu::WeakImplHelper< css::frame::XStatusListener, css::frame::XToolbarController, css::lang::XInitialization, css::util::XUpdatable, css::lang::XComponent > ToolboxController_Base
const URL maURL
const Sequence< PropertyValue > maArgs
Reference< XDispatch > mxDispatch
css::uno::Reference< css::frame::XDispatch > mxDispatch
const css::uno::Sequence< css::beans::PropertyValue > maArgs
DispatchInfo(css::uno::Reference< css::frame::XDispatch > xDispatch, css::util::URL aURL, const css::uno::Sequence< css::beans::PropertyValue > &rArgs)
Listener(css::util::URL _aURL, css::uno::Reference< css::frame::XDispatch > _xDispatch)
css::uno::Reference< css::frame::XDispatch > xDispatch
#define SVT_DLLPUBLIC
Definition: svtdllapi.h:27
unsigned char sal_Bool