LibreOffice Module sfx2 (master) 1
msg.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_SFX2_MSG_HXX
20#define INCLUDED_SFX2_MSG_HXX
21
22#include <sfx2/shell.hxx>
23#include <rtl/string.hxx>
24#include <rtl/ustring.hxx>
25#include <svl/poolitem.hxx>
26#include <sfx2/dllapi.h>
28#include <sfx2/groupid.hxx>
29#include <functional>
30
31#include <climits>
32
33class SfxItemPool;
34
35enum class SfxSlotMode {
36 NONE = 0x0000, // default
37
38 TOGGLE = 0x0004, // inverted for Execute old value
39 AUTOUPDATE = 0x0008, // invalidated the status automatically after execute
40 ASYNCHRON = 0x0020, // via Post-Message
41
42 NORECORD = 0x0100, // no recording
43 RECORDPERITEM = 0x0200, // each item, one statement
44 RECORDPERSET = 0x0400, // The whole Set is a Statement, default
45 RECORDABSOLUTE = 0x1000000, // Recording with absolute Target
46
47 METHOD = 0x4000,
48
49 FASTCALL = 0x8000, // No test if disabled before Execute
50
51 MENUCONFIG = 0x20000, // configurable Menu
52 TOOLBOXCONFIG = 0x40000, // configurable Toolboxen
53 ACCELCONFIG = 0x80000, // configurable keys
54
55 CONTAINER = 0x100000, // Operated by the container at InPlace
56 READONLYDOC = 0x200000 // also available for read-only Documents
57};
58
59namespace o3tl
60{
61 template<> struct typed_flags<SfxSlotMode> : is_typed_flags<SfxSlotMode, 0x13ec72cL> {};
62}
63
64#define SFX_EXEC_STUB( aShellClass, aExecMethod) \
65 void SfxStub##aShellClass##aExecMethod( \
66 SfxShell *pShell, SfxRequest& rReq) \
67 { \
68 ::tools::detail::castTo<aShellClass*>(pShell)->aExecMethod( rReq ); \
69 }
70
71#define SFX_STATE_STUB( aShellClass, aStateMethod) \
72 void SfxStub##aShellClass##aStateMethod( \
73 SfxShell *pShell, SfxItemSet& rSet) \
74 { \
75 static_cast<aShellClass*>(pShell)->aStateMethod( rSet ); \
76 }
77
78#define SFX_STUB_PTR( aShellClass, aMethod ) \
79 &SfxStub##aShellClass##aMethod
80
81#define SFX_STUB_PTR_EXEC_NONE &SfxShell::EmptyExecStub
82
83#define SFX_STUB_PTR_STATE_NONE &SfxShell::EmptyStateStub
84
85
86enum class SfxSlotKind
87{
90};
91
92
94{
95 sal_uInt16 nAID;
96 const char* pName;
97};
98
99template<class T> SfxPoolItem* createSfxPoolItem()
100{
101 return T::CreateDefault();
102}
104{
106 const std::type_info* pType;
107 sal_uInt16 nAttribs;
108 SfxTypeAttrib aAttrib[1]; // variable length
109
110 const std::type_info* Type() const{return pType;}
111 std::unique_ptr<SfxPoolItem> CreateItem() const
112 { return std::unique_ptr<SfxPoolItem>(createSfxPoolItemFunc()); }
113};
114
116{
118 const std::type_info* pType;
119 sal_uInt16 nAttribs;
120 const std::type_info* Type() const { return pType;}
121};
122#define SFX_DECL_TYPE(n) struct SfxType##n \
123 { \
124 std::function<SfxPoolItem* ()> createSfxPoolItemFunc; \
125 const std::type_info* pType; \
126 sal_uInt16 nAttribs; \
127 SfxTypeAttrib aAttrib[n]; \
128 }
129
130#define SFX_TYPE(Class) &a##Class##_Impl
131
140SFX_DECL_TYPE(10); // for SfxDocInfoItem
142
143SFX_DECL_TYPE(13); // for SwAddPrinterItem, Sd...
145SFX_DECL_TYPE(16); // for SwDocDisplayItem
146SFX_DECL_TYPE(17); // for SvxAddressItem
147SFX_DECL_TYPE(23); // for SvxSearchItem
148
149// all SfxTypes must be in this header
150#undef SFX_DECL_TYPE
151
152#define SFX_SLOT_ARG( aShellClass, id, GroupId, ExecMethodPtr, StateMethodPtr, Flags, ItemClass, nArg0, nArgs, Name, Prop ) \
153 { id, GroupId, Flags | Prop, \
154 USHRT_MAX, 0, \
155 ExecMethodPtr, \
156 StateMethodPtr, \
157 (const SfxType*) &a##ItemClass##_Impl, \
158 0, \
159 &a##aShellClass##Args_Impl[nArg0], nArgs, SfxDisableFlags::NONE, Name \
160 }
161
162#define SFX_NEW_SLOT_ARG( aShellClass, id, GroupId, pNext, ExecMethodPtr, StateMethodPtr, Flags, DisableFlags, ItemClass, nArg0, nArgs, Prop, UnoName ) \
163 { id, GroupId, Flags | Prop, \
164 USHRT_MAX, 0, \
165 ExecMethodPtr, \
166 StateMethodPtr, \
167 (const SfxType*) &a##ItemClass##_Impl, \
168 pNext, \
169 &a##aShellClass##Args_Impl[nArg0], nArgs, DisableFlags, UnoName \
170 }
171
173{
174 const SfxType* pType; // Type of the parameter (SfxPoolItem subclass)
175 const char* pName; // Name of the sParameters
176 sal_uInt16 nSlotId; // Slot-Id for identification of the Parameters
177
178 std::unique_ptr<SfxPoolItem> CreateItem() const
179 { return pType->CreateItem(); }
180};
181
182
184{
185public:
186 sal_uInt16 nSlotId; // Unique slot-ID in Shell
187 SfxGroupId nGroupId; // for configuration region
188 SfxSlotMode nFlags; // arithmetic ordered Flags
189
190 sal_uInt16 nMasterSlotId; // Enum-Slot for example Which-Id
191 sal_uInt16 nValue; // Value, in case of Enum-Slot
192
193 SfxExecFunc fnExec; // Function to be executed
194 SfxStateFunc fnState; // Function for Status
195
196 const SfxType* pType; // SfxPoolItem-Type (Status)
197
198 const SfxSlot* pNextSlot; // with the same Status-Method
199
200 const SfxFormalArgument* pFirstArgDef; // first formal Argument-Definition
201 sal_uInt16 nArgDefCount; // Number of formal Arguments
202 SfxDisableFlags nDisableFlags; // DisableFlags that need to be
203 // present, so that the Slot
204 // can be enabled
205 OUString pUnoName; // UnoName for the Slots
206
207public:
208
209 template <size_t N>
210 SfxSlot(sal_uInt16 sId, SfxGroupId gId, SfxSlotMode flags, sal_uInt16 masterSlotId,
211 sal_uInt16 value, SfxExecFunc exec, SfxStateFunc state, const SfxType* type,
212 const SfxSlot* nextSlot, const SfxFormalArgument* firstArgDef, sal_uInt16 argDefCount,
213 SfxDisableFlags disableFlags, const char (&literal)[N])
214 : nSlotId(sId)
215 , nGroupId(gId)
216 , nFlags(flags)
217 , nMasterSlotId(masterSlotId)
218 , nValue(value)
219 , fnExec(exec)
220 , fnState(state)
221 , pType(type)
222 , pNextSlot(nextSlot)
223 , pFirstArgDef(firstArgDef)
224 , nArgDefCount(argDefCount)
225 , nDisableFlags(disableFlags)
226 , pUnoName(literal)
227 {
228 }
229
230 SfxSlotKind GetKind() const;
231 sal_uInt16 GetSlotId() const;
232 SfxSlotMode GetMode() const;
233 bool IsMode( SfxSlotMode nMode ) const;
234 SfxGroupId GetGroupId() const;
235 sal_uInt16 GetWhich( const SfxItemPool &rPool ) const;
236 const SfxType* GetType() const { return pType; }
237 const OUString& GetUnoName() const { return pUnoName; }
238 SFX2_DLLPUBLIC OUString GetCommand() const;
239
240 sal_uInt16 GetFormalArgumentCount() const { return nArgDefCount; }
241 const SfxFormalArgument& GetFormalArgument( sal_uInt16 nNo ) const
242 { return pFirstArgDef[nNo]; }
243
244 SfxExecFunc GetExecFnc() const { return fnExec; }
245 SfxStateFunc GetStateFnc() const { return fnState; }
246
247 const SfxSlot* GetNextSlot() const { return pNextSlot; }
248};
249
250
251// returns the id of the function
252
253inline sal_uInt16 SfxSlot::GetSlotId() const
254{
255 return nSlotId;
256}
257
258// returns a bitfield with flags
259
261{
262 return nFlags;
263}
264
265
266// determines if the specified mode is assigned
267
268inline bool SfxSlot::IsMode( SfxSlotMode nMode ) const
269{
270 return bool(nFlags & nMode);
271}
272
273
274// returns the id of the associated group
275
277{
278 return nGroupId;
279
280}
281
282#endif
283
284/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: msg.hxx:184
sal_uInt16 GetSlotId() const
Definition: msg.hxx:253
OUString pUnoName
Definition: msg.hxx:205
const SfxSlot * pNextSlot
Definition: msg.hxx:198
SfxExecFunc fnExec
Definition: msg.hxx:193
const SfxType * GetType() const
Definition: msg.hxx:236
SfxGroupId GetGroupId() const
Definition: msg.hxx:276
const SfxSlot * GetNextSlot() const
Definition: msg.hxx:247
SFX2_DLLPUBLIC OUString GetCommand() const
Definition: msg.cxx:46
SfxSlotMode GetMode() const
Definition: msg.hxx:260
const SfxFormalArgument & GetFormalArgument(sal_uInt16 nNo) const
Definition: msg.hxx:241
const SfxType * pType
Definition: msg.hxx:196
const OUString & GetUnoName() const
Definition: msg.hxx:237
sal_uInt16 GetFormalArgumentCount() const
Definition: msg.hxx:240
SfxStateFunc GetStateFnc() const
Definition: msg.hxx:245
SfxDisableFlags nDisableFlags
Definition: msg.hxx:202
sal_uInt16 nSlotId
Definition: msg.hxx:186
SfxSlotMode nFlags
Definition: msg.hxx:188
SfxExecFunc GetExecFnc() const
Definition: msg.hxx:244
SfxSlot(sal_uInt16 sId, SfxGroupId gId, SfxSlotMode flags, sal_uInt16 masterSlotId, sal_uInt16 value, SfxExecFunc exec, SfxStateFunc state, const SfxType *type, const SfxSlot *nextSlot, const SfxFormalArgument *firstArgDef, sal_uInt16 argDefCount, SfxDisableFlags disableFlags, const char(&literal)[N])
Definition: msg.hxx:210
sal_uInt16 nValue
Definition: msg.hxx:191
const SfxFormalArgument * pFirstArgDef
Definition: msg.hxx:200
sal_uInt16 nArgDefCount
Definition: msg.hxx:201
SfxStateFunc fnState
Definition: msg.hxx:194
bool IsMode(SfxSlotMode nMode) const
Definition: msg.hxx:268
SfxGroupId nGroupId
Definition: msg.hxx:187
SfxSlotKind GetKind() const
Definition: msg.cxx:25
sal_uInt16 GetWhich(const SfxItemPool &rPool) const
Definition: msg.cxx:39
sal_uInt16 nMasterSlotId
Definition: msg.hxx:190
Any value
#define SFX2_DLLPUBLIC
Definition: dllapi.h:29
SfxGroupId
Definition: groupid.hxx:30
SfxPoolItem * createSfxPoolItem()
Definition: msg.hxx:99
SfxSlotKind
Definition: msg.hxx:87
SfxSlotMode
Definition: msg.hxx:35
#define SFX_DECL_TYPE(n)
Definition: msg.hxx:122
NONE
SfxDisableFlags
Definition: shell.hxx:102
void(* SfxExecFunc)(SfxShell *, SfxRequest &rReq)
Definition: shell.hxx:111
void(* SfxStateFunc)(SfxShell *, SfxItemSet &rSet)
Definition: shell.hxx:112
sal_uInt16 nSlotId
Definition: msg.hxx:176
const char * pName
Definition: msg.hxx:175
std::unique_ptr< SfxPoolItem > CreateItem() const
Definition: msg.hxx:178
const SfxType * pType
Definition: msg.hxx:174
const std::type_info * pType
Definition: msg.hxx:118
std::function< SfxPoolItem *()> createSfxPoolItemFunc
Definition: msg.hxx:117
sal_uInt16 nAttribs
Definition: msg.hxx:119
const std::type_info * Type() const
Definition: msg.hxx:120
const char * pName
Definition: msg.hxx:96
sal_uInt16 nAID
Definition: msg.hxx:95
Definition: msg.hxx:104
const std::type_info * pType
Definition: msg.hxx:106
std::function< SfxPoolItem *()> createSfxPoolItemFunc
Definition: msg.hxx:105
std::unique_ptr< SfxPoolItem > CreateItem() const
Definition: msg.hxx:111
const std::type_info * Type() const
Definition: msg.hxx:110
SfxTypeAttrib aAttrib[1]
Definition: msg.hxx:108
sal_uInt16 nAttribs
Definition: msg.hxx:107
ResultType type
OUString sId