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