desktop/source/lib/init.cxx      |    5 +++++
 include/vcl/ITiledRenderable.hxx |   10 ++++++++++
 sd/source/ui/inc/ViewShell.hxx   |    6 ++++++
 sd/source/ui/inc/unomodel.hxx    |    2 ++
 sd/source/ui/unoidl/unomodel.cxx |    9 +++++++++
 sd/source/ui/view/drviews1.cxx   |   34 +++++++++++++++++++++++++++++++---
 sd/source/ui/view/drviews2.cxx   |    6 +++++-
 sd/source/ui/view/outlnvs2.cxx   |   10 ++++++++--
 sd/source/ui/view/viewshe2.cxx   |   15 +++++++++++++++
 9 files changed, 91 insertions(+), 6 deletions(-)

New commits:
commit 263874ab90435b312d370e7aa49b4687ec65d5a3
Author:     Mohit Marathe <[email protected]>
AuthorDate: Mon Nov 3 16:39:05 2025 +0530
Commit:     Mohit Marathe <[email protected]>
CommitDate: Wed Nov 19 04:37:24 2025 +0100

    sd: remember canvas page zoom
    
    store zoom for canvas page & non-canvas page, and trigger zoom change
    when switching between them
    
    Signed-off-by: Mohit Marathe <[email protected]>
    Change-Id: I93310f09af3f2c2bbc87c4561ef5e0fc791d2ec3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193459
    Reviewed-by: Michael Stahl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 1adcb0c40f59..d1650492743b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -5894,7 +5894,12 @@ static void doc_setViewOption(LibreOfficeKitDocument* 
pThis, const char* pOption
         const int nZoom = getUString(pValue).toInt32();
 
         if (nZoom)
+        {
             pDoc->setExportZoom(nZoom);
+
+            // Remember the current page zoom in Impress
+            pDoc->setPageZoom(nZoom);
+        }
     }
 }
 
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index f93e831a38ea..9e3f0a71c257 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -293,6 +293,16 @@ public:
     {
     }
 
+    /**
+     * Remember the zoom level as a percent for canvas page and
+     * non-canvas page
+     *
+     * @param nZoom - the zoom level as a percent
+     */
+    virtual void setPageZoom(int /*nPageZoom*/)
+    {
+    }
+
     /**
      * Show/Hide a single row/column header outline for Calc documents.
      *
diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx
index 8b1292e554ad..76de1b1b9f7d 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -434,6 +434,9 @@ public:
     /// Allows starting or ending a graphic move or resize action.
     void SetGraphicMm100Position(bool bStart, const Point& rPosition);
 
+    sal_uInt16 GetPageZoom() const;
+    void RememberPageZoom(const sal_uInt16 nZoom);
+
     class Implementation;
 
 protected:
@@ -482,6 +485,9 @@ protected:
     sal_uInt16      mnPrintedHandoutPageNum; // Page number of the handout 
page that is to be printed.
     sal_uInt16      mnPrintedHandoutPageCount; // Page count of the handout 
pages that are to be printed.
 
+    sal_uInt16            mnCanvasPageZoom = 0;
+    sal_uInt16            mnNonCanvasPageZoom = 0;
+
     //af    bool        bPrintDirectSelected;       // Print only selected 
objects in direct print
     //afString      sPageRange;                 // pagerange if selected 
objects in direct print
 
diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx
index 6a2a01ce99f7..1ae9d539da45 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -276,6 +276,8 @@ public:
     SD_DLLPUBLIC virtual void resetSelection() override;
     /// @see vcl::ITiledRenderable::setClientVisibleArea().
     virtual void setClientVisibleArea(const tools::Rectangle& rRectangle) 
override;
+    /// @see vcl::ITiledRenderable::setPageZoom().
+    virtual void setPageZoom(int nPageZoom) override;
     /// @see vcl::ITiledRenderable::setClipboard().
     virtual void setClipboard(const 
css::uno::Reference<css::datatransfer::clipboard::XClipboard>& xClipboard) 
override;
     /// @see vcl::ITiledRenderable::isMimeTypeSupported().
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 3c58264f597a..bac8bb3f1f19 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -4475,6 +4475,15 @@ void SdXImpressDocument::resetSelection()
     pSdrView->UnmarkAll();
 }
 
+void SdXImpressDocument::setPageZoom(int nPageZoom)
+{
+    SolarMutexGuard aGuard;
+    DrawViewShell* pViewShell = GetViewShell();
+    if (!pViewShell)
+        return;
+    pViewShell->RememberPageZoom(nPageZoom);
+}
+
 void SdXImpressDocument::setClientVisibleArea(const ::tools::Rectangle& 
rRectangle)
 {
     SolarMutexGuard aGuard;
diff --git a/sd/source/ui/view/drviews1.cxx b/sd/source/ui/view/drviews1.cxx
index 21dec5ad5204..23bbd397494d 100644
--- a/sd/source/ui/view/drviews1.cxx
+++ b/sd/source/ui/view/drviews1.cxx
@@ -35,6 +35,7 @@
 #include <sfx2/module.hxx>
 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
 #include <sfx2/lokhelper.hxx>
+#include <sfx2/zoomitem.hxx>
 #include <svx/svdopage.hxx>
 #include <svx/fmshell.hxx>
 #include <tools/debug.hxx>
@@ -1034,17 +1035,21 @@ bool DrawViewShell::SwitchPage(sal_uInt16 
nSelectedPage, bool bAllowChangeFocus)
             SdrPageView* pPV = mpDrawView->GetSdrPageView();
             SdPage* pCurrentPage = pPV ? dynamic_cast<SdPage*>(pPV->GetPage()) 
: nullptr;
 
+            bool bChangeZoom = false;
+
             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();
+                SdPage* pSelectedPage = GetDoc()->GetSdPage(nSelectedPage, 
mePageKind);
+                Size aNewPageSize = pSelectedPage->GetSize();
                 const ::tools::Long nNewWidth = aNewPageSize.Width();
                 const ::tools::Long nNewHeight = aNewPageSize.Height();
 
+                bChangeZoom = pCurrentPage->IsCanvasPage() || 
pSelectedPage->IsCanvasPage();
+
                 if ((nCurrentWidth != nNewWidth || nCurrentHeight != 
nNewHeight) && bAllowChangeFocus)
                 {
                     Point aPageOrg(nNewWidth, nNewHeight / 2);
@@ -1054,7 +1059,7 @@ bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage, 
bool bAllowChangeFocus)
 
                     InitWindows(aPageOrg, aViewSize, Point(-1, -1), true);
 
-                    // pNewPage->SetBackgroundFullSize(true);
+                    // pSelectedPage->SetBackgroundFullSize(true);
 
                     UpdateScrollBars();
 
@@ -1095,6 +1100,29 @@ bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage, 
bool bAllowChangeFocus)
             mpDrawView->ShowSdrPage(mpActualPage);
             
GetViewShellBase().GetDrawController()->FireSwitchCurrentPage(mpActualPage);
 
+            if (comphelper::LibreOfficeKit::isActive())
+            {
+                if (bChangeZoom && bAllowChangeFocus)
+                {
+                    sal_uInt16 nZoom = GetPageZoom();
+                    if (nZoom != 0)
+                    {
+                        OString aPayload = ".uno:PageZoomChange="_ostr + 
OString::number(nZoom);
+                        if (SfxViewShell* pViewShell = GetViewShell())
+                            
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, aPayload);
+                    }
+                }
+            }
+            else
+            {
+                const sal_uInt16 nZoom = GetPageZoom();
+                if (nZoom)
+                {
+                    const SvxZoomItem aZoomItem(SvxZoomType::PERCENT, nZoom, 
SID_ATTR_ZOOM);
+                    
GetViewFrame()->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::SLOT, 
{&aZoomItem});
+                }
+            }
+
             SdrPageView* pNewPageView = mpDrawView->GetSdrPageView();
 
             if (pNewPageView)
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index d6827ad97953..b42191d522e6 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -1650,7 +1650,11 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                 switch( eZT )
                 {
                     case SvxZoomType::PERCENT:
-                        SetZoom( static_cast<::tools::Long>( pArgs->Get( 
SID_ATTR_ZOOM ).GetValue()) );
+                    {
+                        sal_uInt16 nZoom = pArgs->Get( SID_ATTR_ZOOM 
).GetValue();
+                        SetZoom( static_cast<::tools::Long>( nZoom ) );
+                        RememberPageZoom(nZoom);
+                    }
                         break;
 
                     case SvxZoomType::OPTIMAL:
diff --git a/sd/source/ui/view/outlnvs2.cxx b/sd/source/ui/view/outlnvs2.cxx
index 99935ec3ec57..7055d2c19b2a 100644
--- a/sd/source/ui/view/outlnvs2.cxx
+++ b/sd/source/ui/view/outlnvs2.cxx
@@ -79,14 +79,20 @@ void OutlineViewShell::FuTemporary(SfxRequest &rReq)
 
             if ( pArgs )
             {
-                SvxZoomType eZT = pArgs->Get( SID_ATTR_ZOOM ).GetType();
+                SvxZoomItem aZoom = pArgs->Get( SID_ATTR_ZOOM );
+                SvxZoomType eZT = aZoom.GetType();
                 switch( eZT )
                 {
                     case SvxZoomType::PERCENT:
+                    {
                         SetZoom( static_cast<::tools::Long>( pArgs->Get( 
SID_ATTR_ZOOM ).GetValue()) );
                         Invalidate( SID_ATTR_ZOOM );
                         Invalidate( SID_ATTR_ZOOMSLIDER );
-                        break;
+                        sal_uInt16 nZoom = aZoom.GetValue();
+                        RememberPageZoom(nZoom);
+                    }
+                    break;
+
                     default:
                         break;
                 }
diff --git a/sd/source/ui/view/viewshe2.cxx b/sd/source/ui/view/viewshe2.cxx
index 597670860794..127f9bc7d324 100644
--- a/sd/source/ui/view/viewshe2.cxx
+++ b/sd/source/ui/view/viewshe2.cxx
@@ -633,6 +633,21 @@ void ViewShell::SetZoomFactor(const Fraction& rZoomX, 
const Fraction&)
     SetZoom(nZoom);
 }
 
+sal_uInt16 ViewShell::GetPageZoom() const
+{
+    if (getCurrentPage()->IsCanvasPage())
+        return mnCanvasPageZoom;
+    return mnNonCanvasPageZoom;
+}
+
+void ViewShell::RememberPageZoom(const sal_uInt16 nZoom)
+{
+    if (getCurrentPage()->IsCanvasPage())
+        mnCanvasPageZoom = nZoom;
+    else
+        mnNonCanvasPageZoom = nZoom;
+}
+
 void ViewShell::SetActiveWindow (::sd::Window* pWin)
 {
     SfxViewShell* pViewShell = GetViewShell();

Reply via email to