diff --git a/common/dialogs/dialog_configure_paths.cpp b/common/dialogs/dialog_configure_paths.cpp index c1f9b8854b..f27b91cd22 100644 --- a/common/dialogs/dialog_configure_paths.cpp +++ b/common/dialogs/dialog_configure_paths.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index 60159ff59f..81af36ecd6 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -36,7 +36,7 @@ #define ROW_SEP wxT( '\n' ) -GRID_TRICKS::GRID_TRICKS( wxGrid* aGrid ): +GRID_TRICKS::GRID_TRICKS( WX_GRID* aGrid ): m_grid( aGrid ) { m_sel_row_start = 0; @@ -44,15 +44,12 @@ GRID_TRICKS::GRID_TRICKS( wxGrid* aGrid ): m_sel_row_count = 0; m_sel_col_count = 0; - m_showEditorOnMouseUp = false; - aGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), NULL, this ); aGrid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftDClick ), NULL, this ); aGrid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridCellRightClick ), NULL, this ); aGrid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridLabelRightClick ), NULL, this ); aGrid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), NULL, this ); aGrid->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( GRID_TRICKS::onKeyDown ), NULL, this ); - aGrid->GetGridWindow()->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( GRID_TRICKS::onMouseUp ), NULL, this ); aGrid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ), NULL, this ); } @@ -99,18 +96,29 @@ bool GRID_TRICKS::toggleCell( int aRow, int aCol ) bool GRID_TRICKS::showEditor( int aRow, int aCol ) { - m_grid->SetGridCursor( aRow, aCol ); + if( m_grid->GetCursorRow() != aRow || m_grid->GetCursorColumn() != aCol ) + m_grid->SetGridCursor( aRow, aCol ); if( m_grid->IsEditable() && !m_grid->IsReadOnly( aRow, aCol ) ) { if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows ) - m_grid->SelectRow( aRow ); + { + wxArrayInt rows = m_grid->GetSelectedRows(); + + if( rows.size() != 1 || rows.at( 0 ) != aRow ) + m_grid->SelectRow( aRow ); + } // For several reasons we can't enable the control here. There's the whole // SetInSetFocus() issue/hack in wxWidgets, and there's also wxGrid's MouseUp // handler which doesn't notice it's processing a MouseUp until after it has - // disabled the editor yet again. So we wait for the MouseUp. - m_showEditorOnMouseUp = true; + // disabled the editor yet again. So we re-use wxWidgets' slow-click hack, + // which is processed later in the MouseUp handler. + // + // It should be pointed out that the fact that it's wxWidgets' hack doesn't + // make it any less of a hack. Be extra careful with any modifications here. + // See, in particular, https://bugs.launchpad.net/kicad/+bug/1817965. + m_grid->ShowEditorOnMouseUp(); return true; } @@ -124,10 +132,8 @@ void GRID_TRICKS::onGridCellLeftClick( wxGridEvent& aEvent ) int row = aEvent.GetRow(); int col = aEvent.GetCol(); - // Activate editor only if a cursor is placed on the clicked cell - if( !aEvent.GetModifiers() && - m_grid->GetGridCursorRow() == row && - m_grid->GetGridCursorCol() == col ) + // Don't make users click twice to toggle a checkbox or edit a text cell + if( !aEvent.GetModifiers() ) { if( toggleCell( row, col ) ) return; @@ -147,33 +153,6 @@ void GRID_TRICKS::onGridCellLeftDClick( wxGridEvent& aEvent ) } -void GRID_TRICKS::onMouseUp( wxMouseEvent& aEvent ) -{ - if( m_showEditorOnMouseUp ) - { - // Some wxGridCellEditors don't have the SetInSetFocus() hack. Even when they do, - // it sometimes fails. Activating the control here seems to avoid those issues. - m_showEditorOnMouseUp = false; - // Mouse button can be pressed on one cell but be released on another - // cell (when range of cells is selecting, for example). - // So it must be checked. - wxGridCellCoords curCell = wxGridCellCoords( m_grid->GetGridCursorRow(), - m_grid->GetGridCursorCol() ); - wxGridCellCoords eventCell = m_grid->XYToCell( m_grid->CalcUnscrolledPosition( aEvent.GetPosition() ) ); - if( eventCell == curCell && m_grid->CanEnableCellControl() ) - { - // Yes, the first of these also shows the control. Well, at least sometimes. - // The second call corrects those (as yet undefined) "other times". - m_grid->EnableCellEditControl(); - m_grid->ShowCellEditControl(); - return; - } - } - - aEvent.Skip(); -} - - bool GRID_TRICKS::handleDoubleClick( wxGridEvent& aEvent ) { // Double-click processing must be handled by specific sub-classes diff --git a/common/widgets/wx_grid.h b/common/widgets/wx_grid.h index 96fe2b5beb..1c4c357bf5 100644 --- a/common/widgets/wx_grid.h +++ b/common/widgets/wx_grid.h @@ -25,7 +25,6 @@ #define KICAD_WX_GRID_H #include -#include class WX_GRID : public wxGrid { @@ -91,6 +90,14 @@ public: */ void EnsureColLabelsVisible(); + /** + * WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell + * editors right after opening them. Helpfully, it already has a bunch of work-arounds in + * place (such as the SetInSetFocus() hack), including one to make slow clicks work. We + * re-purpose this hack to work-around the bugs when we want to open an editor. + */ + void ShowEditorOnMouseUp() { m_waitForSlowClick = true; } + protected: void DrawColLabel( wxDC& dc, int col ) override; diff --git a/eeschema/dialogs/dialog_edit_components_libid.cpp b/eeschema/dialogs/dialog_edit_components_libid.cpp index 91ef906414..94c578fa8b 100644 --- a/eeschema/dialogs/dialog_edit_components_libid.cpp +++ b/eeschema/dialogs/dialog_edit_components_libid.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #define COL_REFS 0 diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index 2520abc2c2..31f537a12a 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -55,7 +55,7 @@ enum class FIELDS_EDITOR_GRID_TRICKS : public GRID_TRICKS { public: - FIELDS_EDITOR_GRID_TRICKS( DIALOG_SHIM* aParent, wxGrid* aGrid, + FIELDS_EDITOR_GRID_TRICKS( DIALOG_SHIM* aParent, WX_GRID* aGrid, wxDataViewListCtrl* aFieldsCtrl ) : GRID_TRICKS( aGrid ), m_dlg( aParent ), diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index 5c1ef541a4..a7f6a97736 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -83,7 +83,7 @@ public: class SYMBOL_GRID_TRICKS : public GRID_TRICKS { public: - SYMBOL_GRID_TRICKS( DIALOG_EDIT_LIBRARY_TABLES* aParent, wxGrid* aGrid ) : + SYMBOL_GRID_TRICKS( DIALOG_EDIT_LIBRARY_TABLES* aParent, WX_GRID* aGrid ) : GRID_TRICKS( aGrid ), m_dialog( aParent ) { diff --git a/eeschema/fields_grid_table.h b/eeschema/fields_grid_table.h index 326bda108d..69d12c6a7d 100644 --- a/eeschema/fields_grid_table.h +++ b/eeschema/fields_grid_table.h @@ -37,7 +37,7 @@ class DIALOG_SHIM; class FIELDS_GRID_TRICKS : public GRID_TRICKS { public: - FIELDS_GRID_TRICKS( wxGrid* aGrid, DIALOG_SHIM* aDialog ) : + FIELDS_GRID_TRICKS( WX_GRID* aGrid, DIALOG_SHIM* aDialog ) : GRID_TRICKS( aGrid ), m_dlg( aDialog ) {} diff --git a/include/grid_tricks.h b/include/grid_tricks.h index f338e13030..6b74174eb4 100644 --- a/include/grid_tricks.h +++ b/include/grid_tricks.h @@ -28,7 +28,7 @@ #include #include - +#include enum { @@ -46,25 +46,23 @@ enum /** * Class GRID_TRICKS - * is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance. + * is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance. */ class GRID_TRICKS : public wxEvtHandler { public: - explicit GRID_TRICKS( wxGrid* aGrid ); + explicit GRID_TRICKS( WX_GRID* aGrid ); protected: - wxGrid* m_grid; ///< I don't own the grid, but he owns me + WX_GRID* m_grid; ///< I don't own the grid, but he owns me // row & col "selection" acquisition // selected area by cell coordinate and count - int m_sel_row_start; - int m_sel_col_start; - int m_sel_row_count; - int m_sel_col_count; - - bool m_showEditorOnMouseUp; + int m_sel_row_start; + int m_sel_col_start; + int m_sel_row_count; + int m_sel_col_count; /// Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above. void getSelectedArea(); @@ -80,7 +78,6 @@ protected: void onGridLabelRightClick( wxGridEvent& event ); void onPopupSelection( wxCommandEvent& event ); void onKeyDown( wxKeyEvent& ev ); - void onMouseUp( wxMouseEvent& aEvent ); void onUpdateUI( wxUpdateUIEvent& event ); virtual bool handleDoubleClick( wxGridEvent& aEvent ); diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index e1a24c2d59..491069e737 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -156,7 +156,7 @@ public: class FP_GRID_TRICKS : public GRID_TRICKS { public: - FP_GRID_TRICKS( DIALOG_EDIT_LIBRARY_TABLES* aParent, wxGrid* aGrid ) : + FP_GRID_TRICKS( DIALOG_EDIT_LIBRARY_TABLES* aParent, WX_GRID* aGrid ) : GRID_TRICKS( aGrid ), m_dialog( aParent ) { } diff --git a/pcbnew/dialogs/panel_modedit_defaults.cpp b/pcbnew/dialogs/panel_modedit_defaults.cpp index 5fb003e94a..a1add09a30 100644 --- a/pcbnew/dialogs/panel_modedit_defaults.cpp +++ b/pcbnew/dialogs/panel_modedit_defaults.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include diff --git a/pcbnew/dialogs/panel_setup_netclasses.cpp b/pcbnew/dialogs/panel_setup_netclasses.cpp index 19a91f78af..a89f575827 100644 --- a/pcbnew/dialogs/panel_setup_netclasses.cpp +++ b/pcbnew/dialogs/panel_setup_netclasses.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include diff --git a/pcbnew/dialogs/panel_setup_text_and_graphics.cpp b/pcbnew/dialogs/panel_setup_text_and_graphics.cpp index 8f771d0fd0..f7e65575e9 100644 --- a/pcbnew/dialogs/panel_setup_text_and_graphics.cpp +++ b/pcbnew/dialogs/panel_setup_text_and_graphics.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include diff --git a/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp b/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp index 69cca386e2..24969a2e6a 100644 --- a/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp +++ b/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 4307a93009..1bf5ce7273 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -198,7 +198,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, auto divider = new wxStaticLine( m_parametersPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL ); - m_parameterGrid = new wxGrid( m_parametersPanel, ID_FOOTPRINT_WIZARD_PARAMETER_LIST ); + m_parameterGrid = new WX_GRID( m_parametersPanel, ID_FOOTPRINT_WIZARD_PARAMETER_LIST ); initParameterGrid(); m_parameterGrid->PushEventHandler( new GRID_TRICKS( m_parameterGrid ) ); diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index 2d00cdb649..f6ba3adcb7 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -35,7 +35,7 @@ #include class wxSashLayoutWindow; class wxListBox; -class wxGrid; +class WX_GRID; class wxGridEvent; class FOOTPRINT_EDIT_FRAME; @@ -55,7 +55,7 @@ class FOOTPRINT_WIZARD_FRAME : public PCB_BASE_FRAME private: wxPanel* m_parametersPanel; ///< Panel for the page list and parameter grid wxListBox* m_pageList; ///< The list of pages - wxGrid* m_parameterGrid; ///< The list of parameters + WX_GRID* m_parameterGrid; ///< The list of parameters int m_parameterGridPage; ///< the page currently displayed by m_parameterGrid ///< it is most of time the m_pageList selection, but can differ ///< during transitions between pages. diff --git a/pcbnew/footprint_wizard_frame_functions.cpp b/pcbnew/footprint_wizard_frame_functions.cpp index 30cb3719d2..a1faa742af 100644 --- a/pcbnew/footprint_wizard_frame_functions.cpp +++ b/pcbnew/footprint_wizard_frame_functions.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include