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/uri/UriReferenceFactory.hpp>
50#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp>
60#include <rtl/ustrbuf.hxx>
73 using ::com::sun::star::uno::Reference;
74 using ::com::sun::star::uno::XComponentContext;
75 using ::com::sun::star::uno::Any;
76 using ::com::sun::star::uno::TypeClass_STRING;
77 using ::com::sun::star::uno::Type;
78 using ::com::sun::star::beans::theIntrospection;
79 using ::com::sun::star::beans::XPropertyChangeListener;
80 using ::com::sun::star::beans::Property;
81 using ::com::sun::star::beans::PropertyState;
82 using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
83 using ::com::sun::star::uno::Sequence;
84 using ::com::sun::star::script::ScriptEventDescriptor;
85 using ::com::sun::star::script::XScriptEventsSupplier;
86 using ::com::sun::star::lang::NullPointerException;
87 using ::com::sun::star::uno::Exception;
88 using ::com::sun::star::container::XChild;
89 using ::com::sun::star::container::XIndexAccess;
90 using ::com::sun::star::script::XEventAttacherManager;
91 using ::com::sun::star::uno::UNO_QUERY;
92 using ::com::sun::star::uno::UNO_QUERY_THROW;
93 using ::com::sun::star::uno::XInterface;
94 using ::com::sun::star::beans::XIntrospection;
95 using ::com::sun::star::beans::XIntrospectionAccess;
96 using ::com::sun::star::container::XNameContainer;
97 using ::com::sun::star::awt::XTabControllerModel;
98 using ::com::sun::star::form::XForm;
99 using ::com::sun::star::form::runtime::FormController;
100 using ::com::sun::star::form::runtime::XFormController;
101 using ::com::sun::star::beans::UnknownPropertyException;
102 using ::com::sun::star::container::NoSuchElementException;
103 using ::com::sun::star::beans::XPropertySetInfo;
104 using ::com::sun::star::container::XNameReplace;
105 using ::com::sun::star::beans::PropertyValue;
106 using ::com::sun::star::inspection::LineDescriptor;
107 using ::com::sun::star::inspection::XPropertyControlFactory;
108 using ::com::sun::star::inspection::InteractiveSelectionResult;
109 using ::com::sun::star::inspection::InteractiveSelectionResult_Cancelled;
110 using ::com::sun::star::inspection::InteractiveSelectionResult_Success;
111 using ::com::sun::star::inspection::XObjectInspectorUI;
112 using ::com::sun::star::beans::PropertyChangeEvent;
113 using ::com::sun::star::frame::XFrame;
114 using ::com::sun::star::frame::XModel;
115 using ::com::sun::star::frame::XController;
116 using ::com::sun::star::uno::UNO_SET_THROW;
117 using com::sun::star::uri::UriReferenceFactory;
118 using com::sun::star::uri::XUriReferenceFactory;
119 using com::sun::star::uri::XVndSunStarScriptUrlReference;
121 namespace PropertyControlType = css::inspection::PropertyControlType;
122 namespace PropertyAttribute = css::beans::PropertyAttribute;
123 namespace FormComponentType = css::form::FormComponentType;
126 std::u16string_view listenerMethodName,
TranslateId pDisplayNameResId, OUString _sHelpId, OString _sUniqueBrowseId )
128 ,sListenerClassName( listenerClassName )
129 ,sListenerMethodName( listenerMethodName )
130 ,sHelpId(
std::move( _sHelpId ))
131 ,sUniqueBrowseId(
std::move( _sUniqueBrowseId ))
138 #define DESCRIBE_EVENT( map, listener, method, id_postfix ) \
141 EventDescription( ++nEventId, u"com.sun.star." listener, u"" method, RID_STR_EVT_##id_postfix, HID_EVT_##id_postfix, UID_BRWEVT_##id_postfix ) )
143 bool lcl_getEventDescriptionForMethod(
const OUString& _rMethodName,
EventDescription& _out_rDescription )
145 static EventMap s_aKnownEvents = []() {
147 sal_Int32 nEventId = 0;
149 DESCRIBE_EVENT(
aMap,
"form.XApproveActionListener",
"approveAction", APPROVEACTIONPERFORMED);
175 DESCRIBE_EVENT(
aMap,
"sdb.XRowSetApproveListener",
"approveRowChange", APPROVEROWCHANGE);
179 DESCRIBE_EVENT(
aMap,
"form.XDatabaseParameterListener",
"approveParameter", APPROVEPARAMETER);
181 DESCRIBE_EVENT(
aMap,
"awt.XAdjustmentListener",
"adjustmentValueChanged", ADJUSTMENTVALUECHANGED);
186 EventMap::const_iterator
pos = s_aKnownEvents.find( _rMethodName );
187 if (
pos == s_aKnownEvents.end() )
190 _out_rDescription =
pos->second;
194 OUString lcl_getEventPropertyName( std::u16string_view _rListenerClassName, std::u16string_view _rMethodName )
196 return _rListenerClassName + OUStringChar(
';') + _rMethodName;
199 ScriptEventDescriptor lcl_getAssignedScriptEvent(
const EventDescription& _rEvent,
const std::vector< ScriptEventDescriptor >& _rAllAssignedMacros )
201 ScriptEventDescriptor aScriptEvent;
204 aScriptEvent.ListenerType = _rEvent.sListenerClassName;
205 aScriptEvent.EventMethod = _rEvent.sListenerMethodName;
207 for (
const ScriptEventDescriptor& rSED : _rAllAssignedMacros )
209 if ( rSED.ListenerType != _rEvent.sListenerClassName
210 || rSED.EventMethod != _rEvent.sListenerMethodName
214 if ( rSED.ScriptCode.isEmpty()
215 || rSED.ScriptType.isEmpty()
218 OSL_FAIL(
"lcl_getAssignedScriptEvent: me thinks this should not happen!" );
224 if ( aScriptEvent.ScriptType !=
"StarBasic" )
232 sal_Int32 nPrefixLen = aScriptEvent.ScriptCode.indexOf(
':' );
233 OSL_ENSURE( nPrefixLen > 0,
"lcl_getAssignedScriptEvent: illegal location!" );
234 std::u16string_view sLocation = aScriptEvent.ScriptCode.subView( 0, nPrefixLen );
235 std::u16string_view sMacroPath = aScriptEvent.ScriptCode.subView( nPrefixLen + 1 );
237 aScriptEvent.ScriptCode =
238 OUString::Concat(
"vnd.sun.star.script:") +
240 "?language=Basic&location=" +
244 aScriptEvent.ScriptType =
"Script";
249 OUString lcl_getQualifiedKnownListenerName(
const ScriptEventDescriptor& _rFormComponentEventDescriptor )
252 if ( lcl_getEventDescriptionForMethod( _rFormComponentEventDescriptor.EventMethod, aKnownEvent ) )
253 return aKnownEvent.sListenerClassName;
254 OSL_FAIL(
"lcl_getQualifiedKnownListenerName: unknown method name!" );
259 return _rFormComponentEventDescriptor.ListenerType;
262 typedef std::set< Type, TypeLessByName >
TypeBag;
265 const Reference< XIntrospection >& _rxIntrospection,
TypeBag& _out_rTypes )
267 if ( !_rxComponent.is() )
269 OSL_PRECOND( _rxIntrospection.is(),
"lcl_addListenerTypesFor_throw: this will crash!" );
271 Reference< XIntrospectionAccess > xIntrospectionAccess(
272 _rxIntrospection->inspect(
Any( _rxComponent ) ), UNO_SET_THROW );
277 std::insert_iterator< TypeBag >( _out_rTypes, _out_rTypes.begin() ) );
281 typedef ::cppu::WeakImplHelper < css::container::XNameReplace
290 typedef std::unordered_map< OUString, ScriptEventDescriptor >
EventMap;
291 typedef std::map< EventId, OUString > EventMapIndexAccess;
294 EventMapIndexAccess m_aEventIndexAccess;
299 void addEvent(
EventId _nId,
const OUString& _rEventName,
const ScriptEventDescriptor& _rScriptEvent );
304 ScriptEventDescriptor getNormalizedDescriptorByName(
const OUString& _rEventName )
const;
307 virtual void SAL_CALL replaceByName(
const OUString& _rName,
const Any& aElement )
override;
308 virtual Any SAL_CALL getByName(
const OUString& _rName )
override;
309 virtual Sequence< OUString > SAL_CALL getElementNames( )
override;
310 virtual sal_Bool SAL_CALL hasByName(
const OUString& _rName )
override;
311 virtual Type SAL_CALL getElementType( )
override;
312 virtual sal_Bool SAL_CALL hasElements( )
override;
315 virtual ~EventHolder( )
override;
318 ScriptEventDescriptor
const & impl_getDescriptor_throw(
const OUString& _rEventName )
const;
323 EventHolder::EventHolder()
327 EventHolder::~EventHolder()
329 m_aEventNameAccess.clear();
330 m_aEventIndexAccess.clear();
333 void EventHolder::addEvent(
EventId _nId,
const OUString& _rEventName,
const ScriptEventDescriptor& _rScriptEvent )
335 std::pair< EventMap::iterator, bool > insertionResult =
336 m_aEventNameAccess.emplace( _rEventName, _rScriptEvent );
337 OSL_ENSURE( insertionResult.second,
"EventHolder::addEvent: there already was a MacroURL for this event!" );
338 m_aEventIndexAccess[ _nId ] = _rEventName;
341 ScriptEventDescriptor EventHolder::getNormalizedDescriptorByName(
const OUString& _rEventName )
const
343 return impl_getDescriptor_throw( _rEventName );
346 ScriptEventDescriptor
const & EventHolder::impl_getDescriptor_throw(
const OUString& _rEventName )
const
348 EventMap::const_iterator
pos = m_aEventNameAccess.find( _rEventName );
349 if ( pos == m_aEventNameAccess.end() )
350 throw NoSuchElementException( OUString(), *
const_cast< EventHolder*
>(
this ) );
354 void SAL_CALL EventHolder::replaceByName(
const OUString& _rName,
const Any& _rElement )
356 EventMap::iterator
pos = m_aEventNameAccess.find( _rName );
357 if ( pos == m_aEventNameAccess.end() )
358 throw NoSuchElementException( OUString(), *
this );
360 Sequence< PropertyValue > aScriptDescriptor;
361 OSL_VERIFY( _rElement >>= aScriptDescriptor );
365 pos->second.ScriptType = aExtractor.getOrDefault(
"EventType", OUString() );
366 pos->second.ScriptCode = aExtractor.getOrDefault(
"Script", OUString() );
369 Any SAL_CALL EventHolder::getByName(
const OUString& _rName )
371 ScriptEventDescriptor aDescriptor( impl_getDescriptor_throw( _rName ) );
373 Sequence< PropertyValue > aScriptDescriptor{
378 return Any( aScriptDescriptor );
381 Sequence< OUString > SAL_CALL EventHolder::getElementNames( )
383 Sequence< OUString > aReturn( m_aEventIndexAccess.size() );
384 OUString* pReturn = aReturn.getArray();
395 for (
auto const& elem : m_aEventIndexAccess)
397 *pReturn = elem.second;
403 sal_Bool SAL_CALL EventHolder::hasByName(
const OUString& _rName )
405 EventMap::const_iterator
pos = m_aEventNameAccess.find( _rName );
406 return pos != m_aEventNameAccess.end();
409 Type SAL_CALL EventHolder::getElementType( )
414 sal_Bool SAL_CALL EventHolder::hasElements( )
416 return !m_aEventNameAccess.empty();
424 ,m_bEventsMapInitialized( false )
425 ,m_bIsDialogElement( false )
426 ,m_nGridColumnType( -1 )
430 EventHandler::~EventHandler()
434 OUString SAL_CALL EventHandler::getImplementationName( )
436 return "com.sun.star.comp.extensions.EventHandler";
439 sal_Bool SAL_CALL EventHandler::supportsService(
const OUString& ServiceName )
444 Sequence< OUString > SAL_CALL EventHandler::getSupportedServiceNames( )
446 return {
"com.sun.star.form.inspection.EventHandler" };
451 ::osl::MutexGuard aGuard(
m_aMutex );
453 if ( !_rxIntrospectee.is() )
454 throw NullPointerException();
456 m_xComponent.set( _rxIntrospectee, UNO_QUERY_THROW );
458 m_bEventsMapInitialized =
false;
461 m_bIsDialogElement =
false;
462 m_nGridColumnType = -1;
465 Reference< XPropertySetInfo > xPSI( m_xComponent->getPropertySetInfo() );
466 m_bIsDialogElement = xPSI.is()
472 Reference< XChild > xAsChild( _rxIntrospectee, UNO_QUERY );
473 if ( xAsChild.is() && !Reference< XForm >( _rxIntrospectee, UNO_QUERY ).is() )
475 if ( FormComponentType::GRIDCONTROL ==
classifyComponent( xAsChild->getParent() ) )
487 Any SAL_CALL EventHandler::getPropertyValue(
const OUString& _rPropertyName )
489 ::osl::MutexGuard aGuard(
m_aMutex );
491 const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName );
493 std::vector< ScriptEventDescriptor > aEvents;
494 impl_getComponentScriptEvents_nothrow( aEvents );
496 ScriptEventDescriptor aPropertyValue;
497 for (
const ScriptEventDescriptor& rSCD : aEvents )
503 aPropertyValue = rSCD;
508 return Any( aPropertyValue );
511 void SAL_CALL EventHandler::setPropertyValue(
const OUString& _rPropertyName,
const Any& _rValue )
513 ::osl::MutexGuard aGuard(
m_aMutex );
515 const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName );
517 ScriptEventDescriptor aNewScriptEvent;
518 OSL_VERIFY( _rValue >>= aNewScriptEvent );
520 ScriptEventDescriptor aOldScriptEvent;
522 if ( aOldScriptEvent == aNewScriptEvent )
525 if ( m_bIsDialogElement )
526 impl_setDialogElementScriptEvent_nothrow( aNewScriptEvent );
528 impl_setFormComponentScriptEvent_nothrow( aNewScriptEvent );
530 PropertyHandlerHelper::setContextDocumentModified(
m_xContext );
532 PropertyChangeEvent
aEvent;
533 aEvent.Source = m_xComponent;
535 aEvent.PropertyName = _rPropertyName;
536 aEvent.OldValue <<= aOldScriptEvent;
537 aEvent.NewValue <<= aNewScriptEvent;
538 m_aPropertyListeners.notifyEach( &XPropertyChangeListener::propertyChange,
aEvent );
541 Any SAL_CALL EventHandler::convertToPropertyValue(
const OUString& _rPropertyName,
const Any& _rControlValue )
543 ::osl::MutexGuard aGuard(
m_aMutex );
545 OUString sNewScriptCode;
546 OSL_VERIFY( _rControlValue >>= sNewScriptCode );
548 std::vector< ScriptEventDescriptor > aAllAssignedEvents;
549 impl_getComponentScriptEvents_nothrow( aAllAssignedEvents );
551 const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName );
552 ScriptEventDescriptor aAssignedScript = lcl_getAssignedScriptEvent( rEvent, aAllAssignedEvents );
554 OSL_ENSURE( sNewScriptCode.isEmpty(),
"EventHandler::convertToPropertyValue: cannot convert a non-empty display name!" );
564 aAssignedScript.ScriptCode = sNewScriptCode;
565 return Any( aAssignedScript );
568 Any SAL_CALL EventHandler::convertToControlValue(
const OUString& ,
const Any& _rPropertyValue,
const Type& _rControlValueType )
570 ::osl::MutexGuard aGuard(
m_aMutex );
572 ScriptEventDescriptor aScriptEvent;
573 OSL_VERIFY( _rPropertyValue >>= aScriptEvent );
575 OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING,
576 "EventHandler::convertToControlValue: unexpected ControlValue type class!" );
578 OUString
sScript( aScriptEvent.ScriptCode );
585 Reference< XUriReferenceFactory > xUriRefFac = UriReferenceFactory::create(
m_xContext );
586 Reference< XVndSunStarScriptUrlReference > xScriptUri( xUriRefFac->parse(
sScript ), UNO_QUERY_THROW );
588 OUStringBuffer aComposeBuffer;
591 aComposeBuffer.append( xScriptUri->getName() );
594 const OUString sLocation = xScriptUri->getParameter(
"location" );
595 const OUString sLanguage = xScriptUri->getParameter(
"language" );
597 if ( !(sLocation.isEmpty() && sLanguage.isEmpty()) )
599 aComposeBuffer.append(
" (" );
602 OSL_ENSURE( !sLocation.isEmpty(),
"EventHandler::convertToControlValue: unexpected: no location!" );
603 if ( !sLocation.isEmpty() )
605 aComposeBuffer.append( sLocation +
", " );
609 if ( !sLanguage.isEmpty() )
611 aComposeBuffer.append( sLanguage );
614 aComposeBuffer.append(
')' );
617 sScript = aComposeBuffer.makeStringAndClear();
628 PropertyState SAL_CALL EventHandler::getPropertyState(
const OUString& )
630 return PropertyState_DIRECT_VALUE;
633 void SAL_CALL EventHandler::addPropertyChangeListener(
const Reference< XPropertyChangeListener >& _rxListener )
635 ::osl::MutexGuard aGuard(
m_aMutex );
636 if ( !_rxListener.is() )
637 throw NullPointerException();
638 m_aPropertyListeners.addInterface( _rxListener );
641 void SAL_CALL EventHandler::removePropertyChangeListener(
const Reference< XPropertyChangeListener >& _rxListener )
643 ::osl::MutexGuard aGuard(
m_aMutex );
644 m_aPropertyListeners.removeInterface( _rxListener );
647 Sequence< Property > SAL_CALL EventHandler::getSupportedProperties()
649 ::osl::MutexGuard aGuard(
m_aMutex );
650 if ( !m_bEventsMapInitialized )
652 m_bEventsMapInitialized =
true;
656 impl_getComponentListenerTypes_nothrow(
aListeners );
658 OUString sListenerClassName;
664 sListenerClassName = rListener.getTypeName();
665 OSL_ENSURE( !sListenerClassName.isEmpty(),
"EventHandler::getSupportedProperties: strange - no listener name ..." );
666 if ( sListenerClassName.isEmpty() )
671 for (
const OUString& rMethod : aEventMethods)
674 if ( !lcl_getEventDescriptionForMethod( rMethod,
aEvent ) )
677 if ( !impl_filterMethod_nothrow(
aEvent ) )
681 lcl_getEventPropertyName( sListenerClassName, rMethod ),
aEvent );
693 std::map< EventId, Property > aOrderedProperties;
694 for (
auto const& event : m_aEvents)
696 aOrderedProperties[
event.second.nId ] =
Property(
697 event.first, event.second.nId,
699 PropertyAttribute::BOUND );
705 Sequence< OUString > SAL_CALL EventHandler::getSupersededProperties( )
708 return Sequence< OUString >( );
711 Sequence< OUString > SAL_CALL EventHandler::getActuatingProperties( )
714 return Sequence< OUString >( );
717 LineDescriptor SAL_CALL EventHandler::describePropertyLine(
const OUString& _rPropertyName,
718 const Reference< XPropertyControlFactory >& _rxControlFactory )
720 if ( !_rxControlFactory.is() )
721 throw NullPointerException();
723 ::osl::MutexGuard aGuard(
m_aMutex );
725 LineDescriptor aDescriptor;
727 aDescriptor.Control = _rxControlFactory->createPropertyControl( PropertyControlType::TextField,
true );
730 const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName );
732 aDescriptor.HelpURL = HelpIdUrl::getHelpURL( rEvent.
sHelpId );
733 aDescriptor.PrimaryButtonId = OStringToOUString(rEvent.
sUniqueBrowseId, RTL_TEXTENCODING_UTF8);
734 aDescriptor.HasPrimaryButton =
true;
735 aDescriptor.Category =
"Events";
739 sal_Bool SAL_CALL EventHandler::isComposable(
const OUString& )
744 InteractiveSelectionResult SAL_CALL EventHandler::onInteractivePropertySelection(
const OUString& _rPropertyName,
sal_Bool , Any& ,
const Reference< XObjectInspectorUI >& _rxInspectorUI )
746 if ( !_rxInspectorUI.is() )
747 throw NullPointerException();
749 ::osl::MutexGuard aGuard(
m_aMutex );
750 const EventDescription& rForEvent = impl_getEventForName_throw( _rPropertyName );
752 std::vector< ScriptEventDescriptor > aAllAssignedEvents;
753 impl_getComponentScriptEvents_nothrow( aAllAssignedEvents );
758 for (
auto const& event : m_aEvents)
761 ScriptEventDescriptor aAssignedScript = lcl_getAssignedScriptEvent( event.second, aAllAssignedEvents );
762 pEventHolder->addEvent( event.second.nId, event.second.sListenerMethodName, aAssignedScript );
766 const Sequence< OUString > aNames( pEventHolder->getElementNames() );
767 const OUString* pChosenEvent = std::find( aNames.begin(), aNames.end(), rForEvent.
sListenerMethodName );
768 sal_uInt16 nInitialSelection =
static_cast<sal_uInt16
>( pChosenEvent - aNames.begin() );
774 PropertyHandlerHelper::getDialogParentFrame(
m_xContext ),
775 impl_getContextFrame_nothrow(),
782 return InteractiveSelectionResult_Cancelled;
787 return InteractiveSelectionResult_Cancelled;
791 for (
auto const& event : m_aEvents)
793 ScriptEventDescriptor aScriptDescriptor( pEventHolder->getNormalizedDescriptorByName( event.second.sListenerMethodName ) );
797 lcl_getEventPropertyName( event.second.sListenerClassName, event.second.sListenerMethodName ),
798 Any( aScriptDescriptor )
807 return InteractiveSelectionResult_Success;
810 void SAL_CALL EventHandler::actuatingPropertyChanged(
const OUString& ,
const Any& ,
const Any& ,
const Reference< XObjectInspectorUI >& ,
sal_Bool )
812 OSL_FAIL(
"EventHandler::actuatingPropertyChanged: no actuating properties -> no callback (well, this is how it *should* be!)" );
820 m_xComponent.clear();
828 Reference< XFrame > EventHandler::impl_getContextFrame_nothrow()
const
830 Reference< XFrame > xContextFrame;
834 Reference< XModel > xContextDocument( PropertyHandlerHelper::getContextDocument(
m_xContext), UNO_QUERY_THROW );
835 Reference< XController >
xController( xContextDocument->getCurrentController(), UNO_SET_THROW );
836 xContextFrame.set(
xController->getFrame(), UNO_SET_THROW );
843 return xContextFrame;
846 sal_Int32 EventHandler::impl_getComponentIndexInParent_throw()
const
848 Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW );
849 Reference< XIndexAccess > xParentAsIndexAccess( xChild->getParent(), UNO_QUERY_THROW );
852 sal_Int32
nElements = xParentAsIndexAccess->getCount();
856 if ( xElement == m_xComponent )
859 throw NoSuchElementException();
862 void EventHandler::impl_getFormComponentScriptEvents_nothrow( std::vector < ScriptEventDescriptor >& _out_rEvents )
const
864 _out_rEvents.clear();
867 Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW );
868 Reference< XEventAttacherManager > xEventManager( xChild->getParent(), UNO_QUERY_THROW );
873 for ( ScriptEventDescriptor& rSED : _out_rEvents)
875 rSED.ListenerType = lcl_getQualifiedKnownListenerName( rSED );
884 void EventHandler::impl_getComponentListenerTypes_nothrow( std::vector< Type >& _out_rTypes )
const
895 lcl_addListenerTypesFor_throw(
902 ::comphelper::disposeComponent( xSecondaryComponent );
914 void EventHandler::impl_getDialogElementScriptEvents_nothrow( std::vector < ScriptEventDescriptor >& _out_rEvents )
const
916 _out_rEvents.clear();
919 Reference< XScriptEventsSupplier > xEventsSupplier( m_xComponent, UNO_QUERY_THROW );
920 Reference< XNameContainer > xEvents( xEventsSupplier->getEvents(), UNO_SET_THROW );
921 Sequence< OUString > aEventNames( xEvents->getElementNames() );
923 sal_Int32 nEventCount = aEventNames.getLength();
924 _out_rEvents.resize( nEventCount );
926 for( sal_Int32
i = 0;
i < nEventCount; ++
i )
927 OSL_VERIFY( xEvents->getByName( aEventNames[
i] ) >>= _out_rEvents[
i] );
940 Reference< XForm > xComponentAsForm( m_xComponent, UNO_QUERY );
941 if ( xComponentAsForm.is() )
943 Reference< XTabControllerModel > xComponentAsTCModel( m_xComponent, UNO_QUERY_THROW );
951 OUString sControlService;
954 xReturn =
m_xContext->getServiceManager()->createInstanceWithContext( sControlService,
m_xContext );
959 const EventDescription& EventHandler::impl_getEventForName_throw(
const OUString& _rPropertyName )
const
961 EventMap::const_iterator
pos = m_aEvents.find( _rPropertyName );
962 if (
pos == m_aEvents.end() )
963 throw UnknownPropertyException(_rPropertyName);
969 bool lcl_endsWith( std::u16string_view _rText, std::u16string_view _rCheck )
971 size_t nTextLen = _rText.size();
972 size_t nCheckLen = _rCheck.size();
973 if ( nCheckLen > nTextLen )
976 return _rText.find( _rCheck ) == ( nTextLen - nCheckLen );
980 void EventHandler::impl_setFormComponentScriptEvent_nothrow(
const ScriptEventDescriptor& _rScriptEvent )
984 OUString sScriptCode( _rScriptEvent.ScriptCode );
985 OUString sScriptType( _rScriptEvent.ScriptType );
986 bool bResetScript = sScriptCode.isEmpty();
988 sal_Int32 nObjectIndex = impl_getComponentIndexInParent_throw();
989 Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW );
990 Reference< XEventAttacherManager > xEventManager( xChild->getParent(), UNO_QUERY_THROW );
991 std::vector< ScriptEventDescriptor > aEvents;
995 sal_Int32 eventCount = aEvents.size(),
event = 0;
996 for ( event = 0;
event < eventCount; ++event )
998 ScriptEventDescriptor* pEvent = &aEvents[event];
999 if ( ( pEvent->EventMethod == _rScriptEvent.EventMethod )
1000 && ( lcl_endsWith( _rScriptEvent.ListenerType, pEvent->ListenerType ) )
1005 if ( !bResetScript )
1008 pEvent->ScriptCode = sScriptCode;
1009 pEvent->ScriptType = sScriptType;
1014 aEvents.erase(aEvents.begin() + event );
1020 if ( ( event >= eventCount ) && !bResetScript )
1023 aEvents.push_back( _rScriptEvent );
1026 xEventManager->revokeScriptEvents( nObjectIndex );
1029 PropertyHandlerHelper::setContextDocumentModified(
m_xContext );
1037 void EventHandler::impl_setDialogElementScriptEvent_nothrow(
const ScriptEventDescriptor& _rScriptEvent )
1041 OUString sScriptCode( _rScriptEvent.ScriptCode );
1042 bool bResetScript = sScriptCode.isEmpty();
1044 Reference< XScriptEventsSupplier > xEventsSupplier( m_xComponent, UNO_QUERY_THROW );
1045 Reference< XNameContainer > xEvents( xEventsSupplier->getEvents(), UNO_SET_THROW );
1047 OUString sCompleteName =
1048 _rScriptEvent.ListenerType +
1050 _rScriptEvent.EventMethod;
1052 bool bExists = xEvents->hasByName( sCompleteName );
1057 xEvents->removeByName( sCompleteName );
1061 Any aNewValue; aNewValue <<= _rScriptEvent;
1064 xEvents->replaceByName( sCompleteName, aNewValue );
1066 xEvents->insertByName( sCompleteName, aNewValue );
1080 switch ( m_nGridColumnType )
1082 case FormComponentType::COMBOBOX:
1086 case FormComponentType::LISTBOX:
1099extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1101 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
static SvxAbstractDialogFactory * Create()
virtual VclPtr< VclAbstractDialog > CreateSvxMacroAssignDlg(weld::Window *_pParent, const css::uno::Reference< css::frame::XFrame > &_rxDocumentFrame, const bool _bUnoDialogMode, const css::uno::Reference< css::container::XNameReplace > &_rxEvents, const sal_uInt16 _nInitiallySelectedEvent)=0
EventHandler(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
#define DBG_UNHANDLED_EXCEPTION(...)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_propctrlr_EventHandler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define DESCRIBE_EVENT(map, listener, method, id_postfix)
Reference< XComponentContext > m_xContext
Reference< XIntrospection > xIntrospection
Sequence< OUString > getEventMethodsForType(const Type &type)
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::uno::Sequence< typename M::mapped_type > mapValuesToSequence(M const &map)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
std::set< css::uno::Type, UnoTypeLess > TypeBag
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
a property handler for any virtual string properties
::cppu::WeakImplHelper< css::container::XNameReplace > EventHolder_Base
std::unordered_map< OUString, EventDescription > EventMap
sal_Int16 classifyComponent(const Reference< XInterface > &_rxComponent)
OUString PcrRes(TranslateId aId)
::cppu::WeakComponentImplHelper< css::inspection::XPropertyHandler, css::lang::XServiceInfo > EventHandler_Base
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
HashMap_OWString_Interface aMap
#define IMPLEMENT_FORWARD_XCOMPONENT(classname, baseclass)
constexpr OStringLiteral UID_BRWEVT_CHANGED
constexpr OStringLiteral UID_BRWEVT_ACTIONPERFORMED
OUString sListenerClassName
OUString sListenerMethodName
Reference< XController > xController
constexpr OUStringLiteral sScript