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