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

@@ -82,10 +82,16 @@ public:
//
// Both components of both blockStart and blockEnd must be valid.
//
// This function sends an event notifying about the selection change using
// the provided event type, which is wxEVT_GRID_RANGE_SELECTED by default,
// but may also be wxEVT_GRID_RANGE_SELECTING, when the selection is not
// final yet.
//
// Return true if the current block was actually changed.
bool ExtendCurrentBlock(const wxGridCellCoords& blockStart,
const wxGridCellCoords& blockEnd,
const wxKeyboardState& kbd);
const wxKeyboardState& kbd,
wxEventType eventType = wxEVT_GRID_RANGE_SELECTED);
// Return the coordinates of the cell from which the selection should
@@ -103,9 +109,8 @@ public:
wxVectorGridBlockCoords& GetBlocks() { return m_selection; }
void StartSelecting();
void EndSelecting();
private:
void SelectBlockNoEvent(const wxGridBlockCoords& block)
{
@@ -141,7 +146,6 @@ private:
wxGrid *m_grid;
wxGrid::wxGridSelectionModes m_selectionMode;
bool m_isSelecting;
wxDECLARE_NO_COPY_CLASS(wxGridSelection);
};

View File

@@ -4384,7 +4384,7 @@ void wxGrid::DoAfterDraggingEnd()
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
m_winCapture->SetCursor( *wxSTANDARD_CURSOR );
m_winCapture = NULL;
m_selection->EndSelecting();
}
@@ -4514,11 +4514,10 @@ wxGrid::DoGridCellDrag(wxMouseEvent& event,
// of the modifier keys matters.
if ( m_selection )
{
if (isFirstDrag)
{
m_selection->StartSelecting();
}
m_selection->ExtendCurrentBlock(m_currentCellCoords, coords, event);
m_selection->ExtendCurrentBlock(m_currentCellCoords,
coords,
event,
wxEVT_GRID_RANGE_SELECTING);
}
return true;
@@ -4823,7 +4822,6 @@ void wxGrid::ProcessGridCellMouseEvent(wxMouseEvent& event, wxGridWindow *eventG
m_winCapture->CaptureMouse();
m_isDragging = true;
m_selection->StartSelecting();
}
return;

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(),