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 b9b12234a4c635457ce83a3f8eec90edc7cb2667
Author:     Mohit Marathe <[email protected]>
AuthorDate: Fri Jul 11 12:46:22 2025 +0530
Commit:     Andras Timar <[email protected]>
CommitDate: Wed Feb 25 18:16:08 2026 +0100

    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 <[email protected]>
    Change-Id: I69cca87f7bb0fbe10bcc1119bd12eb5e5597725d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187682
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Pranam Lashkari <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200308

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index e7b584b32d3f..24116e018ed8 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -2542,6 +2542,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 9dc545881550..de1769001ca6 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -665,6 +665,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)
 #define SID_SC_ATTR_PAGE_SIZE   (SC_RESOURCE_START+21)
 #define SID_SC_ATTR_PAGE_MARGIN   (SC_RESOURCE_START+22)
diff --git a/sc/sdi/docsh.sdi b/sc/sdi/docsh.sdi
index dd8bbfc7f361..0bc3c26e9fc1 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 485aadb47c1e..d6e77fafb3ab 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -6584,6 +6584,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 d07e848b7d9d..da9765453cb0 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -499,6 +499,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 ddc81b67e789..d2cbadcf6957 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 ba453d40cbaa..ff7a330f4fa5 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 <framework/windowstatehelper.hxx>
@@ -1126,6 +1127,50 @@ void ScViewData::SetShowGrid( bool bShow )
     maTabData[GetTabNumber()]->bShowGrid = bShow;
 }
 
+bool ScViewData::GetPrintGrid() const
+{
+    bool bPrintGrid;
+    ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool();
+    SfxStyleSheetBase* pStyleSheet = pStylePool->Find( mrDoc.GetPageStyle( 
GetTabNumber() ), SfxStyleFamily::Page );
+    if (pStyleSheet)
+    {
+        SfxItemSet& rSet = pStyleSheet->GetItemSet();
+        bPrintGrid  = rSet.Get(ATTR_PAGE_GRID).GetValue();
+    }
+    else
+    {
+        const ScViewOptions& rOpt = mrDoc.GetViewOptions();
+        bPrintGrid  = rOpt.GetOption(sc::ViewOption::GRID);
+    }
+    return bPrintGrid;
+}
+
+void ScViewData::SetPrintGrid( bool bPrintGrid )
+{
+    ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool();
+    SfxStyleSheetBase* pStyleSheet = pStylePool->Find( mrDoc.GetPageStyle( 
GetTabNumber() ), 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(GetTabNumber(), pStyleSheet->GetName());
+    }
+    else
+    {
+        // If no style sheet exists, modify the view options directly
+        ScViewOptions aNewOptions = mrDoc.GetViewOptions();
+        aNewOptions.SetOption(sc::ViewOption::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 77d1d9c60efc..e93ac62a18a4 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -1435,6 +1435,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 } },

Reply via email to