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/implbase2.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::WeakImplHelper2
59 ::com::sun::star::container::XNameReplace
,
60 ::com::sun::star::lang::XServiceInfo
63 const OUString sEventType
;
64 const OUString sMacroName
;
65 const OUString sLibrary
;
66 const OUString sStarBasic
;
67 const OUString sJavaScript
;
68 const OUString sScript
;
72 /// name of own service
73 const OUString sServiceName
;
76 const OUString sEmpty
;
78 /// last element is 0, 0
79 const SvEventDescription
* mpSupportedMacroItems
;
80 sal_Int16 mnMacroItems
;
84 SvBaseEventDescriptor(const SvEventDescription
* pSupportedMacroItems
);
86 virtual ~SvBaseEventDescriptor();
90 /// calls replaceByName(const sal_uInt16, const SvxMacro&)
91 virtual void SAL_CALL
replaceByName(
92 const OUString
& rName
, /// API name of event
93 const ::com::sun::star::uno::Any
& rElement
) /// event (PropertyValues)
95 ::com::sun::star::lang::IllegalArgumentException
,
96 ::com::sun::star::container::NoSuchElementException
,
97 ::com::sun::star::lang::WrappedTargetException
,
98 ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
100 // XNameAccess (via XNameReplace)
101 /// calls getByName(sal_uInt16)
102 virtual ::com::sun::star::uno::Any SAL_CALL
getByName(
103 const OUString
& rName
) /// API name of event
105 ::com::sun::star::container::NoSuchElementException
,
106 ::com::sun::star::lang::WrappedTargetException
,
107 ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
109 // XNameAxcess (via XNameReplace)
110 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
112 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
114 // XNameAccess (via XNameReplace)
115 virtual sal_Bool SAL_CALL
hasByName(
116 const OUString
& rName
)
117 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 // XElementAccess (via XNameReplace)
120 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType()
121 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 // XElementAccess (via XNameReplace)
124 virtual sal_Bool SAL_CALL
hasElements()
125 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
128 /// must be implemented in subclass
129 virtual OUString SAL_CALL
getImplementationName()
130 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
= 0;
133 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
)
134 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
137 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
138 getSupportedServiceNames()
139 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
143 /// Must be implemented in subclass.
144 virtual void replaceByName(
145 const sal_uInt16 nEvent
, /// item ID of event
146 const SvxMacro
& rMacro
) /// event (will be copied)
148 ::com::sun::star::lang::IllegalArgumentException
,
149 ::com::sun::star::container::NoSuchElementException
,
150 ::com::sun::star::lang::WrappedTargetException
,
151 ::com::sun::star::uno::RuntimeException
) = 0;
153 /// Must be implemented in subclass.
154 virtual void getByName(
156 const sal_uInt16 nEvent
)
158 ::com::sun::star::container::NoSuchElementException
,
159 ::com::sun::star::lang::WrappedTargetException
,
160 ::com::sun::star::uno::RuntimeException
) = 0;
162 /// convert an API event name to the event ID as used by SvxMacroItem
163 sal_uInt16
mapNameToEventID(const OUString
& rName
) const;
165 /// get the event ID for the name; return 0 if not supported
166 sal_uInt16
getMacroID(const OUString
& rName
) const;
168 /// create PropertyValues and Any from macro
169 void getAnyFromMacro(
170 ::com::sun::star::uno::Any
& aAny
, // Any to be filled by Macro values
171 const SvxMacro
& rMacro
);
173 /// create macro from PropertyValues (in an Any)
174 void getMacroFromAny(
175 SvxMacro
& aMacro
, // reference to be filled by Any
176 const ::com::sun::star::uno::Any
& rAny
)
178 ::com::sun::star::lang::IllegalArgumentException
);
186 * SvEventDescriptor: Implement the XNameReplace that is delivered by
187 * the XEventsSupplier::getEvents() method. The SvEventDescriptor has
188 * to be subclassed to implement the events for a specific
189 * objects. The subclass has to
190 * 1) supply the super class constructor with a list of known events (item IDs)
191 * 2) supply the super class constructor with a reference of its parent object
192 * (to prevent destruction)
193 * 3) implement getItem() and setItem(...) methods.
195 * If no object is available to which the SvEventDescriptor can attach itself,
196 * the class SvDetachedEventDescriptor should be used.
198 class SVT_DLLPUBLIC SvEventDescriptor
: public SvBaseEventDescriptor
200 /// keep reference to parent to prevent it from being destroyed
201 ::com::sun::star::uno::Reference
<
202 ::com::sun::star::uno::XInterface
> xParentRef
;
206 SvEventDescriptor(::com::sun::star::uno::XInterface
& rParent
,
207 const SvEventDescription
* pSupportedMacroItems
);
209 virtual ~SvEventDescriptor();
215 using SvBaseEventDescriptor::replaceByName
;
216 virtual void replaceByName(
217 const sal_uInt16 nEvent
, /// item ID of event
218 const SvxMacro
& rMacro
) /// event (will be copied)
220 ::com::sun::star::lang::IllegalArgumentException
,
221 ::com::sun::star::container::NoSuchElementException
,
222 ::com::sun::star::lang::WrappedTargetException
,
223 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
225 using SvBaseEventDescriptor::getByName
;
226 virtual void getByName(
227 SvxMacro
& rMacros
, /// macro to be filled with values
228 const sal_uInt16 nEvent
) /// item ID of event
230 ::com::sun::star::container::NoSuchElementException
,
231 ::com::sun::star::lang::WrappedTargetException
,
232 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
235 /// Get the SvxMacroItem from the parent.
236 /// must be implemented by subclass
237 virtual const SvxMacroItem
& getMacroItem() = 0;
239 /// Set the SvxMacroItem at the parent.
240 /// must be implemented by subclass
241 virtual void setMacroItem(const SvxMacroItem
& rItem
) = 0;
243 /// Get the SvxMacroItem Which Id needed for the current application
244 /// must be implemented by subclass
245 virtual sal_uInt16
getMacroItemWhich() const = 0;
250 * SvDetachedEventDescriptor:
252 class SVT_DLLPUBLIC SvDetachedEventDescriptor
: public SvBaseEventDescriptor
254 // the macros; aMacros[i] is the value for aSupportedMacroItemIDs[i]
257 const OUString sImplName
;
261 SvDetachedEventDescriptor(const SvEventDescription
* pSupportedMacroItems
);
263 virtual ~SvDetachedEventDescriptor();
266 virtual OUString SAL_CALL
getImplementationName()
267 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
271 sal_Int16
getIndex(const sal_uInt16 nID
) const;
273 using SvBaseEventDescriptor::replaceByName
;
274 virtual void replaceByName(
275 const sal_uInt16 nEvent
, /// item ID of event
276 const SvxMacro
& rMacro
) /// event (will be copied)
278 ::com::sun::star::lang::IllegalArgumentException
,
279 ::com::sun::star::container::NoSuchElementException
,
280 ::com::sun::star::lang::WrappedTargetException
,
281 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
283 using SvBaseEventDescriptor::getByName
;
284 virtual void getByName(
285 SvxMacro
& rMacro
, /// macro to be filled
286 const sal_uInt16 nEvent
) /// item ID of event
288 ::com::sun::star::container::NoSuchElementException
,
289 ::com::sun::star::lang::WrappedTargetException
,
290 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
292 /// do we have an event?
293 /// return true: we have a macro for the event
294 /// return false: no macro; getByName() will return an empty macro
295 /// IllegalArgumentException: the event is not supported
296 using SvBaseEventDescriptor::hasByName
;
298 const sal_uInt16 nEvent
) const /// item ID of event
300 ::com::sun::star::lang::IllegalArgumentException
);
304 class SVT_DLLPUBLIC SvMacroTableEventDescriptor
: public SvDetachedEventDescriptor
308 SvMacroTableEventDescriptor(const SvEventDescription
* pSupportedMacroItems
);
309 SvMacroTableEventDescriptor(const SvxMacroTableDtor
& aFmt
,
310 const SvEventDescription
* pSupportedMacroItems
);
312 virtual ~SvMacroTableEventDescriptor();
314 void copyMacrosFromTable(const SvxMacroTableDtor
& aFmt
);
315 void copyMacrosIntoTable(SvxMacroTableDtor
& aFmt
);
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */