xref: /aoo41x/main/sfx2/inc/sfx2/bindings.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _SFX_BINDINGS_HXX
28 #define _SFX_BINDINGS_HXX
29 
30 #include "sal/config.h"
31 #include "sfx2/dllapi.h"
32 #include "sal/types.h"
33 #include <com/sun/star/frame/XFrame.hpp>
34 #include <com/sun/star/frame/XDispatchProvider.hpp>
35 #include <com/sun/star/uno/Reference.h>
36 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
37 
38 //________________________________________________________________________________________________________________
39 //	some other includes
40 //________________________________________________________________________________________________________________
41 
42 #include <sfx2/minarray.hxx>
43 #include <sfx2/viewfrm.hxx>
44 
45 //________________________________________________________________________________________________________________
46 //	forwards, typedefs, declarations
47 //________________________________________________________________________________________________________________
48 
49 class SfxConfigManager;
50 class SystemWindow;
51 class SfxArg;
52 class SfxSlot;
53 class SfxSlotServer;
54 class SfxControllerItem;
55 class SfxStateCache;
56 class SfxItemSet;
57 class SfxDispatcher;
58 class SfxBindings;
59 class SfxBindings_Impl;
60 class Timer;
61 struct SfxFoundCache_Impl;
62 class SfxFoundCacheArr_Impl;
63 class SfxWorkWindow;
64 class SfxUnoControllerItem;
65 typedef SfxUnoControllerItem* SfxUnoControllerItemPtr;
66 SV_DECL_PTRARR( SfxUnoControllerArr_Impl, SfxUnoControllerItemPtr, 20, 20 )
67 
68 //________________________________________________________________________________________________________________
69 //	defines
70 //________________________________________________________________________________________________________________
71 
72 #define SFX_CALLMODE_SLOT           0x00    // sync/async vom Slot
73 #define SFX_CALLMODE_SYNCHRON		0x01    // synchron im selben Stackframe
74 #define SFX_CALLMODE_ASYNCHRON		0x02    // asynchron per AppEvent
75 #define SFX_CALLMODE_RECORD			0x04    // beim Recorden ber"ucksichtigen
76 #define SFX_CALLMODE_API        	0x08    // Call von der API (silent)
77 #define SFX_CALLMODE_MODAL	     	0x10    // trotz ModalMode
78 
79 #define SFX_CALLMODE_STANDARD       SFX_CALLMODE_RECORD
80 typedef sal_uInt16 SfxCallMode;
81 
82 enum SfxPopupAction
83 {
84 	SFX_POPUP_DELETE,
85 	SFX_POPUP_HIDE,
86 	SFX_POPUP_SHOW
87 };
88 
89 //====================================================================
90 class SFX2_DLLPUBLIC SfxBindings: public SfxBroadcaster
91 
92 /*	[Beschreibung]
93 
94 	In jeder SFx-Applikation existiert "uber die Laufzeit von vor
95 	<SfxApplication::Init()> bis nach <SfxApplication::Exit()> eine Instanz
96 	der Klasse SfxBindings. Sie wird von der SfxApplication automatisch
97 	angelegt und zerst"ort. Instanzen werden aber i.d.R. "uber das
98 	Makro <SFX_BINDINGS> oder den zugeh"origen <SfxViewFrame> besorgt
99 	werden.
100 
101 	Die SfxBindings verwalten alle in den an ihr angemeldeten Controllern
102 	gebundenen Slot-Ids und cachen die jeweiligen <Slot-Server>
103 	(so nenne wir die Kombination aus SfxShell-Instanz und SfxSlot).
104 	In den SfxBindings ist gespeichert, ob und welche Controller dirty
105 	sind sowie welche Slot-Server-Caches jeweils dirty sind. Sie fa"st
106 	Status-Anfragen (Aufrufe der in der IDL genannten Status-Methoden)
107 	zusammen, die von derselben Status-Methode bedient werden, und sorgt
108 	f"ur die Simulation der <Pseudo-Slots>.
109 */
110 
111 {
112 friend class SfxApplication;
113 friend class SfxShell;
114 friend class SfxBindings_Impl;
115 
116 	SfxBindings_Impl*pImp;			// Daten der Bindings-Instanz
117 	SfxDispatcher*	 pDispatcher;	// zu verwendender Dispatcher
118     sal_uInt16       nRegLevel;      // Lock-Level waehrend Reconfig
119 
120 //#if 0 // _SOLAR__PRIVATE
121 private:
122     SAL_DLLPRIVATE const SfxPoolItem*  Execute_Impl( sal_uInt16 nSlot, const SfxPoolItem **pArgs, sal_uInt16 nModi,
123                                     SfxCallMode nCall, const SfxPoolItem **pInternalArgs, sal_Bool bGlobalOnly=sal_False);
124 	SAL_DLLPRIVATE void SetSubBindings_Impl( SfxBindings* );
125 	SAL_DLLPRIVATE void UpdateSlotServer_Impl(); // SlotServer aktualisieren
126 	SAL_DLLPRIVATE SfxItemSet* CreateSet_Impl( SfxStateCache* &pCache,
127 									const SfxSlot* &pRealSlot,
128 									const SfxSlotServer**,
129 									SfxFoundCacheArr_Impl& );
130     SAL_DLLPRIVATE sal_uInt16 GetSlotPos( sal_uInt16 nId, sal_uInt16 nStartSearchAt = 0 );
131 	SAL_DLLPRIVATE void Update_Impl( SfxStateCache* pCache );
132 	SAL_DLLPRIVATE void UpdateControllers_Impl(
133 							const SfxInterface* pIF,
134 							const SfxFoundCache_Impl* pFound,
135 							const SfxPoolItem *pItem,
136 							SfxItemState eItemState );
137 	DECL_DLLPRIVATE_LINK( NextJob_Impl, Timer * );
138 //#endif
139 
140 public:
141 					 SfxBindings();
142 					 ~SfxBindings();
143 
144 	void			 HidePopups( bool bHide = true );
145 	SAL_DLLPRIVATE void HidePopupCtrls_Impl( int bHide = sal_True );
146 
147 	void			 SetDispatcher(SfxDispatcher *pDisp);
148 
149 	void			 Update( sal_uInt16 nId ); // z.B. aus Menu::Activate
150 	void			 Update();
151 	SAL_DLLPRIVATE void StartUpdate_Impl(sal_Bool bComplete=sal_False);
152 	void			 Invalidate( sal_uInt16 nId );
153 	void			 Invalidate( const sal_uInt16* pIds );
154 	void			 InvalidateShell( const SfxShell &rSh, sal_Bool bDeep = sal_False );
155 	void			 InvalidateAll( sal_Bool bWithMsg );
156 	void			 SetState( const SfxItemSet &rSet );
157 	void			 SetState( const SfxPoolItem &rItem );
158 	void 			 Invalidate( sal_uInt16 nId, sal_Bool bWithItem, sal_Bool bWithMsg=sal_False);
159 	void 			 Invalidate( sal_uInt16 nId, sal_Bool bWithMsg);
160 	sal_Bool	     IsInUpdate() const;
161     void             SetVisibleState( sal_uInt16 nId, sal_Bool bShow );
162 
163 	sal_Bool         IsBound( sal_uInt16 nMsgId, sal_uInt16 nStartSearchAt = 0 );
164 
165 	const SfxSlot* 	 GetSlot( sal_uInt16 nMsgId );
166 	SfxStateCache*	 GetStateCache( sal_uInt16 nId, sal_uInt16 *pPos = 0 );
167 	SAL_DLLPRIVATE SfxStateCache* GetAnyStateCache_Impl( sal_uInt16 nId );
168 	SfxItemState	 QueryState( sal_uInt16 nSID, SfxPoolItem* &rpState );
169 
170     const SfxPoolItem*  ExecuteSynchron( sal_uInt16 nSlot,
171 								 const SfxPoolItem **pArgs = 0,
172 								 sal_uInt16 nModi = 0,
173 								 const SfxPoolItem **pInternalArgs = 0);
174     sal_Bool         Execute( sal_uInt16 nSlot,
175 								 const SfxPoolItem **pArgs = 0,
176 								 sal_uInt16 nModi = 0,
177 								 SfxCallMode nCall = SFX_CALLMODE_SLOT,
178 								 const SfxPoolItem **pInternalArgs = 0);
179 
180 	SAL_DLLPRIVATE void SetDispatchProvider_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & rFrame );
181 	SAL_DLLPRIVATE const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & GetDispatchProvider_Impl() const;
182 	void			 SetActiveFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & rFrame );
183     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > GetActiveFrame() const;
184 					 // Reconfig
185 	int 			 IsInRegistrations() const;
186 	sal_uInt16			 EnterRegistrations(const char *pFile = 0, int nLine = 0);
187 	void			 LeaveRegistrations( sal_uInt16 nLevel = USHRT_MAX, const char *pFile = 0, int nLine = 0 );
188 	void			 Register( SfxControllerItem& rBinding );
189 	void			 Release( SfxControllerItem& rBinding );
190     SystemWindow*    GetSystemWindow() const;
191     SfxDispatcher*   GetDispatcher() const
192                      { return pDispatcher; }
193 	com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > GetRecorder() const;
194     com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >
195                     GetDispatch( const SfxSlot*, const com::sun::star::util::URL& aURL, sal_Bool bMasterCommand );
196 //#if 0 // _SOLAR__PRIVATE
197     SAL_DLLPRIVATE void ContextChanged_Impl();
198     SAL_DLLPRIVATE void Execute_Impl( SfxRequest& rReq, const SfxSlot* pSlot, SfxShell* pShell );
199 	SAL_DLLPRIVATE void DeleteControllers_Impl();
200 	SAL_DLLPRIVATE SfxPopupAction GetPopupAction_Impl() const;
201 	SAL_DLLPRIVATE SfxDispatcher* GetDispatcher_Impl()  { return pDispatcher; }
202 	SAL_DLLPRIVATE void ClearCache_Impl( sal_uInt16 nSlotId );
203     SAL_DLLPRIVATE sal_Bool IsInUpdate_Impl() const{ return IsInUpdate(); }
204 	SAL_DLLPRIVATE void RegisterInternal_Impl( SfxControllerItem& rBinding );
205     SAL_DLLPRIVATE void Register_Impl( SfxControllerItem& rBinding, sal_Bool );
206     SAL_DLLPRIVATE SfxWorkWindow* GetWorkWindow_Impl() const;
207     SAL_DLLPRIVATE void SetWorkWindow_Impl( SfxWorkWindow* );
208     SAL_DLLPRIVATE SfxBindings* GetSubBindings_Impl( sal_Bool bTop = sal_False ) const;
209     SAL_DLLPRIVATE void InvalidateUnoControllers_Impl();
210     SAL_DLLPRIVATE void RegisterUnoController_Impl( SfxUnoControllerItem* );
211     SAL_DLLPRIVATE void ReleaseUnoController_Impl( SfxUnoControllerItem* );
212     SAL_DLLPRIVATE sal_Bool ExecuteCommand_Impl( const String& rCommand );
213 	SAL_DLLPRIVATE void SetRecorder_Impl( com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >& );
214 	SAL_DLLPRIVATE void ExecuteGlobal_Impl( sal_uInt16 nId );
215     SAL_DLLPRIVATE void InvalidateSlotsInMap_Impl();
216     SAL_DLLPRIVATE void AddSlotToInvalidateSlotsMap_Impl( sal_uInt16 nId );
217 //#endif
218 };
219 
220 #ifdef DBG_UTIL
221 #define ENTERREGISTRATIONS() EnterRegistrations(__FILE__, __LINE__)
222 #define LEAVEREGISTRATIONS() LeaveRegistrations(USHRT_MAX, __FILE__, __LINE__)
223 #define DENTERREGISTRATIONS(  ) \
224 		EnterRegistrations( (ByteString(__FILE__).Append('(').Append(ByteString::CreateFromInt64((sal_uIntPtr)this).Append(')'))).GetBufferAccess(), __LINE__ )
225 #define DLEAVEREGISTRATIONS(  ) \
226 		LeaveRegistrations( USHRT_MAX, (ByteString(__FILE__).Append('(').Append(ByteString::CreateFromInt64((sal_uIntPtr)this).Append(')'))).GetBufferAccess(), __LINE__ )
227 #else
228 #define ENTERREGISTRATIONS() EnterRegistrations()
229 #define LEAVEREGISTRATIONS() LeaveRegistrations()
230 #define DENTERREGISTRATIONS(  ) EnterRegistrations()
231 #define DLEAVEREGISTRATIONS(  ) LeaveRegistrations()
232 #endif
233 
234 //--------------------------------------------------------------------
235 
236 inline int SfxBindings::IsInRegistrations() const
237 
238 /*	[Beschreibung]
239 
240 	Stellt fest, ob an der SfxBindings Instanz gerade <SfxContollerItems>
241 	an- oder abgemeldet werden, also noch <SfxBindings::EnterRegistrations()>
242 	Aufrufe nicht mit <SfxBindings::EnterRegistrations()> geschlo"sen wurden.
243 
244 	[R"uckgabewert]
245 
246 	int 				sal_True
247 						Die SfxBindings Instanz ist gerade im Registrierungs-
248 						Modus. Es erfolgen also keine Status-Updates.
249 
250 						sal_False
251 						Die SfxBindings Instanz ist gerade im normalen
252 						Modus. Es k"oennen also Status-Updates erfolgen.
253 */
254 
255 {
256 	return 0 != nRegLevel;
257 }
258 
259 //--------------------------------------------------------------------
260 
261 #endif
262 
263