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