LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - eventhandler.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 521 0.0 %
Date: 2014-04-14 Functions: 0 62 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10