Started splitting out lifetime management code into its own place on the GTK+ backend.

This commit is contained in:
Pietro Gagliardi 2015-04-19 01:37:11 -04:00
parent 085e06d054
commit a5e4060b67
4 changed files with 24 additions and 7 deletions

View File

@ -5,6 +5,7 @@ OSCFILES = \
entry.c \
init.c \
label.c \
lifetimes.c \
main.c \
newcontrol.c \
parent.c \

17
unix/lifetimes.c Normal file
View File

@ -0,0 +1,17 @@
// 19 april 2015
#include "uipriv_unix.h"
static void destroyBlocker(GtkWidget *widget, gpointer data)
{
complain("trying to destroy object at %p before destroy function called", data);
}
gulong blockDestruction(GtkWidget *widget, void *object)
{
return g_signal_connect(widget, "destroy", G_CALLBACK(destroyBlocker), object);
}
void readyToDestroy(GtkWidget *widget, gulong block)
{
g_signal_handler_disconnect(widget, block);
}

View File

@ -24,7 +24,7 @@ static void singleDestroy(uiControl *c)
// first call the widget's own destruction code
(*(s->onDestroy))(s->onDestroyData);
// then mark that we are ready to be destroyed
g_signal_handler_disconnect(s->immediate, s->destroyBlocker);
readyToDestroy(s->immediate, s->destroyBlocker);
// then actually destroy (TODO sync these comments)
gtk_widget_destroy(s->immediate);
// and free ourselves
@ -167,11 +167,6 @@ static void singleContainerDisable(uiControl *c)
gtk_widget_set_sensitive(s->immediate, FALSE);
}
static void destroyBlocker(GtkWidget *widget, gpointer data)
{
complain("trying to destroy control at %p before uiControlDestroy()", data);
}
void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*onDestroy)(void *), void *onDestroyData, const char *firstProperty, ...)
{
singleWidget *s;
@ -227,7 +222,7 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool
c->ContainerDisable = singleContainerDisable;
// let's stop premature destruction
s->destroyBlocker = g_signal_connect(s->immediate, "destroy", G_CALLBACK(destroyBlocker), c);
s->destroyBlocker = blockDestruction(s->immediate, c);
// finally, call gtk_widget_show_all() here to set the initial visibility of the widget
gtk_widget_show_all(s->immediate);

View File

@ -12,3 +12,7 @@
#define widget(c) uiControlHandle(uiControl(c))
#define WIDGET(c) GTK_WIDGET(widget(c))
// lifetimes.c
extern gulong blockDestruction(GtkWidget *, void *);
extern void readyToDestroy(GtkWidget *, gulong);