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>
27 #include <o3tl/typed_flags_set.hxx>
28 #include <sfx2/groupid.hxx>
29 #include <functional>
30 
31 #include <climits>
32 
33 class SfxItemPool;
34 
35 enum class SfxSlotMode {
36     NONE            =    0x0000L, // default
37 
38     TOGGLE          =    0x0004L, // inverted for Execute old value
39     AUTOUPDATE      =    0x0008L, // invalidated the status automatically after execute
40     ASYNCHRON       =    0x0020L, // via Post-Message
41 
42     NORECORD        =    0x0100L, // no recording
43     RECORDPERITEM   =    0x0200L, // each item, one statement
44     RECORDPERSET    =    0x0400L, // The whole Set is a Statement, default
45     RECORDABSOLUTE  = 0x1000000L, // Recording with absolute Target
46 
47     METHOD          =    0x4000L,
48 
49     FASTCALL        =    0x8000L, // No test if disabled before Execute
50 
51     MENUCONFIG      =   0x20000L, // configurable Menu
52     TOOLBOXCONFIG   =   0x40000L, // configurable Toolboxen
53     ACCELCONFIG     =   0x80000L, // configurable keys
54 
55     CONTAINER       =  0x100000L, // Operated by the container at InPlace
56     READONLYDOC     =  0x200000L  // also available for read-only Documents
57 };
58 
59 namespace 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 
86 enum class SfxSlotKind
87 {
88     Standard,
89     Attribute
90 };
91 
92 
93 struct SfxTypeAttrib
94 {
95     sal_uInt16                  nAID;
96     const char* pName;
97 };
98 
createSfxPoolItem()99 template<class T> SfxPoolItem* createSfxPoolItem()
100 {
101     return T::CreateDefault();
102 }
103 struct SfxType
104 {
105     std::function<SfxPoolItem* ()> const createSfxPoolItemFunc;
106     const std::type_info*   pType;
107     sal_uInt16 const        nAttribs;
108     SfxTypeAttrib   aAttrib[1]; // variable length
109 
TypeSfxType110     const std::type_info* Type() const{return pType;}
CreateItemSfxType111     std::unique_ptr<SfxPoolItem> CreateItem() const
112                     { return std::unique_ptr<SfxPoolItem>(createSfxPoolItemFunc()); }
113 };
114 
115 struct SfxType0
116 {
117     std::function<SfxPoolItem* ()> const createSfxPoolItemFunc;
118     const std::type_info*    pType;
119     sal_uInt16 const         nAttribs;
TypeSfxType0120     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 
132 SFX_DECL_TYPE(1);
133 SFX_DECL_TYPE(2);
134 SFX_DECL_TYPE(3);
135 SFX_DECL_TYPE(4);
136 SFX_DECL_TYPE(5);
137 SFX_DECL_TYPE(6);
138 SFX_DECL_TYPE(7);
139 SFX_DECL_TYPE(8);
140 SFX_DECL_TYPE(10); // for SfxDocInfoItem
141 SFX_DECL_TYPE(11);
142 
143 SFX_DECL_TYPE(13); // for SwAddPrinterItem, Sd...
144 SFX_DECL_TYPE(14);
145 SFX_DECL_TYPE(16); // for SwDocDisplayItem
146 SFX_DECL_TYPE(17); // for SvxAddressItem
147 SFX_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 
172 struct SfxFormalArgument
173 {
174     const SfxType*   pType;    // Type of the parameter (SfxPoolItem subclass)
175     const char*      pName;    // Name of the sParameters
176     sal_uInt16 const nSlotId;  // Slot-Id for identification of the Parameters
177 
CreateItemSfxFormalArgument178     std::unique_ptr<SfxPoolItem> CreateItem() const
179                             { return pType->CreateItem(); }
180 };
181 
182 
183 class SfxSlot
184 {
185 public:
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     const char*     pUnoName;      // UnoName for the Slots
206 
207 public:
208 
209     SfxSlotKind         GetKind() const;
210     sal_uInt16          GetSlotId() const;
211     SfxSlotMode         GetMode() const;
212     bool                IsMode( SfxSlotMode nMode ) const;
213     SfxGroupId          GetGroupId() const;
214     sal_uInt16          GetWhich( const SfxItemPool &rPool ) const;
GetType() const215     const SfxType*  GetType() const { return pType; }
GetUnoName() const216     const char*     GetUnoName() const { return pUnoName; }
217     SFX2_DLLPUBLIC OString    GetCommand() const;
218     SFX2_DLLPUBLIC OUString    GetCommandString() const;
219 
GetFormalArgumentCount() const220     sal_uInt16          GetFormalArgumentCount() const { return nArgDefCount; }
GetFormalArgument(sal_uInt16 nNo) const221     const SfxFormalArgument& GetFormalArgument( sal_uInt16 nNo ) const
222                     { return pFirstArgDef[nNo]; }
223 
GetExecFnc() const224     SfxExecFunc     GetExecFnc() const { return fnExec; }
GetStateFnc() const225     SfxStateFunc    GetStateFnc() const { return fnState; }
226 
GetNextSlot() const227     const SfxSlot*  GetNextSlot() const { return pNextSlot; }
228 };
229 
230 
231 // returns the id of the function
232 
GetSlotId() const233 inline sal_uInt16 SfxSlot::GetSlotId() const
234 {
235     return nSlotId;
236 }
237 
238 // returns  a bitfield with flags
239 
GetMode() const240 inline SfxSlotMode SfxSlot::GetMode() const
241 {
242     return nFlags;
243 }
244 
245 
246 // determines if the specified mode is assigned
247 
IsMode(SfxSlotMode nMode) const248 inline bool SfxSlot::IsMode( SfxSlotMode nMode ) const
249 {
250     return bool(nFlags & nMode);
251 }
252 
253 
254 // returns the id of the associated group
255 
GetGroupId() const256 inline SfxGroupId SfxSlot::GetGroupId() const
257 {
258     return nGroupId;
259 
260 }
261 
262 #endif
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
265