sd/source/core/drawdoc2.cxx          |   13 +++++++++++++
 sd/source/ui/unoidl/unopage.cxx      |    4 ++++
 sd/source/ui/view/drviews1.cxx       |    6 +++++-
 xmloff/source/draw/sdxmlimp.cxx      |   33 +++++++++++++++++++++++++++++++++
 xmloff/source/draw/sdxmlimp_impl.hxx |   13 ++++++++++++-
 xmloff/source/draw/ximpshap.cxx      |    9 +++++++++
 6 files changed, 76 insertions(+), 2 deletions(-)

New commits:
commit 56cd2b393119e15ab46e4914fb0eeb2312bbdabf
Author:     Mohit Marathe <[email protected]>
AuthorDate: Thu Dec 11 18:26:20 2025 +0530
Commit:     Mohit Marathe <[email protected]>
CommitDate: Tue Dec 16 07:01:57 2025 +0100

    sd: lok: send CanvasPageCenter command to client on canvas page creation
    
    Signed-off-by: Mohit Marathe <[email protected]>
    Change-Id: I5c29ac2393c25ed3f3b5f45303920e735e1f9bd6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195466
    Reviewed-by: Michael Stahl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx
index 95cdabc6c3f4..4a4c47c73565 100644
--- a/sd/source/core/drawdoc2.cxx
+++ b/sd/source/core/drawdoc2.cxx
@@ -65,6 +65,7 @@
 
 #include <DrawDocShell.hxx>
 #include <ViewShell.hxx>
+#include <DrawViewShell.hxx>
 
 #include "PageListWatcher.hxx"
 #include <strings.hxx>
@@ -514,7 +515,14 @@ rtl::Reference<SdrPage> 
SdDrawDocument::RemovePage(sal_uInt16 nPgNum)
 
     auto pSdPage = static_cast<SdPage*>(pPage.get());
     if (pSdPage->IsCanvasPage())
+    {
+        if (comphelper::LibreOfficeKit::isActive())
+        {
+            DrawViewShell* pDrawViewSh = 
dynamic_cast<DrawViewShell*>(mpDocSh->GetViewShell());
+            pDrawViewSh->RememberCanvasPageVisArea(::tools::Rectangle());
+        }
         mpCanvasPage = nullptr;
+    }
     pSdPage->DisconnectLink();
     ReplacePageInCustomShows( pSdPage, nullptr );
     UpdatePageObjectsInNotes(nPgNum);
diff --git a/sd/source/ui/view/drviews1.cxx b/sd/source/ui/view/drviews1.cxx
index dbcb265aa1ab..c768ff4d10fd 100644
--- a/sd/source/ui/view/drviews1.cxx
+++ b/sd/source/ui/view/drviews1.cxx
@@ -1114,8 +1114,12 @@ bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage, 
bool bAllowChangeFocus)
                 }
                 if (GetDoc()->HasCanvasPage() && 
getCurrentPage()->IsCanvasPage() && bAllowChangeFocus)
                 {
+                    bool bShowCenter = maCanvasPageVisArea.IsEmpty();
                     ::tools::JsonWriter aJsonWriter;
-                    aJsonWriter.put("commandName", "CanvasPageVisArea");
+                    if (bShowCenter)
+                        aJsonWriter.put("commandName", "CanvasPageCenter");
+                    else
+                        aJsonWriter.put("commandName", "CanvasPageVisArea");
                     {
                         auto jsonState = aJsonWriter.startNode("state");
                         aJsonWriter.put("x", maCanvasPageVisArea.Left());
commit f0bf2ef52dbd60cd28cba76526f6ba9341f113e9
Author:     Mohit Marathe <[email protected]>
AuthorDate: Fri Dec 5 17:01:14 2025 +0530
Commit:     Mohit Marathe <[email protected]>
CommitDate: Tue Dec 16 07:01:46 2025 +0100

    xmloff: svx: handle import of page shapes that are inside canvas page
    
    Since the canvas page is the first page, the reference page of the page
    shapes are not properly set during import as the other pages does
    not exist yet.
    
    Hence, store the corresponding page number in SdXMLImport, and resolve it
    in SdXMLImport::endDocument()
    
    This went unnoticed as the canvas page got repaired during import.
    
    Signed-off-by: Mohit Marathe <[email protected]>
    Change-Id: Ice966768eafaaaad3a65c3148e3573d20fec8026
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195076
    Reviewed-by: Michael Stahl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx
index 9817cff1bc2b..95cdabc6c3f4 100644
--- a/sd/source/core/drawdoc2.cxx
+++ b/sd/source/core/drawdoc2.cxx
@@ -1500,6 +1500,11 @@ bool SdDrawDocument::ValidateCanvasPage(const SdPage* 
pPage) const
             continue;
         SdrPageObj* pPageObj = static_cast<SdrPageObj*>(pObj);
         SdrPage* pPreviewPage = pPageObj->GetReferencedPage();
+        if (!pPreviewPage)
+        {
+            SAL_WARN("sd", "SdrObject does point to a valid page");
+            return false;
+        }
         if (aPreviewPageSet.contains(pPreviewPage))
             return false;
         else
diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx
index ae0acb28b4b2..a15db4b6eb6a 100644
--- a/sd/source/ui/unoidl/unopage.cxx
+++ b/sd/source/ui/unoidl/unopage.cxx
@@ -452,6 +452,10 @@ rtl::Reference<SdrObject> 
SdGenericDrawPage::CreateSdrObject_( const Reference<
     {
         if( GetPage()->GetPageKind() == PageKind::Notes && 
GetPage()->IsMasterPage() )
             eObjKind = PresObjKind::Title;
+        else if (GetPage()->GetPageKind() == PageKind::Standard
+            && !GetPage()->IsMasterPage())
+            // might be a canvas page
+            eObjKind = PresObjKind::PagePreview;
         else
             eObjKind = PresObjKind::Page;
     }
diff --git a/xmloff/source/draw/sdxmlimp.cxx b/xmloff/source/draw/sdxmlimp.cxx
index c46d397c1167..5df294a8f6f9 100644
--- a/xmloff/source/draw/sdxmlimp.cxx
+++ b/xmloff/source/draw/sdxmlimp.cxx
@@ -405,6 +405,34 @@ void SAL_CALL SdXMLImport::initialize( const 
uno::Sequence< uno::Any >& aArgumen
     }
 }
 
+void SAL_CALL SdXMLImport::endDocument()
+{
+    SvXMLImport::endDocument();
+
+    // Resolve SdrPageObj references that couldn't be resolved during import
+    // (because the target page didn't exist yet at import time).
+    for (const auto& rRef : maPageShapeRefs)
+    {
+        if (!rRef.mxShape.is())
+            continue;
+
+        uno::Reference<beans::XPropertySet> xPropSet(rRef.mxShape, 
uno::UNO_QUERY);
+        if (!xPropSet.is())
+            continue;
+
+        if 
(xPropSet->getPropertySetInfo()->hasPropertyByName(u"PageNumber"_ustr))
+        {
+            sal_Int32 nPageNum = 0;
+            if ((xPropSet->getPropertyValue(u"PageNumber"_ustr) >>= nPageNum) 
&& nPageNum == 0)
+            {
+                xPropSet->setPropertyValue(u"PageNumber"_ustr, 
uno::Any(rRef.mnPageNumber));
+            }
+        }
+    }
+
+    maPageShapeRefs.clear();
+}
+
 SvXMLImportContext *SdXMLImport::CreateFastContext( sal_Int32 nElement,
         const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
 {
@@ -630,6 +658,11 @@ void SdXMLImport::AddDateTimeDecl( const OUString& rName, 
const OUString& rText,
     }
 }
 
+void SdXMLImport::AddPageShapePageNum(const 
css::uno::Reference<css::drawing::XShape>& rxShape, sal_Int32 nPageNumber)
+{
+    maPageShapeRefs.push_back({rxShape, nPageNumber});
+}
+
 OUString SdXMLImport::GetHeaderDecl( const OUString& rName ) const
 {
     OUString aRet;
diff --git a/xmloff/source/draw/sdxmlimp_impl.hxx 
b/xmloff/source/draw/sdxmlimp_impl.hxx
index 212e65c01c16..3d52294def51 100644
--- a/xmloff/source/draw/sdxmlimp_impl.hxx
+++ b/xmloff/source/draw/sdxmlimp_impl.hxx
@@ -70,8 +70,16 @@ class SdXMLImport: public SvXMLImport
     HeaderFooterDeclMap         maFooterDeclsMap;
     DateTimeDeclMap             maDateTimeDeclsMap;
 
-protected:
+    // Storage for page shape references that need to be resolved in 
endDocument()
+    // when all pages have been imported
+    struct PageShapeRef
+    {
+        css::uno::Reference<css::drawing::XShape> mxShape;
+        sal_Int32 mnPageNumber;
+    };
+    std::vector<PageShapeRef> maPageShapeRefs;
 
+protected:
     // This method is called after the namespace map has been updated, but
     // before a context for the current element has been pushed.
     virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
@@ -89,6 +97,7 @@ public:
     // XInitialization
     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any 
>& aArguments ) override;
 
+    virtual void SAL_CALL endDocument() override;
     virtual void SetViewSettings(const 
css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
     virtual void SetConfigurationSettings(const 
css::uno::Sequence<css::beans::PropertyValue>& aConfigProps) override;
 
@@ -125,6 +134,8 @@ public:
     void AddHeaderDecl( const OUString& rName, const OUString& rText );
     void AddFooterDecl( const OUString& rName, const OUString& rText );
     void AddDateTimeDecl( const OUString& rName, const OUString& rText, bool 
bFixed, const OUString& rDateTimeFormat );
+    void AddPageShapePageNum(const css::uno::Reference<css::drawing::XShape>& 
rxShape,
+                         sal_Int32 nPageNumber);
 
     OUString GetHeaderDecl( const OUString& rName ) const;
     OUString GetFooterDecl( const OUString& rName ) const;
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 9ef86aa801d5..7b00b3ec94ff 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -68,6 +68,7 @@
 #include <XMLReplacementImageContext.hxx>
 #include <XMLImageMapContext.hxx>
 #include "sdpropls.hxx"
+#include "sdxmlimp_impl.hxx"
 #include "eventimp.hxx"
 #include "descriptionimp.hxx"
 #include "SignatureLineContext.hxx"
@@ -2254,6 +2255,14 @@ void SdXMLPageShapeContext::startFastElement (sal_Int32 
nElement,
             xPropSet->setPropertyValue(aPageNumberStr, uno::Any( mnPageNumber 
));
     }
 
+    // For later resolution of page shape references, in case the target page 
does not
+    // exist during import. This will be resolved in SdXMLImport::endDocument()
+    if (mnPageNumber > 0)
+    {
+        if (SdXMLImport* pSdImport = dynamic_cast<SdXMLImport*>(&GetImport()))
+            pSdImport->AddPageShapePageNum(mxShape, mnPageNumber);
+    }
+
     SdXMLShapeContext::startFastElement(nElement, xAttrList);
 }
 

Reply via email to