From 3a78de206a4fd21fecd36626f19003d340d06608 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Fri, 3 May 2019 23:10:16 +0700 Subject: [PATCH 1/2] Fix the issue with a last DVC column width on Mac In Cocoa implementation of `wxDataViewControl`: call `sizeLastColumnToFit` function of `NSTableView` in `OnSize` handler (for any amount of columns, previously this function was called only for a singe colunm DVCs). `sizeLastColumnToFit` resizes the last column so the table view fits exactly within its enclosing clip view. This behavior is equivalent to `gtk` and `MSW` realizations. --- src/osx/cocoa/dataview.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 4b881b6315..ced2cac65b 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2564,8 +2564,7 @@ void wxCocoaDataViewControl::SetRowHeight(const wxDataViewItem& WXUNUSED(item), void wxCocoaDataViewControl::OnSize() { - if ([m_OutlineView numberOfColumns] == 1) - [m_OutlineView sizeLastColumnToFit]; + [m_OutlineView sizeLastColumnToFit]; } // From cc8988e56bab7586221f334228209b7c75404e3d Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Mon, 29 Jul 2019 14:14:52 +0700 Subject: [PATCH 2/2] Test the width of the last DVC column Check that the last column of the table view fits within its enclosing clip view. --- tests/controls/dataviewctrltest.cpp | 78 +++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/controls/dataviewctrltest.cpp b/tests/controls/dataviewctrltest.cpp index 83e712a8f3..d070017c60 100644 --- a/tests/controls/dataviewctrltest.cpp +++ b/tests/controls/dataviewctrltest.cpp @@ -20,6 +20,9 @@ #include "wx/app.h" #include "wx/dataview.h" +#ifdef __WXGTK__ + #include "wx/stopwatch.h" +#endif // __WXGTK__ #include "testableframe.h" #include "asserthelper.h" @@ -67,6 +70,27 @@ public: } }; +class MultiColumnsDataViewCtrlTestCase +{ +public: + MultiColumnsDataViewCtrlTestCase(); + ~MultiColumnsDataViewCtrlTestCase(); + +protected: + // the dataview control itself + wxDataViewListCtrl *m_dvc; + + // constants + const wxSize m_size; + const int m_firstColumnWidth; + + // and the columns + wxDataViewColumn* m_firstColumn; + wxDataViewColumn* m_lastColumn; + + wxDECLARE_NO_COPY_CLASS(MultiColumnsDataViewCtrlTestCase); +}; + // ---------------------------------------------------------------------------- // test initialization // ---------------------------------------------------------------------------- @@ -95,6 +119,29 @@ DataViewCtrlTestCase::~DataViewCtrlTestCase() delete m_dvc; } +MultiColumnsDataViewCtrlTestCase::MultiColumnsDataViewCtrlTestCase() + : m_size(200, 100), + m_firstColumnWidth(50) +{ + m_dvc = new wxDataViewListCtrl(wxTheApp->GetTopWindow(), wxID_ANY); + + m_firstColumn = + m_dvc->AppendTextColumn(wxString(), wxDATAVIEW_CELL_INERT, m_firstColumnWidth); + m_lastColumn = + m_dvc->AppendTextColumn(wxString(), wxDATAVIEW_CELL_INERT); + + // Set size after columns appending to extend size of the last column. + m_dvc->SetSize(m_size); + m_dvc->Layout(); + m_dvc->Refresh(); + m_dvc->Update(); +} + +MultiColumnsDataViewCtrlTestCase::~MultiColumnsDataViewCtrlTestCase() +{ + delete m_dvc; +} + // ---------------------------------------------------------------------------- // the tests themselves // ---------------------------------------------------------------------------- @@ -262,4 +309,35 @@ TEST_CASE_METHOD(SingleSelectDataViewCtrlTestCase, CHECK( rectRoot == wxRect() ); } +TEST_CASE_METHOD(MultiColumnsDataViewCtrlTestCase, + "wxDVC::AppendTextColumn", + "[wxDataViewCtrl][column]") +{ +#ifdef __WXGTK__ + // Wait for the list control to be realized. + wxStopWatch sw; + while ( m_firstColumn->GetWidth() == 0 ) + { + if ( sw.Time() > 500 ) + { + WARN("Timed out waiting for wxDataViewListCtrl to be realized"); + break; + } + wxYield(); + } +#endif + + // Check the width of the first column. + CHECK( m_firstColumn->GetWidth() == m_firstColumnWidth ); + + // Check that the last column was extended to fit client area. + const int lastColumnMaxWidth = + m_dvc->GetClientSize().GetWidth() - m_firstColumnWidth; + // In GTK and under Mac the width of the last column is less then + // a remaining client area. + const int lastColumnMinWidth = lastColumnMaxWidth - 10; + CHECK( m_lastColumn->GetWidth() <= lastColumnMaxWidth ); + CHECK( m_lastColumn->GetWidth() >= lastColumnMinWidth ); +} + #endif //wxUSE_DATAVIEWCTRL