sc/source/ui/inc/hdrcont.hxx  |    2 +
 sc/source/ui/view/hdrcont.cxx |   64 +++++++++++++++++++++++++++---------------
 2 files changed, 44 insertions(+), 22 deletions(-)

New commits:
commit b9d3a9b1d62f546dc11b8f3ecb6e23871e261b2d
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Wed Oct 8 15:36:49 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Wed Oct 8 15:39:00 2025 +0200

    sc: reduce the text height if the cell height is smaller
    
    If the cell height gets smaller than the text height when we zoom
    out the sheet, we reduce the font size so it doesn't get clippped
    out and is easier to read.
    
    Change-Id: Ie849d9fecfc6659087b8d5c9dc93be034e104fbb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192064
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/source/ui/inc/hdrcont.hxx b/sc/source/ui/inc/hdrcont.hxx
index 86682f78f2e2..06b7f67678b8 100644
--- a/sc/source/ui/inc/hdrcont.hxx
+++ b/sc/source/ui/inc/hdrcont.hxx
@@ -65,6 +65,8 @@ private:
 
     bool            bInRefMode;
 
+    tools::Long mnDefaultFontHeight = 0L;
+
     tools::Long            GetScrPos( SCCOLROW nEntryNo ) const;
     SCCOLROW        GetMousePos(const Point& rPos, bool& rBorder) const;
     bool            IsSelectionAllowed(SCCOLROW nPos) const;
diff --git a/sc/source/ui/view/hdrcont.cxx b/sc/source/ui/view/hdrcont.cxx
index a281af7ad2a8..e57870510c94 100644
--- a/sc/source/ui/view/hdrcont.cxx
+++ b/sc/source/ui/view/hdrcont.cxx
@@ -86,6 +86,9 @@ ScHeaderControl::ScHeaderControl( vcl::Window* pParent, 
SelectionEngine* pSelect
 
     aNormFont = GetFont();
     aNormFont.SetTransparent( true );       //! hard-set WEIGHT_NORMAL ???
+
+    mnDefaultFontHeight = aNormFont.GetFontHeight();
+
     aBoldFont = aNormFont;
     aBoldFont.SetWeight( WEIGHT_BOLD );
     aAutoFilterFont = aNormFont;
@@ -495,8 +498,9 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                 break;
         }
 
-        SCCOLROW    nCount=0;
-        tools::Long    nScrPos=nInitScrPos;
+        SCCOLROW nCount = 0;
+        tools::Long nScrPos = nInitScrPos;
+        sal_Int32 nFontHeight = 0;
         do
         {
             if (bVertical)
@@ -557,6 +561,17 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                         case HeaderPaintPass::Text:
                             if ( nSizePix > 1 )     // minimal check for small 
columns/rows
                             {
+                                sal_Int32 nCurrentFontHeight = 
std::min(aEndPos.Y() - aScrPos.Y() + 1, mnDefaultFontHeight);
+                                bool bChangedHeight = false;
+                                if (nFontHeight != nCurrentFontHeight)
+                                {
+                                    nFontHeight = nCurrentFontHeight;
+                                    aNormFont.SetFontHeight(nFontHeight);
+                                    aBoldFont.SetFontHeight(nFontHeight);
+                                    aAutoFilterFont.SetFontHeight(nFontHeight);
+                                    bChangedHeight = true;
+                                }
+
                                 if (bVertical)
                                 {
                                     bool bAutoFilterPos = false;
@@ -569,7 +584,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                                         }
                                     }
 
-                                    if (bMark != bBoldSet || bAutoFilterPos != 
bAutoFilterSet)
+                                    if (bMark != bBoldSet || bAutoFilterPos != 
bAutoFilterSet || bChangedHeight)
                                     {
                                         if (bMark)
                                             SetFont(aBoldFont);
@@ -583,7 +598,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                                 }
                                 else
                                 {
-                                    if (bMark != bBoldSet)
+                                    if (bMark != bBoldSet || bChangedHeight)
                                     {
                                         if (bMark)
                                             SetFont(aBoldFont);
commit 15dadea697f9802d14c4fe995e630f0b4917656a
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Wed Oct 8 15:30:30 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Wed Oct 8 15:38:52 2025 +0200

    sc: use enum class for header paint passes instead of defines
    
    And use enumrange to iterate through the enums values.
    I also didn't find any evidence that the values of an enum matters
    (anymore?) so they are not explicitly specified.
    
    Change-Id: I8064bef718f94d4c7efe15234eb23f0cd8130d1d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192063
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/sc/source/ui/view/hdrcont.cxx b/sc/source/ui/view/hdrcont.cxx
index bd3bd37aef5e..a281af7ad2a8 100644
--- a/sc/source/ui/view/hdrcont.cxx
+++ b/sc/source/ui/view/hdrcont.cxx
@@ -36,6 +36,7 @@
 #include <viewdata.hxx>
 #include <columnspanset.hxx>
 #include <officecfg/Office/Common.hxx>
+#include <o3tl/enumrange.hxx>
 
 #define SC_DRAG_MIN     2
 
@@ -43,10 +44,18 @@
 //  (selection left/right must be first because the continuous lines
 //  are partly overwritten later)
 
-#define SC_HDRPAINT_SEL_BOTTOM  4
-#define SC_HDRPAINT_BOTTOM      5
-#define SC_HDRPAINT_TEXT        6
-#define SC_HDRPAINT_COUNT       7
+namespace
+{
+
+enum class HeaderPaintPass
+{
+    SelectionBottom,
+    Bottom,
+    Text,
+    LAST = Text
+};
+
+}
 
 ScHeaderControl::ScHeaderControl( vcl::Window* pParent, SelectionEngine* 
pSelectionEngine,
                                   SCCOLROW nNewSize, bool bNewVertical, 
ScTabView* pTab ) :
@@ -450,23 +459,19 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
 
     ScGridMerger aGrid( GetOutDev(), 1, 1 );
 
-    //  start at SC_HDRPAINT_BOTTOM instead of 0 - selection doesn't get 
different
-    //  borders, light border at top isn't used anymore
-    //  use SC_HDRPAINT_SEL_BOTTOM for different color
-
-    for (sal_uInt16 nPass = SC_HDRPAINT_SEL_BOTTOM; nPass < SC_HDRPAINT_COUNT; 
nPass++)
+    for (HeaderPaintPass ePass : o3tl::enumrange<HeaderPaintPass>())
     {
         //  set line color etc. before entry loop
-        switch ( nPass )
+        switch (ePass)
         {
-            case SC_HDRPAINT_SEL_BOTTOM:
+            case HeaderPaintPass::SelectionBottom:
                 // same as non-selected for high contrast
                 GetOutDev()->SetLineColor( bHighContrast ? 
rStyleSettings.GetShadowColor() : aSelLineColor );
                 break;
-            case SC_HDRPAINT_BOTTOM:
+            case HeaderPaintPass::Bottom:
                 GetOutDev()->SetLineColor( rStyleSettings.GetShadowColor() );
                 break;
-            case SC_HDRPAINT_TEXT:
+            case HeaderPaintPass::Text:
                 // DrawSelectionBackground is used only for high contrast on 
light background
                 if ( nTransEnd * nLayoutSign >= nTransStart * nLayoutSign && 
bHighContrast && !bDark )
                 {
@@ -523,11 +528,11 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                     bool bMark = bMarkRange && nEntryNo >= nMarkStart && 
nEntryNo <= nMarkEnd;
                     bool bNextToMark = bMarkRange && nEntryNo + 1 >= 
nMarkStart && nEntryNo <= nMarkEnd;
 
-                    switch ( nPass )
+                    switch (ePass)
                     {
-                        case SC_HDRPAINT_SEL_BOTTOM:
-                        case SC_HDRPAINT_BOTTOM:
-                            if ( nPass == ( bNextToMark ? 
SC_HDRPAINT_SEL_BOTTOM : SC_HDRPAINT_BOTTOM ) )
+                        case HeaderPaintPass::SelectionBottom:
+                        case HeaderPaintPass::Bottom:
+                            if (ePass == (bNextToMark ? 
HeaderPaintPass::SelectionBottom : HeaderPaintPass::Bottom))
                             {
                                 if (bVertical)
                                     aGrid.AddHorLine(/* here we work in pixels 
*/ true, aScrPos.X(), aEndPos.X(), aEndPos.Y());
@@ -549,7 +554,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                             }
                             break;
 
-                        case SC_HDRPAINT_TEXT:
+                        case HeaderPaintPass::Text:
                             if ( nSizePix > 1 )     // minimal check for small 
columns/rows
                             {
                                 if (bVertical)

Reply via email to