Kaydet (Commit) 6c8c727f authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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/55110Reviewed-by: 's avatarTor Lillqvist <tml@collabora.com>
Tested-by: 's avatarTor Lillqvist <tml@collabora.com>
üst 96735115
......@@ -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;
......
......@@ -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:
......
......@@ -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()
{
......
......@@ -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
......
......@@ -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: */
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment