Split wxGrid RANGE_SELECT event into SELECTING and SELECTED
This will allow the applications that are only interested in the final selection to ignore the intermediate SELECTING events, which are now sent as soon as the selection changes while dragging the mouse, and only handle the final SELECTED ones, when the drag is over.
This commit is contained in:
committed by
Vadim Zeitlin
parent
5192feb38e
commit
415f080c80
@@ -147,7 +147,8 @@ wxDEFINE_EVENT( wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_COL_AUTO_SIZE, wxGridSizeEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_COL_MOVE, wxGridEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_COL_SORT, wxGridEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_RANGE_SELECTING, wxGridRangeSelectEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_RANGE_SELECTED, wxGridRangeSelectEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_CELL_CHANGING, wxGridEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_CELL_CHANGED, wxGridEvent );
|
||||
wxDEFINE_EVENT( wxEVT_GRID_SELECT_CELL, wxGridEvent );
|
||||
@@ -4383,6 +4384,8 @@ void wxGrid::DoAfterDraggingEnd()
|
||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
||||
m_winCapture->SetCursor( *wxSTANDARD_CURSOR );
|
||||
m_winCapture = NULL;
|
||||
|
||||
m_selection->EndSelecting();
|
||||
}
|
||||
|
||||
void wxGrid::EndDraggingIfNecessary()
|
||||
@@ -4510,7 +4513,13 @@ wxGrid::DoGridCellDrag(wxMouseEvent& event,
|
||||
// Ctrl later can't change the dragging behaviour. Only the initial state
|
||||
// of the modifier keys matters.
|
||||
if ( m_selection )
|
||||
{
|
||||
if (isFirstDrag)
|
||||
{
|
||||
m_selection->StartSelecting();
|
||||
}
|
||||
m_selection->ExtendCurrentBlock(m_currentCellCoords, coords, event);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -4814,6 +4823,7 @@ void wxGrid::ProcessGridCellMouseEvent(wxMouseEvent& event, wxGridWindow *eventG
|
||||
m_winCapture->CaptureMouse();
|
||||
|
||||
m_isDragging = true;
|
||||
m_selection->StartSelecting();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -48,6 +48,7 @@ wxGridSelection::wxGridSelection( wxGrid * grid,
|
||||
{
|
||||
m_grid = grid;
|
||||
m_selectionMode = sel;
|
||||
m_isSelecting = false;
|
||||
}
|
||||
|
||||
bool wxGridSelection::IsSelection()
|
||||
@@ -55,6 +56,47 @@ 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())
|
||||
{
|
||||
size_t n;
|
||||
wxRect r;
|
||||
wxGridCellCoords coords1, coords2;
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool wxGridSelection::IsInSelection( int row, int col ) const
|
||||
{
|
||||
// Check whether the given cell is contained in one of the selected blocks.
|
||||
@@ -344,7 +386,7 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
|
||||
if ( sendEvent )
|
||||
{
|
||||
wxGridRangeSelectEvent gridEvt(m_grid->GetId(),
|
||||
wxEVT_GRID_RANGE_SELECT,
|
||||
m_isSelecting ? wxEVT_GRID_RANGE_SELECTING : wxEVT_GRID_RANGE_SELECTED,
|
||||
m_grid,
|
||||
refBlock.GetTopLeft(),
|
||||
refBlock.GetBottomRight(),
|
||||
@@ -383,7 +425,7 @@ void wxGridSelection::ClearSelection()
|
||||
// (No finer grained events for each of the smaller regions
|
||||
// deselected above!)
|
||||
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
|
||||
wxEVT_GRID_RANGE_SELECT,
|
||||
m_isSelecting ? wxEVT_GRID_RANGE_SELECTING : wxEVT_GRID_RANGE_SELECTED,
|
||||
m_grid,
|
||||
wxGridCellCoords( 0, 0 ),
|
||||
wxGridCellCoords(
|
||||
@@ -641,7 +683,7 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart,
|
||||
|
||||
// Send Event.
|
||||
wxGridRangeSelectEvent gridEvt(m_grid->GetId(),
|
||||
wxEVT_GRID_RANGE_SELECT,
|
||||
m_isSelecting ? wxEVT_GRID_RANGE_SELECTING : wxEVT_GRID_RANGE_SELECTED,
|
||||
m_grid,
|
||||
newBlock.GetTopLeft(),
|
||||
newBlock.GetBottomRight(),
|
||||
@@ -814,7 +856,7 @@ wxGridSelection::Select(const wxGridBlockCoords& block,
|
||||
if ( sendEvent )
|
||||
{
|
||||
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
|
||||
wxEVT_GRID_RANGE_SELECT,
|
||||
m_isSelecting ? wxEVT_GRID_RANGE_SELECTING : wxEVT_GRID_RANGE_SELECTED,
|
||||
m_grid,
|
||||
block.GetTopLeft(),
|
||||
block.GetBottomRight(),
|
||||
|
||||
Reference in New Issue
Block a user