diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index e02f45f3ae..bd124f89d1 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2787,28 +2787,33 @@ protected: bool Redimension( wxGridTableMessage& ); - // Send the given grid event and return -1 if it was vetoed or, as a - // special exception, if an event for a particular cell resulted in this - // cell being deleted, 1 if it was processed (but not vetoed) and 0 if it - // wasn't processed. - int DoSendEvent(wxGridEvent& gridEvt); + enum EventResult + { + Event_Vetoed = -1, // Also returned when cell was deleted. + Event_Unhandled, + Event_Handled + }; + + // Send the given grid event and returns one of the event handling results + // defined above. + EventResult DoSendEvent(wxGridEvent& gridEvt); // Generate an event of the given type and call DoSendEvent(). - int SendEvent(wxEventType evtType, + EventResult SendEvent(wxEventType evtType, int row, int col, const wxMouseEvent& e); - int SendEvent(wxEventType evtType, + EventResult SendEvent(wxEventType evtType, const wxGridCellCoords& coords, const wxMouseEvent& e) { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); } - int SendEvent(wxEventType evtType, + EventResult SendEvent(wxEventType evtType, int row, int col, const wxString& s = wxString()); - int SendEvent(wxEventType evtType, + EventResult SendEvent(wxEventType evtType, const wxGridCellCoords& coords, const wxString& s = wxString()) { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), s); } - int SendEvent(wxEventType evtType, const wxString& s = wxString()) + EventResult SendEvent(wxEventType evtType, const wxString& s = wxString()) { return SendEvent(evtType, m_currentCellCoords, s); } // send wxEVT_GRID_{ROW,COL}_SIZE or wxEVT_GRID_COL_AUTO_SIZE, return true diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 397c05bcd5..3414ebbcf8 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3716,7 +3716,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo { row = YToRow(pos.y); if ( row >= 0 && - !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) ) + SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) == Event_Unhandled ) { // Check if row selection is possible and allowed, before doing // anything else, including changing the cursor mode to "select @@ -3792,7 +3792,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo { row = YToRow(pos.y); if ( row >=0 && - !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ) ) + SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ) == Event_Unhandled ) { // no default action at the moment } @@ -3816,7 +3816,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo { row = YToRow(pos.y); if ( row < 0 || - !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) ) + SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) == Event_Unhandled ) { // no default action at the moment event.Skip(); @@ -3829,7 +3829,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo { row = YToRow(pos.y); if ( row < 0 || - !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) ) + SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) == Event_Unhandled ) { // no default action at the moment event.Skip(); @@ -3954,7 +3954,7 @@ void wxGrid::DoColHeaderClick(int col) { // we consider that the grid was resorted if this event is processed and // not vetoed - if ( SendEvent(wxEVT_GRID_COL_SORT, -1, col) == 1 ) + if ( SendEvent(wxEVT_GRID_COL_SORT, -1, col) == Event_Handled ) { SetSortingColumn(col, IsSortingBy(col) ? !m_sortIsAscending : true); Refresh(); @@ -4112,7 +4112,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo else // not a request to start resizing { if ( col >= 0 && - !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) ) + SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) == Event_Unhandled ) { if ( m_canDragColMove ) { @@ -4187,7 +4187,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo if ( colEdge == -1 ) { if ( col >= 0 && - ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ) ) + SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ) == Event_Unhandled ) { // no default action at the moment } @@ -4268,7 +4268,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo else if ( event.RightDown() ) { if ( col < 0 || - !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) ) + SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) == Event_Unhandled ) { // no default action at the moment event.Skip(); @@ -4280,7 +4280,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo else if ( event.RightDClick() ) { if ( col < 0 || - !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) ) + SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) == Event_Unhandled ) { // no default action at the moment event.Skip(); @@ -4322,7 +4322,7 @@ void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event ) // indicate corner label by having both row and // col args == -1 // - if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, event ) ) + if ( SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, event ) == Event_Unhandled ) { SelectAll(); } @@ -4333,7 +4333,7 @@ void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event ) } else if ( event.RightDown() ) { - if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, event ) ) + if ( SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, event ) == Event_Unhandled ) { // no default action at the moment event.Skip(); @@ -4341,7 +4341,7 @@ void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event ) } else if ( event.RightDClick() ) { - if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, event ) ) + if ( SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, event ) == Event_Unhandled ) { // no default action at the moment event.Skip(); @@ -4494,7 +4494,7 @@ wxGrid::DoGridCellDrag(wxMouseEvent& event, if ( CanDragCell() ) { // if event is handled by user code, no further processing - return SendEvent(wxEVT_GRID_CELL_BEGIN_DRAG, coords, event) == 0; + return SendEvent(wxEVT_GRID_CELL_BEGIN_DRAG, coords, event) == Event_Unhandled; } break; @@ -4543,7 +4543,7 @@ wxGrid::DoGridCellLeftDown(wxMouseEvent& event, const wxGridCellCoords& coords, const wxPoint& pos) { - if ( SendEvent(wxEVT_GRID_CELL_LEFT_CLICK, coords, event) ) + if ( SendEvent(wxEVT_GRID_CELL_LEFT_CLICK, coords, event) != Event_Unhandled ) { // event handled by user code, no need to do anything here return; @@ -4644,7 +4644,7 @@ wxGrid::DoGridCellLeftDClick(wxMouseEvent& event, { if ( XToEdgeOfCol(pos.x) < 0 && YToEdgeOfRow(pos.y) < 0 ) { - if ( !SendEvent(wxEVT_GRID_CELL_LEFT_DCLICK, coords, event) ) + if ( SendEvent(wxEVT_GRID_CELL_LEFT_DCLICK, coords, event) == Event_Unhandled ) { // we want double click to select a cell and start editing // (i.e. to behave in same way as sequence of two slow clicks): @@ -4835,9 +4835,9 @@ void wxGrid::ProcessGridCellMouseEvent(wxMouseEvent& event, wxGridWindow *eventG else if ( event.LeftDClick() ) handled = (DoGridCellLeftDClick(event, coords, pos), true); else if ( event.RightDown() ) - handled = SendEvent(wxEVT_GRID_CELL_RIGHT_CLICK, coords, event) != 0; + handled = SendEvent(wxEVT_GRID_CELL_RIGHT_CLICK, coords, event) != Event_Unhandled; else if ( event.RightDClick() ) - handled = SendEvent(wxEVT_GRID_CELL_RIGHT_DCLICK, coords, event) != 0; + handled = SendEvent(wxEVT_GRID_CELL_RIGHT_DCLICK, coords, event) != Event_Unhandled; } } else if ( event.Moving() ) @@ -4949,9 +4949,8 @@ void wxGrid::DoEndMoveCol(int pos) { wxASSERT_MSG( m_dragMoveCol != -1, "no matching DoStartMoveCol?" ); - if ( SendEvent(wxEVT_GRID_COL_MOVE, -1, m_dragMoveCol) != -1 ) + if ( SendEvent(wxEVT_GRID_COL_MOVE, -1, m_dragMoveCol) != Event_Vetoed ) SetColPos(m_dragMoveCol, pos); - //else: vetoed by user m_dragMoveCol = -1; } @@ -5285,17 +5284,13 @@ wxGrid::SendGridSizeEvent(wxEventType type, return ProcessWindowEvent(gridEvt); } -// Process the event and return -// -1 if the event was vetoed or if event cell was deleted -// +1 if the event was processed (but not vetoed) -// 0 if the event wasn't handled -int wxGrid::DoSendEvent(wxGridEvent& gridEvt) +wxGrid::EventResult wxGrid::DoSendEvent(wxGridEvent& gridEvt) { const bool claimed = ProcessWindowEvent(gridEvt); // A Veto'd event may not be `claimed' so test this first if ( !gridEvt.IsAllowed() ) - return -1; + return Event_Vetoed; // We also return -1 if the event cell was deleted, as this allows to have // checks in several functions that generate an event and then proceed @@ -5303,13 +5298,13 @@ int wxGrid::DoSendEvent(wxGridEvent& gridEvt) // done if the user-defined handler deleted this cell. if ( gridEvt.GetRow() >= GetNumberRows() || gridEvt.GetCol() >= GetNumberCols() ) - return -1; + return Event_Vetoed; - return claimed ? 1 : 0; + return claimed ? Event_Handled : Event_Unhandled; } // Generate a grid event based on a mouse event and call DoSendEvent() with it. -int +wxGrid::EventResult wxGrid::SendEvent(wxEventType type, int row, int col, const wxMouseEvent& mouseEv) @@ -5362,7 +5357,7 @@ wxGrid::SendEvent(wxEventType type, // Generate a grid event of specified type, return value same as above // -int +wxGrid::EventResult wxGrid::SendEvent(wxEventType type, int row, int col, const wxString& s) { wxGridEvent gridEvt( GetId(), type, this, row, col ); @@ -6049,7 +6044,7 @@ void wxGrid::DoGridProcessTab(wxKeyboardState& kbdState) bool wxGrid::SetCurrentCell( const wxGridCellCoords& coords ) { - if ( SendEvent(wxEVT_GRID_SELECT_CELL, coords) == -1 ) + if ( SendEvent(wxEVT_GRID_SELECT_CELL, coords) == Event_Vetoed ) { // the event has been vetoed - do nothing return false; @@ -7161,7 +7156,7 @@ void wxGrid::EnableCellEditControl( bool enable ) bool wxGrid::DoEnableCellEditControl(const wxGridActivationSource& actSource) { - if ( SendEvent(wxEVT_GRID_EDITOR_SHOWN) == -1 ) + if ( SendEvent(wxEVT_GRID_EDITOR_SHOWN) == Event_Vetoed ) return false; if ( !DoShowCellEditControl(actSource) ) @@ -7245,7 +7240,7 @@ bool wxGrid::DoShowCellEditControl(const wxGridActivationSource& actSource) // This is somewhat similar to what DoSaveEditControlValue() does. // but we don't allow vetoing CHANGED event here as this code is // new and shouldn't have to support this obsolete usage. - if ( SendEvent(wxEVT_GRID_CELL_CHANGING, res.GetNewValue()) != -1 ) + if ( SendEvent(wxEVT_GRID_CELL_CHANGING, res.GetNewValue()) != Event_Vetoed ) { const wxString& oldval = GetCellValue(m_currentCellCoords); @@ -7254,7 +7249,7 @@ bool wxGrid::DoShowCellEditControl(const wxGridActivationSource& actSource) // Show the new cell value. RefreshBlock(m_currentCellCoords, m_currentCellCoords); - if ( SendEvent(wxEVT_GRID_CELL_CHANGED, oldval) == -1 ) + if ( SendEvent(wxEVT_GRID_CELL_CHANGED, oldval) == Event_Vetoed ) { wxFAIL_MSG( "Vetoing wxEVT_GRID_CELL_CHANGED is ignored" ); } @@ -7493,14 +7488,14 @@ void wxGrid::DoSaveEditControlValue() wxString newval; bool changed = editor->EndEdit(row, col, this, oldval, &newval); - if ( changed && SendEvent(wxEVT_GRID_CELL_CHANGING, newval) != -1 ) + if ( changed && SendEvent(wxEVT_GRID_CELL_CHANGING, newval) != Event_Vetoed ) { editor->ApplyEdit(row, col, this); // for compatibility reasons dating back to wx 2.8 when this event // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING // didn't exist we allow vetoing this one too - if ( SendEvent(wxEVT_GRID_CELL_CHANGED, oldval) == -1 ) + if ( SendEvent(wxEVT_GRID_CELL_CHANGED, oldval) == Event_Vetoed ) { // Event has been vetoed, set the data back. SetCellValue(m_currentCellCoords, oldval);