sc/inc/sc.hrc | 1 sc/sdi/docsh.sdi | 1 sc/sdi/scalc.sdi | 19 +++++++ sc/source/ui/docshell/docsh4.cxx | 93 ++++++++++++++++++++++++++++++++------- sfx2/source/control/unoctitm.cxx | 1 5 files changed, 100 insertions(+), 15 deletions(-)
New commits: commit 040857afb1f83706df7ea03c6ca5065034802302 Author: Darshan-upadhyay1110 <darshan.upadh...@collabora.com> AuthorDate: Mon Jul 14 13:49:11 2025 +0530 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Mon Aug 25 16:00:34 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 <szymon.k...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> (cherry picked from commit 746a429002c68659d110a18c6eb2e1962ec89eaa) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189205 Tested-by: Jenkins diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc index f172e5fd1498..232a45272812 100644 --- a/sc/inc/sc.hrc +++ b/sc/inc/sc.hrc @@ -654,6 +654,7 @@ static_assert(SID_PREVIEW_END < SID_KEYFUNC_START, "calc slots ids trampling inf #define SID_INSERT_CURRENT_TIME (SC_RESOURCE_START+17) #define FID_TAB_TOGGLE_GRID (SC_RESOURCE_START+18) // toggle sheet grid #define WID_SIMPLE_REF (SC_RESOURCE_START+20) +#define SID_SC_ATTR_PAGE_SIZE (SC_RESOURCE_START+21) #define SID_SC_ATTR_PAGE_MARGIN (SC_RESOURCE_START+22) #endif diff --git a/sc/sdi/docsh.sdi b/sc/sdi/docsh.sdi index 7efb92229908..dd8bbfc7f361 100644 --- a/sc/sdi/docsh.sdi +++ b/sc/sdi/docsh.sdi @@ -86,6 +86,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 f386129cd9fe..4a46dcbb9553 100644 --- a/sc/sdi/scalc.sdi +++ b/sc/sdi/scalc.sdi @@ -6434,6 +6434,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 db33df9f9dab..3a5d2aac98bb 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -47,6 +47,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> @@ -649,6 +650,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); @@ -711,7 +774,6 @@ void ScDocShell::Execute( SfxRequest& rReq ) case SID_AUTO_STYLE: OSL_FAIL("use ScAutoStyleHint instead of SID_AUTO_STYLE"); break; - case SID_GET_COLORLIST: { const SvxColorListItem* pColItem = GetItem(SID_COLOR_TABLE); @@ -2413,26 +2475,27 @@ void ScDocShell::GetState( SfxItemSet &rSet ) break; case SID_ATTR_PAGE_ORIENTATION: case SID_SC_ATTR_PAGE_MARGIN: - { - ScViewData* pViewData = GetViewData(); - if (pViewData) + case SID_SC_ATTR_PAGE_SIZE: { - ScDocument& rDoc = GetDocument(); - const SCTAB nTab = pViewData->GetTabNo(); - OUString aStyleName = rDoc.GetPageStyle(nTab); - ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); - if (pStylePool) + ScViewData* pViewData = GetViewData(); + if (pViewData) { - SfxStyleSheetBase* pStyleSheet - = pStylePool->Find(aStyleName, SfxStyleFamily::Page); - if (pStyleSheet) + ScDocument& rDoc = GetDocument(); + const SCTAB nTab = pViewData->GetTabNo(); + OUString aStyleName = rDoc.GetPageStyle(nTab); + ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); + if (pStylePool) { - const SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); - rSet.Put(rStyleSet.Get(ATTR_PAGE)); + 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: { diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index 361f38e2b18d..335222375548 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -1395,6 +1395,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 } },