sd/source/core/drawdoc.cxx |   82 ++++++++++++++++++++++++++++++---------------
 1 file changed, 56 insertions(+), 26 deletions(-)

New commits:
commit a1f3108cae0b5d592bd1c2d6aee78ac4f70e595f
Author:     Mohit Marathe <[email protected]>
AuthorDate: Sat Jan 10 13:26:51 2026 +0530
Commit:     Michael Stahl <[email protected]>
CommitDate: Tue Jan 13 19:52:54 2026 +0100

    tdf#170277 sd: allow setting different page size of a master page directly
    
    Earlier it was only possible to do this via resizing a normal page.
    
    Signed-off-by: Mohit Marathe <[email protected]>
    Change-Id: I93a3b8a57258c5fdbc234d613b6e5d1f3425af7b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196952
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index cdbc3985aff8..db764cbd26b9 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -467,26 +467,31 @@ void SdDrawDocument::ResizeCurrentPage(
 
     // TODO: handle undo action for new master page creation
 
-    SdPage* pMasterPage = static_cast<SdPage*>(&pPage->TRG_GetMasterPage());
+    bool bIsMasterPage = pPage->IsMasterPage();
 
-    // Count how many pages uses pMasterPage
-    sal_uInt16 nCount = 0;
-    for (sal_uInt16 i = 0; i < nPageCnt && nCount <= 1; i++)
+    SdPage* pMasterPage = bIsMasterPage ? pPage : 
static_cast<SdPage*>(&pPage->TRG_GetMasterPage());
+
+    if (!bIsMasterPage)
     {
-        SdPage* pDrawPage = GetSdPage(i, ePageKind);
-        if (pDrawPage->TRG_HasMasterPage() &&
-            static_cast<SdPage*>(&pDrawPage->TRG_GetMasterPage()) == 
pMasterPage)
+        // Count how many pages uses pMasterPage
+        sal_uInt16 nCount = 0;
+        for (sal_uInt16 i = 0; i < nPageCnt && nCount <= 1; i++)
         {
-            nCount++;
+            SdPage* pDrawPage = GetSdPage(i, ePageKind);
+            if (pDrawPage->TRG_HasMasterPage() &&
+                static_cast<SdPage*>(&pDrawPage->TRG_GetMasterPage()) == 
pMasterPage)
+            {
+                nCount++;
+            }
         }
-    }
 
-    // If pMasterPage is used by other pages, create a new master page
-    if (nCount > 1)
-    {
-        SdPage* pNewMasterPage = AddNewMasterPageFromExisting(pMasterPage);
-        pPage->TRG_SetMasterPage(static_cast<SdrPage&>(*pNewMasterPage));
-        pMasterPage = pNewMasterPage;
+        // If pMasterPage is used by other pages, create a new master page
+        if (nCount > 1)
+        {
+            SdPage* pNewMasterPage = AddNewMasterPageFromExisting(pMasterPage);
+            pPage->TRG_SetMasterPage(static_cast<SdrPage&>(*pNewMasterPage));
+            pMasterPage = pNewMasterPage;
+        }
     }
 
     AdaptPageSize(pMasterPage,
@@ -506,17 +511,42 @@ void SdDrawDocument::ResizeCurrentPage(
     //         GetMasterSdPage(i, PageKind::Notes)->CreateTitleAndLayout();
     //     }
 
-    AdaptPageSize(pPage,
-                  rNewSize,
-                  pUndoGroup,
-                  nLeft,
-                  nRight,
-                  nUpper,
-                  nLower,
-                  bScaleAll,
-                  eOrientation,
-                  nPaperBin,
-                  bBackgroundFullSize);
+    if (!bIsMasterPage)
+    {
+        AdaptPageSize(pPage,
+                      rNewSize,
+                      pUndoGroup,
+                      nLeft,
+                      nRight,
+                      nUpper,
+                      nLower,
+                      bScaleAll,
+                      eOrientation,
+                      nPaperBin,
+                      bBackgroundFullSize);
+    }
+    else
+    {
+        for (sal_uInt16 i = 0; i < nPageCnt; i++)
+        {
+            SdPage* pDrawPage = GetSdPage(i, ePageKind);
+            if (pDrawPage->TRG_HasMasterPage() &&
+                static_cast<SdPage*>(&pDrawPage->TRG_GetMasterPage()) == pPage)
+            {
+                AdaptPageSize(pDrawPage,
+                              rNewSize,
+                              pUndoGroup,
+                              nLeft,
+                              nRight,
+                              nUpper,
+                              nLower,
+                              bScaleAll,
+                              eOrientation,
+                              nPaperBin,
+                              bBackgroundFullSize);
+            }
+        }
+    }
 
     // if ( ePageKind == PageKind::Standard )
     // {

Reply via email to