bump product version to 4.2.0.1
[LibreOffice.git] / include / sfx2 / dispatch.hxx
blob151d4833dcea9c8e9017b2caf3af1183f47d6435
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_DISPATCH_HXX
20 #define INCLUDED_SFX2_DISPATCH_HXX
22 #include <sal/config.h>
23 #include <sfx2/dllapi.h>
24 #include <sal/types.h>
26 #include <stdarg.h>
28 #include <sfx2/bindings.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <deque>
31 #include <map>
32 #include <vector>
34 class SfxSlotServer;
35 class SfxShell;
36 class SfxRequest;
37 class SfxHintPoster;
38 class SfxViewFrame;
39 class SfxBindings;
40 class SfxItemSet;
41 class SfxPopupMenuManager;
42 class SfxModule;
43 struct SfxDispatcher_Impl;
45 typedef std::vector<SfxShell*> SfxShellStack_Impl;
47 namespace com
49 namespace sun
51 namespace star
53 namespace frame
55 class XDispatch;
61 //=========================================================================
63 #define SFX_SHELL_POP_UNTIL 4
64 #define SFX_SHELL_POP_DELETE 2
65 #define SFX_SHELL_PUSH 1
67 //=========================================================================
69 // Maps the Which() field to a pointer to a SfxPoolItem
70 class SfxItemPtrMap : public std::map<sal_uInt16, SfxPoolItem*>
72 public:
73 ~SfxItemPtrMap()
75 for(iterator it = begin(); it != end(); ++it)
76 delete it->second;
80 struct SfxToDo_Impl
82 SfxShell* pCluster;
83 bool bPush;
84 bool bDelete;
85 bool bDeleted;
86 bool bUntil;
88 SfxToDo_Impl()
89 : pCluster(0)
90 , bPush(false)
91 , bDelete(false)
92 , bDeleted(false)
93 , bUntil(false)
95 SfxToDo_Impl( bool bOpPush, bool bOpDelete, bool bOpUntil, SfxShell& rCluster )
96 : pCluster(&rCluster)
97 , bPush(bOpPush)
98 , bDelete(bOpDelete)
99 , bDeleted(false)
100 , bUntil(bOpUntil)
103 bool operator==( const SfxToDo_Impl& rWith ) const
104 { return pCluster==rWith.pCluster && bPush==rWith.bPush; }
107 class SFX2_DLLPUBLIC SfxDispatcher
109 SfxDispatcher_Impl* pImp;
110 sal_Bool bFlushed;
111 std::deque< std::deque<SfxToDo_Impl> > aToDoCopyStack;
113 private:
114 // Search for temporary evaluated Todos
115 SAL_DLLPRIVATE sal_Bool CheckVirtualStack( const SfxShell& rShell, sal_Bool bDeep );
117 #ifndef _SFX_HXX
119 friend class SfxApplication;
120 friend class SfxViewFrame;
122 DECL_DLLPRIVATE_LINK( EventHdl_Impl, void * );
123 DECL_DLLPRIVATE_LINK( PostMsgHandler, SfxRequest * );
125 SAL_DLLPRIVATE int Call_Impl( SfxShell& rShell, const SfxSlot &rSlot, SfxRequest &rReq, sal_Bool bRecord );
126 SAL_DLLPRIVATE void _Update_Impl( sal_Bool,sal_Bool,sal_Bool,SfxWorkWindow*);
127 SAL_DLLPRIVATE void CollectTools_Impl(SfxWorkWindow*);
129 protected:
130 friend class SfxBindings;
131 friend class SfxStateCache;
132 friend class SfxPopupMenuManager;
133 friend class SfxHelp;
134 // For bindings: Finding the Message;
135 // level for re-access
136 SAL_DLLPRIVATE sal_Bool _TryIntercept_Impl( sal_uInt16 nId, SfxSlotServer &rServer, sal_Bool bModal );
137 sal_Bool _FindServer( sal_uInt16 nId, SfxSlotServer &rServer, sal_Bool bModal );
138 sal_Bool _FillState( const SfxSlotServer &rServer,
139 SfxItemSet &rState, const SfxSlot *pRealSlot );
140 void _Execute( SfxShell &rShell, const SfxSlot &rSlot,
141 SfxRequest &rReq,
142 SfxCallMode eCall = SFX_CALLMODE_STANDARD);
143 #endif
144 protected:
145 void FlushImpl();
147 public:
148 SfxDispatcher( SfxDispatcher* pParent );
149 SfxDispatcher( SfxViewFrame *pFrame = 0 );
151 SAL_DLLPRIVATE void Construct_Impl( SfxDispatcher* pParent );
153 virtual ~SfxDispatcher();
155 const SfxPoolItem* Execute( sal_uInt16 nSlot,
156 SfxCallMode nCall = SFX_CALLMODE_SLOT,
157 const SfxPoolItem **pArgs = 0,
158 sal_uInt16 nModi = 0,
159 const SfxPoolItem **pInternalArgs = 0);
161 const SfxPoolItem* Execute( sal_uInt16 nSlot,
162 SfxCallMode nCall,
163 SfxItemSet* pArgs,
164 SfxItemSet* pInternalArgs,
165 sal_uInt16 nModi = 0);
167 const SfxPoolItem* Execute( sal_uInt16 nSlot,
168 SfxCallMode nCall,
169 const SfxPoolItem *pArg1, ... );
171 const SfxPoolItem* Execute( sal_uInt16 nSlot,
172 SfxCallMode nCall,
173 const SfxItemSet &rArgs );
175 const SfxPoolItem* Execute( sal_uInt16 nSlot,
176 SfxCallMode nCall,
177 sal_uInt16 nModi,
178 const SfxItemSet &rArgs );
180 const SfxSlot* GetSlot( const OUString& rCommand );
182 sal_Bool IsActive( const SfxShell& rShell );
183 sal_Bool IsOnTop( const SfxShell& rShell );
184 sal_uInt16 GetShellLevel( const SfxShell &rShell );
185 SfxBindings* GetBindings() const;
187 void Push( SfxShell& rShell );
188 void Pop( SfxShell& rShell, sal_uInt16 nMode = 0 );
190 SfxShell* GetShell(sal_uInt16 nIdx) const;
191 SfxViewFrame* GetFrame() const;
192 SfxModule* GetModule() const;
193 // caller has to clean up the Manager on his own
194 static SfxPopupMenuManager* Popup( sal_uInt16 nConfigId,Window *pWin, const Point *pPos );
196 void ExecutePopup( const ResId &rId,
197 Window *pWin = 0, const Point *pPosPixel = 0 );
198 static void ExecutePopup( sal_uInt16 nConfigId = 0,
199 Window *pWin = 0, const Point *pPosPixel = 0 );
201 sal_Bool IsAppDispatcher() const;
202 sal_Bool IsFlushed() const;
203 void Flush();
204 void Lock( sal_Bool bLock );
205 sal_Bool IsLocked( sal_uInt16 nSID = 0 ) const;
206 void SetSlotFilter( sal_Bool bEnable = sal_False,
207 sal_uInt16 nCount = 0, const sal_uInt16 *pSIDs = 0 );
209 void HideUI( sal_Bool bHide = sal_True );
210 void ShowObjectBar(sal_uInt16 nId, SfxShell *pShell=0) const;
211 sal_uInt32 GetObjectBarId( sal_uInt16 nPos ) const;
213 SfxItemState QueryState( sal_uInt16 nSID, const SfxPoolItem* &rpState );
214 SfxItemState QueryState( sal_uInt16 nSID, ::com::sun::star::uno::Any& rAny );
216 ::com::sun::star::frame::XDispatch* GetDispatchInterface( const OUString& );
217 void SetDisableFlags( sal_uInt32 nFlags );
218 sal_uInt32 GetDisableFlags() const;
220 SAL_DLLPRIVATE void SetMenu_Impl();
221 SAL_DLLPRIVATE void Update_Impl( sal_Bool bForce = sal_False ); // ObjectBars etc.
222 SAL_DLLPRIVATE sal_Bool IsUpdated_Impl() const;
223 SAL_DLLPRIVATE int GetShellAndSlot_Impl( sal_uInt16 nSlot, SfxShell **ppShell, const SfxSlot **ppSlot,
224 sal_Bool bOwnShellsOnly, sal_Bool bModal, sal_Bool bRealSlot=sal_True );
225 SAL_DLLPRIVATE void SetReadOnly_Impl( sal_Bool bOn );
226 SAL_DLLPRIVATE sal_Bool GetReadOnly_Impl() const;
227 SAL_DLLPRIVATE sal_Bool IsSlotEnabledByFilter_Impl( sal_uInt16 nSID ) const;
228 SAL_DLLPRIVATE void SetQuietMode_Impl( sal_Bool bOn );
229 SAL_DLLPRIVATE sal_Bool IsReadOnlyShell_Impl( sal_uInt16 nShell ) const;
230 SAL_DLLPRIVATE void RemoveShell_Impl( SfxShell& rShell );
231 SAL_DLLPRIVATE void DoParentActivate_Impl();
232 SAL_DLLPRIVATE void DoParentDeactivate_Impl();
233 SAL_DLLPRIVATE void DoActivate_Impl( sal_Bool bMDI, SfxViewFrame* pOld );
234 SAL_DLLPRIVATE void DoDeactivate_Impl( sal_Bool bMDI, SfxViewFrame* pNew );
235 SAL_DLLPRIVATE void InvalidateBindings_Impl(sal_Bool);
236 SAL_DLLPRIVATE sal_uInt16 GetNextToolBox_Impl( sal_uInt16 nPos, sal_uInt16 nType, OUString *pStr );
239 //--------------------------------------------------------------------
241 inline sal_Bool SfxDispatcher::IsFlushed() const
243 /* [Description]
245 This method checks if the stack of the SfxDispatchers is flushed, or if
246 push- or pop- commands are pending.
250 return bFlushed;
253 //--------------------------------------------------------------------
255 inline void SfxDispatcher::Flush()
257 /* [Description]
259 This method performs outstanding push- and pop- commands. For <SfxShell>s,
260 which are new on the stack, the <SfxShell::Activate(sal_Bool)> is invoked with
261 bMDI == sal_True, for SfxShells that are removed from the stack, the
262 <SfxShell::Deactivate(sal_Bool)> is invoked with bMDI == sal_True
266 if ( !bFlushed ) FlushImpl();
269 //--------------------------------------------------------------------
271 inline void SfxDispatcher::Push( SfxShell& rShell )
273 /* [Description]
275 With this method, a <SfxShell> pushed on to the SfxDispatcher.
276 The SfxShell is first marked for push and a timer is set up.
277 First when the timer has couted down to zero the push
278 ( <SfxDispatcher::Flush()> ) is actually performed and the
279 <SfxBindings> is invalidated. While the timer is counting down
280 the opposing push and pop commands on the same SfxShell are
281 leveled out.
285 Pop( rShell, SFX_SHELL_PUSH );
288 //--------------------------------------------------------------------
290 inline sal_Bool SfxDispatcher::IsActive( const SfxShell& rShell )
292 /* [Description]
294 This method checks whether a particular <SfxShell> instance is
295 on the SfxDispatcher.
297 [Return value]
299 sal_Bool sal_True
300 The SfxShell instance is on the SfxDispatcher.
302 sal_False
303 The SfxShell instance is not on the SfxDispatcher.
307 return CheckVirtualStack( rShell, sal_True );
309 //--------------------------------------------------------------------
311 inline sal_Bool SfxDispatcher::IsOnTop( const SfxShell& rShell )
313 /* [Description]
315 This method checks whether a particular <SfxShell> instance is on
316 top of the SfxDispatcher.
318 [Return value]
320 sal_Bool sal_True
321 The SfxShell instance is on the top of
322 the SfxDispatcher.
324 sal_False
325 The SfxShell instance is not on the top of
326 the SfxDispatcher.
330 return CheckVirtualStack( rShell, sal_False );
333 //--------------------------------------------------------------------
335 #endif
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */