From d8c3c53f057d8280a797d7a73b7311fc0a12f148 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Wed, 18 Sep 2019 04:19:25 +0700 Subject: [PATCH 1/3] Make wxRendererMSW::GetHeaderButtonMargin() more accurate Follow Wine in using 3*SM_CXEDGE as margins on each side. This also has the advantage of working better in high DPI, as we don't hardcode the value in pixels any longer. --- src/msw/renderer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 2b1a5470af..9372afbd29 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -590,9 +590,10 @@ int wxRendererMSW::GetHeaderButtonHeight(wxWindow * win) return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT; } -int wxRendererMSW::GetHeaderButtonMargin(wxWindow *WXUNUSED(win)) +int wxRendererMSW::GetHeaderButtonMargin(wxWindow *win) { - return 10; + // The native control seems to use 3*SM_CXEDGE margins on each size. + return 6*wxGetSystemMetrics(SM_CXEDGE, win); } // ============================================================================ From 0766283b2ea1bbc259c0412e28574c0b714284f1 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Wed, 18 Sep 2019 01:20:53 +0200 Subject: [PATCH 2/3] Add wxHeaderCtrl::GetColumnTitleWidth() overload taking index This makes it possible to get the appropriate column width from outside the class, as GetColumn() itself is currently protected and so the existing overload couldn't easily used. --- include/wx/headerctrl.h | 6 ++++++ interface/wx/headerctrl.h | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/wx/headerctrl.h b/include/wx/headerctrl.h index f2270bf78e..8d677eec67 100644 --- a/include/wx/headerctrl.h +++ b/include/wx/headerctrl.h @@ -159,6 +159,12 @@ public: // compute column title width int GetColumnTitleWidth(const wxHeaderColumn& col); + // compute column title width for the column with the given index + int GetColumnTitleWidth(unsigned int idx) + { + return GetColumnTitleWidth(GetColumn(idx)); + } + // implementation only from now on // ------------------------------- diff --git a/interface/wx/headerctrl.h b/interface/wx/headerctrl.h index d8045cf6de..3980a9a01e 100644 --- a/interface/wx/headerctrl.h +++ b/interface/wx/headerctrl.h @@ -404,6 +404,16 @@ public: */ int GetColumnTitleWidth(const wxHeaderColumn& col); + /** + Returns width needed for the column with the given index. + + This is just a convenient wrapper for the overload taking + wxHeaderColumn. + + @since 3.1.3 + */ + int GetColumnTitleWidth(unsigned int idx); + protected: /** Method to be implemented by the derived classes to return the From 3c72396a3670326e6824d1605954920b351a76d2 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Wed, 18 Sep 2019 04:19:25 +0700 Subject: [PATCH 3/3] Fix auto-sizing column labels when using native header in wxGrid Use wxHeaderCtrl-specific GetColumnTitleWidth() function to account for the native header control margins, otherwise the computed width could be insufficient for short columns, resulting in their ellipsization. --- src/generic/grid.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 77700ba016..e25a2ea050 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -9384,13 +9384,30 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction) if ( column ) { - dc.GetMultiLineTextExtent( GetColLabelValue(colOrRow), &w, &h ); - if ( GetColLabelTextOrientation() == wxVERTICAL ) - w = h; + if ( m_useNativeHeader ) + { + w = GetGridColHeader()->GetColumnTitleWidth(colOrRow); + h = 0; + } + else + { + dc.GetMultiLineTextExtent( GetColLabelValue(colOrRow), &w, &h ); + if ( GetColLabelTextOrientation() == wxVERTICAL ) + w = h; + + // leave some space around text + if ( w ) + w += 10; + } } else + { dc.GetMultiLineTextExtent( GetRowLabelValue(colOrRow), &w, &h ); + if ( h ) + h += 6; + } + extent = column ? w : h; if ( extent > extentMax ) extentMax = extent; @@ -9401,14 +9418,6 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction) // than default extent but != 0, it's OK) extentMax = column ? m_defaultColWidth : m_defaultRowHeight; } - else - { - if ( column ) - // leave some space around text - extentMax += 10; - else - extentMax += 6; - } if ( column ) {