Close the cell editor when the editor's combobox is closed.

See https://github.com/wxWidgets/wxWidgets/pull/1941
This commit is contained in:
Vadim Zeitlin
2020-07-15 15:46:03 +02:00
5 changed files with 33 additions and 25 deletions

View File

@@ -2827,7 +2827,6 @@ protected:
void OnKeyDown( wxKeyEvent& ); void OnKeyDown( wxKeyEvent& );
void OnKeyUp( wxKeyEvent& ); void OnKeyUp( wxKeyEvent& );
void OnChar( wxKeyEvent& ); void OnChar( wxKeyEvent& );
void OnHideEditor( wxCommandEvent& );
bool SetCurrentCell( const wxGridCellCoords& coords ); bool SetCurrentCell( const wxGridCellCoords& coords );

View File

@@ -27,6 +27,8 @@ public:
{ {
} }
void DismissEditor();
void OnKillFocus(wxFocusEvent& event); void OnKillFocus(wxFocusEvent& event);
void OnKeyDown(wxKeyEvent& event); void OnKeyDown(wxKeyEvent& event);
void OnChar(wxKeyEvent& event); void OnChar(wxKeyEvent& event);
@@ -335,6 +337,8 @@ public:
protected: protected:
wxComboBox *Combo() const { return (wxComboBox *)m_control; } wxComboBox *Combo() const { return (wxComboBox *)m_control; }
void OnComboCloseUp(wxCommandEvent& evt);
wxString m_value; wxString m_value;
wxArrayString m_choices; wxArrayString m_choices;
bool m_allowOthers; bool m_allowOthers;

View File

@@ -17,10 +17,6 @@
#include "wx/headerctrl.h" #include "wx/headerctrl.h"
// Internally used (and hence intentionally not exported) event telling wxGrid
// to hide the currently shown editor.
wxDECLARE_EVENT( wxEVT_GRID_HIDE_EDITOR, wxCommandEvent );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// array classes // array classes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -2519,7 +2519,6 @@ wxBEGIN_EVENT_TABLE( wxGrid, wxScrolledCanvas )
EVT_KEY_DOWN( wxGrid::OnKeyDown ) EVT_KEY_DOWN( wxGrid::OnKeyDown )
EVT_KEY_UP( wxGrid::OnKeyUp ) EVT_KEY_UP( wxGrid::OnKeyUp )
EVT_CHAR ( wxGrid::OnChar ) EVT_CHAR ( wxGrid::OnChar )
EVT_COMMAND(wxID_ANY, wxEVT_GRID_HIDE_EDITOR, wxGrid::OnHideEditor )
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
bool wxGrid::Create(wxWindow *parent, wxWindowID id, bool wxGrid::Create(wxWindow *parent, wxWindowID id,
@@ -7543,11 +7542,6 @@ void wxGrid::DoSaveEditControlValue()
} }
} }
void wxGrid::OnHideEditor(wxCommandEvent& WXUNUSED(event))
{
DisableCellEditControl();
}
// //
// ------ Grid location functions // ------ Grid location functions
// Note that all of these functions work with the logical coordinates of // Note that all of these functions work with the logical coordinates of

View File

@@ -66,12 +66,19 @@
// implementation // implementation
// ============================================================================ // ============================================================================
wxDEFINE_EVENT( wxEVT_GRID_HIDE_EDITOR, wxCommandEvent );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGridCellEditorEvtHandler // wxGridCellEditorEvtHandler
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxGridCellEditorEvtHandler::DismissEditor()
{
// Tell the grid to dismiss the control but don't do it immediately as it
// could result in the editor being destroyed right now and a crash in the
// code searching for the next event handler, so tell the grid to close it
// after this event is processed.
m_grid->CallAfter(&wxGrid::DisableCellEditControl);
}
void wxGridCellEditorEvtHandler::OnKillFocus(wxFocusEvent& event) void wxGridCellEditorEvtHandler::OnKillFocus(wxFocusEvent& event)
{ {
// We must let the native control have this event so in any case don't mark // We must let the native control have this event so in any case don't mark
@@ -82,16 +89,7 @@ void wxGridCellEditorEvtHandler::OnKillFocus(wxFocusEvent& event)
if (m_inSetFocus) if (m_inSetFocus)
return; return;
// Tell the grid to dismiss the control but don't do it immediately as it DismissEditor();
// could result in the editor being destroyed right now and a crash in the
// code searching for the next event handler, so post an event asking the
// grid to do it slightly later instead.
// FIXME-VC6: Once we drop support for VC6, we should use a simpler
// m_grid->CallAfter(&wxGrid::DisableCellEditControl) and get
// rid of wxEVT_GRID_HIDE_EDITOR entirely.
m_grid->GetEventHandler()->
AddPendingEvent(wxCommandEvent(wxEVT_GRID_HIDE_EDITOR));
} }
void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
@@ -100,7 +98,7 @@ void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
{ {
case WXK_ESCAPE: case WXK_ESCAPE:
m_editor->Reset(); m_editor->Reset();
m_grid->DisableCellEditControl(); DismissEditor();
break; break;
case WXK_TAB: case WXK_TAB:
@@ -1580,7 +1578,11 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
wxGridCellEditorEvtHandler* evtHandler = NULL; wxGridCellEditorEvtHandler* evtHandler = NULL;
if (m_control) if (m_control)
{
// This event handler is needed to properly dismiss the editor when the popup is closed
m_control->Bind(wxEVT_COMBOBOX_CLOSEUP, &wxGridCellChoiceEditor::OnComboCloseUp, this);
evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler); evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler);
}
// Don't immediately end if we get a kill focus event within BeginEdit // Don't immediately end if we get a kill focus event within BeginEdit
if (evtHandler) if (evtHandler)
@@ -1679,6 +1681,19 @@ wxString wxGridCellChoiceEditor::GetValue() const
return Combo()->GetValue(); return Combo()->GetValue();
} }
void wxGridCellChoiceEditor::OnComboCloseUp(wxCommandEvent& WXUNUSED(evt))
{
wxGridCellEditorEvtHandler* evtHandler = wxDynamicCast(m_control->GetEventHandler(),
wxGridCellEditorEvtHandler);
if ( !evtHandler )
return;
// Close the grid editor when the combobox closes, otherwise it leaves the
// dropdown arrow visible in the cell.
evtHandler->DismissEditor();
}
#endif // wxUSE_COMBOBOX #endif // wxUSE_COMBOBOX
#if wxUSE_COMBOBOX #if wxUSE_COMBOBOX
@@ -1830,7 +1845,7 @@ struct wxGridCellDateEditorKeyHandler
case WXK_RETURN: case WXK_RETURN:
case WXK_NUMPAD_ENTER: case WXK_NUMPAD_ENTER:
wxPostEvent(m_handler, wxCommandEvent(wxEVT_GRID_HIDE_EDITOR)); m_handler->DismissEditor();
event.Skip(); event.Skip();
break; break;