diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 935180d8cf..dbe3222ea9 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -3406,7 +3406,8 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGri wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_COL_SIZE, wxGridSizeEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_COL_AUTO_SIZE, wxGridSizeEvent ); -wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_RANGE_SELECTING, wxGridRangeSelectEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_RANGE_SELECTED, wxGridRangeSelectEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_CHANGING, wxGridEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_CHANGED, wxGridEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_SELECT_CELL, wxGridEvent ); @@ -3460,7 +3461,8 @@ typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreat #define EVT_GRID_CMD_COL_AUTO_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_AUTO_SIZE, id, fn) #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn) #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn) -#define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn) +#define EVT_GRID_CMD_RANGE_SELECTING(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECTING, id, fn) +#define EVT_GRID_CMD_RANGE_SELECTED(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECTED, id, fn) #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn) #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn) #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn) @@ -3485,7 +3487,8 @@ typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreat #define EVT_GRID_COL_AUTO_SIZE(fn) EVT_GRID_CMD_COL_AUTO_SIZE(wxID_ANY, fn) #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn) #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn) -#define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn) +#define EVT_GRID_RANGE_SELECTING(fn) EVT_GRID_CMD_RANGE_SELECTING(wxID_ANY, fn) +#define EVT_GRID_RANGE_SELECTED(fn) EVT_GRID_CMD_RANGE_SELECTED(wxID_ANY, fn) #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn) #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn) #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn) @@ -3506,6 +3509,15 @@ typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreat #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED #endif // WXWIN_COMPATIBILITY_2_8 +// same as above: RANGE_SELECT was split in RANGE_SELECTING and SELECTED in 3.2, +// but we keep the old name for compatibility +#if WXWIN_COMPATIBILITY_3_0 + #define wxEVT_GRID_RANGE_SELECT wxEVT_GRID_RANGE_SELECTED + + #define EVT_GRID_RANGE_SELECT EVT_GRID_RANGE_SELECTED +#endif // WXWIN_COMPATIBILITY_3_0 + + #if 0 // TODO: implement these ? others ? extern const int wxEVT_GRID_CREATE_CELL; diff --git a/include/wx/generic/gridsel.h b/include/wx/generic/gridsel.h index 08377e3b08..4c64c57531 100644 --- a/include/wx/generic/gridsel.h +++ b/include/wx/generic/gridsel.h @@ -103,6 +103,9 @@ public: wxVectorGridBlockCoords& GetBlocks() { return m_selection; } + + void StartSelecting(); + void EndSelecting(); private: void SelectBlockNoEvent(const wxGridBlockCoords& block) { @@ -138,6 +141,7 @@ private: wxGrid *m_grid; wxGrid::wxGridSelectionModes m_selectionMode; + bool m_isSelecting; wxDECLARE_NO_COPY_CLASS(wxGridSelection); }; diff --git a/interface/wx/grid.h b/interface/wx/grid.h index bd11205d7d..d1c2ede0ed 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -6346,12 +6346,19 @@ public: @class wxGridRangeSelectEvent @beginEventTable{wxGridRangeSelectEvent} - @event{EVT_GRID_RANGE_SELECT(func)} + @event{EVT_GRID_RANGE_SELECTING(func)} + The user is selecting a group of contiguous cells. Processes a + @c wxEVT_GRID_RANGE_SELECTING event type. + This event is available in wxWidgets 3.1.5 and later only. + @event{EVT_GRID_CMD_RANGE_SELECTING(id, func)} + The user is selecting a group of contiguous cells; variant taking a window + identifier. Processes a @c wxEVT_GRID_RANGE_SELECTING event type. + @event{EVT_GRID_RANGE_SELECTED(func)} The user selected a group of contiguous cells. Processes a - @c wxEVT_GRID_RANGE_SELECT event type. - @event{EVT_GRID_CMD_RANGE_SELECT(id, func)} + @c wxEVT_GRID_RANGE_SELECTED event type. + @event{EVT_GRID_CMD_RANGE_SELECTED(id, func)} The user selected a group of contiguous cells; variant taking a window - identifier. Processes a @c wxEVT_GRID_RANGE_SELECT event type. + identifier. Processes a @c wxEVT_GRID_RANGE_SELECTED event type. @endEventTable @library{wxcore} @@ -6526,7 +6533,8 @@ wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK; wxEventType wxEVT_GRID_ROW_SIZE; wxEventType wxEVT_GRID_COL_SIZE; wxEventType wxEVT_GRID_COL_AUTO_SIZE; -wxEventType wxEVT_GRID_RANGE_SELECT; +wxEventType wxEVT_GRID_RANGE_SELECTING; +wxEventType wxEVT_GRID_RANGE_SELECTED; wxEventType wxEVT_GRID_CELL_CHANGING; wxEventType wxEVT_GRID_CELL_CHANGED; wxEventType wxEVT_GRID_SELECT_CELL; @@ -6537,4 +6545,3 @@ wxEventType wxEVT_GRID_CELL_BEGIN_DRAG; wxEventType wxEVT_GRID_COL_MOVE; wxEventType wxEVT_GRID_COL_SORT; wxEventType wxEVT_GRID_TABBING; - diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 6bdad3143c..2c51a9d12a 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -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; diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index eb5b9b3139..a31a01a90b 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -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(),