From 6ed0443d2f515587d0c75f2237840c18daf4a18f Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Tue, 1 Oct 2019 12:31:01 +0700 Subject: [PATCH 1/3] Fix wxGrid::SetColSize for the native header In case of the width of -1 for the native header the title width must be calculated by the native header itself. --- src/generic/grid.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 146d13689a..06462eeb2e 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -9128,16 +9128,23 @@ void wxGrid::SetColSize( int col, int width ) // show the column back using its old size. if ( width == -1 && GetColWidth(col) != 0 ) { - long w, h; - wxArrayString lines; - wxClientDC dc(m_colLabelWin); - dc.SetFont(GetLabelFont()); - StringToLines(GetColLabelValue(col), lines); - if ( GetColLabelTextOrientation() == wxHORIZONTAL ) - GetTextBoxSize( dc, lines, &w, &h ); + if ( m_useNativeHeader ) + { + width = GetGridColHeader()->GetColumnTitleWidth(col); + } else - GetTextBoxSize( dc, lines, &h, &w ); - width = w + 6; + { + long w, h; + wxArrayString lines; + wxClientDC dc(m_colLabelWin); + dc.SetFont(GetLabelFont()); + StringToLines(GetColLabelValue(col), lines); + if ( GetColLabelTextOrientation() == wxHORIZONTAL ) + GetTextBoxSize( dc, lines, &w, &h ); + else + GetTextBoxSize( dc, lines, &h, &w ); + width = w + 6; + } // Check that it is not less than the minimal width and do use the // possibly greater than minimal-acceptable-width minimal-width itself From 89713215427da69555327dd48cc6349e76771a8d Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Mon, 30 Sep 2019 23:36:31 +0700 Subject: [PATCH 2/3] Send the autosize column event for grid native header columns Send wxEVT_GRID_COL_AUTO_SIZE on double clicking on a separator line of the grid native header to allow override default behaviour. --- include/wx/generic/grid.h | 2 ++ include/wx/generic/private/grid.h | 6 ++---- src/generic/grid.cpp | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index e9d3d1652d..c16fdec83c 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2404,6 +2404,8 @@ private: wxGridColLabelWindow* colLabelWin); void ProcessCornerLabelMouseEvent(wxMouseEvent& event); + void HandleColumnAutosize(int col, const wxMouseEvent& event); + void DoColHeaderClick(int col); void DoStartResizeCol(int col); diff --git a/include/wx/generic/private/grid.h b/include/wx/generic/private/grid.h index 23177c7b81..a050da3c6f 100644 --- a/include/wx/generic/private/grid.h +++ b/include/wx/generic/private/grid.h @@ -191,11 +191,9 @@ private: } // override to implement column auto sizing - virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle) wxOVERRIDE + virtual bool UpdateColumnWidthToFit(unsigned int idx, int WXUNUSED(widthTitle)) wxOVERRIDE { - // TODO: currently grid doesn't support computing the column best width - // from its contents so we just use the best label width as is - GetOwner()->SetColSize(idx, widthTitle); + GetOwner()->HandleColumnAutosize(idx, GetDummyMouseEvent()); return true; } diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 06462eeb2e..852eabf884 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3874,13 +3874,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo } else { - // adjust column width depending on label text - // - // TODO: generate RESIZING event, see #10754 - if ( !SendGridSizeEvent(wxEVT_GRID_COL_AUTO_SIZE, -1, colEdge, event) ) - AutoSizeColLabelSize( colEdge ); - - SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event); + HandleColumnAutosize(colEdge, event); ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, colLabelWin); m_dragLastPos = -1; @@ -4023,6 +4017,17 @@ void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event ) } } +void wxGrid::HandleColumnAutosize(int col, const wxMouseEvent& event) +{ + // adjust column width depending on label text + // + // TODO: generate RESIZING event, see #10754 + if ( !SendGridSizeEvent(wxEVT_GRID_COL_AUTO_SIZE, -1, col, event) ) + AutoSizeColLabelSize(col); + + SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, col, event); +} + void wxGrid::CancelMouseCapture() { // cancel operation currently in progress, whatever it is From b2194d9ad59a5603a26d9f97820df8bd196d0f97 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Tue, 1 Oct 2019 13:02:00 +0700 Subject: [PATCH 3/3] Fix the native header column minimal width determination wxGrid::AutoSizeColumn can set per column minimal width and this values must be used for native headers columns. --- include/wx/generic/grid.h | 1 + include/wx/generic/private/grid.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index c16fdec83c..6a33df90de 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2282,6 +2282,7 @@ protected: friend class wxGridWindow; friend class wxGridHeaderRenderer; + friend class wxGridHeaderColumn; friend class wxGridHeaderCtrl; private: diff --git a/include/wx/generic/private/grid.h b/include/wx/generic/private/grid.h index a050da3c6f..cd92f64fe5 100644 --- a/include/wx/generic/private/grid.h +++ b/include/wx/generic/private/grid.h @@ -95,7 +95,7 @@ public: virtual wxString GetTitle() const wxOVERRIDE { return m_grid->GetColLabelValue(m_col); } virtual wxBitmap GetBitmap() const wxOVERRIDE { return wxNullBitmap; } virtual int GetWidth() const wxOVERRIDE { return m_grid->GetColSize(m_col); } - virtual int GetMinWidth() const wxOVERRIDE { return m_grid->GetColMinimalAcceptableWidth(); } + virtual int GetMinWidth() const wxOVERRIDE { return m_grid->GetColMinimalWidth(m_col); } virtual wxAlignment GetAlignment() const wxOVERRIDE { int horz,