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 void QueryControlState ( sal_uInt16 nSID
, boost::property_tree::ptree
& rState
);
147 const SfxPoolItem
* ExecuteSynchron( sal_uInt16 nSlot
,
148 const SfxPoolItem
**pArgs
= nullptr);
149 bool Execute( sal_uInt16 nSlot
,
150 const SfxPoolItem
**pArgs
= nullptr,
151 SfxCallMode nCall
= SfxCallMode::SLOT
);
153 SAL_DLLPRIVATE
void SetDispatchProvider_Impl( const css::uno::Reference
< css::frame::XDispatchProvider
> & rFrame
);
154 void SetActiveFrame( const css::uno::Reference
< css::frame::XFrame
> & rFrame
);
155 css::uno::Reference
< css::frame::XFrame
> GetActiveFrame() const;
157 sal_uInt16
EnterRegistrations(const char *pFile
= nullptr, int nLine
= 0);
158 void LeaveRegistrations( const char *pFile
= nullptr, int nLine
= 0 );
159 void Register( SfxControllerItem
& rBinding
);
160 void Release( SfxControllerItem
& rBinding
);
161 SfxDispatcher
* GetDispatcher() const
162 { return pDispatcher
; }
163 const css::uno::Reference
< css::frame::XDispatchRecorder
>& GetRecorder() const;
164 css::uno::Reference
< css::frame::XDispatch
>
165 GetDispatch( const SfxSlot
*, const css::util::URL
& aURL
, bool bMasterCommand
);
166 SAL_DLLPRIVATE
void ContextChanged_Impl();
167 SAL_DLLPRIVATE
void Execute_Impl( SfxRequest
& rReq
, const SfxSlot
* pSlot
, SfxShell
* pShell
);
168 SAL_DLLPRIVATE
void DeleteControllers_Impl();
169 SAL_DLLPRIVATE SfxDispatcher
* GetDispatcher_Impl() { return pDispatcher
; }
170 SAL_DLLPRIVATE
void ClearCache_Impl( sal_uInt16 nSlotId
);
171 SAL_DLLPRIVATE
void RegisterInternal_Impl( SfxControllerItem
& rBinding
);
172 SAL_DLLPRIVATE
void Register_Impl( SfxControllerItem
& rBinding
, bool );
173 SAL_DLLPRIVATE SfxWorkWindow
* GetWorkWindow_Impl() const;
174 SAL_DLLPRIVATE
void SetWorkWindow_Impl( std::unique_ptr
<SfxWorkWindow
> );
175 SAL_DLLPRIVATE SfxBindings
* GetSubBindings_Impl() const;
176 SAL_DLLPRIVATE
void SetRecorder_Impl( css::uno::Reference
< css::frame::XDispatchRecorder
> const & );
177 SAL_DLLPRIVATE
void InvalidateSlotsInMap_Impl();
178 SAL_DLLPRIVATE
void AddSlotToInvalidateSlotsMap_Impl( sal_uInt16 nId
);
182 #define ENTERREGISTRATIONS() EnterRegistrations(__FILE__, __LINE__)
183 #define LEAVEREGISTRATIONS() LeaveRegistrations(__FILE__, __LINE__)
184 #define DENTERREGISTRATIONS() \
185 EnterRegistrations( OStringBuffer(__FILE__).append('(').append(reinterpret_cast<sal_Int64>(this)).append(')').getStr(), __LINE__ )
186 #define DLEAVEREGISTRATIONS( ) \
187 LeaveRegistrations( OStringBuffer(__FILE__).append('(').append(reinterpret_cast<sal_Int64>(this)).append(')').getStr(), __LINE__ )
189 #define ENTERREGISTRATIONS() EnterRegistrations()
190 #define LEAVEREGISTRATIONS() LeaveRegistrations()
191 #define DENTERREGISTRATIONS() EnterRegistrations()
192 #define DLEAVEREGISTRATIONS() LeaveRegistrations()
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */