From 415f080c80acae4ccd1235bf6df90e440c53a596 Mon Sep 17 00:00:00 2001 From: Daniel Kulp Date: Mon, 27 Jul 2020 12:20:01 -0400 Subject: [PATCH 01/15] 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. --- include/wx/generic/grid.h | 18 ++++++++++--- include/wx/generic/gridsel.h | 4 +++ interface/wx/grid.h | 19 +++++++++----- src/generic/grid.cpp | 12 ++++++++- src/generic/gridsel.cpp | 50 +++++++++++++++++++++++++++++++++--- 5 files changed, 89 insertions(+), 14 deletions(-) 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(), From decc255846916600b6306b5241646663eaee6b68 Mon Sep 17 00:00:00 2001 From: Daniel Kulp Date: Fri, 7 Aug 2020 10:10:41 -0400 Subject: [PATCH 02/15] Update grid sample to show selecting events --- samples/grid/griddemo.cpp | 22 +++++++++++++++++++++- samples/grid/griddemo.h | 1 + src/generic/gridsel.cpp | 1 - 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 142a364f22..45beb7770d 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -366,7 +366,8 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame ) EVT_GRID_COL_SIZE( GridFrame::OnColSize ) EVT_GRID_COL_AUTO_SIZE( GridFrame::OnColAutoSize ) EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell ) - EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected ) + EVT_GRID_RANGE_SELECTING( GridFrame::OnRangeSelecting ) + EVT_GRID_RANGE_SELECTED( GridFrame::OnRangeSelected ) EVT_GRID_CELL_CHANGING( GridFrame::OnCellValueChanging ) EVT_GRID_CELL_CHANGED( GridFrame::OnCellValueChanged ) EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag ) @@ -1656,6 +1657,25 @@ void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) ev.Skip(); } +void GridFrame::OnRangeSelecting( wxGridRangeSelectEvent& ev ) +{ + wxString logBuf; + if ( ev.Selecting() ) + logBuf << "Selecting "; + else + logBuf << "Deselecting "; + logBuf << "cells from row " << ev.GetTopRow() + << " col " << ev.GetLeftCol() + << " to row " << ev.GetBottomRow() + << " col " << ev.GetRightCol() + << " ( ControlDown: "<< (ev.ControlDown() ? 'T':'F') + << ", ShiftDown: "<< (ev.ShiftDown() ? 'T':'F') + << ", AltDown: "<< (ev.AltDown() ? 'T':'F') + << ", MetaDown: "<< (ev.MetaDown() ? 'T':'F') << " )"; + wxLogMessage( "%s", logBuf ); + + ev.Skip(); +} void GridFrame::OnCellValueChanging( wxGridEvent& ev ) { diff --git a/samples/grid/griddemo.h b/samples/grid/griddemo.h index 784e0fca3d..e09b96a05d 100644 --- a/samples/grid/griddemo.h +++ b/samples/grid/griddemo.h @@ -110,6 +110,7 @@ class GridFrame : public wxFrame void OnColAutoSize( wxGridSizeEvent& ); void OnSelectCell( wxGridEvent& ); void OnRangeSelected( wxGridRangeSelectEvent& ); + void OnRangeSelecting( wxGridRangeSelectEvent& ); void OnCellValueChanging( wxGridEvent& ); void OnCellValueChanged( wxGridEvent& ); void OnCellBeginDrag( wxGridEvent& ); diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index a31a01a90b..0405e9d041 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -67,7 +67,6 @@ void wxGridSelection::EndSelecting() //send the RANGE_SELECTED events if (IsSelection()) { - size_t n; wxRect r; wxGridCellCoords coords1, coords2; From 0a2c62fc5cd3d2782fbd139cc6fcf4a6f3e97c03 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Tue, 18 Aug 2020 00:30:00 +0700 Subject: [PATCH 03/15] 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. --- include/wx/generic/gridsel.h | 12 ++++--- src/generic/grid.cpp | 12 +++---- src/generic/gridsel.cpp | 62 ++++++++++++------------------------ 3 files changed, 34 insertions(+), 52 deletions(-) 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(), From 39725cabd4d3c8be9fec601c8d9271380ce6bf97 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Tue, 18 Aug 2020 01:04:29 +0700 Subject: [PATCH 04/15] Fix wxGrid selecting mode ending condition --- src/generic/grid.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 8d6c29aeae..2e8b67cb67 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -4378,14 +4378,20 @@ 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; m_cursorMode = WXGRID_CURSOR_SELECT_CELL; m_winCapture->SetCursor( *wxSTANDARD_CURSOR ); m_winCapture = NULL; - - m_selection->EndSelecting(); } void wxGrid::EndDraggingIfNecessary() From e2f316b19d05ad9c91ce591c0458a741a97def05 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Aug 2020 01:16:45 +0200 Subject: [PATCH 05/15] Mention that wxEVT_GRID_RANGE_SELECT{ED,ING} are new in 3.1.5 Also explained that SELECTED is just the new spelling of SELECT. --- interface/wx/grid.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/wx/grid.h b/interface/wx/grid.h index d1c2ede0ed..971cc52cca 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -6353,12 +6353,17 @@ public: @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. + This event is available in wxWidgets 3.1.5 and later only. @event{EVT_GRID_RANGE_SELECTED(func)} The user selected a group of contiguous cells. Processes a @c wxEVT_GRID_RANGE_SELECTED event type. + This event is available in wxWidgets 3.1.5 and later only and was + called @c wxEVT_GRID_RANGE_SELECT in the previous versions. @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_SELECTED event type. + This event is available in wxWidgets 3.1.5 and later only and was + called @c wxEVT_GRID_RANGE_SELECT in the previous versions. @endEventTable @library{wxcore} From 9e27efb2cb87b727222c0f116b31f751d9841c1a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Aug 2020 01:22:40 +0200 Subject: [PATCH 06/15] Further improve wxEVT_GRID_RANGE_SELECT{ED,ING} documentation Explain when it is preferable to handle events of each kind. --- interface/wx/grid.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 971cc52cca..f24fe4df53 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -6345,6 +6345,22 @@ public: /** @class wxGridRangeSelectEvent + Events of this class notify about a range of cells being selected. + + When the user uses the mouse for selection, one or more @c SELECTING events + are generated first, with @c SELECTED event generated at the end, when + selection is final. This allows the application to handle either the @c + SELECTING events if it needs to update its state in real-time, as the + selection changes, or just the final @c SELECTED event, if updating its + state on every selection change would be too time-consuming. + + Note that if the user performs the selection from keyboard, @c SELECTING + events are not generated at all, so @c SELECTED event still must be + handled. + + Finally, contrary to most of the other events with the name ending in + "ing", @c SELECTING event can @e not be vetoed. + @beginEventTable{wxGridRangeSelectEvent} @event{EVT_GRID_RANGE_SELECTING(func)} The user is selecting a group of contiguous cells. Processes a From 4b918966f600411a750744d293ae1217678fc8a6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Aug 2020 01:27:39 +0200 Subject: [PATCH 07/15] Refactor logging of wxGridRangeSelectEvent in the grid sample Avoid duplicating the complicated logging code twice, when it's exactly the same for both the SELECTED and SELECTING events. Just use a common helper function instead. --- samples/grid/griddemo.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 45beb7770d..46ed8d5e42 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -1638,14 +1638,19 @@ void GridFrame::OnSelectCell( wxGridEvent& ev ) ev.Skip(); } -void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) +namespace +{ + +void +LogRangeSelectEvent(wxGridRangeSelectEvent& ev, const char* suffix) { wxString logBuf; if ( ev.Selecting() ) - logBuf << "Selected "; + logBuf << "Select"; else - logBuf << "Deselected "; - logBuf << "cells from row " << ev.GetTopRow() + logBuf << "Deselect"; + logBuf << suffix + << " cells from row " << ev.GetTopRow() << " col " << ev.GetLeftCol() << " to row " << ev.GetBottomRow() << " col " << ev.GetRightCol() @@ -1657,24 +1662,17 @@ void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) ev.Skip(); } + +} // anonymous namespace + +void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) +{ + LogRangeSelectEvent(ev, "ed"); +} + void GridFrame::OnRangeSelecting( wxGridRangeSelectEvent& ev ) { - wxString logBuf; - if ( ev.Selecting() ) - logBuf << "Selecting "; - else - logBuf << "Deselecting "; - logBuf << "cells from row " << ev.GetTopRow() - << " col " << ev.GetLeftCol() - << " to row " << ev.GetBottomRow() - << " col " << ev.GetRightCol() - << " ( ControlDown: "<< (ev.ControlDown() ? 'T':'F') - << ", ShiftDown: "<< (ev.ShiftDown() ? 'T':'F') - << ", AltDown: "<< (ev.AltDown() ? 'T':'F') - << ", MetaDown: "<< (ev.MetaDown() ? 'T':'F') << " )"; - wxLogMessage( "%s", logBuf ); - - ev.Skip(); + LogRangeSelectEvent(ev, "ing"); } void GridFrame::OnCellValueChanging( wxGridEvent& ev ) From eb60684ac7917af960b0bae21dbd8025ce8d2c57 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 20 Aug 2020 17:06:09 +0200 Subject: [PATCH 08/15] Make log window in the grid sample expand too It is too small to show more than a few lines of logs otherwise. --- samples/grid/griddemo.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 46ed8d5e42..2d8f60bc13 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -766,14 +766,10 @@ GridFrame::GridFrame() grid->Bind(wxEVT_CONTEXT_MENU, &GridFrame::OnGridContextMenu, this, grid->GetId()); wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); - topSizer->Add( grid, - 1, - wxEXPAND ); + topSizer->Add(grid, wxSizerFlags(2).Expand()); #if wxUSE_LOG - topSizer->Add( logWin, - 0, - wxEXPAND ); + topSizer->Add(logWin, wxSizerFlags(1).Expand()); #endif // wxUSE_LOG SetSizerAndFit( topSizer ); From 65c27c6a6e662ccb34ae24c0025aa07cdcff674b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 20 Aug 2020 17:08:40 +0200 Subject: [PATCH 09/15] Rename wxID_ABOUT menu handler in the grid sample Use "On" prefix for it for consistency with all the other ones. No real changes. --- samples/grid/griddemo.cpp | 4 ++-- samples/grid/griddemo.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 2d8f60bc13..9c32964145 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -325,7 +325,7 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame ) EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour ) EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour ) - EVT_MENU( wxID_ABOUT, GridFrame::About ) + EVT_MENU( wxID_ABOUT, GridFrame::OnAbout ) EVT_MENU( wxID_EXIT, GridFrame::OnQuit ) EVT_MENU( ID_VTABLE, GridFrame::OnVTable) EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable) @@ -1747,7 +1747,7 @@ void GridFrame::OnEditorHidden( wxGridEvent& ev ) ev.Skip(); } -void GridFrame::About( wxCommandEvent& WXUNUSED(ev) ) +void GridFrame::OnAbout( wxCommandEvent& WXUNUSED(ev) ) { wxAboutDialogInfo aboutInfo; aboutInfo.SetName("wxGrid demo"); diff --git a/samples/grid/griddemo.h b/samples/grid/griddemo.h index e09b96a05d..f02a32d821 100644 --- a/samples/grid/griddemo.h +++ b/samples/grid/griddemo.h @@ -130,7 +130,7 @@ public: ~GridFrame(); void OnQuit( wxCommandEvent& ); - void About( wxCommandEvent& ); + void OnAbout( wxCommandEvent& ); void OnVTable( wxCommandEvent& ); void OnBugsTable( wxCommandEvent& ); void OnTabularTable( wxCommandEvent& ); From 767f19cf25d5e9dc46ca05ccbc7cf1f850a21241 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 20 Aug 2020 17:11:40 +0200 Subject: [PATCH 10/15] Add menu item to clear log in the grid window Just make it more convenient to read the logs in it. --- samples/grid/griddemo.cpp | 13 +++++++++++++ samples/grid/griddemo.h | 1 + 2 files changed, 14 insertions(+) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 9c32964145..e07c699b42 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -326,6 +326,7 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame ) EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour ) EVT_MENU( wxID_ABOUT, GridFrame::OnAbout ) + EVT_MENU( wxID_CLEAR, GridFrame::OnClear ) EVT_MENU( wxID_EXIT, GridFrame::OnQuit ) EVT_MENU( ID_VTABLE, GridFrame::OnVTable) EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable) @@ -420,6 +421,11 @@ GridFrame::GridFrame() fileMenu->Append( wxID_PRINT, "Render" ); fileMenu->Append( ID_RENDER_COORDS, "Render G5:P30" ); +#if wxUSE_LOG + fileMenu->AppendSeparator(); + fileMenu->Append( wxID_CLEAR, "Clear &log\tCtrl-L" ); +#endif // wxUSE_LOG + fileMenu->AppendSeparator(); fileMenu->Append( wxID_EXIT, "E&xit\tAlt-X" ); @@ -1767,6 +1773,13 @@ void GridFrame::OnAbout( wxCommandEvent& WXUNUSED(ev) ) } +void GridFrame::OnClear( wxCommandEvent& WXUNUSED(ev) ) +{ +#if wxUSE_LOG + logWin->Clear(); +#endif // wxUSE_LOG +} + void GridFrame::OnQuit( wxCommandEvent& WXUNUSED(ev) ) { Close( true ); diff --git a/samples/grid/griddemo.h b/samples/grid/griddemo.h index f02a32d821..fa196b0643 100644 --- a/samples/grid/griddemo.h +++ b/samples/grid/griddemo.h @@ -130,6 +130,7 @@ public: ~GridFrame(); void OnQuit( wxCommandEvent& ); + void OnClear( wxCommandEvent& ); void OnAbout( wxCommandEvent& ); void OnVTable( wxCommandEvent& ); void OnBugsTable( wxCommandEvent& ); From 682cb8355cc898278adb25ed41b107602e8eb429 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Aug 2020 02:15:57 +0200 Subject: [PATCH 11/15] Replace "sendEvent" parameter in wxGridSelection with "eventType" Instead of just passing a boolean flag indicating whether wxEVT_GRID_RANGE_SELECTED should be sent, pass wxEventType to send, with wxEVT_NULL being interpreted as "don't send anything". No real changes yet, but this will allow using the existing functions to send wxEVT_GRID_RANGE_SELECTING and not only SELECTED in the upcoming commits. --- include/wx/generic/gridsel.h | 13 ++++++++----- src/generic/gridsel.cpp | 17 +++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/wx/generic/gridsel.h b/include/wx/generic/gridsel.h index 04399e4cd4..a39a42e128 100644 --- a/include/wx/generic/gridsel.h +++ b/include/wx/generic/gridsel.h @@ -21,6 +21,8 @@ typedef wxVector wxVectorGridBlockCoords; +// Note: for all eventType arguments of the methods of this class wxEVT_NULL +// may be passed to forbid events generation completely. class WXDLLIMPEXP_CORE wxGridSelection { public: @@ -41,15 +43,15 @@ public: void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol, const wxKeyboardState& kbd = wxKeyboardState(), - bool sendEvent = true ); + wxEventType eventType = wxEVT_GRID_RANGE_SELECTED); void SelectBlock(const wxGridCellCoords& topLeft, const wxGridCellCoords& bottomRight, const wxKeyboardState& kbd = wxKeyboardState(), - bool sendEvent = true ) + wxEventType eventType = wxEVT_GRID_RANGE_SELECTED) { SelectBlock(topLeft.GetRow(), topLeft.GetCol(), bottomRight.GetRow(), bottomRight.GetCol(), - kbd, sendEvent); + kbd, eventType); } // This function replaces all the existing selected blocks (which become @@ -58,7 +60,7 @@ public: void DeselectBlock(const wxGridBlockCoords& block, const wxKeyboardState& kbd = wxKeyboardState(), - bool sendEvent = true ); + wxEventType eventType = wxEVT_GRID_RANGE_SELECTED); // Note that this method refreshes the previously selected blocks and sends // an event about the selection change. @@ -121,7 +123,8 @@ private: // Really select the block and don't check for the current selection mode. void Select(const wxGridBlockCoords& block, - const wxKeyboardState& kbd, bool sendEvent); + const wxKeyboardState& kbd, + wxEventType eventType); // Ensure that the new "block" becomes part of "blocks", adding it to them // if necessary and, if we do it, also removing any existing elements of diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index 39323a5ea8..4ab51f784d 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -182,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; @@ -224,7 +224,7 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol, return; Select(wxGridBlockCoords(topRow, leftCol, bottomRow, rightCol).Canonicalize(), - kbd, sendEvent); + kbd, eventType); } void @@ -247,7 +247,7 @@ wxGridSelection::SelectAll() void wxGridSelection::DeselectBlock(const wxGridBlockCoords& block, const wxKeyboardState& kbd, - bool sendEvent) + wxEventType eventType) { const wxGridBlockCoords canonicalizedBlock = block.Canonicalize(); @@ -361,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_SELECTED, + eventType, m_grid, refBlock.GetTopLeft(), refBlock.GetBottomRight(), @@ -818,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; @@ -832,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_SELECTED, + eventType, m_grid, block.GetTopLeft(), block.GetBottomRight(), From 6d6c01ff2a9f0350a2dfc4306f7ce7dad96550b7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Aug 2020 02:25:19 +0200 Subject: [PATCH 12/15] Make wxKeyboardState ctor explicit Avoid accidental conversions of e.g. int to wxKeyboardState. --- include/wx/kbdstate.h | 1 + interface/wx/kbdstate.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/wx/kbdstate.h b/include/wx/kbdstate.h index 8945c6b2ba..43444269cb 100644 --- a/include/wx/kbdstate.h +++ b/include/wx/kbdstate.h @@ -19,6 +19,7 @@ class WXDLLIMPEXP_CORE wxKeyboardState { public: + explicit wxKeyboardState(bool controlDown = false, bool shiftDown = false, bool altDown = false, diff --git a/interface/wx/kbdstate.h b/interface/wx/kbdstate.h index b3a2932209..e834be21d3 100644 --- a/interface/wx/kbdstate.h +++ b/interface/wx/kbdstate.h @@ -30,6 +30,7 @@ public: By default, no modifiers are active. */ + explicit wxKeyboardState(bool controlDown = false, bool shiftDown = false, bool altDown = false, From 010007ba1749f75236cc0c0fbd362869936feee9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Aug 2020 02:29:17 +0200 Subject: [PATCH 13/15] Fix type of the initial wxGrid selection event when dragging Pass the same eventType ExtendCurrentBlock() is called with to SelectBlock() called to perform the initial selection to ensure that wxEVT_GRID_RANGE_SELECTING is sent while dragging instead of the unexpected wxEVT_GRID_RANGE_SELECTED (in addition to the expected one sent at the end when the drag is over). --- src/generic/gridsel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index 4ab51f784d..abb25a06a6 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -526,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; } From 408ebfd253144ef3535932314a42fe34256d4a56 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Aug 2020 15:54:47 +0200 Subject: [PATCH 14/15] Capture mouse while selecting rows/columns too Change the logic in ChangeCursorMode() to explicitly exclude the modes for which the mouse should not be captured, as CaptureMouse() should be called in most cases (and ideally for all of them in the future) and do capture it for WXGRID_CURSOR_SELECT_{ROW,COL} too, if only to be notified about mouse capture loss. --- src/generic/grid.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 2e8b67cb67..93a4d4764f 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -4453,19 +4453,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; From 9765b6d58e5c6ec19ce0f684da00f29e0d60aa3e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Aug 2020 16:10:40 +0200 Subject: [PATCH 15/15] Send SELECTING events while selecting rows/columns too Generalize the changes of 415f080c80 (Split wxGrid RANGE_SELECT event into SELECTING and SELECTED, 2020-07-27) to the case when the mouse is dragged over row or column headers: also send SELECTING events while dragging and a SELECTED event at the end, whether it's due to releasing the mouse button or losing mouse capture. --- src/generic/grid.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 93a4d4764f..315e9c95b0 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3678,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; @@ -3695,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() ) @@ -3811,6 +3809,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, rowLabelWin); m_dragLastPos = -1; + m_isDragging = false; } // ------------ Right button down @@ -4021,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; @@ -4092,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() ) @@ -4264,6 +4261,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow()); m_dragLastPos = -1; + m_isDragging = false; } // ------------ Right button down