sc/sdi/docsh.sdi                 |    2 
 sc/source/ui/app/typemap.cxx     |    1 
 sc/source/ui/docshell/docsh4.cxx |   86 ++++++++++++++++++++++++++++++++++++++-
 svx/sdi/svx.sdi                  |    2 
 4 files changed, 89 insertions(+), 2 deletions(-)

New commits:
commit 5114b8edea8289be2315a01e0ced821520eccc8d
Author:     Darshan-upadhyay1110 <darshan.upadh...@collabora.com>
AuthorDate: Wed Jul 9 21:38:05 2025 +0530
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Fri Aug 8 08:21:27 2025 +0200

    feat(sc): Add UNO command for page orientation in Calc
    
    Implements UNO command support for setting Calc page orientation 
(Portrait/Landscape)
    via '.uno:Orientation' with a direct boolean parameter.
    
    - Reuses existing SID_ATTR_PAGE_ORIENTATION.
    - Uses SfxBoolItem parameter for orientation.
    - Provides API for programmatic orientation control
    
    Change-Id: I55bf9a16a0c97aa6d0d242cdfc7771b210eab47b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187590
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    (cherry picked from commit 427de88f7692fc80b99f7a6d001272689a63550f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188753
    Tested-by: Jenkins

diff --git a/sc/sdi/docsh.sdi b/sc/sdi/docsh.sdi
index 2d9a50ccb8ae..38799c3761da 100644
--- a/sc/sdi/docsh.sdi
+++ b/sc/sdi/docsh.sdi
@@ -83,6 +83,8 @@ interface TableDocument
     SID_REFRESH_VIEW        [ ExecMethod = Execute; StateMethod = GetState; ]
     SID_PROTECTPOS          [ ExecMethod = Execute; StateMethod = GetState; ]
     SID_PROTECTSIZE         [ ExecMethod = Execute; StateMethod = GetState; ];
+
+    SID_ATTR_PAGE_ORIENTATION [ ExecMethod = Execute; StateMethod = GetState; ]
 }
 
 
diff --git a/sc/source/ui/app/typemap.cxx b/sc/source/ui/app/typemap.cxx
index 0719a4ed6686..067d9bf40b99 100644
--- a/sc/source/ui/app/typemap.cxx
+++ b/sc/source/ui/app/typemap.cxx
@@ -88,6 +88,7 @@
 #include <attrib.hxx>
 #include <svx/sdprcitm.hxx>
 #include <svx/sdmetitm.hxx>
+#include <svx/pageitem.hxx>
 
 #define avmedia_MediaItem ::avmedia::MediaItem
 
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 8fe15acc0299..c70373acc421 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -45,6 +45,8 @@
 #include <svx/dataaccessdescriptor.hxx>
 #include <svx/drawitem.hxx>
 #include <svx/fmshell.hxx>
+#include <svx/pageitem.hxx>
+#include <editeng/sizeitem.hxx>
 #include <sfx2/passwd.hxx>
 #include <sfx2/filedlghelper.hxx>
 #include <sfx2/dispatch.hxx>
@@ -584,6 +586,67 @@ void ScDocShell::Execute( SfxRequest& rReq )
             }
             break;
 
+            case SID_ATTR_PAGE_ORIENTATION: // .uno:Orientation
+            {
+                const SfxBoolItem* pBool = 
rReq.GetArg<SfxBoolItem>(SID_ATTR_PAGE_ORIENTATION);
+
+                if (!pBool) // nothing supplied  -> do nothing
+                {
+                    rReq.Done();
+                    break;
+                }
+                ScViewData* pViewData = GetViewData();
+                if (!pViewData)
+                    break;
+
+                ScDocument& rDoc = GetDocument();
+                const SCTAB nTab = pViewData->GetTabNo();
+
+                // obtain the page-style’s ItemSet
+                OUString aStyleName = rDoc.GetPageStyle(nTab);
+                ScStyleSheetPool* pPagePool = rDoc.GetStyleSheetPool();
+                if (!pPagePool)
+                    break;
+                SfxStyleSheetBase* pStyle = pPagePool->Find(aStyleName, 
SfxStyleFamily::Page);
+                if (!pStyle)
+                    break;
+
+                SfxItemSet& rSet = pStyle->GetItemSet();
+
+                const SvxPageItem& rOldPageItem = rSet.Get(ATTR_PAGE);
+                const SvxSizeItem& rOldSizeItem = rSet.Get(ATTR_PAGE_SIZE);
+
+                bool bDesiredLandscape = pBool->GetValue();
+                bool bCurrentLandscape = rOldPageItem.IsLandscape();
+
+                if (bDesiredLandscape == bCurrentLandscape) // already correct
+                {
+                    rReq.Done();
+                    break;
+                }
+                //  apply the change: flip orientation and swap paper size
+                SvxPageItem aNewPageItem(ATTR_PAGE);
+                aNewPageItem.SetLandscape(bDesiredLandscape);
+
+                Size aOld = rOldSizeItem.GetSize();
+                Size aNew(aOld.Height(), aOld.Width()); // swap W/H
+                SvxSizeItem aNewSizeItem(ATTR_PAGE_SIZE, aNew);
+
+                rSet.Put(aNewPageItem);
+                rSet.Put(aNewSizeItem);
+
+                SetDocumentModified();
+                PostPaintGridAll(); // repaint sheet
+
+                if (pBindings) {
+
+                    pBindings->Invalidate(SID_ATTR_PAGE_ORIENTATION);
+                    pBindings->Invalidate(SID_ATTR_PAGE_SIZE);
+                }
+
+                rReq.Done();
+            }
+            break;
         case SID_AUTO_STYLE:
             OSL_FAIL("use ScAutoStyleHint instead of SID_AUTO_STYLE");
             break;
@@ -2287,7 +2350,28 @@ void ScDocShell::GetState( SfxItemSet &rSet )
                     }
                 }
                 break;
-
+            case SID_ATTR_PAGE_ORIENTATION:
+            {
+                ScViewData* pViewData = GetViewData();
+                if (pViewData)
+                {
+                    ScDocument& rDoc = GetDocument();
+                    const SCTAB nTab = pViewData->GetTabNo();
+                    OUString aStyleName = rDoc.GetPageStyle(nTab);
+                    ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
+                    if (pStylePool)
+                    {
+                        SfxStyleSheetBase* pStyleSheet
+                            = pStylePool->Find(aStyleName, 
SfxStyleFamily::Page);
+                        if (pStyleSheet)
+                        {
+                            const SfxItemSet& rStyleSet = 
pStyleSheet->GetItemSet();
+                            rSet.Put(rStyleSet.Get(ATTR_PAGE));
+                        }
+                    }
+                }
+            }
+            break;
             case SID_OPEN_HYPERLINK:
                 {
                     ScViewData* pViewData = GetViewData();
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index b36d57c17c83..b62bf0c38f04 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -6458,7 +6458,7 @@ SvxPageItem AttributePage SID_ATTR_PAGE
 
 
 SvxPageItem Orientation SID_ATTR_PAGE_ORIENTATION
-
+(SfxBoolItem isLandscape SID_ATTR_PAGE_ORIENTATION)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,

Reply via email to