diff --git a/TODO.md b/TODO.md index ff293745..acdc9829 100644 --- a/TODO.md +++ b/TODO.md @@ -14,6 +14,8 @@ - buttons not in tab get drawover issues - buttons in tab without transparent drawing code get copied into the label when stack shown and rehidden - see if we can clean up the Darwin backend +- make the Unix and Windows backend use uiParentDestroy() instead of relying on the autodestroy behavior of the backends + - this requires explicitly handling delete events ultimately: - make everything vtable-based diff --git a/unix/parent.c b/unix/parent.c index d6a16908..5ae6812f 100644 --- a/unix/parent.c +++ b/unix/parent.c @@ -131,6 +131,15 @@ static void uipParent_class_init(uipParentClass *class) GTK_CONTAINER_CLASS(class)->forall = uipParent_forall; } +// TODO convert other methods of this + other backends to pp arg p instance variable + +static void parentDestroy(uiParent *pp) +{ + uipParent *p = uipParent(pp->Internal); + + gtk_widget_destroy(GTK_WIDGET(p)); +} + static uintptr_t parentHandle(uiParent *p) { uipParent *pp = uipParent(p->Internal); @@ -172,6 +181,7 @@ uiParent *uiNewParent(uintptr_t osParent) p = uiNew(uiParent); p->Internal = g_object_new(uipParentType, NULL); + p->Destroy = parentDestroy; p->Handle = parentHandle; p->SetMainControl = parentSetMainControl; p->SetMargins = parentSetMargins; diff --git a/windows/parent.c b/windows/parent.c index f1979467..491ebe6b 100644 --- a/windows/parent.c +++ b/windows/parent.c @@ -211,6 +211,14 @@ const char *initParent(HICON hDefaultIcon, HCURSOR hDefaultCursor) return NULL; } +static void parentDestroy(uiParent *pp) +{ + struct parent *p = (struct parent *) (pp->Internal); + + if (DestroyWindow(p->hwnd) == 0) + logLastError("error destroying uiParent window in parentDestroy()"); +} + static uintptr_t parentHandle(uiParent *p) { struct parent *pp = (struct parent *) (p->Internal); @@ -262,6 +270,8 @@ uiParent *uiNewParent(uintptr_t osParent) (HWND) osParent, NULL, hInstance, p); if (pp->hwnd == NULL) logLastError("error creating uiParent window in uiNewParent()"); + + p->Destroy = parentDestroy; p->Handle = parentHandle; p->SetMainControl = parentSetMainControl; p->SetMargins = parentSetMargins;