diff options
author | Tor Lillqvist <tml@collabora.com> | 2018-03-23 14:35:24 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2018-05-31 12:16:13 +0200 |
commit | 6c8c727ffd97e247f1ea43c1a47a55e6d5f68331 (patch) | |
tree | 2fdffdffc01a7016f370c1ba94653a9d9e679422 | |
parent | 9673511526660ff23169456b2cce560d968107b3 (diff) |
Add Document.Close event generation
Use a similar idea as for the Application events. Use the SwDocShell
to keep the XSinkCaller. Call the Close event from
SwXTextDocument::close().
Change-Id: Ie873238c5a966fc859d45b59f424ae0e9f4fbfc7
Reviewed-on: https://gerrit.libreoffice.org/55110
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r-- | oovbaapi/ooo/vba/word/XDocument.idl | 5 | ||||
-rw-r--r-- | sw/inc/docsh.hxx | 6 | ||||
-rw-r--r-- | sw/source/ui/vba/vbadocument.cxx | 98 | ||||
-rw-r--r-- | sw/source/ui/vba/vbadocument.hxx | 20 | ||||
-rw-r--r-- | sw/source/uibase/app/docsh.cxx | 11 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 1 |
6 files changed, 139 insertions, 2 deletions
diff --git a/oovbaapi/ooo/vba/word/XDocument.idl b/oovbaapi/ooo/vba/word/XDocument.idl index 1dde907ca342..b6cb4fc45def 100644 --- a/oovbaapi/ooo/vba/word/XDocument.idl +++ b/oovbaapi/ooo/vba/word/XDocument.idl @@ -26,8 +26,11 @@ module ooo { module vba { module word { -interface XDocument : com::sun::star::script::XInvocation +interface XDocument { + interface com::sun::star::script::XInvocation; + interface XConnectable; + [attribute, readonly] XRange Content; [attribute] any AttachedTemplate; [attribute] long ProtectionType; diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx index 0be7ea783433..dc8214c534d8 100644 --- a/sw/inc/docsh.hxx +++ b/sw/inc/docsh.hxx @@ -22,6 +22,7 @@ #include <memory> #include <rtl/ref.hxx> #include <com/sun/star/uno/Sequence.h> +#include <ooo/vba/XSinkCaller.hpp> #include <sfx2/docfac.hxx> #include <sfx2/objsh.hxx> #include "swdllapi.h" @@ -86,6 +87,8 @@ class SW_DLLPUBLIC SwDocShell ///< whether SID_MAIL_PREPAREEXPORT removed content that ///< SID_MAIL_EXPORT_FINISHED needs to restore + css::uno::Reference< ooo::vba::XSinkCaller > mxAutomationDocumentEventsCaller; + /// Methods for access to doc. SAL_DLLPRIVATE void AddLink(); SAL_DLLPRIVATE void RemoveLink(); @@ -309,6 +312,9 @@ public: virtual void SetChangeRecording( bool bActivate ) override; virtual void SetProtectionPassword( const OUString &rPassword ) override; virtual bool GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ) override; + + void RegisterAutomationDocumentEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller); + void CallAutomationDocumentEventSinks(const OUString& Method, const css::uno::Sequence< css::uno::Any >& Arguments); }; /** Find the right DocShell and create a new one: diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index ca77dc62a799..47abf61c1b03 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -35,6 +35,7 @@ #include <com/sun/star/document/XRedlinesSupplier.hpp> #include <ooo/vba/XControlProvider.hpp> #include <ooo/vba/word/WdProtectionType.hpp> +#include <ooo/vba/word/XDocumentOutgoing.hpp> #include <vbahelper/helperdecl.hxx> #include "wordvbahelper.hxx" @@ -58,6 +59,19 @@ using namespace ::ooo::vba; using namespace ::com::sun::star; +class SwVbaDocumentOutgoingConnectionPoint : public cppu::WeakImplHelper<XConnectionPoint> +{ +private: + SwVbaDocument* mpDoc; + +public: + SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc ); + + // XConnectionPoint + sal_uInt32 SAL_CALL Advise(const uno::Reference< XSink >& Sink ) override; + void SAL_CALL Unadvise( sal_uInt32 Cookie ) override; +}; + SwVbaDocument::SwVbaDocument( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< frame::XModel > const & xModel ): SwVbaDocument_BASE( xParent, xContext, xModel ) { Initialize(); @@ -76,6 +90,23 @@ void SwVbaDocument::Initialize() mxTextDocument.set( getModel(), uno::UNO_QUERY_THROW ); } +sal_uInt32 +SwVbaDocument::AddSink( const uno::Reference< XSink >& xSink ) +{ + word::getDocShell( mxModel )->RegisterAutomationDocumentEventsCaller( uno::Reference< XSinkCaller >(this) ); + mvSinks.push_back(xSink); + return mvSinks.size();; +} + +void +SwVbaDocument::RemoveSink( sal_uInt32 nNumber ) +{ + if (nNumber < 1 || nNumber > mvSinks.size()) + return; + + mvSinks[nNumber-1] = uno::Reference< XSink >(); +} + uno::Reference< word::XRange > SAL_CALL SwVbaDocument::getContent() { @@ -500,6 +531,73 @@ SwVbaDocument::getFormControls() return xFormControls; } +// XInterfaceWithIID + +OUString SAL_CALL +SwVbaDocument::getIID() +{ + return OUString("{82154424-0FBF-11d4-8313-005004526AB4}"); +} + +// XConnectable + +OUString SAL_CALL +SwVbaDocument::GetIIDForClassItselfNotCoclass() +{ + return OUString("{82154425-0FBF-11D4-8313-005004526AB4}"); +} + +TypeAndIID SAL_CALL +SwVbaDocument::GetConnectionPoint() +{ + TypeAndIID aResult = + { word::XDocumentOutgoing::static_type(), + "{82154426-0FBF-11D4-8313-005004526AB4}" + }; + + return aResult; +} + +// XSinkCaller + +void SAL_CALL +SwVbaDocument::CallSinks( const OUString& Method, const uno::Sequence< uno::Any >& Arguments ) +{ + for (auto& i : mvSinks) + { + if (i.is()) + i->Call(Method, Arguments); + } +} + +uno::Reference<XConnectionPoint> SAL_CALL +SwVbaDocument::FindConnectionPoint() +{ + uno::Reference<XConnectionPoint> xCP(new SwVbaDocumentOutgoingConnectionPoint(this)); + return xCP; +} + +// SwVbaApplicationOutgoingConnectionPoint + +SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc ) : + mpDoc(pDoc) +{ +} + +// XConnectionPoint + +sal_uInt32 SAL_CALL +SwVbaDocumentOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink ) +{ + return mpDoc->AddSink(Sink); +} + +void SAL_CALL +SwVbaDocumentOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie ) +{ + mpDoc->RemoveSink( Cookie ); +} + uno::Sequence< OUString > SwVbaDocument::getServiceNames() { diff --git a/sw/source/ui/vba/vbadocument.hxx b/sw/source/ui/vba/vbadocument.hxx index 5a54d2f1433e..61ce2a7ab8bd 100644 --- a/sw/source/ui/vba/vbadocument.hxx +++ b/sw/source/ui/vba/vbadocument.hxx @@ -19,19 +19,23 @@ #ifndef INCLUDED_SW_SOURCE_UI_VBA_VBADOCUMENT_HXX #define INCLUDED_SW_SOURCE_UI_VBA_VBADOCUMENT_HXX +#include <ooo/vba/XSink.hpp> +#include <ooo/vba/XSinkCaller.hpp> #include <ooo/vba/word/XDocument.hpp> #include <vbahelper/vbahelperinterface.hxx> #include <vbahelper/vbadocumentbase.hxx> #include <com/sun/star/text/XTextDocument.hpp> #include <cppuhelper/implbase.hxx> -typedef cppu::ImplInheritanceHelper< VbaDocumentBase, ooo::vba::word::XDocument > SwVbaDocument_BASE; +typedef cppu::ImplInheritanceHelper< VbaDocumentBase, ooo::vba::word::XDocument, ooo::vba::XSinkCaller > SwVbaDocument_BASE; class SwVbaDocument : public SwVbaDocument_BASE { private: css::uno::Reference< css::text::XTextDocument > mxTextDocument; + std::vector<css::uno::Reference< ooo::vba::XSink >> mvSinks; + void Initialize(); css::uno::Any getControlShape( const OUString& sName ); css::uno::Reference< css::container::XNameAccess > getFormControls(); @@ -41,6 +45,9 @@ public: SwVbaDocument( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); virtual ~SwVbaDocument() override; + sal_uInt32 AddSink( const css::uno::Reference< ooo::vba::XSink >& xSink ); + void RemoveSink( sal_uInt32 nNumber ); + // XDocument virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL getContent() override; virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL Range( const css::uno::Any& rStart, const css::uno::Any& rEnd ) override; @@ -86,9 +93,20 @@ public: virtual sal_Bool SAL_CALL hasMethod( const OUString& aName ) override; virtual sal_Bool SAL_CALL hasProperty( const OUString& aName ) override; + // XInterfaceWithIID + virtual OUString SAL_CALL getIID() override; + + // XConnectable + virtual OUString SAL_CALL GetIIDForClassItselfNotCoclass() override; + virtual ov::TypeAndIID SAL_CALL GetConnectionPoint() override; + virtual css::uno::Reference<ov::XConnectionPoint> SAL_CALL FindConnectionPoint() override; + // XHelperInterface virtual OUString getServiceImplName() override; virtual css::uno::Sequence<OUString> getServiceNames() override; + + // XSinkCaller + virtual void SAL_CALL CallSinks( const OUString& Method, const css::uno::Sequence< css::uno::Any >& Arguments ) override; }; #endif // INCLUDED_SW_SOURCE_UI_VBA_VBADOCUMENT_HXX diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index 909725162a79..d5503f78ff77 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -1378,4 +1378,15 @@ bool SwDocShell::GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPas return bRes; } +void SwDocShell::RegisterAutomationDocumentEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller) +{ + mxAutomationDocumentEventsCaller = xCaller; +} + +void SwDocShell::CallAutomationDocumentEventSinks(const OUString& Method, const css::uno::Sequence< css::uno::Any >& Arguments) +{ + if (mxAutomationDocumentEventsCaller.is()) + mxAutomationDocumentEventsCaller->CallSinks(Method, Arguments); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 0a22921c96e6..08c3ea0cac4e 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -629,6 +629,7 @@ void SwXTextDocument::dispose() void SwXTextDocument::close( sal_Bool bDeliverOwnership ) { + pDocShell->CallAutomationDocumentEventSinks( "Close", css::uno::Sequence< css::uno::Any >() ); SolarMutexGuard aGuard; if(IsValid() && m_pHiddenViewFrame) lcl_DisposeView( m_pHiddenViewFrame, pDocShell); |