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