Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / sfx2 / msg.hxx
blobc8d343b04bcf5ac05e7808f39590425b6d5a647b
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_MSG_HXX
20 #define INCLUDED_SFX2_MSG_HXX
22 #include <sfx2/shell.hxx>
23 #include <rtl/ustring.hxx>
24 #include <svl/poolitem.hxx>
25 #include <sfx2/dllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
27 #include <sfx2/groupid.hxx>
28 #include <functional>
30 #include <climits>
32 class SfxItemPool;
34 enum class SfxSlotMode {
35 NONE = 0x0000, // default
37 TOGGLE = 0x0004, // inverted for Execute old value
38 AUTOUPDATE = 0x0008, // invalidated the status automatically after execute
39 ASYNCHRON = 0x0020, // via Post-Message
41 NORECORD = 0x0100, // no recording
42 RECORDPERITEM = 0x0200, // each item, one statement
43 RECORDPERSET = 0x0400, // The whole Set is a Statement, default
44 RECORDABSOLUTE = 0x1000000, // Recording with absolute Target
46 METHOD = 0x4000,
48 FASTCALL = 0x8000, // No test if disabled before Execute
50 MENUCONFIG = 0x20000, // configurable Menu
51 TOOLBOXCONFIG = 0x40000, // configurable Toolboxen
52 ACCELCONFIG = 0x80000, // configurable keys
54 CONTAINER = 0x100000, // Operated by the container at InPlace
55 READONLYDOC = 0x200000 // also available for read-only Documents
58 namespace o3tl
60 template<> struct typed_flags<SfxSlotMode> : is_typed_flags<SfxSlotMode, 0x13ec72cL> {};
63 #define SFX_EXEC_STUB( aShellClass, aExecMethod) \
64 void SfxStub##aShellClass##aExecMethod( \
65 SfxShell *pShell, SfxRequest& rReq) \
66 { \
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) \
73 { \
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
87 Standard,
88 Attribute
92 struct SfxTypeAttrib
94 sal_uInt16 nAID;
95 const char* pName;
98 template<class T> SfxPoolItem* createSfxPoolItem()
100 return T::CreateDefault();
102 struct SfxType
104 std::function<SfxPoolItem* ()> createSfxPoolItemFunc;
105 const std::type_info* pType;
106 sal_uInt16 nAttribs;
107 SfxTypeAttrib aAttrib[1]; // variable length
109 const std::type_info* Type() const{return pType;}
110 std::unique_ptr<SfxPoolItem> CreateItem() const
111 { return std::unique_ptr<SfxPoolItem>(createSfxPoolItemFunc()); }
114 struct SfxType0
116 std::function<SfxPoolItem* ()> createSfxPoolItemFunc;
117 const std::type_info* pType;
118 sal_uInt16 nAttribs;
119 const std::type_info* Type() const { return pType;}
121 #define SFX_DECL_TYPE(n) struct SfxType##n \
123 std::function<SfxPoolItem* ()> createSfxPoolItemFunc; \
124 const std::type_info* pType; \
125 sal_uInt16 nAttribs; \
126 SfxTypeAttrib aAttrib[n]; \
129 #define SFX_TYPE(Class) &a##Class##_Impl
131 SFX_DECL_TYPE(1);
132 SFX_DECL_TYPE(2);
133 SFX_DECL_TYPE(3);
134 SFX_DECL_TYPE(4);
135 SFX_DECL_TYPE(5);
136 SFX_DECL_TYPE(6);
137 SFX_DECL_TYPE(7);
138 SFX_DECL_TYPE(8);
139 SFX_DECL_TYPE(10); // for SfxDocInfoItem
140 SFX_DECL_TYPE(11);
142 SFX_DECL_TYPE(13); // for SwAddPrinterItem, Sd...
143 SFX_DECL_TYPE(14);
144 SFX_DECL_TYPE(16); // for SwDocDisplayItem
145 SFX_DECL_TYPE(17); // for SvxAddressItem
146 SFX_DECL_TYPE(23); // for SvxSearchItem
148 // all SfxTypes must be in this header
149 #undef SFX_DECL_TYPE
151 #define SFX_SLOT_ARG( aShellClass, id, GroupId, ExecMethodPtr, StateMethodPtr, Flags, ItemClass, nArg0, nArgs, Name, Prop ) \
152 { id, GroupId, Flags | Prop, \
153 USHRT_MAX, 0, \
154 ExecMethodPtr, \
155 StateMethodPtr, \
156 (const SfxType*) &a##ItemClass##_Impl, \
157 0, \
158 &a##aShellClass##Args_Impl[nArg0], nArgs, SfxDisableFlags::NONE, Name \
161 #define SFX_NEW_SLOT_ARG( aShellClass, id, GroupId, pNext, ExecMethodPtr, StateMethodPtr, Flags, DisableFlags, ItemClass, nArg0, nArgs, Prop, UnoName ) \
162 { id, GroupId, Flags | Prop, \
163 USHRT_MAX, 0, \
164 ExecMethodPtr, \
165 StateMethodPtr, \
166 (const SfxType*) &a##ItemClass##_Impl, \
167 pNext, \
168 &a##aShellClass##Args_Impl[nArg0], nArgs, DisableFlags, UnoName \
171 struct SfxFormalArgument
173 const SfxType* pType; // Type of the parameter (SfxPoolItem subclass)
174 const char* pName; // Name of the sParameters
175 sal_uInt16 nSlotId; // Slot-Id for identification of the Parameters
177 std::unique_ptr<SfxPoolItem> CreateItem() const
178 { return pType->CreateItem(); }
182 class SfxSlot
184 public:
185 sal_uInt16 nSlotId; // Unique slot-ID in Shell
186 SfxGroupId nGroupId; // for configuration region
187 SfxSlotMode nFlags; // arithmetic ordered Flags
189 sal_uInt16 nMasterSlotId; // Enum-Slot for example Which-Id
190 sal_uInt16 nValue; // Value, in case of Enum-Slot
192 SfxExecFunc fnExec; // Function to be executed
193 SfxStateFunc fnState; // Function for Status
195 const SfxType* pType; // SfxPoolItem-Type (Status)
197 const SfxSlot* pNextSlot; // with the same Status-Method
199 const SfxFormalArgument* pFirstArgDef; // first formal Argument-Definition
200 sal_uInt16 nArgDefCount; // Number of formal Arguments
201 SfxDisableFlags nDisableFlags; // DisableFlags that need to be
202 // present, so that the Slot
203 // can be enabled
204 OUString pUnoName; // UnoName for the Slots
206 public:
208 template <size_t N>
209 SfxSlot(sal_uInt16 sId, SfxGroupId gId, SfxSlotMode flags, sal_uInt16 masterSlotId,
210 sal_uInt16 value, SfxExecFunc exec, SfxStateFunc state, const SfxType* type,
211 const SfxSlot* nextSlot, const SfxFormalArgument* firstArgDef, sal_uInt16 argDefCount,
212 SfxDisableFlags disableFlags, const char (&literal)[N])
213 : nSlotId(sId)
214 , nGroupId(gId)
215 , nFlags(flags)
216 , nMasterSlotId(masterSlotId)
217 , nValue(value)
218 , fnExec(exec)
219 , fnState(state)
220 , pType(type)
221 , pNextSlot(nextSlot)
222 , pFirstArgDef(firstArgDef)
223 , nArgDefCount(argDefCount)
224 , nDisableFlags(disableFlags)
225 , pUnoName(literal)
229 SfxSlotKind GetKind() const;
230 sal_uInt16 GetSlotId() const;
231 SfxSlotMode GetMode() const;
232 bool IsMode( SfxSlotMode nMode ) const;
233 SfxGroupId GetGroupId() const;
234 sal_uInt16 GetWhich( const SfxItemPool &rPool ) const;
235 const SfxType* GetType() const { return pType; }
236 const OUString& GetUnoName() const { return pUnoName; }
237 SFX2_DLLPUBLIC OUString GetCommand() const;
239 sal_uInt16 GetFormalArgumentCount() const { return nArgDefCount; }
240 const SfxFormalArgument& GetFormalArgument( sal_uInt16 nNo ) const
241 { return pFirstArgDef[nNo]; }
243 SfxExecFunc GetExecFnc() const { return fnExec; }
244 SfxStateFunc GetStateFnc() const { return fnState; }
246 const SfxSlot* GetNextSlot() const { return pNextSlot; }
250 // returns the id of the function
252 inline sal_uInt16 SfxSlot::GetSlotId() const
254 return nSlotId;
257 // returns a bitfield with flags
259 inline SfxSlotMode SfxSlot::GetMode() const
261 return nFlags;
265 // determines if the specified mode is assigned
267 inline bool SfxSlot::IsMode( SfxSlotMode nMode ) const
269 return bool(nFlags & nMode);
273 // returns the id of the associated group
275 inline SfxGroupId SfxSlot::GetGroupId() const
277 return nGroupId;
281 #endif
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */