summaryrefslogtreecommitdiffstats
path: root/sfx2/source/notify
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sfx2/source/notify
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sfx2/source/notify')
-rw-r--r--sfx2/source/notify/eventsupplier.cxx443
-rw-r--r--sfx2/source/notify/globalevents.cxx548
-rw-r--r--sfx2/source/notify/hintpost.cxx53
-rw-r--r--sfx2/source/notify/openurlhint.cxx32
4 files changed, 1076 insertions, 0 deletions
diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx
new file mode 100644
index 000000000..65a50da3e
--- /dev/null
+++ b/sfx2/source/notify/eventsupplier.cxx
@@ -0,0 +1,443 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#include <com/sun/star/document/XEmbeddedScripts.hpp>
+#include <com/sun/star/document/XScriptInvocationContext.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/util/URLTransformer.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/uno/XInterface.hpp>
+#include <tools/urlobj.hxx>
+#include <tools/diagnose_ex.h>
+#include <svl/macitem.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/evntconf.hxx>
+#include <unotools/eventcfg.hxx>
+#include <sal/log.hxx>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/sequence.hxx>
+#include <eventsupplier.hxx>
+
+#include <sfx2/app.hxx>
+
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/frame.hxx>
+#include <macroloader.hxx>
+
+using namespace css;
+using namespace ::com::sun::star;
+
+
+
+ // --- XNameReplace ---
+
+void SAL_CALL SfxEvents_Impl::replaceByName( const OUString & aName, const uno::Any & rElement )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and replace the data
+ auto nIndex = comphelper::findValue(maEventNames, aName);
+ if (nIndex != -1)
+ {
+ // check for correct type of the element
+ if ( !::comphelper::NamedValueCollection::canExtractFrom( rElement ) )
+ throw lang::IllegalArgumentException();
+ ::comphelper::NamedValueCollection const aEventDescriptor( rElement );
+
+ // create Configuration at first, creation might call this method also and that would overwrite everything
+ // we might have stored before!
+ if ( mpObjShell && !mpObjShell->IsLoading() )
+ mpObjShell->SetModified();
+
+ ::comphelper::NamedValueCollection aNormalizedDescriptor;
+ NormalizeMacro( aEventDescriptor, aNormalizedDescriptor, mpObjShell );
+
+ OUString sType;
+ if ( ( aNormalizedDescriptor.size() == 1 )
+ && !aNormalizedDescriptor.has( PROP_EVENT_TYPE ) //TODO
+ && ( aNormalizedDescriptor.get( PROP_EVENT_TYPE ) >>= sType )
+ && ( sType.isEmpty() )
+ )
+ {
+ // An empty event type means no binding. Therefore reset data
+ // to reflect that state.
+ // (that's for compatibility only. Nowadays, the Tools/Customize dialog should
+ // set an empty sequence to indicate the request for resetting the assignment.)
+ OSL_ENSURE( false, "legacy event assignment format detected" );
+ aNormalizedDescriptor.clear();
+ }
+
+ if ( !aNormalizedDescriptor.empty() )
+ {
+ maEventData[nIndex] <<= aNormalizedDescriptor.getPropertyValues();
+ }
+ else
+ {
+ maEventData[nIndex].clear();
+ }
+ return;
+ }
+
+ throw container::NoSuchElementException();
+}
+
+
+// --- XNameAccess ---
+
+uno::Any SAL_CALL SfxEvents_Impl::getByName( const OUString& aName )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and return the data
+
+ auto nIndex = comphelper::findValue(maEventNames, aName);
+ if (nIndex != -1)
+ return maEventData[nIndex];
+
+ throw container::NoSuchElementException();
+}
+
+
+uno::Sequence< OUString > SAL_CALL SfxEvents_Impl::getElementNames()
+{
+ return maEventNames;
+}
+
+
+sal_Bool SAL_CALL SfxEvents_Impl::hasByName( const OUString& aName )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and return the data
+
+ return comphelper::findValue(maEventNames, aName) != -1;
+}
+
+
+// --- XElementAccess ( parent of XNameAccess ) ---
+
+uno::Type SAL_CALL SfxEvents_Impl::getElementType()
+{
+ uno::Type aElementType = cppu::UnoType<uno::Sequence < beans::PropertyValue >>::get();
+ return aElementType;
+}
+
+
+sal_Bool SAL_CALL SfxEvents_Impl::hasElements()
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ return maEventNames.hasElements();
+}
+
+void SfxEvents_Impl::Execute( uno::Any const & aEventData, const document::DocumentEvent& aTrigger, SfxObjectShell* pDoc )
+{
+ uno::Sequence < beans::PropertyValue > aProperties;
+ if ( !(aEventData >>= aProperties) )
+ return;
+
+ OUString aType;
+ OUString aScript;
+ OUString aLibrary;
+ OUString aMacroName;
+
+ if ( !aProperties.hasElements() )
+ return;
+
+ for ( const auto& rProp : std::as_const(aProperties) )
+ {
+ if ( rProp.Name == PROP_EVENT_TYPE )
+ rProp.Value >>= aType;
+ else if ( rProp.Name == PROP_SCRIPT )
+ rProp.Value >>= aScript;
+ else if ( rProp.Name == PROP_LIBRARY )
+ rProp.Value >>= aLibrary;
+ else if ( rProp.Name == PROP_MACRO_NAME )
+ rProp.Value >>= aMacroName;
+ else {
+ OSL_FAIL("Unknown property value!");
+ }
+ }
+
+ if (aType.isEmpty())
+ {
+ // Empty type means no active binding for the event. Just ignore do nothing.
+ return;
+ }
+
+ if (aScript.isEmpty())
+ return;
+
+ if (!pDoc)
+ pDoc = SfxObjectShell::Current();
+
+ if (pDoc && !SfxObjectShell::isScriptAccessAllowed(pDoc->GetModel()))
+ return;
+
+ if (aType == STAR_BASIC)
+ {
+ uno::Any aAny;
+ SfxMacroLoader::loadMacro( aScript, aAny, pDoc );
+ }
+ else if (aType == "Service" || aType == "Script")
+ {
+ util::URL aURL;
+ uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
+
+ aURL.Complete = aScript;
+ xTrans->parseStrict( aURL );
+
+ bool bAllowed = !SfxObjectShell::UnTrustedScript(aURL.Complete);
+
+ if (bAllowed)
+ {
+ SfxViewFrame* pView = SfxViewFrame::GetFirst(pDoc);
+
+ uno::Reference
+ < frame::XDispatchProvider > xProv;
+
+ if ( pView != nullptr )
+ {
+ xProv = uno::Reference
+ < frame::XDispatchProvider > (
+ pView->GetFrame().GetFrameInterface(), uno::UNO_QUERY );
+ }
+ else
+ {
+ xProv = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
+ }
+
+ uno::Reference < frame::XDispatch > xDisp;
+ if ( xProv.is() )
+ xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
+
+ if ( xDisp.is() )
+ {
+ beans::PropertyValue aEventParam;
+ aEventParam.Value <<= aTrigger;
+ uno::Sequence< beans::PropertyValue > aDispatchArgs( &aEventParam, 1 );
+ xDisp->dispatch( aURL, aDispatchArgs );
+ }
+ }
+ }
+ else
+ {
+ SAL_WARN( "sfx.notify", "notifyEvent(): Unsupported event type" );
+ }
+}
+
+
+// --- ::document::XEventListener ---
+
+void SAL_CALL SfxEvents_Impl::notifyEvent( const document::EventObject& aEvent )
+{
+ ::osl::ClearableMutexGuard aGuard( maMutex );
+
+ // get the event name, find the corresponding data, execute the data
+
+ auto nIndex = comphelper::findValue(maEventNames, aEvent.EventName);
+ if ( nIndex == -1 )
+ return;
+
+ uno::Any aEventData = maEventData[ nIndex ];
+ aGuard.clear();
+ Execute( aEventData, document::DocumentEvent(aEvent.Source, aEvent.EventName, nullptr, uno::Any()), mpObjShell );
+}
+
+
+// --- ::lang::XEventListener ---
+
+void SAL_CALL SfxEvents_Impl::disposing( const lang::EventObject& /*Source*/ )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( mxBroadcaster.is() )
+ {
+ mxBroadcaster->removeEventListener( this );
+ mxBroadcaster = nullptr;
+ }
+}
+
+
+SfxEvents_Impl::SfxEvents_Impl( SfxObjectShell* pShell,
+ uno::Reference< document::XEventBroadcaster > const & xBroadcaster )
+{
+ // get the list of supported events and store it
+ if ( pShell )
+ maEventNames = pShell->GetEventNames();
+ else
+ maEventNames = rtl::Reference<GlobalEventConfig>(new GlobalEventConfig)->getElementNames();
+
+ maEventData = uno::Sequence < uno::Any > ( maEventNames.getLength() );
+
+ mpObjShell = pShell;
+ mxBroadcaster = xBroadcaster;
+
+ if ( mxBroadcaster.is() )
+ mxBroadcaster->addEventListener( this );
+}
+
+
+SfxEvents_Impl::~SfxEvents_Impl()
+{
+}
+
+
+std::unique_ptr<SvxMacro> SfxEvents_Impl::ConvertToMacro( const uno::Any& rElement, SfxObjectShell* pObjShell )
+{
+ std::unique_ptr<SvxMacro> pMacro;
+ uno::Sequence < beans::PropertyValue > aProperties;
+ uno::Any aAny;
+ NormalizeMacro( rElement, aAny, pObjShell );
+
+ if ( aAny >>= aProperties )
+ {
+ OUString aType;
+ OUString aScriptURL;
+ OUString aLibrary;
+ OUString aMacroName;
+
+ if ( !aProperties.hasElements() )
+ return pMacro;
+
+ for ( const auto& rProp : std::as_const(aProperties) )
+ {
+ if ( rProp.Name == PROP_EVENT_TYPE )
+ rProp.Value >>= aType;
+ else if ( rProp.Name == PROP_SCRIPT )
+ rProp.Value >>= aScriptURL;
+ else if ( rProp.Name == PROP_LIBRARY )
+ rProp.Value >>= aLibrary;
+ else if ( rProp.Name == PROP_MACRO_NAME )
+ rProp.Value >>= aMacroName;
+ else {
+ OSL_FAIL("Unknown property value!");
+ }
+ }
+
+ // Get the type
+ ScriptType eType( STARBASIC );
+ if ( aType == STAR_BASIC )
+ eType = STARBASIC;
+ else if (aType == "Script" && !aScriptURL.isEmpty())
+ eType = EXTENDED_STYPE;
+ else if ( aType == SVX_MACRO_LANGUAGE_JAVASCRIPT )
+ eType = JAVASCRIPT;
+ else {
+ SAL_WARN( "sfx.notify", "ConvertToMacro: Unknown macro type" );
+ }
+
+ if ( !aMacroName.isEmpty() )
+ {
+ if ( aLibrary == "application" )
+ aLibrary = SfxGetpApp()->GetName();
+ else
+ aLibrary.clear();
+ pMacro.reset(new SvxMacro( aMacroName, aLibrary, eType ));
+ }
+ else if ( eType == EXTENDED_STYPE )
+ pMacro.reset(new SvxMacro( aScriptURL, aType ));
+ }
+
+ return pMacro;
+}
+
+void SfxEvents_Impl::NormalizeMacro( const uno::Any& rEvent, uno::Any& rRet, SfxObjectShell* pDoc )
+{
+ const ::comphelper::NamedValueCollection aEventDescriptor( rEvent );
+ ::comphelper::NamedValueCollection aEventDescriptorOut;
+
+ NormalizeMacro( aEventDescriptor, aEventDescriptorOut, pDoc );
+
+ rRet <<= aEventDescriptorOut.getPropertyValues();
+}
+
+void SfxEvents_Impl::NormalizeMacro( const ::comphelper::NamedValueCollection& i_eventDescriptor,
+ ::comphelper::NamedValueCollection& o_normalizedDescriptor, SfxObjectShell* i_document )
+{
+ SfxObjectShell* pDoc = i_document;
+ if ( !pDoc )
+ pDoc = SfxObjectShell::Current();
+
+ OUString aType = i_eventDescriptor.getOrDefault( PROP_EVENT_TYPE, OUString() );
+ OUString aScript = i_eventDescriptor.getOrDefault( PROP_SCRIPT, OUString() );
+ OUString aLibrary = i_eventDescriptor.getOrDefault( PROP_LIBRARY, OUString() );
+ OUString aMacroName = i_eventDescriptor.getOrDefault( PROP_MACRO_NAME, OUString() );
+
+ if ( !aType.isEmpty() )
+ o_normalizedDescriptor.put( PROP_EVENT_TYPE, aType );
+ if ( !aScript.isEmpty() )
+ o_normalizedDescriptor.put( PROP_SCRIPT, aScript );
+
+ if ( aType != STAR_BASIC )
+ return;
+
+ if ( !aScript.isEmpty() )
+ {
+ if ( aMacroName.isEmpty() || aLibrary.isEmpty() )
+ {
+ sal_Int32 nThirdSlashPos = aScript.indexOf( '/', 8 );
+ sal_Int32 nArgsPos = aScript.indexOf( '(' );
+ if ( ( nThirdSlashPos != -1 ) && ( nArgsPos == -1 || nThirdSlashPos < nArgsPos ) )
+ {
+ OUString aBasMgrName( INetURLObject::decode( aScript.copy( 8, nThirdSlashPos-8 ), INetURLObject::DecodeMechanism::WithCharset ) );
+ if (pDoc && aBasMgrName == ".")
+ aLibrary = pDoc->GetTitle();
+ else
+ aLibrary = SfxGetpApp()->GetName();
+
+ // Get the macro name
+ aMacroName = aScript.copy( nThirdSlashPos+1, nArgsPos - nThirdSlashPos - 1 );
+ }
+ else
+ {
+ SAL_WARN( "sfx.notify", "ConvertToMacro: Unknown macro url format" );
+ }
+ }
+ }
+ else if ( !aMacroName.isEmpty() )
+ {
+ aScript = "macro://";
+ if ( aLibrary != SfxGetpApp()->GetName() && aLibrary != "StarDesktop" && aLibrary != "application" )
+ aScript += ".";
+ aScript += "/" + aMacroName + "()";
+ }
+ else
+ // wrong properties
+ return;
+
+ if (aLibrary != "document")
+ {
+ if ( aLibrary.isEmpty() || (pDoc && ( aLibrary == pDoc->GetTitle( SFX_TITLE_APINAME ) || aLibrary == pDoc->GetTitle() )) )
+ aLibrary = "document";
+ else
+ aLibrary = "application";
+ }
+
+ o_normalizedDescriptor.put( PROP_SCRIPT, aScript );
+ o_normalizedDescriptor.put( PROP_LIBRARY, aLibrary );
+ o_normalizedDescriptor.put( PROP_MACRO_NAME, aMacroName );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/notify/globalevents.cxx b/sfx2/source/notify/globalevents.cxx
new file mode 100644
index 000000000..9ac9e8707
--- /dev/null
+++ b/sfx2/source/notify/globalevents.cxx
@@ -0,0 +1,548 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/types.h>
+
+#include <com/sun/star/task/theJobExecutor.hpp>
+#include <com/sun/star/container/XNameReplace.hpp>
+#include <com/sun/star/container/XSet.hpp>
+#include <com/sun/star/document/XEventListener.hpp>
+#include <com/sun/star/document/XEventBroadcaster.hpp>
+#include <com/sun/star/document/XDocumentEventListener.hpp>
+#include <com/sun/star/frame/XGlobalEventBroadcaster.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/lang/NoSupportException.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/Type.hxx>
+
+#include <cppuhelper/implbase.hxx>
+#include <comphelper/interfacecontainer2.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <rtl/ref.hxx>
+#include <comphelper/enumhelper.hxx>
+#include <sfx2/app.hxx>
+#include <tools/diagnose_ex.h>
+#include <unotools/eventcfg.hxx>
+#include <eventsupplier.hxx>
+
+#include <set>
+#include <vector>
+
+using namespace css;
+
+namespace {
+
+struct ModelCollectionMutexBase
+{
+public:
+ osl::Mutex m_aLock;
+};
+
+typedef ::std::vector< css::uno::Reference< css::frame::XModel > > TModelList;
+
+
+//TODO: remove support of obsolete document::XEventBroadcaster/Listener
+class SfxGlobalEvents_Impl : public ModelCollectionMutexBase
+ , public ::cppu::WeakImplHelper< css::lang::XServiceInfo
+ , css::frame::XGlobalEventBroadcaster
+ , css::document::XEventBroadcaster
+ , css::document::XEventListener
+ , css::lang::XComponent
+ >
+{
+ css::uno::Reference< css::container::XNameReplace > m_xEvents;
+ css::uno::Reference< css::document::XEventListener > m_xJobExecutorListener;
+ ::comphelper::OInterfaceContainerHelper2 m_aLegacyListeners;
+ ::comphelper::OInterfaceContainerHelper2 m_aDocumentListeners;
+ std::multiset<css::uno::Reference<css::lang::XEventListener>> m_disposeListeners;
+ TModelList m_lModels;
+ bool m_disposed;
+
+public:
+ explicit SfxGlobalEvents_Impl(const css::uno::Reference < css::uno::XComponentContext >& rxContext);
+
+ virtual OUString SAL_CALL getImplementationName() override
+ {
+ return "com.sun.star.comp.sfx2.GlobalEventBroadcaster";
+ }
+
+ virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
+ {
+ return cppu::supportsService(this, ServiceName);
+ }
+
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
+ {
+ css::uno::Sequence< OUString > aSeq { "com.sun.star.frame.GlobalEventBroadcaster" };
+ return aSeq;
+ }
+
+ // css.document.XEventBroadcaster
+ virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents() override;
+
+ virtual void SAL_CALL addEventListener(const css::uno::Reference< css::document::XEventListener >& xListener) override;
+
+ virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::document::XEventListener >& xListener) override;
+
+ // css.document.XDocumentEventBroadcaster
+ virtual void SAL_CALL addDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& Listener ) override;
+ virtual void SAL_CALL removeDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& Listener ) override;
+ virtual void SAL_CALL notifyDocumentEvent( const OUString& EventName, const css::uno::Reference< css::frame::XController2 >& ViewController, const css::uno::Any& Supplement ) override;
+
+ // css.document.XEventListener
+ virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent) override;
+
+ // css.document.XDocumentEventListener
+ virtual void SAL_CALL documentEventOccured( const css::document::DocumentEvent& Event ) override;
+
+ // css.container.XSet
+ virtual sal_Bool SAL_CALL has(const css::uno::Any& aElement) override;
+
+ virtual void SAL_CALL insert(const css::uno::Any& aElement) override;
+
+ virtual void SAL_CALL remove(const css::uno::Any& aElement) override;
+
+ // css.container.XEnumerationAccess
+ virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override;
+
+ // css.container.XElementAccess
+ virtual css::uno::Type SAL_CALL getElementType() override;
+
+ virtual sal_Bool SAL_CALL hasElements() override;
+
+ // css.lang.XEventListener
+ virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
+
+ // css.lang.XComponent
+ void SAL_CALL dispose() override;
+
+ void SAL_CALL addEventListener(css::uno::Reference<css::lang::XEventListener> const & xListener)
+ override;
+
+ void SAL_CALL removeEventListener(
+ css::uno::Reference<css::lang::XEventListener> const & aListener) override;
+
+private:
+
+ // threadsafe
+ void implts_notifyJobExecution(const css::document::EventObject& aEvent);
+ void implts_checkAndExecuteEventBindings(const css::document::DocumentEvent& aEvent);
+ void implts_notifyListener(const css::document::DocumentEvent& aEvent);
+
+ // not threadsafe
+ TModelList::iterator impl_searchDoc(const css::uno::Reference< css::frame::XModel >& xModel);
+};
+
+SfxGlobalEvents_Impl::SfxGlobalEvents_Impl( const uno::Reference < uno::XComponentContext >& rxContext)
+ : ModelCollectionMutexBase( )
+ , m_xJobExecutorListener( task::theJobExecutor::get( rxContext ), uno::UNO_QUERY_THROW )
+ , m_aLegacyListeners (m_aLock)
+ , m_aDocumentListeners (m_aLock)
+ , m_disposed(false)
+{
+ osl_atomic_increment(&m_refCount);
+ SfxApplication::GetOrCreate();
+ m_xEvents = new GlobalEventConfig();
+ osl_atomic_decrement(&m_refCount);
+}
+
+uno::Reference< container::XNameReplace > SAL_CALL SfxGlobalEvents_Impl::getEvents()
+{
+ // SAFE ->
+ osl::MutexGuard aLock(m_aLock);
+ if (m_disposed) {
+ throw css::lang::DisposedException();
+ }
+ return m_xEvents;
+ // <- SAFE
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::addEventListener(const uno::Reference< document::XEventListener >& xListener)
+{
+ {
+ osl::MutexGuard g(m_aLock);
+ if (m_disposed) {
+ throw css::lang::DisposedException();
+ }
+ }
+ // container is threadsafe
+ m_aLegacyListeners.addInterface(xListener);
+ // Take care of an XComponent::dispose being processed in parallel with the above addInterface:
+ {
+ osl::MutexGuard g(m_aLock);
+ if (!m_disposed) {
+ return;
+ }
+ }
+ m_aLegacyListeners.disposeAndClear({static_cast<OWeakObject *>(this)});
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::removeEventListener(const uno::Reference< document::XEventListener >& xListener)
+{
+ // The below removeInterface will silently do nothing when m_disposed:
+ // container is threadsafe
+ m_aLegacyListeners.removeInterface(xListener);
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& Listener )
+{
+ {
+ osl::MutexGuard g(m_aLock);
+ if (m_disposed) {
+ throw css::lang::DisposedException();
+ }
+ }
+ m_aDocumentListeners.addInterface( Listener );
+ // Take care of an XComponent::dispose being processed in parallel with the above addInterface:
+ {
+ osl::MutexGuard g(m_aLock);
+ if (!m_disposed) {
+ return;
+ }
+ }
+ m_aDocumentListeners.disposeAndClear({static_cast<OWeakObject *>(this)});
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& Listener )
+{
+ // The below removeInterface will silently do nothing when m_disposed:
+ m_aDocumentListeners.removeInterface( Listener );
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::notifyDocumentEvent( const OUString& /*_EventName*/,
+ const uno::Reference< frame::XController2 >& /*_ViewController*/, const uno::Any& /*_Supplement*/ )
+{
+ // we're a multiplexer only, no chance to generate artificial events here
+ throw lang::NoSupportException(OUString(), *this);
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::notifyEvent(const document::EventObject& aEvent)
+{
+ // The below implts_* will silently do nothing when m_disposed:
+ document::DocumentEvent aDocEvent(aEvent.Source, aEvent.EventName, nullptr, uno::Any());
+ implts_notifyJobExecution(aEvent);
+ implts_checkAndExecuteEventBindings(aDocEvent);
+ implts_notifyListener(aDocEvent);
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::documentEventOccured( const document::DocumentEvent& Event )
+{
+ // The below implts_* will silently do nothing when m_disposed:
+ implts_notifyJobExecution(document::EventObject(Event.Source, Event.EventName));
+ implts_checkAndExecuteEventBindings(Event);
+ implts_notifyListener(Event);
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::disposing(const lang::EventObject& aEvent)
+{
+ uno::Reference< frame::XModel > xDoc(aEvent.Source, uno::UNO_QUERY);
+
+ // SAFE ->
+ osl::MutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ m_lModels.erase(pIt);
+ // <- SAFE
+}
+
+void SfxGlobalEvents_Impl::dispose() {
+ std::multiset<css::uno::Reference<css::lang::XEventListener>> listeners;
+ {
+ osl::MutexGuard g(m_aLock);
+ m_xEvents.clear();
+ m_xJobExecutorListener.clear();
+ m_disposeListeners.swap(listeners);
+ m_lModels.clear();
+ m_disposed = true;
+ }
+ m_aLegacyListeners.disposeAndClear({static_cast<OWeakObject *>(this)});
+ m_aDocumentListeners.disposeAndClear({static_cast<OWeakObject *>(this)});
+ for (auto const & i: listeners) {
+ try {
+ i->disposing({static_cast< cppu::OWeakObject * >(this)});
+ } catch (css::lang::DisposedException &) {}
+ }
+}
+
+void SfxGlobalEvents_Impl::addEventListener(
+ css::uno::Reference<css::lang::XEventListener> const & xListener)
+{
+ if (!xListener.is()) {
+ throw css::uno::RuntimeException("null listener");
+ }
+ {
+ osl::MutexGuard g(m_aLock);
+ if (!m_disposed) {
+ m_disposeListeners.insert(xListener);
+ return;
+ }
+ }
+ try {
+ xListener->disposing({static_cast< cppu::OWeakObject * >(this)});
+ } catch (css::lang::DisposedException &) {}
+}
+
+void SfxGlobalEvents_Impl::removeEventListener(
+ css::uno::Reference<css::lang::XEventListener> const & aListener)
+{
+ osl::MutexGuard g(m_aLock);
+ auto const i = m_disposeListeners.find(aListener);
+ if (i != m_disposeListeners.end()) {
+ m_disposeListeners.erase(i);
+ }
+}
+
+sal_Bool SAL_CALL SfxGlobalEvents_Impl::has(const uno::Any& aElement)
+{
+ uno::Reference< frame::XModel > xDoc;
+ aElement >>= xDoc;
+
+ bool bHas = false;
+
+ // SAFE ->
+ osl::MutexGuard aLock(m_aLock);
+ if (m_disposed) {
+ throw css::lang::DisposedException();
+ }
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ bHas = true;
+ // <- SAFE
+
+ return bHas;
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::insert( const uno::Any& aElement )
+{
+ uno::Reference< frame::XModel > xDoc;
+ aElement >>= xDoc;
+ if (!xDoc.is())
+ throw lang::IllegalArgumentException(
+ "Can not locate at least the model parameter.",
+ static_cast< container::XSet* >(this),
+ 0);
+
+ // SAFE ->
+ {
+ osl::MutexGuard aLock(m_aLock);
+ if (m_disposed) {
+ throw css::lang::DisposedException();
+ }
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ throw container::ElementExistException(
+ OUString(),
+ static_cast<container::XSet*>(this));
+ m_lModels.push_back(xDoc);
+ }
+ // <- SAFE
+
+ uno::Reference< document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, uno::UNO_QUERY );
+ if (xDocBroadcaster.is())
+ xDocBroadcaster->addDocumentEventListener(this);
+ else
+ {
+ // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
+ uno::Reference< document::XEventBroadcaster > xBroadcaster(xDoc, uno::UNO_QUERY);
+ if (xBroadcaster.is())
+ xBroadcaster->addEventListener(static_cast< document::XEventListener* >(this));
+ }
+}
+
+
+void SAL_CALL SfxGlobalEvents_Impl::remove( const uno::Any& aElement )
+{
+ uno::Reference< frame::XModel > xDoc;
+ aElement >>= xDoc;
+ if (!xDoc.is())
+ throw lang::IllegalArgumentException(
+ "Can not locate at least the model parameter.",
+ static_cast< container::XSet* >(this),
+ 0);
+
+ // SAFE ->
+ {
+ osl::MutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt == m_lModels.end())
+ throw container::NoSuchElementException(
+ OUString(),
+ static_cast<container::XSet*>(this));
+ m_lModels.erase(pIt);
+ }
+ // <- SAFE
+
+ uno::Reference< document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, uno::UNO_QUERY );
+ if (xDocBroadcaster.is())
+ xDocBroadcaster->removeDocumentEventListener(this);
+ else
+ {
+ // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
+ uno::Reference< document::XEventBroadcaster > xBroadcaster(xDoc, uno::UNO_QUERY);
+ if (xBroadcaster.is())
+ xBroadcaster->removeEventListener(static_cast< document::XEventListener* >(this));
+ }
+}
+
+
+uno::Reference< container::XEnumeration > SAL_CALL SfxGlobalEvents_Impl::createEnumeration()
+{
+ // SAFE ->
+ osl::MutexGuard aLock(m_aLock);
+ if (m_disposed) {
+ throw css::lang::DisposedException();
+ }
+ uno::Sequence<uno::Any> models(m_lModels.size());
+ for (size_t i = 0; i < m_lModels.size(); ++i)
+ {
+ models[i] <<= m_lModels[i];
+ }
+ uno::Reference<container::XEnumeration> xEnum(new ::comphelper::OAnyEnumeration(models));
+ // <- SAFE
+
+ return xEnum;
+}
+
+
+uno::Type SAL_CALL SfxGlobalEvents_Impl::getElementType()
+{
+ return cppu::UnoType<frame::XModel>::get();
+}
+
+
+sal_Bool SAL_CALL SfxGlobalEvents_Impl::hasElements()
+{
+ // SAFE ->
+ osl::MutexGuard aLock(m_aLock);
+ if (m_disposed) {
+ throw css::lang::DisposedException();
+ }
+ return (!m_lModels.empty());
+ // <- SAFE
+}
+
+
+void SfxGlobalEvents_Impl::implts_notifyJobExecution(const document::EventObject& aEvent)
+{
+ css::uno::Reference<css::document::XEventListener> listener;
+ {
+ osl::MutexGuard g(m_aLock);
+ listener = m_xJobExecutorListener;
+ }
+ if (!listener.is()) {
+ return;
+ }
+ try
+ {
+ listener->notifyEvent(aEvent);
+ }
+ catch(const uno::RuntimeException&)
+ { throw; }
+ catch(const uno::Exception&)
+ {}
+}
+
+
+void SfxGlobalEvents_Impl::implts_checkAndExecuteEventBindings(const document::DocumentEvent& aEvent)
+{
+ css::uno::Reference<css::container::XNameReplace> events;
+ {
+ osl::MutexGuard g(m_aLock);
+ events = m_xEvents;
+ }
+ if (!events.is()) {
+ return;
+ }
+ try
+ {
+ uno::Any aAny;
+ if ( events->hasByName( aEvent.EventName ) )
+ aAny = events->getByName(aEvent.EventName);
+ SfxEvents_Impl::Execute(aAny, aEvent, nullptr);
+ }
+ catch ( uno::RuntimeException const & )
+ {
+ throw;
+ }
+ catch ( uno::Exception const & )
+ {
+ DBG_UNHANDLED_EXCEPTION("sfx.notify");
+ }
+}
+
+
+void SfxGlobalEvents_Impl::implts_notifyListener(const document::DocumentEvent& aEvent)
+{
+ // containers are threadsafe
+ document::EventObject aLegacyEvent(aEvent.Source, aEvent.EventName);
+ m_aLegacyListeners.notifyEach( &document::XEventListener::notifyEvent, aLegacyEvent );
+
+ m_aDocumentListeners.notifyEach( &document::XDocumentEventListener::documentEventOccured, aEvent );
+}
+
+
+// not threadsafe ... must be locked from outside!
+TModelList::iterator SfxGlobalEvents_Impl::impl_searchDoc(const uno::Reference< frame::XModel >& xModel)
+{
+ if (!xModel.is())
+ return m_lModels.end();
+
+ return std::find_if(m_lModels.begin(), m_lModels.end(),
+ [&xModel](const TModelList::value_type& rxModel) {
+ uno::Reference< frame::XModel > xContainerDoc(rxModel, uno::UNO_QUERY);
+ return xContainerDoc == xModel;
+ });
+}
+
+struct Instance {
+ explicit Instance(
+ css::uno::Reference<css::uno::XComponentContext> const & context):
+ instance(
+ static_cast<cppu::OWeakObject *>(new SfxGlobalEvents_Impl(context)))
+ {}
+
+ rtl::Reference<css::uno::XInterface> instance;
+};
+
+struct Singleton:
+ public rtl::StaticWithArg<
+ Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
+{};
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
+com_sun_star_comp_sfx2_GlobalEventBroadcaster_get_implementation(
+ css::uno::XComponentContext *context,
+ css::uno::Sequence<css::uno::Any> const &)
+{
+ return cppu::acquire(static_cast<cppu::OWeakObject *>(
+ Singleton::get(context).instance.get()));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/notify/hintpost.cxx b/sfx2/source/notify/hintpost.cxx
new file mode 100644
index 000000000..44b26b52a
--- /dev/null
+++ b/sfx2/source/notify/hintpost.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <hintpost.hxx>
+
+#include <sfx2/request.hxx>
+#include <vcl/svapp.hxx>
+
+
+SfxHintPoster::SfxHintPoster(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink)
+ : m_Link(rLink)
+{
+}
+
+SfxHintPoster::~SfxHintPoster()
+{
+}
+
+void SfxHintPoster::Post( std::unique_ptr<SfxRequest> pHintToPost )
+{
+ Application::PostUserEvent( ( LINK(this, SfxHintPoster, DoEvent_Impl) ), pHintToPost.release() );
+ AddFirstRef();
+}
+
+IMPL_LINK( SfxHintPoster, DoEvent_Impl, void *, pPostedHint, void )
+{
+ if (m_Link)
+ m_Link( std::unique_ptr<SfxRequest>(static_cast<SfxRequest*>(pPostedHint)) );
+ ReleaseRef();
+}
+
+void SfxHintPoster::SetEventHdl(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink)
+{
+ m_Link = rLink;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/notify/openurlhint.cxx b/sfx2/source/notify/openurlhint.cxx
new file mode 100644
index 000000000..ca831a6f4
--- /dev/null
+++ b/sfx2/source/notify/openurlhint.cxx
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <openurlhint.hxx>
+
+SfxOpenUrlHint::SfxOpenUrlHint( const OUString& sDocumentURL ) :
+ msDocumentURL(sDocumentURL) { }
+
+const OUString& SfxOpenUrlHint::GetDocumentURL() const
+{
+ return msDocumentURL;
+}
+
+SfxOpenUrlHint::~SfxOpenUrlHint() {}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */