sd/source/core/drawdoc2.cxx                             |   32 ++++++++++------
 sd/source/filter/eppt/pptx-epptbase.cxx                 |    7 ---
 sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx |   32 +++++++---------
 sd/source/ui/view/ViewClipboard.cxx                     |    4 +-
 4 files changed, 38 insertions(+), 37 deletions(-)

New commits:
commit 4817eac25410c48f4652bc6ebe2078a73bb8041b
Author:     Mohit Marathe <[email protected]>
AuthorDate: Fri Nov 28 17:03:59 2025 +0530
Commit:     Mohit Marathe <[email protected]>
CommitDate: Mon Dec 1 07:49:14 2025 +0100

    sd: make sure canvas page remains as the first page
    
    also reverts 7f5c359ab120ec89af04e2f9cbaee387c30662fb
    
    Signed-off-by: Mohit Marathe <[email protected]>
    Change-Id: I61a3b9baa5e592a662e137b56afeaebc0c855c4d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194773
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx
index 8ce9859989ab..450b9b446bf6 100644
--- a/sd/source/core/drawdoc2.cxx
+++ b/sd/source/core/drawdoc2.cxx
@@ -433,6 +433,13 @@ void SdDrawDocument::UpdatePageRelativeURLs(SdPage const * 
pPage, sal_uInt16 nPo
 // Move page
 void SdDrawDocument::MovePage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
 {
+    if (HasCanvasPage())
+    {
+        if (nPgNum == 1)
+            return;
+        if (nNewPos == 1)
+            nNewPos = 3;
+    }
     FmFormModel::MovePage(nPgNum, nNewPos);
 
     sal_uInt16 nMin = std::min(nPgNum, nNewPos);
@@ -1495,10 +1502,8 @@ bool SdDrawDocument::ValidateCanvasPage(const SdPage* 
pPage) const
 
 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);
+    // what if canvas page is not the first page?
+    SdPage* pPage = GetSdPage(0, PageKind::Standard);
     bool bIsCanvasPageValid = ValidateCanvasPage(pPage);
     pPage->SetCanvasPage();
     mpCanvasPage = pPage;
@@ -1583,7 +1588,7 @@ void SdDrawDocument::ReshufflePages()
     {
         SdPage* pPage = 
static_cast<SdPage*>(aPageOrder[i]->GetReferencedPage());
         sal_uInt16 nCurrentPageNum = pPage->GetPageNum();
-        sal_uInt16 nTargetPageNum = 2 * i + 1;
+        sal_uInt16 nTargetPageNum = 2 * (i + 1) + 1;
         MovePage(nCurrentPageNum, nTargetPageNum); // Standard page
         MovePage(nCurrentPageNum + 1, nTargetPageNum + 1); // Notes page
     }
@@ -1598,15 +1603,20 @@ sal_uInt16 SdDrawDocument::GetOrInsertCanvasPage()
     sal_uInt16 nLastPageNum = GetSdPageCount(PageKind::Standard);
     SdPage* pLastStandardPage = GetSdPage(nLastPageNum - 1, 
PageKind::Standard);
 
-    sal_uInt16 nCanvasPageNum = CreatePage(pLastStandardPage, 
PageKind::Standard,
+    sal_uInt16 nCanvasPageIndex = CreatePage(pLastStandardPage, 
PageKind::Standard,
                                            u"Canvas Page"_ustr, u"Canvas notes 
page"_ustr,
                                            AutoLayout::AUTOLAYOUT_NONE, 
AutoLayout::AUTOLAYOUT_NONE,
                                            false, false, 
pLastStandardPage->GetPageNum() + 2);
 
-    SdPage* pCanvasPage = GetSdPage(nCanvasPageNum, PageKind::Standard);
+    SdPage* pCanvasPage = GetSdPage(nCanvasPageIndex, PageKind::Standard);
     if (!pCanvasPage)
         return 0xffff;
 
+    // move the canvas page to the top
+    sal_uInt16 nCanvasPageNum = 2 * nCanvasPageIndex + 1;
+    MovePage(nCanvasPageNum, 1); // Canvas page
+    MovePage(nCanvasPageNum + 1, 2); // Canvas notes page
+
     const Size aCanvasSize(500000, 500000);
 
     ResizeCurrentPage(pCanvasPage, aCanvasSize, PageKind::Standard);
@@ -1642,9 +1652,9 @@ static int calculateGridColumns(const sal_uInt16 nCnt)
 
 void SdDrawDocument::populatePagePreviewsGrid()
 {
-    sal_uInt16 nPageCnt = GetSdPageCount(PageKind::Standard) - 1; // don't 
count the canvas page
-    sal_uInt16 nTotalCol = 
static_cast<sal_uInt16>(calculateGridColumns(nPageCnt));
-    sal_uInt16 nTotalRow = nPageCnt / nTotalCol + (nPageCnt % nTotalCol ? 1 : 
0);
+    sal_uInt16 nPageCnt = GetSdPageCount(PageKind::Standard);
+    sal_uInt16 nTotalCol = 
static_cast<sal_uInt16>(calculateGridColumns(nPageCnt - 1));
+    sal_uInt16 nTotalRow = (nPageCnt - 1) / nTotalCol + ((nPageCnt - 1) % 
nTotalCol ? 1 : 0);
 
     // width and height of a standard 16:9 page
     sal_uInt16 nWidth = 28000;
@@ -1680,7 +1690,7 @@ void SdDrawDocument::populatePagePreviewsGrid()
         ::tools::Long nX = (mpCanvasPage->GetWidth() - nTotalGridWidth) / 2;
         for (sal_uInt16 nCol = 0; nCol < nTotalCol; nCol++)
         {
-            sal_uInt16 nCurrentPageIndex = nTotalCol * nRow + nCol;
+            sal_uInt16 nCurrentPageIndex = nTotalCol * nRow + nCol + 1;
             if (nCurrentPageIndex == nPageCnt)
                 return;
             SdPage* pPage = GetSdPage(nCurrentPageIndex, PageKind::Standard);
diff --git a/sd/source/filter/eppt/pptx-epptbase.cxx 
b/sd/source/filter/eppt/pptx-epptbase.cxx
index 6b65f886f07c..0b3205eb38cb 100644
--- a/sd/source/filter/eppt/pptx-epptbase.cxx
+++ b/sd/source/filter/eppt/pptx-epptbase.cxx
@@ -241,13 +241,6 @@ bool PPTWriterBase::InitSOIface()
         if ( !GetPageByIndex( 0, NORMAL ) )
             break;
 
-        SdXImpressDocument* pModel = 
comphelper::getFromUnoTunnel<SdXImpressDocument>(mXModel);
-        if (pModel)
-        {
-            SdDrawDocument* pDoc = pModel->GetDoc();
-            if (pDoc && pDoc->HasCanvasPage())
-                mnPages--;
-        }
         return true;
     }
     return false;
diff --git a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx 
b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
index ef62841fd98e..4840c44f5c82 100644
--- a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
+++ b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
@@ -765,7 +765,10 @@ void SlideSorterViewShell::ExecMovePageFirst (SfxRequest& 
/*rReq*/)
     SyncPageSelectionToDocument(xSelection);
 
     // Moves selected pages after page -1
-    GetDoc()->MoveSelectedPages( sal_uInt16(-1) );
+    if (!GetDoc()->HasCanvasPage())
+        GetDoc()->MoveSelectedPages( sal_uInt16(-1) );
+    else
+        GetDoc()->MoveSelectedPages(1);
 
     PostMoveSlidesActions(xSelection);
 }
@@ -799,11 +802,18 @@ void SlideSorterViewShell::GetStateMovePageFirst 
(SfxItemSet& rSet)
     }
 
     if (GetDoc()->HasCanvasPage())
-        if (firstSelectedPageNo == 
GetDoc()->GetSdPageCount(PageKind::Standard) - 1)
+    {
+        if (firstSelectedPageNo == 0)
+        {
+            rSet.DisableItem( SID_MOVE_PAGE_LAST );
+            rSet.DisableItem( SID_MOVE_PAGE_DOWN );
+        }
+        if (firstSelectedPageNo == 1)
         {
             rSet.DisableItem( SID_MOVE_PAGE_FIRST );
             rSet.DisableItem( SID_MOVE_PAGE_UP );
         }
+    }
 }
 
 void SlideSorterViewShell::ExecMovePageUp (SfxRequest& /*rReq*/)
@@ -825,9 +835,8 @@ void SlideSorterViewShell::ExecMovePageUp (SfxRequest& 
/*rReq*/)
 
     if (firstSelectedPageNo == 0)
         return;
-
     if (GetDoc()->HasCanvasPage())
-        if (firstSelectedPageNo == 
GetDoc()->GetSdPageCount(PageKind::Standard) - 1)
+        if (firstSelectedPageNo == 1)
             return;
 
     // Move pages before firstSelectedPageNo - 1 (so after firstSelectedPageNo 
- 2),
@@ -860,7 +869,7 @@ void SlideSorterViewShell::ExecMovePageDown (SfxRequest& 
/*rReq*/)
     if (lastSelectedPageNo == nNoOfPages - 1)
         return;
     if (GetDoc()->HasCanvasPage())
-        if (lastSelectedPageNo == nNoOfPages - 2)
+        if (lastSelectedPageNo == 0)
             return;
 
     // Move to position after lastSelectedPageNo
@@ -888,10 +897,7 @@ void SlideSorterViewShell::ExecMovePageLast (SfxRequest& 
/*rReq*/)
     sal_uInt16 nNoOfPages = GetDoc()->GetSdPageCount(PageKind::Standard);
 
     // Move to position after last page No (=Number of pages - 1)
-    if (!GetDoc()->HasCanvasPage())
-        GetDoc()->MoveSelectedPages( nNoOfPages - 1 );
-    else
-        GetDoc()->MoveSelectedPages( nNoOfPages - 2 );
+    GetDoc()->MoveSelectedPages( nNoOfPages - 1 );
 
     PostMoveSlidesActions(xSelection);
 }
@@ -923,14 +929,6 @@ void SlideSorterViewShell::GetStateMovePageLast 
(SfxItemSet& rSet)
         rSet.DisableItem( SID_MOVE_PAGE_LAST );
         rSet.DisableItem( SID_MOVE_PAGE_DOWN );
     }
-    if (GetDoc()->HasCanvasPage())
-    {
-        if (lastSelectedPageNo == nNoOfPages - 2)
-        {
-            rSet.DisableItem( SID_MOVE_PAGE_LAST );
-            rSet.DisableItem( SID_MOVE_PAGE_DOWN );
-        }
-    }
 }
 
 void SlideSorterViewShell::PostMoveSlidesActions(const 
std::shared_ptr<SlideSorterViewShell::PageSelection> &rpSelection)
diff --git a/sd/source/ui/view/ViewClipboard.cxx 
b/sd/source/ui/view/ViewClipboard.cxx
index 14adb70ca32e..608e9ee41aaf 100644
--- a/sd/source/ui/view/ViewClipboard.cxx
+++ b/sd/source/ui/view/ViewClipboard.cxx
@@ -174,8 +174,8 @@ sal_uInt16 ViewClipboard::DetermineInsertPosition  ()
     }
     if (rDoc.HasCanvasPage())
     {
-        if (nInsertPos == rDoc.GetPageCount())
-            nInsertPos = rDoc.GetPageCount() - 2;
+        if (nInsertPos == 1)
+            nInsertPos = 3;
     }
 
     return nInsertPos;

Reply via email to