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