Remove the selecting mode flag from wxGridSelection

Remove m_isSelecting and StartSelecting() from wxGridSelection to avoid
inconsistency of wxGridSelection selecting mode state with wxGrid state,
as wxGrid already has m_isDragging field which tells it if the selection
state is final or not.

Instead, just allow wxGrid to specify the event to send from
ExtendCurrentBlock().

We still need a separate EndSelecting() for sending the final
wxEVT_GRID_RANGE_SELECTED event, but send it only for the last selection
block, and not all the selected blocks, as this makes more sense (there
should be one SELECTED event for each block and it was already sent for
the other blocks before) and is consistent with the events generated
when performing the same actions from keyboard.
This commit is contained in:
Ilya Sinitsyn
2020-08-18 00:30:00 +07:00
committed by Vadim Zeitlin
parent decc255846
commit 0a2c62fc5c
3 changed files with 34 additions and 52 deletions

View File

@@ -48,7 +48,6 @@ wxGridSelection::wxGridSelection( wxGrid * grid,
{
m_grid = grid;
m_selectionMode = sel;
m_isSelecting = false;
}
bool wxGridSelection::IsSelection()
@@ -56,46 +55,26 @@ bool wxGridSelection::IsSelection()
return !m_selection.empty();
}
void wxGridSelection::StartSelecting()
{
m_isSelecting = true;
}
void wxGridSelection::EndSelecting()
{
m_isSelecting = false;
//send the RANGE_SELECTED events
if (IsSelection())
{
wxRect r;
wxGridCellCoords coords1, coords2;
// It's possible that nothing was selected finally, e.g. the mouse could
// have been dragged around only to return to the starting cell, just don't
// do anything in this case.
if ( !IsSelection() )
return;
// Send selection events for all the selected blocks.
const size_t count = m_selection.size();
for ( size_t n = 0; n < count; n++ )
{
const wxGridBlockCoords& block = m_selection[n];
coords1 = block.GetTopLeft();
coords2 = block.GetBottomRight();
if ( !m_grid->GetBatchCount() )
{
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_RANGE_SELECTED,
m_grid,
coords1,
coords2,
true );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
}
}
}
else
{
ClearSelection();
}
// Send RANGE_SELECTED event for the last modified block.
const wxGridBlockCoords& block = m_selection.back();
wxGridRangeSelectEvent gridEvt(m_grid->GetId(),
wxEVT_GRID_RANGE_SELECTED,
m_grid,
block.GetTopLeft(),
block.GetBottomRight(),
true);
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
}
bool wxGridSelection::IsInSelection( int row, int col ) const
{
// Check whether the given cell is contained in one of the selected blocks.
@@ -385,7 +364,7 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
if ( sendEvent )
{
wxGridRangeSelectEvent gridEvt(m_grid->GetId(),
m_isSelecting ? wxEVT_GRID_RANGE_SELECTING : wxEVT_GRID_RANGE_SELECTED,
wxEVT_GRID_RANGE_SELECTED,
m_grid,
refBlock.GetTopLeft(),
refBlock.GetBottomRight(),
@@ -424,7 +403,7 @@ void wxGridSelection::ClearSelection()
// (No finer grained events for each of the smaller regions
// deselected above!)
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
m_isSelecting ? wxEVT_GRID_RANGE_SELECTING : wxEVT_GRID_RANGE_SELECTED,
wxEVT_GRID_RANGE_SELECTED,
m_grid,
wxGridCellCoords( 0, 0 ),
wxGridCellCoords(
@@ -535,7 +514,8 @@ void wxGridSelection::UpdateCols( size_t pos, int numCols )
bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart,
const wxGridCellCoords& blockEnd,
const wxKeyboardState& kbd)
const wxKeyboardState& kbd,
wxEventType eventType)
{
wxASSERT( blockStart.GetRow() != -1 && blockStart.GetCol() != -1 &&
blockEnd.GetRow() != -1 && blockEnd.GetCol() != -1 );
@@ -682,7 +662,7 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart,
// Send Event.
wxGridRangeSelectEvent gridEvt(m_grid->GetId(),
m_isSelecting ? wxEVT_GRID_RANGE_SELECTING : wxEVT_GRID_RANGE_SELECTED,
eventType,
m_grid,
newBlock.GetTopLeft(),
newBlock.GetBottomRight(),
@@ -855,7 +835,7 @@ wxGridSelection::Select(const wxGridBlockCoords& block,
if ( sendEvent )
{
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
m_isSelecting ? wxEVT_GRID_RANGE_SELECTING : wxEVT_GRID_RANGE_SELECTED,
wxEVT_GRID_RANGE_SELECTED,
m_grid,
block.GetTopLeft(),
block.GetBottomRight(),