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 .
21 #include <sfx2/shell.hxx>
22 #include <rtl/ustring.hxx>
23 #include <svl/poolitem.hxx>
24 #include <sfx2/dllapi.h>
25 #include <o3tl/typed_flags_set.hxx>
26 #include <sfx2/groupid.hxx>
33 enum class SfxSlotMode
{
34 NONE
= 0x0000, // default
36 TOGGLE
= 0x0004, // inverted for Execute old value
37 AUTOUPDATE
= 0x0008, // invalidated the status automatically after execute
38 ASYNCHRON
= 0x0020, // via Post-Message
40 NORECORD
= 0x0100, // no recording
41 RECORDPERITEM
= 0x0200, // each item, one statement
42 RECORDPERSET
= 0x0400, // The whole Set is a Statement, default
43 RECORDABSOLUTE
= 0x1000000, // Recording with absolute Target
47 FASTCALL
= 0x8000, // No test if disabled before Execute
49 MENUCONFIG
= 0x20000, // configurable Menu
50 TOOLBOXCONFIG
= 0x40000, // configurable Toolboxen
51 ACCELCONFIG
= 0x80000, // configurable keys
53 CONTAINER
= 0x100000, // Operated by the container at InPlace
54 READONLYDOC
= 0x200000, // also available for read-only Documents
55 VIEWERAPP
= 0x400000, // also available in Viewer app mode
60 template<> struct typed_flags
<SfxSlotMode
> : is_typed_flags
<SfxSlotMode
, 0x17ec72cL
> {};
63 #define SFX_EXEC_STUB( aShellClass, aExecMethod) \
64 void SfxStub##aShellClass##aExecMethod( \
65 SfxShell *pShell, SfxRequest& rReq) \
67 ::tools::detail::castTo<aShellClass*>(pShell)->aExecMethod( rReq ); \
70 #define SFX_STATE_STUB( aShellClass, aStateMethod) \
71 void SfxStub##aShellClass##aStateMethod( \
72 SfxShell *pShell, SfxItemSet& rSet) \
74 static_cast<aShellClass*>(pShell)->aStateMethod( rSet ); \
77 #define SFX_STUB_PTR( aShellClass, aMethod ) \
78 &SfxStub##aShellClass##aMethod
80 #define SFX_STUB_PTR_EXEC_NONE &SfxShell::EmptyExecStub
82 #define SFX_STUB_PTR_STATE_NONE &SfxShell::EmptyStateStub
85 enum class SfxSlotKind
98 template<class T
> SfxPoolItem
* createSfxPoolItem()
100 return T::CreateDefault();
105 SfxPoolItem
* (*createSfxPoolItemFunc
)();
106 const std::type_info
* pType
;
109 const std::type_info
* Type() const{return pType
;}
110 std::unique_ptr
<SfxPoolItem
> CreateItem() const
111 { return std::unique_ptr
<SfxPoolItem
>(createSfxPoolItemFunc()); }
112 inline const SfxTypeAttrib
& getAttrib(sal_uInt16 idx
) const;
115 struct SfxTypeImpl
: public SfxType
117 SfxTypeAttrib aAttrib
[1]; // variable length
120 // Some casting to work around the lack of zero-sized trailing arrays in c++
121 inline const SfxTypeAttrib
& SfxType::getAttrib(sal_uInt16 idx
) const
122 { return reinterpret_cast<const SfxTypeImpl
*>(this)->aAttrib
[idx
]; }
124 struct SfxType0
: public SfxType
127 #define SFX_DECL_TYPE(n) struct SfxType##n : public SfxType \
129 SfxTypeAttrib aAttrib[n]; \
132 #define SFX_TYPE(Class) &a##Class##_Impl
142 SFX_DECL_TYPE(9); // for SvxHyphenZoneItem
143 SFX_DECL_TYPE(10); // for SfxDocInfoItem
146 SFX_DECL_TYPE(13); // for SwAddPrinterItem, Sd...
148 SFX_DECL_TYPE(16); // for SwDocDisplayItem
149 SFX_DECL_TYPE(17); // for SvxAddressItem
150 SFX_DECL_TYPE(23); // for SvxSearchItem
152 // all SfxTypes must be in this header
155 #define SFX_SLOT_ARG( aShellClass, id, GroupId, ExecMethodPtr, StateMethodPtr, Flags, ItemClass, nArg0, nArgs, Name, Prop ) \
156 { id, GroupId, Flags | Prop, \
160 (const SfxType*) &a##ItemClass##_Impl, \
162 &a##aShellClass##Args_Impl[nArg0], nArgs, SfxDisableFlags::NONE, Name \
165 #define SFX_NEW_SLOT_ARG( aShellClass, id, GroupId, pNext, ExecMethodPtr, StateMethodPtr, Flags, DisableFlags, ItemClass, nArg0, nArgs, Prop, UnoName ) \
166 { id, GroupId, Flags | Prop, \
170 (const SfxType*) &a##ItemClass##_Impl, \
172 &a##aShellClass##Args_Impl[nArg0], nArgs, DisableFlags, UnoName \
175 struct SfxFormalArgument
177 const SfxType
* pType
; // Type of the parameter (SfxPoolItem subclass)
178 OUString aName
; // Name of the sParameters
179 sal_uInt16 nSlotId
; // Slot-Id for identification of the Parameters
181 std::unique_ptr
<SfxPoolItem
> CreateItem() const
182 { return pType
->CreateItem(); }
189 sal_uInt16 nSlotId
; // Unique slot-ID in Shell
190 SfxGroupId nGroupId
; // for configuration region
191 SfxSlotMode nFlags
; // arithmetic ordered Flags
193 sal_uInt16 nMasterSlotId
; // Enum-Slot for example Which-Id
194 sal_uInt16 nValue
; // Value, in case of Enum-Slot
196 SfxExecFunc fnExec
; // Function to be executed
197 SfxStateFunc fnState
; // Function for Status
199 const SfxType
* pType
; // SfxPoolItem-Type (Status)
201 const SfxSlot
* pNextSlot
; // with the same Status-Method
203 const SfxFormalArgument
* pFirstArgDef
; // first formal Argument-Definition
204 sal_uInt16 nArgDefCount
; // Number of formal Arguments
205 SfxDisableFlags nDisableFlags
; // DisableFlags that need to be
206 // present, so that the Slot
208 OUString aUnoName
; // UnoName for the Slots
210 SfxSlotKind
GetKind() const;
211 sal_uInt16
GetSlotId() const;
212 SfxSlotMode
GetMode() const;
213 bool IsMode( SfxSlotMode nMode
) const;
214 SfxGroupId
GetGroupId() const;
215 sal_uInt16
GetWhich( const SfxItemPool
&rPool
) const;
216 const SfxType
* GetType() const { return pType
; }
217 const OUString
& GetUnoName() const { return aUnoName
; }
218 SFX2_DLLPUBLIC OUString
GetCommand() const;
220 sal_uInt16
GetFormalArgumentCount() const { return nArgDefCount
; }
221 const SfxFormalArgument
& GetFormalArgument( sal_uInt16 nNo
) const
222 { return pFirstArgDef
[nNo
]; }
224 SfxExecFunc
GetExecFnc() const { return fnExec
; }
225 SfxStateFunc
GetStateFnc() const { return fnState
; }
227 const SfxSlot
* GetNextSlot() const { return pNextSlot
; }
231 // returns the id of the function
233 inline sal_uInt16
SfxSlot::GetSlotId() const
238 // returns a bitfield with flags
240 inline SfxSlotMode
SfxSlot::GetMode() const
246 // determines if the specified mode is assigned
248 inline bool SfxSlot::IsMode( SfxSlotMode nMode
) const
250 return bool(nFlags
& nMode
);
254 // returns the id of the associated group
256 inline SfxGroupId
SfxSlot::GetGroupId() const
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */