officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu | 8 + sc/inc/sc.hrc | 1 sc/sdi/docsh.sdi | 1 sc/sdi/scalc.sdi | 16 +++ sc/source/ui/inc/viewdata.hxx | 3 sc/source/ui/view/tabvwshf.cxx | 16 +++ sc/source/ui/view/viewdata.cxx | 45 ++++++++++ sfx2/source/control/unoctitm.cxx | 1 8 files changed, 91 insertions(+)
New commits: commit e1ce0de83d6b1325a432e63a47104454abea9bcb Author: Mohit Marathe <mohit.mara...@collabora.com> AuthorDate: Fri Jul 11 12:46:22 2025 +0530 Commit: Pranam Lashkari <lpra...@collabora.com> CommitDate: Mon Jul 14 14:47:27 2025 +0200 sc: Add TogglePrintGrid uno command This command toggles the state of ATTR_PAGE_GRID in page style which is responsible for setting grid lines for print. This allows adding a toolbar button for this functionality instead of going through "Format Page" dialog->"Sheet" tab->"Grid" Signed-off-by: Mohit Marathe <mohit.mara...@collabora.com> Change-Id: I69cca87f7bb0fbe10bcc1119bd12eb5e5597725d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187682 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Pranam Lashkari <lpra...@collabora.com> diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu index 9d8ddf9d7f04..cb39c8c5a20b 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu @@ -2486,6 +2486,14 @@ <value>1</value> </prop> </node> + <node oor:name=".uno:TogglePrintGrid" oor:op="replace"> + <prop oor:name="Label" oor:type="xs:string"> + <value xml:lang="en-US">Print Grid Lines</value> + </prop> + <prop oor:name="Properties" oor:type="xs:int"> + <value>1</value> + </prop> + </node> <node oor:name=".uno:InsertFieldSheet" oor:op="replace"> <prop oor:name="Label" oor:type="xs:string"> <value xml:lang="en-US">Sheet Name</value> diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc index a1a8be63f46a..2b475448f345 100644 --- a/sc/inc/sc.hrc +++ b/sc/inc/sc.hrc @@ -652,6 +652,7 @@ static_assert(SID_PREVIEW_END < SID_KEYFUNC_START, "calc slots ids trampling inf #define SID_INSERT_CURRENT_DATE (SC_RESOURCE_START+16) #define SID_INSERT_CURRENT_TIME (SC_RESOURCE_START+17) #define FID_TAB_TOGGLE_GRID (SC_RESOURCE_START+18) // toggle sheet grid +#define FID_TOGGLE_PRINT_GRID (SC_RESOURCE_START+19) // toggle print grid #define WID_SIMPLE_REF (SC_RESOURCE_START+20) #endif diff --git a/sc/sdi/docsh.sdi b/sc/sdi/docsh.sdi index 23d921ffe454..b985eb0a169c 100644 --- a/sc/sdi/docsh.sdi +++ b/sc/sdi/docsh.sdi @@ -41,6 +41,7 @@ interface TableSelection FID_TAB_RTL [ ExecMethod = ExecuteTable; StateMethod = GetStateTable; ] FID_TAB_SET_TAB_BG_COLOR [ ExecMethod = ExecuteTable; StateMethod = GetStateTable; ] FID_TAB_TOGGLE_GRID [ ExecMethod = ExecuteTable; StateMethod = GetStateTable; ] + FID_TOGGLE_PRINT_GRID [ ExecMethod = ExecuteTable; StateMethod = GetStateTable; ] FID_TOGGLEHIDDENCOLROW [ ExecMethod = ExecuteTable; StateMethod = GetState; ] SID_TABLE_ACTIVATE [ ExecMethod = Execute; ] } diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi index d22c6fbf6529..60421443767f 100644 --- a/sc/sdi/scalc.sdi +++ b/sc/sdi/scalc.sdi @@ -6374,6 +6374,22 @@ SfxBoolItem ToggleSheetGrid FID_TAB_TOGGLE_GRID ] +SfxBoolItem TogglePrintGrid FID_TOGGLE_PRINT_GRID + +[ + AutoUpdate = FALSE, + FastCall = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + + AccelConfig = TRUE, + MenuConfig = TRUE, + ToolBoxConfig = TRUE, + GroupId = SfxGroupId::Format; +] SvxColorItem TabBgColor FID_TAB_SET_TAB_BG_COLOR diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx index 6b9dd8548ef7..54134243dfd6 100644 --- a/sc/source/ui/inc/viewdata.hxx +++ b/sc/source/ui/inc/viewdata.hxx @@ -467,6 +467,9 @@ public: void SetShowGrid( bool bShow ); bool GetShowGrid() const { return pThisTab->bShowGrid; } + void SetPrintGrid( bool bPrintGrid ); + bool GetPrintGrid() const; + const MapMode& GetLogicMode( ScSplitPos eWhich ); const MapMode& GetLogicMode(); // Offset 0 diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx index 70b9e424c32f..833fd039d79f 100644 --- a/sc/source/ui/view/tabvwshf.cxx +++ b/sc/source/ui/view/tabvwshf.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <stlpool.hxx> #include <config_features.h> #include <memory> @@ -427,6 +428,15 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) } break; + case FID_TOGGLE_PRINT_GRID: + { + bool bPrintGrid = rViewData.GetPrintGrid(); + rViewData.SetPrintGrid(!bPrintGrid); + SfxBindings& rBindings = GetViewFrame().GetBindings(); + rBindings.Invalidate( FID_TOGGLE_PRINT_GRID ); + } + break; + case FID_TAB_SET_TAB_BG_COLOR: case FID_TAB_MENU_SET_TAB_BG_COLOR: ExecuteSetTableBackgroundCol(rReq); @@ -593,6 +603,12 @@ void ScTabViewShell::GetStateTable( SfxItemSet& rSet ) case FID_TAB_TOGGLE_GRID: rSet.Put( SfxBoolItem(nWhich, rViewData.GetShowGrid()) ); break; + + case FID_TOGGLE_PRINT_GRID: + { + rSet.Put( SfxBoolItem(nWhich, rViewData.GetPrintGrid())); + } + break; } nWhich = aIter.NextWhich(); } diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index 08f9c099e856..1352bea51040 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <stlpool.hxx> #include <scitems.hxx> #include <editeng/eeitem.hxx> #include <o3tl/safeint.hxx> @@ -1129,6 +1130,50 @@ void ScViewData::SetShowGrid( bool bShow ) maTabData[nTabNo]->bShowGrid = bShow; } +bool ScViewData::GetPrintGrid() const +{ + bool bPrintGrid; + ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool(); + SfxStyleSheetBase* pStyleSheet = pStylePool->Find( mrDoc.GetPageStyle( nTabNo ), SfxStyleFamily::Page ); + if (pStyleSheet) + { + SfxItemSet& rSet = pStyleSheet->GetItemSet(); + bPrintGrid = rSet.Get(ATTR_PAGE_GRID).GetValue(); + } + else + { + const ScViewOptions& rOpt = mrDoc.GetViewOptions(); + bPrintGrid = rOpt.GetOption(ScViewOption::VOPT_GRID); + } + return bPrintGrid; +} + +void ScViewData::SetPrintGrid( bool bPrintGrid ) +{ + ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool(); + SfxStyleSheetBase* pStyleSheet = pStylePool->Find( mrDoc.GetPageStyle( nTabNo ), SfxStyleFamily::Page ); + if (pStyleSheet) + { + SfxItemSet& rSet = pStyleSheet->GetItemSet(); + SfxItemState eState = rSet.GetItemState(ATTR_PAGE_GRID, true); + bool bOld = rSet.Get(ATTR_PAGE_GRID).GetValue(); + + if (bOld == bPrintGrid && eState == SfxItemState::DEFAULT) + rSet.ClearItem(ATTR_PAGE_GRID); + else + rSet.Put(SfxBoolItem(ATTR_PAGE_GRID, bPrintGrid)); + + mrDoc.PageStyleModified(nTabNo, pStyleSheet->GetName()); + } + else + { + // If no style sheet exists, modify the view options directly + ScViewOptions aNewOptions = mrDoc.GetViewOptions(); + aNewOptions.SetOption(ScViewOption::VOPT_GRID, bPrintGrid); + mrDoc.SetViewOptions(aNewOptions); + } +} + void ScViewData::RefreshZoom() { // recalculate zoom-dependent values (only for current sheet) diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index 35805da2f5ef..3167ce83382f 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -1424,6 +1424,7 @@ const std::map<std::u16string_view, KitUnoCommand>& GetKitUnoCommandList() { u"ToggleMergeCells", { PayloadType::BooleanOrDisabledPayload, true } }, { u"SheetRightToLeft", { PayloadType::BooleanOrDisabledPayload, true } }, { u"ToggleSheetGrid", { PayloadType::BooleanOrDisabledPayload, true } }, + { u"TogglePrintGrid", { PayloadType::BooleanOrDisabledPayload, true } }, { u"EditDoc", { PayloadType::BooleanOrDisabledPayload, true } }, { u"Position", { PayloadType::PointPayload, false } },