Implemented the parent updating logic on GTK+.

This commit is contained in:
Pietro Gagliardi 2015-04-08 18:58:59 -04:00
parent 9d67ec7fa4
commit f470768a8e
2 changed files with 18 additions and 1 deletions

View File

@ -102,3 +102,9 @@ GtkWidget *newContainer(void)
{ {
return GTK_WIDGET(g_object_new(uiContainerType, NULL)); return GTK_WIDGET(g_object_new(uiContainerType, NULL));
} }
void updateParent(uintptr_t parent)
{
if (parent != 0)
gtk_widget_queue_resize(GTK_WIDGET(parent));
}

View File

@ -9,6 +9,7 @@ struct uiSingleWidgetControl {
GtkWidget *scrolledWindow; GtkWidget *scrolledWindow;
GtkWidget *immediate; // the widget that is added to the parent container; either widget or scrolledWindow GtkWidget *immediate; // the widget that is added to the parent container; either widget or scrolledWindow
void *data; void *data;
uintptr_t parent;
}; };
#define S(c) ((uiSingleWidgetControl *) (c)) #define S(c) ((uiSingleWidgetControl *) (c))
@ -25,7 +26,16 @@ static uintptr_t singleHandle(uiControl *c)
static void singleSetParent(uiControl *c, uintptr_t parent) static void singleSetParent(uiControl *c, uintptr_t parent)
{ {
gtk_container_add(GTK_CONTAINER(parent), S(c)->immediate); uiSingleWidgetControl *s = S(c);
uintptr_t oldparent;
oldparent = s->parent;
s->parent = parent;
if (oldparent != 0)
gtk_container_remove(GTK_CONTAINER(oldparent), s->immediate);
gtk_container_add(GTK_CONTAINER(s->parent), s->immediate);
updateParent(oldparent);
updateParent(s->parent);
} }
static uiSize singlePreferredSize(uiControl *c, uiSizing *d) static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
@ -91,6 +101,7 @@ uiControl *uiUnixNewControl(GType type, gboolean inScrolledWindow, gboolean scro
// with this: // with this:
// - end user call works (shoudn't be in any container) // - end user call works (shoudn't be in any container)
// - call in uiContainer works (both refs freed) // - call in uiContainer works (both refs freed)
// this also ensures singleSetParent() works properly when changing parents
g_object_ref_sink(c->immediate); g_object_ref_sink(c->immediate);
// and let's free the uiSingleWidgetControl with it // and let's free the uiSingleWidgetControl with it
g_signal_connect(c->immediate, "destroy", G_CALLBACK(onDestroy), c); g_signal_connect(c->immediate, "destroy", G_CALLBACK(onDestroy), c);