xref: /aoo41x/main/sfx2/inc/sfx2/shell.hxx (revision 2a3f8a0e)
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_SHELL_HXX
24 #define _SFX_SHELL_HXX
25 
26 #include "sal/config.h"
27 #include "sfx2/dllapi.h"
28 #include "sal/types.h"
29 #include <com/sun/star/embed/VerbDescriptor.hpp>
30 #include <tools/debug.hxx>
31 #include <tools/rtti.hxx>
32 #include <svl/brdcst.hxx>
33 
34 #include <tools/ownlist.hxx>
35 #include <tools/unqid.hxx>
36 #include <tools/string.hxx>
37 
38 #include <sfx2/sfxuno.hxx>
39 
40 class ResMgr;
41 class Window;
42 class ToolBox;
43 class SfxItemPool;
44 class SfxPoolItem;
45 class SfxRequest;
46 class SfxItemSet;
47 struct SfxFormalArgument;
48 class StatusBar;
49 class SfxInterface;
50 class SfxViewShell;
51 class SfxObjectShell;
52 class SfxSlotPool;
53 class SvGlobalName;
54 
55 class SfxShellObject;
56 class SfxShell;
57 struct SfxShell_Impl;
58 struct SfxTypeLibImpl;
59 class SfxShellObject;
60 class SfxShellSubObject;
61 class SfxDispatcher;
62 class SfxViewFrame;
63 class SfxSlot;
64 class SfxRepeatTarget;
65 class SbxVariable;
66 class SbxBase;
67 class SfxBindings;
68 
69 namespace svl
70 {
71     class IUndoManager;
72 }
73 
74 //====================================================================
75 
76 enum SfxInterfaceId
77 
78 /*	[Beschreibung]
79 
80 	Id f"ur die <SfxInterface>s, damit wird "uber ein Array an der
81 	<SfxApplication> ein quasi-statischer Zugriff auf die Interfaces
82 	erlaubt.
83 */
84 
85 {
86 	SFX_INTERFACE_NONE,
87 	SFX_INTERFACE_SFXAPP,
88 	SFX_INTERFACE_SFXDOCSH,
89 	SFX_INTERFACE_SFXIPFRM,
90 	SFX_INTERFACE_SFXVIEWSH,
91 	SFX_INTERFACE_SFXVIEWFRM,
92 	SFX_INTERFACE_SFXPLUGINFRM,
93 	SFX_INTERFACE_SFXPLUGINOBJ,
94 	SFX_INTERFACE_SFXPLUGINVIEWSH,
95 	SFX_INTERFACE_SFXFRAMESETOBJ,
96 	SFX_INTERFACE_SFXFRAMESETVIEWSH,
97 	SFX_INTERFACE_SFXINTERNALFRM,
98 	SFX_INTERFACE_SFXCOMPONENTDOCSH,
99 	SFX_INTERFACE_SFXGENERICOBJ,
100 	SFX_INTERFACE_SFXGENERICVIEWSH,
101 	SFX_INTERFACE_SFXEXPLOBJ,
102 	SFX_INTERFACE_SFXEXPLVIEWSH,
103 	SFX_INTERFACE_SFXPLUGINVIEWSHDYNAMIC,
104 	SFX_INTERFACE_SFXEXTERNALVIEWFRM,
105 	SFX_INTERFACE_SFXMODULE,
106 	SFX_INTERFACE_SFXFRAMESETVIEW,
107 	SFX_INTERFACE_SFXFRAMESETSOURCEVIEW,
108 	SFX_INTERFACE_SFXHELP_DOCSH,
109 	SFX_INTERFACE_SFXHELP_VIEWSH,
110 	SFX_INTERFACE_SFXTASK,
111 	SFX_INTERFACE_OFA_START			=  100,
112 	SFX_INTERFACE_OFA_END			=  100,
113 	SFX_INTERFACE_SC_START			=  150,
114 	SFX_INTERFACE_SC_END			=  199,
115 	SFX_INTERFACE_SD_START			=  200,
116 	SFX_INTERFACE_SD_END			=  249,
117 	SFX_INTERFACE_SW_START			=  250,
118 	SFX_INTERFACE_SW_END			=  299,
119 	SFX_INTERFACE_SIM_START   		=  300,
120 	SFX_INTERFACE_SIM_END		    =  319,
121 	SFX_INTERFACE_SCH_START		    =  320,
122 	SFX_INTERFACE_SCH_END   	    =  339,
123 	SFX_INTERFACE_SMA_START   		=  340,
124 	SFX_INTERFACE_SMA_END   		=  359,
125 	SFX_INTERFACE_SBA_START   		=  360,
126 	SFX_INTERFACE_SBA_END   		=  399,
127 	SFX_INTERFACE_IDE_START   		=  400,
128 	SFX_INTERFACE_IDE_END   		=  409,
129 	//-falls die noch einer braucht
130 	SFX_INTERFACE_APP				=  SFX_INTERFACE_SW_START,
131 	SFX_INTERFACE_LIB				=  450
132 };
133 
134 //TODO/CLEANUP: replace by UNO constant
135 #define SVVERB_SHOW -1
136 
137 //====================================================================
138 
139 typedef void (*SfxExecFunc)(SfxShell *, SfxRequest &rReq);
140 typedef void (*SfxStateFunc)(SfxShell *, SfxItemSet &rSet);
141 
142 class SFX2_DLLPUBLIC SfxShell: public SfxBroadcaster
143 
144 /*	[Beschreibung]
145 
146 	Die Klasse SfxShell ist Basisklasse f"ur alle Schichten, die
147 	Funktionalit"at Form von <Slot>s bereitstellen wollen.
148 
149 	Jede Instanz hat einen Verweis auf eine Interface-Beschreibung, der
150 	mit <SfxShell::GetInterface()const> erh"altlich ist. Dieses Interface
151 	stellt die Verbindung zu konkreten Methoden her und enth"alt einige
152 	weitere beschreibende Daten f"ur Controller wie Menus und Toolboxen, aber
153 	auch f"ur die diversen APIs. Der Hautpteil der Interface-Beschreibung
154 	liegt in Form einer <Type-Library> vor, die mit dem <SVIDL-Compiler>
155 	aus einem IDL-File generiert wird. F"ur jede SfxShell-Subclass ist ein
156 	solches IDL-File zu schreiben.
157 
158 */
159 
160 {
161 	friend class SfxObjectItem;
162 
163 	SfxShell_Impl*				pImp;
164 	SfxItemPool*				pPool;
165     ::svl::IUndoManager*        pUndoMgr;
166 
167 private:
168 								SfxShell( const SfxShell & ); // n.i.
169 	SfxShell&					operator = ( const SfxShell & ); // n.i.
170 
171 protected:
172 								SfxShell();
173 								SfxShell( SfxViewShell *pViewSh );
174 
175 #ifndef _SFXSH_HXX
176     SAL_DLLPRIVATE void SetViewShell_Impl( SfxViewShell* pView );
177     SAL_DLLPRIVATE void Invalidate_Impl( SfxBindings& rBindings, sal_uInt16 nId );
178 	SAL_DLLPRIVATE SfxShellObject* GetShellObj_Impl() const;
179 	SAL_DLLPRIVATE void SetShellObj_Impl( SfxShellObject* pObj );
180 #endif
181 
182 public:
183 								TYPEINFO();
184 	virtual                     ~SfxShell();
185 
186 	SfxBroadcaster*				GetBroadcaster();
187 
188     // TODO/CLEANUP: still needed?!
189     virtual SvGlobalName        GetGlobalName() const;
190 
191     virtual SfxInterface*       GetInterface() const;
192     static SfxInterface*        GetStaticInterface() { return 0; }
193 
194 	void						SetName( const String &rName );
195 	const String&   			GetName() const;
196 
197 	SfxViewShell*				GetViewShell() const;
198 
199 	void                        CallExec( SfxExecFunc pFunc, SfxRequest &rReq )
200                                 { (*pFunc)(this, rReq); }
201 	void                        CallState( SfxStateFunc pFunc, SfxItemSet &rSet )
202                                 { (*pFunc)(this, rSet); }
203 
204 	static void                 EmptyExecStub(SfxShell *pShell, SfxRequest &);
205 	static void                 EmptyStateStub(SfxShell *pShell, SfxItemSet &);
206 
207     const SfxPoolItem*          GetSlotState( sal_uInt16 nSlotId, const SfxInterface *pIF = 0, SfxItemSet *pStateSet = 0 );
208     const SfxPoolItem*          ExecuteSlot( SfxRequest &rReq, const SfxInterface *pIF = 0 );
209 	const SfxPoolItem*			ExecuteSlot( SfxRequest &rReq, sal_Bool bAsync );
210     sal_uIntPtr                       ExecuteSlot( sal_uInt16 nSlot, sal_uInt16 nMemberId, SbxVariable& rRet, SbxBase* pArgs = 0 );
211 
212     inline SfxItemPool&         GetPool() const;
213 	inline void					SetPool( SfxItemPool *pNewPool ) ;
214 
215     virtual ::svl::IUndoManager*
216                                 GetUndoManager();
217 	void						SetUndoManager( ::svl::IUndoManager *pNewUndoMgr );
218 
219 	SfxRepeatTarget*			GetRepeatTarget() const;
220 	void					    SetRepeatTarget( SfxRepeatTarget *pTarget );
221 
222     virtual void                Invalidate(sal_uInt16 nId = 0);
223 
224 	sal_Bool						IsActive() const;
225 	virtual void                Activate(sal_Bool bMDI);
226 	virtual void                Deactivate(sal_Bool bMDI);
227 	virtual void           		ParentActivate();
228 	virtual	void           		ParentDeactivate();
229 
230 	SfxDispatcher*				GetDispatcher() const;
231 	SfxViewFrame*				GetFrame() const;
232 	ResMgr* 					GetResMgr() const;
233 	virtual	sal_Bool			HasUIFeature( sal_uInt32 nFeature );
234 	void						UIFeatureChanged();
235 
236 	// Items
237 	const SfxPoolItem*			GetItem( sal_uInt16 nSlotId ) const;
238 	void						PutItem( const SfxPoolItem& rItem );
239 	void						RemoveItem( sal_uInt16 nSlotId );
240 
241     // TODO/CLEANUP: still needed?!
242     void SetVerbs(const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& aVerbs);
243     const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& GetVerbs() const;
244 	void						VerbExec (SfxRequest&);
245 	void						VerbState (SfxItemSet&);
246 	SAL_DLLPRIVATE const SfxSlot* GetVerbSlot_Impl(sal_uInt16 nId) const;
247 
248 	void						SetHelpId(sal_uIntPtr nId);
249 	sal_uIntPtr						GetHelpId() const;
250 	virtual	SfxObjectShell*		GetObjectShell();
251 	void						SetDisableFlags( sal_uIntPtr nFlags );
252 	sal_uIntPtr						GetDisableFlags() const;
253 
254     virtual SfxItemSet*         CreateItemSet( sal_uInt16 nId );
255     virtual void                ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet );
256 
257     /** Set the name of the sidebar context that is broadcast on calls
258         to Activation().
259     */
260     void SetContextName (const ::rtl::OUString& rsContextName);
261 
262     /** Broadcast a sidebar context change.
263         This method is typically called from Activate() or
264         Deactivate().
265         @param bIsActivated
266             When <TRUE/> then broadcast the context name that was
267             defined with an earlier call to SetContextName().
268             When <FALSE/> then broadcast the 'default' context.
269     */
270     void BroadcastContextForActivation (const bool bIsActivated);
271 
272 #ifndef _SFXSH_HXX
273     SAL_DLLPRIVATE bool     CanExecuteSlot_Impl( const SfxSlot &rSlot );
274     SAL_DLLPRIVATE void DoActivate_Impl( SfxViewFrame *pFrame, sal_Bool bMDI);
275     SAL_DLLPRIVATE void DoDeactivate_Impl( SfxViewFrame *pFrame, sal_Bool bMDI);
276 #endif
277 };
278 
279 //--------------------------------------------------------------------
280 SfxItemPool& SfxShell::GetPool() const
281 /*
282   [Beschreibung]
283 
284 	Jede Subclass von SfxShell mu"s einen Pool referenzieren. Dieser
285 	wird teilweise von SFx-eigenen Subklassen gesetzt (z.B. <SfxViewShell>),
286 	mu"s aber insbesondere bei direkt von SfxShell abgeleiteten Klassen
287 	und bei Ableitungen von SfxObjectShell selbst gesetzt werden.
288 
289 	Die Klasse SfxShell selbst hat noch keinen SfxItemPool, es wird
290 	daher ein 0-Pointer zur"uckgeliefert.
291 */
292 
293 {
294 	DBG_ASSERT( pPool, "no pool" );
295 	return *pPool;
296 }
297 //-------------------------------------------------------------------
298 inline void SfxShell::SetPool
299 (
300 	SfxItemPool*	pNewPool	// Pointer auf den neuen Pool oder 0
301 )
302 
303 /*  [Beschreibung]
304 
305 	Mit dieser Methode melden die Subklassen ihren speziellen <SfxItemPool>
306 	an der SfxShell an. Jede SfxShell Instanz mu\s Zugriff auf einen
307 	SfxItemPool haben. In der Regel ist dies der SfxItemPool der
308 	SfxDocumentShell. Die SfxShell Subklasse "ubernimmt nicht die
309 	Eigent"umerschaft "uber den "ubergebenen Pool. Bevor er gel"oscht
310 	wirde, mu\s er mit SetPool(0) abgemeldet werden.
311 */
312 
313 {
314 	pPool = pNewPool;
315 }
316 
317 //=====================================================================
318 
319 #define SFX_ARGUMENTMAP(ShellClass) static SfxFormalArgument __FAR_DATA a##ShellClass##Args_Impl[] =
320 
321 #define SFX_SLOTMAP(ShellClass) static SfxFormalArgument __FAR_DATA a##ShellClass##Args_Impl[1]; \
322 								static SfxSlot __FAR_DATA a##ShellClass##Slots_Impl[] =
323 
324 #define SFX_SLOTMAP_ARG(ShellClass) static SfxSlot __FAR_DATA a##ShellClass##Slots_Impl[] =
325 
326 #define SFX_DECL_INTERFACE(nId) 											\
327             static SfxInterface*                pInterface;                 \
328         private:                                                            \
329 			static void 						InitInterface_Impl();		\
330         public:                                                             \
331             static const SfxFormalArgument*     pSfxFormalArgs_Impl;        \
332             static SfxInterface*                GetStaticInterface();       \
333             static SfxInterfaceId               GetInterfaceId() {return SfxInterfaceId(nId);} \
334             static void                         RegisterInterface(SfxModule* pMod=NULL); \
335             virtual SfxInterface*       GetInterface() const;
336 
337 #define SFX_IMPL_INTERFACE(Class,SuperClass,NameResId)                      \
338 																			\
339     SfxInterface* Class::pInterface = 0;                                    \
340     const SfxFormalArgument* Class::pSfxFormalArgs_Impl = a##Class##Args_Impl;\
341     SfxInterface* __EXPORT Class::GetStaticInterface()                      \
342     {                                                                       \
343         if ( !pInterface )                                                  \
344         {                                                                   \
345             pInterface =                                                    \
346                 new SfxInterface(                                           \
347             #Class, NameResId, GetInterfaceId(),                            \
348             SuperClass::GetStaticInterface(),                               \
349             a##Class##Slots_Impl[0],                                        \
350             (sal_uInt16) (sizeof(a##Class##Slots_Impl) / sizeof(SfxSlot) ) );   \
351             InitInterface_Impl();                                           \
352         }                                                                   \
353         return pInterface;                                                  \
354     }                                                                       \
355 																			\
356     SfxInterface* Class::GetInterface() const                               \
357     {                                                                       \
358         return GetStaticInterface();                                        \
359     }                                                                       \
360                                                                             \
361     void Class::RegisterInterface(SfxModule* pMod)                          \
362     {                                                                       \
363         GetStaticInterface()->Register(pMod);                               \
364     }                                                                       \
365 																			\
366 	void Class::InitInterface_Impl()
367 
368 #define SFX_POSITION_MASK				0x000F
369 #define SFX_VISIBILITY_MASK 			0xFFF0
370 #define SFX_VISIBILITY_UNVISIBLE		0x0000	// nie sichtbar
371 #define SFX_VISIBILITY_PLUGSERVER       0x0010
372 #define SFX_VISIBILITY_PLUGCLIENT       0x0020
373 #define SFX_VISIBILITY_VIEWER	        0x0040
374 												// noch 1 sind frei!
375 #define SFX_VISIBILITY_RECORDING		0x0200
376 #define SFX_VISIBILITY_READONLYDOC		0x0400
377 #define SFX_VISIBILITY_DESKTOP    		0x0800
378 #define SFX_VISIBILITY_STANDARD 		0x1000
379 #define SFX_VISIBILITY_FULLSCREEN		0x2000
380 #define SFX_VISIBILITY_CLIENT			0x4000
381 #define SFX_VISIBILITY_SERVER			0x8000
382 #define SFX_VISIBILITY_NOCONTEXT		0xFFFF	// immer sichtbar
383 
384 #define SFX_OBJECTBAR_REGISTRATION(nPos,rResId) \
385         GetStaticInterface()->RegisterObjectBar( nPos, rResId )
386 
387 #define SFX_FEATURED_OBJECTBAR_REGISTRATION(nPos,rResId,nFeature) \
388         GetStaticInterface()->RegisterObjectBar( nPos, rResId, nFeature )
389 
390 #define SFX_CHILDWINDOW_REGISTRATION(nId) \
391         GetStaticInterface()->RegisterChildWindow( nId, (sal_Bool) sal_False )
392 
393 #define SFX_FEATURED_CHILDWINDOW_REGISTRATION(nId,nFeature) \
394         GetStaticInterface()->RegisterChildWindow( nId, (sal_Bool) sal_False, nFeature )
395 
396 #define SFX_CHILDWINDOW_CONTEXT_REGISTRATION(nId) \
397         GetStaticInterface()->RegisterChildWindow( nId, (sal_Bool) sal_True )
398 
399 #define SFX_POPUPMENU_REGISTRATION(rResId) \
400         GetStaticInterface()->RegisterPopupMenu( rResId )
401 
402 #define SFX_OBJECTMENU_REGISTRATION(nPos,rResId) \
403         GetStaticInterface()->RegisterObjectMenu( nPos, rResId )
404 
405 #define SFX_STATUSBAR_REGISTRATION(rResId) \
406         GetStaticInterface()->RegisterStatusBar( rResId )
407 
408 #endif
409 
410