Started working on code to monitor creation and deletion of UI objects correctly.
This commit is contained in:
parent
c6daf8d308
commit
1e263930eb
|
@ -17,6 +17,7 @@ static void uiContainer_dispose(GObject *obj)
|
|||
|
||||
static void uiContainer_finalize(GObject *obj)
|
||||
{
|
||||
printf("in uiContainer_finalize(); freeing container\n");
|
||||
G_OBJECT_CLASS(uiContainer_parent_class)->finalize(obj);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,14 @@ struct uiWindow {
|
|||
void *onClosingData;
|
||||
};
|
||||
|
||||
static void onDestroy(GtkWindow *window, gpointer data)
|
||||
{
|
||||
uiWindow *w = (uiWindow *) data;
|
||||
|
||||
printf("destroying window; freeing uiWindow\n");
|
||||
uiFree(w);
|
||||
}
|
||||
|
||||
uiWindow *uiNewWindow(char *title, int width, int height)
|
||||
{
|
||||
uiWindow *w;
|
||||
|
@ -16,6 +24,7 @@ uiWindow *uiNewWindow(char *title, int width, int height)
|
|||
w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title(GTK_WINDOW(w->widget), title);
|
||||
gtk_window_resize(GTK_WINDOW(w->widget), width, height);
|
||||
g_signal_connect(w->widget, "destroy", G_CALLBACK(onDestroy), w);
|
||||
w->container = newContainer();
|
||||
gtk_container_add(GTK_CONTAINER(w->widget), w->container);
|
||||
return w;
|
||||
|
@ -24,7 +33,6 @@ uiWindow *uiNewWindow(char *title, int width, int height)
|
|||
void uiWindowDestroy(uiWindow *w)
|
||||
{
|
||||
gtk_widget_destroy(w->widget);
|
||||
uiFree(w);
|
||||
}
|
||||
|
||||
uintptr_t uiWindowHandle(uiWindow *w)
|
||||
|
@ -44,7 +52,6 @@ void uiWindowHide(uiWindow *w)
|
|||
gtk_widget_hide(w->widget);
|
||||
}
|
||||
|
||||
// TODO will not free w
|
||||
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
|
||||
{
|
||||
uiWindow *w = (uiWindow *) data;
|
||||
|
|
|
@ -45,6 +45,10 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
|
|||
if (!(*(w->onClosing))(w, w->onClosingData))
|
||||
return 0;
|
||||
break; // fall through to DefWindowProcW()
|
||||
case WM_DESTROY:
|
||||
printf("destroying window; freeing uiWindow\n");
|
||||
uiFree(w);
|
||||
break; // fall through to DefWindowProcW()
|
||||
}
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
@ -104,7 +108,6 @@ uiWindow *uiNewWindow(char *title, int width, int height)
|
|||
void uiWindowDestroy(uiWindow *w)
|
||||
{
|
||||
DestroyWindow(w->hwnd);
|
||||
uiFree(w);
|
||||
}
|
||||
|
||||
uintptr_t uiWindowHandle(uiWindow *w)
|
||||
|
|
Loading…
Reference in New Issue