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