Check for valid entry in wxTextEntry::EnableTextChangedEvents()

GetTextObject() might return null, e.g. it does it for read-only
wxBitmapComboBox, so EnableTextChangedEvents() must account for this
possibility, as it's not really possible to avoid calling it in this
case, as it's called indirectly from e.g. SetSelection().

Check that the entry is valid before enabling or disabling events for it
to avoid several GLib assertion failures every time when e.g.
wxBitmapComboBox::SetValue() is called.

Closes https://github.com/wxWidgets/wxWidgets/pull/1756
This commit is contained in:
Yuri D'Elia
2020-03-10 19:16:29 +01:00
committed by Vadim Zeitlin
parent b08b697665
commit f9b793f8d1

View File

@@ -1003,14 +1003,21 @@ int wxTextEntry::GTKEntryIMFilterKeypress(GdkEventKey* event) const
void wxTextEntry::EnableTextChangedEvents(bool enable)
{
// Check that we have the associated text, as it may happen (for e.g.
// read-only wxBitmapComboBox) and shouldn't result in any errors, we just
// don't have any events to enable or disable in this case.
void* const entry = GetTextObject();
if ( !entry )
return;
if ( enable )
{
g_signal_handlers_unblock_by_func(GetTextObject(),
g_signal_handlers_unblock_by_func(entry,
(gpointer)wx_gtk_text_changed_callback, this);
}
else // disable events
{
g_signal_handlers_block_by_func(GetTextObject(),
g_signal_handlers_block_by_func(entry,
(gpointer)wx_gtk_text_changed_callback, this);
}
}