offapi/UnoApi_offapi.mk                     |    1 
 offapi/com/sun/star/drawing/XDrawPages2.idl |   40 +++++++
 sd/inc/sdpage.hxx                           |    2 
 sd/source/core/sdpage.cxx                   |    5 
 sd/source/ui/inc/unomodel.hxx               |    9 +
 sd/source/ui/unoidl/unomodel.cxx            |   57 +++++++---
 xmloff/source/draw/sdxmlimp.cxx             |    2 
 xmloff/source/draw/sdxmlimp_impl.hxx        |    5 
 xmloff/source/draw/ximpbody.cxx             |    2 
 xmloff/source/draw/ximppage.cxx             |   21 +++
 xmloff/source/draw/ximppage.hxx             |    4 
 xmloff/source/draw/ximpstyl.cxx             |  149 +++++++++++++++++++++-------
 xmloff/source/draw/ximpstyl.hxx             |    8 +
 13 files changed, 244 insertions(+), 61 deletions(-)

New commits:
commit abe6ab7aec0993dd54746d9f0c743fc42cf7ce79
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Oct 18 08:34:29 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Mon Oct 21 15:48:24 2024 +0200

    set master slide name at creation time
    
    which avoids some expensive broadcasting when the name is changed
    
    a similar mega-master-page scenario as reported in tdf#158773
    
    48s -> 20s
    
    Change-Id: Ifcfd96077a9e83868ac96671ce9f208ae3ca418f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175126
    Tested-by: Jenkins
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 2a21d9acc791..30dbe69773a6 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -2370,6 +2370,7 @@ $(eval $(call 
gb_UnoApi_add_idlfiles,offapi,com/sun/star/drawing,\
        XDrawPageSummarizer \
        XDrawPageSupplier \
        XDrawPages \
+       XDrawPages2 \
        XDrawPagesSupplier \
        XDrawSubController \
        XDrawView \
diff --git a/offapi/com/sun/star/drawing/XDrawPages2.idl 
b/offapi/com/sun/star/drawing/XDrawPages2.idl
new file mode 100644
index 000000000000..7131638c4204
--- /dev/null
+++ b/offapi/com/sun/star/drawing/XDrawPages2.idl
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+
+module com {  module sun {  module star {  module drawing {
+
+
+/**
+*/
+interface XDrawPages2 : com::sun::star::drawing::XDrawPages
+{
+
+    /** creates and inserts a new DrawPage or MasterPage
+        into this container
+
+        @param nIndex
+            the index at which the newly created DrawPage or
+            MasterPage will be inserted.
+
+        @param sName
+            The name for the new page. Currently only used for master pages.
+
+        @return
+            the newly created and already inserted DrawPage or
+            MasterPage.
+    */
+    com::sun::star::drawing::XDrawPage insertNamedNewByIndex( [in] long 
nIndex, [in] string sName );
+
+};
+
+
+}; }; }; };
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx
index 698336a590ca..317e99160a18 100644
--- a/sd/inc/sdpage.hxx
+++ b/sd/inc/sdpage.hxx
@@ -312,7 +312,7 @@ public:
 
     /** Set the name of the page and broadcast a model change.
     */
-    SD_DLLPUBLIC void SetName(const OUString& rName);
+    SD_DLLPUBLIC void SetName(const OUString& rName, bool 
bUpdatePageRelativeURLs = true);
 
     SD_DLLPUBLIC const sd::HeaderFooterSettings& getHeaderFooterSettings() 
const;
     SD_DLLPUBLIC void setHeaderFooterSettings( const sd::HeaderFooterSettings& 
rNewSettings );
diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx
index 48b0ca4e6baa..de125de66590 100644
--- a/sd/source/core/sdpage.cxx
+++ b/sd/source/core/sdpage.cxx
@@ -2696,11 +2696,12 @@ SdPage* SdPage::getImplementation( const 
css::uno::Reference< css::drawing::XDra
     return nullptr;
 }
 
-void SdPage::SetName (const OUString& rName)
+void SdPage::SetName (const OUString& rName, bool bUpdatePageRelativeURLs)
 {
     OUString aOldName( GetName() );
     FmFormPage::SetName (rName);
-    static_cast< SdDrawDocument& 
>(getSdrModelFromSdrPage()).UpdatePageRelativeURLs(aOldName, rName);
+    if (bUpdatePageRelativeURLs)
+        static_cast< SdDrawDocument& 
>(getSdrModelFromSdrPage()).UpdatePageRelativeURLs(aOldName, rName);
     ActionChanged();
 }
 
diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx
index 3141abd46bc9..424834b3bfd1 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -21,6 +21,7 @@
 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
 #include <com/sun/star/document/XLinkTargetSupplier.hpp>
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/drawing/XDrawPages2.hpp>
 #include <com/sun/star/drawing/XDrawPageDuplicator.hpp>
 #include <com/sun/star/drawing/XLayerSupplier.hpp>
 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
@@ -366,7 +367,7 @@ public:
 *                                                                      *
 ***********************************************************************/
 
-class SdMasterPagesAccess final : public ::cppu::WeakImplHelper< 
css::drawing::XDrawPages, css::lang::XServiceInfo, css::lang::XComponent >
+class SdMasterPagesAccess final : public ::cppu::WeakImplHelper< 
css::drawing::XDrawPages2, css::lang::XServiceInfo, css::lang::XComponent >
 {
 private:
     SdXImpressDocument* mpModel;
@@ -379,6 +380,9 @@ public:
     virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL 
insertNewByIndex( sal_Int32 nIndex ) override;
     virtual void SAL_CALL remove( const css::uno::Reference< 
css::drawing::XDrawPage >& xPage ) override;
 
+    // XDrawPages2
+    virtual css::uno::Reference< ::css::drawing::XDrawPage > SAL_CALL 
insertNamedNewByIndex( sal_Int32 nIndex, const OUString& sName ) override;
+
     // XIndexAccess
     virtual sal_Int32 SAL_CALL getCount() override ;
     virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
@@ -396,6 +400,9 @@ public:
     virtual void SAL_CALL dispose(  ) override;
     virtual void SAL_CALL addEventListener( const css::uno::Reference< 
css::lang::XEventListener >& xListener ) override;
     virtual void SAL_CALL removeEventListener( const css::uno::Reference< 
css::lang::XEventListener >& aListener ) override;
+
+private:
+    virtual css::uno::Reference< ::css::drawing::XDrawPage > insertNewImpl( 
sal_Int32 nIndex, std::optional<OUString> oName );
 };
 
 /***********************************************************************
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index ade8a206aa14..3abf1be3b0ad 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -4860,6 +4860,17 @@ sal_Bool SAL_CALL SdMasterPagesAccess::hasElements()
 
 // XDrawPages
 uno::Reference< drawing::XDrawPage > SAL_CALL 
SdMasterPagesAccess::insertNewByIndex( sal_Int32 nInsertPos )
+{
+    return insertNewImpl(nInsertPos, std::nullopt);
+}
+
+// XDrawPages2
+uno::Reference< drawing::XDrawPage > SAL_CALL 
SdMasterPagesAccess::insertNamedNewByIndex( sal_Int32 nInsertPos, const 
OUString& sName )
+{
+    return insertNewImpl(nInsertPos, sName);
+}
+
+uno::Reference< drawing::XDrawPage > SdMasterPagesAccess::insertNewImpl( 
sal_Int32 nInsertPos, std::optional<OUString> oPageName )
 {
     ::SolarMutexGuard aGuard;
 
@@ -4878,29 +4889,34 @@ uno::Reference< drawing::XDrawPage > SAL_CALL 
SdMasterPagesAccess::insertNewByIn
             nInsertPos = nMPageCount;
 
         // now generate a unique name for the new masterpage
-        const OUString aStdPrefix( SdResId(STR_LAYOUT_DEFAULT_NAME) );
-        OUString aPrefix( aStdPrefix );
+        OUString aPrefix;
+        if (oPageName)
+            aPrefix = *oPageName;
+        else
+        {
+            const OUString aStdPrefix( SdResId(STR_LAYOUT_DEFAULT_NAME) );
+            aPrefix = aStdPrefix;
 
-        bool bUnique = true;
+            bool bUnique = true;
 
-        std::vector<OUString> aPageNames;
-        for (sal_Int32 nMaster = 1; nMaster < nMPageCount; ++nMaster)
-        {
-            const SdPage* pPage = static_cast<const 
SdPage*>(pDoc->GetMasterPage(static_cast<sal_uInt16>(nMaster)));
-            if (!pPage)
-                continue;
-            aPageNames.push_back(pPage->GetName());
-            if (aPageNames.back() == aPrefix)
-                bUnique = false;
-        }
+            std::vector<OUString> aPageNames;
+            for (sal_Int32 nMaster = 1; nMaster < nMPageCount; ++nMaster)
+            {
+                const SdPage* pPage = static_cast<const 
SdPage*>(pDoc->GetMasterPage(static_cast<sal_uInt16>(nMaster)));
+                if (!pPage)
+                    continue;
+                aPageNames.push_back(pPage->GetName());
+                if (aPageNames.back() == aPrefix)
+                    bUnique = false;
+            }
 
-        sal_Int32 i = 0;
-        while (!bUnique)
-        {
-            aPrefix = aStdPrefix + " " + OUString::number(++i);
-            bUnique = std::find(aPageNames.begin(), aPageNames.end(), aPrefix) 
== aPageNames.end();
+            sal_Int32 i = 0;
+            while (!bUnique)
+            {
+                aPrefix = aStdPrefix + " " + OUString::number(++i);
+                bUnique = std::find(aPageNames.begin(), aPageNames.end(), 
aPrefix) == aPageNames.end();
+            }
         }
-
         OUString aLayoutName = aPrefix + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE;
 
         // create styles
@@ -4917,6 +4933,9 @@ uno::Reference< drawing::XDrawPage > SAL_CALL 
SdMasterPagesAccess::insertNewByIn
                            pPage->GetUpperBorder(),
                            pPage->GetRightBorder(),
                            pPage->GetLowerBorder() );
+        if (oPageName)
+            // no need to update the page URLs on a brand new page
+            pMPage->SetName(*oPageName, /*bUpdatePageRelativeURLs*/false);
         pMPage->SetLayoutName( aLayoutName );
         pDoc->InsertMasterPage(pMPage.get(),  
static_cast<sal_uInt16>(nInsertPos));
 
diff --git a/xmloff/source/draw/sdxmlimp.cxx b/xmloff/source/draw/sdxmlimp.cxx
index f8ec3a1b3aca..2cf82579f078 100644
--- a/xmloff/source/draw/sdxmlimp.cxx
+++ b/xmloff/source/draw/sdxmlimp.cxx
@@ -338,7 +338,7 @@ void SAL_CALL SdXMLImport::setTargetDocument( const 
uno::Reference< lang::XCompo
     // prepare access to master pages
     uno::Reference < drawing::XMasterPagesSupplier > 
xMasterPagesSupplier(GetModel(), uno::UNO_QUERY);
     if(xMasterPagesSupplier.is())
-        mxDocMasterPages = xMasterPagesSupplier->getMasterPages();
+        mxDocMasterPages.set(xMasterPagesSupplier->getMasterPages(), 
uno::UNO_QUERY_THROW);
 
     // prepare access to draw pages
     uno::Reference <drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(GetModel(), uno::UNO_QUERY);
diff --git a/xmloff/source/draw/sdxmlimp_impl.hxx 
b/xmloff/source/draw/sdxmlimp_impl.hxx
index 60641601a93f..212e65c01c16 100644
--- a/xmloff/source/draw/sdxmlimp_impl.hxx
+++ b/xmloff/source/draw/sdxmlimp_impl.hxx
@@ -20,6 +20,7 @@
 #pragma once
 
 #include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/drawing/XDrawPages2.hpp>
 #include <com/sun/star/task/XStatusIndicator.hpp>
 #include <xmloff/xmltkmap.hxx>
 #include <com/sun/star/container/XNameAccess.hpp>
@@ -48,7 +49,7 @@ typedef std::map<OUString, DateTimeDeclContextImpl> 
DateTimeDeclMap;
 class SdXMLImport: public SvXMLImport
 {
     css::uno::Reference< css::container::XNameAccess > mxDocStyleFamilies;
-    css::uno::Reference< css::container::XIndexAccess > mxDocMasterPages;
+    css::uno::Reference< css::drawing::XDrawPages2 > mxDocMasterPages;
     css::uno::Reference< css::container::XIndexAccess > mxDocDrawPages;
     css::uno::Reference< css::container::XNameAccess > mxPageLayouts;
 
@@ -103,7 +104,7 @@ public:
 
     // export local parameters concerning page access and similar
     const css::uno::Reference< css::container::XNameAccess >& 
GetLocalDocStyleFamilies() const { return mxDocStyleFamilies; }
-    const css::uno::Reference< css::container::XIndexAccess >& 
GetLocalMasterPages() const { return mxDocMasterPages; }
+    const css::uno::Reference< css::drawing::XDrawPages2 >& 
GetLocalMasterPages() const { return mxDocMasterPages; }
     const css::uno::Reference< css::container::XIndexAccess >& 
GetLocalDrawPages() const { return mxDocDrawPages; }
 
     sal_Int32 GetNewPageCount() const { return mnNewPageCount; }
diff --git a/xmloff/source/draw/ximpbody.cxx b/xmloff/source/draw/ximpbody.cxx
index 38664f6c121d..f1f19a156ffa 100644
--- a/xmloff/source/draw/ximpbody.cxx
+++ b/xmloff/source/draw/ximpbody.cxx
@@ -144,7 +144,7 @@ SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& 
rImport,
         // because of content/style file split. Now the mechanism is to
         // compare the wanted masterpage-name with the existing masterpages
         // which were loaded and created in the styles section loading.
-        uno::Reference< drawing::XDrawPages > 
xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
+        uno::Reference< drawing::XDrawPages2 > 
xMasterPages(GetSdImport().GetLocalMasterPages());
         uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, 
uno::UNO_QUERY);
         uno::Reference< drawing::XDrawPage > xMasterPage;
 
diff --git a/xmloff/source/draw/ximppage.cxx b/xmloff/source/draw/ximppage.cxx
index cb1ded1de477..8a9a69a63b66 100644
--- a/xmloff/source/draw/ximppage.cxx
+++ b/xmloff/source/draw/ximppage.cxx
@@ -229,6 +229,27 @@ SdXMLGenericPageContext::SdXMLGenericPageContext(
     }
 }
 
+SdXMLGenericPageContext::SdXMLGenericPageContext(
+    SvXMLImport& rImport,
+    const Reference< xml::sax::XFastAttributeList>& xAttrList)
+: SvXMLImportContext( rImport )
+{
+    for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
+    {
+        if( aIter.getToken() == XML_ELEMENT(DRAW, XML_NAV_ORDER) )
+        {
+            msNavOrder = aIter.toString();
+            break;
+        }
+    }
+}
+
+void SdXMLGenericPageContext::SetShapes(Reference< drawing::XShapes > const & 
rShapes)
+{
+    mxShapes = rShapes;
+    mxAnnotationAccess.set( rShapes, UNO_QUERY );
+}
+
 SdXMLGenericPageContext::~SdXMLGenericPageContext()
 {
 }
diff --git a/xmloff/source/draw/ximppage.hxx b/xmloff/source/draw/ximppage.hxx
index 5303458dd112..0073e8a12035 100644
--- a/xmloff/source/draw/ximppage.hxx
+++ b/xmloff/source/draw/ximppage.hxx
@@ -56,11 +56,15 @@ protected:
 
     void SetNavigationOrder();
 
+    void SetShapes(css::uno::Reference< css::drawing::XShapes > const & 
rShapes);
+
 public:
 
     SdXMLGenericPageContext( SvXMLImport& rImport,
         const css::uno::Reference< css::xml::sax::XFastAttributeList>& 
xAttrList,
         css::uno::Reference< css::drawing::XShapes > const & rShapes);
+    SdXMLGenericPageContext( SvXMLImport& rImport,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList>& 
xAttrList);
     virtual ~SdXMLGenericPageContext() override;
 
     virtual void SAL_CALL startFastElement( sal_Int32 nElement, const 
css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx
index 82f9160c2e69..2014ea5aec8c 100644
--- a/xmloff/source/draw/ximpstyl.cxx
+++ b/xmloff/source/draw/ximpstyl.cxx
@@ -681,6 +681,7 @@ 
SdXMLPresentationPlaceholderContext::~SdXMLPresentationPlaceholderContext()
 }
 
 
+// Only called for handout master
 SdXMLMasterPageContext::SdXMLMasterPageContext(
     SdXMLImport& rImport,
     sal_Int32 nElement,
@@ -688,7 +689,7 @@ SdXMLMasterPageContext::SdXMLMasterPageContext(
     uno::Reference< drawing::XShapes > const & rShapes)
 :   SdXMLGenericPageContext( rImport, xAttrList, rShapes )
 {
-    const bool bHandoutMaster = (nElement & TOKEN_MASK) == XML_HANDOUT_MASTER;
+    assert((nElement & TOKEN_MASK) == XML_HANDOUT_MASTER); (void)nElement;
     OUString sStyleName, sPageMasterName;
 
     for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
@@ -748,14 +749,111 @@ SdXMLMasterPageContext::SdXMLMasterPageContext(
 
     GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
 
-    // set page name?
-    if(!bHandoutMaster && !msDisplayName.isEmpty() && 
GetLocalShapesContext().is())
+    // set page-master?
+    if(!sPageMasterName.isEmpty())
     {
-        uno::Reference < container::XNamed > xNamed(GetLocalShapesContext(), 
uno::UNO_QUERY);
-        if(xNamed.is())
-            xNamed->setName(msDisplayName);
+        SetPageMaster( sPageMasterName );
     }
 
+    SetStyle( sStyleName );
+
+    SetLayout();
+
+    DeleteAllShapes();
+}
+
+// only called for normal master pages
+SdXMLMasterPageContext::SdXMLMasterPageContext(
+    SdXMLImport& rImport,
+    sal_Int32 nElement,
+    const uno::Reference< xml::sax::XFastAttributeList>& xAttrList,
+    uno::Reference< drawing::XDrawPages2 > const & xMasterPages)
+:   SdXMLGenericPageContext( rImport, xAttrList )
+{
+    assert((nElement & TOKEN_MASK) != XML_HANDOUT_MASTER); (void)nElement;
+    OUString sStyleName, sPageMasterName;
+
+    for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
+    {
+        const OUString sValue = aIter.toString();
+        switch(aIter.getToken())
+        {
+            case XML_ELEMENT(STYLE, XML_NAME):
+            {
+                msName = sValue;
+                break;
+            }
+            case XML_ELEMENT(STYLE, XML_DISPLAY_NAME):
+            {
+                msDisplayName = sValue;
+                break;
+            }
+            case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME):
+            {
+                sPageMasterName = sValue;
+                break;
+            }
+            case XML_ELEMENT(DRAW, XML_STYLE_NAME):
+            {
+                sStyleName = sValue;
+                break;
+            }
+            case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME):
+            {
+                maPageLayoutName = sValue;
+                break;
+            }
+            case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME):
+            {
+                maUseHeaderDeclName =  sValue;
+                break;
+            }
+            case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME):
+            {
+                maUseFooterDeclName =  sValue;
+                break;
+            }
+            case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME):
+            {
+                maUseDateTimeDeclName =  sValue;
+                break;
+            }
+            default:
+                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
+        }
+    }
+
+    if( msDisplayName.isEmpty() )
+        msDisplayName = msName;
+    else if( msDisplayName != msName )
+        GetImport().AddStyleDisplayName( XmlStyleFamily::MASTER_PAGE, msName, 
msDisplayName );
+
+    sal_Int32 nNewMasterPageCount = GetSdImport().GetNewMasterPageCount();
+    sal_Int32 nMasterPageCount = xMasterPages->getCount();
+    uno::Reference< drawing::XDrawPage > xNewMasterPage;
+    if (nNewMasterPageCount + 1 > nMasterPageCount)
+    {
+        // new page, create and insert
+        xNewMasterPage = xMasterPages->insertNamedNewByIndex(nMasterPageCount, 
msDisplayName);
+        SetShapes(xNewMasterPage);
+    }
+    else
+    {
+        // existing page, use it
+        xMasterPages->getByIndex(nNewMasterPageCount) >>= xNewMasterPage;
+        SetShapes(xNewMasterPage);
+        if(!msDisplayName.isEmpty())
+        {
+            uno::Reference < container::XNamed > xNamed(xNewMasterPage, 
uno::UNO_QUERY);
+            if(xNamed.is())
+                xNamed->setName(msDisplayName);
+        }
+    }
+    // increment global import page counter
+    GetSdImport().IncrementNewMasterPageCount();
+
+    GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
+
     // set page-master?
     if(!sPageMasterName.isEmpty())
     {
@@ -1323,41 +1421,24 @@ css::uno::Reference< css::xml::sax::XFastContextHandler 
> SdXMLMasterStylesConte
     else if( nElement == XML_ELEMENT(STYLE, XML_MASTER_PAGE) )
     {
         // style:masterpage inside office:styles context
-        uno::Reference< drawing::XDrawPage > xNewMasterPage;
-        uno::Reference< drawing::XDrawPages > 
xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
+        uno::Reference< drawing::XDrawPages2 > 
xMasterPages(GetSdImport().GetLocalMasterPages());
 
         if( xMasterPages.is() )
         {
-            sal_Int32 nNewMasterPageCount = 
GetSdImport().GetNewMasterPageCount();
             sal_Int32 nMasterPageCount = xMasterPages->getCount();
-            if (nNewMasterPageCount + 1 > nMasterPageCount)
-            {
-                // arbitrary limit to master pages when fuzzing to avoid 
deadend timeouts
-                if (nMasterPageCount >= 64 && comphelper::IsFuzzing())
-                    return nullptr;
+            // arbitrary limit to master pages when fuzzing to avoid deadend 
timeouts
+            if (nMasterPageCount >= 64 && comphelper::IsFuzzing())
+               return nullptr;
 
-                // new page, create and insert
-                xNewMasterPage = 
xMasterPages->insertNewByIndex(nMasterPageCount);
-            }
-            else
-            {
-                // existing page, use it
-                xMasterPages->getByIndex(nNewMasterPageCount) >>= 
xNewMasterPage;
-            }
-
-            // increment global import page counter
-            GetSdImport().IncrementNewMasterPageCount();
+            // new page, create and insert
 
-            if(xNewMasterPage.is())
+            if(GetSdImport().GetShapeImport()->GetStylesContext())
             {
-                if(GetSdImport().GetShapeImport()->GetStylesContext())
-                {
-                    const rtl::Reference<SdXMLMasterPageContext> xLclContext{
-                        new SdXMLMasterPageContext(GetSdImport(),
-                            nElement, xAttrList, xNewMasterPage)};
-                    maMasterPageList.push_back(xLclContext);
-                    return xLclContext;
-                }
+                const rtl::Reference<SdXMLMasterPageContext> xLclContext{
+                    new SdXMLMasterPageContext(GetSdImport(),
+                        nElement, xAttrList, xMasterPages)};
+                maMasterPageList.push_back(xLclContext);
+                return xLclContext;
             }
         }
     }
diff --git a/xmloff/source/draw/ximpstyl.hxx b/xmloff/source/draw/ximpstyl.hxx
index 115bf2bcb5b5..1a89cc83bffa 100644
--- a/xmloff/source/draw/ximpstyl.hxx
+++ b/xmloff/source/draw/ximpstyl.hxx
@@ -27,6 +27,7 @@
 #include "ximppage.hxx"
 #include <xmloff/xmlstyle.hxx>
 #include <com/sun/star/view/PaperOrientation.hpp>
+#include <com/sun/star/drawing/XDrawPages2.hpp>
 #include <memory>
 #include <vector>
 
@@ -93,6 +94,13 @@ class SdXMLMasterPageContext: public SdXMLGenericPageContext
 
 public:
 
+    // called for normal master page
+    SdXMLMasterPageContext(
+        SdXMLImport& rImport,
+        sal_Int32 nElement,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList >& 
xAttrList,
+        css::uno::Reference< css::drawing::XDrawPages2 > const & xMasterPages);
+    // Called for handout master page
     SdXMLMasterPageContext(
         SdXMLImport& rImport,
         sal_Int32 nElement,

Reply via email to