Disconnect all GTK signals referencing a wx object which is being destructed

or which is destroying the associated GTK object


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72696 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett 2012-10-17 16:23:18 +00:00
parent 5475b39f53
commit 8ab7533289
28 changed files with 96 additions and 90 deletions

View File

@ -56,6 +56,7 @@ public:
Init();
Create(parent, id, value, pos, size, choices, style, validator, name);
}
~wxComboBox();
bool Create(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString,

View File

@ -88,7 +88,7 @@ public:
Create( parent, id, defaultDirectory, defaultFilename, wildCard, style, pos, size, name );
}
virtual ~wxGtkFileCtrl() {}
virtual ~wxGtkFileCtrl();
bool Create( wxWindow *parent,
wxWindowID id,

View File

@ -33,6 +33,7 @@ public:
{
Create(parent, id, title, pos, size, style, name);
}
~wxMiniFrame();
bool Create(wxWindow *parent,
wxWindowID id,

View File

@ -30,6 +30,7 @@ public:
Create( parent, id, value, minValue, maxValue,
pos, size, style, validator, name );
}
~wxSlider();
bool Create(wxWindow *parent,
wxWindowID id,

View File

@ -10,7 +10,7 @@
#ifndef _WX_GTK_WEBKITCTRL_H_
#define _WX_GTK_WEBKITCTRL_H_
#include "wx/setup.h"
#include "wx/defs.h"
#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
@ -26,7 +26,7 @@ typedef struct _WebKitWebView WebKitWebView;
class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
{
public:
wxWebViewWebKit() { }
wxWebViewWebKit();
wxWebViewWebKit(wxWindow *parent,
wxWindowID id = wxID_ANY,

View File

@ -59,8 +59,6 @@ public:
// implement base class (pure) virtual methods
// -------------------------------------------
virtual bool Destroy();
virtual void Raise();
virtual void Lower();
@ -308,7 +306,6 @@ public:
// extra (wxGTK-specific) flags
bool m_noExpose:1; // wxGLCanvas has its own redrawing
bool m_nativeSizeEvent:1; // wxGLCanvas sends wxSizeEvent upon "alloc_size"
bool m_hasVMT:1; // set after PostCreation() is called
bool m_isScrolling:1; // dragging scrollbar thumb?
bool m_clipPaintRegion:1; // true after ScrollWindow()
wxRegion m_nativeUpdateRegion; // not transformed for RTL
@ -352,6 +349,7 @@ protected:
void GTKFreezeWidget(GtkWidget *w);
void GTKThawWidget(GtkWidget *w);
void GTKDisconnect(void* instance);
#if wxUSE_TOOLTIPS
virtual void DoSetToolTip( wxToolTip *tip );

View File

@ -30,8 +30,6 @@ extern bool g_blockEventsOnDrag;
extern "C" {
static void gtk_checkbox_toggled_callback(GtkWidget *widget, wxCheckBox *cb)
{
if (!cb->m_hasVMT) return;
if (g_blockEventsOnDrag) return;
// Transitions for 3state checkbox must be done manually, GTK's checkbox

View File

@ -103,9 +103,6 @@ wxChoice::~wxChoice()
void wxChoice::SendSelectionChangedEvent(wxEventType evt_type)
{
if (!m_hasVMT)
return;
if (GetSelection() == -1)
return;

View File

@ -33,8 +33,6 @@ extern "C" {
static void
gtkcombobox_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
{
if (!combo->m_hasVMT) return;
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
event.SetString( combo->GetValue() );
event.SetEventObject( combo );
@ -87,6 +85,12 @@ BEGIN_EVENT_TABLE(wxComboBox, wxChoice)
EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll)
END_EVENT_TABLE()
wxComboBox::~wxComboBox()
{
if (m_entry)
GTKDisconnect(m_entry);
}
void wxComboBox::Init()
{
m_entry = NULL;

View File

@ -139,9 +139,7 @@ void wxControl::GTKFixSensitivity(bool WXUNUSED_IN_GTK3(onlyIfUnderMouse))
#endif
)
{
wxPoint pt = wxGetMousePosition();
wxRect rect(ClientToScreen(wxPoint(0, 0)), GetSize());
if (!onlyIfUnderMouse || rect.Contains(pt))
if (!onlyIfUnderMouse || GetScreenRect().Contains(wxGetMousePosition()))
{
Hide();
Show();

View File

@ -4462,6 +4462,11 @@ wxDataViewCtrl::~wxDataViewCtrl()
// This won't do anything if we're not editing it
wxcol->GetRenderer()->CancelEditing();
}
GTKDisconnect(m_treeview);
GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview));
if (selection)
GTKDisconnect(selection);
}
m_cols.Clear();
@ -4471,6 +4476,7 @@ wxDataViewCtrl::~wxDataViewCtrl()
void wxDataViewCtrl::Init()
{
m_treeview = NULL;
m_internal = NULL;
m_cols.DeleteContents( true );

View File

@ -285,6 +285,12 @@ extern "C"
IMPLEMENT_DYNAMIC_CLASS( wxGtkFileCtrl, wxControl )
wxGtkFileCtrl::~wxGtkFileCtrl()
{
if (m_fcWidget)
GTKDisconnect(m_fcWidget);
}
void wxGtkFileCtrl::Init()
{
m_checkNextSelEvent = false;

View File

@ -99,9 +99,6 @@ gtk_glcanvas_size_callback(GtkWidget *WXUNUSED(widget),
GtkAllocation * WXUNUSED(alloc),
wxGLCanvas *win)
{
if (!win->m_hasVMT)
return;
wxSizeEvent event( wxSize(win->m_width,win->m_height), win->GetId() );
event.SetEventObject( win );
win->HandleWindowEvent( event );

View File

@ -404,7 +404,13 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
wxListBox::~wxListBox()
{
m_hasVMT = false;
if (m_treeview)
{
GTKDisconnect(m_treeview);
GtkTreeSelection* selection = gtk_tree_view_get_selection(m_treeview);
if (selection)
GTKDisconnect(selection);
}
Clear();
}

View File

@ -70,8 +70,7 @@ wxMenuBar::~wxMenuBar()
GtkWidget* widget = m_widget;
m_focusWidget =
m_widget = NULL;
g_signal_handlers_disconnect_matched(widget,
GSignalMatchType(G_SIGNAL_MATCH_DATA), 0, 0, NULL, NULL, this);
GTKDisconnect(widget);
g_object_unref(widget);
}
}
@ -750,7 +749,8 @@ wxMenu::~wxMenu()
// Destroying a menu generates a "hide" signal even if it's not shown
// currently, so disconnect it to avoid dummy wxEVT_MENU_CLOSE events
// generation.
g_signal_handlers_disconnect_by_func(m_menu, (gpointer)menu_hide, this);
g_signal_handlers_disconnect_matched(m_menu,
GSignalMatchType(G_SIGNAL_MATCH_DATA), 0, 0, NULL, NULL, this);
// see wxMenu::Init
g_object_unref(m_menu);
@ -913,6 +913,10 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
return NULL;
GtkWidget * const mitem = item->GetMenuItem();
g_signal_handlers_disconnect_matched(mitem,
GSignalMatchType(G_SIGNAL_MATCH_DATA), 0, 0, NULL, NULL, item);
#ifdef __WXGTK3__
gtk_menu_item_set_submenu(GTK_MENU_ITEM(mitem), NULL);
#else

View File

@ -81,7 +81,7 @@ static gboolean expose_event(GtkWidget* widget, GdkEventExpose* gdk_event, wxMin
wxGTKCairoDC dc(cr);
#else
if (!win->m_hasVMT || gdk_event->count > 0 ||
if (gdk_event->count > 0 ||
gdk_event->window != gtk_widget_get_window(widget))
{
return false;
@ -144,7 +144,7 @@ extern "C" {
static gboolean
gtk_window_button_press_callback(GtkWidget* widget, GdkEventButton* gdk_event, wxMiniFrame* win)
{
if (!win->m_hasVMT || gdk_event->window != gtk_widget_get_window(widget))
if (gdk_event->window != gtk_widget_get_window(widget))
return false;
if (g_blockEventsOnDrag) return TRUE;
if (g_blockEventsOnScroll) return TRUE;
@ -224,7 +224,7 @@ extern "C" {
static gboolean
gtk_window_button_release_callback(GtkWidget* widget, GdkEventButton* gdk_event, wxMiniFrame* win)
{
if (!win->m_hasVMT || gdk_event->window != gtk_widget_get_window(widget))
if (gdk_event->window != gtk_widget_get_window(widget))
return false;
if (g_blockEventsOnDrag) return TRUE;
if (g_blockEventsOnScroll) return TRUE;
@ -257,9 +257,8 @@ extern "C" {
static gboolean
gtk_window_leave_callback(GtkWidget *widget,
GdkEventCrossing* gdk_event,
wxMiniFrame *win)
wxMiniFrame*)
{
if (!win->m_hasVMT) return FALSE;
if (g_blockEventsOnDrag) return FALSE;
if (gdk_event->window != gtk_widget_get_window(widget))
return false;
@ -278,7 +277,7 @@ extern "C" {
static gboolean
gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win )
{
if (!win->m_hasVMT || gdk_event->window != gtk_widget_get_window(widget))
if (gdk_event->window != gtk_widget_get_window(widget))
return false;
if (g_blockEventsOnDrag) return TRUE;
if (g_blockEventsOnScroll) return TRUE;
@ -340,6 +339,15 @@ static unsigned char close_bits[]={
IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame)
wxMiniFrame::~wxMiniFrame()
{
if (m_widget)
{
GtkWidget* eventbox = gtk_bin_get_child(GTK_BIN(m_widget));
GTKDisconnect(eventbox);
}
}
bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )

View File

@ -292,6 +292,7 @@ int wxMessageDialog::ShowModal()
gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
GTKDisconnect(m_widget);
gtk_widget_destroy(m_widget);
g_object_unref(m_widget);
m_widget = NULL;

View File

@ -125,6 +125,7 @@ void wxNativeContainerWindow::OnNativeDestroyed()
// because it's a private GDK function and calling normal
// gdk_window_destroy() results in X errors while nulling just the window
// pointer and destroying m_widget results in many GTK errors
GTKDisconnect(m_widget);
m_widget = NULL;
// notice that we intentionally don't use Close() nor Delete() here as our

View File

@ -58,7 +58,6 @@ extern bool g_blockEventsOnDrag;
extern "C" {
static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBox *rb )
{
if (!rb->m_hasVMT) return;
if (g_blockEventsOnDrag) return;
if (!gtk_toggle_button_get_active(button)) return;
@ -78,7 +77,6 @@ static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBo
extern "C" {
static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb )
{
if (!rb->m_hasVMT) return FALSE;
if (g_blockEventsOnDrag) return FALSE;
if ( ((gdk_event->keyval == GDK_Tab) ||
@ -319,6 +317,7 @@ wxRadioBox::~wxRadioBox()
while (node)
{
GtkWidget *button = GTK_WIDGET( node->GetData()->button );
GTKDisconnect(button);
gtk_widget_destroy( button );
node = node->GetNext();
}

View File

@ -32,8 +32,6 @@ extern "C" {
static
void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioButton *rb )
{
if (!rb->m_hasVMT) return;
if (g_blockEventsOnDrag) return;
if (!gtk_toggle_button_get_active(button)) return;

View File

@ -129,7 +129,7 @@ gtk_value_changed(GtkRange* range, wxSlider* win)
const double oldPos = win->m_pos;
win->m_pos = value;
if (!win->m_hasVMT || g_blockEventsOnDrag)
if (g_blockEventsOnDrag)
return;
if (win->GTKEventsDisabled())
@ -275,10 +275,13 @@ static gchar* gtk_format_value(GtkScale*, double value, void*)
wxSlider::wxSlider()
{
m_pos = 0;
m_scrollEventType = GTK_SCROLL_NONE;
m_needThumbRelease = false;
m_blockScrollEvent = false;
m_scale = NULL;
}
wxSlider::~wxSlider()
{
if (m_scale && m_scale != m_widget)
GTKDisconnect(m_scale);
}
bool wxSlider::Create(wxWindow *parent,
@ -294,6 +297,8 @@ bool wxSlider::Create(wxWindow *parent,
{
m_pos = value;
m_scrollEventType = GTK_SCROLL_NONE;
m_needThumbRelease = false;
m_blockScrollEvent = false;
if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, validator, name ))

View File

@ -38,7 +38,7 @@ gtk_value_changed(GtkSpinButton* spinbutton, wxSpinButton* win)
const double value = gtk_spin_button_get_value(spinbutton);
const int pos = int(value);
const int oldPos = win->m_pos;
if (!win->m_hasVMT || g_blockEventsOnDrag || pos == oldPos)
if (g_blockEventsOnDrag || pos == oldPos)
{
win->m_pos = pos;
return;

View File

@ -39,7 +39,7 @@ extern "C" {
static void
gtk_value_changed(GtkSpinButton* spinbutton, wxSpinCtrlGTKBase* win)
{
if (!win->m_hasVMT || g_blockEventsOnDrag)
if (g_blockEventsOnDrag)
return;
if (wxIsKindOf(win, wxSpinCtrl))
@ -69,9 +69,6 @@ extern "C" {
static void
gtk_changed(GtkSpinButton* spinbutton, wxSpinCtrl* win)
{
if (!win->m_hasVMT)
return;
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
event.SetEventObject( win );
event.SetString(gtk_entry_get_text(GTK_ENTRY(spinbutton)));

View File

@ -546,8 +546,6 @@ gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
if ( win->IgnoreTextUpdate() )
return;
if (!win->m_hasVMT) return;
if ( win->MarkDirtyOnChange() )
win->MarkDirty();
@ -607,12 +605,18 @@ void wxTextCtrl::Init()
SetUpdateFont(false);
m_text = NULL;
m_buffer = NULL;
m_showPositionOnThaw = NULL;
m_anonymousMarkList = NULL;
}
wxTextCtrl::~wxTextCtrl()
{
if (m_text)
GTKDisconnect(m_text);
if (m_buffer)
GTKDisconnect(m_buffer);
// this is also done by wxWindowGTK dtor, but has to be done here so our
// DoThaw() override is called
while (IsFrozen())

View File

@ -29,7 +29,7 @@ extern bool g_blockEventsOnDrag;
extern "C" {
static void gtk_togglebutton_clicked_callback(GtkWidget *WXUNUSED(widget), wxToggleButton *cb)
{
if (!cb->m_hasVMT || g_blockEventsOnDrag)
if (g_blockEventsOnDrag)
return;
// Generate a wx event.

View File

@ -269,7 +269,7 @@ gtk_frame_configure_callback( GtkWidget* widget,
GdkEventConfigure *WXUNUSED(event),
wxTopLevelWindowGTK *win )
{
if (!win->m_hasVMT || !win->IsShown())
if (!win->IsShown())
return FALSE;
wxPoint point;

View File

@ -33,11 +33,6 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget,
GParamSpec*,
wxWebViewWebKit *webKitCtrl)
{
// We can be called from webkit_web_view_dispose() during the window
// destruction, don't use half-destroyed object in this case.
if ( webKitCtrl->IsBeingDeleted() )
return;
wxString url = webKitCtrl->GetCurrentURL();
WebKitLoadStatus status;
@ -391,6 +386,11 @@ wxgtk_webview_webkit_resource_req(WebKitWebView *,
wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit, wxWebView);
wxWebViewWebKit::wxWebViewWebKit()
{
m_web_view = NULL;
}
bool wxWebViewWebKit::Create(wxWindow *parent,
wxWindowID id,
const wxString &url,
@ -456,11 +456,8 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
wxWebViewWebKit::~wxWebViewWebKit()
{
// The main goal here is to set m_isBeingDeleted to true to avoid the use
// of this -- already half-destroyed -- object from WebKit callbacks, but
// just setting it would prevent wxWindowDestroyEvent from being sent, so
// send it now instead.
SendDestroyEvent();
if (m_web_view)
GTKDisconnect(m_web_view);
}
bool wxWebViewWebKit::Enable( bool enable )

View File

@ -950,8 +950,6 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget),
GdkEventKey *gdk_event,
wxWindow *win )
{
if (!win->m_hasVMT)
return FALSE;
if (g_blockEventsOnDrag)
return FALSE;
@ -1124,9 +1122,6 @@ gtk_window_key_release_callback( GtkWidget * WXUNUSED(widget),
GdkEventKey *gdk_event,
wxWindowGTK *win )
{
if (!win->m_hasVMT)
return FALSE;
if (g_blockEventsOnDrag)
return FALSE;
@ -1276,13 +1271,11 @@ bool wxWindowGTK::GTKProcessEvent(wxEvent& event) const
bool wxWindowGTK::GTKShouldIgnoreEvent() const
{
return !m_hasVMT || g_blockEventsOnDrag;
return g_blockEventsOnDrag;
}
int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny *event) const
{
if (!m_hasVMT)
return FALSE;
if (g_blockEventsOnDrag)
return TRUE;
if (g_blockEventsOnScroll)
@ -2191,8 +2184,6 @@ void wxWindowGTK::Init()
m_width = 0;
m_height = 0;
m_hasVMT = false;
m_showOnIdle = false;
m_noExpose = false;
@ -2359,6 +2350,12 @@ bool wxWindowGTK::Create( wxWindow *parent,
return true;
}
void wxWindowGTK::GTKDisconnect(void* instance)
{
g_signal_handlers_disconnect_matched(instance,
GSignalMatchType(G_SIGNAL_MATCH_DATA), 0, 0, NULL, NULL, this);
}
wxWindowGTK::~wxWindowGTK()
{
SendDestroyEvent();
@ -2371,23 +2368,14 @@ wxWindowGTK::~wxWindowGTK()
if ( gs_deferredFocusOut == this )
gs_deferredFocusOut = NULL;
m_hasVMT = false;
if (m_widget)
GTKDisconnect(m_widget);
if (m_wxwindow && m_wxwindow != m_widget)
GTKDisconnect(m_wxwindow);
// destroy children before destroying this window itself
DestroyChildren();
// unhook focus handlers to prevent stray events being
// propagated to this (soon to be) dead object
if (m_focusWidget != NULL)
{
g_signal_handlers_disconnect_by_func (m_focusWidget,
(gpointer) gtk_window_focus_in_callback,
this);
g_signal_handlers_disconnect_by_func (m_focusWidget,
(gpointer) gtk_window_focus_out_callback,
this);
}
if (m_widget)
Show( false );
@ -2564,8 +2552,6 @@ void wxWindowGTK::PostCreation()
InheritAttributes();
m_hasVMT = true;
SetLayoutDirection(wxLayout_Default);
// unless the window was created initially hidden (i.e. Hide() had been
@ -2610,13 +2596,6 @@ void wxWindowGTK::ConnectWidget( GtkWidget *widget )
G_CALLBACK (gtk_window_leave_callback), this);
}
bool wxWindowGTK::Destroy()
{
m_hasVMT = false;
return wxWindowBase::Destroy();
}
static GSList* gs_queueResizeList;
extern "C" {
@ -4571,7 +4550,7 @@ wxEventType wxWindowGTK::GTKGetScrollEventType(GtkRange* range)
// update current position
m_scrollPos[barIndex] = value;
// If event should be ignored, or integral position has not changed
if (!m_hasVMT || g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos))
if (g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos))
{
return wxEVT_NULL;
}