diff --git a/include/wx/generic/gridsel.h b/include/wx/generic/gridsel.h index 4c64c57531..04399e4cd4 100644 --- a/include/wx/generic/gridsel.h +++ b/include/wx/generic/gridsel.h @@ -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); }; diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 2c51a9d12a..8d6c29aeae 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -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; diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index 0405e9d041..39323a5ea8 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -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(),