sc/inc/dbdata.hxx                     |    6 ++++--
 sc/inc/document.hxx                   |    5 +++--
 sc/inc/tablestyle.hxx                 |    1 +
 sc/source/core/data/documen2.cxx      |   13 +++++++++----
 sc/source/core/data/tablestyle.cxx    |   22 +++++++++++++++++++---
 sc/source/core/tool/dbdata.cxx        |   12 +++++++++++-
 sc/source/filter/excel/xedbdata.cxx   |   12 +++++++++---
 sc/source/filter/excel/xestyle.cxx    |    9 ++++++---
 sc/source/filter/oox/stylesbuffer.cxx |    4 ++--
 sc/source/ui/inc/gridwin.hxx          |    2 +-
 sc/source/ui/unoobj/docuno.cxx        |    1 +
 sc/source/ui/view/gridwin.cxx         |   29 +++++++++++++++++++++++------
 12 files changed, 89 insertions(+), 27 deletions(-)

New commits:
commit 571d63cfe96f0e39531534f1f6777e3199e1ede0
Author:     Balazs Varga <[email protected]>
AuthorDate: Thu Nov 20 09:03:57 2025 +0100
Commit:     Balazs Varga <[email protected]>
CommitDate: Wed Jan 7 17:16:37 2026 +0100

    Table styles: fix missing border style if have no total row
    
    Also change some table style function to get back pointers
    instead of references to check if they are really exists.
    
    Change-Id: Icec52d11a416cc9831f83bdce979b9530bb0b8b9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194239
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196765
    Tested-by: Balazs Varga <[email protected]>

diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index 981ac3b6e9de..a100c9345b72 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -194,8 +194,9 @@ public:
 
     SC_DLLPUBLIC ScDBData(const OUString& rName,
              SCTAB nTab,
-             SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
-             bool bByR = true, bool bHasH = true, bool bTotals = false, const 
OUString& rTableType = "worksheet");
+             SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bByR = 
true, bool bHasH = true, bool bTotals = false,
+                          const OUString& rTableType = u"worksheet"_ustr,
+                          const OUString& rTableStyleID = u""_ustr);
     ScDBData(const ScDBData& rData);
     ScDBData(const OUString& rName, const ScDBData& rData);
     SC_DLLPUBLIC virtual ~ScDBData() override;
@@ -325,6 +326,7 @@ public:
 
     SC_DLLPUBLIC void SetTableStyleInfo(const ScTableStyleParam& rParams);
     SC_DLLPUBLIC const ScTableStyleParam* GetTableStyleInfo() const;
+    void RemoveTableStyleInfo();
 
     static ScSubTotalFunc GetSubTotalFuncFromString(std::u16string_view 
sFunction);
     static OUString GetStringFromSubTotalFunc(ScSubTotalFunc eFunc);
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 1fff76c3b0cf..1b5bdf73c84b 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2765,8 +2765,9 @@ public:
     bool  SetLOKFreezeCol(SCCOL nFreezeCol, SCTAB nTab);
     bool  SetLOKFreezeRow(SCROW nFreezeRow, SCTAB nTab);
 
-    SC_DLLPUBLIC ScTableStyles& GetTableStyles();
-    SC_DLLPUBLIC const ScTableStyles& GetTableStyles() const;
+    SC_DLLPUBLIC ScTableStyles* GetTableStyles();
+    SC_DLLPUBLIC const ScTableStyles* GetTableStyles() const;
+    SC_DLLPUBLIC bool HasTableStyles() const;
 
 private:
 
diff --git a/sc/inc/tablestyle.hxx b/sc/inc/tablestyle.hxx
index 514f23d7ecce..57fbd8046b14 100644
--- a/sc/inc/tablestyle.hxx
+++ b/sc/inc/tablestyle.hxx
@@ -126,6 +126,7 @@ public:
     void AddTableStyle(std::unique_ptr<ScTableStyle> pTableStyle);
     void DeleteTableStyle(const OUString& rName);
     const ScTableStyle* GetTableStyle(const OUString& rName) const;
+    bool HasTableStyle() const { return maTableStyles.size() > 0; }
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index ecdb8a1dd358..71f938dcc0f2 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1543,14 +1543,19 @@ sc::IconSetBitmapMap& ScDocument::GetIconSetBitmapMap()
     return *m_pIconSetBitmapMap;
 }
 
-ScTableStyles& ScDocument::GetTableStyles()
+ScTableStyles* ScDocument::GetTableStyles()
 {
-    return *mpTableStyles;
+    return mpTableStyles.get();
 }
 
-const ScTableStyles& ScDocument::GetTableStyles() const
+const ScTableStyles* ScDocument::GetTableStyles() const
 {
-    return *mpTableStyles;
+    return mpTableStyles.get();
+}
+
+bool ScDocument::HasTableStyles() const
+{
+    return mpTableStyles->HasTableStyle();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/tablestyle.cxx 
b/sc/source/core/data/tablestyle.cxx
index 29373b9e81ab..bf7c03664d09 100644
--- a/sc/source/core/data/tablestyle.cxx
+++ b/sc/source/core/data/tablestyle.cxx
@@ -521,12 +521,17 @@ std::unique_ptr<SvxBoxItem> 
ScTableStyle::GetBoxItem(const ScDBData& rDBData, SC
                     {
                         const ::editeng::SvxBorderLine* pLLine
                             = pBoxItem->GetLine(SvxBoxItemLine::LEFT);
-                        if (pLLine)
+                        const ::editeng::SvxBorderLine* pBLine = nullptr;
+                        if (aRange.aEnd.Row() == nRow)
+                            pBLine = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                        if (pLLine || pBLine)
                         {
                             std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem 
? pPoolItem->Clone()
                                                                               
: nullptr);
                             if (!pNewBoxItem)
                                 pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                            if (pBLine)
+                                pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
                             if (pLLine)
                                 pNewBoxItem->SetLine(pLLine, 
SvxBoxItemLine::LEFT);
 
@@ -537,12 +542,17 @@ std::unique_ptr<SvxBoxItem> 
ScTableStyle::GetBoxItem(const ScDBData& rDBData, SC
                     {
                         const ::editeng::SvxBorderLine* pRLine
                             = pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
-                        if (pRLine)
+                        const ::editeng::SvxBorderLine* pBLine = nullptr;
+                        if (aRange.aEnd.Row() == nRow)
+                            pBLine = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                        if (pRLine || pBLine)
                         {
                             std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem 
? pPoolItem->Clone()
                                                                               
: nullptr);
                             if (!pNewBoxItem)
                                 pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                            if (pBLine)
+                                pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
                             if (pRLine)
                                 pNewBoxItem->SetLine(pRLine, 
SvxBoxItemLine::RIGHT);
 
@@ -551,16 +561,22 @@ std::unique_ptr<SvxBoxItem> 
ScTableStyle::GetBoxItem(const ScDBData& rDBData, SC
                     }
                     else
                     {
+                        const ::editeng::SvxBorderLine* pBLine = nullptr;
+                        if (pBoxItem && aRange.aEnd.Row() == nRow)
+                            pBLine = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+
                         const ::editeng::SvxBorderLine* pVLine = nullptr;
                         if (pBoxInfoItem)
                             pVLine = pBoxInfoItem->GetVert();
 
-                        if (pVLine)
+                        if (pBLine || pVLine)
                         {
                             std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem 
? pPoolItem->Clone()
                                                                               
: nullptr);
                             if (!pNewBoxItem)
                                 pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                            if (pBLine)
+                                pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
                             if (pVLine)
                             {
                                 pNewBoxItem->SetLine(pVLine, 
SvxBoxItemLine::LEFT);
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index 3a7aea7c1644..5da39755b8d5 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -285,7 +285,7 @@ bool ScDBData::less::operator() (const 
std::unique_ptr<ScDBData>& left, const st
 ScDBData::ScDBData( const OUString& rName,
                     SCTAB nTab,
                     SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
-                    bool bByR, bool bHasH, bool bTotals, const OUString& 
rTableType) :
+                    bool bByR, bool bHasH, bool bTotals, const OUString& 
rTableType, const OUString& rTableStyleID) :
     // Listeners are to be setup by the "parent" container.
     mpSortParam(new ScSortParam),
     mpQueryParam(new ScQueryParam),
@@ -315,6 +315,11 @@ ScDBData::ScDBData( const OUString& rName,
     nFilteredRowCount(SCSIZE_MAX)
 {
     aUpper = ScGlobal::getCharClass().uppercase(aUpper);
+    if (!rTableStyleID.isEmpty())
+    {
+        mpTableStyles.reset(new ScTableStyleParam());
+        mpTableStyles->maStyleID = rTableStyleID;
+    }
 }
 
 ScDBData::ScDBData( const ScDBData& rData ) :
@@ -1571,6 +1576,11 @@ const ScTableStyleParam* ScDBData::GetTableStyleInfo() 
const
     return mpTableStyles.get();
 }
 
+void ScDBData::RemoveTableStyleInfo()
+{
+    mpTableStyles.reset();
+}
+
 ScSubTotalFunc ScDBData::GetSubTotalFuncFromString(std::u16string_view 
sFunction)
 {
     if (sFunction == u"sum")
diff --git a/sc/source/filter/excel/xedbdata.cxx 
b/sc/source/filter/excel/xedbdata.cxx
index cde80605294a..b2625f5d01e6 100644
--- a/sc/source/filter/excel/xedbdata.cxx
+++ b/sc/source/filter/excel/xedbdata.cxx
@@ -321,10 +321,16 @@ void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, 
const Entry& rEntry )
     if (const ScTableStyleParam* pParam = rData.GetTableStyleInfo())
     {
         const OUString& rStyleName = pParam->maStyleID;
-        const ScTableStyle* pTableStyle = 
rStrm.GetRoot().GetDoc().GetTableStyles().GetTableStyle(rStyleName);
-        if (pTableStyle)
+        if (const ScTableStyles* pTableStyles = 
rStrm.GetRoot().GetDoc().GetTableStyles())
         {
-            pTableStrm->singleElement( XML_tableStyleInfo, XML_name, 
rStyleName.toUtf8(), XML_showFirstColumn, ToPsz10(pParam->mbFirstColumn), 
XML_showLastColumn, ToPsz10(pParam->mbLastColumn), XML_showRowStripes, 
ToPsz10(pParam->mbRowStripes), XML_showColumnStripes, 
ToPsz10(pParam->mbColumnStripes));
+            if (const ScTableStyle* pTableStyle = 
pTableStyles->GetTableStyle(rStyleName))
+            {
+                pTableStrm->singleElement(XML_tableStyleInfo, XML_name, 
rStyleName.toUtf8(),
+                                          XML_showFirstColumn, 
ToPsz10(pParam->mbFirstColumn),
+                                          XML_showLastColumn, 
ToPsz10(pParam->mbLastColumn),
+                                          XML_showRowStripes, 
ToPsz10(pParam->mbRowStripes),
+                                          XML_showColumnStripes, 
ToPsz10(pParam->mbColumnStripes));
+            }
         }
     }
 
diff --git a/sc/source/filter/excel/xestyle.cxx 
b/sc/source/filter/excel/xestyle.cxx
index ee749733cdef..1b9c5c269bac 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -3381,11 +3381,14 @@ XclExpXmlTableStyles::XclExpXmlTableStyles( const 
XclExpRoot& rRoot):
 
     const ScDBCollection* pDBCollection = GetDoc().GetDBCollection();
     const ScDBCollection::NamedDBs& rDBs = pDBCollection->getNamedDBs();
-    const ScTableStyles& rTableStyles = GetDoc().GetTableStyles();
+    const ScTableStyles* pTableStyles = GetDoc().GetTableStyles();
+    if (!pTableStyles)
+        return;
+
     for (auto itr = rDBs.begin(); itr != rDBs.end(); ++itr)
     {
         const ScTableStyleParam* pParam = itr->get()->GetTableStyleInfo();
-        if (pParam && rTableStyles.GetTableStyle(pParam->maStyleID))
+        if (pParam && pTableStyles->GetTableStyle(pParam->maStyleID))
         {
             aTableStyleNames.insert(pParam->maStyleID);
         }
@@ -3393,7 +3396,7 @@ XclExpXmlTableStyles::XclExpXmlTableStyles( const 
XclExpRoot& rRoot):
 
     for (const OUString& aTableStyleName : aTableStyleNames)
     {
-        const ScTableStyle* pTableStyle = 
rTableStyles.GetTableStyle(aTableStyleName);
+        const ScTableStyle* pTableStyle = 
pTableStyles->GetTableStyle(aTableStyleName);
         maTableStyles.push_back(std::make_unique<XclExpXmlTableStyle>(rRoot, 
pTableStyle));
     }
 }
diff --git a/sc/source/filter/oox/stylesbuffer.cxx 
b/sc/source/filter/oox/stylesbuffer.cxx
index 5b408727bb07..d38bd13ece3e 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2668,7 +2668,6 @@ void TableStyle::setTableStyleElement(ScTableStyleElement 
eElement, sal_Int32 nD
 void TableStyle::finalizeImport(const DxfVector& rDxfs)
 {
     ::ScDocument& rDoc = getScDocument();
-    ScTableStyles& rStyles = rDoc.GetTableStyles();
     std::unique_ptr<ScTableStyle> pTableStyle = 
std::make_unique<ScTableStyle>(maName, maUIName);
     pTableStyle->SetOOXMLDefault(mbDefaultOOXMLStyle);
     for (const auto& aTableStyleElementInfo : maTableStyleElements)
@@ -2705,7 +2704,8 @@ void TableStyle::finalizeImport(const DxfVector& rDxfs)
                 SAL_WARN("sc", "the stripe count should only be set for row 
and column stripe elements");
         }
     }
-    rStyles.AddTableStyle(std::move(pTableStyle));
+    if (ScTableStyles* pStyles = rDoc.GetTableStyles())
+        pStyles->AddTableStyle(std::move(pTableStyle));
 }
 
 namespace {
commit 4c005ee63fc06a5f94a6d5c0292a9f2e1b317d95
Author:     Balazs Varga <[email protected]>
AuthorDate: Tue Nov 18 08:33:25 2025 +0100
Commit:     Balazs Varga <[email protected]>
CommitDate: Wed Jan 7 17:16:26 2026 +0100

    Table Styles ooxml: send TableAutoFillInfo callback
    
    state for kit to create new section as an indication
    of selected database table style range.
    
    Change-Id: I0737f90f376e33a1c79cbfda169bddabd366a8dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194152
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196764
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>

diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 1f0f541792b6..c9ae75c3b12c 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -335,7 +335,7 @@ class SAL_DLLPUBLIC_RTTI ScGridWindow : public 
vcl::DocWindow, public DropTarget
     void            UpdateFormulaRange(SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW 
nY2);
 
     std::unique_ptr<sdr::overlay::OverlayObject> DrawOverlay(const 
std::vector<tools::Rectangle>& rRects, const Color& rColor, bool bBorder, bool 
bContrastOutline, sdr::overlay::OverlayType eOverlayType);
-    std::unique_ptr<sdr::overlay::OverlayObjectList> DrawFillMarker(SCCOL 
nCol, SCROW nRow, std::optional<tools::Rectangle>& rRect);
+    std::unique_ptr<sdr::overlay::OverlayObjectList> DrawFillMarker(SCCOL 
nCol, SCROW nRow, std::optional<tools::Rectangle>& rRect, bool bIsTableArea);
 
 protected:
     virtual void    PrePaint(vcl::RenderContext& rRenderContext) override;
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 2924e0615b60..d2371ceb940d 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1128,6 +1128,7 @@ void ScModelObj::setClientZoom(int nTilePixelWidth_, int 
nTilePixelHeight_, int
     // refresh our view's take on other view's cursors & selections
     ScGridWindow* pGridWindow = pViewData->GetActiveWin();
     pGridWindow->UpdateEditViewPos();
+    pGridWindow->UpdateDatabaseOverlay();
     pGridWindow->updateKitOtherCursors();
     pGridWindow->updateOtherKitSelections();
     pGridWindow->resetCachedViewGridOffsets();
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 836309319465..72e626f326aa 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -6625,7 +6625,7 @@ void ScGridWindow::updateOtherKitSelections() const
 namespace
 {
 
-void updateLibreOfficeKitAutoFill(const ScViewData& rViewData, 
tools::Rectangle const & rRectangle)
+void updateLibreOfficeKitAutoFill(const ScViewData& rViewData, 
tools::Rectangle const & rRectangle, bool bIsTableArea)
 {
     if (!comphelper::LibreOfficeKit::isActive())
         return;
@@ -6644,7 +6644,19 @@ void updateLibreOfficeKitAutoFill(const ScViewData& 
rViewData, tools::Rectangle
     }
 
     ScTabViewShell* pViewShell = rViewData.GetViewShell();
-    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_AUTO_FILL_AREA, 
sRectangleString);
+    if (bIsTableArea)
+    {
+        tools::JsonWriter writer;
+        writer.put("commandName", "TableAutoFillInfo");
+        {
+            const auto aState = writer.startNode("state");
+            writer.put("rectangle", sRectangleString);
+        }
+        OString info = writer.finishAndGetAsOString();
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
info);
+    }
+    else
+        
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_AUTO_FILL_AREA, 
sRectangleString);
 }
 
 } //end anonymous namespace
@@ -6981,6 +6993,11 @@ void ScGridWindow::DeleteDatabaseOverlay()
 {
     mpDBExpandRect.reset();
     mpOODatabase.reset();
+    if (comphelper::LibreOfficeKit::isActive()) // notify the LibreOfficeKit
+    {
+        tools::Rectangle aEmptyRect;
+        updateLibreOfficeKitAutoFill(mrViewData, aEmptyRect, true);
+    }
 }
 
 void ScGridWindow::UpdateDatabaseOverlay()
@@ -7036,7 +7053,7 @@ void ScGridWindow::UpdateDatabaseOverlay()
                 true, true));
 
             xOverlayManager->add(*pOverlay);
-            std::unique_ptr<sdr::overlay::OverlayObjectList> pOverlayList = 
DrawFillMarker(aCurrRange.aEnd.Col(), aCurrRange.aEnd.Row(), mpDBExpandRect);
+            std::unique_ptr<sdr::overlay::OverlayObjectList> pOverlayList = 
DrawFillMarker(aCurrRange.aEnd.Col(), aCurrRange.aEnd.Row(), mpDBExpandRect, 
true);
             if (pOverlayList)
             {
                 mpOODatabase.swap(pOverlayList);
@@ -7080,7 +7097,7 @@ void ScGridWindow::DeleteAutoFillOverlay()
     mpAutoFillRect.reset();
 }
 
-std::unique_ptr<sdr::overlay::OverlayObjectList> 
ScGridWindow::DrawFillMarker(SCCOL nX, SCROW nY, 
std::optional<tools::Rectangle>& rRect)
+std::unique_ptr<sdr::overlay::OverlayObjectList> 
ScGridWindow::DrawFillMarker(SCCOL nX, SCROW nY, 
std::optional<tools::Rectangle>& rRect, bool bIsTableArea)
 {
     SCTAB nTab = mrViewData.CurrentTabForData();
     ScDocument& rDoc = mrViewData.GetDocument();
@@ -7125,7 +7142,7 @@ std::unique_ptr<sdr::overlay::OverlayObjectList> 
ScGridWindow::DrawFillMarker(SC
     rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager = 
getOverlayManager();
     if (comphelper::LibreOfficeKit::isActive()) // notify the LibreOfficeKit
     {
-        updateLibreOfficeKitAutoFill(mrViewData, aFillRect);
+        updateLibreOfficeKitAutoFill(mrViewData, aFillRect, bIsTableArea);
     }
     else if (xOverlayManager.is())
     {
@@ -7207,7 +7224,7 @@ void ScGridWindow::UpdateAutoFillOverlay()
         return;
     }
 
-    mpOOAutoFill = DrawFillMarker(nX, nY, mpAutoFillRect);
+    mpOOAutoFill = DrawFillMarker(nX, nY, mpAutoFillRect, false);
 }
 
 void ScGridWindow::DeleteDragRectOverlay()

Reply via email to