1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/uno/XInterface.hpp>
26 #include <cppuhelper/implbase.hxx>
28 class SvxMacroTableDtor
;
32 /** SvEventDescription: Description of a single event.
33 mnEvent is the id used by SvxMacroItem
34 mpEventName is the api name for this event
36 the last event in an array is indicated by mnEvent && mpEventName == 0
38 struct SvEventDescription
41 const sal_Char
* mpEventName
;
45 * SvBaseEventDescriptor: Abstract class that implements the basics
46 * of an XNameReplace that is delivered by the
47 * XEventsSupplier::getEvents() method.
49 * The functionality this class provides is:
50 * 1) Which elements are in the XNameReplace?
51 * 2) Mapping from Api names to item IDs.
52 * 3) conversion from SvxMacroItem to Any and vice versa.
54 * All details of how to actually get and set SvxMacroItem(s) have to
55 * be supplied by the base class.
57 class SVT_DLLPUBLIC SvBaseEventDescriptor
: public cppu::WeakImplHelper
59 css::container::XNameReplace
,
60 css::lang::XServiceInfo
64 /// last element is 0, 0
65 const SvEventDescription
* mpSupportedMacroItems
;
66 sal_Int16 mnMacroItems
;
70 SvBaseEventDescriptor(const SvEventDescription
* pSupportedMacroItems
);
72 virtual ~SvBaseEventDescriptor() override
;
76 /// calls replaceByName(const sal_uInt16, const SvxMacro&)
77 virtual void SAL_CALL
replaceByName(
78 const OUString
& rName
, /// API name of event
79 const css::uno::Any
& rElement
) /// event (PropertyValues)
82 // XNameAccess (via XNameReplace)
83 /// calls getByName(sal_uInt16)
84 virtual css::uno::Any SAL_CALL
getByName(
85 const OUString
& rName
) /// API name of event
88 // XNameAxcess (via XNameReplace)
89 virtual css::uno::Sequence
< OUString
> SAL_CALL
90 getElementNames() override
;
92 // XNameAccess (via XNameReplace)
93 virtual sal_Bool SAL_CALL
hasByName(
94 const OUString
& rName
) override
;
96 // XElementAccess (via XNameReplace)
97 virtual css::uno::Type SAL_CALL
getElementType() override
;
99 // XElementAccess (via XNameReplace)
100 virtual sal_Bool SAL_CALL
hasElements() override
;
103 /// must be implemented in subclass
104 virtual OUString SAL_CALL
getImplementationName() override
= 0;
107 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
110 virtual css::uno::Sequence
< OUString
> SAL_CALL
111 getSupportedServiceNames() override
;
115 /// Must be implemented in subclass.
117 /// @throws css::lang::IllegalArgumentException
118 /// @throws css::container::NoSuchElementException
119 /// @throws css::lang::WrappedTargetException
120 /// @throws css::uno::RuntimeException
121 virtual void replaceByName(
122 const sal_uInt16 nEvent
, /// item ID of event
123 const SvxMacro
& rMacro
) /// event (will be copied)
126 /// Must be implemented in subclass.
128 /// @throws css::container::NoSuchElementException
129 /// @throws css::lang::WrappedTargetException
130 /// @throws css::uno::RuntimeException
131 virtual void getByName(
133 const sal_uInt16 nEvent
) = 0;
135 /// convert an API event name to the event ID as used by SvxMacroItem
136 sal_uInt16
mapNameToEventID(const OUString
& rName
) const;
138 /// get the event ID for the name; return 0 if not supported
139 sal_uInt16
getMacroID(const OUString
& rName
) const;
144 * SvEventDescriptor: Implement the XNameReplace that is delivered by
145 * the XEventsSupplier::getEvents() method. The SvEventDescriptor has
146 * to be subclassed to implement the events for a specific
147 * objects. The subclass has to
148 * 1) supply the super class constructor with a list of known events (item IDs)
149 * 2) supply the super class constructor with a reference of its parent object
150 * (to prevent destruction)
151 * 3) implement getItem() and setItem(...) methods.
153 * If no object is available to which the SvEventDescriptor can attach itself,
154 * the class SvDetachedEventDescriptor should be used.
156 class SVT_DLLPUBLIC SvEventDescriptor
: public SvBaseEventDescriptor
158 /// keep reference to parent to prevent it from being destroyed
159 css::uno::Reference
< css::uno::XInterface
> xParentRef
;
163 SvEventDescriptor(css::uno::XInterface
& rParent
,
164 const SvEventDescription
* pSupportedMacroItems
);
166 virtual ~SvEventDescriptor() override
;
172 using SvBaseEventDescriptor::replaceByName
;
173 virtual void replaceByName(
174 const sal_uInt16 nEvent
, /// item ID of event
175 const SvxMacro
& rMacro
) /// event (will be copied)
178 using SvBaseEventDescriptor::getByName
;
179 virtual void getByName(
180 SvxMacro
& rMacros
, /// macro to be filled with values
181 const sal_uInt16 nEvent
) /// item ID of event
185 /// Get the SvxMacroItem from the parent.
186 /// must be implemented by subclass
187 virtual const SvxMacroItem
& getMacroItem() = 0;
189 /// Set the SvxMacroItem at the parent.
190 /// must be implemented by subclass
191 virtual void setMacroItem(const SvxMacroItem
& rItem
) = 0;
193 /// Get the SvxMacroItem Which Id needed for the current application
194 /// must be implemented by subclass
195 virtual sal_uInt16
getMacroItemWhich() const = 0;
200 * SvDetachedEventDescriptor:
202 class SVT_DLLPUBLIC SvDetachedEventDescriptor
: public SvBaseEventDescriptor
204 // the macros; aMacros[i] is the value for aSupportedMacroItemIDs[i]
207 const OUString sImplName
;
211 SvDetachedEventDescriptor(const SvEventDescription
* pSupportedMacroItems
);
213 virtual ~SvDetachedEventDescriptor() override
;
216 virtual OUString SAL_CALL
getImplementationName() override
;
220 sal_Int16
getIndex(const sal_uInt16 nID
) const;
222 using SvBaseEventDescriptor::replaceByName
;
223 virtual void replaceByName(
224 const sal_uInt16 nEvent
, /// item ID of event
225 const SvxMacro
& rMacro
) /// event (will be copied)
228 using SvBaseEventDescriptor::getByName
;
229 virtual void getByName(
230 SvxMacro
& rMacro
, /// macro to be filled
231 const sal_uInt16 nEvent
) /// item ID of event
234 /// do we have an event?
235 /// return true: we have a macro for the event
236 /// return false: no macro; getByName() will return an empty macro
237 /// @throws css::lang::IllegalArgumentException if the event is not supported
239 const sal_uInt16 nEvent
) const /// item ID of event
244 class SVT_DLLPUBLIC SvMacroTableEventDescriptor
: public SvDetachedEventDescriptor
248 SvMacroTableEventDescriptor(const SvEventDescription
* pSupportedMacroItems
);
249 SvMacroTableEventDescriptor(const SvxMacroTableDtor
& aFmt
,
250 const SvEventDescription
* pSupportedMacroItems
);
252 virtual ~SvMacroTableEventDescriptor() override
;
254 void copyMacrosIntoTable(SvxMacroTableDtor
& aFmt
);
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */