More TODO resolution and some GTK+ uiWindow inconsistency (and future repeated-event bug waiting to happen) cleanup.

This commit is contained in:
Pietro Gagliardi 2015-04-10 21:48:50 -04:00
parent da3009bfbb
commit 47c89f6aef
2 changed files with 17 additions and 12 deletions

View File

@ -8,6 +8,21 @@ struct uiWindow {
void *onClosingData; void *onClosingData;
}; };
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
{
uiWindow *w = (uiWindow *) data;
// return exact values just in case
if ((*(w->onClosing))(w, w->onClosingData))
return FALSE;
return TRUE;
}
static int defaultOnClosing(uiWindow *w, void *data)
{
return 1;
}
static void onDestroy(GtkWidget *widget, gpointer data) static void onDestroy(GtkWidget *widget, gpointer data)
{ {
uiWindow *w = (uiWindow *) data; uiWindow *w = (uiWindow *) data;
@ -23,9 +38,11 @@ uiWindow *uiNewWindow(char *title, int width, int height)
w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(w->widget), title); gtk_window_set_title(GTK_WINDOW(w->widget), title);
gtk_window_resize(GTK_WINDOW(w->widget), width, height); gtk_window_resize(GTK_WINDOW(w->widget), width, height);
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
g_signal_connect(w->widget, "destroy", G_CALLBACK(onDestroy), w); g_signal_connect(w->widget, "destroy", G_CALLBACK(onDestroy), w);
w->container = newContainer(); w->container = newContainer();
gtk_container_add(GTK_CONTAINER(w->widget), w->container); gtk_container_add(GTK_CONTAINER(w->widget), w->container);
w->onClosing = defaultOnClosing;
return w; return w;
} }
@ -59,21 +76,10 @@ void uiWindowHide(uiWindow *w)
gtk_widget_hide(w->widget); gtk_widget_hide(w->widget);
} }
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
{
uiWindow *w = (uiWindow *) data;
// return exact values just in case
if ((*(w->onClosing))(w, w->onClosingData))
return FALSE;
return TRUE;
}
void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
{ {
w->onClosing = f; w->onClosing = f;
w->onClosingData = data; w->onClosingData = data;
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
} }
void uiWindowSetChild(uiWindow *w, uiControl *c) void uiWindowSetChild(uiWindow *w, uiControl *c)

View File

@ -96,7 +96,6 @@ uiWindow *uiNewWindow(char *title, int width, int height)
WCHAR *wtitle; WCHAR *wtitle;
w = uiNew(uiWindow); w = uiNew(uiWindow);
// TODO move other cases of default events here relative
w->onClosing = defaultOnClosing; w->onClosing = defaultOnClosing;
adjust.left = 0; adjust.left = 0;