lok: calc - send other views our selection in their co-ordinates.
[LibreOffice.git] / include / sfx2 / shell.hxx
blob2edcb6a36bb29832ae5857303c3c389b6ee321d4
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_SHELL_HXX
20 #define INCLUDED_SFX2_SHELL_HXX
22 #include <memory>
23 #include <rtl/ustring.hxx>
24 #include <sal/config.h>
25 #include <sal/types.h>
26 #include <svl/typedwhich.hxx>
27 #include <sfx2/dllapi.h>
28 #include <svl/SfxBroadcaster.hxx>
29 #include <o3tl/typed_flags_set.hxx>
30 #include <o3tl/strong_int.hxx>
32 namespace com::sun::star::embed { struct VerbDescriptor; }
33 namespace com::sun::star::uno { template <class E> class Sequence; }
35 class SfxItemPool;
36 class SfxPoolItem;
37 class SfxRequest;
38 class SfxItemSet;
39 class SfxInterface;
40 class SfxViewShell;
41 class SfxObjectShell;
43 class SfxShell;
44 struct SfxShell_Impl;
45 class SfxDispatcher;
46 class SfxViewFrame;
47 class SfxSlot;
48 class SfxRepeatTarget;
49 class SfxBindings;
50 class SfxModule;
51 class SfxUndoManager;
53 /**
54 Id for <SfxInterface>s, gives a quasi-static access to the interface
55 through an array to <SfxApplication>.
57 typedef o3tl::strong_int<sal_uInt16, struct SfxInterfaceIdTag> SfxInterfaceId;
59 constexpr auto SFX_INTERFACE_NONE = SfxInterfaceId(0);
60 constexpr auto SFX_INTERFACE_SFXAPP = SfxInterfaceId(1);
61 constexpr auto SFX_INTERFACE_SFXDOCSH = SfxInterfaceId(2);
62 constexpr auto SFX_INTERFACE_SFXVIEWSH = SfxInterfaceId(3);
63 constexpr auto SFX_INTERFACE_SFXVIEWFRM = SfxInterfaceId(4);
64 constexpr auto SFX_INTERFACE_SFXMODULE = SfxInterfaceId(5);
65 constexpr auto SFX_INTERFACE_SC_START = SfxInterfaceId(150);
66 constexpr auto SFX_INTERFACE_SD_START = SfxInterfaceId(200);
67 constexpr auto SFX_INTERFACE_SW_START = SfxInterfaceId(250);
68 constexpr auto SFX_INTERFACE_SMA_START = SfxInterfaceId(340);
69 constexpr auto SFX_INTERFACE_IDE_START = SfxInterfaceId(400);
70 constexpr auto SFX_INTERFACE_IDE_END = SfxInterfaceId(409);
72 enum class SfxShellFeature
74 NONE = 0x0000,
75 // Writer only, class SwView
76 SwChildWindowLabel = 0x0001,
77 // Basic only, class Shell
78 BasicShowBrowser = 0x0004,
79 // Forms only, class FmFormShell
80 FormShowDatabaseBar = 0x0008,
81 FormShowField = 0x0010,
82 FormShowProperies = 0x0020,
83 FormShowExplorer = 0x0040,
84 FormShowFilterBar = 0x0080,
85 FormShowFilterNavigator = 0x0100,
86 FormShowTextControlBar = 0x0200,
87 FormTBControls = 0x0400,
88 FormTBDesign = 0x1000,
89 FormShowDataNavigator = 0x2000,
90 // masks to make sure modules don't use flags from another
91 SwMask = 0x0001,
92 BasicMask = 0x0004,
93 FormMask = 0x3ff8
95 namespace o3tl
97 template<> struct typed_flags<SfxShellFeature> : is_typed_flags<SfxShellFeature, 0x3ffd> {};
100 /* Flags that are being used in the slot definitions for the disable-features */
101 enum class SfxDisableFlags {
102 NONE,
103 SwOnProtectedCursor = 0x0001,
104 SwOnMailboxEditor = 0x0002,
106 namespace o3tl {
107 template<> struct typed_flags<SfxDisableFlags> : is_typed_flags<SfxDisableFlags, 0x0003> {};
110 typedef void (*SfxExecFunc)(SfxShell *, SfxRequest &rReq);
111 typedef void (*SfxStateFunc)(SfxShell *, SfxItemSet &rSet);
114 The class SfxShell is the base class for all classes, which provide
115 the functionality of the form <Slot>s.
117 Each instance has a reference to an interface description, which is
118 obtainable through <SfxShell::GetInterface()const>. This interface
119 provides the connection to specific methods and contains some other
120 descriptive data for controllers like menus and toolboxes, but also
121 for the various APIs. The main part of the interface description is in
122 the form of a <Type-Library>, which is generated from an IDL-file by
123 the <SVIDL-Compiler>. For each SfxShell Subclass-File there is one
124 such IDL-file to write.
126 class SFX2_DLLPUBLIC SfxShell: public SfxBroadcaster
128 friend class SfxObjectItem;
130 std::unique_ptr< SfxShell_Impl > pImpl;
131 SfxItemPool* pPool;
132 SfxUndoManager* pUndoMgr;
134 private:
135 SfxShell( const SfxShell & ) = delete;
136 SfxShell& operator = ( const SfxShell & ) = delete;
138 protected:
140 The constructor of the SfxShell class initializes only simple types,
141 the corresponding SbxObject is only created on-demand. Therefore,
142 the application of a SfxShell instance is very cheap.
144 SfxShell();
147 The constructor of the SfxShell class initializes only simple types,
148 the corresponding SbxObject is only created on-demand. Therefore,
149 the application of a SfxShell instance is very cheap.
151 SfxShell( SfxViewShell *pViewSh );
153 void SetViewShell_Impl( SfxViewShell* pView );
154 SAL_DLLPRIVATE void Invalidate_Impl( SfxBindings& rBindings, sal_uInt16 nId );
155 static void HandleOpenXmlFilterSettings(SfxRequest &);
157 public:
160 The connection to a possible corresponding SbxObject is dissolved.
161 The SbxObject may continue to exist, but can not any longer perform
162 any functions and can not provide any properties.
164 virtual ~SfxShell() override;
167 With this virtual method, which is automatically overridden by each subclass
168 with its own slots through the macro <SFX_DECL_INTERFACE>, one can access
169 each of the <SfxInterface> instance belonging to the subclass.
171 The class SfxShell itself has no own SfxInterface (no slots), therefore a
172 NULL-pointer is returned.
174 virtual SfxInterface* GetInterface() const;
175 static SfxInterface* GetStaticInterface() { return nullptr; }
178 Sets the name of the Shell object. With this name, the SfxShell instance
179 of BASIC can be expressed.
181 void SetName( const OUString &rName );
184 Returns the name of the Shell object. With this name, the SfxShell instance
185 of BASIC can be expressed.
187 const OUString& GetName() const;
190 Returns the SfxViewShell in which they are located in the subshells.
191 Otherwise, and if not specified by the App developer, this method
192 returns NULL.
194 SfxViewShell* GetViewShell() const;
196 void CallExec( SfxExecFunc pFunc, SfxRequest &rReq )
197 { (*pFunc)(this, rReq); }
198 void CallState( SfxStateFunc pFunc, SfxItemSet &rSet )
199 { (*pFunc)(this, rSet); }
201 static void EmptyExecStub(SfxShell *pShell, SfxRequest &);
202 static void EmptyStateStub(SfxShell *pShell, SfxItemSet &);
205 This method returns the status of the slot with the specified slot ID
206 on the specified interface.
208 If the slot is disabled or in this SfxShell (and their parent shells) are
209 not known, a Null-pointer is returned.
211 If the slot does not have a Status, a SfxVoidItem is returned.
213 The status is set directly in this Set when pStateSet != 0 , so that
214 overridden Slots of the <SfxShell> Subclasses and also in the Status
215 method of the base implementation can be called.
217 [Example]
219 In a derived class of SfxViewShell the SID_PRINTDOCDIRECT will be
220 intercepted. Under certain circumstances a query should appear before
221 you print, and the request will be aborted if necessary.
223 Also in the IDL of this subclass of the above slot is entered. The status
224 method will contain in outline:
226 void SubViewShell::PrintState( SfxItemSet &rState )
228 if ( rState.GetItemState( SID_PRINTDOCDIRECT ) != SfxItemState::UNKNOWN )
229 GetSlotState( SID_PRINTDOCDIRECT, SfxViewShell::GetInterface(),
230 &rState );
234 [Cross-reference]
236 <SfxShell::ExecuteSlot(SfxRequest&)>
238 const SfxPoolItem* GetSlotState( sal_uInt16 nSlotId, const SfxInterface *pIF = nullptr, SfxItemSet *pStateSet = nullptr );
241 This method allows you to forward a <SfxRequest> to the specified
242 base <SfxShell>.
244 [Example]
246 In a derived class of SfxViewShell the SID_PRINTDOCDIRECT will be
247 intercepted. Under certain circumstances a query should appear before
248 you print, and the request will be aborted if necessary.
250 Also in the IDL of this subclass of the above slot is entered. The status
251 method will contain in outline:
253 void SubViewShell::Exec( SfxRequest &rReq )
255 if ( rReq.GetSlot() == SID_PRINTDOCDIRECT )
257 'dialog'
258 if ( 'condition' )
259 ExecuteSlot( rReq, SfxViewShell::GetInterface() );
263 It usually takes no rReq.Done() to be called as that is already completed
264 in implementation of the SfxViewShell, for instance it has been canceled.
266 [Cross-reference]
268 <SfxShell::GetSlotState(sal_uInt16,const SfxInterface*,SfxItemSet*)>
270 const SfxPoolItem* ExecuteSlot( SfxRequest &rReq, const SfxInterface *pIF = nullptr );
273 Asynchronous ExecuteSlot for the RELOAD
275 void ExecuteSlot( SfxRequest &rReq, bool bAsync );
277 inline SfxItemPool& GetPool() const;
278 inline void SetPool( SfxItemPool *pNewPool ) ;
281 Each Subclass of SfxShell can have a <SfxUndoManager>. This can be set in
282 the derived class with <SfxShell:SetUndoManager()>.
284 The class SfxShell itself does not have a SfxUndoManager, a NULL-pointer
285 is therefore returned.
287 virtual SfxUndoManager* GetUndoManager();
290 Sets a <SfxUndoManager> for this <SfxShell> Instance. For the undo
291 is only the undo-manager used for SfxShell at the top of the stack of each
292 <SfxDispatcher>.
294 On the given <SfxUndoManager> is automatically the current
295 Max-Undo-Action-Count setting set from the options.
297 'pNewUndoMgr' must exist until the Destructor of SfxShell instance is called
298 or until the next 'SetUndoManager()'.
300 void SetUndoManager( SfxUndoManager *pNewUndoMgr );
303 Returns a pointer to the <SfxRepeatTarget> instance that is used in
304 SID_REPEAT as repeat target when it is addressed from the <SfxUndoManager>
305 supplied by this SfxShell. The return value can be NULL.
307 [Note]
309 A derivation of <SfxShell> or one of its subclasses of <SfxRepeatTarget>
310 is not recommended, as compiler errors are provoked.
311 (due to Call-to-Pointer-to-Member-Function to the subclass).
313 SfxRepeatTarget* GetRepeatTarget() const;
316 Sets the <SfxRepeatTarget> instance that is used in SID_REPEAT as
317 RepeatTarget, when the current supplied by this <SfxUndoManager> is
318 addressed. By 'pTarget==0' the SID_REPEAT is disabled for this SfxShell.
319 The instance '*pTarget' must live as long as it is registered.
321 [Note]
323 A derivation of <SfxShell> or one of its subclasses of <SfxRepeatTarget>
324 is not recommended, as compiler errors are provoked.
325 (due to Call-to-Pointer-to-Member-Function to the subclass).
327 void SetRepeatTarget( SfxRepeatTarget *pTarget );
330 With this method can the slots of the subclasses be invalidated through the
331 slot Id or alternatively through the Which ID. Slot IDs, which are
332 inherited by the subclass are also invalidated.
334 [Cross-reference]
336 <SfxBindings::Invalidate(sal_uInt16)>
337 <SfxBindings::InvalidateAll(sal_Bool)>
339 virtual void Invalidate(sal_uInt16 nId = 0);
341 virtual bool IsDesignMode() const { return false; };
343 bool IsActive() const;
346 Virtual method that is called when enabling the SfxShell instance,
347 in order to give the Subclasses the opportunity to respond to the
348 to the enabling.
350 [Cross-reference]
352 StarView SystemWindow::Activate(bool)
354 virtual void Activate(bool bMDI);
357 Virtual method that is called when disabling the SfxShell instance,
358 to give the Subclasses the opportunity to respond to the disabling.
360 [Cross-reference]
362 StarView SystemWindow::Deactivate(bool)
364 virtual void Deactivate(bool bMDI);
367 This method returns a pointer to the <SfxDispatcher>, when the SfxShell
368 is currently <UI-active> or a NULL-pointer if it is not UI-active.
370 The returned pointer is only valid in the immediate context of the method
371 call.
373 SfxDispatcher* GetDispatcher() const;
376 This method returns a pointer to the <SfxViewFrame> to which this SfxShell
377 instance is associated or in which they currently is <UI-active>.
378 A NULL pointer is returned if this SfxShell instance is not UI-active at
379 the moment and also no SfxViewFrame is permanently assigned.
381 The returned pointer is only valid in the immediate context of the method
382 call.
384 [Note]
386 Only instances of a subclass of SfxApplication and SfxObjectShell
387 should here provide a NULL-pointer. Otherwise, there is an error in the
388 application program (wrong constructor was called from SfxShell).
390 [Cross-reference]
392 <SfxViewShell::GetViewFrame()const>
394 SfxViewFrame* GetFrame() const;
396 virtual bool HasUIFeature(SfxShellFeature nFeature) const;
397 void UIFeatureChanged();
399 // Items
401 With this method any objects of <SfxPoolItemu> subclasses can be accessed.
402 This exchange method is needed if, for example special <SfxToolBoxControl>
403 subclasses need access to certain data such as the <SfxObjectShell>.
405 The returned instance belongs to the particular SfxShell and may be
406 used only in the immediate context of the method call.
408 [Cross-reference]
410 <SfxShell::PutItem(const SfxPoolItem&)>
411 <SfxShell::RemoveItem(sal_uInt16)>
413 const SfxPoolItem* GetItem( sal_uInt16 nSlotId ) const;
414 template<class T> const T* GetItem( TypedWhichId<T> nWhich ) const
416 return static_cast<const T*>(GetItem(sal_uInt16(nWhich)));
420 With this method, any objects of subclasses of <SfxPoolItem> can be made
421 available. This exchange technology is needed if, for example, special
422 <SfxToolBoxControl> Subclasses need access to certain data such as the
423 <SfxObjectShell>
425 If a SfxPoolItem exists with the same slot ID, it is deleted automatically.
427 [Cross-reference]
429 <SfxShell::RemoveItem(sal_uInt16)>
430 <SfxShell::GetItem(sal_uInt16)>
432 void PutItem( const SfxPoolItem& rItem );
434 // TODO/CLEANUP: still needed?!
435 void SetVerbs(const css::uno::Sequence < css::embed::VerbDescriptor >& aVerbs);
436 const css::uno::Sequence < css::embed::VerbDescriptor >& GetVerbs() const;
437 void VerbExec (SfxRequest&);
438 static void VerbState (SfxItemSet&);
439 SAL_DLLPRIVATE const SfxSlot* GetVerbSlot_Impl(sal_uInt16 nId) const;
441 virtual SfxObjectShell* GetObjectShell();
442 void SetDisableFlags( SfxDisableFlags nFlags );
443 SfxDisableFlags GetDisableFlags() const;
445 virtual std::unique_ptr<SfxItemSet> CreateItemSet( sal_uInt16 nId );
446 virtual void ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet );
448 /** Set the name of the sidebar context that is broadcast on calls
449 to Activation().
451 void SetContextName (const OUString& rsContextName);
453 /** Broadcast a sidebar context change.
454 This method is typically called from Activate() or
455 Deactivate().
456 @param bIsActivated
457 When <TRUE/> then broadcast the context name that was
458 defined with an earlier call to SetContextName().
459 When <FALSE/> then broadcast the 'default' context.
461 void BroadcastContextForActivation (const bool bIsActivated);
463 /** Enabled or disable the context broadcaster. Returns the old state.
465 bool SetContextBroadcasterEnabled (const bool bIsEnabled);
469 This method determines by calling the status function whether 'rSlot'
470 can be executed currently.
472 SAL_DLLPRIVATE bool CanExecuteSlot_Impl( const SfxSlot &rSlot );
476 This method determines whether we need to execute without checking
477 the disabled state of the slot. This is used for dynamic conditions
478 while you can use SfxSlotMode::FASTCALL for a specific slotid in general.
480 virtual bool IsConditionalFastCall( const SfxRequest &rReq );
484 This method controls the activation of SfxShell instance. First, by calling
485 the virtual method <SfxShell::Activate(sal_Bool)> which gives the subclass the
486 opportunity to respond to the event.
488 When bMDI == TRUE, the associated SbxObject is being 'armed', so that
489 unqualified methods of the object (without the name of the object)
490 from BASIC are found.
492 SAL_DLLPRIVATE void DoActivate_Impl( SfxViewFrame *pFrame, bool bMDI);
496 This method controls the deactivation of the SfxShell instance. When
497 bMDI == TRUE the SbxObject is first set to a status that only qualified
498 BASIC methods can be called.
500 Then the subclass gets the opportunity in every case to respond to the
501 event by calling the virtual method <SfxShell::Deactivate(sal_Bool)>.
503 SAL_DLLPRIVATE void DoDeactivate_Impl( SfxViewFrame const *pFrame, bool bMDI);
507 Each Subclass of SfxShell must reference a pool. This is partly set by
508 SFx's own set of subclasses (eg <SfxViewShell>). In particular however
509 this must be set directly from one derived SfxShell class and ny
510 derivatives of SfxObjectShell.
512 The SfxShell class itself does not have any SfxItemPool, therefore a
513 null-pointer is returned.
515 SfxItemPool& SfxShell::GetPool() const
517 assert(pPool && "no pool");
518 return *pPool;
522 With this method, the subclasses register their special <SfxItemPool>
523 in the SfxShell. Each SfxShell instance must have access to a SfxItemPool.
524 Usually this is the SfxItemPool of the SfxDocumentShell. The SfxShell
525 subclass does not take ownership of the orphaned pool. Before it is
526 deleted it has to be deregistered with SetPool(0).
528 inline void SfxShell::SetPool
530 SfxItemPool* pNewPool // Pointer to the new Pool or null
533 pPool = pNewPool;
536 #define SFX_DECL_INTERFACE(nId) \
537 static SfxInterface* pInterface; \
538 static SfxInterface* GetStaticInterface(); \
539 static SfxInterfaceId GetInterfaceId() {return nId;} \
540 static void RegisterInterface(SfxModule* pMod=nullptr); \
541 virtual SfxInterface* GetInterface() const override;
543 #define SFX_TMPL_INTERFACE(Class,SuperClass,Abstract) \
545 SfxInterface* Class::pInterface = nullptr; \
546 SfxInterface* Class::GetStaticInterface() \
548 if ( !pInterface ) \
550 pInterface = \
551 new SfxInterface( \
552 #Class, Abstract, GetInterfaceId(), \
553 SuperClass::GetStaticInterface(), \
554 a##Class##Slots_Impl[0], \
555 sal_uInt16(sizeof(a##Class##Slots_Impl) / sizeof(SfxSlot) ) ); \
556 InitInterface_Impl(); \
558 return pInterface; \
561 SfxInterface* Class::GetInterface() const \
563 return GetStaticInterface(); \
566 void Class::RegisterInterface(SfxModule* pMod) \
568 GetStaticInterface()->Register(pMod); \
571 #define SFX_IMPL_INTERFACE(Class,SuperClass) \
572 SFX_TMPL_INTERFACE(Class,SuperClass,false) \
574 #define SFX_IMPL_SUPERCLASS_INTERFACE(Class,SuperClass) \
575 SFX_TMPL_INTERFACE(Class,SuperClass,true) \
577 enum class SfxVisibilityFlags {
578 Invisible = 0x0000, // Never visible
579 Viewer = 0x0040,
580 ReadonlyDoc = 0x0400,
581 Standard = 0x1000,
582 FullScreen = 0x2000,
583 Client = 0x4000,
584 Server = 0x8000,
586 namespace o3tl {
587 template<> struct typed_flags<SfxVisibilityFlags> : is_typed_flags<SfxVisibilityFlags, 0xf440> {};
589 #endif
591 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */