1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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>
33 namespace com::sun::star::embed
{ struct VerbDescriptor
; }
34 namespace com::sun::star::uno
{ template <class E
> class Sequence
; }
49 class SfxRepeatTarget
;
53 class SfxPoolItemHolder
;
56 Id for <SfxInterface>s, gives a quasi-static access to the interface
57 through an array to <SfxApplication>.
59 typedef o3tl::strong_int
<sal_uInt16
, struct SfxInterfaceIdTag
> SfxInterfaceId
;
61 constexpr auto SFX_INTERFACE_NONE
= SfxInterfaceId(0);
62 constexpr auto SFX_INTERFACE_SFXAPP
= SfxInterfaceId(1);
63 constexpr auto SFX_INTERFACE_SFXDOCSH
= SfxInterfaceId(2);
64 constexpr auto SFX_INTERFACE_SFXVIEWSH
= SfxInterfaceId(3);
65 constexpr auto SFX_INTERFACE_SFXVIEWFRM
= SfxInterfaceId(4);
66 constexpr auto SFX_INTERFACE_SFXMODULE
= SfxInterfaceId(5);
67 constexpr auto SFX_INTERFACE_SC_START
= SfxInterfaceId(150);
68 constexpr auto SFX_INTERFACE_SD_START
= SfxInterfaceId(200);
69 constexpr auto SFX_INTERFACE_SW_START
= SfxInterfaceId(250);
70 constexpr auto SFX_INTERFACE_SMA_START
= SfxInterfaceId(340);
71 constexpr auto SFX_INTERFACE_IDE_START
= SfxInterfaceId(400);
72 constexpr auto SFX_INTERFACE_IDE_END
= SfxInterfaceId(409);
74 enum class SfxShellFeature
77 // Writer only, class SwView
78 SwChildWindowLabel
= 0x0001,
79 // Basic only, class Shell
80 BasicShowBrowser
= 0x0004,
81 // Forms only, class FmFormShell
82 FormShowDatabaseBar
= 0x0008,
83 FormShowField
= 0x0010,
84 FormShowProperties
= 0x0020,
85 FormShowExplorer
= 0x0040,
86 FormShowFilterBar
= 0x0080,
87 FormShowFilterNavigator
= 0x0100,
88 FormShowTextControlBar
= 0x0200,
89 FormTBControls
= 0x0400,
90 FormTBDesign
= 0x1000,
91 FormShowDataNavigator
= 0x2000,
92 // masks to make sure modules don't use flags from another
99 template<> struct typed_flags
<SfxShellFeature
> : is_typed_flags
<SfxShellFeature
, 0x37fd> {};
102 /* Flags that are being used in the slot definitions for the disable-features */
103 enum class SfxDisableFlags
{
105 SwOnProtectedCursor
= 0x0001,
106 SwOnMailboxEditor
= 0x0002,
109 template<> struct typed_flags
<SfxDisableFlags
> : is_typed_flags
<SfxDisableFlags
, 0x0003> {};
112 typedef void (*SfxExecFunc
)(SfxShell
*, SfxRequest
&rReq
);
113 typedef void (*SfxStateFunc
)(SfxShell
*, SfxItemSet
&rSet
);
116 The class SfxShell is the base class for all classes, which provide
117 the functionality of the form <Slot>s.
119 Each instance has a reference to an interface description, which is
120 obtainable through <SfxShell::GetInterface()const>. This interface
121 provides the connection to specific methods and contains some other
122 descriptive data for controllers like menus and toolboxes, but also
123 for the various APIs. The main part of the interface description is in
124 the form of a <Type-Library>, which is generated from an IDL-file by
125 the <SVIDL-Compiler>. For each SfxShell Subclass-File there is one
126 such IDL-file to write.
128 class SFX2_DLLPUBLIC SfxShell
: public SfxBroadcaster
130 friend class SfxObjectItem
;
132 std::unique_ptr
< SfxShell_Impl
> pImpl
;
134 SfxUndoManager
* pUndoMgr
;
137 SfxShell( const SfxShell
& ) = delete;
138 SfxShell
& operator = ( const SfxShell
& ) = delete;
142 The constructor of the SfxShell class initializes only simple types,
143 the corresponding SbxObject is only created on-demand. Therefore,
144 the application of a SfxShell instance is very cheap.
149 The constructor of the SfxShell class initializes only simple types,
150 the corresponding SbxObject is only created on-demand. Therefore,
151 the application of a SfxShell instance is very cheap.
153 SfxShell( SfxViewShell
*pViewSh
);
155 void SetViewShell_Impl( SfxViewShell
* pView
);
156 SAL_DLLPRIVATE
void Invalidate_Impl( SfxBindings
& rBindings
, sal_uInt16 nId
);
157 static void HandleOpenXmlFilterSettings(SfxRequest
&);
162 The connection to a possible corresponding SbxObject is dissolved.
163 The SbxObject may continue to exist, but can not any longer perform
164 any functions and can not provide any properties.
166 virtual ~SfxShell() override
;
169 With this virtual method, which is automatically overridden by each subclass
170 with its own slots through the macro <SFX_DECL_INTERFACE>, one can access
171 each of the <SfxInterface> instance belonging to the subclass.
173 The class SfxShell itself has no own SfxInterface (no slots), therefore a
174 NULL-pointer is returned.
176 virtual SfxInterface
* GetInterface() const;
177 static SfxInterface
* GetStaticInterface() { return nullptr; }
180 Sets the name of the Shell object. With this name, the SfxShell instance
181 of BASIC can be expressed.
183 void SetName( const OUString
&rName
);
186 Returns the name of the Shell object. With this name, the SfxShell instance
187 of BASIC can be expressed.
189 const OUString
& GetName() const;
192 Returns the SfxViewShell in which they are located in the subshells.
193 Otherwise, and if not specified by the App developer, this method
196 SfxViewShell
* GetViewShell() const;
198 static void EmptyExecStub(SfxShell
*pShell
, SfxRequest
&);
199 static void EmptyStateStub(SfxShell
*pShell
, SfxItemSet
&);
202 This method returns the status of the slot with the specified slot ID
203 on the specified interface.
205 If the slot is disabled or in this SfxShell (and their parent shells) are
206 not known, a Null-pointer is returned.
208 If the slot does not have a Status, a SfxVoidItem is returned.
210 The status is set directly in this Set when pStateSet != 0 , so that
211 overridden Slots of the <SfxShell> Subclasses and also in the Status
212 method of the base implementation can be called.
216 In a derived class of SfxViewShell the SID_PRINTDOCDIRECT will be
217 intercepted. Under certain circumstances a query should appear before
218 you print, and the request will be aborted if necessary.
220 Also in the IDL of this subclass of the above slot is entered. The status
221 method will contain in outline:
223 void SubViewShell::PrintState( SfxItemSet &rState )
225 if ( rState.GetItemState( SID_PRINTDOCDIRECT ) != SfxItemState::UNKNOWN )
226 GetSlotState( SID_PRINTDOCDIRECT, SfxViewShell::GetInterface(),
233 <SfxShell::ExecuteSlot(SfxRequest&)>
235 SfxPoolItemHolder
GetSlotState( sal_uInt16 nSlotId
, const SfxInterface
*pIF
= nullptr, SfxItemSet
*pStateSet
= nullptr );
238 This method allows you to forward a <SfxRequest> to the specified
243 In a derived class of SfxViewShell the SID_PRINTDOCDIRECT will be
244 intercepted. Under certain circumstances a query should appear before
245 you print, and the request will be aborted if necessary.
247 Also in the IDL of this subclass of the above slot is entered. The status
248 method will contain in outline:
250 void SubViewShell::Exec( SfxRequest &rReq )
252 if ( rReq.GetSlot() == SID_PRINTDOCDIRECT )
256 ExecuteSlot( rReq, SfxViewShell::GetInterface() );
260 It usually takes no rReq.Done() to be called as that is already completed
261 in implementation of the SfxViewShell, for instance it has been canceled.
265 <SfxShell::GetSlotState(sal_uInt16,const SfxInterface*,SfxItemSet*)>
267 const SfxPoolItemHolder
& ExecuteSlot( SfxRequest
&rReq
, const SfxInterface
*pIF
= nullptr );
270 Asynchronous ExecuteSlot for the RELOAD
272 void ExecuteSlot( SfxRequest
&rReq
, bool bAsync
);
274 inline SfxItemPool
& GetPool() const;
275 inline void SetPool( SfxItemPool
*pNewPool
) ;
278 Each Subclass of SfxShell can have a <SfxUndoManager>. This can be set in
279 the derived class with <SfxShell:SetUndoManager()>.
281 The class SfxShell itself does not have a SfxUndoManager, a NULL-pointer
282 is therefore returned.
284 virtual SfxUndoManager
* GetUndoManager();
287 Sets a <SfxUndoManager> for this <SfxShell> Instance. For the undo
288 is only the undo-manager used for SfxShell at the top of the stack of each
291 On the given <SfxUndoManager> is automatically the current
292 Max-Undo-Action-Count setting set from the options.
294 'pNewUndoMgr' must exist until the Destructor of SfxShell instance is called
295 or until the next 'SetUndoManager()'.
297 void SetUndoManager( SfxUndoManager
*pNewUndoMgr
);
300 Returns a pointer to the <SfxRepeatTarget> instance that is used in
301 SID_REPEAT as repeat target when it is addressed from the <SfxUndoManager>
302 supplied by this SfxShell. The return value can be NULL.
306 A derivation of <SfxShell> or one of its subclasses of <SfxRepeatTarget>
307 is not recommended, as compiler errors are provoked.
308 (due to Call-to-Pointer-to-Member-Function to the subclass).
310 SfxRepeatTarget
* GetRepeatTarget() const;
313 Sets the <SfxRepeatTarget> instance that is used in SID_REPEAT as
314 RepeatTarget, when the current supplied by this <SfxUndoManager> is
315 addressed. By 'pTarget==0' the SID_REPEAT is disabled for this SfxShell.
316 The instance '*pTarget' must live as long as it is registered.
320 A derivation of <SfxShell> or one of its subclasses of <SfxRepeatTarget>
321 is not recommended, as compiler errors are provoked.
322 (due to Call-to-Pointer-to-Member-Function to the subclass).
324 void SetRepeatTarget( SfxRepeatTarget
*pTarget
);
327 With this method can the slots of the subclasses be invalidated through the
328 slot Id or alternatively through the Which ID. Slot IDs, which are
329 inherited by the subclass are also invalidated.
333 <SfxBindings::Invalidate(sal_uInt16)>
334 <SfxBindings::InvalidateAll(sal_Bool)>
336 virtual void Invalidate(sal_uInt16 nId
= 0);
338 virtual bool IsDesignMode() const { return false; };
340 bool IsActive() const;
343 Virtual method that is called when enabling the SfxShell instance,
344 in order to give the Subclasses the opportunity to respond to the
349 StarView SystemWindow::Activate(bool)
351 virtual void Activate(bool bMDI
);
354 Virtual method that is called when disabling the SfxShell instance,
355 to give the Subclasses the opportunity to respond to the disabling.
359 StarView SystemWindow::Deactivate(bool)
361 virtual void Deactivate(bool bMDI
);
364 This method returns a pointer to the <SfxDispatcher>, when the SfxShell
365 is currently <UI-active> or a NULL-pointer if it is not UI-active.
367 The returned pointer is only valid in the immediate context of the method
370 SfxDispatcher
* GetDispatcher() const;
373 This method returns a pointer to the <SfxViewFrame> to which this SfxShell
374 instance is associated or in which they currently is <UI-active>.
375 A NULL pointer is returned if this SfxShell instance is not UI-active at
376 the moment and also no SfxViewFrame is permanently assigned.
378 The returned pointer is only valid in the immediate context of the method
383 Only instances of a subclass of SfxApplication and SfxObjectShell
384 should here provide a NULL-pointer. Otherwise, there is an error in the
385 application program (wrong constructor was called from SfxShell).
389 <SfxViewShell::GetViewFrame()const>
391 SfxViewFrame
* GetFrame() const;
393 virtual bool HasUIFeature(SfxShellFeature nFeature
) const;
394 void UIFeatureChanged();
398 With this method any objects of <SfxPoolItemu> subclasses can be accessed.
399 This exchange method is needed if, for example special <SfxToolBoxControl>
400 subclasses need access to certain data such as the <SfxObjectShell>.
402 The returned instance belongs to the particular SfxShell and may be
403 used only in the immediate context of the method call.
407 <SfxShell::PutItem(const SfxPoolItem&)>
408 <SfxShell::RemoveItem(sal_uInt16)>
410 const SfxPoolItem
* GetItem( sal_uInt16 nSlotId
) const;
411 template<class T
> const T
* GetItem( TypedWhichId
<T
> nWhich
) const
413 return static_cast<const T
*>(GetItem(sal_uInt16(nWhich
)));
417 With this method, any objects of subclasses of <SfxPoolItem> can be made
418 available. This exchange technology is needed if, for example, special
419 <SfxToolBoxControl> Subclasses need access to certain data such as the
422 If a SfxPoolItem exists with the same slot ID, it is deleted automatically.
426 <SfxShell::RemoveItem(sal_uInt16)>
427 <SfxShell::GetItem(sal_uInt16)>
429 void PutItem( const SfxPoolItem
& rItem
);
431 // TODO/CLEANUP: still needed?!
432 void SetVerbs(const css::uno::Sequence
< css::embed::VerbDescriptor
>& aVerbs
);
433 const css::uno::Sequence
< css::embed::VerbDescriptor
>& GetVerbs() const;
434 void VerbExec (SfxRequest
&);
435 static void VerbState (SfxItemSet
&);
436 SAL_DLLPRIVATE
const SfxSlot
* GetVerbSlot_Impl(sal_uInt16 nId
) const;
438 virtual SfxObjectShell
* GetObjectShell();
439 void SetDisableFlags( SfxDisableFlags nFlags
);
440 SfxDisableFlags
GetDisableFlags() const;
442 virtual std::optional
<SfxItemSet
> CreateItemSet( sal_uInt16 nId
);
443 virtual void ApplyItemSet( sal_uInt16 nId
, const SfxItemSet
& rSet
);
445 /** Set the name of the sidebar context that is broadcast on calls
448 void SetContextName (const OUString
& rsContextName
);
450 /** Broadcast a sidebar context change.
451 This method is typically called from Activate() or
454 When <TRUE/> then broadcast the context name that was
455 defined with an earlier call to SetContextName().
456 When <FALSE/> then broadcast the 'default' context.
458 void BroadcastContextForActivation (const bool bIsActivated
);
460 /** Enabled or disable the context broadcaster. Returns the old state.
462 bool SetContextBroadcasterEnabled (const bool bIsEnabled
);
466 This method determines by calling the status function whether 'rSlot'
467 can be executed currently.
469 SAL_DLLPRIVATE
bool CanExecuteSlot_Impl( const SfxSlot
&rSlot
);
473 This method determines whether we need to execute without checking
474 the disabled state of the slot. This is used for dynamic conditions
475 while you can use SfxSlotMode::FASTCALL for a specific slotid in general.
477 virtual bool IsConditionalFastCall( const SfxRequest
&rReq
);
481 This method controls the activation of SfxShell instance. First, by calling
482 the virtual method <SfxShell::Activate(sal_Bool)> which gives the subclass the
483 opportunity to respond to the event.
485 When bMDI == TRUE, the associated SbxObject is being 'armed', so that
486 unqualified methods of the object (without the name of the object)
487 from BASIC are found.
489 SAL_DLLPRIVATE
void DoActivate_Impl( SfxViewFrame
*pFrame
, bool bMDI
);
493 This method controls the deactivation of the SfxShell instance. When
494 bMDI == TRUE the SbxObject is first set to a status that only qualified
495 BASIC methods can be called.
497 Then the subclass gets the opportunity in every case to respond to the
498 event by calling the virtual method <SfxShell::Deactivate(sal_Bool)>.
500 SAL_DLLPRIVATE
void DoDeactivate_Impl( SfxViewFrame
const *pFrame
, bool bMDI
);
504 Each Subclass of SfxShell must reference a pool. This is partly set by
505 SFx's own set of subclasses (eg <SfxViewShell>). In particular however
506 this must be set directly from one derived SfxShell class and ny
507 derivatives of SfxObjectShell.
509 The SfxShell class itself does not have any SfxItemPool, therefore a
510 null-pointer is returned.
512 SfxItemPool
& SfxShell::GetPool() const
514 assert(pPool
&& "no pool");
519 With this method, the subclasses register their special <SfxItemPool>
520 in the SfxShell. Each SfxShell instance must have access to a SfxItemPool.
521 Usually this is the SfxItemPool of the SfxDocumentShell. The SfxShell
522 subclass does not take ownership of the orphaned pool. Before it is
523 deleted it has to be deregistered with SetPool(0).
525 inline void SfxShell::SetPool
527 SfxItemPool
* pNewPool
// Pointer to the new Pool or null
533 #define SFX_DECL_INTERFACE(nId) \
534 static SfxInterface* s_pInterface; \
535 static SfxInterface* GetStaticInterface(); \
536 static SfxInterfaceId GetInterfaceId() {return nId;} \
537 static void RegisterInterface(const SfxModule* pMod=nullptr); \
538 virtual SfxInterface* GetInterface() const override;
540 #define SFX_TMPL_INTERFACE(Class,SuperClass,Abstract) \
542 SfxInterface* Class::s_pInterface = nullptr; \
543 SfxInterface* Class::GetStaticInterface() \
545 if ( !s_pInterface ) \
549 #Class, Abstract, GetInterfaceId(), \
550 SuperClass::GetStaticInterface(), \
551 a##Class##Slots_Impl[0], \
552 sal_uInt16(sizeof(a##Class##Slots_Impl) / sizeof(SfxSlot) ) ); \
553 InitInterface_Impl(); \
555 return s_pInterface; \
558 SfxInterface* Class::GetInterface() const \
560 return GetStaticInterface(); \
563 void Class::RegisterInterface(const SfxModule* pMod) \
565 GetStaticInterface()->Register(pMod); \
568 #define SFX_IMPL_INTERFACE(Class,SuperClass) \
569 SFX_TMPL_INTERFACE(Class,SuperClass,false) \
571 #define SFX_IMPL_SUPERCLASS_INTERFACE(Class,SuperClass) \
572 SFX_TMPL_INTERFACE(Class,SuperClass,true) \
574 enum class SfxVisibilityFlags {
575 Invisible
= 0x0000, // Never visible
577 ReadonlyDoc
= 0x0400,
584 template<> struct typed_flags
<SfxVisibilityFlags
> : is_typed_flags
<SfxVisibilityFlags
, 0xf440> {};
588 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */