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

New commits:
commit 427de88f7692fc80b99f7a6d001272689a63550f
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: Thu Jul 10 10:21:00 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>

diff --git a/sc/sdi/docsh.sdi b/sc/sdi/docsh.sdi
index 380ddb08e620..23d921ffe454 100644
--- a/sc/sdi/docsh.sdi
+++ b/sc/sdi/docsh.sdi
@@ -81,6 +81,8 @@ interface TableDocument
     SID_SPELLCHECK_APPLY_SUGGESTION     [ ExecMethod = Execute; StateMethod = 
GetState; ]
 
     SID_REFRESH_VIEW        [ 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 a00bf023c74c..84d635c43b2c 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -44,6 +44,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>
@@ -588,11 +590,72 @@ void ScDocShell::Execute( SfxRequest& rReq )
             }
             break;
 
-        case SID_AUTO_STYLE:
-            OSL_FAIL("use ScAutoStyleHint instead of SID_AUTO_STYLE");
+            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;
 
-        case SID_GET_COLORLIST:
+            case SID_GET_COLORLIST:
             {
                 const SvxColorListItem* pColItem = GetItem(SID_COLOR_TABLE);
                 const XColorListRef& pList = pColItem->GetColorList();
@@ -2272,11 +2335,34 @@ void ScDocShell::GetState( SfxItemSet &rSet )
                 }
                 break;
 
-            case SID_ATTR_CHAR_FONTLIST:
-                rSet.Put( SvxFontListItem( m_pImpl->pFontList.get(), nWhich ) 
);
+                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_ATTR_CHAR_FONTLIST:
+                    rSet.Put(SvxFontListItem(m_pImpl->pFontList.get(), 
nWhich));
+                    break;
 
-            case SID_NOTEBOOKBAR:
+                case SID_NOTEBOOKBAR:
                 {
                     if (SfxBindings* pBindings = GetViewBindings())
                     {
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index edc54923f4d0..fd3c867693c7 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