diff options
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/ui/vba/vbaapplication.cxx | 35 | ||||
-rw-r--r-- | sw/source/ui/vba/vbaapplication.hxx | 15 | ||||
-rw-r--r-- | sw/source/uibase/app/docsh2.cxx | 3 | ||||
-rw-r--r-- | sw/source/uibase/app/swmodule.cxx | 12 |
4 files changed, 50 insertions, 15 deletions
diff --git a/sw/source/ui/vba/vbaapplication.cxx b/sw/source/ui/vba/vbaapplication.cxx index f86032a249e7..d76e7730a783 100644 --- a/sw/source/ui/vba/vbaapplication.cxx +++ b/sw/source/ui/vba/vbaapplication.cxx @@ -34,6 +34,8 @@ #include <editeng/acorrcfg.hxx> #include "wordvbahelper.hxx" #include <docsh.hxx> +#include <swdll.hxx> +#include <swmodule.hxx> #include "vbalistgalleries.hxx" using namespace ::ooo; @@ -60,17 +62,17 @@ SwVbaApplication::SwVbaApplication( uno::Reference<uno::XComponentContext >& xCo SwVbaApplication::~SwVbaApplication() { - // FIXME: Sadly this is not the place to do this, this dtor is never called, it seems - for (auto& i : mvSinks) - { - if (i.is()) - i->Call("Quit", uno::Sequence<uno::Any>()); - } } sal_uInt32 -SwVbaApplication::AddSink( const css::uno::Reference< XSink >& xSink ) +SwVbaApplication::AddSink( const uno::Reference< XSink >& xSink ) { + { + SolarMutexGuard aGuard; + SwGlobals::ensure(); + } + // No harm in potentially calling this several times + SW_MOD()->RegisterAutomationApplicationEventsCaller( uno::Reference< XSinkCaller >(this) ); mvSinks.push_back(xSink); return mvSinks.size();; } @@ -132,13 +134,6 @@ SwVbaApplication::getSelection() uno::Any SAL_CALL SwVbaApplication::Documents( const uno::Any& index ) { - // FIXME DUMMY just to test calling this somewhere... the dtor is never called - for (auto& i : mvSinks) - { - if (i.is()) - i->Call("Quit", uno::Sequence<uno::Any>()); - } - uno::Reference< XCollection > xCol( new SwVbaDocuments( this, mxContext ) ); if ( index.hasValue() ) return xCol->Item( index, uno::Any() ); @@ -269,6 +264,18 @@ SwVbaApplicationOutgoingConnectionPoint::SwVbaApplicationOutgoingConnectionPoint { } +// XSinkCaller + +void SAL_CALL +SwVbaApplication::CallSinks( const OUString& Method, const uno::Sequence< uno::Any >& Arguments ) +{ + for (auto& i : mvSinks) + { + if (i.is()) + i->Call(Method, Arguments); + } +} + // SwVbaApplicationOutgoingConnectionPoint // XConnectionPoint diff --git a/sw/source/ui/vba/vbaapplication.hxx b/sw/source/ui/vba/vbaapplication.hxx index 8b8b85f86c8c..681c4f9159c6 100644 --- a/sw/source/ui/vba/vbaapplication.hxx +++ b/sw/source/ui/vba/vbaapplication.hxx @@ -22,6 +22,7 @@ #include <vector> #include <ooo/vba/XSink.hpp> +#include <ooo/vba/XSinkCaller.hpp> #include <ooo/vba/word/XApplication.hpp> #include <ooo/vba/word/XDocument.hpp> #include <ooo/vba/word/XWindow.hpp> @@ -33,7 +34,15 @@ #include <vbahelper/vbaapplicationbase.hxx> #include <cppuhelper/implbase.hxx> -typedef cppu::ImplInheritanceHelper< VbaApplicationBase, ooo::vba::word::XApplication > SwVbaApplication_BASE; +typedef cppu::ImplInheritanceHelper< VbaApplicationBase, ooo::vba::word::XApplication, ooo::vba::XSinkCaller > SwVbaApplication_BASE; + +// This class is currently not a singleton. One instance is created per document with (potential?) +// StarBasic code in it, I think, and a shared one for all Automation clients connected to the +// ooo::vba::word::Application (Writer.Application) service. (Of course it probably is not common to +// have several Automation clients at once.) + +// Should it be a true singleton? Hard to say. Anyway, it is actually the SwVbaGlobals class that +// should be a singleton in that case, I think. class SwVbaApplication : public SwVbaApplication_BASE { @@ -76,6 +85,10 @@ public: // 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; + protected: virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() override; }; diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx index 7f7df1db893e..91c86d8c74ff 100644 --- a/sw/source/uibase/app/docsh2.cxx +++ b/sw/source/uibase/app/docsh2.cxx @@ -254,6 +254,9 @@ void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) if( xVbaEvents.is() ) lcl_processCompatibleSfxHint( xVbaEvents, rHint ); + if ( rHint.GetId() == SfxHintId::DocChanged ) + SW_MOD()->CallAutomationApplicationEventSinks( "DocumentChange", css::uno::Sequence< css::uno::Any >() ); + sal_uInt16 nAction = 0; auto pEventHint = dynamic_cast<const SfxEventHint*>(&rHint); if( pEventHint && pEventHint->GetEventId() == SfxEventHintId::LoadFinished ) diff --git a/sw/source/uibase/app/swmodule.cxx b/sw/source/uibase/app/swmodule.cxx index 9b901012e86c..e82aa7f25eb1 100644 --- a/sw/source/uibase/app/swmodule.cxx +++ b/sw/source/uibase/app/swmodule.cxx @@ -221,6 +221,7 @@ uno::Reference< linguistic2::XLanguageGuessing > const & SwModule::GetLanguageGu SwModule::~SwModule() { + CallAutomationApplicationEventSinks( "Quit", css::uno::Sequence< css::uno::Any >() ); delete m_pErrorHandler; EndListening( *SfxGetpApp() ); } @@ -435,4 +436,15 @@ SfxStyleFamilies* SwModule::CreateStyleFamilies() return pStyleFamilies; } +void SwModule::RegisterAutomationApplicationEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller) +{ + mxAutomationApplicationEventsCaller = xCaller; +} + +void SwModule::CallAutomationApplicationEventSinks(const OUString& Method, const css::uno::Sequence< css::uno::Any >& Arguments) +{ + if (mxAutomationApplicationEventsCaller.is()) + mxAutomationApplicationEventsCaller->CallSinks(Method, Arguments); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |