workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / svtools / unoevent.hxx
blob825280e16b8ab6e0129a73b646f0ffee77106d5d
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 #pragma once
21 #include <svtools/svtdllapi.h>
22 #include <com/sun/star/container/XNameReplace.hpp>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <cppuhelper/implbase.hxx>
25 #include <vector>
26 #include <memory>
28 namespace com :: sun :: star :: uno { class XInterface; }
30 class SvxMacroTableDtor;
31 class SvxMacroItem;
32 class SvxMacro;
33 enum class SvMacroItemId : sal_uInt16;
35 /** SvEventDescription: Description of a single event.
36 mnEvent is the id used by SvxMacroItem
37 mpEventName is the api name for this event
39 the last event in an array is indicated by mnEvent && mpEventName == 0
41 struct SvEventDescription
43 SvMacroItemId mnEvent;
44 const char* mpEventName;
47 /**
48 * SvBaseEventDescriptor: Abstract class that implements the basics
49 * of an XNameReplace that is delivered by the
50 * XEventsSupplier::getEvents() method.
52 * The functionality this class provides is:
53 * 1) Which elements are in the XNameReplace?
54 * 2) Mapping from Api names to item IDs.
55 * 3) conversion from SvxMacroItem to Any and vice versa.
57 * All details of how to actually get and set SvxMacroItem(s) have to
58 * be supplied by the base class.
60 class SVT_DLLPUBLIC SvBaseEventDescriptor : public cppu::WeakImplHelper
62 css::container::XNameReplace,
63 css::lang::XServiceInfo
66 protected:
67 /// last element is 0, 0
68 const SvEventDescription* mpSupportedMacroItems;
69 sal_Int16 mnMacroItems;
71 public:
73 SvBaseEventDescriptor(const SvEventDescription* pSupportedMacroItems);
75 virtual ~SvBaseEventDescriptor() override;
78 // XNameReplace
79 /// calls replaceByName(const sal_uInt16, const SvxMacro&)
80 virtual void SAL_CALL replaceByName(
81 const OUString& rName, /// API name of event
82 const css::uno::Any& rElement ) /// event (PropertyValues)
83 override;
85 // XNameAccess (via XNameReplace)
86 /// calls getByName(sal_uInt16)
87 virtual css::uno::Any SAL_CALL getByName(
88 const OUString& rName ) /// API name of event
89 override;
91 // XNameAxcess (via XNameReplace)
92 virtual css::uno::Sequence< OUString > SAL_CALL
93 getElementNames() override;
95 // XNameAccess (via XNameReplace)
96 virtual sal_Bool SAL_CALL hasByName(
97 const OUString& rName ) override;
99 // XElementAccess (via XNameReplace)
100 virtual css::uno::Type SAL_CALL getElementType() override;
102 // XElementAccess (via XNameReplace)
103 virtual sal_Bool SAL_CALL hasElements() override;
105 // XServiceInfo
106 /// must be implemented in subclass
107 virtual OUString SAL_CALL getImplementationName() override = 0;
109 // XServiceInfo
110 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
112 // XServiceInfo
113 virtual css::uno::Sequence< OUString > SAL_CALL
114 getSupportedServiceNames() override;
116 protected:
118 /// Must be implemented in subclass.
120 /// @throws css::lang::IllegalArgumentException
121 /// @throws css::container::NoSuchElementException
122 /// @throws css::lang::WrappedTargetException
123 /// @throws css::uno::RuntimeException
124 virtual void replaceByName(
125 const SvMacroItemId nEvent, /// item ID of event
126 const SvxMacro& rMacro) /// event (will be copied)
127 = 0;
129 /// Must be implemented in subclass.
131 /// @throws css::container::NoSuchElementException
132 /// @throws css::lang::WrappedTargetException
133 /// @throws css::uno::RuntimeException
134 virtual void getByName(
135 SvxMacro& rMacro,
136 const SvMacroItemId nEvent ) = 0;
138 /// convert an API event name to the event ID as used by SvxMacroItem
139 SvMacroItemId mapNameToEventID(std::u16string_view rName) const;
141 /// get the event ID for the name; return 0 if not supported
142 SvMacroItemId getMacroID(std::u16string_view rName) const;
147 * SvEventDescriptor: Implement the XNameReplace that is delivered by
148 * the XEventsSupplier::getEvents() method. The SvEventDescriptor has
149 * to be subclassed to implement the events for a specific
150 * objects. The subclass has to
151 * 1) supply the super class constructor with a list of known events (item IDs)
152 * 2) supply the super class constructor with a reference of its parent object
153 * (to prevent destruction)
154 * 3) implement getItem() and setItem(...) methods.
156 * If no object is available to which the SvEventDescriptor can attach itself,
157 * the class SvDetachedEventDescriptor should be used.
159 class SVT_DLLPUBLIC SvEventDescriptor : public SvBaseEventDescriptor
161 /// keep reference to parent to prevent it from being destroyed
162 css::uno::Reference< css::uno::XInterface > xParentRef;
164 public:
166 SvEventDescriptor(css::uno::XInterface& rParent,
167 const SvEventDescription* pSupportedMacroItems);
169 virtual ~SvEventDescriptor() override;
172 protected:
175 using SvBaseEventDescriptor::replaceByName;
176 virtual void replaceByName(
177 const SvMacroItemId nEvent, /// item ID of event
178 const SvxMacro& rMacro) /// event (will be copied)
179 override;
181 using SvBaseEventDescriptor::getByName;
182 virtual void getByName(
183 SvxMacro& rMacros, /// macro to be filled with values
184 const SvMacroItemId nEvent ) /// item ID of event
185 override;
188 /// Get the SvxMacroItem from the parent.
189 /// must be implemented by subclass
190 virtual const SvxMacroItem& getMacroItem() = 0;
192 /// Set the SvxMacroItem at the parent.
193 /// must be implemented by subclass
194 virtual void setMacroItem(const SvxMacroItem& rItem) = 0;
196 /// Get the SvxMacroItem Which Id needed for the current application
197 /// must be implemented by subclass
198 virtual sal_uInt16 getMacroItemWhich() const = 0;
203 * SvDetachedEventDescriptor:
205 class SVT_DLLPUBLIC SvDetachedEventDescriptor : public SvBaseEventDescriptor
207 // the macros; aMacros[i] is the value for aSupportedMacroItemIDs[i]
208 std::vector<std::unique_ptr<SvxMacro>> aMacros;
210 public:
212 SvDetachedEventDescriptor(const SvEventDescription* pSupportedMacroItems);
213 SvDetachedEventDescriptor& operator=( SvDetachedEventDescriptor const & ) = delete; // MSVC2015 workaround
214 SvDetachedEventDescriptor( SvDetachedEventDescriptor const & ) = delete; // MSVC2015 workaround
216 virtual ~SvDetachedEventDescriptor() override;
218 //XServiceInfo
219 virtual OUString SAL_CALL getImplementationName() override;
221 protected:
223 sal_Int16 getIndex(const SvMacroItemId nID) const;
225 using SvBaseEventDescriptor::replaceByName;
226 virtual void replaceByName(
227 const SvMacroItemId nEvent, /// item ID of event
228 const SvxMacro& rMacro) /// event (will be copied)
229 override;
231 using SvBaseEventDescriptor::getByName;
232 virtual void getByName(
233 SvxMacro& rMacro, /// macro to be filled
234 const SvMacroItemId nEvent ) /// item ID of event
235 override;
237 /// do we have an event?
238 /// return true: we have a macro for the event
239 /// return false: no macro; getByName() will return an empty macro
240 /// @throws css::lang::IllegalArgumentException if the event is not supported
241 bool hasById(
242 const SvMacroItemId nEvent ) const; /// item ID of event
246 class SVT_DLLPUBLIC SvMacroTableEventDescriptor final : public SvDetachedEventDescriptor
248 public:
250 SvMacroTableEventDescriptor(const SvEventDescription* pSupportedMacroItems);
251 SvMacroTableEventDescriptor(const SvxMacroTableDtor& aFmt,
252 const SvEventDescription* pSupportedMacroItems);
254 virtual ~SvMacroTableEventDescriptor() override;
256 void copyMacrosIntoTable(SvxMacroTableDtor& aFmt);
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */