Make using non-wxControl-derived wxGrid editors really work
While feacaf8714
changed the API to allow
using any wxWindow (and not only a window of a wxControl-derived class)
as the associated window of the grid editor, actually doing resulted in
an immediate crash due to dereferencing a null pointer in wxGrid code
which still expected to have a wxControl.
Fix this by replacing all calls to wxGridCellEditor::GetControl() inside
wxGrid with wxGridCellEditor::GetWindow(), to ensure that a non-null
editor window is used even in this case.
Closes https://github.com/wxWidgets/wxWidgets/pull/1509
This commit is contained in:
committed by
Vadim Zeitlin
parent
0ea4366163
commit
1bce1a1d4c
@@ -74,6 +74,7 @@ private:
|
||||
NONGTK_TEST( LabelClick );
|
||||
NONGTK_TEST( SortClick );
|
||||
CPPUNIT_TEST( ColumnOrder );
|
||||
WXUISIM_TEST( WindowAsEditorControl );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void CellEdit();
|
||||
@@ -95,6 +96,7 @@ private:
|
||||
void CellFormatting();
|
||||
void Editable();
|
||||
void ReadOnly();
|
||||
void WindowAsEditorControl();
|
||||
void PseudoTest_NativeHeader() { ms_nativeheader = true; }
|
||||
void PseudoTest_NativeLabels() { ms_nativeheader = false;
|
||||
ms_nativelabels = true; }
|
||||
@@ -742,4 +744,66 @@ void GridTestCase::ReadOnly()
|
||||
#endif
|
||||
}
|
||||
|
||||
void GridTestCase::WindowAsEditorControl()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
// A very simple editor using a window not derived from wxControl as the
|
||||
// editor.
|
||||
class TestEditor : public wxGridCellEditor
|
||||
{
|
||||
public:
|
||||
TestEditor() {}
|
||||
|
||||
void Create(wxWindow* parent,
|
||||
wxWindowID id,
|
||||
wxEvtHandler* evtHandler) wxOVERRIDE
|
||||
{
|
||||
SetWindow(new wxWindow(parent, id));
|
||||
wxGridCellEditor::Create(parent, id, evtHandler);
|
||||
}
|
||||
|
||||
void BeginEdit(int, int, wxGrid*) wxOVERRIDE {}
|
||||
|
||||
bool EndEdit(int, int, wxGrid const*, wxString const&,
|
||||
wxString* newval) wxOVERRIDE
|
||||
{
|
||||
*newval = GetValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ApplyEdit(int row, int col, wxGrid* grid) wxOVERRIDE
|
||||
{
|
||||
grid->GetTable()->SetValue(row, col, GetValue());
|
||||
}
|
||||
|
||||
void Reset() wxOVERRIDE {}
|
||||
|
||||
wxGridCellEditor* Clone() const wxOVERRIDE { return new TestEditor(); }
|
||||
|
||||
wxString GetValue() const wxOVERRIDE { return "value"; }
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(TestEditor);
|
||||
};
|
||||
|
||||
wxGridCellAttr* attr = new wxGridCellAttr();
|
||||
attr->SetRenderer(new wxGridCellStringRenderer());
|
||||
attr->SetEditor(new TestEditor());
|
||||
m_grid->SetAttr(1, 1, attr);
|
||||
|
||||
EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
|
||||
m_grid->SetFocus();
|
||||
m_grid->SetGridCursor(1, 1);
|
||||
m_grid->EnableCellEditControl();
|
||||
|
||||
sim.Char(WXK_RETURN);
|
||||
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, created.GetCount());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif //wxUSE_GRID
|
||||
|
Reference in New Issue
Block a user