/src/libreoffice/include/sfx2/bindings.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 | | #ifndef INCLUDED_SFX2_BINDINGS_HXX |
20 | | #define INCLUDED_SFX2_BINDINGS_HXX |
21 | | |
22 | | #include <sal/config.h> |
23 | | |
24 | | #include <cstddef> |
25 | | #include <memory> |
26 | | #include <optional> |
27 | | #include <string_view> |
28 | | |
29 | | #include <o3tl/typed_flags_set.hxx> |
30 | | #include <sfx2/dllapi.h> |
31 | | #include <sal/types.h> |
32 | | #include <tools/link.hxx> |
33 | | #include <svl/poolitem.hxx> |
34 | | #include <svl/SfxBroadcaster.hxx> |
35 | | #include <svl/typedwhich.hxx> |
36 | | |
37 | | #include <boost/property_tree/ptree_fwd.hpp> |
38 | | |
39 | | namespace com::sun::star::frame { class XDispatch; } |
40 | | namespace com::sun::star::frame { class XDispatchProvider; } |
41 | | namespace com::sun::star::frame { class XDispatchRecorder; } |
42 | | namespace com::sun::star::frame { class XFrame; } |
43 | | namespace com::sun::star::util { struct URL; } |
44 | | namespace com::sun::star::uno { template <class interface_type> class Reference; } |
45 | | |
46 | | class SfxSlot; |
47 | | class SfxSlotServer; |
48 | | class SfxControllerItem; |
49 | | class SfxStateCache; |
50 | | class SfxItemSet; |
51 | | class SfxDispatcher; |
52 | | class SfxBindings_Impl; |
53 | | class Timer; |
54 | | class SfxWorkWindow; |
55 | | struct SfxFoundCache_Impl; |
56 | | class SfxFoundCacheArr_Impl; |
57 | | class SfxPoolItemHolder; |
58 | | class SfxRequest; |
59 | | class SfxShell; |
60 | | enum class SfxItemState; |
61 | | |
62 | | enum class SfxCallMode : sal_uInt16 |
63 | | { |
64 | | SLOT = 0x00, // sync/async from Slot |
65 | | SYNCHRON = 0x01, // synchronously in the same Stackframe |
66 | | ASYNCHRON = 0x02, // asynchronously via AppEvent |
67 | | RECORD = 0x04, // take into account while recording |
68 | | API = 0x08 // API call (silent) |
69 | | }; |
70 | | |
71 | | namespace o3tl { |
72 | | |
73 | | template<> struct typed_flags<SfxCallMode>: is_typed_flags<SfxCallMode, 0x0F> |
74 | | {}; |
75 | | |
76 | | } |
77 | | |
78 | | class SFX2_DLLPUBLIC SfxBindings final : public SfxBroadcaster |
79 | | |
80 | | /* [Description] |
81 | | |
82 | | In each SFx application one instance of the SfxBindings-Class will |
83 | | exists from <SfxApplication::Init()> until <SfxApplication::Exit()>. |
84 | | This instance is automatically created and destroyed by SfxApplication. |
85 | | However these instances will be handled by the Macro <SFX_BINDINGS> |
86 | | or the associated <SfxViewFrame>. |
87 | | |
88 | | The SfxBindings manages all of its Slot-Ids bound by the registered |
89 | | controllers and keeps a cache of the <Slot-Server> respectively. |
90 | | (it is what we call the combination of SfxShell instance and SfxSlot). |
91 | | In the SfxBindings it is stored, if and in this case which controllers |
92 | | that are dirty and which Slot-Server-Caches are dirty respectively. |
93 | | It summarizes status queries (calls to the status methods specified |
94 | | in the IDL) that are served by the same state methods, and handles |
95 | | the simulation of <Pseudo-Slots>. |
96 | | */ |
97 | | |
98 | | { |
99 | | friend class SfxApplication; |
100 | | friend class SfxShell; |
101 | | friend class SfxBindings_Impl; |
102 | | |
103 | | std::unique_ptr< SfxBindings_Impl> pImpl; // Data of the Bindings instance |
104 | | SfxDispatcher* pDispatcher; // Dispatcher, to be used |
105 | | sal_uInt16 nRegLevel; // Lock-Level while Reconfig |
106 | | |
107 | | private: |
108 | | SAL_DLLPRIVATE SfxPoolItemHolder Execute_Impl(sal_uInt16 nSlot, const SfxPoolItem** pArgs, |
109 | | SfxCallMode nCall); |
110 | | SAL_DLLPRIVATE void SetSubBindings_Impl( SfxBindings* ); |
111 | | SAL_DLLPRIVATE void UpdateSlotServer_Impl(); // Update SlotServer |
112 | | SAL_DLLPRIVATE std::optional<SfxItemSet> CreateSet_Impl(SfxStateCache& rCache, const SfxSlot* &pRealSlot, |
113 | | const SfxSlotServer**, SfxFoundCacheArr_Impl&); |
114 | | SAL_DLLPRIVATE std::size_t GetSlotPos( sal_uInt16 nId, std::size_t nStartSearchAt = 0 ); |
115 | | SAL_DLLPRIVATE void Update_Impl(SfxStateCache& rCache); |
116 | | static SAL_DLLPRIVATE void UpdateControllers_Impl( |
117 | | const SfxFoundCache_Impl& rFound, |
118 | | const SfxPoolItem *pItem, |
119 | | SfxItemState eItemState ); |
120 | | SAL_DLLPRIVATE SfxStateCache* GetStateCache( sal_uInt16 nId, std::size_t * pPos); |
121 | | DECL_DLLPRIVATE_LINK( NextJob, Timer *, void ); |
122 | | SAL_DLLPRIVATE bool NextJob_Impl(Timer const * pTimer); |
123 | | |
124 | | public: |
125 | | SfxBindings(); |
126 | | virtual ~SfxBindings() override; |
127 | | |
128 | | void HidePopups( bool bHide = true ); |
129 | | |
130 | | void SetDispatcher(SfxDispatcher *pDisp); |
131 | | |
132 | | void Update( sal_uInt16 nId ); // For example, from Menu::Activate |
133 | | void Update(); |
134 | | SAL_DLLPRIVATE void StartUpdate_Impl(bool bComplete=false); |
135 | | void Invalidate( sal_uInt16 nId ); |
136 | | void Invalidate( const sal_uInt16* pIds ); |
137 | | void InvalidateShell( const SfxShell &rSh, bool bDeep = false ); |
138 | | void InvalidateAll( bool bWithMsg ); |
139 | | void SetState( const SfxItemSet &rSet ); |
140 | | void SetState( const SfxPoolItem &rItem ); |
141 | | void Invalidate( sal_uInt16 nId, bool bWithItem, bool bWithMsg=false); |
142 | | bool IsInUpdate() const; |
143 | | void SetVisibleState( sal_uInt16 nId, bool bShow ); |
144 | | |
145 | | SfxStateCache* GetStateCache( sal_uInt16 nId); |
146 | | SAL_DLLPRIVATE SfxStateCache* GetAnyStateCache_Impl( sal_uInt16 nId ); |
147 | | /** |
148 | | * @param rpState the caller has to delete the pointer |
149 | | */ |
150 | | SfxItemState QueryState( sal_uInt16 nSID, std::unique_ptr<SfxPoolItem> &rpState ); |
151 | | template<class T> |
152 | | SfxItemState QueryState( TypedWhichId<T> nSID, std::unique_ptr<T> &rpState ) |
153 | 0 | { |
154 | 0 | std::unique_ptr<SfxPoolItem> tmp; |
155 | 0 | auto ret = QueryState(sal_uInt16(nSID), tmp); |
156 | 0 | rpState.reset(static_cast<T*>(tmp.release())); |
157 | 0 | return ret; |
158 | 0 | } Unexecuted instantiation: SfxItemState SfxBindings::QueryState<SfxUInt16Item>(TypedWhichId<SfxUInt16Item>, std::__1::unique_ptr<SfxUInt16Item, std::__1::default_delete<SfxUInt16Item> >&) Unexecuted instantiation: SfxItemState SfxBindings::QueryState<SfxBoolItem>(TypedWhichId<SfxBoolItem>, std::__1::unique_ptr<SfxBoolItem, std::__1::default_delete<SfxBoolItem> >&) |
159 | | |
160 | | void QueryControlState ( sal_uInt16 nSID, boost::property_tree::ptree& rState ); |
161 | | |
162 | | sal_uInt16 QuerySlotId( const css::util::URL& aURL ); |
163 | | |
164 | | SfxPoolItemHolder ExecuteSynchron( sal_uInt16 nSlot, |
165 | | const SfxPoolItem **pArgs = nullptr); |
166 | | SfxPoolItemHolder Execute( sal_uInt16 nSlot, |
167 | | const SfxPoolItem **pArgs = nullptr, |
168 | | SfxCallMode nCall = SfxCallMode::SLOT); |
169 | | |
170 | | SAL_DLLPRIVATE void SetDispatchProvider_Impl( const css::uno::Reference< css::frame::XDispatchProvider > & rFrame ); |
171 | | void SetActiveFrame( const css::uno::Reference< css::frame::XFrame > & rFrame ); |
172 | | css::uno::Reference< css::frame::XFrame > GetActiveFrame() const; |
173 | | // Reconfig |
174 | | sal_uInt16 EnterRegistrations( std::string_view pFile = {}, int nLine = 0); |
175 | | void LeaveRegistrations( std::string_view pFile = {}, int nLine = 0 ); |
176 | | void Register( SfxControllerItem& rBinding ); |
177 | | void Release( SfxControllerItem& rBinding ); |
178 | | SfxDispatcher* GetDispatcher() const |
179 | 28.5k | { return pDispatcher; } |
180 | | const css::uno::Reference< css::frame::XDispatchRecorder >& GetRecorder() const; |
181 | | css::uno::Reference < css::frame::XDispatch > |
182 | | GetDispatch( const SfxSlot*, const css::util::URL& aURL, bool bMasterCommand ); |
183 | | SAL_DLLPRIVATE void ContextChanged_Impl(); |
184 | | SAL_DLLPRIVATE void Execute_Impl( SfxRequest& rReq, const SfxSlot* pSlot, SfxShell* pShell ); |
185 | | SAL_DLLPRIVATE void DeleteControllers_Impl(); |
186 | 204k | SAL_DLLPRIVATE SfxDispatcher* GetDispatcher_Impl() { return pDispatcher; } |
187 | | SAL_DLLPRIVATE void ClearCache_Impl( sal_uInt16 nSlotId ); |
188 | | SAL_DLLPRIVATE void RegisterInternal_Impl( SfxControllerItem& rBinding ); |
189 | | SAL_DLLPRIVATE void Register_Impl( SfxControllerItem& rBinding, bool ); |
190 | | SAL_DLLPRIVATE SfxWorkWindow* GetWorkWindow_Impl() const; |
191 | | SAL_DLLPRIVATE void SetWorkWindow_Impl( std::unique_ptr<SfxWorkWindow> ); |
192 | | SAL_DLLPRIVATE SfxBindings* GetSubBindings_Impl() const; |
193 | | SAL_DLLPRIVATE void SetRecorder_Impl( css::uno::Reference< css::frame::XDispatchRecorder > const & ); |
194 | | SAL_DLLPRIVATE void InvalidateSlotsInMap_Impl(); |
195 | | SAL_DLLPRIVATE void AddSlotToInvalidateSlotsMap_Impl( sal_uInt16 nId ); |
196 | | Timer& GetTimer(); |
197 | | }; |
198 | | |
199 | | #ifdef DBG_UTIL |
200 | | #define ENTERREGISTRATIONS() EnterRegistrations(__FILE__, __LINE__) |
201 | | #define LEAVEREGISTRATIONS() LeaveRegistrations(__FILE__, __LINE__) |
202 | | #define DENTERREGISTRATIONS() \ |
203 | | EnterRegistrations( Concat2View(OString::Concat(__FILE__) + "(" + OString::number(reinterpret_cast<sal_Int64>(this)) + ")"), __LINE__ ) |
204 | | #define DLEAVEREGISTRATIONS( ) \ |
205 | | LeaveRegistrations( Concat2View(OString::Concat(__FILE__) + "(" + OString::number(reinterpret_cast<sal_Int64>(this)) + ")"), __LINE__ ) |
206 | | #else |
207 | 102k | #define ENTERREGISTRATIONS() EnterRegistrations() |
208 | 93.8k | #define LEAVEREGISTRATIONS() LeaveRegistrations() |
209 | 32.6k | #define DENTERREGISTRATIONS() EnterRegistrations() |
210 | 32.6k | #define DLEAVEREGISTRATIONS() LeaveRegistrations() |
211 | | #endif |
212 | | |
213 | | |
214 | | #endif |
215 | | |
216 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |