22#include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
23#include <com/sun/star/util/URLTransformer.hpp>
24#include <com/sun/star/util/XURLTransformer.hpp>
25#include <com/sun/star/frame/XModel.hpp>
26#include <com/sun/star/frame/XDispatchProvider.hpp>
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::UNO_QUERY;
38 using ::com::sun::star::uno::UNO_QUERY_THROW;
39 using ::com::sun::star::uno::UNO_SET_THROW;
40 using ::com::sun::star::uno::Exception;
41 using ::com::sun::star::uno::RuntimeException;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::WeakReference;
44 using ::com::sun::star::uno::XComponentContext;
45 using ::com::sun::star::document::XDocumentEventBroadcaster;
46 using ::com::sun::star::document::XEventsSupplier;
47 using ::com::sun::star::container::XNameAccess;
48 using ::com::sun::star::frame::XModel;
49 using ::com::sun::star::util::URLTransformer;
50 using ::com::sun::star::util::XURLTransformer;
51 using ::com::sun::star::frame::XDispatchProvider;
52 using ::com::sun::star::frame::XDispatch;
53 using ::com::sun::star::util::URL;
54 using ::com::sun::star::beans::PropertyValue;
55 using ::com::sun::star::frame::XController;
56 using ::com::sun::star::document::DocumentEvent;
62 void lcl_dispatchScriptURL_throw(
63 css::uno::WeakReference< css::document::XEventsSupplier >
const & xWeakDocument,
64 css::uno::Reference< css::util::XURLTransformer >
const & xURLTransformer,
65 const OUString& _rScriptURL,
const DocumentEvent& _rTrigger )
67 Reference< XModel > xDocument( xWeakDocument.get(), UNO_QUERY_THROW );
69 Reference< XController >
xController( xDocument->getCurrentController() );
70 Reference< XDispatchProvider > xDispProv;
72 xDispProv.set(
xController->getFrame(), UNO_QUERY );
73 if ( !xDispProv.is() )
75 OSL_FAIL(
"lcl_dispatchScriptURL_throw: no controller/frame? How should I dispatch?" );
80 aScriptURL.Complete = _rScriptURL;
81 if ( xURLTransformer.is() )
82 xURLTransformer->parseStrict( aScriptURL );
89 Reference< XDispatch >
xDispatch( xDispProv->queryDispatch( aScriptURL, OUString(), 0 ) );
92 OSL_FAIL(
"lcl_dispatchScriptURL_throw: no dispatcher for the script URL!" );
96 PropertyValue aEventParam;
97 aEventParam.Value <<= _rTrigger;
98 Sequence< PropertyValue > aDispatchArgs( &aEventParam, 1 );
99 xDispatch->dispatch( aScriptURL, aDispatchArgs );
105 const Reference< XEventsSupplier >& _rxDocument )
106 :mxDocument( _rxDocument )
112 xBroadcaster->addDocumentEventListener(
this );
132 Reference< XEventsSupplier > xEventsSupplier(
mxDocument.get(), UNO_QUERY );
133 if ( !xEventsSupplier )
135 OSL_FAIL(
"DocumentEventExecutor::documentEventOccurred: no document anymore, but still being notified?" );
139 Reference< XModel > xDocument( xEventsSupplier, UNO_QUERY_THROW );
143 Reference< XNameAccess > xDocEvents( xEventsSupplier->getEvents(), UNO_SET_THROW );
144 if ( !xDocEvents->hasByName( Event.EventName ) )
148 OSL_FAIL(
"DocumentEventExecutor::documentEventOccurred: an unsupported event is notified!" );
152 const ::comphelper::NamedValueCollection aScriptDescriptor( xDocEvents->getByName( Event.EventName ) );
155 bool bScriptAssigned = aScriptDescriptor.get_ensureType(
"EventType",
sEventType );
158 bScriptAssigned = bScriptAssigned && aScriptDescriptor.get_ensureType(
"Script",
sScript );
160 if ( !bScriptAssigned )
165 bool bNonEmptyScript = !
sScript.isEmpty();
167 OSL_ENSURE( bDispatchScriptURL && bNonEmptyScript,
168 "DocumentEventExecutor::documentEventOccurred: invalid/unsupported script descriptor" );
170 if ( bDispatchScriptURL && bNonEmptyScript )
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
css::uno::WeakReference< css::document::XEventsSupplier > mxDocument
DocumentEventExecutor(const css::uno::Reference< css::uno::XComponentContext > &_rContext, const css::uno::Reference< css::document::XEventsSupplier > &_rxDocument)
css::uno::Reference< css::util::XURLTransformer > mxURLTransformer
virtual void SAL_CALL documentEventOccured(const css::document::DocumentEvent &Event) override
virtual ~DocumentEventExecutor() override
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XDispatch > xDispatch
Reference< XController > xController
the controller of the sub component. Must not be <NULL>
constexpr OUStringLiteral sScript
constexpr OUStringLiteral sEventType