sync master with lastest vba changes
[ooovba.git] / binfilter / inc / bf_svtools / unoevent.hxx
blobd5cb0b716575eb6bea5603eca354ec31ec8c62e5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoevent.hxx,v $
10 * $Revision: 1.4.30.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SVTOOLS_UNOEVENT_HXX_
31 #define _SVTOOLS_UNOEVENT_HXX_
33 #ifndef INCLUDED_SVTDLLAPI_H
34 #include "bf_svtools/svtdllapi.h"
35 #endif
37 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEREPLACE_HPP_
38 #include <com/sun/star/container/XNameReplace.hpp>
39 #endif
41 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #endif
45 #ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_
46 #include <com/sun/star/uno/XInterface.hpp>
47 #endif
49 #ifndef _CPPUHELPER_IMPLBASE2_HXX_
50 #include <cppuhelper/implbase2.hxx>
51 #endif
53 namespace binfilter
56 class SvxMacroTableDtor;
57 class SvxMacroItem;
58 class SvxMacro;
60 /** SvEventDescription: Description of a single event.
61 mnEvent is the id used by SvxMacroItem
62 mpEventName is the api name for this event
64 the last event in an array is indicated by mnEvent && mpEventName == 0
66 struct SvEventDescription
68 sal_uInt16 mnEvent;
69 const sal_Char* mpEventName;
72 /**
73 * SvBaseEventDescriptor: Abstract class that implements the basics
74 * of an XNameReplace that is delivered by the
75 * XEventsSupplier::getEvents() method.
77 * The functionality this class provides is:
78 * 1) Which elements are in the XNameReplace?
79 * 2) Mapping from Api names to item IDs.
80 * 3) conversion from SvxMacroItem to Any and vice versa.
82 * All details of how to actually get and set SvxMacroItem(s) have to
83 * be supplied by the base class.
85 class SvBaseEventDescriptor : public cppu::WeakImplHelper2
87 ::com::sun::star::container::XNameReplace,
88 ::com::sun::star::lang::XServiceInfo
91 const ::rtl::OUString sEventType;
92 const ::rtl::OUString sMacroName;
93 const ::rtl::OUString sLibrary;
94 const ::rtl::OUString sStarBasic;
95 const ::rtl::OUString sJavaScript;
96 const ::rtl::OUString sScript;
97 const ::rtl::OUString sNone;
100 /// name of own service
101 const ::rtl::OUString sServiceName;
103 protected:
104 const ::rtl::OUString sEmpty;
106 /// last element is 0, 0
107 const SvEventDescription* mpSupportedMacroItems;
108 sal_Int16 mnMacroItems;
110 public:
112 SvBaseEventDescriptor(const SvEventDescription* pSupportedMacroItems);
114 virtual ~SvBaseEventDescriptor();
117 // XNameReplace
118 /// calls replaceByName(const sal_uInt16, const SvxMacro&)
119 virtual void SAL_CALL replaceByName(
120 const ::rtl::OUString& rName, /// API name of event
121 const ::com::sun::star::uno::Any& rElement ) /// event (PropertyValues)
122 throw(
123 ::com::sun::star::lang::IllegalArgumentException,
124 ::com::sun::star::container::NoSuchElementException,
125 ::com::sun::star::lang::WrappedTargetException,
126 ::com::sun::star::uno::RuntimeException);
128 // XNameAccess (via XNameReplace)
129 /// calls getByName(sal_uInt16)
130 virtual ::com::sun::star::uno::Any SAL_CALL getByName(
131 const ::rtl::OUString& rName ) /// API name of event
132 throw(
133 ::com::sun::star::container::NoSuchElementException,
134 ::com::sun::star::lang::WrappedTargetException,
135 ::com::sun::star::uno::RuntimeException);
137 // XNameAxcess (via XNameReplace)
138 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
139 getElementNames()
140 throw(::com::sun::star::uno::RuntimeException);
142 // XNameAccess (via XNameReplace)
143 virtual sal_Bool SAL_CALL hasByName(
144 const ::rtl::OUString& rName )
145 throw(::com::sun::star::uno::RuntimeException);
147 // XElementAccess (via XNameReplace)
148 virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
149 throw(::com::sun::star::uno::RuntimeException);
151 // XElementAccess (via XNameReplace)
152 virtual sal_Bool SAL_CALL hasElements()
153 throw(::com::sun::star::uno::RuntimeException);
155 // XServiceInfo
156 /// must be implemented in subclass
157 virtual rtl::OUString SAL_CALL getImplementationName(void)
158 throw( ::com::sun::star::uno::RuntimeException ) = 0;
160 // XServiceInfo
161 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName)
162 throw( ::com::sun::star::uno::RuntimeException );
164 // XServiceInfo
165 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
166 getSupportedServiceNames(void)
167 throw( ::com::sun::star::uno::RuntimeException );
169 protected:
171 /// Must be implemented in subclass.
172 virtual void replaceByName(
173 const sal_uInt16 nEvent, /// item ID of event
174 const SvxMacro& rMacro) /// event (will be copied)
175 throw(
176 ::com::sun::star::lang::IllegalArgumentException,
177 ::com::sun::star::container::NoSuchElementException,
178 ::com::sun::star::lang::WrappedTargetException,
179 ::com::sun::star::uno::RuntimeException) = 0;
181 /// Must be implemented in subclass.
182 virtual void getByName(
183 SvxMacro& rMacro,
184 const sal_uInt16 nEvent )
185 throw(
186 ::com::sun::star::container::NoSuchElementException,
187 ::com::sun::star::lang::WrappedTargetException,
188 ::com::sun::star::uno::RuntimeException) = 0;
190 /// convert an API event name to the event ID as used by SvxMacroItem
191 sal_uInt16 mapNameToEventID(const ::rtl::OUString& rName) const;
193 /// get the event ID for the name; return 0 if not supported
194 sal_uInt16 getMacroID(const ::rtl::OUString& rName) const;
196 /// create PropertyValues and Any from macro
197 void getAnyFromMacro(
198 ::com::sun::star::uno::Any& aAny, // Any to be filled by Macro values
199 const SvxMacro& rMacro);
201 /// create macro from PropertyValues (in an Any)
202 void getMacroFromAny(
203 SvxMacro& aMacro, // reference to be filled by Any
204 const ::com::sun::star::uno::Any& rAny)
205 throw (
206 ::com::sun::star::lang::IllegalArgumentException);
213 /**
214 * SvEventDescriptor: Implement the XNameReplace that is delivered by
215 * the XEventsSupplier::getEvents() method. The SvEventDescriptor has
216 * to be subclassed to implement the events for a specific
217 * objects. The subclass has to
218 * 1) supply the super class constructor with a list of known events (item IDs)
219 * 2) supply the super class constructor with a reference of it's parent object
220 * (to prevent destruction)
221 * 3) implement getItem() and setItem(...) methods.
223 * If no object is available to which the SvEventDescriptor can attach itself,
224 * the class SvDetachedEventDescriptor should be used.
226 class SvEventDescriptor : public SvBaseEventDescriptor
228 /// keep reference to parent to prevent it from being destroyed
229 ::com::sun::star::uno::Reference<
230 ::com::sun::star::uno::XInterface > xParentRef;
232 public:
234 SvEventDescriptor(::com::sun::star::uno::XInterface& rParent,
235 const SvEventDescription* pSupportedMacroItems);
237 virtual ~SvEventDescriptor();
240 protected:
243 using SvBaseEventDescriptor::replaceByName;
244 virtual void replaceByName(
245 const sal_uInt16 nEvent, /// item ID of event
246 const SvxMacro& rMacro) /// event (will be copied)
247 throw(
248 ::com::sun::star::lang::IllegalArgumentException,
249 ::com::sun::star::container::NoSuchElementException,
250 ::com::sun::star::lang::WrappedTargetException,
251 ::com::sun::star::uno::RuntimeException);
253 using SvBaseEventDescriptor::getByName;
254 virtual void getByName(
255 SvxMacro& rMacros, /// macro to be filled with values
256 const sal_uInt16 nEvent ) /// item ID of event
257 throw(
258 ::com::sun::star::container::NoSuchElementException,
259 ::com::sun::star::lang::WrappedTargetException,
260 ::com::sun::star::uno::RuntimeException);
263 /// Get the SvxMacroItem from the parent.
264 /// must be implemented by subclass
265 virtual const SvxMacroItem& getMacroItem() = 0;
267 /// Set the SvxMacroItem at the parent.
268 /// must be implemented by subclass
269 virtual void setMacroItem(const SvxMacroItem& rItem) = 0;
271 /// Get the SvxMacroItem Which Id needed for the current application
272 /// must be implemented by subclass
273 virtual sal_uInt16 getMacroItemWhich() const = 0;
278 * SvDetachedEventDescriptor:
280 class SvDetachedEventDescriptor : public SvBaseEventDescriptor
282 // the macros; aMacros[i] is the value for aSupportedMacroItemIDs[i]
283 SvxMacro** aMacros;
285 const ::rtl::OUString sImplName;
287 public:
289 SvDetachedEventDescriptor(const SvEventDescription* pSupportedMacroItems);
291 virtual ~SvDetachedEventDescriptor();
293 //XServiceInfo
294 virtual rtl::OUString SAL_CALL getImplementationName(void)
295 throw( ::com::sun::star::uno::RuntimeException );
297 protected:
299 sal_Int16 getIndex(const sal_uInt16 nID);
301 using SvBaseEventDescriptor::replaceByName;
302 virtual void replaceByName(
303 const sal_uInt16 nEvent, /// item ID of event
304 const SvxMacro& rMacro) /// event (will be copied)
305 throw(
306 ::com::sun::star::lang::IllegalArgumentException,
307 ::com::sun::star::container::NoSuchElementException,
308 ::com::sun::star::lang::WrappedTargetException,
309 ::com::sun::star::uno::RuntimeException);
311 using SvBaseEventDescriptor::getByName;
312 virtual void getByName(
313 SvxMacro& rMacro, /// macro to be filled
314 const sal_uInt16 nEvent ) /// item ID of event
315 throw(
316 ::com::sun::star::container::NoSuchElementException,
317 ::com::sun::star::lang::WrappedTargetException,
318 ::com::sun::star::uno::RuntimeException);
320 /// do we have an event?
321 /// return sal_True: we have a macro for the event
322 /// return sal_False: no macro; getByName() will return an empty macro
323 /// IllegalArgumentException: the event is not supported
324 using SvBaseEventDescriptor::hasByName;
325 virtual sal_Bool hasByName(
326 const sal_uInt16 nEvent ) /// item ID of event
327 throw(
328 ::com::sun::star::lang::IllegalArgumentException);
332 class SvMacroTableEventDescriptor : public SvDetachedEventDescriptor
334 public:
336 SvMacroTableEventDescriptor(const SvEventDescription* pSupportedMacroItems);
337 SvMacroTableEventDescriptor(const SvxMacroTableDtor& aFmt,
338 const SvEventDescription* pSupportedMacroItems);
340 virtual ~SvMacroTableEventDescriptor();
342 void copyMacrosFromTable(const SvxMacroTableDtor& aFmt);
343 void copyMacrosIntoTable(SvxMacroTableDtor& aFmt);
348 #endif