Rebased ref, commits from common ancestor:
commit 1ebf5af315d25511df2e1c2f905d872c0dec850e
Author:     Tamás Zolnai <[email protected]>
AuthorDate: Mon Dec 1 13:08:09 2025 +0100
Commit:     Tamás Zolnai <[email protected]>
CommitDate: Tue Dec 2 18:40:30 2025 +0100

    Baseline grid options UI.
    
    Change-Id: I2e6208f36261f09026aa0d4fa6264ab0436224e1

diff --git a/cui/inc/treeopt.hrc b/cui/inc/treeopt.hrc
index 0edd9c3aa06d..48c7b06b89b6 100644
--- a/cui/inc/treeopt.hrc
+++ b/cui/inc/treeopt.hrc
@@ -71,7 +71,7 @@ const std::pair<TranslateId, sal_uInt16> 
SID_SW_EDITOPTIONS_RES[] =
     { NC_("SID_SW_EDITOPTIONS_RES", "General"),     RID_SW_TP_OPTLOAD_PAGE    
},
     { NC_("SID_SW_EDITOPTIONS_RES", "View"),       RID_SW_TP_CONTENT_OPT   },
     { NC_("SID_SW_EDITOPTIONS_RES", "Formatting Aids"),        
RID_SW_TP_OPTSHDWCRSR     },
-    { NC_("SID_SW_EDITOPTIONS_RES", "Grid"),        RID_SVXPAGE_GRID         },
+    { NC_("SID_SW_EDITOPTIONS_RES", "Grids"),        RID_SVXPAGE_GRID         
},
     { NC_("SID_SW_EDITOPTIONS_RES", "Basic Fonts 
(Western)"),RID_SW_TP_STD_FONT        },
     { NC_("SID_SW_EDITOPTIONS_RES", "Basic Fonts 
(Asian)"),RID_SW_TP_STD_FONT_CJK        },
     { NC_("SID_SW_EDITOPTIONS_RES", "Basic Fonts (CTL)"),      
RID_SW_TP_STD_FONT_CTL        },
diff --git a/include/svx/optgrid.hxx b/include/svx/optgrid.hxx
index d6dc7310def2..1bb80e1a7ad5 100644
--- a/include/svx/optgrid.hxx
+++ b/include/svx/optgrid.hxx
@@ -144,6 +144,11 @@ protected:
     std::unique_ptr<weld::MetricSpinButton> m_xMtrFldBezAngle;
     std::unique_ptr<weld::Widget> m_xMtrFldBezAngleImg;
 
+    // Baseline grid related items used only by Writer
+    std::unique_ptr<weld::Widget> m_xBaselineGrid;
+    std::unique_ptr<weld::CheckButton> m_xCbxBaselineGridVisible;
+    std::unique_ptr<weld::Widget> m_xCbxBaselineGridVisibleImg;
+
     bool IsDrawMode() const { return m_Emode == DRAW_MODE; }
 
     DECL_LINK(ClickRotateHdl_Impl, weld::Toggleable&, void);
diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
index 3ce84488d980..fba655b954ee 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
@@ -1505,7 +1505,7 @@
           <desc>Contains options for the grid.</desc>
         </info>
         <prop oor:name="SnapToGrid" oor:type="xs:boolean" oor:nillable="false">
-          <!-- UIHints: Tools - Options - Text document  Grid - [Section] 
Options -->
+          <!-- UIHints: Tools - Options - LibreOffice Writer - Grids - 
[Section] Options -->
           <info>
             <desc>Moves frames, drawing elements, and form functions only 
between the grid points.</desc>
             <label>Snap to grid</label>
@@ -1513,7 +1513,7 @@
           <value>false</value>
         </prop>
         <prop oor:name="VisibleGrid" oor:type="xs:boolean" 
oor:nillable="false">
-          <!-- UIHints: Tools - Options - Text document  Grid - [Section] 
Options -->
+          <!-- UIHints: Tools - Options - LibreOffice Writer - Grids - 
[Section] Options -->
           <info>
             <desc>Displays the grid.</desc>
             <label>Visible grid</label>
@@ -1521,7 +1521,7 @@
           <value>false</value>
         </prop>
         <prop oor:name="Synchronize" oor:type="xs:boolean" 
oor:nillable="false">
-          <!-- UIHints: Tools - Options - Text document  Grid - [Section] 
Options -->
+          <!-- UIHints: Tools - Options - LibreOffice Writer - Grids - 
[Section] Options -->
           <info>
             <desc>Changes the current grid settings symmetrically. The 
resolution and subdivision for the X- and Y-axis remains the same.</desc>
             <label>Synchronize axes</label>
@@ -1534,7 +1534,7 @@
           <desc>Contains settings for specifying the grid resolution.</desc>
         </info>
         <prop oor:name="XAxis" oor:type="xs:int" oor:nillable="false">
-          <!-- UIHints: Tools - Options - Text document - Grid - [Section] 
Grid -->
+          <!-- UIHints: Tools - Options - LibreOffice Writer - Grids - 
[Section] Grid -->
           <info>
             <desc>Defines the grid points distance in the X-axis [UNIT=1/100 
mm].</desc>
             <label>X Axis Resolution</label>
@@ -1542,7 +1542,7 @@
           <value>1000</value>
         </prop>
         <prop oor:name="YAxis" oor:type="xs:int" oor:nillable="false">
-          <!-- UIHints: Tools - Options - Text document - Grid - [Section] 
Grid -->
+          <!-- UIHints: Tools - Options - LibreOffice Writer - Grids - 
[Section] Grid -->
           <info>
             <desc>Defines the grid points distance in the Y-axis [UNIT=1/100 
mm].</desc>
             <label>Y Axis Resolution</label>
@@ -1555,7 +1555,7 @@
           <desc>Contains settings for specifying the subdivision of the 
grid.</desc>
         </info>
         <prop oor:name="XAxis" oor:type="xs:int" oor:nillable="false">
-          <!-- UIHints: Tools - Options - Text document - Grid - [Section] 
Grid -->
+          <!-- UIHints: Tools - Options - LibreOffice Writer - Grids - 
[Section] Grid -->
           <info>
             <desc>Specifies the number of intervals between two grid points on 
the X-axis.</desc>
             <label>X Axis Subdivision</label>
@@ -1563,7 +1563,7 @@
           <value>3</value>
         </prop>
         <prop oor:name="YAxis" oor:type="xs:int" oor:nillable="false">
-          <!-- UIHints: Tools - Options - Text document - Grid - [Section] 
Grid -->
+          <!-- UIHints: Tools - Options - LibreOffice Writer - Grids - 
[Section] Grid -->
           <info>
             <desc>Defines the distance between the grid points on the 
Y-axis.</desc>
             <label>Y Axis Subdivision</label>
@@ -1572,6 +1572,19 @@
         </prop>
       </group>
     </group>
+    <group oor:name="BaselineGrid">
+      <info>
+        <desc>Contains various options for the baseline grid.</desc>
+      </info>
+      <prop oor:name="VisibleGrid" oor:type="xs:boolean" oor:nillable="false">
+        <!-- UIHints: Tools - Options - LibreOffice Writer - Grids - [Section] 
Baseline Grid -->
+        <info>
+          <desc>Displays the baseline grid.</desc>
+          <label>Visible grid</label>
+        </info>
+        <value>false</value>
+      </prop>
+    </group>
     <group oor:name="DefaultFont">
       <info>
         <desc>Specifies the basic western fonts to be used.</desc>
diff --git a/svx/source/dialog/optgrid.cxx b/svx/source/dialog/optgrid.cxx
index 3d3c07453824..e87096027752 100644
--- a/svx/source/dialog/optgrid.cxx
+++ b/svx/source/dialog/optgrid.cxx
@@ -136,6 +136,9 @@ SvxGridTabPage::SvxGridTabPage(weld::Container* pPage, 
weld::DialogController* p
     , m_xMtrFldAngle(m_xBuilder->weld_metric_spin_button(u"mtrfldangle"_ustr, 
FieldUnit::DEGREE))
     , 
m_xMtrFldBezAngle(m_xBuilder->weld_metric_spin_button(u"mtrfldbezangle"_ustr, 
FieldUnit::DEGREE))
     , m_xMtrFldBezAngleImg(m_xBuilder->weld_widget(u"lockmtrfldbezangle"_ustr))
+    , m_xBaselineGrid(m_xBuilder->weld_widget(u"baselinegridframe"_ustr))
+    , 
m_xCbxBaselineGridVisible(m_xBuilder->weld_check_button(u"baselinegridvisible"_ustr))
+    , 
m_xCbxBaselineGridVisibleImg(m_xBuilder->weld_widget(u"lockbaselinegridvisible"_ustr))
 {
     // This page requires exchange Support
     SetExchangeSupport();
@@ -204,7 +207,7 @@ OUString SvxGridTabPage::GetAllStrings()
     OUString sAllStrings;
     OUString labels[]
         = { u"label1"_ustr,    u"label2"_ustr, u"flddrawx"_ustr,  
u"flddrawy"_ustr, u"label6"_ustr, u"label7"_ustr, u"label3"_ustr,
-            u"divisionx"_ustr, u"label4"_ustr, u"divisiony"_ustr, 
u"label5"_ustr,   u"label8"_ustr, u"label9"_ustr };
+            u"divisionx"_ustr, u"label4"_ustr, u"divisiony"_ustr, 
u"label5"_ustr,   u"label8"_ustr, u"label9"_ustr, u"label10"_ustr };
 
     for (const auto& label : labels)
     {
@@ -214,7 +217,8 @@ OUString SvxGridTabPage::GetAllStrings()
 
     OUString checkButton[]
         = { u"usegridsnap"_ustr, u"gridvisible"_ustr, u"synchronize"_ustr, 
u"snaphelplines"_ustr, u"snapborder"_ustr,
-            u"snapframe"_ustr,   u"snappoints"_ustr,  u"ortho"_ustr,       
u"bigortho"_ustr,      u"rotate"_ustr };
+            u"snapframe"_ustr,   u"snappoints"_ustr,  u"ortho"_ustr,       
u"bigortho"_ustr,      u"rotate"_ustr,
+            u"baselinegridvisible"_ustr };
 
     for (const auto& check : checkButton)
     {
diff --git a/svx/uiconfig/ui/optgridpage.ui b/svx/uiconfig/ui/optgridpage.ui
index d8a2ae2f39a0..7b3e0603e23a 100644
--- a/svx/uiconfig/ui/optgridpage.ui
+++ b/svx/uiconfig/ui/optgridpage.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.40.0 -->
 <interface domain="svx">
   <requires lib="gtk+" version="3.24"/>
   <object class="GtkAdjustment" id="adjustment1">
@@ -960,6 +960,72 @@
         <property name="position">2</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkFrame" id="baselinegridframe">
+        <property name="no-show-all">True</property>
+        <property name="can-focus">False</property>
+        <property name="label-xalign">0</property>
+        <property name="shadow-type">none</property>
+        <child>
+          <!-- n-columns=2 n-rows=1 -->
+          <object class="GtkGrid" id="grid10">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+            <property name="margin-start">12</property>
+            <property name="margin-top">6</property>
+            <property name="hexpand">True</property>
+            <property name="row-spacing">6</property>
+            <child>
+              <object class="GtkCheckButton" id="baselinegridvisible">
+                <property name="label" translatable="yes" 
context="optgridpage|baselinegridvisible">V_isible grid</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">False</property>
+                <property name="use-underline">True</property>
+                <property name="draw-indicator">True</property>
+                <child internal-child="accessible">
+                  <object class="AtkObject" id="baselinegridvisible-atkobject">
+                    <property name="AtkObject::accessible-description" 
translatable="yes" context="extended_tip|baselinegridvisible">Specifies whether 
to display the baseline grid.</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left-attach">1</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkImage" id="lockbaselinegridvisible">
+                <property name="can-focus">False</property>
+                <property name="no-show-all">True</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="icon-name">res/lock.png</property>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+        <child type="label">
+          <object class="GtkLabel" id="label10">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+            <property name="label" translatable="yes" 
context="optgridpage|label10">Baseline Grid</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">3</property>
+      </packing>
+    </child>
     <child internal-child="accessible">
       <object class="AtkObject" id="OptGridPage-atkobject">
         <property name="AtkObject::accessible-description" translatable="yes" 
context="extended_tip|OptGridPage">Specifies the settings for the configurable 
grid on your document pages. This grid helps you determine the exact position 
of your objects. You can also set this grid in line with the "magnetic" snap 
grid.</property>
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index f887b4fa24e9..7e4cd65039a0 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -633,6 +633,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/uibase/config/fontcfg \
     sw/source/uibase/config/modcfg \
     sw/source/uibase/config/prtopt \
+    sw/source/uibase/config/SwBaselineGridConfig \
     sw/source/uibase/config/uinums \
     sw/source/uibase/config/usrpref \
     sw/source/uibase/config/viewopt \
diff --git a/sw/Library_swui.mk b/sw/Library_swui.mk
index cf025735337e..016519430421 100644
--- a/sw/Library_swui.mk
+++ b/sw/Library_swui.mk
@@ -95,6 +95,7 @@ $(eval $(call gb_Library_add_exception_objects,swui,\
     sw/source/ui/config/optcomp \
     sw/source/ui/config/optload \
     sw/source/ui/config/optpage \
+    sw/source/ui/config/SwGridTabPage \
     sw/source/ui/dialog/abstract \
     sw/source/ui/dialog/addrdlg \
     sw/source/ui/dialog/ascfldlg \
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index ce9293a0b4ef..f852288c912b 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -877,6 +877,7 @@ class SwUINumRuleItem;
 #define FN_TEXT_BOX                     (FN_PARAM2+28) /* TextBox Property*/
 #define FN_BOOKMARK_HIDDEN              (FN_PARAM2+29) /* Hidden Property of 
bookmarks*/
 #define FN_BOOKMARK_CONDITION           (FN_PARAM2+30) /* Condition Property 
of bookmarks*/
+#define FN_PARAM_BASELINE_GRID_VISIBLE  
TypedWhichId<SfxBoolItem>(FN_PARAM2+31) /* Baseline grid visibility */
 
 // Status: not more than 19!
 #define FN_STAT_PAGE                TypedWhichId<SfxStringListItem>(FN_STAT + 
1)
diff --git a/sw/inc/viewopt.hxx b/sw/inc/viewopt.hxx
index ff93ba1540c7..b0969c9d8e33 100644
--- a/sw/inc/viewopt.hxx
+++ b/sw/inc/viewopt.hxx
@@ -61,6 +61,7 @@ struct ViewOptFlags1
     bool bSnap : 1;
     bool bSynchronize : 1;
     bool bGridVisible : 1;
+    bool bBaselineGridVisible : 1;
     bool bOnlineSpell : 1;
     bool bTreatSubOutlineLevelsAsContent : 1;
     bool bShowInlineTooltips : 1; //tooltips on tracked changes
@@ -104,6 +105,7 @@ struct ViewOptFlags1
         , bSnap(false)
         , bSynchronize(false)
         , bGridVisible(false)
+        , bBaselineGridVisible(false)
         , bOnlineSpell(false)
         , bTreatSubOutlineLevelsAsContent(false)
         , bShowInlineTooltips(false)
@@ -146,6 +148,7 @@ struct ViewOptFlags1
             && bSnap == rOther.bSnap
             && bSynchronize == rOther.bSynchronize
             && bGridVisible == rOther.bGridVisible
+            && bBaselineGridVisible == rOther.bBaselineGridVisible
             && bOnlineSpell == rOther.bOnlineSpell
             && bTreatSubOutlineLevelsAsContent == 
rOther.bTreatSubOutlineLevelsAsContent
             && bShowInlineTooltips == rOther.bShowInlineTooltips
@@ -555,6 +558,15 @@ public:
     void SetGridVisible( bool b )
     { m_nCoreOptions.bGridVisible = b; }
 
+    bool IsBaselineGridVisible() const
+    {
+        return m_nCoreOptions.bBaselineGridVisible;
+    }
+    void SetBaselineGridVisible( bool bVisible )
+    {
+        m_nCoreOptions.bBaselineGridVisible = bVisible;
+    }
+
     bool IsOnlineSpell() const
     {
         return m_nCoreOptions.bOnlineSpell;
diff --git a/sw/source/core/layout/paintfrm.cxx 
b/sw/source/core/layout/paintfrm.cxx
index c0ab186853c4..787d36c751cf 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -6197,6 +6197,30 @@ void SwPageFrame::PaintBaselineGrid(OutputDevice& 
rOututDevice) const
         return;
     }
 
+    const SwRootFrame* pRootFrame = getRootFrame();
+    if (!pRootFrame)
+    {
+        return;
+    }
+
+    const SwViewShell* pViewShell = pRootFrame->GetCurrShell();
+    if (!pViewShell)
+    {
+        return;
+    }
+
+    const SwViewOption *pViewOption = pViewShell->GetViewOptions();
+    if(!pViewOption)
+    {
+        return;
+    }
+
+    // Draw if baseline grid visibility option is set
+    if(!pViewOption->IsBaselineGridVisible())
+    {
+        return;
+    }
+
     const SwPageDesc* pPageDesc = GetPageDesc();
     if (!pPageDesc)
     {
@@ -6205,28 +6229,18 @@ void SwPageFrame::PaintBaselineGrid(OutputDevice& 
rOututDevice) const
 
     sal_uInt16 nLineHeight = 0;
     sal_uInt16 nLineOffset = 0;
+    bool bRegisterTrueEnabled;
     // If page line spacing is enabled we have the correct height / ascent 
values computed already.
     if (pPageDesc->GetRegisterFormatColl())
     {
         nLineHeight = pPageDesc->GetRegHeight();
         nLineOffset = pPageDesc->GetRegAscent();
+        bRegisterTrueEnabled = true;
     }
     else
     {
         // If page line spacing is disabled, use the standard paragraph style 
(Body text) to compute
         // height / ascent values.
-        const SwRootFrame* pRootFrame = getRootFrame();
-        if (!pRootFrame)
-        {
-            return;
-        }
-
-        const SwViewShell* pViewShell = pRootFrame->GetCurrShell();
-        if (!pViewShell)
-        {
-            return;
-        }
-
         SwDoc* pDoc = pViewShell->GetDoc();
         if (!pDoc)
         {
@@ -6239,6 +6253,7 @@ void SwPageFrame::PaintBaselineGrid(OutputDevice& 
rOututDevice) const
             return;
         }
         ComputeRegister(pFormat, nLineHeight, nLineOffset);
+        bRegisterTrueEnabled = false;
     }
 
     const SwLayoutFrame* pBody = FindBodyCont();
@@ -6255,9 +6270,18 @@ void SwPageFrame::PaintBaselineGrid(OutputDevice& 
rOututDevice) const
     const Color aOriginalLineColor(rOututDevice.GetLineColor());
     rOututDevice.SetLineColor(aGridColor);
 
-    const tools::Long nLineWidth = aGridArea.Right() - aGridArea.Left();
-    rOututDevice.DrawGrid(aGridArea.SVRect(), Size(nLineWidth, nLineHeight),
-                          DrawGridFlags::HorzLines);
+    if (bRegisterTrueEnabled)
+    {
+        const tools::Long nLineWidth = aGridArea.Right() - aGridArea.Left();
+        rOututDevice.DrawGrid(aGridArea.SVRect(), Size(nLineWidth, 
nLineHeight),
+                              DrawGridFlags::HorzLines);
+    }
+    else
+    {
+        const tools::Long nDotDistance = 50;
+        rOututDevice.DrawGrid(aGridArea.SVRect(), Size(nDotDistance, 
nLineHeight),
+                              DrawGridFlags::Dots);
+    }
 
     rOututDevice.SetLineColor(aOriginalLineColor);
 }
diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index a9f7213f6444..bf87029fb18d 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -554,7 +554,8 @@ bool SwTextFrame::FillRegister( SwTwips& rRegStart, 
sal_uInt16& rRegDiff )
         pFrame = pFrame->FindPageFrame();
         if( pFrame->IsPageFrame() )
         {
-            SwPageDesc* pDesc = const_cast<SwPageFrame*>(static_cast<const 
SwPageFrame*>(pFrame))->FindPageDesc();
+            const SwPageFrame* pPage = static_cast<const SwPageFrame*>(pFrame);
+            SwPageDesc* pDesc = 
const_cast<SwPageFrame*>(pPage)->FindPageDesc();
             if( pDesc )
             {
                 rRegDiff = pDesc->GetRegHeight();
@@ -565,7 +566,7 @@ bool SwTextFrame::FillRegister( SwTwips& rRegStart, 
sal_uInt16& rRegDiff )
                     {
                         sal_uInt16 nRegHeight = 0;
                         sal_uInt16 nRegAscent = 0;
-                        static_cast<const 
SwPageFrame*>(pFrame)->ComputeRegister(pFormat, nRegHeight, nRegAscent);
+                        pPage->ComputeRegister(pFormat, nRegHeight, 
nRegAscent);
                         pDesc->SetRegHeight( nRegHeight );
                         pDesc->SetRegAscent( nRegAscent );
                         rRegDiff = pDesc->GetRegHeight();
diff --git a/sw/source/ui/config/SwGridTabPage.cxx 
b/sw/source/ui/config/SwGridTabPage.cxx
new file mode 100644
index 000000000000..77095d9919ea
--- /dev/null
+++ b/sw/source/ui/config/SwGridTabPage.cxx
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <cmdid.h>
+#include <SwGridTabPage.hxx>
+
+#include <officecfg/Office/Writer.hxx>
+#include <svl/eitem.hxx>
+
+SwGridTabPage::SwGridTabPage(weld::Container* pPage, weld::DialogController* 
pController,
+                             const SfxItemSet& rItemSet)
+    : SvxGridTabPage(pPage, pController, rItemSet)
+{
+    m_xBaselineGrid->show();
+}
+
+bool SwGridTabPage::FillItemSet(SfxItemSet* pItemSet)
+{
+    SvxGridTabPage::FillItemSet(pItemSet);
+
+    if (m_xCbxBaselineGridVisible->get_state_changed_from_saved())
+    {
+        pItemSet->Put(
+            SfxBoolItem(FN_PARAM_BASELINE_GRID_VISIBLE, 
m_xCbxBaselineGridVisible->get_active()));
+    }
+
+    return true;
+}
+
+void SwGridTabPage::Reset(const SfxItemSet* pItemSet)
+{
+    SvxGridTabPage::Reset(pItemSet);
+
+    if (const SfxBoolItem* pItem = 
pItemSet->GetItemIfSet(FN_PARAM_BASELINE_GRID_VISIBLE, false))
+    {
+        m_xCbxBaselineGridVisible->set_active(pItem->GetValue());
+    }
+
+    const bool bReadOnly = 
officecfg::Office::Writer::BaselineGrid::VisibleGrid::isReadOnly();
+    m_xCbxBaselineGridVisible->set_sensitive(!bReadOnly);
+    m_xCbxBaselineGridVisibleImg->set_visible(bReadOnly);
+    m_xCbxBaselineGridVisible->save_state();
+}
+
+std::unique_ptr<SfxTabPage> SwGridTabPage::Create(weld::Container* pPage,
+                                                  weld::DialogController* 
pController,
+                                                  const SfxItemSet* pItemSet)
+{
+    return std::make_unique<SwGridTabPage>(pPage, pController, *pItemSet);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index a29d8e86a175..c1fec98137b7 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -94,6 +94,7 @@
 #include <formatlinebreak.hxx>
 #include <translatelangselect.hxx>
 #include <copyfielddlg.hxx>
+#include <SwGridTabPage.hxx>
 
 using namespace css::frame;
 using namespace css::uno;
@@ -1290,6 +1291,9 @@ CreateTabPage 
SwAbstractDialogFactory_Impl::GetTabPageCreatorFunc( sal_uInt16 nI
         case RID_SW_TP_COMPARISON_OPT :
             pRet = SwCompareOptionsTabPage::Create;
         break;
+        case RID_SVXPAGE_GRID :
+            pRet = SwGridTabPage::Create;
+        break;
     }
 
     return pRet;
diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx
index bcd5c69d725a..927eeae82842 100644
--- a/sw/source/uibase/app/appopt.cxx
+++ b/sw/source/uibase/app/appopt.cxx
@@ -103,7 +103,8 @@ std::optional<SfxItemSet> SwModule::CreateItemSet( 
sal_uInt16 nId )
             FN_PARAM_WRTSHELL, FN_PARAM_WRTSHELL,
             FN_PARAM_SHADOWCURSOR, FN_PARAM_SHADOWCURSOR,
             FN_PARAM_CRSR_IN_PROTECTED, FN_PARAM_CRSR_IN_PROTECTED,
-            FN_PARAM_FMT_AIDS_AUTOCOMPL, FN_PARAM_FMT_AIDS_AUTOCOMPL>
+            FN_PARAM_FMT_AIDS_AUTOCOMPL, FN_PARAM_FMT_AIDS_AUTOCOMPL,
+            FN_PARAM_BASELINE_GRID_VISIBLE, FN_PARAM_BASELINE_GRID_VISIBLE>
         aRet(GetPool());
 
     aRet.Put( SwDocDisplayItem( aViewOpt ) );
@@ -202,6 +203,9 @@ std::optional<SfxItemSet> SwModule::CreateItemSet( 
sal_uInt16 nId )
 
     aRet.Put(aGridItem);
 
+    // Baseline grid options
+    aRet.Put( SfxBoolItem(FN_PARAM_BASELINE_GRID_VISIBLE, 
aViewOpt.IsBaselineGridVisible()));
+
     // Options for PrintTabPage
     const SwPrintData* pOpt = GetPrtOptions(!bTextDialog);
     SwAddPrinterItem aAddPrinterItem(*pOpt );
@@ -372,6 +376,12 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const 
SfxItemSet& rSet )
         }
     }
 
+    // Baseline grid options
+    if( const SfxBoolItem* pItem = rSet.GetItemIfSet( 
FN_PARAM_BASELINE_GRID_VISIBLE, false ))
+    {
+        aViewOpt.SetBaselineGridVisible(pItem->GetValue());
+    }
+
     // Interpret Writer Printer Options
     if( const SwAddPrinterItem* pAddPrinterAttr = rSet.GetItemIfSet( 
FN_PARAM_ADDPRINTER, false ) )
     {
@@ -454,9 +464,15 @@ std::unique_ptr<SfxTabPage> SwModule::CreateTabPage( 
sal_uInt16 nId, weld::Conta
             break;
         }
         case RID_SW_TP_HTML_OPTGRID_PAGE:
-        case RID_SVXPAGE_GRID:
             xRet = SvxGridTabPage::Create(pPage, pController, rSet);
         break;
+        case RID_SVXPAGE_GRID:
+        {
+            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
+            ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( nId );
+            xRet = (*fnCreatePage)( pPage, pController, &rSet );
+            break;
+        }
 
         case RID_SW_TP_STD_FONT:
         case RID_SW_TP_STD_FONT_CJK:
diff --git a/sw/source/uibase/config/SwBaselineGridConfig.cxx 
b/sw/source/uibase/config/SwBaselineGridConfig.cxx
new file mode 100644
index 000000000000..d356d9aeb6bb
--- /dev/null
+++ b/sw/source/uibase/config/SwBaselineGridConfig.cxx
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <SwBaselineGridConfig.hxx>
+#include <usrpref.hxx>
+
+#include <o3tl/any.hxx>
+#include <osl/diagnose.h>
+
+css::uno::Sequence<OUString> SwBaselineGridConfig::GetPropertyNames()
+{
+    static css::uno::Sequence<OUString> aNames{
+        u"VisibleGrid"_ustr, // 0
+    };
+    return aNames;
+}
+
+SwBaselineGridConfig::SwBaselineGridConfig(SwMasterUsrPref& rParent)
+    : ConfigItem(u"Office.Writer/BaselineGrid"_ustr)
+    , m_rParent(rParent)
+{
+    Load();
+    EnableNotification(GetPropertyNames());
+}
+
+void SwBaselineGridConfig::ImplCommit()
+{
+    const css::uno::Sequence<OUString> aNames = GetPropertyNames();
+    css::uno::Sequence<css::uno::Any> aValues(aNames.getLength());
+    css::uno::Any* pValues = aValues.getArray();
+
+    for (int nProp = 0; nProp < aNames.getLength(); nProp++)
+    {
+        switch (nProp)
+        {
+            case 0: // "VisibleGrid",
+                pValues[nProp] <<= m_rParent.IsBaselineGridVisible();
+                break;
+        }
+    }
+    PutProperties(aNames, aValues);
+}
+
+void SwBaselineGridConfig::Load()
+{
+    const css::uno::Sequence<OUString> aNames = GetPropertyNames();
+    const css::uno::Sequence<css::uno::Any> aValues = GetProperties(aNames);
+    const css::uno::Any* pValues = aValues.getConstArray();
+
+    OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties 
failed");
+    if (aValues.getLength() != aNames.getLength())
+        return;
+
+    for (int nProp = 0; nProp < aNames.getLength(); nProp++)
+    {
+        if (pValues[nProp].hasValue())
+        {
+            switch (nProp)
+            {
+                case 0: // "VisibleGrid"
+                {
+                    bool bVisible = *o3tl::doAccess<bool>(pValues[nProp]);
+                    m_rParent.SetBaselineGridVisible(bVisible);
+                    break;
+                }
+            }
+        }
+    }
+}
+
+void SwBaselineGridConfig::Notify(const css::uno::Sequence<OUString>&) { 
Load(); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sw/source/uibase/config/usrpref.cxx 
b/sw/source/uibase/config/usrpref.cxx
index 1308ba687625..f96b66cc27a0 100644
--- a/sw/source/uibase/config/usrpref.cxx
+++ b/sw/source/uibase/config/usrpref.cxx
@@ -71,7 +71,8 @@ SwMasterUsrPref::SwMasterUsrPref(bool bWeb) :
     m_aGridConfig(bWeb, *this),
     m_aCursorConfig(*this),
     m_pWebColorConfig(bWeb ? new SwWebColorConfig(*this) : nullptr),
-    m_aFmtAidsAutoComplConfig(*this)
+    m_aFmtAidsAutoComplConfig(*this),
+    m_aBaselineGridConfig(bWeb ? std::nullopt : 
std::make_optional<SwBaselineGridConfig>(*this))
 {
     if (comphelper::IsFuzzing())
     {
diff --git a/sw/source/uibase/config/viewopt.cxx 
b/sw/source/uibase/config/viewopt.cxx
index 5a2b5dcdbe90..a8f3e85f602b 100644
--- a/sw/source/uibase/config/viewopt.cxx
+++ b/sw/source/uibase/config/viewopt.cxx
@@ -718,6 +718,10 @@ void ViewOptFlags1::dumpAsXml(xmlTextWriterPtr pWriter) 
const
     (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
                                 
BAD_CAST(OString::boolean(bGridVisible).getStr()));
     (void)xmlTextWriterEndElement(pWriter);
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("bBaselineGridVisible"));
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
+                                
BAD_CAST(OString::boolean(bBaselineGridVisible).getStr()));
+    (void)xmlTextWriterEndElement(pWriter);
     (void)xmlTextWriterStartElement(pWriter, BAD_CAST("bOnlineSpell"));
     (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
                                 
BAD_CAST(OString::boolean(bOnlineSpell).getStr()));
diff --git a/sw/source/uibase/inc/SwBaselineGridConfig.hxx 
b/sw/source/uibase/inc/SwBaselineGridConfig.hxx
new file mode 100644
index 000000000000..ea12215270c7
--- /dev/null
+++ b/sw/source/uibase/inc/SwBaselineGridConfig.hxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <unotools/configitem.hxx>
+
+#include <com/sun/star/uno/Sequence.h>
+
+class SwMasterUsrPref;
+
+class SwBaselineGridConfig final : public utl::ConfigItem
+{
+private:
+    SwMasterUsrPref& m_rParent;
+
+    static css::uno::Sequence<OUString> GetPropertyNames();
+
+    virtual void ImplCommit() override;
+
+public:
+    SwBaselineGridConfig(SwMasterUsrPref& rParent);
+    virtual ~SwBaselineGridConfig() override = default;
+
+    virtual void Notify(const css::uno::Sequence<OUString>& aPropertyNames) 
override;
+    void Load();
+    using ConfigItem::SetModified;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sw/source/uibase/inc/SwGridTabPage.hxx 
b/sw/source/uibase/inc/SwGridTabPage.hxx
new file mode 100644
index 000000000000..535e4a85c60e
--- /dev/null
+++ b/sw/source/uibase/inc/SwGridTabPage.hxx
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sfx2/tabdlg.hxx>
+#include <svx/optgrid.hxx>
+
+class SwGridTabPage final : public SvxGridTabPage
+{
+public:
+    SwGridTabPage(weld::Container* pPage, weld::DialogController* pController,
+                  const SfxItemSet& rItemSet);
+    static std::unique_ptr<SfxTabPage>
+    Create(weld::Container* pPage, weld::DialogController* pController, const 
SfxItemSet* pItemSet);
+    virtual ~SwGridTabPage() override = default;
+
+    virtual bool FillItemSet(SfxItemSet* pItemSet) override;
+    virtual void Reset(const SfxItemSet* pItemSet) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sw/source/uibase/inc/usrpref.hxx b/sw/source/uibase/inc/usrpref.hxx
index 74789e15f641..a7ce4f076717 100644
--- a/sw/source/uibase/inc/usrpref.hxx
+++ b/sw/source/uibase/inc/usrpref.hxx
@@ -24,6 +24,8 @@
 #include <fldupde.hxx>
 #include <viewopt.hxx>
 #include <tools/fldunit.hxx>
+#include <optional>
+#include <SwBaselineGridConfig.hxx>
 
 class SwMasterUsrPref;
 
@@ -176,6 +178,7 @@ class SwMasterUsrPref : public SwViewOption
     SwCursorConfig      m_aCursorConfig;
     std::unique_ptr<SwWebColorConfig>   m_pWebColorConfig;
     SwFmtAidsAutoComplConfig m_aFmtAidsAutoComplConfig;
+    std::optional<SwBaselineGridConfig> m_aBaselineGridConfig; // Not 
available in web mode
 
 public:
     SwMasterUsrPref(bool bWeb);
@@ -192,6 +195,11 @@ public:
             if(m_pWebColorConfig)
                 m_pWebColorConfig->SetModified();
             m_aFmtAidsAutoComplConfig.SetModified();
+
+            if(m_aBaselineGridConfig.has_value())
+            {
+                m_aBaselineGridConfig->SetModified();
+            }
         }
 
     void SetUpdateLinkMode(sal_Int32 nSet, bool bNoModify = false)

Reply via email to