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