/src/libreoffice/include/svtools/toolboxcontroller.hxx
Line | Count | Source |
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 <comphelper/compbase.hxx> |
30 | | #include <comphelper/propcontainerimplhelper.hxx> |
31 | | #include <tools/link.hxx> |
32 | | #include <utility> |
33 | | #include <vcl/toolboxid.hxx> |
34 | | |
35 | | #include <unordered_map> |
36 | | |
37 | | namespace com::sun::star::frame { class XDispatch; } |
38 | | namespace com::sun::star::frame { class XFrame; } |
39 | | namespace com::sun::star::frame { class XLayoutManager; } |
40 | | namespace com::sun::star::uno { class XComponentContext; } |
41 | | namespace com::sun::star::util { class XURLTransformer; } |
42 | | |
43 | | namespace weld { class Builder; } |
44 | | namespace weld { class Toolbar; } |
45 | | |
46 | | class ToolBox; |
47 | | |
48 | | namespace svt |
49 | | { |
50 | | class ToolboxController; |
51 | | } |
52 | | |
53 | | // extern template otherwise the ref-counting magic here ends up duplicated across multiple libraries |
54 | | extern template class SAL_DLLPUBLIC_TEMPLATE comphelper::OPropertyArrayUsageHelper<svt::ToolboxController>; |
55 | | |
56 | | namespace svt |
57 | | { |
58 | | |
59 | | typedef comphelper::WeakComponentImplHelper< |
60 | | css::frame::XStatusListener, css::frame::XToolbarController, |
61 | | css::lang::XInitialization, css::util::XUpdatable > |
62 | | ToolboxController_Base; |
63 | | |
64 | | class SVT_DLLPUBLIC ToolboxController : |
65 | | public ::comphelper::OPropertyContainerImplHelper< |
66 | | ToolboxController_Base, ToolboxController > |
67 | | { |
68 | | private: |
69 | | bool m_bSupportVisible; |
70 | | public: |
71 | | ToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
72 | | const css::uno::Reference< css::frame::XFrame >& xFrame, |
73 | | OUString aCommandURL ); |
74 | | ToolboxController(); |
75 | | virtual ~ToolboxController() override; |
76 | | |
77 | | css::uno::Reference< css::frame::XFrame > getFrameInterface() const; |
78 | | const css::uno::Reference< css::uno::XComponentContext >& getContext() const; |
79 | | css::uno::Reference< css::frame::XLayoutManager > getLayoutManager() const; |
80 | | |
81 | | void updateStatus( const OUString& rCommandURL ); |
82 | | void updateStatus(); |
83 | | |
84 | | // XInitialization |
85 | | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) override; |
86 | | |
87 | | // XUpdatable |
88 | | virtual void SAL_CALL update() override; |
89 | | |
90 | | // XEventListener |
91 | | virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; |
92 | | |
93 | | // XStatusListener |
94 | | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override = 0; |
95 | | |
96 | | // XToolbarController |
97 | | virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override; |
98 | | virtual void SAL_CALL click() override; |
99 | | virtual void SAL_CALL doubleClick() override; |
100 | | virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() override; |
101 | | virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override; |
102 | | // OPropertyArrayUsageHelper |
103 | | virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; |
104 | | |
105 | | |
106 | 0 | const OUString& getCommandURL() const { return m_aCommandURL; } |
107 | 0 | const OUString& getModuleName() const { return m_sModuleName; } |
108 | | |
109 | | void dispatchCommand( const OUString& sCommandURL, const css::uno::Sequence< css::beans::PropertyValue >& rArgs, const OUString &rTarget = OUString() ); |
110 | | |
111 | | void enable( bool bEnable ); |
112 | | |
113 | 0 | bool IsInSidebar() const { return m_bSidebar; } |
114 | | |
115 | | protected: |
116 | | // weak component / custom disposal |
117 | | virtual void disposing(std::unique_lock<std::mutex>& rGuard) override; |
118 | | |
119 | | bool getToolboxId( ToolBoxItemId& rItemId, ToolBox** ppToolBox ); |
120 | | struct Listener |
121 | | { |
122 | | Listener( css::util::URL _aURL, css::uno::Reference< css::frame::XDispatch > _xDispatch ) : |
123 | 0 | aURL(std::move( _aURL )), xDispatch(std::move( _xDispatch )) {} |
124 | | |
125 | | css::util::URL aURL; |
126 | | css::uno::Reference< css::frame::XDispatch > xDispatch; |
127 | | }; |
128 | | |
129 | | struct DispatchInfo |
130 | | { |
131 | | css::uno::Reference< css::frame::XDispatch > mxDispatch; |
132 | | const css::util::URL maURL; |
133 | | const css::uno::Sequence< css::beans::PropertyValue > maArgs; |
134 | | |
135 | | DispatchInfo( css::uno::Reference< css::frame::XDispatch > xDispatch, |
136 | | css::util::URL aURL, |
137 | | const css::uno::Sequence< css::beans::PropertyValue >& rArgs ) |
138 | 0 | : mxDispatch(std::move( xDispatch )) |
139 | 0 | , maURL(std::move( aURL )) |
140 | 0 | , maArgs( rArgs ) |
141 | 0 | {} |
142 | | }; |
143 | | |
144 | | DECL_DLLPRIVATE_STATIC_LINK( ToolboxController, ExecuteHdl_Impl, void*, void ); |
145 | | |
146 | | typedef std::unordered_map< OUString, |
147 | | css::uno::Reference< css::frame::XDispatch > > URLToDispatchMap; |
148 | | |
149 | | // methods to support status forwarder, known by the old sfx2 toolbox controller implementation |
150 | | void addStatusListener( const OUString& rCommandURL ); |
151 | | void removeStatusListener( const OUString& rCommandURL ); |
152 | | void bindListener(); |
153 | | void unbindListener(); |
154 | | |
155 | | // TODO remove |
156 | 0 | const css::uno::Reference< css::util::XURLTransformer >& getURLTransformer() const { return m_xUrlTransformer;} |
157 | | // TODO remove |
158 | 0 | const css::uno::Reference< css::awt::XWindow >& getParent() const { return m_xParentWindow;} |
159 | | |
160 | | bool m_bInitialized, |
161 | | m_bSidebar; |
162 | | ToolBoxItemId m_nToolBoxId; |
163 | | css::uno::Reference< css::frame::XFrame > m_xFrame; |
164 | | css::uno::Reference< css::uno::XComponentContext > m_xContext; |
165 | | OUString m_aCommandURL; |
166 | | URLToDispatchMap m_aListenerMap; |
167 | | |
168 | | css::uno::Reference< css::awt::XWindow > m_xParentWindow; |
169 | | css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer; |
170 | | OUString m_sModuleName; |
171 | | weld::Toolbar* m_pToolbar; |
172 | | weld::Builder* m_pBuilder; |
173 | | }; |
174 | | |
175 | | } |
176 | | |
177 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |