1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include <string_view>
29 #include <o3tl/typed_flags_set.hxx>
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>
35 #include <svl/SfxBroadcaster.hxx>
36 #include <sfx2/shell.hxx>
38 namespace com::sun::star::frame
{ class XDispatch
; }
39 namespace com::sun::star::frame
{ class XDispatchProvider
; }
40 namespace com::sun::star::frame
{ class XDispatchRecorder
; }
41 namespace com::sun::star::frame
{ class XFrame
; }
42 namespace com::sun::star::util
{ struct URL
; }
46 class SfxControllerItem
;
50 class SfxBindings_Impl
;
53 struct SfxFoundCache_Impl
;
54 class SfxFoundCacheArr_Impl
;
56 enum class SfxCallMode
: sal_uInt16
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)
67 template<> struct typed_flags
<SfxCallMode
>: is_typed_flags
<SfxCallMode
, 0x0F>
72 class SFX2_DLLPUBLIC SfxBindings final
: public SfxBroadcaster
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>.
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>.
93 friend class SfxApplication
;
94 friend class SfxShell
;
95 friend class SfxBindings_Impl
;
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
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
,
107 const SfxSlotServer
**, SfxFoundCacheArr_Impl
&);
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
);
120 virtual ~SfxBindings() override
;
122 void HidePopups( bool bHide
= true );
124 void SetDispatcher(SfxDispatcher
*pDisp
);
126 void Update( sal_uInt16 nId
); // For example, from Menu::Activate
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
);
139 SfxStateCache
* GetStateCache( sal_uInt16 nId
);
140 SAL_DLLPRIVATE SfxStateCache
* GetAnyStateCache_Impl( sal_uInt16 nId
);
142 * @param rpState the caller has to delete the pointer
144 SfxItemState
QueryState( sal_uInt16 nSID
, std::unique_ptr
<SfxPoolItem
> &rpState
);
146 SfxItemState
QueryState( TypedWhichId
<T
> nSID
, std::unique_ptr
<T
> &rpState
)
148 std::unique_ptr
<SfxPoolItem
> tmp
;
149 auto ret
= QueryState(sal_uInt16(nSID
), tmp
);
150 rpState
.reset(static_cast<T
*>(tmp
.release()));
154 void QueryControlState ( sal_uInt16 nSID
, boost::property_tree::ptree
& rState
);
156 sal_uInt16
QuerySlotId( const css::util::URL
& aURL
);
158 const SfxPoolItem
* ExecuteSynchron( sal_uInt16 nSlot
,
159 const SfxPoolItem
**pArgs
= nullptr);
160 bool Execute( sal_uInt16 nSlot
,
161 const SfxPoolItem
**pArgs
= nullptr,
162 SfxCallMode nCall
= SfxCallMode::SLOT
);
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;
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
);
172 SfxDispatcher
* GetDispatcher() const
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
);
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__ )
200 #define ENTERREGISTRATIONS() EnterRegistrations()
201 #define LEAVEREGISTRATIONS() LeaveRegistrations()
202 #define DENTERREGISTRATIONS() EnterRegistrations()
203 #define DLEAVEREGISTRATIONS() LeaveRegistrations()
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */