Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sal/macros.h>
21 : #include <comphelper/processfactory.hxx>
22 : #include <comphelper/uno3.hxx>
23 : #include <comphelper/proparrhlp.hxx>
24 : #include <comphelper/propertycontainer.hxx>
25 :
26 : #include <ooo/vba/XVBAToOOEventDescGen.hpp>
27 :
28 : #include <com/sun/star/beans/XPropertySet.hpp>
29 : #include <com/sun/star/beans/Introspection.hpp>
30 : #include <com/sun/star/beans/PropertyAttribute.hpp>
31 :
32 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
33 : #include <com/sun/star/lang/XServiceName.hpp>
34 : #include <com/sun/star/lang/XServiceInfo.hpp>
35 : #include <com/sun/star/lang/XInitialization.hpp>
36 :
37 : #include <com/sun/star/util/XCloseListener.hpp>
38 : #include <com/sun/star/util/XCloseBroadcaster.hpp>
39 :
40 : #include <com/sun/star/frame/XModel.hpp>
41 :
42 : #include <com/sun/star/script/XLibraryContainer.hpp>
43 : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
44 : #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
45 : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
46 :
47 : #include <com/sun/star/container/XNamed.hpp>
48 :
49 : #include <com/sun/star/drawing/XControlShape.hpp>
50 :
51 : #include <com/sun/star/awt/XControl.hpp>
52 : #include <com/sun/star/awt/XDialog.hpp>
53 : #include <com/sun/star/awt/KeyEvent.hpp>
54 : #include <com/sun/star/awt/MouseEvent.hpp>
55 : #include <com/sun/star/awt/XFixedText.hpp>
56 : #include <com/sun/star/awt/XTextComponent.hpp>
57 : #include <com/sun/star/awt/XComboBox.hpp>
58 : #include <com/sun/star/awt/XRadioButton.hpp>
59 : #include <com/sun/star/awt/XListBox.hpp>
60 :
61 : #include <ooo/vba/msforms/ReturnInteger.hpp>
62 :
63 : #include <sfx2/objsh.hxx>
64 : #include <basic/sbstar.hxx>
65 : #include <basic/basmgr.hxx>
66 : #include <basic/sbmeth.hxx>
67 : #include <basic/sbmod.hxx>
68 : #include <basic/sbx.hxx>
69 : #include <filter/msfilter/msvbahelper.hxx>
70 :
71 : // for debug
72 : #include <comphelper/anytostring.hxx>
73 :
74 :
75 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
76 : #include <com/sun/star/script/XScriptListener.hpp>
77 : #include <cppuhelper/implbase1.hxx>
78 : #include <cppuhelper/implbase3.hxx>
79 : #include <cppuhelper/implbase2.hxx>
80 : #include <comphelper/evtmethodhelper.hxx>
81 :
82 : #include <set>
83 : #include <list>
84 : #include <boost/unordered_map.hpp>
85 : #define ASYNC 0
86 :
87 : // primitive support for asynchronous handling of
88 : // events from controls ( all event will be processed asynchronously
89 : // in the application thread )
90 : #if ASYNC
91 : #include <vcl/svapp.hxx>
92 : #endif
93 :
94 : using namespace ::com::sun::star;
95 : using namespace ::com::sun::star::script;
96 : using namespace ::com::sun::star::uno;
97 : using namespace ::ooo::vba;
98 :
99 : #define MAP_CHAR_LEN(x) ::rtl::OUString(x)
100 : #define GET_TYPE(x) ::getCppuType((uno::Reference< x > *)0);
101 :
102 : // Some constants
103 0 : const static rtl::OUString DELIM("::");
104 0 : const static sal_Int32 DELIMLEN = DELIM.getLength();
105 :
106 0 : bool isKeyEventOk( awt::KeyEvent& evt, const Sequence< Any >& params )
107 : {
108 0 : if ( !( params.getLength() > 0 ) ||
109 0 : !( params[ 0 ] >>= evt ) )
110 0 : return false;
111 0 : return true;
112 : }
113 :
114 0 : bool isMouseEventOk( awt::MouseEvent& evt, const Sequence< Any >& params )
115 : {
116 0 : if ( !( params.getLength() > 0 ) ||
117 0 : !( params[ 0 ] >>= evt ) )
118 0 : return false;
119 0 : return true;
120 : }
121 :
122 0 : Sequence< Any > ooMouseEvtToVBADblClick( const Sequence< Any >& params )
123 : {
124 0 : Sequence< Any > translatedParams;
125 0 : awt::MouseEvent evt;
126 :
127 0 : if ( !( isMouseEventOk(evt, params)) ||
128 : (evt.ClickCount != 2) )
129 0 : return Sequence< Any >();
130 : // give back orig params, this will signal that the event is good
131 0 : return params;
132 : }
133 :
134 0 : Sequence< Any > ooMouseEvtToVBAMouseEvt( const Sequence< Any >& params )
135 : {
136 0 : Sequence< Any > translatedParams;
137 0 : awt::MouseEvent evt;
138 :
139 0 : if ( !isMouseEventOk(evt, params) )
140 0 : return Sequence< Any >();
141 :
142 0 : translatedParams.realloc(4);
143 :
144 : // Buttons
145 0 : translatedParams[ 0 ] <<= evt.Buttons;
146 : // Shift
147 0 : translatedParams[ 1 ] <<= evt.Modifiers;
148 : // X
149 0 : translatedParams[ 2 ] <<= evt.X;
150 : // Y
151 0 : translatedParams[ 3 ] <<= evt.Y;
152 0 : return translatedParams;
153 : }
154 :
155 0 : Sequence< Any > ooKeyPressedToVBAKeyPressed( const Sequence< Any >& params )
156 : {
157 0 : Sequence< Any > translatedParams;
158 0 : awt::KeyEvent evt;
159 :
160 0 : if ( !isKeyEventOk( evt, params ) )
161 0 : return Sequence< Any >();
162 :
163 0 : translatedParams.realloc(1);
164 :
165 0 : msforms::ReturnInteger keyCode;
166 0 : keyCode.Value = evt.KeyCode;
167 0 : translatedParams[0] <<= keyCode;
168 0 : return translatedParams;
169 : }
170 :
171 0 : Sequence< Any > ooKeyPressedToVBAKeyUpDown( const Sequence< Any >& params )
172 : {
173 0 : Sequence< Any > translatedParams;
174 0 : awt::KeyEvent evt;
175 :
176 0 : if ( !isKeyEventOk( evt, params ) )
177 0 : return Sequence< Any >();
178 :
179 0 : translatedParams.realloc(2);
180 :
181 0 : msforms::ReturnInteger keyCode;
182 0 : sal_Int8 shift = sal::static_int_cast<sal_Int8>( evt.Modifiers );
183 :
184 : // #TODO check whether values from OOO conform to values generated from vba
185 0 : keyCode.Value = evt.KeyCode;
186 0 : translatedParams[0] <<= keyCode;
187 0 : translatedParams[1] <<= shift;
188 0 : return translatedParams;
189 : }
190 :
191 : typedef Sequence< Any > (*Translator)(const Sequence< Any >&);
192 :
193 : //expand the "TranslateInfo" struct to support more kinds of events
194 0 : struct TranslateInfo
195 : {
196 : rtl::OUString sVBAName; //vba event name
197 : Translator toVBA; //the method to convert OO event parameters to VBA event parameters
198 : bool (*ApproveRule)(const ScriptEvent& evt, void* pPara); //this method is used to determine which types of controls should execute the event
199 : void *pPara; //Parameters for the above approve method
200 : };
201 :
202 :
203 : typedef boost::unordered_map< rtl::OUString,
204 : std::list< TranslateInfo >,
205 : ::rtl::OUStringHash,
206 : ::std::equal_to< ::rtl::OUString > > EventInfoHash;
207 :
208 :
209 0 : struct TranslatePropMap
210 : {
211 : rtl::OUString sEventInfo; //OO event name
212 : TranslateInfo aTransInfo;
213 : };
214 :
215 : bool ApproveAll(const ScriptEvent& evt, void* pPara); //allow all types of controls to execute the event
216 : bool ApproveType(const ScriptEvent& evt, void* pPara); //certain types of controls should execute the event, those types are given by pPara
217 : bool DenyType(const ScriptEvent& evt, void* pPara); //certain types of controls should not execute the event, those types are given by pPara
218 : bool DenyMouseDrag(const ScriptEvent& evt, void* pPara); //used for VBA MouseMove event when "Shift" key is pressed
219 :
220 : struct TypeList
221 : {
222 : uno::Type* pTypeList;
223 : int nListLength;
224 : };
225 :
226 0 : Type typeXFixedText = GET_TYPE(awt::XFixedText);
227 0 : Type typeXTextComponent = GET_TYPE(awt::XTextComponent);
228 0 : Type typeXComboBox = GET_TYPE(awt::XComboBox);
229 0 : Type typeXRadioButton = GET_TYPE(awt::XRadioButton);
230 0 : Type typeXListBox = GET_TYPE(awt::XListBox);
231 :
232 :
233 : TypeList fixedTextList = {&typeXFixedText, 1};
234 : TypeList textCompList = {&typeXTextComponent, 1};
235 : TypeList radioButtonList = {&typeXRadioButton, 1};
236 : TypeList comboBoxList = {&typeXComboBox, 1};
237 : TypeList listBoxList = {&typeXListBox, 1};
238 :
239 : //this array stores the OO event to VBA event translation info
240 0 : static TranslatePropMap aTranslatePropMap_Impl[] =
241 : {
242 : { MAP_CHAR_LEN("actionPerformed"), { MAP_CHAR_LEN("_Change"), NULL, DenyType, (void*)(&radioButtonList) } },
243 : // actionPerformed ooo event
244 : { MAP_CHAR_LEN("actionPerformed"), { MAP_CHAR_LEN("_Click"), NULL, ApproveAll, NULL } },
245 : { MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Change"), NULL, ApproveType, (void*)(&radioButtonList) } },
246 : // itemStateChanged ooo event
247 : { MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Click"), NULL, ApproveType, (void*)(&comboBoxList) } },
248 :
249 : { MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Click"), NULL, ApproveType, (void*)(&listBoxList) } },
250 : // changed ooo event
251 : { MAP_CHAR_LEN("changed"), { MAP_CHAR_LEN("_Change"), NULL, ApproveAll, NULL } },
252 :
253 : // focusGained ooo event
254 : { MAP_CHAR_LEN("focusGained"), { MAP_CHAR_LEN("_GotFocus"), NULL, ApproveAll, NULL } },
255 :
256 : // focusLost ooo event
257 : { MAP_CHAR_LEN("focusLost"), { MAP_CHAR_LEN("_LostFocus"), NULL, ApproveAll, NULL } },
258 : { MAP_CHAR_LEN("focusLost"), { MAP_CHAR_LEN("_Exit"), NULL, ApproveType, (void*)(&textCompList) } }, // support VBA TextBox_Exit event
259 :
260 : // adjustmentValueChanged ooo event
261 : { MAP_CHAR_LEN("adjustmentValueChanged"), { MAP_CHAR_LEN("_Scroll"), NULL, ApproveAll, NULL } },
262 : { MAP_CHAR_LEN("adjustmentValueChanged"), { MAP_CHAR_LEN("_Change"), NULL, ApproveAll, NULL } },
263 :
264 : // textChanged ooo event
265 : { MAP_CHAR_LEN("textChanged"), { MAP_CHAR_LEN("_Change"), NULL, ApproveAll, NULL } },
266 :
267 : // keyReleased ooo event
268 : { MAP_CHAR_LEN("keyReleased"), { MAP_CHAR_LEN("_KeyUp"), ooKeyPressedToVBAKeyUpDown, ApproveAll, NULL } },
269 :
270 : // mouseReleased ooo event
271 : { MAP_CHAR_LEN("mouseReleased"), { MAP_CHAR_LEN("_Click"), ooMouseEvtToVBAMouseEvt, ApproveType, (void*)(&fixedTextList) } },
272 : { MAP_CHAR_LEN("mouseReleased"), { MAP_CHAR_LEN("_MouseUp"), ooMouseEvtToVBAMouseEvt, ApproveAll, NULL } },
273 :
274 : // mousePressed ooo event
275 : { MAP_CHAR_LEN("mousePressed"), { MAP_CHAR_LEN("_MouseDown"), ooMouseEvtToVBAMouseEvt, ApproveAll, NULL } },
276 : { MAP_CHAR_LEN("mousePressed"), { MAP_CHAR_LEN("_DblClick"), ooMouseEvtToVBADblClick, ApproveAll, NULL } },
277 :
278 : // mouseMoved ooo event
279 : { MAP_CHAR_LEN("mouseMoved"), { MAP_CHAR_LEN("_MouseMove"), ooMouseEvtToVBAMouseEvt, ApproveAll, NULL } },
280 : { MAP_CHAR_LEN("mouseDragged"), { MAP_CHAR_LEN("_MouseMove"), ooMouseEvtToVBAMouseEvt, DenyMouseDrag, NULL } },
281 :
282 : // keyPressed ooo event
283 : { MAP_CHAR_LEN("keyPressed"), { MAP_CHAR_LEN("_KeyDown"), ooKeyPressedToVBAKeyUpDown, ApproveAll, NULL } },
284 : { MAP_CHAR_LEN("keyPressed"), { MAP_CHAR_LEN("_KeyPress"), ooKeyPressedToVBAKeyPressed, ApproveAll, NULL } }
285 0 : };
286 :
287 0 : EventInfoHash& getEventTransInfo()
288 : {
289 : static bool initialised = false;
290 0 : static EventInfoHash eventTransInfo;
291 0 : if ( !initialised )
292 : {
293 0 : rtl::OUString sEventInfo = MAP_CHAR_LEN("");
294 0 : TranslatePropMap* pTransProp = aTranslatePropMap_Impl;
295 0 : int nCount = sizeof(aTranslatePropMap_Impl) / sizeof(aTranslatePropMap_Impl[0]);
296 :
297 0 : int i = 0;
298 0 : while (i < nCount)
299 : {
300 0 : sEventInfo = pTransProp->sEventInfo;
301 0 : std::list< TranslateInfo > infoList;
302 0 : do
303 : {
304 0 : infoList.push_back( pTransProp->aTransInfo );
305 0 : pTransProp++;
306 0 : i++;
307 0 : }while(i < nCount && sEventInfo == pTransProp->sEventInfo);
308 0 : eventTransInfo[sEventInfo] = infoList;
309 0 : }
310 0 : initialised = true;
311 : }
312 0 : return eventTransInfo;
313 : }
314 :
315 :
316 : // Helper class
317 :
318 0 : class ScriptEventHelper
319 : {
320 : public:
321 : ScriptEventHelper( const Reference< XInterface >& xControl );
322 : Sequence< ScriptEventDescriptor > createEvents( const rtl::OUString& sCodeName );
323 : Sequence< rtl::OUString > getEventListeners();
324 : private:
325 : Reference< XComponentContext > m_xCtx;
326 : Reference< XInterface > m_xControl;
327 : };
328 :
329 : bool
330 0 : eventMethodToDescriptor( const ::rtl::OUString& rEventMethod, ScriptEventDescriptor& evtDesc, const ::rtl::OUString& sCodeName )
331 : {
332 : // format of ControlListener is TypeName::methodname e.g.
333 : // "com.sun.star.awt.XActionListener::actionPerformed" or
334 : // "XActionListener::actionPerformed
335 :
336 0 : ::rtl::OUString sMethodName;
337 0 : ::rtl::OUString sTypeName;
338 0 : sal_Int32 nDelimPos = rEventMethod.indexOf( DELIM );
339 0 : if ( nDelimPos == -1 )
340 : {
341 0 : return false;
342 : }
343 0 : sMethodName = rEventMethod.copy( nDelimPos + DELIMLEN );
344 0 : sTypeName = rEventMethod.copy( 0, nDelimPos );
345 :
346 0 : EventInfoHash& infos = getEventTransInfo();
347 :
348 : // Only create an ScriptEventDescriptor for an event we can translate
349 : // or emulate
350 0 : if ( !sMethodName.isEmpty()
351 0 : && !sTypeName.isEmpty()
352 0 : && ( infos.find( sMethodName ) != infos.end() ) )
353 : {
354 : // just fill in CodeName, when the event fires the other
355 : // info is gathered from the event source to determine what
356 : // event handler we try to call
357 0 : evtDesc.ScriptCode = sCodeName;
358 0 : evtDesc.ListenerType = sTypeName;
359 0 : evtDesc.EventMethod = sMethodName;
360 :
361 : // set this it VBAInterop, ensures that it doesn't
362 : // get persisted or shown in property editors
363 : evtDesc.ScriptType = rtl::OUString(
364 0 : "VBAInterop" );
365 0 : return true;
366 : }
367 0 : return false;
368 :
369 : }
370 :
371 0 : ScriptEventHelper::ScriptEventHelper( const Reference< XInterface >& xControl ):
372 : m_xCtx( comphelper::getProcessComponentContext() ),
373 0 : m_xControl( xControl )
374 0 : {}
375 :
376 : Sequence< rtl::OUString >
377 0 : ScriptEventHelper::getEventListeners()
378 : {
379 0 : std::list< rtl::OUString > eventMethods;
380 :
381 0 : Reference< beans::XIntrospection > xIntrospection = beans::Introspection::create( m_xCtx );
382 :
383 : Reference< beans::XIntrospectionAccess > xIntrospectionAccess =
384 0 : xIntrospection->inspect( makeAny( m_xControl ) );
385 : Sequence< Type > aControlListeners =
386 0 : xIntrospectionAccess->getSupportedListeners();
387 0 : sal_Int32 nLength = aControlListeners.getLength();
388 0 : for ( sal_Int32 i = 0; i< nLength; ++i )
389 : {
390 0 : Type& listType = aControlListeners[ i ];
391 0 : rtl::OUString sFullTypeName = listType.getTypeName();
392 : Sequence< ::rtl::OUString > sMeths =
393 0 : comphelper::getEventMethodsForType( listType );
394 0 : sal_Int32 sMethLen = sMeths.getLength();
395 0 : for ( sal_Int32 j=0 ; j < sMethLen; ++j )
396 : {
397 0 : rtl::OUString sEventMethod = sFullTypeName;
398 0 : sEventMethod += DELIM;
399 0 : sEventMethod += sMeths[ j ];
400 0 : eventMethods.push_back( sEventMethod );
401 0 : }
402 0 : }
403 :
404 0 : Sequence< rtl::OUString > sEventMethodNames( eventMethods.size() );
405 0 : std::list< rtl::OUString >::const_iterator it = eventMethods.begin();
406 0 : rtl::OUString* pDest = sEventMethodNames.getArray();
407 :
408 0 : for ( ; it != eventMethods.end(); ++it, ++pDest )
409 0 : *pDest = *it;
410 :
411 0 : return sEventMethodNames;
412 : }
413 :
414 : Sequence< ScriptEventDescriptor >
415 0 : ScriptEventHelper::createEvents( const rtl::OUString& sCodeName )
416 : {
417 0 : Sequence< rtl::OUString > aControlListeners = getEventListeners();
418 0 : rtl::OUString* pSrc = aControlListeners.getArray();
419 0 : sal_Int32 nLength = aControlListeners.getLength();
420 :
421 0 : Sequence< ScriptEventDescriptor > aDest( nLength );
422 0 : sal_Int32 nEvts = 0;
423 0 : for ( sal_Int32 i = 0; i< nLength; ++i, ++pSrc )
424 : {
425 : // from getListeners eventName is of form
426 : // "com.sun.star.awt.XActionListener::actionPerformed"
427 : // we need to strip "com.sun.star.awt." from that for form
428 : // controls
429 0 : ScriptEventDescriptor evtDesc;
430 0 : if ( eventMethodToDescriptor( *pSrc, evtDesc, sCodeName ) )
431 : {
432 0 : sal_Int32 dIndex = nEvts;
433 0 : ++nEvts;
434 0 : if ( nEvts > aDest.getLength() )
435 0 : aDest.realloc( nEvts );// should never happen
436 0 : aDest[ dIndex ] = evtDesc;
437 : }
438 0 : }
439 0 : aDest.realloc( nEvts );
440 :
441 0 : return aDest;
442 : }
443 :
444 :
445 : typedef ::cppu::WeakImplHelper1< container::XNameContainer > NameContainer_BASE;
446 :
447 0 : class ReadOnlyEventsNameContainer : public NameContainer_BASE
448 : {
449 : public:
450 : ReadOnlyEventsNameContainer( const Sequence< rtl::OUString >& eventMethods, const rtl::OUString& sCodeName );
451 : // XNameContainer
452 :
453 0 : virtual void SAL_CALL insertByName( const ::rtl::OUString&, const Any& ) throw (lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, RuntimeException)
454 : {
455 0 : throw RuntimeException( rtl::OUString("ReadOnly container"), Reference< XInterface >() );
456 :
457 : }
458 0 : virtual void SAL_CALL removeByName( const ::rtl::OUString& ) throw (::com::sun::star::container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
459 : {
460 0 : throw RuntimeException( rtl::OUString("ReadOnly container"), Reference< XInterface >() );
461 : }
462 :
463 : // XNameReplace
464 0 : virtual void SAL_CALL replaceByName( const ::rtl::OUString&, const Any& ) throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
465 : {
466 0 : throw RuntimeException( rtl::OUString("ReadOnly container"), Reference< XInterface >() );
467 :
468 : }
469 :
470 : // XNameAccess
471 : virtual Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, RuntimeException);
472 : virtual Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (RuntimeException);
473 : virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (RuntimeException);
474 :
475 : // XElementAccess
476 0 : virtual Type SAL_CALL getElementType( ) throw (RuntimeException)
477 0 : { return getCppuType(static_cast< const rtl::OUString * >(0) ); }
478 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (RuntimeException)
479 0 : { return ( ( m_hEvents.size() > 0 ? sal_True : sal_False ) ); }
480 : private:
481 :
482 : typedef boost::unordered_map< rtl::OUString, Any, ::rtl::OUStringHash,
483 : ::std::equal_to< ::rtl::OUString > > EventSupplierHash;
484 :
485 : EventSupplierHash m_hEvents;
486 : };
487 :
488 0 : ReadOnlyEventsNameContainer::ReadOnlyEventsNameContainer( const Sequence< rtl::OUString >& eventMethods, const rtl::OUString& sCodeName )
489 : {
490 0 : const rtl::OUString* pSrc = eventMethods.getConstArray();
491 0 : sal_Int32 nLen = eventMethods.getLength();
492 0 : for ( sal_Int32 index = 0; index < nLen; ++index, ++pSrc )
493 : {
494 0 : Any aDesc;
495 0 : ScriptEventDescriptor evtDesc;
496 0 : if ( eventMethodToDescriptor( *pSrc, evtDesc, sCodeName ) )
497 : {
498 0 : aDesc <<= evtDesc;
499 0 : m_hEvents[ *pSrc ] = aDesc;
500 : }
501 0 : }
502 0 : }
503 :
504 : Any SAL_CALL
505 0 : ReadOnlyEventsNameContainer::getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, RuntimeException){
506 0 : EventSupplierHash::const_iterator it = m_hEvents.find( aName );
507 0 : if ( it == m_hEvents.end() )
508 0 : throw container::NoSuchElementException();
509 0 : return it->second;
510 : }
511 :
512 : Sequence< ::rtl::OUString > SAL_CALL
513 0 : ReadOnlyEventsNameContainer::getElementNames( ) throw (RuntimeException)
514 : {
515 0 : Sequence< ::rtl::OUString > names(m_hEvents.size());
516 0 : rtl::OUString* pDest = names.getArray();
517 0 : EventSupplierHash::const_iterator it = m_hEvents.begin();
518 0 : EventSupplierHash::const_iterator it_end = m_hEvents.end();
519 0 : for ( sal_Int32 index = 0; it != it_end; ++index, ++pDest, ++it )
520 0 : *pDest = it->first;
521 0 : return names;
522 : }
523 :
524 : sal_Bool SAL_CALL
525 0 : ReadOnlyEventsNameContainer::hasByName( const ::rtl::OUString& aName ) throw (RuntimeException)
526 : {
527 0 : EventSupplierHash::const_iterator it = m_hEvents.find( aName );
528 0 : if ( it == m_hEvents.end() )
529 0 : return sal_False;
530 0 : return sal_True;
531 : }
532 :
533 : typedef ::cppu::WeakImplHelper1< XScriptEventsSupplier > EventsSupplier_BASE;
534 :
535 0 : class ReadOnlyEventsSupplier : public EventsSupplier_BASE
536 : {
537 : public:
538 0 : ReadOnlyEventsSupplier( const Sequence< ::rtl::OUString >& eventMethods, const rtl::OUString& sCodeName )
539 0 : { m_xNameContainer = new ReadOnlyEventsNameContainer( eventMethods, sCodeName ); }
540 :
541 : // XScriptEventSupplier
542 0 : virtual Reference< container::XNameContainer > SAL_CALL getEvents( ) throw (RuntimeException){ return m_xNameContainer; }
543 : private:
544 : Reference< container::XNameContainer > m_xNameContainer;
545 : };
546 :
547 : typedef ::cppu::WeakImplHelper3< XScriptListener, util::XCloseListener, lang::XInitialization > EventListener_BASE;
548 :
549 : #define EVENTLSTNR_PROPERTY_ID_MODEL 1
550 : #define EVENTLSTNR_PROPERTY_MODEL ::rtl::OUString( "Model" )
551 :
552 0 : class EventListener : public EventListener_BASE
553 : ,public ::comphelper::OMutexAndBroadcastHelper
554 : ,public ::comphelper::OPropertyContainer
555 : ,public ::comphelper::OPropertyArrayUsageHelper< EventListener >
556 :
557 : {
558 :
559 : public:
560 : EventListener( const Reference< XComponentContext >& rxContext );
561 : // XEventListener
562 : virtual void SAL_CALL disposing(const lang::EventObject& Source) throw( RuntimeException );
563 : using cppu::OPropertySetHelper::disposing;
564 :
565 : // XScriptListener
566 : virtual void SAL_CALL firing(const ScriptEvent& evt) throw(RuntimeException);
567 : virtual Any SAL_CALL approveFiring(const ScriptEvent& evt) throw(reflection::InvocationTargetException, RuntimeException);
568 : // XCloseListener
569 : virtual void SAL_CALL queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException);
570 : virtual void SAL_CALL notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException);
571 : // XPropertySet
572 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException);
573 : // XInitialization
574 : virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
575 : // XInterface
576 : DECLARE_XINTERFACE()
577 :
578 : // XTypeProvider
579 : DECLARE_XTYPEPROVIDER()
580 0 : virtual void SAL_CALL setFastPropertyValue( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
581 : {
582 0 : if ( nHandle == EVENTLSTNR_PROPERTY_ID_MODEL )
583 : {
584 0 : uno::Reference< frame::XModel > xModel( rValue, uno::UNO_QUERY );
585 0 : if( xModel != m_xModel)
586 : {
587 : // Remove the listener from the old XCloseBroadcaster.
588 0 : uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xModel, uno::UNO_QUERY );
589 0 : if (xCloseBroadcaster.is())
590 : {
591 0 : xCloseBroadcaster->removeCloseListener( this );
592 : }
593 : // Add the listener into the new XCloseBroadcaster.
594 0 : xCloseBroadcaster = uno::Reference< util::XCloseBroadcaster >( xModel, uno::UNO_QUERY );
595 0 : if (xCloseBroadcaster.is())
596 : {
597 0 : xCloseBroadcaster->addCloseListener( this );
598 0 : }
599 0 : }
600 : }
601 0 : OPropertyContainer::setFastPropertyValue( nHandle, rValue );
602 0 : if ( nHandle == EVENTLSTNR_PROPERTY_ID_MODEL )
603 0 : setShellFromModel();
604 0 : }
605 :
606 : protected:
607 : // OPropertySetHelper
608 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper( );
609 :
610 : // OPropertyArrayUsageHelper
611 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
612 :
613 : private:
614 : #if ASYNC
615 : DECL_LINK( OnAsyncScriptEvent, ScriptEvent* );
616 : #endif
617 : void setShellFromModel();
618 : void firing_Impl( const ScriptEvent& evt, Any *pSyncRet=NULL ) throw( RuntimeException );
619 :
620 : Reference< XComponentContext > m_xContext;
621 : Reference< frame::XModel > m_xModel;
622 : bool m_bDocClosed;
623 : SfxObjectShell* mpShell;
624 : rtl::OUString msProject;
625 : };
626 :
627 0 : EventListener::EventListener( const Reference< XComponentContext >& rxContext ) :
628 0 : OPropertyContainer(GetBroadcastHelper()), m_xContext( rxContext ), m_bDocClosed(false), mpShell( 0 )
629 : {
630 : registerProperty( EVENTLSTNR_PROPERTY_MODEL, EVENTLSTNR_PROPERTY_ID_MODEL,
631 0 : beans::PropertyAttribute::TRANSIENT, &m_xModel, ::getCppuType( &m_xModel ) );
632 0 : msProject = rtl::OUString("Standard");
633 0 : }
634 :
635 : void
636 0 : EventListener::setShellFromModel()
637 : {
638 : // reset mpShell
639 0 : mpShell = 0;
640 0 : SfxObjectShell* pShell = SfxObjectShell::GetFirst();
641 0 : while ( m_xModel.is() && pShell )
642 : {
643 0 : if ( pShell->GetModel() == m_xModel )
644 : {
645 0 : mpShell = pShell;
646 0 : break;
647 : }
648 0 : pShell = SfxObjectShell::GetNext( *pShell );
649 : }
650 : // set ProjectName from model
651 : try
652 : {
653 0 : uno::Reference< beans::XPropertySet > xProps( m_xModel, UNO_QUERY_THROW );
654 0 : uno::Reference< script::vba::XVBACompatibility > xVBAMode( xProps->getPropertyValue( rtl::OUString( "BasicLibraries" ) ), uno::UNO_QUERY_THROW );
655 0 : msProject = xVBAMode->getProjectName();
656 : }
657 0 : catch ( uno::Exception& ) {}
658 0 : }
659 :
660 : //XEventListener
661 : void
662 0 : EventListener::disposing(const lang::EventObject&) throw( RuntimeException )
663 : {
664 0 : }
665 :
666 : //XScriptListener
667 :
668 : void SAL_CALL
669 0 : EventListener::firing(const ScriptEvent& evt) throw(RuntimeException)
670 : {
671 : #if ASYNC
672 : // needs some logic to check if the event handler is oneway or not
673 : // if not oneway then firing_Impl otherwise... as below
674 : acquire();
675 : Application::PostUserEvent( LINK( this, EventListener, OnAsyncScriptEvent ), new ScriptEvent( evt ) );
676 : #else
677 0 : firing_Impl( evt );
678 : #endif
679 0 : }
680 :
681 : #if ASYNC
682 : IMPL_LINK( EventListener, OnAsyncScriptEvent, ScriptEvent*, _pEvent )
683 : {
684 : if ( !_pEvent )
685 : return 1L;
686 :
687 : {
688 : // #FIXME if we enable ASYNC we probably need something like
689 : // below
690 : //::osl::ClearableMutexGuard aGuard( m_aMutex );
691 :
692 : //if ( !impl_isDisposed_nothrow() )
693 : // impl_doFireScriptEvent_nothrow( aGuard, *_pEvent, NULL );
694 : firing_Impl( *_pEvent, NULL );
695 : }
696 :
697 : delete _pEvent;
698 : // we acquired ourself immediately before posting the event
699 : release();
700 : return 0L;
701 : }
702 : #endif
703 :
704 : Any SAL_CALL
705 0 : EventListener::approveFiring(const ScriptEvent& evt) throw(reflection::InvocationTargetException, RuntimeException)
706 : {
707 0 : Any ret;
708 0 : firing_Impl( evt, &ret );
709 0 : return ret;
710 : }
711 :
712 : // XCloseListener
713 : void SAL_CALL
714 0 : EventListener::queryClosing( const lang::EventObject& /*Source*/, ::sal_Bool /*GetsOwnership*/ ) throw (util::CloseVetoException, uno::RuntimeException)
715 : {
716 : //Nothing to do
717 0 : }
718 :
719 : void SAL_CALL
720 0 : EventListener::notifyClosing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException)
721 : {
722 0 : m_bDocClosed = true;
723 0 : uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xModel, uno::UNO_QUERY );
724 0 : if (xCloseBroadcaster.is())
725 : {
726 0 : xCloseBroadcaster->removeCloseListener( this );
727 0 : }
728 0 : }
729 :
730 : // XInitialization
731 : void SAL_CALL
732 0 : EventListener::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
733 : {
734 0 : if ( aArguments.getLength() == 1 )
735 0 : aArguments[0] >>= m_xModel;
736 : OSL_TRACE("EventListener::initialize() args %d m_xModel %d", aArguments.getLength(), m_xModel.is() );
737 0 : }
738 :
739 : // XInterface
740 :
741 0 : IMPLEMENT_FORWARD_XINTERFACE2( EventListener, EventListener_BASE, OPropertyContainer )
742 :
743 : // XTypeProvider
744 :
745 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( EventListener, EventListener_BASE, OPropertyContainer )
746 :
747 : // OPropertySetHelper
748 :
749 : ::cppu::IPropertyArrayHelper&
750 0 : EventListener::getInfoHelper( )
751 : {
752 0 : return *getArrayHelper();
753 : }
754 :
755 : // OPropertyArrayUsageHelper
756 :
757 : ::cppu::IPropertyArrayHelper*
758 0 : EventListener::createArrayHelper( ) const
759 : {
760 0 : Sequence< beans::Property > aProps;
761 0 : describeProperties( aProps );
762 0 : return new ::cppu::OPropertyArrayHelper( aProps );
763 : }
764 :
765 : // XPropertySet
766 : Reference< beans::XPropertySetInfo >
767 0 : EventListener::getPropertySetInfo( ) throw (RuntimeException)
768 : {
769 0 : Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
770 0 : return xInfo;
771 : }
772 :
773 :
774 : //decide if the control should execute the event
775 0 : bool ApproveAll(const ScriptEvent&, void* )
776 : {
777 0 : return true;
778 : }
779 :
780 : //for the given control type in evt.Arguments[0], look for if it appears in the type list in pPara
781 0 : bool FindControl(const ScriptEvent& evt, void* pPara)
782 : {
783 0 : lang::EventObject aEvent;
784 0 : evt.Arguments[ 0 ] >>= aEvent;
785 0 : uno::Reference< uno::XInterface > xInterface( aEvent.Source, uno::UNO_QUERY );
786 :
787 0 : TypeList* pTypeListInfo = static_cast<TypeList*>(pPara);
788 0 : Type* pType = pTypeListInfo->pTypeList;
789 0 : int nLen = pTypeListInfo->nListLength;
790 :
791 0 : for (int i = 0; i < nLen; i++)
792 : {
793 0 : if ( xInterface->queryInterface( *pType ).hasValue() )
794 : {
795 0 : return true;
796 : }
797 0 : pType++;
798 : }
799 :
800 0 : return false;
801 : }
802 :
803 : //if the the given control type in evt.Arguments[0] appears in the type list in pPara, then approve the execution
804 0 : bool ApproveType(const ScriptEvent& evt, void* pPara)
805 : {
806 0 : return FindControl(evt, pPara);
807 : }
808 :
809 : //if the the given control type in evt.Arguments[0] appears in the type list in pPara, then deny the execution
810 0 : bool DenyType(const ScriptEvent& evt, void* pPara)
811 : {
812 0 : return !FindControl(evt, pPara);
813 : }
814 :
815 : //when mouse is moving, either the mouse button is pressed or some key is pressed can trigger the OO mouseDragged event,
816 : //the former should be denyed, and the latter allowed, only by doing so can the VBA MouseMove event when the "Shift" key is
817 : //pressed can be correctly triggered
818 0 : bool DenyMouseDrag(const ScriptEvent& evt, void* )
819 : {
820 0 : awt::MouseEvent aEvent;
821 0 : evt.Arguments[ 0 ] >>= aEvent;
822 0 : if (aEvent.Buttons == 0 )
823 : {
824 0 : return true;
825 : }
826 : else
827 : {
828 0 : return false;
829 0 : }
830 : }
831 :
832 :
833 : // EventListener
834 :
835 : void
836 0 : EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) throw(RuntimeException)
837 : {
838 : OSL_TRACE("EventListener::firing_Impl( FAKE VBA_EVENTS )");
839 : static const ::rtl::OUString vbaInterOp =
840 0 : ::rtl::OUString("VBAInterop");
841 :
842 : // let default handlers deal with non vba stuff
843 0 : if ( !evt.ScriptType.equals( vbaInterOp ) )
844 : return;
845 0 : lang::EventObject aEvent;
846 0 : evt.Arguments[ 0 ] >>= aEvent;
847 : OSL_TRACE("evt.MethodName is %s", rtl::OUStringToOString( evt.MethodName, RTL_TEXTENCODING_UTF8 ).getStr() );
848 : OSL_TRACE("Argument[0] is %s", rtl::OUStringToOString( comphelper::anyToString( evt.Arguments[0] ), RTL_TEXTENCODING_UTF8 ).getStr() );
849 : OSL_TRACE("Getting Control");
850 0 : rtl::OUString sName = rtl::OUString( "UserForm" );
851 : OSL_TRACE("Getting Name");
852 :
853 0 : uno::Reference< awt::XDialog > xDlg( aEvent.Source, uno::UNO_QUERY );
854 0 : if ( !xDlg.is() )
855 : {
856 : OSL_TRACE("Getting Control");
857 : // evt.Source is
858 : // a) Dialog
859 : // b) xShapeControl ( from api (sheet control) )
860 : // c) eventmanager ( I guess )
861 : // d) vba control ( from api also )
862 0 : uno::Reference< drawing::XControlShape > xCntrlShape( evt.Source, uno::UNO_QUERY );
863 0 : uno::Reference< awt::XControl > xControl( aEvent.Source, uno::UNO_QUERY );
864 0 : if ( xCntrlShape.is() )
865 : {
866 : // for sheet controls ( that fire from the api ) we don't
867 : // have the real control ( thats only available from the view )
868 : // api code creates just a control instance that is transferred
869 : // via aEvent.Arguments[ 0 ] that control though has no
870 : // info like name etc.
871 : OSL_TRACE("Got control shape");
872 0 : uno::Reference< container::XNamed > xName( xCntrlShape->getControl(), uno::UNO_QUERY_THROW );
873 : OSL_TRACE("Got xnamed ");
874 0 : sName = xName->getName();
875 : }
876 : else
877 : {
878 : // Userform control ( fired from the api or from event manager )
879 0 : uno::Reference< beans::XPropertySet > xProps;
880 : OSL_TRACE("Getting properties");
881 0 : xProps.set( xControl->getModel(), uno::UNO_QUERY_THROW );
882 0 : xProps->getPropertyValue( rtl::OUString( "Name" ) ) >>= sName;
883 0 : }
884 : }
885 : //dumpEvent( evt );
886 0 : EventInfoHash& infos = getEventTransInfo();
887 0 : EventInfoHash::const_iterator eventInfo_it = infos.find( evt.MethodName );
888 0 : EventInfoHash::const_iterator it_end = infos.end();
889 0 : if ( eventInfo_it == it_end )
890 : {
891 : OSL_TRACE("Bogus event for %s",
892 : rtl::OUStringToOString( evt.ScriptType, RTL_TEXTENCODING_UTF8 ).getStr() );
893 : return;
894 : }
895 :
896 0 : uno::Reference< script::provider::XScriptProviderSupplier > xSPS( m_xModel, uno::UNO_QUERY );
897 0 : uno::Reference< script::provider::XScriptProvider > xScriptProvider;
898 0 : if ( xSPS.is() )
899 : {
900 0 : xScriptProvider = xSPS->getScriptProvider();
901 : }
902 0 : if ( xScriptProvider.is() && mpShell )
903 : {
904 : std::list< TranslateInfo >::const_iterator txInfo =
905 0 : eventInfo_it->second.begin();
906 0 : std::list< TranslateInfo >::const_iterator txInfo_end = eventInfo_it->second.end();
907 :
908 0 : BasicManager* pBasicManager = mpShell->GetBasicManager();
909 0 : rtl::OUString sProject;
910 0 : rtl::OUString sScriptCode( evt.ScriptCode );
911 : // dialogs pass their own library, presence of Dot determines that
912 0 : if ( sScriptCode.indexOf( '.' ) == -1 )
913 : {
914 : //'Project' is a better default but I want to force failures
915 : //rtl::OUString sMacroLoc("Project");
916 0 : sProject = "Standard";
917 :
918 0 : if (!pBasicManager->GetName().isEmpty())
919 : {
920 0 : sProject = pBasicManager->GetName();
921 : }
922 : }
923 : else
924 : {
925 0 : sal_Int32 nIndex = sScriptCode.indexOf( '.' );
926 0 : sProject = sScriptCode.copy( 0, nIndex );
927 0 : sScriptCode = sScriptCode.copy( nIndex + 1 );
928 : }
929 0 : rtl::OUString sMacroLoc = sProject;
930 0 : sMacroLoc = sMacroLoc.concat( rtl::OUString(".") );
931 0 : sMacroLoc = sMacroLoc.concat( sScriptCode ).concat( rtl::OUString(".") );
932 :
933 : OSL_TRACE("sMacroLoc is %s", rtl::OUStringToOString( sMacroLoc, RTL_TEXTENCODING_UTF8 ).getStr() );
934 0 : for ( ; txInfo != txInfo_end; ++txInfo )
935 : {
936 : // If the document is closed, we should not execute macro.
937 0 : if (m_bDocClosed)
938 : {
939 : break;
940 : }
941 :
942 0 : rtl::OUString sTemp = sName.concat( (*txInfo).sVBAName );
943 : // see if we have a match for the handlerextension
944 : // where ScriptCode is methodname_handlerextension
945 0 : rtl::OUString sToResolve = sMacroLoc.concat( sTemp );
946 :
947 : OSL_TRACE("*** trying to invoke %s ",
948 : rtl::OUStringToOString( sToResolve, RTL_TEXTENCODING_UTF8 ).getStr() );
949 0 : ooo::vba::MacroResolvedInfo aMacroResolvedInfo = ooo::vba::resolveVBAMacro( mpShell, sToResolve );
950 0 : if ( aMacroResolvedInfo.mbFound )
951 : {
952 :
953 0 : if (! txInfo->ApproveRule(evt, txInfo->pPara) )
954 : {
955 0 : continue;
956 : }
957 :
958 : // !! translate arguments & emulate events where necessary
959 0 : Sequence< Any > aArguments;
960 0 : if ( (*txInfo).toVBA )
961 : {
962 0 : aArguments = (*txInfo).toVBA( evt.Arguments );
963 : }
964 : else
965 : {
966 0 : aArguments = evt.Arguments;
967 : }
968 0 : if ( aArguments.getLength() )
969 : {
970 : // call basic event handlers for event
971 :
972 : // create script url
973 0 : rtl::OUString url = aMacroResolvedInfo.msResolvedMacro;
974 :
975 : OSL_TRACE("resolved script = %s",
976 : rtl::OUStringToOString( url,
977 : RTL_TEXTENCODING_UTF8 ).getStr() );
978 : try
979 : {
980 0 : uno::Any aDummyCaller = uno::makeAny( rtl::OUString("Error") );
981 0 : if ( pRet )
982 : {
983 0 : ooo::vba::executeMacro( mpShell, url, aArguments, *pRet, aDummyCaller );
984 : }
985 : else
986 : {
987 0 : uno::Any aRet;
988 0 : ooo::vba::executeMacro( mpShell, url, aArguments, aRet, aDummyCaller );
989 0 : }
990 : }
991 0 : catch ( uno::Exception& e )
992 : {
993 : OSL_TRACE("event script raised %s", rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
994 0 : }
995 0 : }
996 : }
997 0 : }
998 0 : }
999 : }
1000 :
1001 : typedef ::cppu::WeakImplHelper1< XVBAToOOEventDescGen > VBAToOOEventDescGen_BASE;
1002 :
1003 :
1004 0 : class VBAToOOEventDescGen : public VBAToOOEventDescGen_BASE
1005 : {
1006 : public:
1007 : VBAToOOEventDescGen( const Reference< XComponentContext >& rxContext );
1008 :
1009 : // XVBAToOOEventDescGen
1010 : virtual Sequence< ScriptEventDescriptor > SAL_CALL getEventDescriptions( const Reference< XInterface >& control, const rtl::OUString& sCodeName ) throw (RuntimeException);
1011 : virtual Reference< XScriptEventsSupplier > SAL_CALL getEventSupplier( const Reference< XInterface >& xControl, const rtl::OUString& sCodeName ) throw (::com::sun::star::uno::RuntimeException);
1012 : private:
1013 : Reference< XComponentContext > m_xContext;
1014 :
1015 : };
1016 :
1017 0 : VBAToOOEventDescGen::VBAToOOEventDescGen( const Reference< XComponentContext >& rxContext ):m_xContext( rxContext ) {}
1018 :
1019 : Sequence< ScriptEventDescriptor > SAL_CALL
1020 0 : VBAToOOEventDescGen::getEventDescriptions( const Reference< XInterface >& xControl, const rtl::OUString& sCodeName ) throw (RuntimeException)
1021 : {
1022 0 : ScriptEventHelper evntHelper( xControl );
1023 0 : return evntHelper.createEvents( sCodeName );
1024 : }
1025 :
1026 : Reference< XScriptEventsSupplier > SAL_CALL
1027 0 : VBAToOOEventDescGen::getEventSupplier( const Reference< XInterface >& xControl, const rtl::OUString& sCodeName ) throw (::com::sun::star::uno::RuntimeException)
1028 : {
1029 0 : ScriptEventHelper evntHelper( xControl );
1030 : Reference< XScriptEventsSupplier > xSupplier =
1031 : new ReadOnlyEventsSupplier(
1032 0 : evntHelper.getEventListeners(), sCodeName ) ;
1033 0 : return xSupplier;
1034 : }
1035 :
1036 : // Component related
1037 :
1038 : namespace evtlstner
1039 : {
1040 0 : ::rtl::OUString SAL_CALL getImplementationName()
1041 : {
1042 : static ::rtl::OUString* pImplName = 0;
1043 0 : if ( !pImplName )
1044 : {
1045 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1046 0 : if ( !pImplName )
1047 : {
1048 0 : static ::rtl::OUString aImplName( "ooo.vba.EventListener" );
1049 0 : pImplName = &aImplName;
1050 0 : }
1051 : }
1052 0 : return *pImplName;
1053 : }
1054 :
1055 0 : uno::Reference< XInterface > SAL_CALL create(
1056 : Reference< XComponentContext > const & xContext )
1057 : SAL_THROW(())
1058 : {
1059 0 : return static_cast< lang::XTypeProvider * >( new EventListener( xContext ) );
1060 : }
1061 :
1062 0 : Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
1063 : {
1064 0 : const ::rtl::OUString strName( ::evtlstner::getImplementationName() );
1065 0 : return Sequence< ::rtl::OUString >( &strName, 1 );
1066 : }
1067 : }
1068 : namespace ooevtdescgen
1069 : {
1070 0 : ::rtl::OUString SAL_CALL getImplementationName()
1071 : {
1072 : static ::rtl::OUString* pImplName = 0;
1073 0 : if ( !pImplName )
1074 : {
1075 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1076 0 : if ( !pImplName )
1077 : {
1078 0 : static ::rtl::OUString aImplName( "ooo.vba.VBAToOOEventDesc" );
1079 0 : pImplName = &aImplName;
1080 0 : }
1081 : }
1082 0 : return *pImplName;
1083 : }
1084 :
1085 0 : uno::Reference< XInterface > SAL_CALL create(
1086 : Reference< XComponentContext > const & xContext )
1087 : SAL_THROW(())
1088 : {
1089 0 : return static_cast< lang::XTypeProvider * >( new VBAToOOEventDescGen( xContext ) );
1090 : }
1091 :
1092 0 : Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
1093 : {
1094 0 : const ::rtl::OUString strName( ::ooevtdescgen::getImplementationName() );
1095 0 : return Sequence< ::rtl::OUString >( &strName, 1 );
1096 : }
1097 0 : }
1098 :
1099 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|