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 e107108aa07a0a0f7418231f561a159d8cc7d53d Author: Mohit Marathe <[email protected]> AuthorDate: Wed Oct 29 18:59:10 2025 +0530 Commit: Mohit Marathe <[email protected]> CommitDate: Fri Nov 21 13:59:15 2025 +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]> diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx index 64d1b78bbc1b..8b3e3656d37d 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -1036,6 +1036,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 89c79994afc8..77970635602a 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> @@ -1472,6 +1473,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 54b84a5f550f..0f48f7b9899f 100644 --- a/sd/source/ui/view/frmview.cxx +++ b/sd/source/ui/view/frmview.cxx @@ -406,6 +406,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() ) ); @@ -480,6 +481,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() ); @@ -911,6 +913,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);
