Make wxGrid column selecting more user friendly

This commit is contained in:
Ilya Sinitsyn
2020-03-04 23:00:10 +07:00
committed by Vadim Zeitlin
parent e1b9ece9a4
commit 89dd47edee
3 changed files with 73 additions and 6 deletions

View File

@@ -1466,6 +1466,9 @@ public:
void MakeCellVisible( const wxGridCellCoords& coords ) void MakeCellVisible( const wxGridCellCoords& coords )
{ MakeCellVisible( coords.GetRow(), coords.GetCol() ); } { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
// Returns the topmost row of the current visible area.
int GetFirstFullyVisibleRow() const;
// ------ grid cursor movement functions // ------ grid cursor movement functions
// //

View File

@@ -4830,6 +4830,12 @@ public:
*/ */
void MakeCellVisible(const wxGridCellCoords& coords); void MakeCellVisible(const wxGridCellCoords& coords);
/**
Returns the topmost row of the current visible area.
Returns -1 if the grid doesn't have any rows.
*/
int GetFirstFullyVisibleRow() const;
/** /**
Sets the number of pixels per horizontal scroll increment. Sets the number of pixels per horizontal scroll increment.

View File

@@ -4001,8 +4001,13 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
{ {
if ( col != -1 ) if ( col != -1 )
{ {
if ( m_selection ) if ( !m_selection || m_numRows == 0 || m_numCols == 0 )
m_selection->SelectCol(col, event); break;
m_selection->ExtendOrCreateCurrentBlock(
wxGridCellCoords(0, m_currentCellCoords.GetCol()),
wxGridCellCoords(GetNumberRows() - 1, col),
event);
} }
} }
break; break;
@@ -4111,12 +4116,14 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
} }
else else
{ {
if ( !event.ShiftDown() && !event.CmdDown() ) if ( m_selection && m_numRows > 0 && m_numCols > 0 )
ClearSelection();
if ( m_selection )
{ {
if ( event.ShiftDown() ) bool selectNewCol = 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(0, m_currentCellCoords.GetCol()), wxGridCellCoords(0, m_currentCellCoords.GetCol()),
@@ -4125,9 +4132,25 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
); );
MakeCellVisible(-1, col); MakeCellVisible(-1, col);
} }
else if ( event.CmdDown() && !event.ShiftDown() )
{
if ( GetSelectedCols().Index(col) != wxNOT_FOUND )
DeselectCol(col);
else
selectNewCol = true;
}
else else
{ {
ClearSelection();
selectNewCol = true;
}
if (selectNewCol)
{
// Select the new column.
m_selection->SelectCol(col, event); m_selection->SelectCol(col, event);
SetCurrentCell(GetFirstFullyVisibleRow(), col);
} }
} }
@@ -7795,6 +7818,41 @@ void wxGrid::MakeCellVisible( int row, int col )
AdjustScrollbars(); AdjustScrollbars();
} }
int wxGrid::GetFirstFullyVisibleRow() const
{
if ( m_numRows == 0 )
return -1;
int row;
if ( GetNumberFrozenRows() > 0 )
{
row = 0;
}
else
{
int y;
CalcGridWindowUnscrolledPosition(0, 0,
NULL, &y,
m_gridWin);
row = YToRow(y, true, m_gridWin);
// If the row is not fully visible (if only 2 pixels is hidden
// the row still looks fully visible).
if ( GetRowTop(row) - 2 < y )
{
// Use the next visible row.
for ( ; row < m_numRows; ++row )
{
if ( IsRowShown(row) )
break;
}
}
}
return row;
}
// //
// ------ Grid cursor movement functions // ------ Grid cursor movement functions
// //