sc/inc/tablestyle.hxx              |    5 ++-
 sc/source/core/data/documen4.cxx   |    2 -
 sc/source/core/data/fillinfo.cxx   |    2 -
 sc/source/core/data/tablestyle.cxx |   52 +++++++++++++++++++++++++++----------
 sc/source/ui/drawfunc/drawsh2.cxx  |   26 ++++++++++++++++--
 sc/source/ui/view/tabvwsh4.cxx     |    2 -
 6 files changed, 68 insertions(+), 21 deletions(-)

New commits:
commit ba725a806a724181b5f798fd0f712aa0dfd7226d
Author:     Balazs Varga <[email protected]>
AuthorDate: Thu Nov 13 10:39:52 2025 +0100
Commit:     Balazs Varga <[email protected]>
CommitDate: Thu Jan 29 09:30:22 2026 +0100

    Table styles: fix wrong font colors after we applied an empty
    
    font attr set for FirstColumnStripePattern, which didn't have
    any font attr but TablePattern has.
    
    Change-Id: Ib125432b3d34311348f864005f97a2eeeac92ea1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193985
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196759
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197985
    Tested-by: Jenkins

diff --git a/sc/inc/tablestyle.hxx b/sc/inc/tablestyle.hxx
index 04b9c36d56e4..514f23d7ecce 100644
--- a/sc/inc/tablestyle.hxx
+++ b/sc/inc/tablestyle.hxx
@@ -71,8 +71,9 @@ private:
 public:
     ScTableStyle(const OUString& rName, const std::optional<OUString>& 
rUIName);
 
-    const SfxItemSet* GetTableCellItemSet(const ScDBData& rDBData, SCCOL nCol, 
SCROW nRow,
-                                          SCROW nRowIndex) const;
+    static bool HasFontAttrSet(ScPatternAttr* pPattern);
+    const SfxItemSet* GetFontItemSet(const ScDBData& rDBData, SCCOL nCol, 
SCROW nRow,
+                                     SCROW nRowIndex) const;
     const SvxBrushItem* GetFillItem(const ScDBData& rDBData, SCCOL nCol, SCROW 
nRow,
                                     SCROW nRowIndex) const;
     std::unique_ptr<SvxBoxItem> GetBoxItem(const ScDBData& rDBData, SCCOL 
nCol, SCROW nRow,
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index b0664bcae0ed..9612ec11154a 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -813,7 +813,7 @@ const SfxItemSet* ScDocument::GetTableFormatSet(SCCOL nCol, 
SCROW nRow, SCTAB nT
         {
             nNonEmptyRowsBeforePaintRange += 
this->CountNonFilteredRows(aDBRange.aStart.Row(), nRow - 1, nTab);
         }
-        return pTableStyle->GetTableCellItemSet(*pDBData, nCol, nRow, 
nNonEmptyRowsBeforePaintRange);
+        return pTableStyle->GetFontItemSet(*pDBData, nCol, nRow, 
nNonEmptyRowsBeforePaintRange);
     }
     return nullptr;
 }
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index e175216a26c3..ad5c735f696a 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -458,7 +458,7 @@ void ScDocument::FillInfo(
                     pInfo->maLinesAttr = SfxPoolItemHolder(*pPool, 
pLinesAttr.get());
                 }
 
-                const SfxItemSet* pPoolItem = 
pTableStyle->GetTableCellItemSet(*pDBData, nCol, nRow, nRowIndex);
+                const SfxItemSet* pPoolItem = 
pTableStyle->GetFontItemSet(*pDBData, nCol, nRow, nRowIndex);
                 if (pPoolItem)
                 {
                     pInfo->pTableFormatSet = pPoolItem;
diff --git a/sc/source/core/data/tablestyle.cxx 
b/sc/source/core/data/tablestyle.cxx
index d7d3ff02a330..9d930e888e90 100644
--- a/sc/source/core/data/tablestyle.cxx
+++ b/sc/source/core/data/tablestyle.cxx
@@ -20,8 +20,23 @@ ScTableStyle::ScTableStyle(const OUString& rName, const 
std::optional<OUString>&
 {
 }
 
-const SfxItemSet* ScTableStyle::GetTableCellItemSet(const ScDBData& rDBData, 
SCCOL nCol, SCROW nRow,
-                                                    SCROW nRowIndex) const
+bool ScTableStyle::HasFontAttrSet(ScPatternAttr* pPattern)
+{
+    // TODO: maybe different pPatterns can have different font attributes, and
+    // now we only check if any font attribute is set on a pattern.
+    // e.g.: mpFirstRowStripePattern only has ATTR_FONT_WEIGHT set and we will 
retirn that one,
+    // but mpTablePattern also can have ATTR_FONT_COLOR set (need to merge 
them and return that
+    // one for custom styles, but now it is enough for the ooxml default 
styles).
+    for (sal_Int16 nWhich = ATTR_FONT; nWhich <= ATTR_FONT_RELIEF; nWhich++)
+    {
+        if (pPattern->GetItemSet().GetItemState(nWhich) == SfxItemState::SET)
+            return true;
+    }
+    return false;
+}
+
+const SfxItemSet* ScTableStyle::GetFontItemSet(const ScDBData& rDBData, SCCOL 
nCol, SCROW nRow,
+                                               SCROW nRowIndex) const
 {
     const ScTableStyleParam* pParam = rDBData.GetTableStyleInfo();
     ScRange aRange;
@@ -32,33 +47,39 @@ const SfxItemSet* ScTableStyle::GetTableCellItemSet(const 
ScDBData& rDBData, SCC
     if (bHasHeader && mpLastHeaderCellPattern && nRow == aRange.aStart.Row()
         && nCol == aRange.aEnd.Col())
     {
-        return &mpLastHeaderCellPattern->GetItemSet();
+        if (HasFontAttrSet(mpLastHeaderCellPattern.get()))
+            return &mpLastHeaderCellPattern->GetItemSet();
     }
 
     if (bHasHeader && mpFirstHeaderCellPattern && nRow == aRange.aStart.Row()
         && nCol == aRange.aStart.Col())
     {
-        return &mpFirstHeaderCellPattern->GetItemSet();
+        if (HasFontAttrSet(mpFirstHeaderCellPattern.get()))
+            return &mpFirstHeaderCellPattern->GetItemSet();
     }
 
     if (bHasTotal && mpTotalRowPattern && nRow == aRange.aEnd.Row())
     {
-        return &mpTotalRowPattern->GetItemSet();
+        if (HasFontAttrSet(mpTotalRowPattern.get()))
+            return &mpTotalRowPattern->GetItemSet();
     }
 
     if (bHasHeader && mpHeaderRowPattern && nRow == aRange.aStart.Row())
     {
-        return &mpHeaderRowPattern->GetItemSet();
+        if (HasFontAttrSet(mpHeaderRowPattern.get()))
+            return &mpHeaderRowPattern->GetItemSet();
     }
 
     if (pParam->mbFirstColumn && mpFirstColumnPattern && nCol == 
aRange.aStart.Col())
     {
-        return &mpFirstColumnPattern->GetItemSet();
+        if (HasFontAttrSet(mpFirstColumnPattern.get()))
+            return &mpFirstColumnPattern->GetItemSet();
     }
 
     if (pParam->mbLastColumn && mpLastColumnPattern && nCol == 
aRange.aEnd.Col())
     {
-        return &mpLastColumnPattern->GetItemSet();
+        if (HasFontAttrSet(mpLastColumnPattern.get()))
+            return &mpLastColumnPattern->GetItemSet();
     }
 
     if (!bHasTotal || aRange.aEnd.Row() != nRow)
@@ -69,12 +90,14 @@ const SfxItemSet* ScTableStyle::GetTableCellItemSet(const 
ScDBData& rDBData, SCC
             bool bFirstRowStripe = (nRowIndex % nTotalRowStripPattern) < 
mnFirstRowStripeSize;
             if (mpSecondRowStripePattern && !bFirstRowStripe)
             {
-                return &mpSecondRowStripePattern->GetItemSet();
+                if (HasFontAttrSet(mpSecondRowStripePattern.get()))
+                    return &mpSecondRowStripePattern->GetItemSet();
             }
 
             if (mpFirstRowStripePattern && bFirstRowStripe)
             {
-                return &mpFirstRowStripePattern->GetItemSet();
+                if (HasFontAttrSet(mpFirstRowStripePattern.get()))
+                    return &mpFirstRowStripePattern->GetItemSet();
             }
         }
 
@@ -85,19 +108,22 @@ const SfxItemSet* ScTableStyle::GetTableCellItemSet(const 
ScDBData& rDBData, SCC
             bool bFirstColStripe = (nRelativeCol % nTotalColStripePattern) < 
mnFirstColStripeSize;
             if (mpSecondColumnStripePattern && !bFirstColStripe)
             {
-                return &mpSecondColumnStripePattern->GetItemSet();
+                if (HasFontAttrSet(mpSecondColumnStripePattern.get()))
+                    return &mpSecondColumnStripePattern->GetItemSet();
             }
 
             if (mpFirstColumnStripePattern && bFirstColStripe)
             {
-                return &mpFirstColumnStripePattern->GetItemSet();
+                if (HasFontAttrSet(mpFirstColumnStripePattern.get()))
+                    return &mpFirstColumnStripePattern->GetItemSet();
             }
         }
     }
 
     if (mpTablePattern)
     {
-        return &mpTablePattern->GetItemSet();
+        if (HasFontAttrSet(mpTablePattern.get()))
+            return &mpTablePattern->GetItemSet();
     }
 
     return nullptr;
commit 7022766aab8bb17209e1b872edd40e3a0962d64f
Author:     Balazs Varga <[email protected]>
AuthorDate: Sun Nov 9 21:01:02 2025 +0100
Commit:     Balazs Varga <[email protected]>
CommitDate: Thu Jan 29 09:30:11 2026 +0100

    Table style: fix wrong sidebar context after selecting
    
    table style area. After we selected a draw object and then
    we clicked inside a table style area the context was not updated
    and only the cell context UI elements appeared.
    Also need force the update in case of we set the cursor position
    from one table cell area to another one, otherwise the sidebar
    will not update the different Table area properties on the panel.
    
    Change-Id: I70a25e30071779ad4053b967a3fb15ec0328d6cb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193690
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196758
    Reviewed-by: Balazs Varga <[email protected]>
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197984
    Tested-by: Jenkins

diff --git a/sc/source/ui/drawfunc/drawsh2.cxx 
b/sc/source/ui/drawfunc/drawsh2.cxx
index 9e8c009fcf74..cd926e4b1d86 100644
--- a/sc/source/ui/drawfunc/drawsh2.cxx
+++ b/sc/source/ui/drawfunc/drawsh2.cxx
@@ -47,6 +47,7 @@
 #include <gridwin.hxx>
 #include <scmod.hxx>
 #include <appoptio.hxx>
+#include <dbdata.hxx>
 #include <svx/svdoole2.hxx>
 #include <svx/xflgrit.hxx>
 #include <comphelper/lok.hxx>
@@ -574,9 +575,28 @@ void ScDrawShell::Activate (const bool)
 
 const OUString & ScDrawShell::GetSidebarContextName()
 {
-    return vcl::EnumContext::GetContextName(
-        svx::sidebar::SelectionAnalyzer::GetContextForSelection_SC(
-            GetDrawView()->GetMarkedObjectList()));
+    vcl::EnumContext::Context eContext = 
svx::sidebar::SelectionAnalyzer::GetContextForSelection_SC(
+            GetDrawView()->GetMarkedObjectList());
+
+    // If no special context detected, check for table context
+    if (eContext == vcl::EnumContext::Context::Unknown)
+    {
+        ScDocument& rDocument = rViewData.GetDocument();
+        if (!rDocument.HasDataPilotAtPosition(rViewData.GetCurPos()))
+        {
+            const ScAddress aAddr = rViewData.GetCurPos();
+            if (!rDocument.HasSparkline(aAddr))
+            {
+                const ScDBData* pDbData = rDocument.GetDBAtCursor(
+                    aAddr.Col(), aAddr.Row(), aAddr.Tab(), 
ScDBDataPortion::AREA);
+                if (pDbData && pDbData->GetTableStyleInfo())
+                {
+                    eContext = vcl::EnumContext::Context::Table;
+                }
+            }
+        }
+    }
+    return vcl::EnumContext::GetContextName(eContext);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index 8ecdd362a01e..54000d4112f0 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -731,7 +731,7 @@ void ScTabViewShell::SetTableShell(bool bActive)
         bActiveMediaSh=false;
         bActiveOleObjectSh=false;
         bActiveChartSh=false;
-        SetCurSubShell(OST_Table);
+        SetCurSubShell(OST_Table, true);
     }
     else
         SetCurSubShell(OST_Cell);

Reply via email to