Merge branch 'grid-selected'
Split the wxGrid RANGE_SELECT event into separate SELECTING and SELECTED events. See https://github.com/wxWidgets/wxWidgets/pull/2028
This commit is contained in:
@@ -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 );
|
||||
@@ -3677,7 +3678,8 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo
|
||||
m_selection->ExtendCurrentBlock(
|
||||
wxGridCellCoords(m_currentCellCoords.GetRow(), 0),
|
||||
wxGridCellCoords(row, GetNumberCols() - 1),
|
||||
event);
|
||||
event,
|
||||
wxEVT_GRID_RANGE_SELECTING);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -3694,9 +3696,6 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo
|
||||
if ( m_isDragging && (event.Entering() || event.Leaving()) )
|
||||
return;
|
||||
|
||||
if (m_isDragging)
|
||||
m_isDragging = false;
|
||||
|
||||
// ------------ Entering or leaving the window
|
||||
//
|
||||
if ( event.Entering() || event.Leaving() )
|
||||
@@ -3810,6 +3809,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo
|
||||
|
||||
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, rowLabelWin);
|
||||
m_dragLastPos = -1;
|
||||
m_isDragging = false;
|
||||
}
|
||||
|
||||
// ------------ Right button down
|
||||
@@ -4020,7 +4020,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
|
||||
m_selection->ExtendCurrentBlock(
|
||||
wxGridCellCoords(0, m_currentCellCoords.GetCol()),
|
||||
wxGridCellCoords(GetNumberRows() - 1, col),
|
||||
event);
|
||||
event,
|
||||
wxEVT_GRID_RANGE_SELECTING);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -4091,9 +4092,6 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
|
||||
if ( m_isDragging && (event.Entering() || event.Leaving()) )
|
||||
return;
|
||||
|
||||
if (m_isDragging)
|
||||
m_isDragging = false;
|
||||
|
||||
// ------------ Entering or leaving the window
|
||||
//
|
||||
if ( event.Entering() || event.Leaving() )
|
||||
@@ -4263,6 +4261,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
|
||||
|
||||
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
|
||||
m_dragLastPos = -1;
|
||||
m_isDragging = false;
|
||||
}
|
||||
|
||||
// ------------ Right button down
|
||||
@@ -4377,6 +4376,14 @@ void wxGrid::CancelMouseCapture()
|
||||
|
||||
void wxGrid::DoAfterDraggingEnd()
|
||||
{
|
||||
if ( m_isDragging &&
|
||||
(m_cursorMode == WXGRID_CURSOR_SELECT_CELL ||
|
||||
m_cursorMode == WXGRID_CURSOR_SELECT_ROW ||
|
||||
m_cursorMode == WXGRID_CURSOR_SELECT_COL) )
|
||||
{
|
||||
m_selection->EndSelecting();
|
||||
}
|
||||
|
||||
m_isDragging = false;
|
||||
m_startDragPos = wxDefaultPosition;
|
||||
|
||||
@@ -4444,19 +4451,24 @@ void wxGrid::ChangeCursorMode(CursorMode mode,
|
||||
break;
|
||||
|
||||
case WXGRID_CURSOR_MOVE_COL:
|
||||
// Currently we don't capture mouse when moving columns, which is
|
||||
// almost certainly wrong.
|
||||
captureMouse = false;
|
||||
win->SetCursor( wxCursor(wxCURSOR_HAND) );
|
||||
break;
|
||||
|
||||
default:
|
||||
case WXGRID_CURSOR_SELECT_CELL:
|
||||
// Mouse is captured in ProcessGridCellMouseEvent() in this mode.
|
||||
captureMouse = false;
|
||||
wxFALLTHROUGH;
|
||||
|
||||
case WXGRID_CURSOR_SELECT_ROW:
|
||||
case WXGRID_CURSOR_SELECT_COL:
|
||||
win->SetCursor( *wxSTANDARD_CURSOR );
|
||||
break;
|
||||
}
|
||||
|
||||
// we need to capture mouse when resizing
|
||||
bool resize = m_cursorMode == WXGRID_CURSOR_RESIZE_ROW ||
|
||||
m_cursorMode == WXGRID_CURSOR_RESIZE_COL;
|
||||
|
||||
if ( captureMouse && resize )
|
||||
if ( captureMouse )
|
||||
{
|
||||
win->CaptureMouse();
|
||||
m_winCapture = win;
|
||||
@@ -4510,7 +4522,12 @@ wxGrid::DoGridCellDrag(wxMouseEvent& event,
|
||||
// Ctrl later can't change the dragging behaviour. Only the initial state
|
||||
// of the modifier keys matters.
|
||||
if ( m_selection )
|
||||
m_selection->ExtendCurrentBlock(m_currentCellCoords, coords, event);
|
||||
{
|
||||
m_selection->ExtendCurrentBlock(m_currentCellCoords,
|
||||
coords,
|
||||
event,
|
||||
wxEVT_GRID_RANGE_SELECTING);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,26 @@ bool wxGridSelection::IsSelection()
|
||||
return !m_selection.empty();
|
||||
}
|
||||
|
||||
void wxGridSelection::EndSelecting()
|
||||
{
|
||||
// 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 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.
|
||||
@@ -162,7 +182,7 @@ void wxGridSelection::SelectCol(int col, const wxKeyboardState& kbd)
|
||||
void wxGridSelection::SelectBlock( int topRow, int leftCol,
|
||||
int bottomRow, int rightCol,
|
||||
const wxKeyboardState& kbd,
|
||||
bool sendEvent )
|
||||
wxEventType eventType )
|
||||
{
|
||||
// Fix the coordinates of the block if needed.
|
||||
int allowed = -1;
|
||||
@@ -204,7 +224,7 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol,
|
||||
return;
|
||||
|
||||
Select(wxGridBlockCoords(topRow, leftCol, bottomRow, rightCol).Canonicalize(),
|
||||
kbd, sendEvent);
|
||||
kbd, eventType);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -227,7 +247,7 @@ wxGridSelection::SelectAll()
|
||||
void
|
||||
wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
|
||||
const wxKeyboardState& kbd,
|
||||
bool sendEvent)
|
||||
wxEventType eventType)
|
||||
{
|
||||
const wxGridBlockCoords canonicalizedBlock = block.Canonicalize();
|
||||
|
||||
@@ -341,10 +361,10 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
|
||||
refBlock.GetBottomRow(), refBlock.GetRightCol());
|
||||
}
|
||||
|
||||
if ( sendEvent )
|
||||
if ( eventType != wxEVT_NULL )
|
||||
{
|
||||
wxGridRangeSelectEvent gridEvt(m_grid->GetId(),
|
||||
wxEVT_GRID_RANGE_SELECT,
|
||||
eventType,
|
||||
m_grid,
|
||||
refBlock.GetTopLeft(),
|
||||
refBlock.GetBottomRight(),
|
||||
@@ -383,7 +403,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,
|
||||
wxEVT_GRID_RANGE_SELECTED,
|
||||
m_grid,
|
||||
wxGridCellCoords( 0, 0 ),
|
||||
wxGridCellCoords(
|
||||
@@ -494,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 );
|
||||
@@ -505,7 +526,7 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart,
|
||||
// block to non-selected current cell.
|
||||
if ( !IsInSelection(m_grid->GetGridCursorCoords()) )
|
||||
{
|
||||
SelectBlock(blockStart, blockEnd);
|
||||
SelectBlock(blockStart, blockEnd, kbd, eventType);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -641,7 +662,7 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart,
|
||||
|
||||
// Send Event.
|
||||
wxGridRangeSelectEvent gridEvt(m_grid->GetId(),
|
||||
wxEVT_GRID_RANGE_SELECT,
|
||||
eventType,
|
||||
m_grid,
|
||||
newBlock.GetTopLeft(),
|
||||
newBlock.GetBottomRight(),
|
||||
@@ -797,7 +818,8 @@ wxArrayInt wxGridSelection::GetColSelection() const
|
||||
|
||||
void
|
||||
wxGridSelection::Select(const wxGridBlockCoords& block,
|
||||
const wxKeyboardState& kbd, bool sendEvent)
|
||||
const wxKeyboardState& kbd,
|
||||
wxEventType eventType)
|
||||
{
|
||||
if (m_grid->GetNumberRows() == 0 || m_grid->GetNumberCols() == 0)
|
||||
return;
|
||||
@@ -811,10 +833,10 @@ wxGridSelection::Select(const wxGridBlockCoords& block,
|
||||
}
|
||||
|
||||
// Send Event, if not disabled.
|
||||
if ( sendEvent )
|
||||
if ( eventType != wxEVT_NULL )
|
||||
{
|
||||
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
|
||||
wxEVT_GRID_RANGE_SELECT,
|
||||
eventType,
|
||||
m_grid,
|
||||
block.GetTopLeft(),
|
||||
block.GetBottomRight(),
|
||||
|
||||
Reference in New Issue
Block a user