xref: /AOO41X/main/sfx2/inc/sfx2/dispatch.hxx (revision 353d8f4d17010cd2d0ea815067cad67e477f2bee)
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 _SFXDISPATCH_HXX
24 #define _SFXDISPATCH_HXX
25 
26 #include "sal/config.h"
27 #include "sfx2/dllapi.h"
28 #include "sal/types.h"
29 
30 #include <stdarg.h>
31 
32 #define _SVSTDARR_USHORTS
33 #include <svl/svstdarr.hxx>     // SvUShorts
34 
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/viewfrm.hxx>
37 
38 class SfxSlotServer;
39 class SfxShell;
40 class SfxRequest;
41 class SfxShellStack_Impl;
42 class SfxHintPoster;
43 class SfxViewFrame;
44 class SfxBindings;
45 class SfxItemSet;
46 class SfxPopupMenuManager;
47 class SfxModule;
48 struct SfxDispatcher_Impl;
49 struct SfxPlugInInfo_Impl;
50 
51 namespace com
52 {
53     namespace sun
54     {
55         namespace star
56         {
57             namespace frame
58             {
59                 class XDispatch;
60             }
61         }
62     }
63 }
64 
65 //=========================================================================
66 
67 #define SFX_SHELL_POP_UNTIL     4
68 #define SFX_SHELL_POP_DELETE    2
69 #define SFX_SHELL_PUSH          1
70 
71 //=========================================================================
72 
73 typedef SfxPoolItem* SfxPoolItemPtr;
74 SV_DECL_PTRARR_DEL( SfxItemPtrArray, SfxPoolItemPtr, 4, 4 )
75 
76 // fuer  shell.cxx
77 typedef SfxItemPtrArray SfxItemArray_Impl;
78 
79 class SfxExecuteItem : public SfxItemPtrArray, public SfxPoolItem
80 {
81     sal_uInt16 nSlot;
82     SfxCallMode eCall;
83     sal_uInt16 nModifier;
84 public:
GetSlot() const85     sal_uInt16                   GetSlot() const { return nSlot; }
GetModifier() const86     sal_uInt16                   GetModifier() const { return nModifier; }
SetModifier(sal_uInt16 nModifierP)87     void                     SetModifier( sal_uInt16 nModifierP ) { nModifier = nModifierP; }
GetCallMode() const88     SfxCallMode              GetCallMode() const { return eCall; }
SetCallMode(SfxCallMode eMode)89     void                     SetCallMode( SfxCallMode eMode ) { eCall = eMode; }
90     virtual int              operator==( const SfxPoolItem& ) const;
91 
92     virtual SfxPoolItem*     Clone( SfxItemPool *pPool = 0 ) const;
93                              SfxExecuteItem(
94                                  sal_uInt16 nWhich, sal_uInt16 nSlot, SfxCallMode eMode,
95                                  const SfxPoolItem *pArg1, ... );
96                              SfxExecuteItem(
97                                  sal_uInt16 nWhich, sal_uInt16 nSlot, SfxCallMode eMode );
98                              SfxExecuteItem( const SfxExecuteItem& );
99 };
100 
101 //=========================================================================
102 
103 class SFX2_DLLPUBLIC SfxDispatcher
104 {
105     SfxDispatcher_Impl*             pImp;
106     sal_Bool                            bFlushed;
107 
108 private:
109     // auf temporaer ausgewerteten Todos suchen
110     SAL_DLLPRIVATE sal_Bool CheckVirtualStack( const SfxShell& rShell, sal_Bool bDeep );
111 
112 #ifndef _SFX_HXX
113 
114 friend class SfxApplication;
115 friend class SfxViewFrame;
116 
117     DECL_DLLPRIVATE_LINK( EventHdl_Impl, void * );
118     DECL_DLLPRIVATE_LINK( PostMsgHandler, SfxRequest * );
119 
120     SAL_DLLPRIVATE int Call_Impl( SfxShell& rShell, const SfxSlot &rSlot, SfxRequest &rReq, sal_Bool bRecord );
121     SAL_DLLPRIVATE void _Update_Impl( sal_Bool,sal_Bool,sal_Bool,SfxWorkWindow*);
122     SAL_DLLPRIVATE void CollectTools_Impl(SfxWorkWindow*);
123 
124 protected:
125 friend class SfxBindings;
126 friend class SfxStateCache;
127 friend class SfxPopupMenuManager;
128 friend class SfxHelp;
129                         // Fuer die Bindings: Finden einer Message; Level fuer
130                         // erneuten Zugriff
131     SAL_DLLPRIVATE sal_Bool _TryIntercept_Impl( sal_uInt16 nId, SfxSlotServer &rServer, sal_Bool bModal );
132     sal_Bool                _FindServer( sal_uInt16 nId, SfxSlotServer &rServer, sal_Bool bModal );
133     sal_Bool                _FillState( const SfxSlotServer &rServer,
134                                     SfxItemSet &rState, const SfxSlot *pRealSlot );
135     const SfxPoolItem*  _Execute( const SfxSlotServer &rServer );
136     void                _Execute( SfxShell &rShell, const SfxSlot &rSlot,
137                                   SfxRequest &rReq,
138                                   SfxCallMode eCall = SFX_CALLMODE_STANDARD);
139     const SfxPoolItem*  _Execute( sal_uInt16 nSlot, SfxCallMode eCall,
140                                   va_list pArgs, const SfxPoolItem *pArg1 );
141 
142 #endif
143 protected:
144     void FlushImpl();
145 
146 public:
147                         SfxDispatcher( SfxDispatcher* pParent );
148                         SfxDispatcher( SfxViewFrame *pFrame = 0 );
149 
150     SAL_DLLPRIVATE void Construct_Impl( SfxDispatcher* pParent );
151 
152     virtual             ~SfxDispatcher();
153 
154     const SfxPoolItem*  Execute( const SfxExecuteItem& rItem );
155     virtual sal_uInt16      ExecuteFunction( sal_uInt16 nSID, SfxPoolItem** ppArgs=0, sal_uInt16 nMode=0 );
156     sal_uInt16              ExecuteFunction( sal_uInt16 nSID, const SfxItemSet& rArgs , sal_uInt16 nMode=0 );
157 
158     virtual void        SetExecuteMode( sal_uInt16 );
159 
160     const SfxPoolItem*  Execute( sal_uInt16 nSlot,
161                                  SfxCallMode nCall = SFX_CALLMODE_SLOT,
162                                  const SfxPoolItem **pArgs = 0,
163                                  sal_uInt16 nModi = 0,
164                                  const SfxPoolItem **pInternalArgs = 0);
165 
166     const SfxPoolItem*  Execute( sal_uInt16 nSlot,
167                                  SfxCallMode nCall,
168                                  SfxItemSet* pArgs,
169                                  SfxItemSet* pInternalArgs,
170                                  sal_uInt16 nModi = 0);
171 
172     const SfxPoolItem*  Execute( sal_uInt16 nSlot,
173                                  SfxCallMode nCall,
174                                  const SfxPoolItem *pArg1, ... );
175 
176     const SfxPoolItem*  Execute( sal_uInt16 nSlot,
177                                  SfxCallMode nCall,
178                                  const SfxItemSet &rArgs );
179 
180     const SfxPoolItem*  Execute( sal_uInt16 nSlot,
181                                  SfxCallMode nCall,
182                                  sal_uInt16 nModi,
183                                  const SfxItemSet &rArgs );
184 
185     sal_uInt16              GetSlotId( const String& rCommand );
186     const SfxSlot*      GetSlot( const String& rCommand );
187 
188     sal_Bool                IsActive( const SfxShell& rShell );
189     sal_Bool                IsOnTop( const SfxShell& rShell );
190     sal_uInt16              GetShellLevel( const SfxShell &rShell );
191     SfxBindings*        GetBindings() const;
192 
193     void                Push( SfxShell& rShell );
194     void                Pop( SfxShell& rShell, sal_uInt16 nMode = 0 );
195 
196     SfxShell*           GetShell(sal_uInt16 nIdx) const;
197     SfxViewFrame*       GetFrame() const;
198     SfxModule*      GetModule() const;
199     // caller has to clean up the Manager on his own
200     static SfxPopupMenuManager* Popup( sal_uInt16 nConfigId,Window *pWin, const Point *pPos );
201 
202     void                ExecutePopup( const ResId &rId,
203                               Window *pWin = 0, const Point *pPosPixel = 0 );
204     static void         ExecutePopup( sal_uInt16 nConfigId = 0,
205                               Window *pWin = 0, const Point *pPosPixel = 0 );
206     static void         ExecutePopup( sal_uInt16 nConfigId,
207                                       Window *pWin, const Point *pPosPixel,
208                                       const SfxPoolItem *pArg1, ...  );
209 
210     sal_Bool            IsAppDispatcher() const;
211     sal_Bool            IsFlushed() const;
212     void                Flush();
213     void                Lock( sal_Bool bLock );
214     sal_Bool                IsLocked( sal_uInt16 nSID = 0 ) const;
215     void                SetSlotFilter( sal_Bool bEnable = sal_False,
216                                        sal_uInt16 nCount = 0, const sal_uInt16 *pSIDs = 0 );
217 
218     void                HideUI( sal_Bool bHide = sal_True );
219     void                ShowObjectBar(sal_uInt16 nId, SfxShell *pShell=0) const;
220     sal_uInt32          GetObjectBarId( sal_uInt16 nPos ) const;
221 
222     SfxItemState        QueryState( sal_uInt16 nSID, const SfxPoolItem* &rpState );
223     SfxItemState        QueryState( sal_uInt16 nSID, ::com::sun::star::uno::Any& rAny );
224 
225     sal_Bool                IsAllowed( sal_uInt16 nSlot ) const;
226     ::com::sun::star::frame::XDispatch*          GetDispatchInterface( const String& );
227     void                SetDisableFlags( sal_uInt32 nFlags );
228     sal_uInt32              GetDisableFlags() const;
229 
230 //#if 0 // _SOLAR__PRIVATE
231     SAL_DLLPRIVATE sal_Bool HasSlot_Impl( sal_uInt16 );
232     SAL_DLLPRIVATE void SetMenu_Impl();
233     SAL_DLLPRIVATE void Update_Impl( sal_Bool bForce = sal_False ); // ObjectBars etc.
234     SAL_DLLPRIVATE sal_Bool IsUpdated_Impl() const;
235     SAL_DLLPRIVATE void DebugOutput_Impl() const;
236     SAL_DLLPRIVATE void ResetObjectBars_Impl();
237     SAL_DLLPRIVATE int GetShellAndSlot_Impl( sal_uInt16 nSlot, SfxShell **ppShell, const SfxSlot **ppSlot,
238                                               sal_Bool bOwnShellsOnly, sal_Bool bModal, sal_Bool bRealSlot=sal_True );
239     SAL_DLLPRIVATE void LockUI_Impl( sal_Bool bLock = sal_True );
240     SAL_DLLPRIVATE void SetReadOnly_Impl( sal_Bool  bOn );
241     SAL_DLLPRIVATE sal_Bool GetReadOnly_Impl() const;
242     SAL_DLLPRIVATE sal_Bool IsSlotEnabledByFilter_Impl( sal_uInt16 nSID ) const;
243     SAL_DLLPRIVATE void SetQuietMode_Impl( sal_Bool bOn );
244     SAL_DLLPRIVATE void SetModalMode_Impl( sal_Bool bOn );
245     SAL_DLLPRIVATE sal_Bool IsReadOnlyShell_Impl( sal_uInt16 nShell ) const;
246     SAL_DLLPRIVATE void RemoveShell_Impl( SfxShell& rShell );
247     SAL_DLLPRIVATE void InsertShell_Impl( SfxShell& rShell, sal_uInt16 nPos );
248     SAL_DLLPRIVATE void DoParentActivate_Impl();
249     SAL_DLLPRIVATE void DoParentDeactivate_Impl();
250     SAL_DLLPRIVATE void DoActivate_Impl( sal_Bool bMDI, SfxViewFrame* pOld );
251     SAL_DLLPRIVATE void DoDeactivate_Impl( sal_Bool bMDI, SfxViewFrame* pNew );
252     SAL_DLLPRIVATE void InvalidateBindings_Impl(sal_Bool);
253     SAL_DLLPRIVATE sal_uInt16 GetNextToolBox_Impl( sal_uInt16 nPos, sal_uInt16 nType, String *pStr );
254 //#endif
255 };
256 
257 //--------------------------------------------------------------------
258 
IsFlushed() const259 inline sal_Bool SfxDispatcher::IsFlushed() const
260 
261 /*  [Beschreibung]
262 
263     Mit dieser Methode l"a"st sich erfragen, ob der Stack des
264     SfxDispatchers geflusht ist, oder noch Push- oder Pop-Befehle
265     ausstehen.
266 */
267 
268 {
269      return bFlushed;
270 }
271 
272 //--------------------------------------------------------------------
273 
Flush()274 inline void SfxDispatcher::Flush()
275 
276 /*  [Beschreibung]
277 
278     Diese Methode f"uhrt ausstehenden Push- und Pop-Befehle aus.
279     F"ur <SfxShell>s, die dabei neu auf den Stack kommen, wird
280     <SfxShell::Activate(sal_Bool)> mit bMDI == sal_True aufgerufen, f"ur
281     SfxShells, die vom Stack entfernt werden, wird <SfxShell::Deactivate(sal_Bool)>
282     mit bMDI == sal_True aufgerufen.
283 */
284 
285 {
286     if ( !bFlushed ) FlushImpl();
287 }
288 
289 //--------------------------------------------------------------------
290 
Push(SfxShell & rShell)291 inline void SfxDispatcher::Push( SfxShell& rShell )
292 
293 /*  [Beschreibung]
294 
295     Mit dieser Methode wird eine <SfxShell> auf den SfxDispatcher
296     gepusht. Die SfxShell wird zun"achst zum pushen vermerkt und
297     es wird ein Timer aufgesetzt. Erst bei Ablauf des Timers wird
298     tats"achlich gepusht (<SfxDispatcher::Flush()>) und die <SfxBindings>
299     werden invalidiert. W"ahrend der Timer l"auft gleichen sich
300     entgegengesetzte Push und Pop Befehle mit derselben SfxShell aus.
301 */
302 
303 {
304     Pop( rShell, SFX_SHELL_PUSH );
305 }
306 
307 //--------------------------------------------------------------------
308 
IsActive(const SfxShell & rShell)309 inline sal_Bool SfxDispatcher::IsActive( const SfxShell& rShell )
310 
311 /*  [Beschreibung]
312 
313     Mit dieser Methode kann abgefragt werden, ob sich eine bestimmte
314     <SfxShell>-Instanz auf dem SfxDispatcher befindet.
315 
316     [R"uckgabewert]
317 
318     sal_Bool                sal_True
319                         Die SfxShell-Instanz befindet sich auf dem
320                         SfxDispatcher.
321 
322                         sal_False
323                         Die SfxShell-Instanz befindet sich nicht auf dem
324                         SfxDispatcher.
325 
326 */
327 
328 {
329     return CheckVirtualStack( rShell, sal_True );
330 }
331 //--------------------------------------------------------------------
332 
IsOnTop(const SfxShell & rShell)333 inline sal_Bool SfxDispatcher::IsOnTop( const SfxShell& rShell )
334 
335 /*  [Beschreibung]
336 
337     Mit dieser Methode kann abgefragt werden, ob sich eine bestimmte
338     <SfxShell>-Instanz zuoberst auf dem SfxDispatcher befindet.
339 
340     [R"uckgabewert]
341 
342     sal_Bool                sal_True
343                         Die SfxShell-Instanz befindet sich als oberste
344                         SfxShell auf dem SfxDispatcher.
345 
346                         sal_False
347                         Die SfxShell-Instanz befindet sich nicht als
348                         oberste SfxShell auf dem SfxDispatcher.
349 
350 */
351 
352 {
353     return CheckVirtualStack( rShell, sal_False );
354 }
355 
356 //--------------------------------------------------------------------
357 
358 #endif
359 
360