xref: /aoo41x/main/sfx2/inc/sfx2/shell.hxx (revision f120fe41)
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     void                        SetContextName (const ::rtl::OUString& rsContextName);
258 
259 #ifndef _SFXSH_HXX
260     SAL_DLLPRIVATE bool     CanExecuteSlot_Impl( const SfxSlot &rSlot );
261     SAL_DLLPRIVATE void DoActivate_Impl( SfxViewFrame *pFrame, sal_Bool bMDI);
262     SAL_DLLPRIVATE void DoDeactivate_Impl( SfxViewFrame *pFrame, sal_Bool bMDI);
263 #endif
264 };
265 
266 //--------------------------------------------------------------------
267 SfxItemPool& SfxShell::GetPool() const
268 /*
269   [Beschreibung]
270 
271 	Jede Subclass von SfxShell mu"s einen Pool referenzieren. Dieser
272 	wird teilweise von SFx-eigenen Subklassen gesetzt (z.B. <SfxViewShell>),
273 	mu"s aber insbesondere bei direkt von SfxShell abgeleiteten Klassen
274 	und bei Ableitungen von SfxObjectShell selbst gesetzt werden.
275 
276 	Die Klasse SfxShell selbst hat noch keinen SfxItemPool, es wird
277 	daher ein 0-Pointer zur"uckgeliefert.
278 */
279 
280 {
281 	DBG_ASSERT( pPool, "no pool" );
282 	return *pPool;
283 }
284 //-------------------------------------------------------------------
285 inline void SfxShell::SetPool
286 (
287 	SfxItemPool*	pNewPool	// Pointer auf den neuen Pool oder 0
288 )
289 
290 /*  [Beschreibung]
291 
292 	Mit dieser Methode melden die Subklassen ihren speziellen <SfxItemPool>
293 	an der SfxShell an. Jede SfxShell Instanz mu\s Zugriff auf einen
294 	SfxItemPool haben. In der Regel ist dies der SfxItemPool der
295 	SfxDocumentShell. Die SfxShell Subklasse "ubernimmt nicht die
296 	Eigent"umerschaft "uber den "ubergebenen Pool. Bevor er gel"oscht
297 	wirde, mu\s er mit SetPool(0) abgemeldet werden.
298 */
299 
300 {
301 	pPool = pNewPool;
302 }
303 
304 //=====================================================================
305 
306 #define SFX_ARGUMENTMAP(ShellClass) static SfxFormalArgument __FAR_DATA a##ShellClass##Args_Impl[] =
307 
308 #define SFX_SLOTMAP(ShellClass) static SfxFormalArgument __FAR_DATA a##ShellClass##Args_Impl[1]; \
309 								static SfxSlot __FAR_DATA a##ShellClass##Slots_Impl[] =
310 
311 #define SFX_SLOTMAP_ARG(ShellClass) static SfxSlot __FAR_DATA a##ShellClass##Slots_Impl[] =
312 
313 #define SFX_DECL_INTERFACE(nId) 											\
314             static SfxInterface*                pInterface;                 \
315         private:                                                            \
316 			static void 						InitInterface_Impl();		\
317         public:                                                             \
318             static const SfxFormalArgument*     pSfxFormalArgs_Impl;        \
319             static SfxInterface*                GetStaticInterface();       \
320             static SfxInterfaceId               GetInterfaceId() {return SfxInterfaceId(nId);} \
321             static void                         RegisterInterface(SfxModule* pMod=NULL); \
322             virtual SfxInterface*       GetInterface() const;
323 
324 #define SFX_IMPL_INTERFACE(Class,SuperClass,NameResId)                      \
325 																			\
326     SfxInterface* Class::pInterface = 0;                                    \
327     const SfxFormalArgument* Class::pSfxFormalArgs_Impl = a##Class##Args_Impl;\
328     SfxInterface* __EXPORT Class::GetStaticInterface()                      \
329     {                                                                       \
330         if ( !pInterface )                                                  \
331         {                                                                   \
332             pInterface =                                                    \
333                 new SfxInterface(                                           \
334             #Class, NameResId, GetInterfaceId(),                            \
335             SuperClass::GetStaticInterface(),                               \
336             a##Class##Slots_Impl[0],                                        \
337             (sal_uInt16) (sizeof(a##Class##Slots_Impl) / sizeof(SfxSlot) ) );   \
338             InitInterface_Impl();                                           \
339         }                                                                   \
340         return pInterface;                                                  \
341     }                                                                       \
342 																			\
343     SfxInterface* Class::GetInterface() const                               \
344     {                                                                       \
345         return GetStaticInterface();                                        \
346     }                                                                       \
347                                                                             \
348     void Class::RegisterInterface(SfxModule* pMod)                          \
349     {                                                                       \
350         GetStaticInterface()->Register(pMod);                               \
351     }                                                                       \
352 																			\
353 	void Class::InitInterface_Impl()
354 
355 #define SFX_POSITION_MASK				0x000F
356 #define SFX_VISIBILITY_MASK 			0xFFF0
357 #define SFX_VISIBILITY_UNVISIBLE		0x0000	// nie sichtbar
358 #define SFX_VISIBILITY_PLUGSERVER       0x0010
359 #define SFX_VISIBILITY_PLUGCLIENT       0x0020
360 #define SFX_VISIBILITY_VIEWER	        0x0040
361 												// noch 1 sind frei!
362 #define SFX_VISIBILITY_RECORDING		0x0200
363 #define SFX_VISIBILITY_READONLYDOC		0x0400
364 #define SFX_VISIBILITY_DESKTOP    		0x0800
365 #define SFX_VISIBILITY_STANDARD 		0x1000
366 #define SFX_VISIBILITY_FULLSCREEN		0x2000
367 #define SFX_VISIBILITY_CLIENT			0x4000
368 #define SFX_VISIBILITY_SERVER			0x8000
369 #define SFX_VISIBILITY_NOCONTEXT		0xFFFF	// immer sichtbar
370 
371 #define SFX_OBJECTBAR_REGISTRATION(nPos,rResId) \
372         GetStaticInterface()->RegisterObjectBar( nPos, rResId )
373 
374 #define SFX_FEATURED_OBJECTBAR_REGISTRATION(nPos,rResId,nFeature) \
375         GetStaticInterface()->RegisterObjectBar( nPos, rResId, nFeature )
376 
377 #define SFX_CHILDWINDOW_REGISTRATION(nId) \
378         GetStaticInterface()->RegisterChildWindow( nId, (sal_Bool) sal_False )
379 
380 #define SFX_FEATURED_CHILDWINDOW_REGISTRATION(nId,nFeature) \
381         GetStaticInterface()->RegisterChildWindow( nId, (sal_Bool) sal_False, nFeature )
382 
383 #define SFX_CHILDWINDOW_CONTEXT_REGISTRATION(nId) \
384         GetStaticInterface()->RegisterChildWindow( nId, (sal_Bool) sal_True )
385 
386 #define SFX_POPUPMENU_REGISTRATION(rResId) \
387         GetStaticInterface()->RegisterPopupMenu( rResId )
388 
389 #define SFX_OBJECTMENU_REGISTRATION(nPos,rResId) \
390         GetStaticInterface()->RegisterObjectMenu( nPos, rResId )
391 
392 #define SFX_STATUSBAR_REGISTRATION(rResId) \
393         GetStaticInterface()->RegisterStatusBar( rResId )
394 
395 #endif
396 
397