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