Implement NewWorkbook and WorkbookOpen Automation callbacks in Calc

Change-Id: I1ff31d692100695a706bf128c18c4e3ae8b55ce3
diff --git a/oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl b/oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl
index 9e601c5..6ca5b45 100644
--- a/oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl
+++ b/oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl
@@ -25,6 +25,7 @@ module ooo {  module vba {  module excel {

interface XApplicationOutgoing : XInterfaceWithIID
{
    void NewWorkbook([in] any Wb);
    void WorkbookOpen([in] any Wb);
    void WorkbookBeforeClose([in] any Wb, [out] any Cancel);
};
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index d2ae9a9..362ddbd 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1080,6 +1080,33 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                pClipDoc->ClosingClipboardSource();
        }
    }

    if ( const SfxEventHint* pSfxEventHint = dynamic_cast<const SfxEventHint*>(&rHint) )
    {
        switch( pSfxEventHint->GetEventId() )
        {
           case SfxEventHintId::CreateDoc:
                {
                    uno::Any aWorkbook;
                    aWorkbook <<= mxAutomationWorkbookObject;
                    uno::Sequence< uno::Any > aArgs(1);
                    aArgs[0] = aWorkbook;
                    SC_MOD()->CallAutomationApplicationEventSinks( "NewWorkbook", aArgs );
                }
                break;
            case SfxEventHintId::OpenDoc:
                {
                    uno::Any aWorkbook;
                    aWorkbook <<= mxAutomationWorkbookObject;
                    uno::Sequence< uno::Any > aArgs(1);
                    aArgs[0] = aWorkbook;
                    SC_MOD()->CallAutomationApplicationEventSinks( "WorkbookOpen", aArgs );
                }
                break;
            default:
                break;
        }
    }
}

// Load contents for organizer
@@ -3340,6 +3367,11 @@ void ScDocShell::SetIsInUcalc()
    mbUcalcTest = true;
}

void ScDocShell::RegisterAutomationWorkbookObject(css::uno::Reference< ooo::vba::excel::XWorkbook > const& xWorkbook)
{
    mxAutomationWorkbookObject = xWorkbook;
}

extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportSLK(SvStream &rStream)
{
    ScDLL::Init();
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 29fe6de..55cbdb9 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -20,8 +20,8 @@
#ifndef INCLUDED_SC_SOURCE_UI_INC_DOCSH_HXX
#define INCLUDED_SC_SOURCE_UI_INC_DOCSH_HXX

#include <ooo/vba/excel/XWorkbook.hpp>
#include <sfx2/objsh.hxx>

#include <sfx2/docfac.hxx>
#include <sfx2/sfxmodelfactory.hxx>
#include <sfx2/viewsh.hxx>
@@ -114,6 +114,8 @@ class SC_DLLPUBLIC ScDocShell final: public SfxObjectShell, public SfxListener

    ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)

    css::uno::Reference< ooo::vba::excel::XWorkbook> mxAutomationWorkbookObject;

    // Only used by Vba helper functions
    css::uno::Reference<css::script::vba::XVBAScriptListener>   m_xVBAListener;
    css::uno::Reference<css::datatransfer::XTransferable2>      m_xClipData;
@@ -427,6 +429,8 @@ public:
    void SnapVisArea( tools::Rectangle& rRect ) const;

    void SetIsInUcalc();

    void RegisterAutomationWorkbookObject(css::uno::Reference< ooo::vba::excel::XWorkbook > const& xWorkbook);
};

void UpdateAcceptChangesDialog();
diff --git a/sc/source/ui/vba/vbaworkbook.cxx b/sc/source/ui/vba/vbaworkbook.cxx
index 96ee2bf..93f7738 100644
--- a/sc/source/ui/vba/vbaworkbook.cxx
+++ b/sc/source/ui/vba/vbaworkbook.cxx
@@ -201,6 +201,9 @@ ScVbaWorkbook::init()
{
    if ( !ColorData.getLength() )
        ResetColors();
    uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY );
    if ( xModel.is() )
        excel::getDocShell( xModel )->RegisterAutomationWorkbookObject( this );
}

ScVbaWorkbook::ScVbaWorkbook(   const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::frame::XModel > const & xModel ) : ScVbaWorkbook_BASE( xParent, xContext, xModel )