Line data Source code
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 : #include <sfx2/dllapi.h>
24 : #include <sal/types.h>
25 : #include <rtl/strbuf.hxx>
26 : #include <tools/link.hxx>
27 : #include <com/sun/star/frame/XFrame.hpp>
28 : #include <com/sun/star/frame/XDispatchProvider.hpp>
29 : #include <com/sun/star/uno/Reference.h>
30 : #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
31 : #include <vector>
32 : #include <boost/ptr_container/ptr_vector.hpp>
33 :
34 :
35 : // some other includes
36 :
37 :
38 : #include <sfx2/viewfrm.hxx>
39 :
40 :
41 : // forwards, typedefs, declarations
42 :
43 :
44 : class SystemWindow;
45 : class SfxSlot;
46 : class SfxSlotServer;
47 : class SfxControllerItem;
48 : class SfxStateCache;
49 : class SfxItemSet;
50 : class SfxDispatcher;
51 : class SfxBindings;
52 : class SfxBindings_Impl;
53 : class Timer;
54 : class SfxWorkWindow;
55 : class SfxUnoControllerItem;
56 :
57 : typedef std::vector<SfxUnoControllerItem*> SfxUnoControllerArr_Impl;
58 :
59 : enum class SfxCallMode : sal_uInt16
60 : {
61 : SLOT = 0x00, // sync/async from Slot
62 : SYNCHRON = 0x01, // synchronously in the same Stackframe
63 : ASYNCHRON = 0x02, // asynchronously via AppEvent
64 : RECORD = 0x04, // take into account while recording
65 : API = 0x08, // API call (silent)
66 : MODAL = 0x10 // despite ModalMode
67 : };
68 : // make combining these type-safe
69 2035 : inline SfxCallMode operator| (SfxCallMode lhs, SfxCallMode rhs)
70 : {
71 2035 : return static_cast<SfxCallMode>(static_cast<sal_uInt16>(lhs) | static_cast<sal_uInt16>(rhs));
72 : }
73 6557 : inline SfxCallMode operator& (SfxCallMode lhs, SfxCallMode rhs)
74 : {
75 6557 : return static_cast<SfxCallMode>(static_cast<sal_uInt16>(lhs) & static_cast<sal_uInt16>(rhs));
76 : }
77 770 : inline SfxCallMode operator~ (SfxCallMode rhs)
78 : {
79 770 : return static_cast<SfxCallMode>(0x1f & ~(static_cast<sal_uInt16>(rhs)));
80 : }
81 0 : inline SfxCallMode& operator|= (SfxCallMode& lhs, SfxCallMode rhs)
82 : {
83 0 : lhs = static_cast<SfxCallMode>(static_cast<sal_uInt16>(lhs) | static_cast<sal_uInt16>(rhs));
84 0 : return lhs;
85 : }
86 770 : inline SfxCallMode& operator&= (SfxCallMode& lhs, SfxCallMode rhs)
87 : {
88 770 : lhs = static_cast<SfxCallMode>(static_cast<sal_uInt16>(lhs) & static_cast<sal_uInt16>(rhs));
89 770 : return lhs;
90 : }
91 :
92 :
93 : enum SfxPopupAction
94 : {
95 : SFX_POPUP_DELETE,
96 : SFX_POPUP_HIDE,
97 : SFX_POPUP_SHOW
98 : };
99 :
100 : struct SfxFoundCache_Impl
101 : {
102 : sal_uInt16 nSlotId; // the Slot-Id
103 : sal_uInt16 nWhichId; // If available: Which-Id, else: nSlotId
104 : const SfxSlot* pSlot; // Pointer to <Master-Slot>
105 : SfxStateCache* pCache; // Pointer to StatusCache, if possible NULL
106 :
107 38143 : SfxFoundCache_Impl(sal_uInt16 nS, sal_uInt16 nW, const SfxSlot *pS, SfxStateCache *pC ):
108 : nSlotId(nS),
109 : nWhichId(nW),
110 : pSlot(pS),
111 38143 : pCache(pC)
112 38143 : {}
113 : };
114 :
115 : typedef boost::ptr_vector<SfxFoundCache_Impl> SfxFoundCacheArr_Impl;
116 :
117 : class SFX2_DLLPUBLIC SfxBindings: public SfxBroadcaster
118 :
119 : /* [Description]
120 :
121 : In each SFx application one instance of the SfxBindings-Class will
122 : exists from <SfxApplication::Init()> until <SfxApplication::Exit()>.
123 : This instance is automatically created and destroyed by SfxApplication.
124 : However these instances will be handled by the Macro <SFX_BINDINGS>
125 : or the associated <SfxViewFrame>.
126 :
127 : The SfxBindings manages all of its Slot-Ids bound by the registered
128 : controllers and keeps a cache of the <Slot-Server> respectively.
129 : (it is what we call the combination of SfxShell instance and SfxSlot).
130 : In the SfxBindings it is stored, if and in this case which controllers
131 : that are dirty and which Slot-Server-Caches are dirty respectively.
132 : It summarizes status queries (calls to the status methods specified
133 : in the IDL) that are served by the same state methods, and handles
134 : the simulation of <Pseudo-Slots>.
135 : */
136 :
137 : {
138 : friend class SfxApplication;
139 : friend class SfxShell;
140 : friend class SfxBindings_Impl;
141 :
142 : SfxBindings_Impl*pImp; // Data of the Bindings instance
143 : SfxDispatcher* pDispatcher; // Dispatcher, to be used
144 : sal_uInt16 nRegLevel; // Lock-Level while Reconfig
145 :
146 : private:
147 : SAL_DLLPRIVATE const SfxPoolItem* Execute_Impl( sal_uInt16 nSlot, const SfxPoolItem **pArgs, sal_uInt16 nModi,
148 : SfxCallMode nCall, const SfxPoolItem **pInternalArgs, bool bGlobalOnly=false);
149 : SAL_DLLPRIVATE void SetSubBindings_Impl( SfxBindings* );
150 : SAL_DLLPRIVATE void UpdateSlotServer_Impl(); // Update SlotServer
151 : SAL_DLLPRIVATE SfxItemSet* CreateSet_Impl( SfxStateCache* &pCache,
152 : const SfxSlot* &pRealSlot,
153 : const SfxSlotServer**,
154 : SfxFoundCacheArr_Impl& );
155 : SAL_DLLPRIVATE sal_uInt16 GetSlotPos( sal_uInt16 nId, sal_uInt16 nStartSearchAt = 0 );
156 : SAL_DLLPRIVATE void Update_Impl( SfxStateCache* pCache );
157 : SAL_DLLPRIVATE void UpdateControllers_Impl(
158 : const SfxInterface* pIF,
159 : const SfxFoundCache_Impl& rFound,
160 : const SfxPoolItem *pItem,
161 : SfxItemState eItemState );
162 : SAL_DLLPRIVATE SfxStateCache* GetStateCache( sal_uInt16 nId, sal_uInt16 *pPos);
163 : DECL_DLLPRIVATE_LINK( NextJob_Impl, Timer * );
164 :
165 : public:
166 : SfxBindings();
167 : virtual ~SfxBindings();
168 :
169 : void HidePopups( bool bHide = true );
170 : SAL_DLLPRIVATE void HidePopupCtrls_Impl( bool bHide = true );
171 :
172 : void SetDispatcher(SfxDispatcher *pDisp);
173 :
174 : void Update( sal_uInt16 nId ); // For example, from Menu::Activate
175 : void Update();
176 : SAL_DLLPRIVATE void StartUpdate_Impl(bool bComplete=false);
177 : void Invalidate( sal_uInt16 nId );
178 : void Invalidate( const sal_uInt16* pIds );
179 : void InvalidateShell( const SfxShell &rSh, bool bDeep = false );
180 : void InvalidateAll( bool bWithMsg );
181 : void SetState( const SfxItemSet &rSet );
182 : void SetState( const SfxPoolItem &rItem );
183 : void Invalidate( sal_uInt16 nId, bool bWithItem, bool bWithMsg=false);
184 : void Invalidate( sal_uInt16 nId, bool bWithMsg);
185 : bool IsInUpdate() const;
186 : void SetVisibleState( sal_uInt16 nId, bool bShow );
187 :
188 : bool IsBound( sal_uInt16 nMsgId, sal_uInt16 nStartSearchAt = 0 );
189 :
190 : SfxStateCache* GetStateCache( sal_uInt16 nId);
191 : SAL_DLLPRIVATE SfxStateCache* GetAnyStateCache_Impl( sal_uInt16 nId );
192 : /**
193 : * @param rpState the caller has to delete the pointer
194 : */
195 : SfxItemState QueryState( sal_uInt16 nSID, SfxPoolItem* &rpState );
196 :
197 : const SfxPoolItem* ExecuteSynchron( sal_uInt16 nSlot,
198 : const SfxPoolItem **pArgs = 0,
199 : sal_uInt16 nModi = 0,
200 : const SfxPoolItem **pInternalArgs = 0);
201 : bool Execute( sal_uInt16 nSlot,
202 : const SfxPoolItem **pArgs = 0,
203 : sal_uInt16 nModi = 0,
204 : SfxCallMode nCall = SfxCallMode::SLOT,
205 : const SfxPoolItem **pInternalArgs = 0);
206 :
207 : SAL_DLLPRIVATE void SetDispatchProvider_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & rFrame );
208 : void SetActiveFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & rFrame );
209 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > GetActiveFrame() const;
210 : // Reconfig
211 : bool IsInRegistrations() const;
212 : sal_uInt16 EnterRegistrations(const char *pFile = 0, int nLine = 0);
213 : void LeaveRegistrations( sal_uInt16 nLevel = USHRT_MAX, const char *pFile = 0, int nLine = 0 );
214 : void Register( SfxControllerItem& rBinding );
215 : void Release( SfxControllerItem& rBinding );
216 98291 : SfxDispatcher* GetDispatcher() const
217 98291 : { return pDispatcher; }
218 : com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > GetRecorder() const;
219 : com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >
220 : GetDispatch( const SfxSlot*, const com::sun::star::util::URL& aURL, bool bMasterCommand );
221 : SAL_DLLPRIVATE void ContextChanged_Impl();
222 : SAL_DLLPRIVATE void Execute_Impl( SfxRequest& rReq, const SfxSlot* pSlot, SfxShell* pShell );
223 : SAL_DLLPRIVATE void DeleteControllers_Impl();
224 317618 : SAL_DLLPRIVATE SfxDispatcher* GetDispatcher_Impl() { return pDispatcher; }
225 : SAL_DLLPRIVATE void ClearCache_Impl( sal_uInt16 nSlotId );
226 : SAL_DLLPRIVATE bool IsInUpdate_Impl() const{ return IsInUpdate(); }
227 : SAL_DLLPRIVATE void RegisterInternal_Impl( SfxControllerItem& rBinding );
228 : SAL_DLLPRIVATE void Register_Impl( SfxControllerItem& rBinding, bool );
229 : SAL_DLLPRIVATE SfxWorkWindow* GetWorkWindow_Impl() const;
230 : SAL_DLLPRIVATE void SetWorkWindow_Impl( SfxWorkWindow* );
231 : SAL_DLLPRIVATE SfxBindings* GetSubBindings_Impl( bool bTop = false ) const;
232 : SAL_DLLPRIVATE void InvalidateUnoControllers_Impl();
233 : SAL_DLLPRIVATE void RegisterUnoController_Impl( SfxUnoControllerItem* );
234 : SAL_DLLPRIVATE void ReleaseUnoController_Impl( SfxUnoControllerItem* );
235 : SAL_DLLPRIVATE bool ExecuteCommand_Impl( const OUString& rCommand );
236 : SAL_DLLPRIVATE void SetRecorder_Impl( com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >& );
237 : SAL_DLLPRIVATE void InvalidateSlotsInMap_Impl();
238 : SAL_DLLPRIVATE void AddSlotToInvalidateSlotsMap_Impl( sal_uInt16 nId );
239 : };
240 :
241 : #ifdef DBG_UTIL
242 : #define ENTERREGISTRATIONS() EnterRegistrations(__FILE__, __LINE__)
243 : #define LEAVEREGISTRATIONS() LeaveRegistrations(USHRT_MAX, __FILE__, __LINE__)
244 : #define DENTERREGISTRATIONS() \
245 : EnterRegistrations( OStringBuffer(__FILE__).append('(').append(reinterpret_cast<sal_Int64>(this)).append(')').getStr(), __LINE__ )
246 : #define DLEAVEREGISTRATIONS( ) \
247 : LeaveRegistrations( USHRT_MAX, OStringBuffer(__FILE__).append('(').append(reinterpret_cast<sal_Int64>(this)).append(')').getStr(), __LINE__ )
248 : #else
249 : #define ENTERREGISTRATIONS() EnterRegistrations()
250 : #define LEAVEREGISTRATIONS() LeaveRegistrations()
251 : #define DENTERREGISTRATIONS() EnterRegistrations()
252 : #define DLEAVEREGISTRATIONS() LeaveRegistrations()
253 : #endif
254 :
255 :
256 :
257 : inline bool SfxBindings::IsInRegistrations() const
258 :
259 : /* [Description]
260 :
261 : Determines whether the <SfxContollerItems> SfxBindings instance is
262 : registered or unregistered, i.e. <SfxBindings::EnterRegistrations()>
263 : calls that have not been closed by <SfxBindings::LeaveRegistrations()>.
264 :
265 : [Return value]
266 :
267 : int sal_True
268 : The SfxBindings instance is currently in
269 : Registration-Mode. No status updates .
270 :
271 : int sal_False
272 : The SfxBindings instance is the normal mode.
273 : Status updates can be done.
274 : */
275 :
276 : {
277 : return 0 != nRegLevel;
278 : }
279 :
280 :
281 :
282 : #endif
283 :
284 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|