From 1df13ce32bb0d3c28de9a8fbe1e975707972236a Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 10 Oct 2020 13:07:02 +0100 Subject: [PATCH] Dismiss the layer selector grid combobox when it loses focus Fixes https://gitlab.com/kicad/code/kicad/issues/5943 --- pcbnew/grid_layer_box_helpers.cpp | 25 +++++++++++++++++++++++++ pcbnew/grid_layer_box_helpers.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/pcbnew/grid_layer_box_helpers.cpp b/pcbnew/grid_layer_box_helpers.cpp index 22be5f2d7d..ec226f62d8 100644 --- a/pcbnew/grid_layer_box_helpers.cpp +++ b/pcbnew/grid_layer_box_helpers.cpp @@ -135,6 +135,10 @@ void GRID_CELL_LAYER_SELECTOR::BeginEdit( int aRow, int aCol, wxGrid* aGrid ) // Don't immediately end if we get a kill focus event within BeginEdit evtHandler->SetInSetFocus( true ); + // These event handlers are needed to properly dismiss the editor when the popup is closed + m_control->Bind(wxEVT_COMBOBOX_DROPDOWN, &GRID_CELL_LAYER_SELECTOR::onComboDropDown, this); + m_control->Bind(wxEVT_COMBOBOX_CLOSEUP, &GRID_CELL_LAYER_SELECTOR::onComboCloseUp, this); + m_value = (LAYER_NUM) aGrid->GetTable()->GetValueAsLong( aRow, aCol ); // Footprints are defined in a global context and may contain layers not enabled @@ -192,3 +196,24 @@ void GRID_CELL_LAYER_SELECTOR::Reset() } +void GRID_CELL_LAYER_SELECTOR::onComboDropDown( wxCommandEvent& aEvent ) +{ + auto evtHandler = static_cast( m_control->GetEventHandler() ); + + // Once the combobox is dropped, reset the flag to allow the focus-loss handler + // to function and close the editor. + evtHandler->SetInSetFocus( false ); +} + + +void GRID_CELL_LAYER_SELECTOR::onComboCloseUp( wxCommandEvent& aEvent ) +{ + auto evtHandler = static_cast( m_control->GetEventHandler() ); + + // Forward the combobox close up event to the cell event handler as a focus kill event + // so that the grid editor is dismissed when the combox closes, otherwise it leaves the + // dropdown arrow visible in the cell. + wxFocusEvent event( wxEVT_KILL_FOCUS, m_control->GetId() ); + event.SetEventObject( m_control ); + evtHandler->ProcessEvent( event ); +} diff --git a/pcbnew/grid_layer_box_helpers.h b/pcbnew/grid_layer_box_helpers.h index 549cdb6440..329384f7b2 100644 --- a/pcbnew/grid_layer_box_helpers.h +++ b/pcbnew/grid_layer_box_helpers.h @@ -70,6 +70,10 @@ public: void Reset() override; protected: + // Event handlers to properly dismiss the layer selector when it loses focus + void onComboDropDown( wxCommandEvent& aEvent ); + void onComboCloseUp( wxCommandEvent& aEvent ); + PCB_LAYER_BOX_SELECTOR* LayerBox() const { return static_cast( m_control );