sd/inc/drawdoc.hxx | 3 +++ sd/source/core/drawdoc2.cxx | 42 ++++++++++++++++++++++++++++++++++++++++++ sd/source/ui/inc/unokywds.hxx | 2 ++ sd/source/ui/view/frmview.cxx | 7 +++++++ 4 files changed, 54 insertions(+)
New commits: commit d0fd7a2635ef1b3de0ba8b8b79ad425f820de5a3 Author: Mohit Marathe <[email protected]> AuthorDate: Wed Oct 29 18:59:10 2025 +0530 Commit: Michael Stahl <[email protected]> CommitDate: Mon Jan 12 19:37:57 2026 +0100 sd: store "HasCanvasPage" boolean in settings.xml and validate the incoming canvas page Signed-off-by: Mohit Marathe <[email protected]> Change-Id: I2a110a8cd674e8a6d5be61b9623f9373deaa6f2d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193243 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Michael Stahl <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196704 diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx index f0afaa39826d..9d5c33d1a3b7 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -1005,6 +1005,9 @@ public: SAL_DLLPRIVATE bool HasCanvasPage() const { return mpCanvasPage.is(); } + SAL_DLLPRIVATE void ImportCanvasPage(); + SAL_DLLPRIVATE bool ValidateCanvasPage(const SdPage* pPage) const; + SAL_DLLPRIVATE sal_uInt16 GetOrInsertCanvasPage (); /** return the document fonts for latin, cjk and ctl according to the current diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx index 63f9634fc2a6..e163bc2cf525 100644 --- a/sd/source/core/drawdoc2.cxx +++ b/sd/source/core/drawdoc2.cxx @@ -18,6 +18,7 @@ */ #include <algorithm> +#include <unordered_set> #include <vcl/settings.hxx> #include <sal/log.hxx> @@ -1471,6 +1472,47 @@ void SdDrawDocument::SetupNewPage ( } } +bool SdDrawDocument::ValidateCanvasPage(const SdPage* pPage) const +{ + std::unordered_set<SdrPage*> aPreviewPageSet; + SdrObjListIter aIter(pPage, SdrIterMode::Flat); + for (SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next()) + { + if (pObj->GetObjIdentifier() != SdrObjKind::Page) + continue; + SdrPageObj* pPageObj = static_cast<SdrPageObj*>(pObj); + SdrPage* pPreviewPage = pPageObj->GetReferencedPage(); + if (aPreviewPageSet.contains(pPreviewPage)) + return false; + else + aPreviewPageSet.insert(pPreviewPage); + } + if (aPreviewPageSet.size() != GetSdPageCount(PageKind::Standard) - 1) + return false; + return true; +} + +void SdDrawDocument::ImportCanvasPage() +{ + sal_uInt16 nStdPageCnt = GetSdPageCount(PageKind::Standard); + + // what if canvas page is not the last page? + SdPage* pPage = GetSdPage(nStdPageCnt - 1, PageKind::Standard); + bool bIsCanvasPageValid = ValidateCanvasPage(pPage); + pPage->SetCanvasPage(); + mpCanvasPage = pPage; + // re-populate the previews grid if not valid + if (!bIsCanvasPageValid) + { + while (pPage->GetObjCount() > 0) + { + // maybe only SdrPageObj(s) should be removed? + pPage->NbcRemoveObject(0); + } + populatePagePreviewsGrid(); + } +} + void SdDrawDocument::ReshufflePages() { SdrObjList* pObjList = mpCanvasPage.get(); diff --git a/sd/source/ui/inc/unokywds.hxx b/sd/source/ui/inc/unokywds.hxx index 67c0fbabb3f3..5b2297fbfa37 100644 --- a/sd/source/ui/inc/unokywds.hxx +++ b/sd/source/ui/inc/unokywds.hxx @@ -113,4 +113,6 @@ inline constexpr OUString sUNO_View_VisibleAreaHeight = u"VisibleAreaHeight"_ust inline constexpr OUString sUNO_View_ZoomOnPage = u"ZoomOnPage"_ustr; +inline constexpr OUString sUNO_View_HasCanvasPage = u"HasCanvasPage"_ustr; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/view/frmview.cxx b/sd/source/ui/view/frmview.cxx index 7def456f4468..2d6cc454bb02 100644 --- a/sd/source/ui/view/frmview.cxx +++ b/sd/source/ui/view/frmview.cxx @@ -405,6 +405,7 @@ void FrameView::WriteUserDataSequence ( css::uno::Sequence < css::beans::Propert { std::vector< std::pair< OUString, Any > > aUserData; aUserData.reserve(41); // worst case + SdDrawDocument* pDrawDocument = dynamic_cast<SdDrawDocument*>(&GetModel()); aUserData.emplace_back( sUNO_View_GridIsVisible, Any( IsGridVisible() ) ); aUserData.emplace_back( sUNO_View_GridIsFront, Any( IsGridFront() ) ); @@ -479,6 +480,7 @@ void FrameView::WriteUserDataSequence ( css::uno::Sequence < css::beans::Propert aUserData.emplace_back( sUNO_View_GridSnapWidthYDenominator, Any( GetSnapGridWidthY().GetDenominator() ) ); aUserData.emplace_back( sUNO_View_IsAngleSnapEnabled, Any( IsAngleSnapEnabled() ) ); aUserData.emplace_back( sUNO_View_SnapAngle, Any( static_cast<sal_Int32>(GetSnapAngle()) ) ); + aUserData.emplace_back( sUNO_View_HasCanvasPage, Any( pDrawDocument->HasCanvasPage() ) ); const sal_Int32 nOldLength = rValues.getLength(); rValues.realloc( nOldLength + aUserData.size() ); @@ -910,6 +912,11 @@ void FrameView::ReadUserDataSequence ( const css::uno::Sequence < css::beans::Pr aSdrLayerIDSets.PutValue( rValue.Value ); SetLockedLayers( aSdrLayerIDSets ); } + else if ( bImpress && rValue.Name == sUNO_View_HasCanvasPage ) + { + if ( (rValue.Value >>= bBool) && bBool ) + pDrawDocument->ImportCanvasPage(); + } } SetViewShEditModeOnLoad(EditMode::Page);
