1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5900e8ecSAndrew Rist * distributed with this work for additional information
6*5900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
10*5900e8ecSAndrew Rist *
11*5900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist *
13*5900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
17*5900e8ecSAndrew Rist * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist * under the License.
19*5900e8ecSAndrew Rist *
20*5900e8ecSAndrew Rist *************************************************************/
21*5900e8ecSAndrew Rist
22*5900e8ecSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
28cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
29cdf0e10cSrcweir #include <tools/rtti.hxx>
30cdf0e10cSrcweir #include <tools/solar.h>
31cdf0e10cSrcweir #include <svtools/unoevent.hxx>
32cdf0e10cSrcweir #include <svl/macitem.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir using namespace ::com::sun::star::uno;
36cdf0e10cSrcweir
37cdf0e10cSrcweir using ::com::sun::star::container::NoSuchElementException;
38cdf0e10cSrcweir using ::com::sun::star::container::XNameReplace;
39cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException;
40cdf0e10cSrcweir using ::com::sun::star::lang::WrappedTargetException;
41cdf0e10cSrcweir using ::com::sun::star::lang::XServiceInfo;
42cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
43cdf0e10cSrcweir using ::cppu::WeakImplHelper2;
44cdf0e10cSrcweir using ::rtl::OUString;
45cdf0e10cSrcweir using ::rtl::OUStringBuffer;
46cdf0e10cSrcweir
47cdf0e10cSrcweir
48cdf0e10cSrcweir const sal_Char sAPI_ServiceName[] = "com.sun.star.container.XNameReplace";
49cdf0e10cSrcweir const sal_Char sAPI_SvDetachedEventDescriptor[] = "SvDetachedEventDescriptor";
50cdf0e10cSrcweir
51cdf0e10cSrcweir //
52cdf0e10cSrcweir // SvBaseEventDescriptor
53cdf0e10cSrcweir //
54cdf0e10cSrcweir
SvBaseEventDescriptor(const SvEventDescription * pSupportedMacroItems)55cdf0e10cSrcweir SvBaseEventDescriptor::SvBaseEventDescriptor( const SvEventDescription* pSupportedMacroItems ) :
56cdf0e10cSrcweir sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
57cdf0e10cSrcweir sMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName")),
58cdf0e10cSrcweir sLibrary(RTL_CONSTASCII_USTRINGPARAM("Library")),
59cdf0e10cSrcweir sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic")),
60cdf0e10cSrcweir sJavaScript(RTL_CONSTASCII_USTRINGPARAM("JavaScript")),
61cdf0e10cSrcweir sScript(RTL_CONSTASCII_USTRINGPARAM("Script")),
62cdf0e10cSrcweir sNone(RTL_CONSTASCII_USTRINGPARAM("None")),
63cdf0e10cSrcweir sServiceName(RTL_CONSTASCII_USTRINGPARAM(sAPI_ServiceName)),
64cdf0e10cSrcweir sEmpty(),
65cdf0e10cSrcweir mpSupportedMacroItems(pSupportedMacroItems),
66cdf0e10cSrcweir mnMacroItems(0)
67cdf0e10cSrcweir {
68cdf0e10cSrcweir DBG_ASSERT(pSupportedMacroItems != NULL, "Need a list of supported events!");
69cdf0e10cSrcweir
70cdf0e10cSrcweir for( ; mpSupportedMacroItems[mnMacroItems].mnEvent != 0; mnMacroItems++) ;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir
~SvBaseEventDescriptor()74cdf0e10cSrcweir SvBaseEventDescriptor::~SvBaseEventDescriptor()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
replaceByName(const OUString & rName,const Any & rElement)78cdf0e10cSrcweir void SvBaseEventDescriptor::replaceByName(
79cdf0e10cSrcweir const OUString& rName,
80cdf0e10cSrcweir const Any& rElement )
81cdf0e10cSrcweir throw(
82cdf0e10cSrcweir IllegalArgumentException,
83cdf0e10cSrcweir NoSuchElementException,
84cdf0e10cSrcweir WrappedTargetException,
85cdf0e10cSrcweir RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir sal_uInt16 nMacroID = getMacroID(rName);
88cdf0e10cSrcweir
89cdf0e10cSrcweir // error checking
90cdf0e10cSrcweir if (0 == nMacroID)
91cdf0e10cSrcweir throw NoSuchElementException();
92cdf0e10cSrcweir if (rElement.getValueType() != getElementType())
93cdf0e10cSrcweir throw IllegalArgumentException();
94cdf0e10cSrcweir
95cdf0e10cSrcweir // get sequence
96cdf0e10cSrcweir Sequence<PropertyValue> aSequence;
97cdf0e10cSrcweir rElement >>= aSequence;
98cdf0e10cSrcweir
99cdf0e10cSrcweir // perform replace (in subclass)
100cdf0e10cSrcweir SvxMacro aMacro(sEmpty,sEmpty);
101cdf0e10cSrcweir getMacroFromAny(aMacro, rElement);
102cdf0e10cSrcweir replaceByName(nMacroID, aMacro);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
getByName(const OUString & rName)105cdf0e10cSrcweir Any SvBaseEventDescriptor::getByName(
106cdf0e10cSrcweir const OUString& rName )
107cdf0e10cSrcweir throw(
108cdf0e10cSrcweir NoSuchElementException,
109cdf0e10cSrcweir WrappedTargetException,
110cdf0e10cSrcweir RuntimeException)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir sal_uInt16 nMacroID = getMacroID(rName);
113cdf0e10cSrcweir
114cdf0e10cSrcweir // error checking
115cdf0e10cSrcweir if (0 == nMacroID)
116cdf0e10cSrcweir throw NoSuchElementException();
117cdf0e10cSrcweir
118cdf0e10cSrcweir // perform get (in subclass)
119cdf0e10cSrcweir Any aAny;
120cdf0e10cSrcweir SvxMacro aMacro( sEmpty, sEmpty );
121cdf0e10cSrcweir getByName(aMacro, nMacroID);
122cdf0e10cSrcweir getAnyFromMacro(aAny, aMacro);
123cdf0e10cSrcweir return aAny;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
getElementNames()126cdf0e10cSrcweir Sequence<OUString> SvBaseEventDescriptor::getElementNames()
127cdf0e10cSrcweir throw(RuntimeException)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir // create and fill sequence
130cdf0e10cSrcweir Sequence<OUString> aSequence(mnMacroItems);
131cdf0e10cSrcweir for( sal_Int16 i = 0; i < mnMacroItems; i++)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir aSequence[i] = OUString::createFromAscii( mpSupportedMacroItems[i].mpEventName );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir
136cdf0e10cSrcweir return aSequence;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
hasByName(const OUString & rName)139cdf0e10cSrcweir sal_Bool SvBaseEventDescriptor::hasByName(
140cdf0e10cSrcweir const OUString& rName )
141cdf0e10cSrcweir throw(RuntimeException)
142cdf0e10cSrcweir {
143cdf0e10cSrcweir sal_uInt16 nMacroID = getMacroID(rName);
144cdf0e10cSrcweir return (nMacroID != 0);
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
getElementType()147cdf0e10cSrcweir Type SvBaseEventDescriptor::getElementType()
148cdf0e10cSrcweir throw(RuntimeException)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir return ::getCppuType((Sequence<PropertyValue> *)0);
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
hasElements()153cdf0e10cSrcweir sal_Bool SvBaseEventDescriptor::hasElements()
154cdf0e10cSrcweir throw(RuntimeException)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir return mnMacroItems != 0;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
supportsService(const OUString & rServiceName)159cdf0e10cSrcweir sal_Bool SvBaseEventDescriptor::supportsService(const OUString& rServiceName)
160cdf0e10cSrcweir throw(RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir return sServiceName.equals(rServiceName);
163cdf0e10cSrcweir }
164cdf0e10cSrcweir
getSupportedServiceNames(void)165cdf0e10cSrcweir Sequence<OUString> SvBaseEventDescriptor::getSupportedServiceNames(void)
166cdf0e10cSrcweir throw(RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir Sequence<OUString> aSequence(1);
169cdf0e10cSrcweir aSequence[0] = sServiceName;
170cdf0e10cSrcweir
171cdf0e10cSrcweir return aSequence;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
mapNameToEventID(const OUString & rName) const174cdf0e10cSrcweir sal_uInt16 SvBaseEventDescriptor::mapNameToEventID(const OUString& rName) const
175cdf0e10cSrcweir {
176cdf0e10cSrcweir // iterate over known event names
177cdf0e10cSrcweir for(sal_Int16 i = 0; i < mnMacroItems; i++)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir if (0 == rName.compareToAscii(mpSupportedMacroItems[i].mpEventName))
180cdf0e10cSrcweir {
181cdf0e10cSrcweir return mpSupportedMacroItems[i].mnEvent;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir }
184cdf0e10cSrcweir
185cdf0e10cSrcweir // not found -> return zero
186cdf0e10cSrcweir return 0;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
mapEventIDToName(sal_uInt16 nPoolID) const189cdf0e10cSrcweir OUString SvBaseEventDescriptor::mapEventIDToName(sal_uInt16 nPoolID) const
190cdf0e10cSrcweir {
191cdf0e10cSrcweir // iterate over known event IDs
192cdf0e10cSrcweir for(sal_Int16 i = 0; i < mnMacroItems; i++)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir if (nPoolID == mpSupportedMacroItems[i].mnEvent)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir return OUString::createFromAscii(mpSupportedMacroItems[i].mpEventName);
197cdf0e10cSrcweir }
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir // not found -> return empty string
201cdf0e10cSrcweir return OUString();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
getMacroID(const OUString & rName) const204cdf0e10cSrcweir sal_uInt16 SvBaseEventDescriptor::getMacroID(const OUString& rName) const
205cdf0e10cSrcweir {
206cdf0e10cSrcweir return mapNameToEventID(rName);
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
getAnyFromMacro(Any & rAny,const SvxMacro & rMacro)209cdf0e10cSrcweir void SvBaseEventDescriptor::getAnyFromMacro(Any& rAny,
210cdf0e10cSrcweir const SvxMacro& rMacro)
211cdf0e10cSrcweir {
212cdf0e10cSrcweir sal_Bool bRetValueOK = sal_False; // do we have a ret value?
213cdf0e10cSrcweir
214cdf0e10cSrcweir if (rMacro.HasMacro())
215cdf0e10cSrcweir {
216cdf0e10cSrcweir switch (rMacro.GetScriptType())
217cdf0e10cSrcweir {
218cdf0e10cSrcweir case STARBASIC:
219cdf0e10cSrcweir {
220cdf0e10cSrcweir // create sequence
221cdf0e10cSrcweir Sequence<PropertyValue> aSequence(3);
222cdf0e10cSrcweir Any aTmp;
223cdf0e10cSrcweir
224cdf0e10cSrcweir // create type
225cdf0e10cSrcweir PropertyValue aTypeValue;
226cdf0e10cSrcweir aTypeValue.Name = sEventType;
227cdf0e10cSrcweir aTmp <<= sStarBasic;
228cdf0e10cSrcweir aTypeValue.Value = aTmp;
229cdf0e10cSrcweir aSequence[0] = aTypeValue;
230cdf0e10cSrcweir
231cdf0e10cSrcweir // macro name
232cdf0e10cSrcweir PropertyValue aNameValue;
233cdf0e10cSrcweir aNameValue.Name = sMacroName;
234cdf0e10cSrcweir OUString sNameTmp(rMacro.GetMacName());
235cdf0e10cSrcweir aTmp <<= sNameTmp;
236cdf0e10cSrcweir aNameValue.Value = aTmp;
237cdf0e10cSrcweir aSequence[1] = aNameValue;
238cdf0e10cSrcweir
239cdf0e10cSrcweir // library name
240cdf0e10cSrcweir PropertyValue aLibValue;
241cdf0e10cSrcweir aLibValue.Name = sLibrary;
242cdf0e10cSrcweir OUString sLibTmp(rMacro.GetLibName());
243cdf0e10cSrcweir aTmp <<= sLibTmp;
244cdf0e10cSrcweir aLibValue.Value = aTmp;
245cdf0e10cSrcweir aSequence[2] = aLibValue;
246cdf0e10cSrcweir
247cdf0e10cSrcweir rAny <<= aSequence;
248cdf0e10cSrcweir bRetValueOK = sal_True;
249cdf0e10cSrcweir break;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir case EXTENDED_STYPE:
252cdf0e10cSrcweir {
253cdf0e10cSrcweir // create sequence
254cdf0e10cSrcweir Sequence<PropertyValue> aSequence(2);
255cdf0e10cSrcweir Any aTmp;
256cdf0e10cSrcweir
257cdf0e10cSrcweir // create type
258cdf0e10cSrcweir PropertyValue aTypeValue;
259cdf0e10cSrcweir aTypeValue.Name = sEventType;
260cdf0e10cSrcweir aTmp <<= sScript;
261cdf0e10cSrcweir aTypeValue.Value = aTmp;
262cdf0e10cSrcweir aSequence[0] = aTypeValue;
263cdf0e10cSrcweir
264cdf0e10cSrcweir // macro name
265cdf0e10cSrcweir PropertyValue aNameValue;
266cdf0e10cSrcweir aNameValue.Name = sScript;
267cdf0e10cSrcweir OUString sNameTmp(rMacro.GetMacName());
268cdf0e10cSrcweir aTmp <<= sNameTmp;
269cdf0e10cSrcweir aNameValue.Value = aTmp;
270cdf0e10cSrcweir aSequence[1] = aNameValue;
271cdf0e10cSrcweir
272cdf0e10cSrcweir rAny <<= aSequence;
273cdf0e10cSrcweir bRetValueOK = sal_True;
274cdf0e10cSrcweir break;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir case JAVASCRIPT:
277cdf0e10cSrcweir default:
278cdf0e10cSrcweir DBG_ERROR("not implemented");
279cdf0e10cSrcweir }
280cdf0e10cSrcweir }
281cdf0e10cSrcweir // else: bRetValueOK not set
282cdf0e10cSrcweir
283cdf0e10cSrcweir // if we don't have a return value, make an empty one
284cdf0e10cSrcweir if (! bRetValueOK)
285cdf0e10cSrcweir {
286cdf0e10cSrcweir // create "None" macro
287cdf0e10cSrcweir Sequence<PropertyValue> aSequence(1);
288cdf0e10cSrcweir
289cdf0e10cSrcweir PropertyValue aKindValue;
290cdf0e10cSrcweir aKindValue.Name = sEventType;
291cdf0e10cSrcweir Any aTmp;
292cdf0e10cSrcweir aTmp <<= sNone;
293cdf0e10cSrcweir aKindValue.Value = aTmp;
294cdf0e10cSrcweir aSequence[0] = aKindValue;
295cdf0e10cSrcweir
296cdf0e10cSrcweir rAny <<= aSequence;
297cdf0e10cSrcweir bRetValueOK = sal_True;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir }
300cdf0e10cSrcweir
301cdf0e10cSrcweir
getMacroFromAny(SvxMacro & rMacro,const Any & rAny)302cdf0e10cSrcweir void SvBaseEventDescriptor::getMacroFromAny(
303cdf0e10cSrcweir SvxMacro& rMacro,
304cdf0e10cSrcweir const Any& rAny)
305cdf0e10cSrcweir throw ( IllegalArgumentException )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir // get sequence
308cdf0e10cSrcweir Sequence<PropertyValue> aSequence;
309cdf0e10cSrcweir rAny >>= aSequence;
310cdf0e10cSrcweir
311cdf0e10cSrcweir // process ...
312cdf0e10cSrcweir sal_Bool bTypeOK = sal_False;
313cdf0e10cSrcweir sal_Bool bNone = sal_False; // true if EventType=="None"
314cdf0e10cSrcweir enum ScriptType eType = EXTENDED_STYPE;
315cdf0e10cSrcweir OUString sScriptVal;
316cdf0e10cSrcweir OUString sMacroVal;
317cdf0e10cSrcweir OUString sLibVal;
318cdf0e10cSrcweir sal_Int32 nCount = aSequence.getLength();
319cdf0e10cSrcweir for (sal_Int32 i = 0; i < nCount; i++)
320cdf0e10cSrcweir {
321cdf0e10cSrcweir PropertyValue& aValue = aSequence[i];
322cdf0e10cSrcweir if (aValue.Name.equals(sEventType))
323cdf0e10cSrcweir {
324cdf0e10cSrcweir OUString sTmp;
325cdf0e10cSrcweir aValue.Value >>= sTmp;
326cdf0e10cSrcweir if (sTmp.equals(sStarBasic))
327cdf0e10cSrcweir {
328cdf0e10cSrcweir eType = STARBASIC;
329cdf0e10cSrcweir bTypeOK = sal_True;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir else if (sTmp.equals(sJavaScript))
332cdf0e10cSrcweir {
333cdf0e10cSrcweir eType = JAVASCRIPT;
334cdf0e10cSrcweir bTypeOK = sal_True;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir else if (sTmp.equals(sScript))
337cdf0e10cSrcweir {
338cdf0e10cSrcweir eType = EXTENDED_STYPE;
339cdf0e10cSrcweir bTypeOK = sal_True;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir else if (sTmp.equals(sNone))
342cdf0e10cSrcweir {
343cdf0e10cSrcweir bNone = sal_True;
344cdf0e10cSrcweir bTypeOK = sal_True;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir // else: unknown script type
347cdf0e10cSrcweir }
348cdf0e10cSrcweir else if (aValue.Name.equals(sMacroName))
349cdf0e10cSrcweir {
350cdf0e10cSrcweir aValue.Value >>= sMacroVal;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir else if (aValue.Name.equals(sLibrary))
353cdf0e10cSrcweir {
354cdf0e10cSrcweir aValue.Value >>= sLibVal;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir else if (aValue.Name.equals(sScript))
357cdf0e10cSrcweir {
358cdf0e10cSrcweir aValue.Value >>= sScriptVal;
359cdf0e10cSrcweir }
360cdf0e10cSrcweir // else: unknown PropertyValue -> ignore
361cdf0e10cSrcweir }
362cdf0e10cSrcweir
363cdf0e10cSrcweir if (bTypeOK)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir if (bNone)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir // return empty macro
368cdf0e10cSrcweir rMacro = SvxMacro( sEmpty, sEmpty );
369cdf0e10cSrcweir }
370cdf0e10cSrcweir else
371cdf0e10cSrcweir {
372cdf0e10cSrcweir if (eType == STARBASIC)
373cdf0e10cSrcweir {
374cdf0e10cSrcweir // create macro and return
375cdf0e10cSrcweir SvxMacro aMacro(sMacroVal, sLibVal, eType);
376cdf0e10cSrcweir rMacro = aMacro;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir else if (eType == EXTENDED_STYPE)
379cdf0e10cSrcweir {
380cdf0e10cSrcweir SvxMacro aMacro(sScriptVal, sScript);
381cdf0e10cSrcweir rMacro = aMacro;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir else
384cdf0e10cSrcweir {
385cdf0e10cSrcweir // we can't process type: abort
386cdf0e10cSrcweir // TODO: JavaScript macros
387cdf0e10cSrcweir throw IllegalArgumentException();
388cdf0e10cSrcweir }
389cdf0e10cSrcweir }
390cdf0e10cSrcweir }
391cdf0e10cSrcweir else
392cdf0e10cSrcweir {
393cdf0e10cSrcweir // no valid type: abort
394cdf0e10cSrcweir throw IllegalArgumentException();
395cdf0e10cSrcweir }
396cdf0e10cSrcweir }
397cdf0e10cSrcweir
398cdf0e10cSrcweir
399cdf0e10cSrcweir
400cdf0e10cSrcweir
401cdf0e10cSrcweir //
402cdf0e10cSrcweir // SvEventDescriptor
403cdf0e10cSrcweir //
404cdf0e10cSrcweir
405cdf0e10cSrcweir
SvEventDescriptor(XInterface & rParent,const SvEventDescription * pSupportedMacroItems)406cdf0e10cSrcweir SvEventDescriptor::SvEventDescriptor(
407cdf0e10cSrcweir XInterface& rParent,
408cdf0e10cSrcweir const SvEventDescription* pSupportedMacroItems) :
409cdf0e10cSrcweir SvBaseEventDescriptor(pSupportedMacroItems),
410cdf0e10cSrcweir xParentRef(&rParent)
411cdf0e10cSrcweir {
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir
~SvEventDescriptor()415cdf0e10cSrcweir SvEventDescriptor::~SvEventDescriptor()
416cdf0e10cSrcweir {
417cdf0e10cSrcweir // automatically release xParentRef !
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
replaceByName(const sal_uInt16 nEvent,const SvxMacro & rMacro)420cdf0e10cSrcweir void SvEventDescriptor::replaceByName(
421cdf0e10cSrcweir const sal_uInt16 nEvent,
422cdf0e10cSrcweir const SvxMacro& rMacro)
423cdf0e10cSrcweir throw(
424cdf0e10cSrcweir IllegalArgumentException,
425cdf0e10cSrcweir NoSuchElementException,
426cdf0e10cSrcweir WrappedTargetException,
427cdf0e10cSrcweir RuntimeException)
428cdf0e10cSrcweir {
429cdf0e10cSrcweir SvxMacroItem aItem(getMacroItemWhich());
430cdf0e10cSrcweir aItem.SetMacroTable(getMacroItem().GetMacroTable());
431cdf0e10cSrcweir aItem.SetMacro(nEvent, rMacro);
432cdf0e10cSrcweir setMacroItem(aItem);
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
getByName(SvxMacro & rMacro,const sal_uInt16 nEvent)435cdf0e10cSrcweir void SvEventDescriptor::getByName(
436cdf0e10cSrcweir SvxMacro& rMacro,
437cdf0e10cSrcweir const sal_uInt16 nEvent )
438cdf0e10cSrcweir throw(
439cdf0e10cSrcweir NoSuchElementException,
440cdf0e10cSrcweir WrappedTargetException,
441cdf0e10cSrcweir RuntimeException)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir const SvxMacroItem& rItem = getMacroItem();
444cdf0e10cSrcweir if( rItem.HasMacro( nEvent ) )
445cdf0e10cSrcweir rMacro = rItem.GetMacro(nEvent);
446cdf0e10cSrcweir else
447cdf0e10cSrcweir {
448cdf0e10cSrcweir SvxMacro aEmptyMacro(sEmpty, sEmpty);
449cdf0e10cSrcweir rMacro = aEmptyMacro;
450cdf0e10cSrcweir }
451cdf0e10cSrcweir }
452cdf0e10cSrcweir
453cdf0e10cSrcweir
454cdf0e10cSrcweir
455cdf0e10cSrcweir
456cdf0e10cSrcweir //
457cdf0e10cSrcweir // SvDetachedEventDescriptor
458cdf0e10cSrcweir //
459cdf0e10cSrcweir
SvDetachedEventDescriptor(const SvEventDescription * pSupportedMacroItems)460cdf0e10cSrcweir SvDetachedEventDescriptor::SvDetachedEventDescriptor(
461cdf0e10cSrcweir const SvEventDescription* pSupportedMacroItems) :
462cdf0e10cSrcweir SvBaseEventDescriptor(pSupportedMacroItems),
463cdf0e10cSrcweir sImplName(RTL_CONSTASCII_USTRINGPARAM(sAPI_SvDetachedEventDescriptor))
464cdf0e10cSrcweir {
465cdf0e10cSrcweir // allocate aMacros
466cdf0e10cSrcweir aMacros = new SvxMacro*[mnMacroItems];
467cdf0e10cSrcweir
468cdf0e10cSrcweir // ... and initialize
469cdf0e10cSrcweir for(sal_Int16 i = 0; i < mnMacroItems; i++)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir aMacros[i] = NULL;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir }
474cdf0e10cSrcweir
~SvDetachedEventDescriptor()475cdf0e10cSrcweir SvDetachedEventDescriptor::~SvDetachedEventDescriptor()
476cdf0e10cSrcweir {
477cdf0e10cSrcweir // delete contents of aMacros
478cdf0e10cSrcweir for(sal_Int16 i = 0; i < mnMacroItems; i++)
479cdf0e10cSrcweir {
480cdf0e10cSrcweir if (NULL != aMacros[i])
481cdf0e10cSrcweir delete aMacros[i];
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
484cdf0e10cSrcweir delete [] aMacros;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir
getIndex(const sal_uInt16 nID) const487cdf0e10cSrcweir sal_Int16 SvDetachedEventDescriptor::getIndex(const sal_uInt16 nID) const
488cdf0e10cSrcweir {
489cdf0e10cSrcweir // iterate over supported events
490cdf0e10cSrcweir sal_Int16 nIndex = 0;
491cdf0e10cSrcweir while ( (mpSupportedMacroItems[nIndex].mnEvent != nID) &&
492cdf0e10cSrcweir (mpSupportedMacroItems[nIndex].mnEvent != 0) )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir nIndex++;
495cdf0e10cSrcweir }
496cdf0e10cSrcweir return (mpSupportedMacroItems[nIndex].mnEvent == nID) ? nIndex : -1;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir
getImplementationName()499cdf0e10cSrcweir OUString SvDetachedEventDescriptor::getImplementationName()
500cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir return sImplName;
503cdf0e10cSrcweir }
504cdf0e10cSrcweir
505cdf0e10cSrcweir
replaceByName(const sal_uInt16 nEvent,const SvxMacro & rMacro)506cdf0e10cSrcweir void SvDetachedEventDescriptor::replaceByName(
507cdf0e10cSrcweir const sal_uInt16 nEvent,
508cdf0e10cSrcweir const SvxMacro& rMacro)
509cdf0e10cSrcweir throw(
510cdf0e10cSrcweir IllegalArgumentException,
511cdf0e10cSrcweir NoSuchElementException,
512cdf0e10cSrcweir WrappedTargetException,
513cdf0e10cSrcweir RuntimeException)
514cdf0e10cSrcweir {
515cdf0e10cSrcweir sal_Int16 nIndex = getIndex(nEvent);
516cdf0e10cSrcweir if (-1 == nIndex)
517cdf0e10cSrcweir throw IllegalArgumentException();
518cdf0e10cSrcweir
519cdf0e10cSrcweir aMacros[nIndex] = new SvxMacro(rMacro.GetMacName(), rMacro.GetLibName(),
520cdf0e10cSrcweir rMacro.GetScriptType() );
521cdf0e10cSrcweir }
522cdf0e10cSrcweir
523cdf0e10cSrcweir
getByName(SvxMacro & rMacro,const sal_uInt16 nEvent)524cdf0e10cSrcweir void SvDetachedEventDescriptor::getByName(
525cdf0e10cSrcweir SvxMacro& rMacro,
526cdf0e10cSrcweir const sal_uInt16 nEvent )
527cdf0e10cSrcweir throw(
528cdf0e10cSrcweir NoSuchElementException,
529cdf0e10cSrcweir WrappedTargetException,
530cdf0e10cSrcweir RuntimeException)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir sal_Int16 nIndex = getIndex(nEvent);
533cdf0e10cSrcweir if (-1 == nIndex )
534cdf0e10cSrcweir throw NoSuchElementException();
535cdf0e10cSrcweir
536cdf0e10cSrcweir if( aMacros[nIndex] )
537cdf0e10cSrcweir rMacro = (*aMacros[nIndex]);
538cdf0e10cSrcweir }
539cdf0e10cSrcweir
hasByName(const sal_uInt16 nEvent) const540cdf0e10cSrcweir sal_Bool SvDetachedEventDescriptor::hasByName(
541cdf0e10cSrcweir const sal_uInt16 nEvent ) const /// item ID of event
542cdf0e10cSrcweir throw(IllegalArgumentException)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir sal_Int16 nIndex = getIndex(nEvent);
545cdf0e10cSrcweir if (-1 == nIndex)
546cdf0e10cSrcweir throw IllegalArgumentException();
547cdf0e10cSrcweir
548cdf0e10cSrcweir return (NULL == aMacros[nIndex]) ? sal_False : aMacros[nIndex]->HasMacro();
549cdf0e10cSrcweir }
550cdf0e10cSrcweir
551cdf0e10cSrcweir
552cdf0e10cSrcweir //
553cdf0e10cSrcweir // SvMacroTableEventDescriptor
554cdf0e10cSrcweir //
555cdf0e10cSrcweir
SvMacroTableEventDescriptor(const SvEventDescription * pSupportedMacroItems)556cdf0e10cSrcweir SvMacroTableEventDescriptor::SvMacroTableEventDescriptor(const SvEventDescription* pSupportedMacroItems) :
557cdf0e10cSrcweir SvDetachedEventDescriptor(pSupportedMacroItems)
558cdf0e10cSrcweir {
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
SvMacroTableEventDescriptor(const SvxMacroTableDtor & rMacroTable,const SvEventDescription * pSupportedMacroItems)561cdf0e10cSrcweir SvMacroTableEventDescriptor::SvMacroTableEventDescriptor(
562cdf0e10cSrcweir const SvxMacroTableDtor& rMacroTable,
563cdf0e10cSrcweir const SvEventDescription* pSupportedMacroItems) :
564cdf0e10cSrcweir SvDetachedEventDescriptor(pSupportedMacroItems)
565cdf0e10cSrcweir {
566cdf0e10cSrcweir copyMacrosFromTable(rMacroTable);
567cdf0e10cSrcweir }
568cdf0e10cSrcweir
~SvMacroTableEventDescriptor()569cdf0e10cSrcweir SvMacroTableEventDescriptor::~SvMacroTableEventDescriptor()
570cdf0e10cSrcweir {
571cdf0e10cSrcweir }
572cdf0e10cSrcweir
copyMacrosFromTable(const SvxMacroTableDtor & rMacroTable)573cdf0e10cSrcweir void SvMacroTableEventDescriptor::copyMacrosFromTable(
574cdf0e10cSrcweir const SvxMacroTableDtor& rMacroTable)
575cdf0e10cSrcweir {
576cdf0e10cSrcweir for(sal_Int16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; i++)
577cdf0e10cSrcweir {
578cdf0e10cSrcweir const sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
579cdf0e10cSrcweir const SvxMacro* pMacro = rMacroTable.Get(nEvent);
580cdf0e10cSrcweir if (NULL != pMacro)
581cdf0e10cSrcweir replaceByName(nEvent, *pMacro);
582cdf0e10cSrcweir }
583cdf0e10cSrcweir
584cdf0e10cSrcweir }
585cdf0e10cSrcweir
copyMacrosIntoTable(SvxMacroTableDtor & rMacroTable)586cdf0e10cSrcweir void SvMacroTableEventDescriptor::copyMacrosIntoTable(
587cdf0e10cSrcweir SvxMacroTableDtor& rMacroTable)
588cdf0e10cSrcweir {
589cdf0e10cSrcweir for(sal_Int16 i = 0; mpSupportedMacroItems[i].mnEvent != 0; i++)
590cdf0e10cSrcweir {
591cdf0e10cSrcweir const sal_uInt16 nEvent = mpSupportedMacroItems[i].mnEvent;
592cdf0e10cSrcweir if (hasByName(nEvent))
593cdf0e10cSrcweir {
594cdf0e10cSrcweir SvxMacro* pMacro = new SvxMacro(sEmpty, sEmpty);
595cdf0e10cSrcweir getByName(*pMacro, nEvent);
596cdf0e10cSrcweir rMacroTable.Insert(nEvent, pMacro);
597cdf0e10cSrcweir }
598cdf0e10cSrcweir }
599cdf0e10cSrcweir }
600cdf0e10cSrcweir
601cdf0e10cSrcweir
602cdf0e10cSrcweir
603