Make wxGrid row selecting more user friendly

This commit is contained in:
Ilya Sinitsyn
2020-03-04 23:18:45 +07:00
committed by Vadim Zeitlin
parent 89dd47edee
commit 0920a1646b
3 changed files with 70 additions and 7 deletions

View File

@@ -1468,7 +1468,8 @@ public:
// Returns the topmost row of the current visible area. // Returns the topmost row of the current visible area.
int GetFirstFullyVisibleRow() const; int GetFirstFullyVisibleRow() const;
// Returns the leftmost column of the current visible area.
int GetFirstFullyVisibleColumn() const;
// ------ grid cursor movement functions // ------ grid cursor movement functions
// //

View File

@@ -4835,6 +4835,11 @@ public:
Returns -1 if the grid doesn't have any rows. Returns -1 if the grid doesn't have any rows.
*/ */
int GetFirstFullyVisibleRow() const; int GetFirstFullyVisibleRow() const;
/**
Returns the leftmost column of the current visible area.
Returns -1 if the grid doesn't have any columns.
*/
int GetFirstFullyVisibleColumn() const;
/** /**
Sets the number of pixels per horizontal scroll increment. Sets the number of pixels per horizontal scroll increment.

View File

@@ -3691,10 +3691,15 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo
case WXGRID_CURSOR_SELECT_ROW: case WXGRID_CURSOR_SELECT_ROW:
{ {
if ( !m_selection || m_numRows == 0 || m_numCols == 0 )
break;
if ( (row = YToRow( pos.y )) >= 0 ) if ( (row = YToRow( pos.y )) >= 0 )
{ {
if ( m_selection ) m_selection->ExtendOrCreateCurrentBlock(
m_selection->SelectRow(row, event); wxGridCellCoords(m_currentCellCoords.GetRow(), 0),
wxGridCellCoords(row, GetNumberCols() - 1),
event);
} }
} }
break; break;
@@ -3736,12 +3741,14 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo
if ( row >= 0 && if ( row >= 0 &&
!SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) ) !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
{ {
if ( !event.ShiftDown() && !event.CmdDown() ) if ( m_selection && m_numRows > 0 && m_numCols > 0 )
ClearSelection();
if ( m_selection )
{ {
if ( event.ShiftDown() ) bool selectNewRow = false;
if ( event.ShiftDown() && !event.CmdDown() )
{ {
// Continue editing the current selection and don't
// move the grid cursor.
m_selection->ExtendOrCreateCurrentBlock m_selection->ExtendOrCreateCurrentBlock
( (
wxGridCellCoords(m_currentCellCoords.GetRow(), 0), wxGridCellCoords(m_currentCellCoords.GetRow(), 0),
@@ -3750,9 +3757,25 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo
); );
MakeCellVisible(row, -1); MakeCellVisible(row, -1);
} }
else if ( event.CmdDown() && !event.ShiftDown() )
{
if ( GetSelectedRows().Index(row) != wxNOT_FOUND )
DeselectRow(row);
else
selectNewRow = true;
}
else else
{ {
ClearSelection();
selectNewRow = true;
}
if ( selectNewRow )
{
// Select the new row.
m_selection->SelectRow(row, event); m_selection->SelectRow(row, event);
SetCurrentCell(row, GetFirstFullyVisibleColumn());
} }
} }
@@ -7853,6 +7876,40 @@ int wxGrid::GetFirstFullyVisibleRow() const
return row; return row;
} }
int wxGrid::GetFirstFullyVisibleColumn() const
{
if ( m_numCols == 0 )
return -1;
int col;
if ( GetNumberFrozenCols() > 0 )
{
col = 0;
}
else
{
int x;
CalcGridWindowUnscrolledPosition(0, 0,
&x, NULL,
m_gridWin);
col = XToCol(x, true, m_gridWin);
// If the column is not fully visible.
if ( GetColLeft(col) < x )
{
// Use the next visible column.
for ( ; col < m_numCols; ++col )
{
if ( IsColShown(GetColAt(col)) )
break;
}
}
}
return col;
}
// //
// ------ Grid cursor movement functions // ------ Grid cursor movement functions
// //