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).
This commit is contained in:
Ilya Sinitsyn 2019-08-28 06:30:50 +07:00 committed by Vadim Zeitlin
parent 560c247feb
commit 2290d97453
2 changed files with 43 additions and 0 deletions

View File

@ -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);
}

View File

@ -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