1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "eventhandler.hxx" 28cdf0e10cSrcweir #include "propctrlr.hrc" 29cdf0e10cSrcweir #include "formbrowsertools.hxx" 30cdf0e10cSrcweir #include "formresid.hrc" 31cdf0e10cSrcweir #include "formstrings.hxx" 32cdf0e10cSrcweir #include "handlerhelper.hxx" 33cdf0e10cSrcweir #include "modulepcr.hxx" 34cdf0e10cSrcweir #include "pcrcommon.hxx" 35cdf0e10cSrcweir #include "pcrstrings.hxx" 36cdf0e10cSrcweir #include "propertycontrolextender.hxx" 37cdf0e10cSrcweir 38cdf0e10cSrcweir /** === begin UNO includes === **/ 39cdf0e10cSrcweir #include <com/sun/star/awt/XTabControllerModel.hpp> 40cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 41cdf0e10cSrcweir #include <com/sun/star/beans/UnknownPropertyException.hpp> 42cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospection.hpp> 43cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospectionAccess.hpp> 44cdf0e10cSrcweir #include <com/sun/star/container/NoSuchElementException.hpp> 45cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 46cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 47cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 48cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp> 49cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp> 50cdf0e10cSrcweir #include <com/sun/star/form/XForm.hpp> 51cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormController.hpp> 52cdf0e10cSrcweir #include <com/sun/star/inspection/PropertyControlType.hpp> 53cdf0e10cSrcweir #include <com/sun/star/lang/NullPointerException.hpp> 54cdf0e10cSrcweir #include <com/sun/star/script/XEventAttacherManager.hpp> 55cdf0e10cSrcweir #include <com/sun/star/script/XScriptEventsSupplier.hpp> 56cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 57cdf0e10cSrcweir #include <com/sun/star/uri/UriReferenceFactory.hpp> 58cdf0e10cSrcweir #include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp> 59cdf0e10cSrcweir /** === end UNO includes === **/ 60cdf0e10cSrcweir 61cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 62cdf0e10cSrcweir #include <comphelper/evtmethodhelper.hxx> 63cdf0e10cSrcweir #include <comphelper/types.hxx> 64cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 65cdf0e10cSrcweir #include <rtl/ref.hxx> 66cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 67cdf0e10cSrcweir #include <sfx2/app.hxx> 68cdf0e10cSrcweir #include <svl/eitem.hxx> 69cdf0e10cSrcweir #include <svl/itemset.hxx> 70cdf0e10cSrcweir #include <svx/svxdlg.hxx> 71cdf0e10cSrcweir #include <svx/svxids.hrc> 72cdf0e10cSrcweir #include <tools/diagnose_ex.h> 73cdf0e10cSrcweir #include <vcl/msgbox.hxx> 74cdf0e10cSrcweir 75cdf0e10cSrcweir #include <map> 76cdf0e10cSrcweir #include <algorithm> 77cdf0e10cSrcweir 78cdf0e10cSrcweir //------------------------------------------------------------------------ 79cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_EventHandler() 80cdf0e10cSrcweir { 81cdf0e10cSrcweir ::pcr::OAutoRegistration< ::pcr::EventHandler > aAutoRegistration; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir //........................................................................ 85cdf0e10cSrcweir namespace pcr 86cdf0e10cSrcweir { 87cdf0e10cSrcweir //........................................................................ 88cdf0e10cSrcweir 89cdf0e10cSrcweir /** === begin UNO using === **/ 90cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 91cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 92cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 93cdf0e10cSrcweir using ::com::sun::star::uno::Any; 94cdf0e10cSrcweir using ::com::sun::star::uno::TypeClass_STRING; 95cdf0e10cSrcweir using ::com::sun::star::uno::Type; 96cdf0e10cSrcweir using ::com::sun::star::beans::XPropertyChangeListener; 97cdf0e10cSrcweir using ::com::sun::star::beans::Property; 98cdf0e10cSrcweir using ::com::sun::star::beans::PropertyState; 99cdf0e10cSrcweir using ::com::sun::star::beans::PropertyState_DIRECT_VALUE; 100cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 101cdf0e10cSrcweir using ::com::sun::star::script::ScriptEventDescriptor; 102cdf0e10cSrcweir using ::com::sun::star::script::XScriptEventsSupplier; 103cdf0e10cSrcweir using ::com::sun::star::lang::NullPointerException; 104cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 105cdf0e10cSrcweir using ::com::sun::star::container::XChild; 106cdf0e10cSrcweir using ::com::sun::star::container::XIndexAccess; 107cdf0e10cSrcweir using ::com::sun::star::script::XEventAttacherManager; 108cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 109cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 110cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 111cdf0e10cSrcweir using ::com::sun::star::beans::XIntrospection; 112cdf0e10cSrcweir using ::com::sun::star::beans::XIntrospectionAccess; 113cdf0e10cSrcweir using ::com::sun::star::container::XNameContainer; 114cdf0e10cSrcweir using ::com::sun::star::awt::XTabControllerModel; 115cdf0e10cSrcweir using ::com::sun::star::form::XForm; 116cdf0e10cSrcweir using ::com::sun::star::form::runtime::XFormController; 117cdf0e10cSrcweir using ::com::sun::star::beans::UnknownPropertyException; 118cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 119cdf0e10cSrcweir using ::com::sun::star::container::NoSuchElementException; 120cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySetInfo; 121cdf0e10cSrcweir using ::com::sun::star::container::XNameReplace; 122cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException; 123cdf0e10cSrcweir using ::com::sun::star::lang::WrappedTargetException; 124cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 125cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue; 126cdf0e10cSrcweir using ::com::sun::star::inspection::LineDescriptor; 127cdf0e10cSrcweir using ::com::sun::star::inspection::XPropertyControlFactory; 128cdf0e10cSrcweir using ::com::sun::star::inspection::InteractiveSelectionResult; 129cdf0e10cSrcweir using ::com::sun::star::inspection::InteractiveSelectionResult_Cancelled; 130cdf0e10cSrcweir using ::com::sun::star::inspection::InteractiveSelectionResult_Success; 131cdf0e10cSrcweir using ::com::sun::star::inspection::XObjectInspectorUI; 132cdf0e10cSrcweir using ::com::sun::star::util::XModifiable; 133cdf0e10cSrcweir using ::com::sun::star::beans::PropertyChangeEvent; 134cdf0e10cSrcweir using ::com::sun::star::frame::XFrame; 135cdf0e10cSrcweir using ::com::sun::star::frame::XModel; 136cdf0e10cSrcweir using ::com::sun::star::frame::XController; 137cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 138cdf0e10cSrcweir using com::sun::star::uri::UriReferenceFactory; 139cdf0e10cSrcweir using com::sun::star::uri::XUriReferenceFactory; 140cdf0e10cSrcweir using com::sun::star::uri::XVndSunStarScriptUrlReference; 141cdf0e10cSrcweir using ::com::sun::star::lang::XEventListener; 142cdf0e10cSrcweir /** === end UNO using === **/ 143cdf0e10cSrcweir namespace PropertyControlType = ::com::sun::star::inspection::PropertyControlType; 144cdf0e10cSrcweir namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute; 145cdf0e10cSrcweir namespace FormComponentType = ::com::sun::star::form::FormComponentType; 146cdf0e10cSrcweir 147cdf0e10cSrcweir //==================================================================== 148cdf0e10cSrcweir //= EventDescription 149cdf0e10cSrcweir //==================================================================== 150cdf0e10cSrcweir EventDescription::EventDescription( EventId _nId, const sal_Char* _pListenerNamespaceAscii, const sal_Char* _pListenerClassAsciiName, 151cdf0e10cSrcweir const sal_Char* _pListenerMethodAsciiName, sal_uInt16 _nDisplayNameResId, const rtl::OString& _sHelpId, const rtl::OString& _sUniqueBrowseId ) 152cdf0e10cSrcweir :sDisplayName( String( PcrRes( _nDisplayNameResId ) ) ) 153cdf0e10cSrcweir ,sListenerMethodName( ::rtl::OUString::createFromAscii( _pListenerMethodAsciiName ) ) 154cdf0e10cSrcweir ,sHelpId( _sHelpId ) 155cdf0e10cSrcweir ,sUniqueBrowseId( _sUniqueBrowseId ) 156cdf0e10cSrcweir ,nId( _nId ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir ::rtl::OUStringBuffer aQualifiedListenerClass; 159cdf0e10cSrcweir aQualifiedListenerClass.appendAscii( "com.sun.star." ); 160cdf0e10cSrcweir aQualifiedListenerClass.appendAscii( _pListenerNamespaceAscii ); 161cdf0e10cSrcweir aQualifiedListenerClass.appendAscii( "." ); 162cdf0e10cSrcweir aQualifiedListenerClass.appendAscii( _pListenerClassAsciiName ); 163cdf0e10cSrcweir sListenerClassName = aQualifiedListenerClass.makeStringAndClear(); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir //======================================================================== 167cdf0e10cSrcweir //= helper 168cdf0e10cSrcweir //======================================================================== 169cdf0e10cSrcweir namespace 170cdf0e10cSrcweir { 171cdf0e10cSrcweir //.................................................................... 172cdf0e10cSrcweir #define DESCRIBE_EVENT( asciinamespace, asciilistener, asciimethod, id_postfix ) \ 173cdf0e10cSrcweir s_aKnownEvents.insert( EventMap::value_type( \ 174cdf0e10cSrcweir ::rtl::OUString::createFromAscii( asciimethod ), \ 175cdf0e10cSrcweir EventDescription( ++nEventId, asciinamespace, asciilistener, asciimethod, RID_STR_EVT_##id_postfix, HID_EVT_##id_postfix, UID_BRWEVT_##id_postfix ) ) ) 176cdf0e10cSrcweir 177cdf0e10cSrcweir //.................................................................... 178cdf0e10cSrcweir bool lcl_getEventDescriptionForMethod( const ::rtl::OUString& _rMethodName, EventDescription& _out_rDescription ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir static EventMap s_aKnownEvents; 181cdf0e10cSrcweir if ( s_aKnownEvents.empty() ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 184cdf0e10cSrcweir if ( s_aKnownEvents.empty() ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir static sal_Int32 nEventId = 0; 187cdf0e10cSrcweir 188cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XApproveActionListener", "approveAction", APPROVEACTIONPERFORMED ); 189cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XActionListener", "actionPerformed", ACTIONPERFORMED ); 190cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XChangeListener", "changed", CHANGED ); 191cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XTextListener", "textChanged", TEXTCHANGED ); 192cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XItemListener", "itemStateChanged", ITEMSTATECHANGED ); 193cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XFocusListener", "focusGained", FOCUSGAINED ); 194cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XFocusListener", "focusLost", FOCUSLOST ); 195cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XKeyListener", "keyPressed", KEYTYPED ); 196cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XKeyListener", "keyReleased", KEYUP ); 197cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XMouseListener", "mouseEntered", MOUSEENTERED ); 198cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XMouseMotionListener", "mouseDragged", MOUSEDRAGGED ); 199cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XMouseMotionListener", "mouseMoved", MOUSEMOVED ); 200cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XMouseListener", "mousePressed", MOUSEPRESSED ); 201cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XMouseListener", "mouseReleased", MOUSERELEASED ); 202cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XMouseListener", "mouseExited", MOUSEEXITED ); 203cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XResetListener", "approveReset", APPROVERESETTED ); 204cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XResetListener", "resetted", RESETTED ); 205cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XSubmitListener", "approveSubmit", SUBMITTED ); 206cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XUpdateListener", "approveUpdate", BEFOREUPDATE ); 207cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XUpdateListener", "updated", AFTERUPDATE ); 208cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XLoadListener", "loaded", LOADED ); 209cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XLoadListener", "reloading", RELOADING ); 210cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XLoadListener", "reloaded", RELOADED ); 211cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XLoadListener", "unloading", UNLOADING ); 212cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XLoadListener", "unloaded", UNLOADED ); 213cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XConfirmDeleteListener", "confirmDelete", CONFIRMDELETE ); 214cdf0e10cSrcweir DESCRIBE_EVENT( "sdb", "XRowSetApproveListener", "approveRowChange", APPROVEROWCHANGE ); 215cdf0e10cSrcweir DESCRIBE_EVENT( "sdbc", "XRowSetListener", "rowChanged", ROWCHANGE ); 216cdf0e10cSrcweir DESCRIBE_EVENT( "sdb", "XRowSetApproveListener", "approveCursorMove", POSITIONING ); 217cdf0e10cSrcweir DESCRIBE_EVENT( "sdbc", "XRowSetListener", "cursorMoved", POSITIONED ); 218cdf0e10cSrcweir DESCRIBE_EVENT( "form", "XDatabaseParameterListener", "approveParameter", APPROVEPARAMETER ); 219cdf0e10cSrcweir DESCRIBE_EVENT( "sdb", "XSQLErrorListener", "errorOccured", ERROROCCURED ); 220cdf0e10cSrcweir DESCRIBE_EVENT( "awt", "XAdjustmentListener", "adjustmentValueChanged", ADJUSTMENTVALUECHANGED ); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir EventMap::const_iterator pos = s_aKnownEvents.find( _rMethodName ); 225cdf0e10cSrcweir if ( pos == s_aKnownEvents.end() ) 226cdf0e10cSrcweir return false; 227cdf0e10cSrcweir 228cdf0e10cSrcweir _out_rDescription = pos->second; 229cdf0e10cSrcweir return true; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir //.................................................................... 233cdf0e10cSrcweir ::rtl::OUString lcl_getEventPropertyName( const ::rtl::OUString& _rListenerClassName, const ::rtl::OUString& _rMethodName ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir ::rtl::OUStringBuffer aPropertyName; 236cdf0e10cSrcweir aPropertyName.append( _rListenerClassName ); 237cdf0e10cSrcweir aPropertyName.append( (sal_Unicode)';' ); 238cdf0e10cSrcweir aPropertyName.append( _rMethodName.getStr() ); 239cdf0e10cSrcweir return aPropertyName.makeStringAndClear(); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir //................................................................ 243cdf0e10cSrcweir ScriptEventDescriptor lcl_getAssignedScriptEvent( const EventDescription& _rEvent, const Sequence< ScriptEventDescriptor >& _rAllAssignedMacros ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir ScriptEventDescriptor aScriptEvent; 246cdf0e10cSrcweir // for the case there is actually no event assigned, initialize at least ListenerType and MethodName, 247cdf0e10cSrcweir // so this ScriptEventDescriptor properly describes the given event 248cdf0e10cSrcweir aScriptEvent.ListenerType = _rEvent.sListenerClassName; 249cdf0e10cSrcweir aScriptEvent.EventMethod = _rEvent.sListenerMethodName; 250cdf0e10cSrcweir 251cdf0e10cSrcweir const ScriptEventDescriptor* pAssignedEvent = _rAllAssignedMacros.getConstArray(); 252cdf0e10cSrcweir sal_Int32 assignedEventCount( _rAllAssignedMacros.getLength() ); 253cdf0e10cSrcweir for ( sal_Int32 assignedEvent = 0; assignedEvent < assignedEventCount; ++assignedEvent, ++pAssignedEvent ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir if ( ( pAssignedEvent->ListenerType != _rEvent.sListenerClassName ) 256cdf0e10cSrcweir || ( pAssignedEvent->EventMethod != _rEvent.sListenerMethodName ) 257cdf0e10cSrcweir ) 258cdf0e10cSrcweir continue; 259cdf0e10cSrcweir 260cdf0e10cSrcweir if ( ( pAssignedEvent->ScriptCode.getLength() == 0 ) 261cdf0e10cSrcweir || ( pAssignedEvent->ScriptType.getLength() == 0 ) 262cdf0e10cSrcweir ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir DBG_ERROR( "lcl_getAssignedScriptEvent: me thinks this should not happen!" ); 265cdf0e10cSrcweir continue; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir aScriptEvent = *pAssignedEvent; 269cdf0e10cSrcweir 270cdf0e10cSrcweir if ( !aScriptEvent.ScriptType.equalsAscii( "StarBasic" ) ) 271cdf0e10cSrcweir continue; 272cdf0e10cSrcweir 273cdf0e10cSrcweir // this is an old-style macro specification: 274cdf0e10cSrcweir // [document|application]:Library.Module.Function 275cdf0e10cSrcweir // we need to translate this to the new-style macro specification 276cdf0e10cSrcweir // vnd.sun.star.script:Library.Module.Function?language=Basic&location=[document|application] 277cdf0e10cSrcweir 278cdf0e10cSrcweir sal_Int32 nPrefixLen = aScriptEvent.ScriptCode.indexOf( ':' ); 279cdf0e10cSrcweir OSL_ENSURE( nPrefixLen > 0, "lcl_getAssignedScriptEvent: illegal location!" ); 280cdf0e10cSrcweir ::rtl::OUString sLocation = aScriptEvent.ScriptCode.copy( 0, nPrefixLen ); 281cdf0e10cSrcweir ::rtl::OUString sMacroPath = aScriptEvent.ScriptCode.copy( nPrefixLen + 1 ); 282cdf0e10cSrcweir 283cdf0e10cSrcweir ::rtl::OUStringBuffer aNewStyleSpec; 284cdf0e10cSrcweir aNewStyleSpec.appendAscii( "vnd.sun.star.script:" ); 285cdf0e10cSrcweir aNewStyleSpec.append ( sMacroPath ); 286cdf0e10cSrcweir aNewStyleSpec.appendAscii( "?language=Basic&location=" ); 287cdf0e10cSrcweir aNewStyleSpec.append ( sLocation ); 288cdf0e10cSrcweir 289cdf0e10cSrcweir aScriptEvent.ScriptCode = aNewStyleSpec.makeStringAndClear(); 290cdf0e10cSrcweir 291cdf0e10cSrcweir // also, this new-style spec requires the script code to be "Script" instead of "StarBasic" 292cdf0e10cSrcweir aScriptEvent.ScriptType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Script" ) ); 293cdf0e10cSrcweir } 294cdf0e10cSrcweir return aScriptEvent; 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir //................................................................ 298cdf0e10cSrcweir ::rtl::OUString lcl_getQualifiedKnownListenerName( const ScriptEventDescriptor& _rFormComponentEventDescriptor ) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir EventDescription aKnownEvent; 301cdf0e10cSrcweir if ( lcl_getEventDescriptionForMethod( _rFormComponentEventDescriptor.EventMethod, aKnownEvent ) ) 302cdf0e10cSrcweir return aKnownEvent.sListenerClassName; 303cdf0e10cSrcweir DBG_ERROR( "lcl_getQualifiedKnownListenerName: unknown method name!" ); 304cdf0e10cSrcweir // somebody assigned an script to a form component event which we don't know 305cdf0e10cSrcweir // Speaking strictly, this is not really an error - it is possible to do 306cdf0e10cSrcweir // this programmatically -, but it should rarely happen, since it's not possible 307cdf0e10cSrcweir // via UI 308cdf0e10cSrcweir return _rFormComponentEventDescriptor.ListenerType; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir //................................................................ 312cdf0e10cSrcweir typedef ::std::set< Type, TypeLessByName > TypeBag; 313cdf0e10cSrcweir 314cdf0e10cSrcweir //................................................................ 315cdf0e10cSrcweir void lcl_addListenerTypesFor_throw( const Reference< XInterface >& _rxComponent, 316cdf0e10cSrcweir const Reference< XIntrospection >& _rxIntrospection, TypeBag& _out_rTypes ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir if ( !_rxComponent.is() ) 319cdf0e10cSrcweir return; 320cdf0e10cSrcweir OSL_PRECOND( _rxIntrospection.is(), "lcl_addListenerTypesFor_throw: this will crash!" ); 321cdf0e10cSrcweir 322cdf0e10cSrcweir Reference< XIntrospectionAccess > xIntrospectionAccess( 323cdf0e10cSrcweir _rxIntrospection->inspect( makeAny( _rxComponent ) ), UNO_QUERY_THROW ); 324cdf0e10cSrcweir 325cdf0e10cSrcweir Sequence< Type > aListeners( xIntrospectionAccess->getSupportedListeners() ); 326cdf0e10cSrcweir 327cdf0e10cSrcweir ::std::copy( aListeners.getConstArray(), aListeners.getConstArray() + aListeners.getLength(), 328cdf0e10cSrcweir ::std::insert_iterator< TypeBag >( _out_rTypes, _out_rTypes.begin() ) ); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir //................................................................ 332cdf0e10cSrcweir bool operator ==( const ScriptEventDescriptor _lhs, const ScriptEventDescriptor _rhs ) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir return ( ( _lhs.ListenerType == _rhs.ListenerType ) 335cdf0e10cSrcweir && ( _lhs.EventMethod == _rhs.EventMethod ) 336cdf0e10cSrcweir && ( _lhs.AddListenerParam == _rhs.AddListenerParam ) 337cdf0e10cSrcweir && ( _lhs.ScriptType == _rhs.ScriptType ) 338cdf0e10cSrcweir && ( _lhs.ScriptCode == _rhs.ScriptCode ) 339cdf0e10cSrcweir ); 340cdf0e10cSrcweir } 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir //==================================================================== 344cdf0e10cSrcweir //= EventHandler 345cdf0e10cSrcweir //==================================================================== 346cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1 < ::com::sun::star::container::XNameReplace 347cdf0e10cSrcweir > EventHolder_Base; 348cdf0e10cSrcweir /** a UNO component holding assigned event descriptions, for use with a SvxMacroAssignDlg 349cdf0e10cSrcweir */ 350cdf0e10cSrcweir class EventHolder : public EventHolder_Base 351cdf0e10cSrcweir { 352cdf0e10cSrcweir private: 353cdf0e10cSrcweir typedef ::std::hash_map< ::rtl::OUString, ScriptEventDescriptor, ::rtl::OUStringHash > EventMap; 354cdf0e10cSrcweir typedef ::std::map< EventId, EventMap::iterator > EventMapIndexAccess; 355cdf0e10cSrcweir 356cdf0e10cSrcweir EventMap m_aEventNameAccess; 357cdf0e10cSrcweir EventMapIndexAccess m_aEventIndexAccess; 358cdf0e10cSrcweir 359cdf0e10cSrcweir public: 360cdf0e10cSrcweir EventHolder( ); 361cdf0e10cSrcweir 362cdf0e10cSrcweir void addEvent( EventId _nId, const ::rtl::OUString& _rEventName, const ScriptEventDescriptor& _rScriptEvent ); 363cdf0e10cSrcweir 364cdf0e10cSrcweir /** effectively the same as getByName, but instead of converting the ScriptEventDescriptor to the weird 365cdf0e10cSrcweir format used by the macro assignment dialog, it is returned directly 366cdf0e10cSrcweir */ 367cdf0e10cSrcweir ScriptEventDescriptor getNormalizedDescriptorByName( const ::rtl::OUString& _rEventName ) const; 368cdf0e10cSrcweir 369cdf0e10cSrcweir // XNameReplace 370cdf0e10cSrcweir virtual void SAL_CALL replaceByName( const ::rtl::OUString& _rName, const Any& aElement ) throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException); 371cdf0e10cSrcweir virtual Any SAL_CALL getByName( const ::rtl::OUString& _rName ) throw (NoSuchElementException, WrappedTargetException, RuntimeException); 372cdf0e10cSrcweir virtual Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (RuntimeException); 373cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& _rName ) throw (RuntimeException); 374cdf0e10cSrcweir virtual Type SAL_CALL getElementType( ) throw (RuntimeException); 375cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements( ) throw (RuntimeException); 376cdf0e10cSrcweir 377cdf0e10cSrcweir protected: 378cdf0e10cSrcweir ~EventHolder( ); 379cdf0e10cSrcweir 380cdf0e10cSrcweir private: 381cdf0e10cSrcweir ScriptEventDescriptor impl_getDescriptor_throw( const ::rtl::OUString& _rEventName ) const; 382cdf0e10cSrcweir }; 383cdf0e10cSrcweir 384cdf0e10cSrcweir DBG_NAME( EventHolder ) 385cdf0e10cSrcweir //------------------------------------------------------------------------ 386cdf0e10cSrcweir EventHolder::EventHolder() 387cdf0e10cSrcweir { 388cdf0e10cSrcweir DBG_CTOR( EventHolder, NULL ); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir //------------------------------------------------------------------------ 392cdf0e10cSrcweir EventHolder::~EventHolder() 393cdf0e10cSrcweir { 394cdf0e10cSrcweir m_aEventNameAccess.clear(); 395cdf0e10cSrcweir m_aEventIndexAccess.clear(); 396cdf0e10cSrcweir DBG_DTOR( EventHolder, NULL ); 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir //------------------------------------------------------------------------ 400cdf0e10cSrcweir void EventHolder::addEvent( EventId _nId, const ::rtl::OUString& _rEventName, const ScriptEventDescriptor& _rScriptEvent ) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir ::std::pair< EventMap::iterator, bool > insertionResult = 403cdf0e10cSrcweir m_aEventNameAccess.insert( EventMap::value_type( _rEventName, _rScriptEvent ) ); 404cdf0e10cSrcweir OSL_ENSURE( insertionResult.second, "EventHolder::addEvent: there already was a MacroURL for this event!" ); 405cdf0e10cSrcweir m_aEventIndexAccess[ _nId ] = insertionResult.first; 406cdf0e10cSrcweir } 407cdf0e10cSrcweir 408cdf0e10cSrcweir //------------------------------------------------------------------------ 409cdf0e10cSrcweir ScriptEventDescriptor EventHolder::getNormalizedDescriptorByName( const ::rtl::OUString& _rEventName ) const 410cdf0e10cSrcweir { 411cdf0e10cSrcweir return impl_getDescriptor_throw( _rEventName ); 412cdf0e10cSrcweir } 413cdf0e10cSrcweir 414cdf0e10cSrcweir //------------------------------------------------------------------------ 415cdf0e10cSrcweir ScriptEventDescriptor EventHolder::impl_getDescriptor_throw( const ::rtl::OUString& _rEventName ) const 416cdf0e10cSrcweir { 417cdf0e10cSrcweir EventMap::const_iterator pos = m_aEventNameAccess.find( _rEventName ); 418cdf0e10cSrcweir if ( pos == m_aEventNameAccess.end() ) 419cdf0e10cSrcweir throw NoSuchElementException( ::rtl::OUString(), *const_cast< EventHolder* >( this ) ); 420cdf0e10cSrcweir return pos->second; 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 423cdf0e10cSrcweir //------------------------------------------------------------------------ 424cdf0e10cSrcweir void SAL_CALL EventHolder::replaceByName( const ::rtl::OUString& _rName, const Any& _rElement ) throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir EventMap::iterator pos = m_aEventNameAccess.find( _rName ); 427cdf0e10cSrcweir if ( pos == m_aEventNameAccess.end() ) 428cdf0e10cSrcweir throw NoSuchElementException( ::rtl::OUString(), *this ); 429cdf0e10cSrcweir 430cdf0e10cSrcweir Sequence< PropertyValue > aScriptDescriptor; 431cdf0e10cSrcweir OSL_VERIFY( _rElement >>= aScriptDescriptor ); 432cdf0e10cSrcweir 433cdf0e10cSrcweir ::comphelper::NamedValueCollection aExtractor( aScriptDescriptor ); 434cdf0e10cSrcweir 435cdf0e10cSrcweir pos->second.ScriptType = aExtractor.getOrDefault( "EventType", ::rtl::OUString() ); 436cdf0e10cSrcweir pos->second.ScriptCode = aExtractor.getOrDefault( "Script", ::rtl::OUString() ); 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir //------------------------------------------------------------------------ 440cdf0e10cSrcweir Any SAL_CALL EventHolder::getByName( const ::rtl::OUString& _rName ) throw (NoSuchElementException, WrappedTargetException, RuntimeException) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir ScriptEventDescriptor aDescriptor( impl_getDescriptor_throw( _rName ) ); 443cdf0e10cSrcweir 444cdf0e10cSrcweir Any aRet; 445cdf0e10cSrcweir Sequence< PropertyValue > aScriptDescriptor( 2 ); 446cdf0e10cSrcweir aScriptDescriptor[0].Name = ::rtl::OUString::createFromAscii( "EventType" ); 447cdf0e10cSrcweir aScriptDescriptor[0].Value <<= aDescriptor.ScriptType; 448cdf0e10cSrcweir aScriptDescriptor[1].Name = ::rtl::OUString::createFromAscii( "Script" ); 449cdf0e10cSrcweir aScriptDescriptor[1].Value <<= aDescriptor.ScriptCode; 450cdf0e10cSrcweir 451cdf0e10cSrcweir return makeAny( aScriptDescriptor ); 452cdf0e10cSrcweir } 453cdf0e10cSrcweir 454cdf0e10cSrcweir //------------------------------------------------------------------------ 455cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EventHolder::getElementNames( ) throw (RuntimeException) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir Sequence< ::rtl::OUString > aReturn( m_aEventIndexAccess.size() ); 458cdf0e10cSrcweir ::rtl::OUString* pReturn = aReturn.getArray(); 459cdf0e10cSrcweir 460cdf0e10cSrcweir // SvxMacroAssignDlg has a weird API: It expects a XNameReplace, means a container whose 461cdf0e10cSrcweir // main access method is by name. In it's UI, it shows the possible events in exactly the 462cdf0e10cSrcweir // order in which XNameAccess::getElementNames returns them. 463cdf0e10cSrcweir // However, SvxMacroAssignDlg *also* takes an index for the initial selection, which is 464cdf0e10cSrcweir // relative to the sequence returned by XNameAccess::getElementNames. 465cdf0e10cSrcweir // This is IMO weird, since it mixes index access with name access, which decreases efficiency 466cdf0e10cSrcweir // of the implementation. 467cdf0e10cSrcweir // Well, it means we're forced to return the events in getElementNames in exactly the same as they 468cdf0e10cSrcweir // appear in the property browser UI. 469cdf0e10cSrcweir for ( EventMapIndexAccess::const_iterator loop = m_aEventIndexAccess.begin(); 470cdf0e10cSrcweir loop != m_aEventIndexAccess.end(); 471cdf0e10cSrcweir ++loop, ++pReturn 472cdf0e10cSrcweir ) 473cdf0e10cSrcweir *pReturn = loop->second->first; 474cdf0e10cSrcweir return aReturn; 475cdf0e10cSrcweir } 476cdf0e10cSrcweir 477cdf0e10cSrcweir //------------------------------------------------------------------------ 478cdf0e10cSrcweir sal_Bool SAL_CALL EventHolder::hasByName( const ::rtl::OUString& _rName ) throw (RuntimeException) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir EventMap::const_iterator pos = m_aEventNameAccess.find( _rName ); 481cdf0e10cSrcweir return pos != m_aEventNameAccess.end(); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir 484cdf0e10cSrcweir //------------------------------------------------------------------------ 485cdf0e10cSrcweir Type SAL_CALL EventHolder::getElementType( ) throw (RuntimeException) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir return ::getCppuType( static_cast< Sequence< PropertyValue >* >( NULL ) ); 488cdf0e10cSrcweir } 489cdf0e10cSrcweir 490cdf0e10cSrcweir //------------------------------------------------------------------------ 491cdf0e10cSrcweir sal_Bool SAL_CALL EventHolder::hasElements( ) throw (RuntimeException) 492cdf0e10cSrcweir { 493cdf0e10cSrcweir return !m_aEventNameAccess.empty(); 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir 497cdf0e10cSrcweir //==================================================================== 498cdf0e10cSrcweir //= EventHandler 499cdf0e10cSrcweir //==================================================================== 500cdf0e10cSrcweir DBG_NAME( EventHandler ) 501cdf0e10cSrcweir //-------------------------------------------------------------------- 502cdf0e10cSrcweir EventHandler::EventHandler( const Reference< XComponentContext >& _rxContext ) 503cdf0e10cSrcweir :EventHandler_Base( m_aMutex ) 504cdf0e10cSrcweir ,m_aContext( _rxContext ) 505cdf0e10cSrcweir ,m_aPropertyListeners( m_aMutex ) 506cdf0e10cSrcweir ,m_bEventsMapInitialized( false ) 507cdf0e10cSrcweir ,m_bIsDialogElement( false ) 508cdf0e10cSrcweir ,m_nGridColumnType( -1 ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir DBG_CTOR( EventHandler, NULL ); 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513cdf0e10cSrcweir //-------------------------------------------------------------------- 514cdf0e10cSrcweir EventHandler::~EventHandler() 515cdf0e10cSrcweir { 516cdf0e10cSrcweir DBG_DTOR( EventHandler, NULL ); 517cdf0e10cSrcweir } 518cdf0e10cSrcweir 519cdf0e10cSrcweir //-------------------------------------------------------------------- 520cdf0e10cSrcweir ::rtl::OUString SAL_CALL EventHandler::getImplementationName( ) throw (RuntimeException) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir return getImplementationName_static(); 523cdf0e10cSrcweir } 524cdf0e10cSrcweir 525cdf0e10cSrcweir //-------------------------------------------------------------------- 526cdf0e10cSrcweir ::sal_Bool SAL_CALL EventHandler::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir StlSyntaxSequence< ::rtl::OUString > aAllServices( getSupportedServiceNames() ); 529cdf0e10cSrcweir return ::std::find( aAllServices.begin(), aAllServices.end(), ServiceName ) != aAllServices.end(); 530cdf0e10cSrcweir } 531cdf0e10cSrcweir 532cdf0e10cSrcweir //-------------------------------------------------------------------- 533cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EventHandler::getSupportedServiceNames( ) throw (RuntimeException) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir return getSupportedServiceNames_static(); 536cdf0e10cSrcweir } 537cdf0e10cSrcweir 538cdf0e10cSrcweir //-------------------------------------------------------------------- 539cdf0e10cSrcweir ::rtl::OUString SAL_CALL EventHandler::getImplementationName_static( ) throw (RuntimeException) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EventHandler" ) ); 542cdf0e10cSrcweir } 543cdf0e10cSrcweir 544cdf0e10cSrcweir //-------------------------------------------------------------------- 545cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EventHandler::getSupportedServiceNames_static( ) throw (RuntimeException) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported( 1 ); 548cdf0e10cSrcweir aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.EventHandler" ) ); 549cdf0e10cSrcweir return aSupported; 550cdf0e10cSrcweir } 551cdf0e10cSrcweir 552cdf0e10cSrcweir //-------------------------------------------------------------------- 553cdf0e10cSrcweir Reference< XInterface > SAL_CALL EventHandler::Create( const Reference< XComponentContext >& _rxContext ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir return *( new EventHandler( _rxContext ) ); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir //-------------------------------------------------------------------- 559cdf0e10cSrcweir void SAL_CALL EventHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException) 560cdf0e10cSrcweir { 561cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 562cdf0e10cSrcweir 563cdf0e10cSrcweir if ( !_rxIntrospectee.is() ) 564cdf0e10cSrcweir throw NullPointerException(); 565cdf0e10cSrcweir 566cdf0e10cSrcweir m_xComponent = Reference< XPropertySet >( _rxIntrospectee, UNO_QUERY_THROW ); 567cdf0e10cSrcweir 568cdf0e10cSrcweir m_bEventsMapInitialized = false; 569cdf0e10cSrcweir EventMap aEmpty; 570cdf0e10cSrcweir m_aEvents.swap( aEmpty ); 571cdf0e10cSrcweir 572cdf0e10cSrcweir m_bIsDialogElement = false; 573cdf0e10cSrcweir m_nGridColumnType = -1; 574cdf0e10cSrcweir try 575cdf0e10cSrcweir { 576cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI( m_xComponent->getPropertySetInfo() ); 577cdf0e10cSrcweir m_bIsDialogElement = xPSI.is() 578cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_WIDTH ) 579cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_HEIGHT ) 580cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_POSITIONX ) 581cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_POSITIONY ); 582cdf0e10cSrcweir 583cdf0e10cSrcweir Reference< XChild > xAsChild( _rxIntrospectee, UNO_QUERY ); 584cdf0e10cSrcweir if ( xAsChild.is() && !Reference< XForm >( _rxIntrospectee, UNO_QUERY ).is() ) 585cdf0e10cSrcweir { 586cdf0e10cSrcweir if ( FormComponentType::GRIDCONTROL == classifyComponent( xAsChild->getParent() ) ) 587cdf0e10cSrcweir { 588cdf0e10cSrcweir m_nGridColumnType = classifyComponent( _rxIntrospectee ); 589cdf0e10cSrcweir } 590cdf0e10cSrcweir } 591cdf0e10cSrcweir } 592cdf0e10cSrcweir catch( const Exception& ) 593cdf0e10cSrcweir { 594cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir } 597cdf0e10cSrcweir 598cdf0e10cSrcweir //-------------------------------------------------------------------- 599cdf0e10cSrcweir Any SAL_CALL EventHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 602cdf0e10cSrcweir 603cdf0e10cSrcweir const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName ); 604cdf0e10cSrcweir 605cdf0e10cSrcweir Sequence< ScriptEventDescriptor > aEvents; 606cdf0e10cSrcweir impl_getComponentScriptEvents_nothrow( aEvents ); 607cdf0e10cSrcweir 608cdf0e10cSrcweir sal_Int32 nEventCount = aEvents.getLength(); 609cdf0e10cSrcweir const ScriptEventDescriptor* pEvents = aEvents.getConstArray(); 610cdf0e10cSrcweir 611cdf0e10cSrcweir ScriptEventDescriptor aPropertyValue; 612cdf0e10cSrcweir for ( sal_Int32 event = 0; event < nEventCount; ++event, ++pEvents ) 613cdf0e10cSrcweir { 614cdf0e10cSrcweir if ( rEvent.sListenerClassName == pEvents->ListenerType 615cdf0e10cSrcweir && rEvent.sListenerMethodName == pEvents->EventMethod 616cdf0e10cSrcweir ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir aPropertyValue = *pEvents; 619cdf0e10cSrcweir break; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir } 622cdf0e10cSrcweir 623cdf0e10cSrcweir return makeAny( aPropertyValue ); 624cdf0e10cSrcweir } 625cdf0e10cSrcweir 626cdf0e10cSrcweir //-------------------------------------------------------------------- 627cdf0e10cSrcweir void SAL_CALL EventHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException) 628cdf0e10cSrcweir { 629cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 630cdf0e10cSrcweir 631cdf0e10cSrcweir const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName ); 632cdf0e10cSrcweir 633cdf0e10cSrcweir ScriptEventDescriptor aNewScriptEvent; 634cdf0e10cSrcweir OSL_VERIFY( _rValue >>= aNewScriptEvent ); 635cdf0e10cSrcweir 636cdf0e10cSrcweir ScriptEventDescriptor aOldScriptEvent; 637cdf0e10cSrcweir OSL_VERIFY( getPropertyValue( _rPropertyName ) >>= aOldScriptEvent ); 638cdf0e10cSrcweir if ( aOldScriptEvent == aNewScriptEvent ) 639cdf0e10cSrcweir return; 640cdf0e10cSrcweir 641cdf0e10cSrcweir if ( m_bIsDialogElement ) 642cdf0e10cSrcweir impl_setDialogElementScriptEvent_nothrow( aNewScriptEvent ); 643cdf0e10cSrcweir else 644cdf0e10cSrcweir impl_setFormComponentScriptEvent_nothrow( aNewScriptEvent ); 645cdf0e10cSrcweir 646cdf0e10cSrcweir Reference< XModifiable > xDoc( m_aContext.getContextValueByAsciiName( "ContextDocument" ), UNO_QUERY ); 647cdf0e10cSrcweir if ( xDoc.is() ) 648cdf0e10cSrcweir xDoc->setModified( sal_True ); 649cdf0e10cSrcweir 650cdf0e10cSrcweir PropertyChangeEvent aEvent; 651cdf0e10cSrcweir aEvent.Source = m_xComponent; 652cdf0e10cSrcweir aEvent.PropertyHandle = rEvent.nId; 653cdf0e10cSrcweir aEvent.PropertyName = _rPropertyName; 654cdf0e10cSrcweir aEvent.OldValue <<= aOldScriptEvent; 655cdf0e10cSrcweir aEvent.NewValue <<= aNewScriptEvent; 656cdf0e10cSrcweir m_aPropertyListeners.notify( aEvent, &XPropertyChangeListener::propertyChange ); 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir //-------------------------------------------------------------------- 660cdf0e10cSrcweir Any SAL_CALL EventHandler::convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException) 661cdf0e10cSrcweir { 662cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 663cdf0e10cSrcweir 664cdf0e10cSrcweir ::rtl::OUString sNewScriptCode; 665cdf0e10cSrcweir OSL_VERIFY( _rControlValue >>= sNewScriptCode ); 666cdf0e10cSrcweir 667cdf0e10cSrcweir Sequence< ScriptEventDescriptor > aAllAssignedEvents; 668cdf0e10cSrcweir impl_getComponentScriptEvents_nothrow( aAllAssignedEvents ); 669cdf0e10cSrcweir 670cdf0e10cSrcweir const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName ); 671cdf0e10cSrcweir ScriptEventDescriptor aAssignedScript = lcl_getAssignedScriptEvent( rEvent, aAllAssignedEvents ); 672cdf0e10cSrcweir 673cdf0e10cSrcweir OSL_ENSURE( !sNewScriptCode.getLength(), "EventHandler::convertToPropertyValue: cannot convert a non-empty display name!" ); 674cdf0e10cSrcweir // Usually, there is no possibility for the user to change the content of an event binding directly in the 675cdf0e10cSrcweir // input field, this instead is done with the macro assignment dialog. 676cdf0e10cSrcweir // The only exception is the user pressing "DEL" while the control has the focus, in this case, we reset the 677cdf0e10cSrcweir // control content to an empty string. So this is the only scenario where this method is allowed to be called. 678cdf0e10cSrcweir 679cdf0e10cSrcweir // Striclty, we would be able to convert the display value to a property value, 680cdf0e10cSrcweir // using the "name (location, language)" format we used in convertToControlValue. However, 681cdf0e10cSrcweir // there is no need for this code ... 682cdf0e10cSrcweir 683cdf0e10cSrcweir aAssignedScript.ScriptCode = sNewScriptCode; 684cdf0e10cSrcweir return makeAny( aAssignedScript ); 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir //-------------------------------------------------------------------- 688cdf0e10cSrcweir Any SAL_CALL EventHandler::convertToControlValue( const ::rtl::OUString& /*_rPropertyName*/, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 691cdf0e10cSrcweir 692cdf0e10cSrcweir ScriptEventDescriptor aScriptEvent; 693cdf0e10cSrcweir OSL_VERIFY( _rPropertyValue >>= aScriptEvent ); 694cdf0e10cSrcweir 695cdf0e10cSrcweir OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING, 696cdf0e10cSrcweir "EventHandler::convertToControlValue: unexpected ControlValue type class!" ); 697cdf0e10cSrcweir (void)_rControlValueType; 698cdf0e10cSrcweir 699cdf0e10cSrcweir ::rtl::OUString sScript( aScriptEvent.ScriptCode ); 700cdf0e10cSrcweir if ( sScript.getLength() ) 701cdf0e10cSrcweir { 702cdf0e10cSrcweir // format is: "name (location, language)" 703cdf0e10cSrcweir try 704cdf0e10cSrcweir { 705cdf0e10cSrcweir // parse 706cdf0e10cSrcweir Reference< XUriReferenceFactory > xUriRefFac = UriReferenceFactory::create( m_aContext.getUNOContext() ); 707cdf0e10cSrcweir Reference< XVndSunStarScriptUrlReference > xScriptUri( xUriRefFac->parse( sScript ), UNO_QUERY_THROW ); 708cdf0e10cSrcweir 709cdf0e10cSrcweir ::rtl::OUStringBuffer aComposeBuffer; 710cdf0e10cSrcweir 711cdf0e10cSrcweir // name 712cdf0e10cSrcweir aComposeBuffer.append( xScriptUri->getName() ); 713cdf0e10cSrcweir 714cdf0e10cSrcweir // location 715cdf0e10cSrcweir const ::rtl::OUString sLocationParamName( RTL_CONSTASCII_USTRINGPARAM( "location" ) ); 716cdf0e10cSrcweir const ::rtl::OUString sLocation = xScriptUri->getParameter( sLocationParamName ); 717cdf0e10cSrcweir const ::rtl::OUString sLangParamName( RTL_CONSTASCII_USTRINGPARAM( "language" ) ); 718cdf0e10cSrcweir const ::rtl::OUString sLanguage = xScriptUri->getParameter( sLangParamName ); 719cdf0e10cSrcweir 720cdf0e10cSrcweir if ( sLocation.getLength() || sLanguage.getLength() ) 721cdf0e10cSrcweir { 722cdf0e10cSrcweir aComposeBuffer.appendAscii( " (" ); 723cdf0e10cSrcweir 724cdf0e10cSrcweir // location 725cdf0e10cSrcweir OSL_ENSURE( sLocation.getLength(), "EventHandler::convertToControlValue: unexpected: no location!" ); 726cdf0e10cSrcweir if ( sLocation.getLength() ) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir aComposeBuffer.append( sLocation ); 729cdf0e10cSrcweir aComposeBuffer.appendAscii( ", " ); 730cdf0e10cSrcweir } 731cdf0e10cSrcweir 732cdf0e10cSrcweir // language 733cdf0e10cSrcweir if ( sLanguage.getLength() ) 734cdf0e10cSrcweir { 735cdf0e10cSrcweir aComposeBuffer.append( sLanguage ); 736cdf0e10cSrcweir } 737cdf0e10cSrcweir 738cdf0e10cSrcweir aComposeBuffer.append( sal_Unicode( ')' ) ); 739cdf0e10cSrcweir } 740cdf0e10cSrcweir 741cdf0e10cSrcweir sScript = aComposeBuffer.makeStringAndClear(); 742cdf0e10cSrcweir } 743cdf0e10cSrcweir catch( const Exception& ) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 746cdf0e10cSrcweir } 747cdf0e10cSrcweir } 748cdf0e10cSrcweir 749cdf0e10cSrcweir return makeAny( sScript ); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir 752cdf0e10cSrcweir //-------------------------------------------------------------------- 753cdf0e10cSrcweir PropertyState SAL_CALL EventHandler::getPropertyState( const ::rtl::OUString& /*_rPropertyName*/ ) throw (UnknownPropertyException, RuntimeException) 754cdf0e10cSrcweir { 755cdf0e10cSrcweir return PropertyState_DIRECT_VALUE; 756cdf0e10cSrcweir } 757cdf0e10cSrcweir 758cdf0e10cSrcweir //-------------------------------------------------------------------- 759cdf0e10cSrcweir void SAL_CALL EventHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException) 760cdf0e10cSrcweir { 761cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 762cdf0e10cSrcweir if ( !_rxListener.is() ) 763cdf0e10cSrcweir throw NullPointerException(); 764cdf0e10cSrcweir m_aPropertyListeners.addListener( _rxListener ); 765cdf0e10cSrcweir } 766cdf0e10cSrcweir 767cdf0e10cSrcweir //-------------------------------------------------------------------- 768cdf0e10cSrcweir void SAL_CALL EventHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException) 769cdf0e10cSrcweir { 770cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 771cdf0e10cSrcweir m_aPropertyListeners.removeListener( _rxListener ); 772cdf0e10cSrcweir } 773cdf0e10cSrcweir 774cdf0e10cSrcweir //-------------------------------------------------------------------- 775cdf0e10cSrcweir Sequence< Property > SAL_CALL EventHandler::getSupportedProperties() throw (RuntimeException) 776cdf0e10cSrcweir { 777cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 778cdf0e10cSrcweir if ( !m_bEventsMapInitialized ) 779cdf0e10cSrcweir { 780cdf0e10cSrcweir const_cast< EventHandler* >( this )->m_bEventsMapInitialized = true; 781cdf0e10cSrcweir try 782cdf0e10cSrcweir { 783cdf0e10cSrcweir Sequence< Type > aListeners; 784cdf0e10cSrcweir impl_getCopmonentListenerTypes_nothrow( aListeners ); 785cdf0e10cSrcweir sal_Int32 listenerCount = aListeners.getLength(); 786cdf0e10cSrcweir 787cdf0e10cSrcweir Property aCurrentProperty; 788cdf0e10cSrcweir ::rtl::OUString sListenerClassName; 789cdf0e10cSrcweir 790cdf0e10cSrcweir // loop through all listeners and all methods, and see which we can present at the UI 791cdf0e10cSrcweir const Type* pListeners = aListeners.getConstArray(); 792cdf0e10cSrcweir for ( sal_Int32 listener = 0; listener < listenerCount; ++listener, ++pListeners ) 793cdf0e10cSrcweir { 794cdf0e10cSrcweir aCurrentProperty = Property(); 795cdf0e10cSrcweir 796cdf0e10cSrcweir // the programmatic name of the listener, to be used as "property" name 797cdf0e10cSrcweir sListenerClassName = pListeners->getTypeName(); 798cdf0e10cSrcweir OSL_ENSURE( sListenerClassName.getLength(), "EventHandler::getSupportedProperties: strange - no listener name ..." ); 799cdf0e10cSrcweir if ( !sListenerClassName.getLength() ) 800cdf0e10cSrcweir continue; 801cdf0e10cSrcweir 802cdf0e10cSrcweir // loop through all methods 803cdf0e10cSrcweir Sequence< ::rtl::OUString > aMethods( comphelper::getEventMethodsForType( *pListeners ) ); 804cdf0e10cSrcweir 805cdf0e10cSrcweir const ::rtl::OUString* pMethods = aMethods.getConstArray(); 806cdf0e10cSrcweir sal_uInt32 methodCount = aMethods.getLength(); 807cdf0e10cSrcweir 808cdf0e10cSrcweir for (sal_uInt32 method = 0 ; method < methodCount ; ++method, ++pMethods ) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir EventDescription aEvent; 811cdf0e10cSrcweir if ( !lcl_getEventDescriptionForMethod( *pMethods, aEvent ) ) 812cdf0e10cSrcweir continue; 813cdf0e10cSrcweir 814cdf0e10cSrcweir if ( !impl_filterMethod_nothrow( aEvent ) ) 815cdf0e10cSrcweir continue; 816cdf0e10cSrcweir 817cdf0e10cSrcweir const_cast< EventHandler* >( this )->m_aEvents.insert( EventMap::value_type( 818cdf0e10cSrcweir lcl_getEventPropertyName( sListenerClassName, *pMethods ), aEvent ) ); 819cdf0e10cSrcweir } 820cdf0e10cSrcweir } 821cdf0e10cSrcweir 822cdf0e10cSrcweir } 823cdf0e10cSrcweir catch( const Exception& ) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 826cdf0e10cSrcweir } 827cdf0e10cSrcweir } 828cdf0e10cSrcweir 829cdf0e10cSrcweir // sort them by ID - this is the relative ordering in the UI 830cdf0e10cSrcweir ::std::map< EventId, Property > aOrderedProperties; 831cdf0e10cSrcweir for ( EventMap::const_iterator loop = m_aEvents.begin(); 832cdf0e10cSrcweir loop != m_aEvents.end(); 833cdf0e10cSrcweir ++loop 834cdf0e10cSrcweir ) 835cdf0e10cSrcweir { 836cdf0e10cSrcweir aOrderedProperties[ loop->second.nId ] = Property( 837cdf0e10cSrcweir loop->first, loop->second.nId, 838cdf0e10cSrcweir ::getCppuType( static_cast< const ::rtl::OUString* >( NULL ) ), 839cdf0e10cSrcweir PropertyAttribute::BOUND ); 840cdf0e10cSrcweir } 841cdf0e10cSrcweir 842cdf0e10cSrcweir StlSyntaxSequence< Property > aReturn( aOrderedProperties.size() ); 843cdf0e10cSrcweir ::std::transform( aOrderedProperties.begin(), aOrderedProperties.end(), aReturn.begin(), 844cdf0e10cSrcweir ::std::select2nd< ::std::map< EventId, Property >::value_type >() ); 845cdf0e10cSrcweir return aReturn; 846cdf0e10cSrcweir } 847cdf0e10cSrcweir 848cdf0e10cSrcweir //-------------------------------------------------------------------- 849cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EventHandler::getSupersededProperties( ) throw (RuntimeException) 850cdf0e10cSrcweir { 851cdf0e10cSrcweir // none 852cdf0e10cSrcweir return Sequence< ::rtl::OUString >( ); 853cdf0e10cSrcweir } 854cdf0e10cSrcweir 855cdf0e10cSrcweir //-------------------------------------------------------------------- 856cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EventHandler::getActuatingProperties( ) throw (RuntimeException) 857cdf0e10cSrcweir { 858cdf0e10cSrcweir // none 859cdf0e10cSrcweir return Sequence< ::rtl::OUString >( ); 860cdf0e10cSrcweir } 861cdf0e10cSrcweir 862cdf0e10cSrcweir //-------------------------------------------------------------------- 863cdf0e10cSrcweir LineDescriptor SAL_CALL EventHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName, 864cdf0e10cSrcweir const Reference< XPropertyControlFactory >& _rxControlFactory ) 865cdf0e10cSrcweir throw (UnknownPropertyException, NullPointerException, RuntimeException) 866cdf0e10cSrcweir { 867cdf0e10cSrcweir if ( !_rxControlFactory.is() ) 868cdf0e10cSrcweir throw NullPointerException(); 869cdf0e10cSrcweir 870cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 871cdf0e10cSrcweir 872cdf0e10cSrcweir LineDescriptor aDescriptor; 873cdf0e10cSrcweir 874cdf0e10cSrcweir aDescriptor.Control = _rxControlFactory->createPropertyControl( PropertyControlType::TextField, sal_True ); 875cdf0e10cSrcweir Reference< XEventListener > xControlExtender = new PropertyControlExtender( aDescriptor.Control ); 876cdf0e10cSrcweir 877cdf0e10cSrcweir const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName ); 878cdf0e10cSrcweir aDescriptor.DisplayName = rEvent.sDisplayName; 879cdf0e10cSrcweir aDescriptor.HelpURL = HelpIdUrl::getHelpURL( rEvent.sHelpId ); 880cdf0e10cSrcweir aDescriptor.PrimaryButtonId = rtl::OStringToOUString(rEvent.sUniqueBrowseId, RTL_TEXTENCODING_UTF8); 881cdf0e10cSrcweir aDescriptor.HasPrimaryButton = sal_True; 882cdf0e10cSrcweir aDescriptor.Category = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Events" ) ); 883cdf0e10cSrcweir return aDescriptor; 884cdf0e10cSrcweir } 885cdf0e10cSrcweir 886cdf0e10cSrcweir //-------------------------------------------------------------------- 887cdf0e10cSrcweir ::sal_Bool SAL_CALL EventHandler::isComposable( const ::rtl::OUString& /*_rPropertyName*/ ) throw (UnknownPropertyException, RuntimeException) 888cdf0e10cSrcweir { 889cdf0e10cSrcweir return sal_False; 890cdf0e10cSrcweir } 891cdf0e10cSrcweir 892cdf0e10cSrcweir //-------------------------------------------------------------------- 893cdf0e10cSrcweir InteractiveSelectionResult SAL_CALL EventHandler::onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool /*_bPrimary*/, Any& /*_rData*/, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException) 894cdf0e10cSrcweir { 895cdf0e10cSrcweir if ( !_rxInspectorUI.is() ) 896cdf0e10cSrcweir throw NullPointerException(); 897cdf0e10cSrcweir 898cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 899cdf0e10cSrcweir const EventDescription& rForEvent = impl_getEventForName_throw( _rPropertyName ); 900cdf0e10cSrcweir 901cdf0e10cSrcweir Sequence< ScriptEventDescriptor > aAllAssignedEvents; 902cdf0e10cSrcweir impl_getComponentScriptEvents_nothrow( aAllAssignedEvents ); 903cdf0e10cSrcweir 904cdf0e10cSrcweir // SvxMacroAssignDlg-compatible structure holding all event/assignments 905cdf0e10cSrcweir ::rtl::Reference< EventHolder > pEventHolder( new EventHolder ); 906cdf0e10cSrcweir 907cdf0e10cSrcweir for ( EventMap::const_iterator event = m_aEvents.begin(); 908cdf0e10cSrcweir event != m_aEvents.end(); 909cdf0e10cSrcweir ++event 910cdf0e10cSrcweir ) 911cdf0e10cSrcweir { 912cdf0e10cSrcweir // the script which is assigned to the current event (if any) 913cdf0e10cSrcweir ScriptEventDescriptor aAssignedScript = lcl_getAssignedScriptEvent( event->second, aAllAssignedEvents ); 914cdf0e10cSrcweir pEventHolder->addEvent( event->second.nId, event->second.sListenerMethodName, aAssignedScript ); 915cdf0e10cSrcweir } 916cdf0e10cSrcweir 917cdf0e10cSrcweir // the inital selection in the dialog 918cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames( pEventHolder->getElementNames() ); 919cdf0e10cSrcweir const ::rtl::OUString* pChosenEvent = ::std::find( aNames.getConstArray(), aNames.getConstArray() + aNames.getLength(), rForEvent.sListenerMethodName ); 920cdf0e10cSrcweir sal_uInt16 nInitialSelection = (sal_uInt16)( pChosenEvent - aNames.getConstArray() ); 921cdf0e10cSrcweir 922cdf0e10cSrcweir // the dialog 923cdf0e10cSrcweir SvxAbstractDialogFactory* pFactory = SvxAbstractDialogFactory::Create(); 924cdf0e10cSrcweir if ( !pFactory ) 925cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled; 926cdf0e10cSrcweir 927cdf0e10cSrcweir ::std::auto_ptr< VclAbstractDialog > pDialog( pFactory->CreateSvxMacroAssignDlg( 928cdf0e10cSrcweir PropertyHandlerHelper::getDialogParentWindow( m_aContext ), 929cdf0e10cSrcweir impl_getContextFrame_nothrow(), 930cdf0e10cSrcweir m_bIsDialogElement, 931cdf0e10cSrcweir pEventHolder.get(), 932cdf0e10cSrcweir nInitialSelection 933cdf0e10cSrcweir ) ); 934cdf0e10cSrcweir 935cdf0e10cSrcweir if ( !pDialog.get() ) 936cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled; 937cdf0e10cSrcweir 938cdf0e10cSrcweir // DF definite problem here 939cdf0e10cSrcweir // OK & Cancel seem to be both returning 0 940cdf0e10cSrcweir if ( pDialog->Execute() == RET_CANCEL ) 941cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled; 942cdf0e10cSrcweir 943cdf0e10cSrcweir try 944cdf0e10cSrcweir { 945cdf0e10cSrcweir for ( EventMap::const_iterator event = m_aEvents.begin(); 946cdf0e10cSrcweir event != m_aEvents.end(); 947cdf0e10cSrcweir ++event 948cdf0e10cSrcweir ) 949cdf0e10cSrcweir { 950cdf0e10cSrcweir ScriptEventDescriptor aScriptDescriptor( pEventHolder->getNormalizedDescriptorByName( event->second.sListenerMethodName ) ); 951cdf0e10cSrcweir 952cdf0e10cSrcweir // set the new "property value" 953cdf0e10cSrcweir setPropertyValue( 954cdf0e10cSrcweir lcl_getEventPropertyName( event->second.sListenerClassName, event->second.sListenerMethodName ), 955cdf0e10cSrcweir makeAny( aScriptDescriptor ) 956cdf0e10cSrcweir ); 957cdf0e10cSrcweir } 958cdf0e10cSrcweir } 959cdf0e10cSrcweir catch( const Exception& ) 960cdf0e10cSrcweir { 961cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 962cdf0e10cSrcweir } 963cdf0e10cSrcweir 964cdf0e10cSrcweir return InteractiveSelectionResult_Success; 965cdf0e10cSrcweir } 966cdf0e10cSrcweir 967cdf0e10cSrcweir //-------------------------------------------------------------------- 968cdf0e10cSrcweir void SAL_CALL EventHandler::actuatingPropertyChanged( const ::rtl::OUString& /*_rActuatingPropertyName*/, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException) 969cdf0e10cSrcweir { 970cdf0e10cSrcweir DBG_ERROR( "EventHandler::actuatingPropertyChanged: no actuating properties -> no callback (well, this is how it *should* be!)" ); 971cdf0e10cSrcweir } 972cdf0e10cSrcweir 973cdf0e10cSrcweir //-------------------------------------------------------------------- 974cdf0e10cSrcweir IMPLEMENT_FORWARD_XCOMPONENT( EventHandler, EventHandler_Base ) 975cdf0e10cSrcweir 976cdf0e10cSrcweir //-------------------------------------------------------------------- 977cdf0e10cSrcweir void SAL_CALL EventHandler::disposing() 978cdf0e10cSrcweir { 979cdf0e10cSrcweir EventMap aEmpty; 980cdf0e10cSrcweir m_aEvents.swap( aEmpty ); 981cdf0e10cSrcweir m_xComponent.clear(); 982cdf0e10cSrcweir } 983cdf0e10cSrcweir 984cdf0e10cSrcweir //-------------------------------------------------------------------- 985cdf0e10cSrcweir sal_Bool SAL_CALL EventHandler::suspend( sal_Bool /*_bSuspend*/ ) throw (RuntimeException) 986cdf0e10cSrcweir { 987cdf0e10cSrcweir return sal_True; 988cdf0e10cSrcweir } 989cdf0e10cSrcweir 990cdf0e10cSrcweir //------------------------------------------------------------------------ 991cdf0e10cSrcweir Reference< XFrame > EventHandler::impl_getContextFrame_nothrow() const 992cdf0e10cSrcweir { 993cdf0e10cSrcweir Reference< XFrame > xContextFrame; 994cdf0e10cSrcweir 995cdf0e10cSrcweir try 996cdf0e10cSrcweir { 997cdf0e10cSrcweir Reference< XModel > xContextDocument( m_aContext.getContextValueByAsciiName( "ContextDocument" ), UNO_QUERY_THROW ); 998cdf0e10cSrcweir Reference< XController > xController( xContextDocument->getCurrentController(), UNO_SET_THROW ); 999cdf0e10cSrcweir xContextFrame.set( xController->getFrame(), UNO_SET_THROW ); 1000cdf0e10cSrcweir } 1001cdf0e10cSrcweir catch( const Exception& ) 1002cdf0e10cSrcweir { 1003cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1004cdf0e10cSrcweir } 1005cdf0e10cSrcweir 1006cdf0e10cSrcweir return xContextFrame; 1007cdf0e10cSrcweir } 1008cdf0e10cSrcweir 1009cdf0e10cSrcweir //-------------------------------------------------------------------- 1010cdf0e10cSrcweir sal_Int32 EventHandler::impl_getComponentIndexInParent_throw() const 1011cdf0e10cSrcweir { 1012cdf0e10cSrcweir Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW ); 1013cdf0e10cSrcweir Reference< XIndexAccess > xParentAsIndexAccess( xChild->getParent(), UNO_QUERY_THROW ); 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir // get the index of the inspected object within it's parent container 1016cdf0e10cSrcweir sal_Int32 nElements = xParentAsIndexAccess->getCount(); 1017cdf0e10cSrcweir for ( sal_Int32 i=0; i<nElements; ++i ) 1018cdf0e10cSrcweir { 1019cdf0e10cSrcweir Reference< XInterface > xElement( xParentAsIndexAccess->getByIndex( i ), UNO_QUERY_THROW ); 1020cdf0e10cSrcweir if ( xElement == m_xComponent ) 1021cdf0e10cSrcweir return i; 1022cdf0e10cSrcweir } 1023cdf0e10cSrcweir throw NoSuchElementException(); 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir //-------------------------------------------------------------------- 1027cdf0e10cSrcweir void EventHandler::impl_getFormComponentScriptEvents_nothrow( Sequence < ScriptEventDescriptor >& _out_rEvents ) const 1028cdf0e10cSrcweir { 1029cdf0e10cSrcweir _out_rEvents = Sequence < ScriptEventDescriptor >(); 1030cdf0e10cSrcweir try 1031cdf0e10cSrcweir { 1032cdf0e10cSrcweir Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW ); 1033cdf0e10cSrcweir Reference< XEventAttacherManager > xEventManager( xChild->getParent(), UNO_QUERY_THROW ); 1034cdf0e10cSrcweir _out_rEvents = xEventManager->getScriptEvents( impl_getComponentIndexInParent_throw() ); 1035cdf0e10cSrcweir 1036cdf0e10cSrcweir // the form component script API has unqualified listener names, but for normalization 1037cdf0e10cSrcweir // purpose, we want fully qualified ones 1038cdf0e10cSrcweir ScriptEventDescriptor* pEvents = _out_rEvents.getArray(); 1039cdf0e10cSrcweir ScriptEventDescriptor* pEventsEnd = _out_rEvents.getArray() + _out_rEvents.getLength(); 1040cdf0e10cSrcweir while ( pEvents != pEventsEnd ) 1041cdf0e10cSrcweir { 1042cdf0e10cSrcweir pEvents->ListenerType = lcl_getQualifiedKnownListenerName( *pEvents ); 1043cdf0e10cSrcweir ++pEvents; 1044cdf0e10cSrcweir } 1045cdf0e10cSrcweir } 1046cdf0e10cSrcweir catch( const Exception& ) 1047cdf0e10cSrcweir { 1048cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1049cdf0e10cSrcweir } 1050cdf0e10cSrcweir } 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir //-------------------------------------------------------------------- 1053cdf0e10cSrcweir void EventHandler::impl_getCopmonentListenerTypes_nothrow( Sequence< Type >& _out_rTypes ) const 1054cdf0e10cSrcweir { 1055cdf0e10cSrcweir _out_rTypes.realloc( 0 ); 1056cdf0e10cSrcweir try 1057cdf0e10cSrcweir { 1058cdf0e10cSrcweir // we use a set to avoid duplicates 1059cdf0e10cSrcweir TypeBag aListeners; 1060cdf0e10cSrcweir 1061cdf0e10cSrcweir Reference< XIntrospection > xIntrospection( m_aContext.createComponent( "com.sun.star.beans.Introspection" ), UNO_QUERY_THROW ); 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir // --- model listeners 1064cdf0e10cSrcweir lcl_addListenerTypesFor_throw( 1065cdf0e10cSrcweir m_xComponent, xIntrospection, aListeners ); 1066cdf0e10cSrcweir 1067cdf0e10cSrcweir // --- "secondary component" (usually: "control" listeners) 1068cdf0e10cSrcweir { 1069cdf0e10cSrcweir Reference< XInterface > xSecondaryComponent( impl_getSecondaryComponentForEventInspection_throw() ); 1070cdf0e10cSrcweir lcl_addListenerTypesFor_throw( xSecondaryComponent, xIntrospection, aListeners ); 1071cdf0e10cSrcweir ::comphelper::disposeComponent( xSecondaryComponent ); 1072cdf0e10cSrcweir } 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir // now that they're disambiguated, copy these types into our member 1075cdf0e10cSrcweir _out_rTypes.realloc( aListeners.size() ); 1076cdf0e10cSrcweir ::std::copy( aListeners.begin(), aListeners.end(), _out_rTypes.getArray() ); 1077cdf0e10cSrcweir } 1078cdf0e10cSrcweir catch( const Exception& ) 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1081cdf0e10cSrcweir } 1082cdf0e10cSrcweir } 1083cdf0e10cSrcweir 1084cdf0e10cSrcweir //-------------------------------------------------------------------- 1085cdf0e10cSrcweir void EventHandler::impl_getDialogElementScriptEvents_nothrow( Sequence < ScriptEventDescriptor >& _out_rEvents ) const 1086cdf0e10cSrcweir { 1087cdf0e10cSrcweir _out_rEvents = Sequence < ScriptEventDescriptor >(); 1088cdf0e10cSrcweir try 1089cdf0e10cSrcweir { 1090cdf0e10cSrcweir Reference< XScriptEventsSupplier > xEventsSupplier( m_xComponent, UNO_QUERY_THROW ); 1091cdf0e10cSrcweir Reference< XNameContainer > xEvents( xEventsSupplier->getEvents(), UNO_QUERY_THROW ); 1092cdf0e10cSrcweir Sequence< ::rtl::OUString > aEventNames( xEvents->getElementNames() ); 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir sal_Int32 nEventCount = aEventNames.getLength(); 1095cdf0e10cSrcweir _out_rEvents.realloc( nEventCount ); 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir const ::rtl::OUString* pNames = aEventNames.getConstArray(); 1098cdf0e10cSrcweir ScriptEventDescriptor* pDescs = _out_rEvents.getArray(); 1099cdf0e10cSrcweir 1100cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nEventCount ; ++i, ++pNames, ++pDescs ) 1101cdf0e10cSrcweir OSL_VERIFY( xEvents->getByName( *pNames ) >>= *pDescs ); 1102cdf0e10cSrcweir } 1103cdf0e10cSrcweir catch( const Exception& ) 1104cdf0e10cSrcweir { 1105cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir } 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir //-------------------------------------------------------------------- 1110cdf0e10cSrcweir Reference< XInterface > EventHandler::impl_getSecondaryComponentForEventInspection_throw( ) const 1111cdf0e10cSrcweir { 1112cdf0e10cSrcweir Reference< XInterface > xReturn; 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir // if it's a form, create a form controller for the additional events 1115cdf0e10cSrcweir Reference< XForm > xComponentAsForm( m_xComponent, UNO_QUERY ); 1116cdf0e10cSrcweir if ( xComponentAsForm.is() ) 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir Reference< XTabControllerModel > xComponentAsTCModel( m_xComponent, UNO_QUERY_THROW ); 1119cdf0e10cSrcweir Reference< XFormController > xController( 1120cdf0e10cSrcweir m_aContext.createComponent( "com.sun.star.form.runtime.FormController" ), UNO_QUERY_THROW ); 1121cdf0e10cSrcweir xController->setModel( xComponentAsTCModel ); 1122cdf0e10cSrcweir 1123cdf0e10cSrcweir xReturn = xController; 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir else 1126cdf0e10cSrcweir { 1127cdf0e10cSrcweir ::rtl::OUString sControlService; 1128cdf0e10cSrcweir OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_DEFAULTCONTROL ) >>= sControlService ); 1129cdf0e10cSrcweir 1130cdf0e10cSrcweir xReturn = m_aContext.createComponent( sControlService ); 1131cdf0e10cSrcweir } 1132cdf0e10cSrcweir return xReturn; 1133cdf0e10cSrcweir } 1134cdf0e10cSrcweir 1135cdf0e10cSrcweir //-------------------------------------------------------------------- 1136cdf0e10cSrcweir const EventDescription& EventHandler::impl_getEventForName_throw( const ::rtl::OUString& _rPropertyName ) const 1137cdf0e10cSrcweir { 1138cdf0e10cSrcweir EventMap::const_iterator pos = m_aEvents.find( _rPropertyName ); 1139cdf0e10cSrcweir if ( pos == m_aEvents.end() ) 1140cdf0e10cSrcweir throw UnknownPropertyException(); 1141cdf0e10cSrcweir return pos->second; 1142cdf0e10cSrcweir } 1143cdf0e10cSrcweir 1144cdf0e10cSrcweir //-------------------------------------------------------------------- 1145cdf0e10cSrcweir namespace 1146cdf0e10cSrcweir { 1147cdf0e10cSrcweir static bool lcl_endsWith( const ::rtl::OUString& _rText, const ::rtl::OUString& _rCheck ) 1148cdf0e10cSrcweir { 1149cdf0e10cSrcweir sal_Int32 nTextLen = _rText.getLength(); 1150cdf0e10cSrcweir sal_Int32 nCheckLen = _rCheck.getLength(); 1151cdf0e10cSrcweir if ( nCheckLen > nTextLen ) 1152cdf0e10cSrcweir return false; 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir return _rText.indexOf( _rCheck ) == ( nTextLen - nCheckLen ); 1155cdf0e10cSrcweir } 1156cdf0e10cSrcweir } 1157cdf0e10cSrcweir //-------------------------------------------------------------------- 1158cdf0e10cSrcweir void EventHandler::impl_setFormComponentScriptEvent_nothrow( const ScriptEventDescriptor& _rScriptEvent ) 1159cdf0e10cSrcweir { 1160cdf0e10cSrcweir try 1161cdf0e10cSrcweir { 1162cdf0e10cSrcweir ::rtl::OUString sScriptCode( _rScriptEvent.ScriptCode ); 1163cdf0e10cSrcweir ::rtl::OUString sScriptType( _rScriptEvent.ScriptType ); 1164cdf0e10cSrcweir bool bResetScript = ( sScriptCode.getLength() == 0 ); 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir sal_Int32 nObjectIndex = impl_getComponentIndexInParent_throw(); 1167cdf0e10cSrcweir Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW ); 1168cdf0e10cSrcweir Reference< XEventAttacherManager > xEventManager( xChild->getParent(), UNO_QUERY_THROW ); 1169cdf0e10cSrcweir Sequence< ScriptEventDescriptor > aEvents( xEventManager->getScriptEvents( nObjectIndex ) ); 1170cdf0e10cSrcweir 1171cdf0e10cSrcweir // is there already a registered script for this event? 1172cdf0e10cSrcweir ScriptEventDescriptor* pEvent = aEvents.getArray(); 1173cdf0e10cSrcweir sal_Int32 eventCount = aEvents.getLength(), event = 0; 1174cdf0e10cSrcweir for ( event = 0; event < eventCount; ++event, ++pEvent ) 1175cdf0e10cSrcweir { 1176cdf0e10cSrcweir if ( ( pEvent->EventMethod == _rScriptEvent.EventMethod ) 1177cdf0e10cSrcweir && ( lcl_endsWith( _rScriptEvent.ListenerType, pEvent->ListenerType ) ) 1178cdf0e10cSrcweir // (strange enough, the events we get from getScriptEvents are not fully qualified) 1179cdf0e10cSrcweir ) 1180cdf0e10cSrcweir { 1181cdf0e10cSrcweir // yes 1182cdf0e10cSrcweir if ( !bResetScript ) 1183cdf0e10cSrcweir { 1184cdf0e10cSrcweir // set to something non-empty -> overwrite 1185cdf0e10cSrcweir pEvent->ScriptCode = sScriptCode; 1186cdf0e10cSrcweir pEvent->ScriptType = sScriptType; 1187cdf0e10cSrcweir } 1188cdf0e10cSrcweir else 1189cdf0e10cSrcweir { 1190cdf0e10cSrcweir // set to empty -> remove from sequence 1191cdf0e10cSrcweir ::std::copy( pEvent + 1, aEvents.getArray() + eventCount, pEvent ); 1192cdf0e10cSrcweir aEvents.realloc( eventCount - 1 ); 1193cdf0e10cSrcweir --eventCount; 1194cdf0e10cSrcweir } 1195cdf0e10cSrcweir break; 1196cdf0e10cSrcweir } 1197cdf0e10cSrcweir } 1198cdf0e10cSrcweir if ( ( event >= eventCount ) && !bResetScript ) 1199cdf0e10cSrcweir { 1200cdf0e10cSrcweir // no, did not find it -> append 1201cdf0e10cSrcweir aEvents.realloc( eventCount + 1 ); 1202cdf0e10cSrcweir aEvents[ eventCount ] = _rScriptEvent; 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir xEventManager->revokeScriptEvents( nObjectIndex ); 1206cdf0e10cSrcweir xEventManager->registerScriptEvents( nObjectIndex, aEvents ); 1207cdf0e10cSrcweir 1208cdf0e10cSrcweir PropertyHandlerHelper::setContextDocumentModified( m_aContext ); 1209cdf0e10cSrcweir } 1210cdf0e10cSrcweir catch( const Exception& ) 1211cdf0e10cSrcweir { 1212cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1213cdf0e10cSrcweir } 1214cdf0e10cSrcweir } 1215cdf0e10cSrcweir 1216cdf0e10cSrcweir //-------------------------------------------------------------------- 1217cdf0e10cSrcweir void EventHandler::impl_setDialogElementScriptEvent_nothrow( const ScriptEventDescriptor& _rScriptEvent ) 1218cdf0e10cSrcweir { 1219cdf0e10cSrcweir try 1220cdf0e10cSrcweir { 1221cdf0e10cSrcweir ::rtl::OUString sScriptCode( _rScriptEvent.ScriptCode ); 1222cdf0e10cSrcweir bool bResetScript = ( sScriptCode.getLength() == 0 ); 1223cdf0e10cSrcweir 1224cdf0e10cSrcweir Reference< XScriptEventsSupplier > xEventsSupplier( m_xComponent, UNO_QUERY_THROW ); 1225cdf0e10cSrcweir Reference< XNameContainer > xEvents( xEventsSupplier->getEvents(), UNO_QUERY_THROW ); 1226cdf0e10cSrcweir 1227cdf0e10cSrcweir ::rtl::OUStringBuffer aCompleteName; 1228cdf0e10cSrcweir aCompleteName.append( _rScriptEvent.ListenerType ); 1229cdf0e10cSrcweir aCompleteName.appendAscii( "::" ); 1230cdf0e10cSrcweir aCompleteName.append( _rScriptEvent.EventMethod ); 1231cdf0e10cSrcweir ::rtl::OUString sCompleteName( aCompleteName.makeStringAndClear() ); 1232cdf0e10cSrcweir 1233cdf0e10cSrcweir bool bExists = xEvents->hasByName( sCompleteName ); 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir if ( bResetScript ) 1236cdf0e10cSrcweir { 1237cdf0e10cSrcweir if ( bExists ) 1238cdf0e10cSrcweir xEvents->removeByName( sCompleteName ); 1239cdf0e10cSrcweir } 1240cdf0e10cSrcweir else 1241cdf0e10cSrcweir { 1242cdf0e10cSrcweir Any aNewValue; aNewValue <<= _rScriptEvent; 1243cdf0e10cSrcweir 1244cdf0e10cSrcweir if ( bExists ) 1245cdf0e10cSrcweir xEvents->replaceByName( sCompleteName, aNewValue ); 1246cdf0e10cSrcweir else 1247cdf0e10cSrcweir xEvents->insertByName( sCompleteName, aNewValue ); 1248cdf0e10cSrcweir } 1249cdf0e10cSrcweir } 1250cdf0e10cSrcweir catch( const Exception& ) 1251cdf0e10cSrcweir { 1252cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1253cdf0e10cSrcweir } 1254cdf0e10cSrcweir } 1255cdf0e10cSrcweir 1256cdf0e10cSrcweir //-------------------------------------------------------------------- 1257cdf0e10cSrcweir bool EventHandler::impl_filterMethod_nothrow( const EventDescription& _rEvent ) const 1258cdf0e10cSrcweir { 1259cdf0e10cSrcweir // some (control-triggered) events do not make sense for certain grid control columns. However, 1260cdf0e10cSrcweir // our mechnism to retrieve control-triggered events does not know about this, so we do some 1261cdf0e10cSrcweir // late filtering here. 1262cdf0e10cSrcweir switch ( m_nGridColumnType ) 1263cdf0e10cSrcweir { 1264cdf0e10cSrcweir case FormComponentType::COMBOBOX: 1265cdf0e10cSrcweir if ( UID_BRWEVT_ACTIONPERFORMED == _rEvent.sUniqueBrowseId ) 1266cdf0e10cSrcweir return false; 1267cdf0e10cSrcweir break; 1268cdf0e10cSrcweir case FormComponentType::LISTBOX: 1269cdf0e10cSrcweir if ( ( UID_BRWEVT_CHANGED == _rEvent.sUniqueBrowseId ) 1270cdf0e10cSrcweir || ( UID_BRWEVT_ACTIONPERFORMED == _rEvent.sUniqueBrowseId ) 1271cdf0e10cSrcweir ) 1272cdf0e10cSrcweir return false; 1273cdf0e10cSrcweir break; 1274cdf0e10cSrcweir } 1275cdf0e10cSrcweir 1276cdf0e10cSrcweir return true; 1277cdf0e10cSrcweir } 1278cdf0e10cSrcweir 1279cdf0e10cSrcweir //........................................................................ 1280cdf0e10cSrcweir } // namespace pcr 1281cdf0e10cSrcweir //........................................................................ 1282cdf0e10cSrcweir 1283