Replace wxEVT_GRID_HIDE_EDITOR usage with CallAfter
This simplifies the code by removing the need for a special event, and also means the combox popup handler is no longer needed to reset the inSetFocus flag for the closing handler.
This commit is contained in:
@@ -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 );
|
||||||
|
@@ -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,8 +337,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
|
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
|
||||||
|
|
||||||
void onComboCloseUp(wxCommandEvent& evt);
|
void OnComboCloseUp(wxCommandEvent& evt);
|
||||||
void onComboDropDown(wxCommandEvent& evt);
|
|
||||||
|
|
||||||
wxString m_value;
|
wxString m_value;
|
||||||
wxArrayString m_choices;
|
wxArrayString m_choices;
|
||||||
|
@@ -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
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -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
|
||||||
|
@@ -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:
|
||||||
@@ -1581,9 +1579,8 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
wxGridCellEditorEvtHandler* evtHandler = NULL;
|
wxGridCellEditorEvtHandler* evtHandler = NULL;
|
||||||
if (m_control)
|
if (m_control)
|
||||||
{
|
{
|
||||||
// These event handlers are needed to properly dismiss the editor when the popup is closed
|
// This event handler is needed to properly dismiss the editor when the popup is closed
|
||||||
m_control->Bind(wxEVT_COMBOBOX_DROPDOWN, &wxGridCellChoiceEditor::onComboDropDown, this);
|
m_control->Bind(wxEVT_COMBOBOX_CLOSEUP, &wxGridCellChoiceEditor::OnComboCloseUp, this);
|
||||||
m_control->Bind(wxEVT_COMBOBOX_CLOSEUP, &wxGridCellChoiceEditor::onComboCloseUp, this);
|
|
||||||
evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler);
|
evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1684,7 +1681,7 @@ wxString wxGridCellChoiceEditor::GetValue() const
|
|||||||
return Combo()->GetValue();
|
return Combo()->GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellChoiceEditor::onComboDropDown(wxCommandEvent& WXUNUSED(evt))
|
void wxGridCellChoiceEditor::OnComboCloseUp(wxCommandEvent& WXUNUSED(evt))
|
||||||
{
|
{
|
||||||
wxGridCellEditorEvtHandler* evtHandler = wxDynamicCast(m_control->GetEventHandler(),
|
wxGridCellEditorEvtHandler* evtHandler = wxDynamicCast(m_control->GetEventHandler(),
|
||||||
wxGridCellEditorEvtHandler);
|
wxGridCellEditorEvtHandler);
|
||||||
@@ -1692,25 +1689,9 @@ void wxGridCellChoiceEditor::onComboDropDown(wxCommandEvent& WXUNUSED(evt))
|
|||||||
if ( !evtHandler )
|
if ( !evtHandler )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Once the combobox is dropped, reset the flag to allow the focus-loss handler
|
// Close the grid editor when the combobox closes, otherwise it leaves the
|
||||||
// to function and close the editor.
|
|
||||||
evtHandler->SetInSetFocus(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxGridCellChoiceEditor::onComboCloseUp(wxCommandEvent& WXUNUSED(evt))
|
|
||||||
{
|
|
||||||
wxGridCellEditorEvtHandler* evtHandler = wxDynamicCast(m_control->GetEventHandler(),
|
|
||||||
wxGridCellEditorEvtHandler);
|
|
||||||
|
|
||||||
if ( !evtHandler )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 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.
|
// dropdown arrow visible in the cell.
|
||||||
wxFocusEvent event(wxEVT_KILL_FOCUS, m_control->GetId());
|
evtHandler->DismissEditor();
|
||||||
event.SetEventObject(m_control);
|
|
||||||
evtHandler->ProcessEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_COMBOBOX
|
#endif // wxUSE_COMBOBOX
|
||||||
@@ -1864,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;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user