tdf#126700 handle Impress default documents

Impress has a two stage load, eventually because of the optional
template manager. Since I don't know, what the 2nd load URL
"private:object" is used for otherwise in LO, this just marks the
empty and default documents as replaceable in Impress.

Regressed-by: 61e1e0413296928d929f99c0f006c6cbbcf4ac40
Change-Id: Ief8d9eeaa65e8fb40400e64c16768d37ca343893
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104581
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
diff --git a/sd/inc/sdmod.hxx b/sd/inc/sdmod.hxx
index 9b07b44..42c4ea4 100644
--- a/sd/inc/sdmod.hxx
+++ b/sd/inc/sdmod.hxx
@@ -142,7 +142,9 @@ private:
    SfxFrame* ExecuteNewDocument( SfxRequest const & rReq );

    static SfxFrame* CreateEmptyDocument( const css::uno::Reference< css::frame::XFrame >& i_rFrame );
    static SfxFrame* CreateFromTemplate( const OUString& rTemplatePath, const css::uno::Reference< css::frame::XFrame >& i_rFrame );
    static SfxFrame* CreateFromTemplate(const OUString& rTemplatePath,
                                        const css::uno::Reference<css::frame::XFrame>& i_rFrame,
                                        const bool bReplaceable);

    bool mbEventListenerAdded;

diff --git a/sd/source/ui/app/sdmod1.cxx b/sd/source/ui/app/sdmod1.cxx
index 4ec1e83..35bf5eb 100644
--- a/sd/source/ui/app/sdmod1.cxx
+++ b/sd/source/ui/app/sdmod1.cxx
@@ -30,6 +30,7 @@
#include <editeng/langitem.hxx>
#include <vcl/weld.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/request.hxx>
#include <sfx2/templatedlg.hxx>
#include <editeng/eeitem.hxx>
@@ -411,7 +412,8 @@ IMPL_STATIC_LINK( SdModule, EventListenerHdl, VclSimpleEvent&, rSimpleEvent, voi
}


SfxFrame* SdModule::CreateFromTemplate( const OUString& rTemplatePath, const Reference< XFrame >& i_rFrame )
SfxFrame* SdModule::CreateFromTemplate(const OUString& rTemplatePath, const Reference<XFrame>& i_rFrame,
                                       const bool bReplaceable)
{
    SfxFrame* pFrame = nullptr;

@@ -430,6 +432,8 @@ SfxFrame* SdModule::CreateFromTemplate( const OUString& rTemplatePath, const Ref
    }
    else if( pDocShell )
    {
        if (pDocShell->GetMedium() && pDocShell->GetMedium()->GetItemSet())
            pDocShell->GetMedium()->GetItemSet()->Put(SfxBoolItem(SID_REPLACEABLE, bReplaceable));
        SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pDocShell, i_rFrame );
        OSL_ENSURE( pViewFrame, "SdModule::CreateFromTemplate: no view frame - was the document really loaded?" );
        pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr;
@@ -464,7 +468,7 @@ SfxFrame* SdModule::ExecuteNewDocument( SfxRequest const & rReq )
            if( !aStandardTemplate.isEmpty() )
            {
                //load a template document
                pFrame = CreateFromTemplate( aStandardTemplate, xTargetFrame );
                pFrame = CreateFromTemplate(aStandardTemplate, xTargetFrame, true);
            }
            else
            {
@@ -485,7 +489,7 @@ SfxFrame* SdModule::ExecuteNewDocument( SfxRequest const & rReq )

            //pFrame is loaded with the desired template
            if (!aTemplDlg.getTemplatePath().isEmpty())
                pFrame = CreateFromTemplate(aTemplDlg.getTemplatePath(), xTargetFrame);
                pFrame = CreateFromTemplate(aTemplDlg.getTemplatePath(), xTargetFrame, false);
        }
    }

@@ -506,6 +510,8 @@ SfxFrame* SdModule::CreateEmptyDocument( const Reference< XFrame >& i_rFrame )
        pDoc->CreateFirstPages();
        pDoc->StopWorkStartupDelay();
    }
    if (pNewDocSh->GetMedium() && pNewDocSh->GetMedium()->GetItemSet())
        pNewDocSh->GetMedium()->GetItemSet()->Put(SfxBoolItem(SID_REPLACEABLE, true));

    SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pNewDocSh, i_rFrame );
    OSL_ENSURE( pViewFrame, "SdModule::CreateEmptyDocument: no view frame - was the document really loaded?" );
diff --git a/sfx2/source/view/frmload.cxx b/sfx2/source/view/frmload.cxx
index f69706d..bb9c321 100644
--- a/sfx2/source/view/frmload.cxx
+++ b/sfx2/source/view/frmload.cxx
@@ -612,7 +612,8 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const Sequence< PropertyValue >& rA
    const bool bIsFactoryURL = sURL.startsWith( "private:factory/" );
    bool bInitNewModel = bIsFactoryURL;
    const bool bIsDefault = bIsFactoryURL && !bExternalModel;
    aDescriptor.put("Replaceable", bIsDefault);
    if (!aDescriptor.has("Replaceable"))
        aDescriptor.put("Replaceable", bIsDefault);
    if (bIsDefault)
    {
        const OUString sFactory = sURL.copy( sizeof( "private:factory/" ) -1 );