sc/inc/sc.hrc | 1 sc/sdi/docsh.sdi | 1 sc/sdi/scalc.sdi | 19 +++++++++++ sc/source/ui/docshell/docsh4.cxx | 64 +++++++++++++++++++++++++++++++++++++++ sfx2/source/control/unoctitm.cxx | 1 5 files changed, 86 insertions(+)
New commits: commit 746a429002c68659d110a18c6eb2e1962ec89eaa Author: Darshan-upadhyay1110 <[email protected]> AuthorDate: Mon Jul 14 13:49:11 2025 +0530 Commit: Szymon Kłos <[email protected]> CommitDate: Thu Jul 24 18:53:14 2025 +0200 feat(sc): Add new UNO command for page size for Calc sheet Implements UNO command support for setting Calc page size (e.g., A4, Letter) via '.uno:CalcPageSize' with a string parameter. - Defines new SvxSizeItem command 'CalcPageSize' in scalc.sdi. - Uses SfxStringItem parameter 'PaperFormat' for the desired size id. - Provides API for programmatic page size control from remote clients. - Implements Execute and GetState methods in ScDocShell to apply and report the page size, translating between internal dimensions and string names using SvxPaperInfo. Change-Id: I60a023fd4a28b957e6332834a84845d9b57fc85e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187847 Reviewed-by: Szymon Kłos <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc index 2d8448463080..63ffdd2b6228 100644 --- a/sc/inc/sc.hrc +++ b/sc/inc/sc.hrc @@ -655,6 +655,7 @@ static_assert(SID_PREVIEW_END < SID_KEYFUNC_START, "calc slots ids trampling inf #define FID_TOGGLE_PRINT_GRID (SC_RESOURCE_START+19) // toggle print grid #define WID_SIMPLE_REF (SC_RESOURCE_START+20) #define SID_SC_ATTR_PAGE_MARGIN (SC_RESOURCE_START+22) +#define SID_SC_ATTR_PAGE_SIZE (SC_RESOURCE_START+21) #endif diff --git a/sc/sdi/docsh.sdi b/sc/sdi/docsh.sdi index 63858c1ccf9d..3ff3ac21b00a 100644 --- a/sc/sdi/docsh.sdi +++ b/sc/sdi/docsh.sdi @@ -85,6 +85,7 @@ interface TableDocument SID_ATTR_PAGE_ORIENTATION [ ExecMethod = Execute; StateMethod = GetState; ] SID_SC_ATTR_PAGE_MARGIN [ ExecMethod = Execute; StateMethod = GetState; ] + SID_SC_ATTR_PAGE_SIZE [ ExecMethod = Execute; StateMethod = GetState; ] } diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi index 9ea5b43211e8..20012f564304 100644 --- a/sc/sdi/scalc.sdi +++ b/sc/sdi/scalc.sdi @@ -6433,6 +6433,25 @@ SvxSizeItem CalcPageMargin SID_SC_ATTR_PAGE_MARGIN ] +SvxSizeItem CalcPageSize SID_SC_ATTR_PAGE_SIZE +( + SfxUInt16Item PaperFormat SID_SC_ATTR_PAGE_SIZE +) +[ + AutoUpdate = FALSE, + FastCall = FALSE, + ReadOnlyDoc = FALSE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + + AccelConfig = TRUE, + MenuConfig = TRUE, + ToolBoxConfig = TRUE, + GroupId = SfxGroupId::Format; +] + SfxVoidItem MarkPrecedents SID_DETECTIVE_MARK_PRED () [ diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index eb49b3c240b5..27d956f1e9f6 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -46,6 +46,7 @@ #include <svx/fmshell.hxx> #include <svx/pageitem.hxx> #include <editeng/sizeitem.hxx> +#include <editeng/paperinf.hxx> #include <sfx2/passwd.hxx> #include <sfx2/filedlghelper.hxx> #include <sfx2/dispatch.hxx> @@ -653,6 +654,68 @@ void ScDocShell::Execute( SfxRequest& rReq ) rReq.Done(); } break; + case SID_SC_ATTR_PAGE_SIZE: + { + const SfxUInt16Item* pPaperFormatInt + = rReq.GetArg<SfxUInt16Item>(SID_SC_ATTR_PAGE_SIZE); + if (!pPaperFormatInt) + break; + + Paper ePaper = static_cast<Paper>(pPaperFormatInt->GetValue()); + if (ePaper >= NUM_PAPER_ENTRIES + && ePaper != PAPER_USER) // PAPER_USER is a valid special case + { + break; + } + + Size aNewSize = SvxPaperInfo::GetPaperSize(ePaper); + + ScViewData* pViewData = GetViewData(); + if (!pViewData) + break; + ScDocument& rDoc = GetDocument(); + const SCTAB nTab = pViewData->GetTabNo(); + OUString aStyleName = rDoc.GetPageStyle(nTab); + ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); + SfxStyleSheetBase* pStyleSheet = pStylePool->Find(aStyleName, SfxStyleFamily::Page); + if (!pStyleSheet) + break; + + SfxItemSet& rSet = pStyleSheet->GetItemSet(); + const SvxSizeItem& rOldSizeItem = rSet.Get(ATTR_PAGE_SIZE); + + // Only apply if the size is actually different + if (aNewSize == rOldSizeItem.GetSize()) + { + rReq.Done(); + break; + } + + SvxSizeItem aNewSizeItem(ATTR_PAGE_SIZE, aNewSize); + rSet.Put(aNewSizeItem); + + // Also update the orientation flag to be consistent with the new dimensions + const SvxPageItem& rOldPageItem = rSet.Get(ATTR_PAGE); + bool bNewIsLandscape = aNewSize.Width() > aNewSize.Height(); + if (bNewIsLandscape != rOldPageItem.IsLandscape()) + { + SvxPageItem aNewPageItem(ATTR_PAGE); + aNewPageItem.SetLandscape(bNewIsLandscape); + rSet.Put(aNewPageItem); + } + + SetDocumentModified(); + PostPaintGridAll(); + + if (pBindings) + { + pBindings->Invalidate(SID_ATTR_PAGE_SIZE); + pBindings->Invalidate(SID_ATTR_PAGE_ORIENTATION); + } + + rReq.Done(); + } + break; case SID_SC_ATTR_PAGE_MARGIN: { const SvxLRSpaceItem* pLR = rReq.GetArg<SvxLRSpaceItem>(SID_ATTR_LRSPACE); @@ -2398,6 +2461,7 @@ void ScDocShell::GetState( SfxItemSet &rSet ) case SID_ATTR_PAGE_ORIENTATION: case SID_SC_ATTR_PAGE_MARGIN: + case SID_SC_ATTR_PAGE_SIZE: { ScViewData* pViewData = GetViewData(); if (pViewData) diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index fd25a604bc2a..daf456f5b981 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -1398,6 +1398,7 @@ const std::map<std::u16string_view, KitUnoCommand>& GetKitUnoCommandList() { u"Signature", { PayloadType::Int32Payload, false } }, { u"SelectionMode", { PayloadType::Int32Payload, true } }, { u"StatusBarFunc", { PayloadType::Int32Payload, true } }, + { u"CalcPageSize", { PayloadType::Int32Payload, true } }, { u"TransformPosX", { PayloadType::TransformPayload, true } }, { u"TransformPosY", { PayloadType::TransformPayload, true } },
