From 2290d974536c35fd53ef8f372aed8800deb2292f Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Wed, 28 Aug 2019 06:30:50 +0700 Subject: [PATCH] Fix dragging grid columns when using scrolled native header Drag-resizing the columns didn't work correctly when using the native header and scrolling it horizontally, as the wrong offset was used in this case. Fix the offset in wxGrid code and add a unit test checking that this works as intended (at least under MSW, as wxUIActionSimulator just doesn't work reliably enough to test for this under the other platforms, and, besides, only MSW has the native header control implementation anyhow). --- src/generic/grid.cpp | 1 + tests/controls/gridtest.cpp | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 520f9e2b66..b7f7f387d6 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3687,6 +3687,7 @@ void wxGrid::DoUpdateResizeColWidth(int w) { wxPoint pt(GetColLeft(m_dragRowOrCol) + w, 0); + pt = CalcGridWindowScrolledPosition(pt, m_gridWin); DrawGridDragLine(pt, wxGridColumnOperations(), m_gridWin); } diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 4aae8ae871..a74ceecef5 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -66,10 +66,12 @@ private: CPPUNIT_TEST( CellFormatting ); WXUISIM_TEST( Editable ); WXUISIM_TEST( ReadOnly ); + WXUISIM_TEST( ResizeScrolledHeader ); CPPUNIT_TEST( PseudoTest_NativeHeader ); NONGTK_TEST( LabelClick ); NONGTK_TEST( SortClick ); CPPUNIT_TEST( ColumnOrder ); + WXUISIM_TEST( ResizeScrolledHeader ); CPPUNIT_TEST( PseudoTest_NativeLabels ); NONGTK_TEST( LabelClick ); NONGTK_TEST( SortClick ); @@ -97,6 +99,7 @@ private: void Editable(); void ReadOnly(); void WindowAsEditorControl(); + void ResizeScrolledHeader(); void PseudoTest_NativeHeader() { ms_nativeheader = true; } void PseudoTest_NativeLabels() { ms_nativeheader = false; ms_nativelabels = true; } @@ -806,4 +809,43 @@ void GridTestCase::WindowAsEditorControl() #endif } +void GridTestCase::ResizeScrolledHeader() +{ + // TODO this test currently works only under Windows unfortunately +#if wxUSE_UIACTIONSIMULATOR && defined(__WXMSW__) + int const startwidth = m_grid->GetColSize(0); + int const draglength = 100; + + m_grid->AppendCols(8); + m_grid->Scroll(5, 0); + m_grid->Refresh(); + m_grid->Update(); + + wxRect rect = m_grid->CellToRect(0, 1); + wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition()); + point = m_grid->ClientToScreen(point + + wxPoint(m_grid->GetRowLabelSize(), + m_grid->GetColLabelSize()) + - wxPoint(0, 5)); + + wxUIActionSimulator sim; + + wxYield(); + sim.MouseMove(point); + + wxYield(); + sim.MouseDown(); + + wxYield(); + sim.MouseMove(point + wxPoint(draglength, 0)); + + wxYield(); + sim.MouseUp(); + + wxYield(); + + CPPUNIT_ASSERT_EQUAL(startwidth + draglength, m_grid->GetColSize(0)); +#endif +} + #endif //wxUSE_GRID