merge the formfield patch from ooo-build
[ooovba.git] / svtools / inc / unoevent.hxx
blob340e135872652d2eaddbd8625d6c1ce879a18cec
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.5.136.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 #include "svtools/svtdllapi.h"
34 #include <com/sun/star/container/XNameReplace.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/uno/XInterface.hpp>
37 #include <cppuhelper/implbase2.hxx>
39 class SvxMacroTableDtor;
40 class SvxMacroItem;
41 class SvxMacro;
43 /** SvEventDescription: Description of a single event.
44 mnEvent is the id used by SvxMacroItem
45 mpEventName is the api name for this event
47 the last event in an array is indicated by mnEvent && mpEventName == 0
49 struct SvEventDescription
51 sal_uInt16 mnEvent;
52 const sal_Char* mpEventName;
55 /**
56 * SvBaseEventDescriptor: Abstract class that implements the basics
57 * of an XNameReplace that is delivered by the
58 * XEventsSupplier::getEvents() method.
60 * The functionality this class provides is:
61 * 1) Which elements are in the XNameReplace?
62 * 2) Mapping from Api names to item IDs.
63 * 3) conversion from SvxMacroItem to Any and vice versa.
65 * All details of how to actually get and set SvxMacroItem(s) have to
66 * be supplied by the base class.
68 class SVT_DLLPUBLIC SvBaseEventDescriptor : public cppu::WeakImplHelper2
70 ::com::sun::star::container::XNameReplace,
71 ::com::sun::star::lang::XServiceInfo
74 const ::rtl::OUString sEventType;
75 const ::rtl::OUString sMacroName;
76 const ::rtl::OUString sLibrary;
77 const ::rtl::OUString sStarBasic;
78 const ::rtl::OUString sJavaScript;
79 const ::rtl::OUString sScript;
80 const ::rtl::OUString sNone;
83 /// name of own service
84 const ::rtl::OUString sServiceName;
86 protected:
87 const ::rtl::OUString sEmpty;
89 /// last element is 0, 0
90 const SvEventDescription* mpSupportedMacroItems;
91 sal_Int16 mnMacroItems;
93 public:
95 SvBaseEventDescriptor(const SvEventDescription* pSupportedMacroItems);
97 virtual ~SvBaseEventDescriptor();
100 // XNameReplace
101 /// calls replaceByName(const sal_uInt16, const SvxMacro&)
102 virtual void SAL_CALL replaceByName(
103 const ::rtl::OUString& rName, /// API name of event
104 const ::com::sun::star::uno::Any& rElement ) /// event (PropertyValues)
105 throw(
106 ::com::sun::star::lang::IllegalArgumentException,
107 ::com::sun::star::container::NoSuchElementException,
108 ::com::sun::star::lang::WrappedTargetException,
109 ::com::sun::star::uno::RuntimeException);
111 // XNameAccess (via XNameReplace)
112 /// calls getByName(sal_uInt16)
113 virtual ::com::sun::star::uno::Any SAL_CALL getByName(
114 const ::rtl::OUString& rName ) /// API name of event
115 throw(
116 ::com::sun::star::container::NoSuchElementException,
117 ::com::sun::star::lang::WrappedTargetException,
118 ::com::sun::star::uno::RuntimeException);
120 // XNameAxcess (via XNameReplace)
121 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
122 getElementNames()
123 throw(::com::sun::star::uno::RuntimeException);
125 // XNameAccess (via XNameReplace)
126 virtual sal_Bool SAL_CALL hasByName(
127 const ::rtl::OUString& rName )
128 throw(::com::sun::star::uno::RuntimeException);
130 // XElementAccess (via XNameReplace)
131 virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
132 throw(::com::sun::star::uno::RuntimeException);
134 // XElementAccess (via XNameReplace)
135 virtual sal_Bool SAL_CALL hasElements()
136 throw(::com::sun::star::uno::RuntimeException);
138 // XServiceInfo
139 /// must be implemented in subclass
140 virtual rtl::OUString SAL_CALL getImplementationName(void)
141 throw( ::com::sun::star::uno::RuntimeException ) = 0;
143 // XServiceInfo
144 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName)
145 throw( ::com::sun::star::uno::RuntimeException );
147 // XServiceInfo
148 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
149 getSupportedServiceNames(void)
150 throw( ::com::sun::star::uno::RuntimeException );
152 protected:
154 /// Must be implemented in subclass.
155 virtual void replaceByName(
156 const sal_uInt16 nEvent, /// item ID of event
157 const SvxMacro& rMacro) /// event (will be copied)
158 throw(
159 ::com::sun::star::lang::IllegalArgumentException,
160 ::com::sun::star::container::NoSuchElementException,
161 ::com::sun::star::lang::WrappedTargetException,
162 ::com::sun::star::uno::RuntimeException) = 0;
164 /// Must be implemented in subclass.
165 virtual void getByName(
166 SvxMacro& rMacro,
167 const sal_uInt16 nEvent )
168 throw(
169 ::com::sun::star::container::NoSuchElementException,
170 ::com::sun::star::lang::WrappedTargetException,
171 ::com::sun::star::uno::RuntimeException) = 0;
173 /// convert an API event name to the event ID as used by SvxMacroItem
174 sal_uInt16 mapNameToEventID(const ::rtl::OUString& rName) const;
176 /// convert an event ID to an API event name
177 ::rtl::OUString mapEventIDToName(sal_uInt16 nPoolID) const;
179 /// get the event ID for the name; return 0 if not supported
180 sal_uInt16 getMacroID(const ::rtl::OUString& rName) const;
182 /// create PropertyValues and Any from macro
183 void getAnyFromMacro(
184 ::com::sun::star::uno::Any& aAny, // Any to be filled by Macro values
185 const SvxMacro& rMacro);
187 /// create macro from PropertyValues (in an Any)
188 void getMacroFromAny(
189 SvxMacro& aMacro, // reference to be filled by Any
190 const ::com::sun::star::uno::Any& rAny)
191 throw (
192 ::com::sun::star::lang::IllegalArgumentException);
199 /**
200 * SvEventDescriptor: Implement the XNameReplace that is delivered by
201 * the XEventsSupplier::getEvents() method. The SvEventDescriptor has
202 * to be subclassed to implement the events for a specific
203 * objects. The subclass has to
204 * 1) supply the super class constructor with a list of known events (item IDs)
205 * 2) supply the super class constructor with a reference of it's parent object
206 * (to prevent destruction)
207 * 3) implement getItem() and setItem(...) methods.
209 * If no object is available to which the SvEventDescriptor can attach itself,
210 * the class SvDetachedEventDescriptor should be used.
212 class SVT_DLLPUBLIC SvEventDescriptor : public SvBaseEventDescriptor
214 /// keep reference to parent to prevent it from being destroyed
215 ::com::sun::star::uno::Reference<
216 ::com::sun::star::uno::XInterface > xParentRef;
218 public:
220 SvEventDescriptor(::com::sun::star::uno::XInterface& rParent,
221 const SvEventDescription* pSupportedMacroItems);
223 virtual ~SvEventDescriptor();
226 protected:
229 using SvBaseEventDescriptor::replaceByName;
230 virtual void replaceByName(
231 const sal_uInt16 nEvent, /// item ID of event
232 const SvxMacro& rMacro) /// event (will be copied)
233 throw(
234 ::com::sun::star::lang::IllegalArgumentException,
235 ::com::sun::star::container::NoSuchElementException,
236 ::com::sun::star::lang::WrappedTargetException,
237 ::com::sun::star::uno::RuntimeException);
239 using SvBaseEventDescriptor::getByName;
240 virtual void getByName(
241 SvxMacro& rMacros, /// macro to be filled with values
242 const sal_uInt16 nEvent ) /// item ID of event
243 throw(
244 ::com::sun::star::container::NoSuchElementException,
245 ::com::sun::star::lang::WrappedTargetException,
246 ::com::sun::star::uno::RuntimeException);
249 /// Get the SvxMacroItem from the parent.
250 /// must be implemented by subclass
251 virtual const SvxMacroItem& getMacroItem() = 0;
253 /// Set the SvxMacroItem at the parent.
254 /// must be implemented by subclass
255 virtual void setMacroItem(const SvxMacroItem& rItem) = 0;
257 /// Get the SvxMacroItem Which Id needed for the current application
258 /// must be implemented by subclass
259 virtual sal_uInt16 getMacroItemWhich() const = 0;
264 * SvDetachedEventDescriptor:
266 class SVT_DLLPUBLIC SvDetachedEventDescriptor : public SvBaseEventDescriptor
268 // the macros; aMacros[i] is the value for aSupportedMacroItemIDs[i]
269 SvxMacro** aMacros;
271 const ::rtl::OUString sImplName;
273 public:
275 SvDetachedEventDescriptor(const SvEventDescription* pSupportedMacroItems);
277 virtual ~SvDetachedEventDescriptor();
279 //XServiceInfo
280 virtual rtl::OUString SAL_CALL getImplementationName(void)
281 throw( ::com::sun::star::uno::RuntimeException );
283 protected:
285 sal_Int16 getIndex(const sal_uInt16 nID) const;
287 using SvBaseEventDescriptor::replaceByName;
288 virtual void replaceByName(
289 const sal_uInt16 nEvent, /// item ID of event
290 const SvxMacro& rMacro) /// event (will be copied)
291 throw(
292 ::com::sun::star::lang::IllegalArgumentException,
293 ::com::sun::star::container::NoSuchElementException,
294 ::com::sun::star::lang::WrappedTargetException,
295 ::com::sun::star::uno::RuntimeException);
297 using SvBaseEventDescriptor::getByName;
298 virtual void getByName(
299 SvxMacro& rMacro, /// macro to be filled
300 const sal_uInt16 nEvent ) /// item ID of event
301 throw(
302 ::com::sun::star::container::NoSuchElementException,
303 ::com::sun::star::lang::WrappedTargetException,
304 ::com::sun::star::uno::RuntimeException);
306 /// do we have an event?
307 /// return sal_True: we have a macro for the event
308 /// return sal_False: no macro; getByName() will return an empty macro
309 /// IllegalArgumentException: the event is not supported
310 using SvBaseEventDescriptor::hasByName;
311 virtual sal_Bool hasByName(
312 const sal_uInt16 nEvent ) const /// item ID of event
313 throw(
314 ::com::sun::star::lang::IllegalArgumentException);
318 class SVT_DLLPUBLIC SvMacroTableEventDescriptor : public SvDetachedEventDescriptor
320 public:
322 SvMacroTableEventDescriptor(const SvEventDescription* pSupportedMacroItems);
323 SvMacroTableEventDescriptor(const SvxMacroTableDtor& aFmt,
324 const SvEventDescription* pSupportedMacroItems);
326 virtual ~SvMacroTableEventDescriptor();
328 void copyMacrosFromTable(const SvxMacroTableDtor& aFmt);
329 void copyMacrosIntoTable(SvxMacroTableDtor& aFmt);
332 #endif