cui/source/inc/page.hxx           |    1 
 cui/source/tabpages/page.cxx      |   20 ++-
 cui/uiconfig/ui/pageformatpage.ui |   28 ++--
 include/svx/svxids.hrc            |    4 
 sd/inc/drawdoc.hxx                |   37 +++++
 sd/source/core/drawdoc.cxx        |  251 +++++++++++++++++++++++++-------------
 sd/source/ui/func/fupage.cxx      |   14 +-
 sd/source/ui/view/drviews1.cxx    |   37 +++++
 sd/source/ui/view/viewshe2.cxx    |   48 +++++--
 sd/source/ui/view/viewshel.cxx    |   15 ++
 10 files changed, 343 insertions(+), 112 deletions(-)

New commits:
commit 15772d8e1515b23d9ace7095c7612c2e991c2350
Author:     Mohit Marathe <[email protected]>
AuthorDate: Tue Sep 16 19:52:09 2025 +0530
Commit:     Mohit Marathe <[email protected]>
CommitDate: Wed Jan 7 05:14:55 2026 +0100

    tdf#49787 cool#13066 support multiple slide size in Impress
    
    by supporting multiple master pages having different size.
    
    This patch:
    - adds an option to resize only current page instead of all pages
    - creates a new master page in case only one page is resized
    - updates the scrollbar when switched to a page with different size
    
    Signed-off-by: Mohit Marathe <[email protected]>
    Change-Id: I053a330c897767d8a148e17aa62b3461a414f218
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191524
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit 814c889b9dbb80afe9f73141c8ea2a1bc857747f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191037
    Tested-by: Jenkins

diff --git a/cui/source/inc/page.hxx b/cui/source/inc/page.hxx
index fe4b2cfc8d97..827625e3f54a 100644
--- a/cui/source/inc/page.hxx
+++ b/cui/source/inc/page.hxx
@@ -97,6 +97,7 @@ private:
     std::unique_ptr<weld::RadioButton> m_xLandscapeBtn;
     std::unique_ptr<weld::Label> m_xTextFlowLbl;
     std::unique_ptr<svx::FrameDirectionListBox>  m_xTextFlowBox;
+    std::unique_ptr<weld::CheckButton> m_xResizeAllPages;
     std::unique_ptr<weld::ComboBox> m_xPaperTrayBox;
     // Margins
     std::unique_ptr<weld::Label> m_xLeftMarginLbl;
diff --git a/cui/source/tabpages/page.cxx b/cui/source/tabpages/page.cxx
index 6d745eeb5809..4403bac2042f 100644
--- a/cui/source/tabpages/page.cxx
+++ b/cui/source/tabpages/page.cxx
@@ -56,6 +56,8 @@
 #include <sal/log.hxx>
 #include <svl/grabbagitem.hxx>
 #include <officecfg/Office/Common.hxx>
+#include <comphelper/servicehelper.hxx>
+#include <svx/unomodel.hxx>
 
 // static ----------------------------------------------------------------
 
@@ -66,7 +68,8 @@ const WhichRangesContainer SvxPageDescPage::pRanges(
     svl::Items<
     SID_ATTR_BORDER_OUTER, SID_ATTR_BORDER_SHADOW,
     SID_ATTR_LRSPACE, SID_ATTR_PAGE_SHARED,
-    SID_SWREGISTER_COLLECTION, SID_SWREGISTER_MODE>);
+    SID_SWREGISTER_COLLECTION, SID_SWREGISTER_MODE,
+    SID_ATTR_RESIZE_ALL_PAGES, SID_ATTR_RESIZE_ALL_PAGES>);
 // ------- Mapping page layout ------------------------------------------
 
 const SvxPageUsage aArr[] =
@@ -153,6 +156,7 @@ SvxPageDescPage::SvxPageDescPage(weld::Container* pPage, 
weld::DialogController*
     , 
m_xLandscapeBtn(m_xBuilder->weld_radio_button(u"radiobuttonLandscape"_ustr))
     , m_xTextFlowLbl(m_xBuilder->weld_label(u"labelTextFlow"_ustr))
     , m_xTextFlowBox(new 
svx::FrameDirectionListBox(m_xBuilder->weld_combo_box(u"comboTextFlowBox"_ustr)))
+    , 
m_xResizeAllPages(m_xBuilder->weld_check_button(u"checkResizeAllPages"_ustr))
     , m_xPaperTrayBox(m_xBuilder->weld_combo_box(u"comboPaperTray"_ustr))
     , m_xLeftMarginLbl(m_xBuilder->weld_label(u"labelLeftMargin"_ustr))
     , 
m_xLeftMarginEdit(m_xBuilder->weld_metric_spin_button(u"spinMargLeft"_ustr, 
FieldUnit::CM))
@@ -396,6 +400,12 @@ void SvxPageDescPage::Reset( const SfxItemSet* rSet )
         }
     }
 
+    if (rSet->HasItem(SID_ATTR_RESIZE_ALL_PAGES))
+    {
+        const SfxBoolItem& rItem = rSet->Get(SID_ATTR_RESIZE_ALL_PAGES);
+        m_xResizeAllPages->set_active(rItem.GetValue());
+    }
+
     // general page data
     SvxNumType eNumType = SVX_NUM_ARABIC;
     bLandscape = ( mpDefPrinter->GetOrientation() == Orientation::Landscape );
@@ -568,6 +578,7 @@ void SvxPageDescPage::Reset( const SfxItemSet* rSet )
     m_xPaperSizeBox->save_value();
     m_xPaperWidthEdit->save_value();
     m_xPaperHeightEdit->save_value();
+    m_xResizeAllPages->save_state();
     m_xPortraitBtn->save_state();
     m_xLandscapeBtn->save_state();
     m_xPaperTrayBox->save_value();
@@ -723,6 +734,13 @@ bool SvxPageDescPage::FillItemSet( SfxItemSet* rSet )
         }
     }
 
+    if (m_xResizeAllPages->get_state_changed_from_saved())
+    {
+        SfxBoolItem aResize (GetWhich(SID_ATTR_RESIZE_ALL_PAGES), 
m_xResizeAllPages->get_active());
+        rSet->Put(aResize);
+        bModified = true;
+    }
+
     // paper tray
     TypedWhichId<SvxPaperBinItem> nPaperWhich = GetWhich( 
SID_ATTR_PAGE_PAPERBIN );
     sal_Int32 nPos = m_xPaperTrayBox->get_active();
diff --git a/cui/uiconfig/ui/pageformatpage.ui 
b/cui/uiconfig/ui/pageformatpage.ui
index 3bfec6c4c609..586079e669e9 100644
--- a/cui/uiconfig/ui/pageformatpage.ui
+++ b/cui/uiconfig/ui/pageformatpage.ui
@@ -18,7 +18,7 @@
         <property name="label-xalign">0</property>
         <property name="shadow-type">none</property>
         <child>
-          <!-- n-columns=2 n-rows=1 -->
+          <!-- n-columns=3 n-rows=1 -->
           <object class="GtkGrid" id="grid2">
             <property name="visible">True</property>
             <property name="can-focus">False</property>
@@ -252,6 +252,21 @@
                   </packing>
                 </child>
               </object>
+              <packing>
+                <property name="left-attach">2</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="checkResizeAllPages">
+                <property name="label" translatable="yes" 
context="pageformatpage|checkResizeAllPages">Resize all pages</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">False</property>
+                <property name="use-underline">True</property>
+                <property name="active">True</property>
+                <property name="draw-indicator">True</property>
+              </object>
               <packing>
                 <property name="left-attach">1</property>
                 <property name="top-attach">0</property>
@@ -591,7 +606,6 @@
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
                     <style>
-                      <!-- tdf#161662 try and shrink this height to min and 
then use the size-group to bring it back up to that height -->
                       <class name="novertpad"/>
                     </style>
                   </object>
@@ -799,13 +813,6 @@ Do you still want to apply these settings?</property>
       <widget name="grid6"/>
     </widgets>
   </object>
-  <object class="GtkSizeGroup" id="sizegroup2">
-    <property name="ignore-hidden">True</property>
-    <widgets>
-      <widget name="grid4"/>
-      <widget name="grid7"/>
-    </widgets>
-  </object>
   <object class="GtkSizeGroup" id="sizegroupLabel1">
     <widgets>
       <widget name="labelFormat"/>
@@ -837,4 +844,7 @@ Do you still want to apply these settings?</property>
       <widget name="comboRegisterStyle"/>
     </widgets>
   </object>
+  <object class="GtkSizeGroup" id="sizegroup2">
+    <property name="ignore-hidden">True</property>
+  </object>
 </interface>
diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc
index a93ad0c3bed9..9d318e8da829 100644
--- a/include/svx/svxids.hrc
+++ b/include/svx/svxids.hrc
@@ -1121,8 +1121,10 @@ class XFillGradientItem;
 #define SID_ATTR_TEXT_UPPERDIST                         ( SID_SVX_START + 1255 
)
 #define SID_ATTR_TEXT_LOWERDIST                         ( SID_SVX_START + 1256 
)
 
+#define SID_ATTR_RESIZE_ALL_PAGES                       
TypedWhichId<SfxBoolItem>( SID_SVX_START + 1257 )
+
 // IMPORTANT NOTE: adjust SID_SVX_FIRSTFREE, when adding new slot id
-#define SID_SVX_FIRSTFREE                               ( SID_SVX_START + 1256 
+ 1 )
+#define SID_SVX_FIRSTFREE                               ( SID_SVX_START + 1257 
+ 1 )
 
 // Overflow check for slot IDs
 #if SID_SVX_FIRSTFREE > SID_SVX_END
diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx
index cb44248ba7cd..3c16e264da04 100644
--- a/sd/inc/drawdoc.hxx
+++ b/sd/inc/drawdoc.hxx
@@ -409,6 +409,8 @@ private:
     bool mbEmbedFontScriptAsian : 1;
     bool mbEmbedFontScriptComplex : 1;
 
+    bool mbResizeAllPages = true;
+
     sal_Int32 mnImagePreferredDPI;
 
     SAL_DLLPRIVATE virtual css::uno::Reference< css::frame::XModel > 
createUnoModel() override;
@@ -520,10 +522,41 @@ public:
         tools::Long nUpper = 0,
         tools::Long nLower = 0) override;
 
-    // Adapt PageSize for all Pages of PageKind ePageKind. Also
-    // set Borders to left/right/upper/lower, ScaleAll, Orientation,
+    bool ShouldResizeAllPages() const { return mbResizeAllPages; }
+    void SetResizeAllPages(bool bValue) { mbResizeAllPages = bValue; }
+
+    // Allows to have pages with different sizes in a document
+    void ResizeCurrentPage(
+        SdPage* pPage,
+        const Size& rNewSize,
+        PageKind ePageKind,
+        SdUndoGroup* pUndoGroup = nullptr,
+        tools::Long nLeft = 0,
+        tools::Long nRight = 0,
+        tools::Long nUpper = 0,
+        tools::Long nLower = 0,
+        bool bScaleAll = false,
+        Orientation eOrientation = Orientation::Landscape,
+        sal_uInt16 nPaperBin = 0,
+        bool bBackgroundFullSize = false);
+
+    // Set Borders to left/right/upper/lower, ScaleAll, Orientation,
     // PaperBin and BackgroundFullSize. Create Undo-Actions when
     // a SdUndoGroup is given (then used from the View probably)
+    void AdaptPageSize(
+        SdPage* pPage,
+        const Size& rNewSize,
+        SdUndoGroup* pUndoGroup = nullptr,
+        tools::Long nLeft = 0,
+        tools::Long nRight = 0,
+        tools::Long nUpper = 0,
+        tools::Long nLower = 0,
+        bool bScaleAll = false,
+        Orientation eOrientation = Orientation::Landscape,
+        sal_uInt16 nPaperBin = 0,
+        bool bBackgroundFullSize = false);
+
+    // Adapt PageSize for all Pages of PageKind ePageKind.
     void AdaptPageSizeForAllPages(
         const Size& rNewSize,
         PageKind ePageKind,
diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index 7cbf50613202..a3a79d64591f 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -436,7 +436,8 @@ void SdDrawDocument::adaptSizeAndBorderForAllPages(
     }
 }
 
-void SdDrawDocument::AdaptPageSizeForAllPages(
+void SdDrawDocument::ResizeCurrentPage(
+    SdPage* pPage,
     const Size& rNewSize,
     PageKind ePageKind,
     SdUndoGroup* pUndoGroup,
@@ -449,7 +450,6 @@ void SdDrawDocument::AdaptPageSizeForAllPages(
     sal_uInt16 nPaperBin,
     bool bBackgroundFullSize)
 {
-    sal_uInt16 i;
     const sal_uInt16 nMasterPageCnt(GetMasterSdPageCount(ePageKind));
     const sal_uInt16 nPageCnt(GetSdPageCount(ePageKind));
 
@@ -458,115 +458,198 @@ void SdDrawDocument::AdaptPageSizeForAllPages(
         return;
     }
 
-    for (i = 0; i < nMasterPageCnt; i++)
-    {
-        // first, handle all master pages
-        SdPage* pPage(GetMasterSdPage(i, ePageKind));
+    // TODO: handle undo action for new master page creation
 
-        if(pUndoGroup)
+    SdPage* pMasterPage = static_cast<SdPage*>(&pPage->TRG_GetMasterPage());
+
+    // Count how many pages uses pMasterPage
+    sal_uInt16 nCount = 0;
+    for (sal_uInt16 i = 0; i < nPageCnt && nCount <= 1; i++)
+    {
+        SdPage* pDrawPage = GetSdPage(i, ePageKind);
+        if (pDrawPage->TRG_HasMasterPage() &&
+            static_cast<SdPage*>(&pDrawPage->TRG_GetMasterPage()) == 
pMasterPage)
         {
-            SdUndoAction* pUndo(
-                new SdPageFormatUndoAction(
-                    *this,
-                    pPage,
-                    pPage->GetSize(),
-                    pPage->GetLeftBorder(), pPage->GetRightBorder(),
-                    pPage->GetUpperBorder(), pPage->GetLowerBorder(),
-                    pPage->GetOrientation(),
-                    pPage->GetPaperBin(),
-                    pPage->IsBackgroundFullSize(),
-                    rNewSize,
-                    nLeft, nRight,
-                    nUpper, nLower,
-                    bScaleAll,
-                    eOrientation,
-                    nPaperBin,
-                    bBackgroundFullSize));
-            pUndoGroup->AddAction(pUndo);
+            nCount++;
         }
+    }
 
-        if (rNewSize.Width() > 0 || nLeft  >= 0 || nRight >= 0 || nUpper >= 0 
|| nLower >= 0)
-        {
-            ::tools::Rectangle aNewBorderRect(nLeft, nUpper, nRight, nLower);
-            pPage->ScaleObjects(rNewSize, aNewBorderRect, bScaleAll);
+    // 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 (rNewSize.Width() > 0)
-            {
-                pPage->SetSize(rNewSize);
-            }
-        }
+    AdaptPageSize(pMasterPage,
+                  rNewSize,
+                  pUndoGroup,
+                  nLeft,
+                  nRight,
+                  nUpper,
+                  nLower,
+                  bScaleAll,
+                  eOrientation,
+                  nPaperBin,
+                  bBackgroundFullSize);
+
+    //     if ( ePageKind == PageKind::Standard )
+    //     {
+    //         GetMasterSdPage(i, PageKind::Notes)->CreateTitleAndLayout();
+    //     }
+
+    AdaptPageSize(pPage,
+                  rNewSize,
+                  pUndoGroup,
+                  nLeft,
+                  nRight,
+                  nUpper,
+                  nLower,
+                  bScaleAll,
+                  eOrientation,
+                  nPaperBin,
+                  bBackgroundFullSize);
+
+    // if ( ePageKind == PageKind::Standard )
+    // {
+    //     SdPage* pNotesPage = GetSdPage(i, PageKind::Notes);
+    //     pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() );
+    // }
+}
 
-        if( nLeft  >= 0 || nRight >= 0 || nUpper >= 0 || nLower >= 0 )
-        {
-            pPage->SetBorder(nLeft, nUpper, nRight, nLower);
-        }
+void SdDrawDocument::AdaptPageSize(
+        SdPage* pPage,
+        const Size& rNewSize,
+        SdUndoGroup* pUndoGroup,
+        ::tools::Long nLeft,
+        ::tools::Long nRight,
+        ::tools::Long nUpper,
+        ::tools::Long nLower,
+        bool bScaleAll,
+        Orientation eOrientation,
+        sal_uInt16 nPaperBin,
+        bool bBackgroundFullSize)
+{
+    if(pUndoGroup)
+    {
+        SdUndoAction* pUndo(
+            new SdPageFormatUndoAction(
+                *this,
+                pPage,
+                pPage->GetSize(),
+                pPage->GetLeftBorder(), pPage->GetRightBorder(),
+                pPage->GetUpperBorder(), pPage->GetLowerBorder(),
+                pPage->GetOrientation(),
+                pPage->GetPaperBin(),
+                pPage->IsBackgroundFullSize(),
+                rNewSize,
+                nLeft, nRight,
+                nUpper, nLower,
+                bScaleAll,
+                eOrientation,
+                nPaperBin,
+                bBackgroundFullSize));
+        pUndoGroup->AddAction(pUndo);
+    }
 
-        pPage->SetOrientation(eOrientation);
-        pPage->SetPaperBin( nPaperBin );
-        pPage->SetBackgroundFullSize( bBackgroundFullSize );
+    if (rNewSize.Width() > 0 || nLeft  >= 0 || nRight >= 0 || nUpper >= 0 || 
nLower >= 0)
+    {
+        ::tools::Rectangle aNewBorderRect(nLeft, nUpper, nRight, nLower);
+        pPage->ScaleObjects(rNewSize, aNewBorderRect, bScaleAll);
 
-        if ( ePageKind == PageKind::Standard )
+        if (rNewSize.Width() > 0)
         {
-            GetMasterSdPage(i, PageKind::Notes)->CreateTitleAndLayout();
+            pPage->SetSize(rNewSize);
         }
+    }
 
-        pPage->CreateTitleAndLayout();
+    if( nLeft  >= 0 || nRight >= 0 || nUpper >= 0 || nLower >= 0 )
+    {
+        pPage->SetBorder(nLeft, nUpper, nRight, nLower);
     }
 
-    for (i = 0; i < nPageCnt; i++)
+    pPage->SetOrientation(eOrientation);
+    pPage->SetPaperBin( nPaperBin );
+    pPage->SetBackgroundFullSize( bBackgroundFullSize );
+
+    if (pPage->IsMasterPage())
     {
-        // then, handle all pages
-        SdPage* pPage(GetSdPage(i, ePageKind));
+        pPage->CreateTitleAndLayout();
+    }
+    else
+    {
+        pPage->SetAutoLayout( pPage->GetAutoLayout() );
+    }
+}
 
-        if(pUndoGroup)
-        {
-            SdUndoAction* pUndo(
-                new SdPageFormatUndoAction(
-                    *this,
-                    pPage,
-                    pPage->GetSize(),
-                    pPage->GetLeftBorder(), pPage->GetRightBorder(),
-                    pPage->GetUpperBorder(), pPage->GetLowerBorder(),
-                    pPage->GetOrientation(),
-                    pPage->GetPaperBin(),
-                    pPage->IsBackgroundFullSize(),
-                    rNewSize,
-                    nLeft, nRight,
-                    nUpper, nLower,
-                    bScaleAll,
-                    eOrientation,
-                    nPaperBin,
-                    bBackgroundFullSize));
-            pUndoGroup->AddAction(pUndo);
-        }
+void SdDrawDocument::AdaptPageSizeForAllPages(
+    const Size& rNewSize,
+    PageKind ePageKind,
+    SdUndoGroup* pUndoGroup,
+    ::tools::Long nLeft,
+    ::tools::Long nRight,
+    ::tools::Long nUpper,
+    ::tools::Long nLower,
+    bool bScaleAll,
+    Orientation eOrientation,
+    sal_uInt16 nPaperBin,
+    bool bBackgroundFullSize)
+{
+    sal_uInt16 i;
+    const sal_uInt16 nMasterPageCnt(GetMasterSdPageCount(ePageKind));
+    const sal_uInt16 nPageCnt(GetSdPageCount(ePageKind));
 
-        if (rNewSize.Width() > 0 || nLeft  >= 0 || nRight >= 0 || nUpper >= 0 
|| nLower >= 0)
-        {
-            ::tools::Rectangle aNewBorderRect(nLeft, nUpper, nRight, nLower);
-            pPage->ScaleObjects(rNewSize, aNewBorderRect, bScaleAll);
+    if(0 == nMasterPageCnt && 0 == nPageCnt)
+    {
+        return;
+    }
 
-            if (rNewSize.Width() > 0)
-            {
-                pPage->SetSize(rNewSize);
-            }
-        }
+    for (i = 0; i < nMasterPageCnt; i++)
+    {
+        // first, handle all master pages
+        SdPage* pMasterPage(GetMasterSdPage(i, ePageKind));
+
+        AdaptPageSize(pMasterPage,
+                      rNewSize,
+                      pUndoGroup,
+                      nLeft,
+                      nRight,
+                      nUpper,
+                      nLower,
+                      bScaleAll,
+                      eOrientation,
+                      nPaperBin,
+                      bBackgroundFullSize);
 
-        if( nLeft  >= 0 || nRight >= 0 || nUpper >= 0 || nLower >= 0 )
+        if ( ePageKind == PageKind::Standard )
         {
-            pPage->SetBorder(nLeft, nUpper, nRight, nLower);
+            GetMasterSdPage(i, PageKind::Notes)->CreateTitleAndLayout();
         }
+    }
 
-        pPage->SetOrientation(eOrientation);
-        pPage->SetPaperBin( nPaperBin );
-        pPage->SetBackgroundFullSize( bBackgroundFullSize );
+    for (i = 0; i < nPageCnt; i++)
+    {
+        // then, handle all pages
+        SdPage* pPage(GetSdPage(i, ePageKind));
+
+        AdaptPageSize(pPage,
+                      rNewSize,
+                      pUndoGroup,
+                      nLeft,
+                      nRight,
+                      nUpper,
+                      nLower,
+                      bScaleAll,
+                      eOrientation,
+                      nPaperBin,
+                      bBackgroundFullSize);
 
         if ( ePageKind == PageKind::Standard )
         {
             SdPage* pNotesPage = GetSdPage(i, PageKind::Notes);
             pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() );
         }
-
-        pPage->SetAutoLayout( pPage->GetAutoLayout() );
     }
 }
 
diff --git a/sd/source/ui/func/fupage.cxx b/sd/source/ui/func/fupage.cxx
index 5ecfc3dc07d1..0424ea8c5d6e 100644
--- a/sd/source/ui/func/fupage.cxx
+++ b/sd/source/ui/func/fupage.cxx
@@ -204,7 +204,8 @@ void FuPage::ExecuteAsyncDialog(weld::Window* pParent, 
const SfxRequest& rReq)
         XATTR_FILL_FIRST, XATTR_FILL_LAST, EE_PARA_WRITINGDIR, 
EE_PARA_WRITINGDIR,
         SID_ATTR_BORDER_OUTER, SID_ATTR_BORDER_OUTER, SID_ATTR_BORDER_SHADOW,
         SID_ATTR_BORDER_SHADOW, SID_ATTR_PAGE, SID_ATTR_PAGE_SHARED, 
SID_ATTR_CHAR_GRABBAG,
-        SID_ATTR_CHAR_GRABBAG, SID_ATTR_PAGE_COLOR, 
SID_ATTR_PAGE_FILLSTYLE>(mrDoc.GetPool()));
+        SID_ATTR_CHAR_GRABBAG, SID_ATTR_PAGE_COLOR, SID_ATTR_PAGE_FILLSTYLE,
+        SID_ATTR_RESIZE_ALL_PAGES, 
SID_ATTR_RESIZE_ALL_PAGES>(mrDoc.GetPool()));
     // Keep it sorted
     
aNewAttr->MergeRange(mrDoc.GetPool().GetWhichIDFromSlotID(SID_ATTR_LRSPACE),
                          
mrDoc.GetPool().GetWhichIDFromSlotID(SID_ATTR_ULSPACE));
@@ -229,6 +230,10 @@ void FuPage::ExecuteAsyncDialog(weld::Window* pParent, 
const SfxRequest& rReq)
     aPageItem.SetNumType( mrDoc.GetPageNumType() );
     aNewAttr->Put( aPageItem );
 
+    bool bResizeAllPages = mrDoc.ShouldResizeAllPages();
+    SfxBoolItem aResize( SID_ATTR_RESIZE_ALL_PAGES, bResizeAllPages );
+    aNewAttr->Put( aResize );
+
     // size
     maSize = mpPage->GetSize();
     SvxSizeItem aSizeItem( SID_ATTR_PAGE_SIZE, maSize );
@@ -487,7 +492,6 @@ void FuPage::ApplyItemSet( const SfxItemSet* pArgs )
     if (!pArgs || !mpDrawViewShell) {
         return;
     }
-
     // Set new page-attributes
     PageKind ePageKind = mpDrawViewShell->GetPageKind();
     const SfxPoolItem*  pPoolItem;
@@ -513,6 +517,12 @@ void FuPage::ApplyItemSet( const SfxItemSet* pArgs )
         mpDrawViewShell->ResetActualPage();
     }
 
+    if ( pArgs->GetItemState(SID_ATTR_RESIZE_ALL_PAGES, true, &pPoolItem) == 
SfxItemState::SET)
+    {
+        SdDrawDocument* pDrawDoc = mpDrawViewShell->GetDoc();
+        pDrawDoc->SetResizeAllPages(static_cast<const 
SfxBoolItem*>(pPoolItem)->GetValue());
+    }
+
     if( pArgs->GetItemState(SID_ATTR_PAGE_SIZE, true, &pPoolItem) == 
SfxItemState::SET )
     {
         aNewSize = static_cast<const SvxSizeItem*>(pPoolItem)->GetSize();
diff --git a/sd/source/ui/view/drviews1.cxx b/sd/source/ui/view/drviews1.cxx
index e6eef33c79c3..4a23b76cad18 100644
--- a/sd/source/ui/view/drviews1.cxx
+++ b/sd/source/ui/view/drviews1.cxx
@@ -34,6 +34,7 @@
 #include <sfx2/dispatch.hxx>
 #include <sfx2/module.hxx>
 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
+#include <sfx2/lokhelper.hxx>
 #include <svx/svdopage.hxx>
 #include <svx/fmshell.hxx>
 #include <tools/debug.hxx>
@@ -74,6 +75,7 @@
 #include <titledockwin.hxx>
 #include <strings.hrc>
 #include <sdresid.hxx>
+#include <unomodel.hxx>
 
 using namespace com::sun::star;
 
@@ -1032,6 +1034,41 @@ bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage, 
bool bAllowChangeFocus,
             
/**********************************************************************
             * PAGEMODE
             
**********************************************************************/
+
+            SdrPageView* pPV = mpDrawView->GetSdrPageView();
+            SdPage* pCurrentPage = pPV ? dynamic_cast<SdPage*>(pPV->GetPage()) 
: nullptr;
+
+            if (pCurrentPage)
+            {
+                Size aCurrentPageSize = pCurrentPage->GetSize();
+                const ::tools::Long nCurrentWidth = aCurrentPageSize.Width();
+                const ::tools::Long nCurrentHeight = aCurrentPageSize.Height();
+
+                SdPage* pNewPage = GetDoc()->GetSdPage(nSelectedPage, 
mePageKind);
+                Size aNewPageSize = pNewPage->GetSize();
+                const ::tools::Long nNewWidth = aNewPageSize.Width();
+                const ::tools::Long nNewHeight = aNewPageSize.Height();
+
+                if ((nCurrentWidth != nNewWidth || nCurrentHeight != 
nNewHeight) && bAllowChangeFocus)
+                {
+                    Point aPageOrg(nNewWidth, nNewHeight / 2);
+                    Size aViewSize(nNewWidth * 3, nNewHeight * 2);
+
+                    GetDoc()->SetMaxObjSize(aViewSize);
+
+                    InitWindows(aPageOrg, aViewSize, Point(-1, -1), true);
+
+                    // pNewPage->SetBackgroundFullSize(true);
+
+                    UpdateScrollBars();
+
+                    if (comphelper::LibreOfficeKit::isActive())
+                    {
+                        SdXImpressDocument* pDoc = GetDoc()->getUnoModel();
+                        SfxLokHelper::notifyDocumentSizeChangedAllViews(pDoc);
+                    }
+                }
+            }
             GetDoc()->SetSelected(mpActualPage, true);
 
             SdrPageView* pPageView = mpDrawView->GetSdrPageView();
diff --git a/sd/source/ui/view/viewshe2.cxx b/sd/source/ui/view/viewshe2.cxx
index a883dfacc9b4..c7403d702f07 100644
--- a/sd/source/ui/view/viewshe2.cxx
+++ b/sd/source/ui/view/viewshe2.cxx
@@ -536,19 +536,41 @@ void ViewShell::SetPageSizeAndBorder(PageKind ePageKind, 
const Size& rNewSize,
     }
     Broadcast (ViewShellHint(ViewShellHint::HINT_PAGE_RESIZE_START));
 
-    // use Model-based method at SdDrawDocument
-    GetDoc()->AdaptPageSizeForAllPages(
-        rNewSize,
-        ePageKind,
-        pUndoGroup.get(),
-        nLeft,
-        nRight,
-        nUpper,
-        nLower,
-        bScaleAll,
-        eOrientation,
-        nPaperBin,
-        bBackgroundFullSize);
+    SdDrawDocument* pDrawDoc = GetDoc();
+
+    if (pDrawDoc->ShouldResizeAllPages())
+        // use Model-based method at SdDrawDocument
+        pDrawDoc->AdaptPageSizeForAllPages(
+            rNewSize,
+            ePageKind,
+            pUndoGroup.get(),
+            nLeft,
+            nRight,
+            nUpper,
+            nLower,
+            bScaleAll,
+            eOrientation,
+            nPaperBin,
+            bBackgroundFullSize);
+
+    else
+    {
+        SdPage* pCurrentPage = getCurrentPage();
+        pDrawDoc->ResizeCurrentPage(
+            pCurrentPage,
+            rNewSize,
+            ePageKind,
+            pUndoGroup.get(),
+            nLeft,
+            nRight,
+            nUpper,
+            nLower,
+            bScaleAll,
+            eOrientation,
+            nPaperBin,
+            bBackgroundFullSize
+        );
+    }
 
     // adjust handout page to new format of the standard page
     if(0 != nPageCnt && ((ePageKind == PageKind::Standard) || (ePageKind == 
PageKind::Handout)))
diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index 51ab68b362cd..38c6b41f08c4 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -210,6 +210,21 @@ ViewShell::ViewShell( vcl::Window* pParentWindow, 
ViewShellBase& rViewShellBase)
     // Register the sub shell factory.
     mpImpl->mpSubShellFactory = 
std::make_shared<ViewShellObjectBarFactory>(*this);
     
GetViewShellBase().GetViewShellManager()->AddSubShellFactory(this,mpImpl->mpSubShellFactory);
+
+    // Compare size of all pages to set SdDrawDocument's mbResizeAllPages 
after document load
+    // instead of setting it true unconditionally.
+    sal_uInt16 nPageCnt = GetDoc()->GetSdPageCount(PageKind::Standard);
+    if (nPageCnt > 0)
+    {
+        Size aSize1 = GetDoc()->GetSdPage(0, PageKind::Standard)->GetSize();
+
+        for (sal_uInt16 i = 1; i < nPageCnt; i++)
+        {
+            Size aSize2 = GetDoc()->GetSdPage(i, 
PageKind::Standard)->GetSize();
+            if (aSize1 != aSize2)
+                GetDoc()->SetResizeAllPages(false);
+        }
+    }
 }
 
 ViewShell::~ViewShell()

Reply via email to