bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / svtools / unoevent.hxx
blob448573c117bd0f6b62ca6cbf75f713acb54c9143
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_SVTOOLS_UNOEVENT_HXX
20 #define INCLUDED_SVTOOLS_UNOEVENT_HXX
22 #include <svtools/svtdllapi.h>
23 #include <com/sun/star/container/XNameReplace.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <vector>
27 #include <memory>
29 namespace com :: sun :: star :: uno { class XInterface; }
31 class SvxMacroTableDtor;
32 class SvxMacroItem;
33 class SvxMacro;
34 enum class SvMacroItemId : sal_uInt16;
36 /** SvEventDescription: Description of a single event.
37 mnEvent is the id used by SvxMacroItem
38 mpEventName is the api name for this event
40 the last event in an array is indicated by mnEvent && mpEventName == 0
42 struct SvEventDescription
44 SvMacroItemId const mnEvent;
45 const sal_Char* mpEventName;
48 /**
49 * SvBaseEventDescriptor: Abstract class that implements the basics
50 * of an XNameReplace that is delivered by the
51 * XEventsSupplier::getEvents() method.
53 * The functionality this class provides is:
54 * 1) Which elements are in the XNameReplace?
55 * 2) Mapping from Api names to item IDs.
56 * 3) conversion from SvxMacroItem to Any and vice versa.
58 * All details of how to actually get and set SvxMacroItem(s) have to
59 * be supplied by the base class.
61 class SVT_DLLPUBLIC SvBaseEventDescriptor : public cppu::WeakImplHelper
63 css::container::XNameReplace,
64 css::lang::XServiceInfo
67 protected:
68 /// last element is 0, 0
69 const SvEventDescription* mpSupportedMacroItems;
70 sal_Int16 mnMacroItems;
72 public:
74 SvBaseEventDescriptor(const SvEventDescription* pSupportedMacroItems);
76 virtual ~SvBaseEventDescriptor() override;
79 // XNameReplace
80 /// calls replaceByName(const sal_uInt16, const SvxMacro&)
81 virtual void SAL_CALL replaceByName(
82 const OUString& rName, /// API name of event
83 const css::uno::Any& rElement ) /// event (PropertyValues)
84 override;
86 // XNameAccess (via XNameReplace)
87 /// calls getByName(sal_uInt16)
88 virtual css::uno::Any SAL_CALL getByName(
89 const OUString& rName ) /// API name of event
90 override;
92 // XNameAxcess (via XNameReplace)
93 virtual css::uno::Sequence< OUString > SAL_CALL
94 getElementNames() override;
96 // XNameAccess (via XNameReplace)
97 virtual sal_Bool SAL_CALL hasByName(
98 const OUString& rName ) override;
100 // XElementAccess (via XNameReplace)
101 virtual css::uno::Type SAL_CALL getElementType() override;
103 // XElementAccess (via XNameReplace)
104 virtual sal_Bool SAL_CALL hasElements() override;
106 // XServiceInfo
107 /// must be implemented in subclass
108 virtual OUString SAL_CALL getImplementationName() override = 0;
110 // XServiceInfo
111 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
113 // XServiceInfo
114 virtual css::uno::Sequence< OUString > SAL_CALL
115 getSupportedServiceNames() override;
117 protected:
119 /// Must be implemented in subclass.
121 /// @throws css::lang::IllegalArgumentException
122 /// @throws css::container::NoSuchElementException
123 /// @throws css::lang::WrappedTargetException
124 /// @throws css::uno::RuntimeException
125 virtual void replaceByName(
126 const SvMacroItemId nEvent, /// item ID of event
127 const SvxMacro& rMacro) /// event (will be copied)
128 = 0;
130 /// Must be implemented in subclass.
132 /// @throws css::container::NoSuchElementException
133 /// @throws css::lang::WrappedTargetException
134 /// @throws css::uno::RuntimeException
135 virtual void getByName(
136 SvxMacro& rMacro,
137 const SvMacroItemId nEvent ) = 0;
139 /// convert an API event name to the event ID as used by SvxMacroItem
140 SvMacroItemId mapNameToEventID(const OUString& rName) const;
142 /// get the event ID for the name; return 0 if not supported
143 SvMacroItemId getMacroID(const OUString& rName) const;
148 * SvEventDescriptor: Implement the XNameReplace that is delivered by
149 * the XEventsSupplier::getEvents() method. The SvEventDescriptor has
150 * to be subclassed to implement the events for a specific
151 * objects. The subclass has to
152 * 1) supply the super class constructor with a list of known events (item IDs)
153 * 2) supply the super class constructor with a reference of its parent object
154 * (to prevent destruction)
155 * 3) implement getItem() and setItem(...) methods.
157 * If no object is available to which the SvEventDescriptor can attach itself,
158 * the class SvDetachedEventDescriptor should be used.
160 class SVT_DLLPUBLIC SvEventDescriptor : public SvBaseEventDescriptor
162 /// keep reference to parent to prevent it from being destroyed
163 css::uno::Reference< css::uno::XInterface > xParentRef;
165 public:
167 SvEventDescriptor(css::uno::XInterface& rParent,
168 const SvEventDescription* pSupportedMacroItems);
170 virtual ~SvEventDescriptor() override;
173 protected:
176 using SvBaseEventDescriptor::replaceByName;
177 virtual void replaceByName(
178 const SvMacroItemId nEvent, /// item ID of event
179 const SvxMacro& rMacro) /// event (will be copied)
180 override;
182 using SvBaseEventDescriptor::getByName;
183 virtual void getByName(
184 SvxMacro& rMacros, /// macro to be filled with values
185 const SvMacroItemId nEvent ) /// item ID of event
186 override;
189 /// Get the SvxMacroItem from the parent.
190 /// must be implemented by subclass
191 virtual const SvxMacroItem& getMacroItem() = 0;
193 /// Set the SvxMacroItem at the parent.
194 /// must be implemented by subclass
195 virtual void setMacroItem(const SvxMacroItem& rItem) = 0;
197 /// Get the SvxMacroItem Which Id needed for the current application
198 /// must be implemented by subclass
199 virtual sal_uInt16 getMacroItemWhich() const = 0;
204 * SvDetachedEventDescriptor:
206 class SVT_DLLPUBLIC SvDetachedEventDescriptor : public SvBaseEventDescriptor
208 // the macros; aMacros[i] is the value for aSupportedMacroItemIDs[i]
209 std::vector<std::unique_ptr<SvxMacro>> aMacros;
211 public:
213 SvDetachedEventDescriptor(const SvEventDescription* pSupportedMacroItems);
214 SvDetachedEventDescriptor& operator=( SvDetachedEventDescriptor const & ) = delete; // MSVC2015 workaround
215 SvDetachedEventDescriptor( SvDetachedEventDescriptor const & ) = delete; // MSVC2015 workaround
217 virtual ~SvDetachedEventDescriptor() override;
219 //XServiceInfo
220 virtual OUString SAL_CALL getImplementationName() override;
222 protected:
224 sal_Int16 getIndex(const SvMacroItemId nID) const;
226 using SvBaseEventDescriptor::replaceByName;
227 virtual void replaceByName(
228 const SvMacroItemId nEvent, /// item ID of event
229 const SvxMacro& rMacro) /// event (will be copied)
230 override;
232 using SvBaseEventDescriptor::getByName;
233 virtual void getByName(
234 SvxMacro& rMacro, /// macro to be filled
235 const SvMacroItemId nEvent ) /// item ID of event
236 override;
238 /// do we have an event?
239 /// return true: we have a macro for the event
240 /// return false: no macro; getByName() will return an empty macro
241 /// @throws css::lang::IllegalArgumentException if the event is not supported
242 bool hasById(
243 const SvMacroItemId nEvent ) const; /// item ID of event
247 class SVT_DLLPUBLIC SvMacroTableEventDescriptor : public SvDetachedEventDescriptor
249 public:
251 SvMacroTableEventDescriptor(const SvEventDescription* pSupportedMacroItems);
252 SvMacroTableEventDescriptor(const SvxMacroTableDtor& aFmt,
253 const SvEventDescription* pSupportedMacroItems);
255 virtual ~SvMacroTableEventDescriptor() override;
257 void copyMacrosIntoTable(SvxMacroTableDtor& aFmt);
260 #endif
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */