diff --git a/common/dialogs/panel_setup_netclasses.cpp b/common/dialogs/panel_setup_netclasses.cpp index ea10b49f70..1e0ec77151 100644 --- a/common/dialogs/panel_setup_netclasses.cpp +++ b/common/dialogs/panel_setup_netclasses.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -311,7 +312,7 @@ void PANEL_SETUP_NETCLASSES::rebuildNetclassDropdowns() } wxGridCellAttr* attr = new wxGridCellAttr; - attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) ); + attr->SetEditor( new GRID_CELL_COMBOBOX( netclassNames ) ); m_membershipGrid->SetColAttr( 1, attr ); m_assignNetClass->Set( netclassNames ); @@ -510,12 +511,6 @@ void PANEL_SETUP_NETCLASSES::OnSizeNetclassGrid( wxSizeEvent& event ) } -void PANEL_SETUP_NETCLASSES::OnMembershipKillFocus( wxFocusEvent& event ) -{ - m_membershipGrid->CommitPendingChanges(); -} - - void PANEL_SETUP_NETCLASSES::AdjustMembershipGridColumns( int aWidth ) { // Account for scroll bars diff --git a/common/dialogs/panel_setup_netclasses.h b/common/dialogs/panel_setup_netclasses.h index 1de908820c..19c9c7213e 100644 --- a/common/dialogs/panel_setup_netclasses.h +++ b/common/dialogs/panel_setup_netclasses.h @@ -50,7 +50,6 @@ private: void OnSizeMembershipGrid( wxSizeEvent& event ) override; void OnUpdateUI( wxUpdateUIEvent &event ) override; void OnNetclassGridCellChanging( wxGridEvent& event ); - void OnMembershipKillFocus( wxFocusEvent& event ) override; void OnShowAll( wxCommandEvent& event ) override { doApplyFilters( true ); } void OnApplyFilters( wxCommandEvent& event ) override { doApplyFilters( false ); } void OnAssignAll( wxCommandEvent& event ) override { doAssignments( true ); } diff --git a/common/dialogs/panel_setup_netclasses_base.cpp b/common/dialogs/panel_setup_netclasses_base.cpp index 5094529191..6d38d64709 100644 --- a/common/dialogs/panel_setup_netclasses_base.cpp +++ b/common/dialogs/panel_setup_netclasses_base.cpp @@ -245,7 +245,6 @@ PANEL_SETUP_NETCLASSES_BASE::PANEL_SETUP_NETCLASSES_BASE( wxWindow* parent, wxWi m_filterNetsButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnApplyFilters ), NULL, this ); m_assignAllButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnAssignAll ), NULL, this ); m_assignSelectedButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnAssignSelected ), NULL, this ); - m_membershipGrid->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnMembershipKillFocus ), NULL, this ); m_membershipGrid->Connect( wxEVT_SIZE, wxSizeEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnSizeMembershipGrid ), NULL, this ); } @@ -260,7 +259,6 @@ PANEL_SETUP_NETCLASSES_BASE::~PANEL_SETUP_NETCLASSES_BASE() m_filterNetsButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnApplyFilters ), NULL, this ); m_assignAllButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnAssignAll ), NULL, this ); m_assignSelectedButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnAssignSelected ), NULL, this ); - m_membershipGrid->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnMembershipKillFocus ), NULL, this ); m_membershipGrid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( PANEL_SETUP_NETCLASSES_BASE::OnSizeMembershipGrid ), NULL, this ); } diff --git a/common/dialogs/panel_setup_netclasses_base.fbp b/common/dialogs/panel_setup_netclasses_base.fbp index 65b373603c..f072b3a029 100644 --- a/common/dialogs/panel_setup_netclasses_base.fbp +++ b/common/dialogs/panel_setup_netclasses_base.fbp @@ -1325,7 +1325,6 @@ wxBORDER_DEFAULT - OnMembershipKillFocus OnSizeMembershipGrid diff --git a/common/dialogs/panel_setup_netclasses_base.h b/common/dialogs/panel_setup_netclasses_base.h index d0baea8bd7..9a110dd46b 100644 --- a/common/dialogs/panel_setup_netclasses_base.h +++ b/common/dialogs/panel_setup_netclasses_base.h @@ -66,7 +66,6 @@ class PANEL_SETUP_NETCLASSES_BASE : public wxPanel virtual void OnApplyFilters( wxCommandEvent& event ) { event.Skip(); } virtual void OnAssignAll( wxCommandEvent& event ) { event.Skip(); } virtual void OnAssignSelected( wxCommandEvent& event ) { event.Skip(); } - virtual void OnMembershipKillFocus( wxFocusEvent& event ) { event.Skip(); } virtual void OnSizeMembershipGrid( wxSizeEvent& event ) { event.Skip(); } diff --git a/common/widgets/grid_combobox.cpp b/common/widgets/grid_combobox.cpp index cfde2fabaf..ca675eaa5c 100644 --- a/common/widgets/grid_combobox.cpp +++ b/common/widgets/grid_combobox.cpp @@ -79,6 +79,10 @@ void GRID_CELL_COMBOBOX::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_COMBOBOX::onComboDropDown, this); + m_control->Bind(wxEVT_COMBOBOX_CLOSEUP, &GRID_CELL_COMBOBOX::onComboCloseUp, this); + m_value = aGrid->GetTable()->GetValue( aRow, aCol ); Combo()->SetFocus(); @@ -126,3 +130,24 @@ void GRID_CELL_COMBOBOX::Reset() } +void GRID_CELL_COMBOBOX::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_COMBOBOX::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/include/widgets/grid_combobox.h b/include/widgets/grid_combobox.h index ce6c7edf92..9a32a7e430 100644 --- a/include/widgets/grid_combobox.h +++ b/include/widgets/grid_combobox.h @@ -52,8 +52,11 @@ public: protected: wxComboBox* Combo() const { return static_cast( m_control ); } - const wxArrayString& m_names; - wxString m_value; + void onComboCloseUp( wxCommandEvent& aEvent ); + void onComboDropDown( wxCommandEvent& aEvent ); + + wxArrayString m_names; + wxString m_value; wxDECLARE_NO_COPY_CLASS( GRID_CELL_COMBOBOX ); };