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