2015-04-07 11:59:01 -05:00
|
|
|
// 13 august 2014
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(uiContainer, uiContainer, GTK_TYPE_CONTAINER)
|
|
|
|
|
|
|
|
static void uiContainer_init(uiContainer *c)
|
|
|
|
{
|
2015-04-07 22:40:18 -05:00
|
|
|
#ifdef uiLogAllocations
|
|
|
|
fprintf(stderr, "%p alloc uiContainer\n", c);
|
|
|
|
#endif
|
2015-04-07 11:59:01 -05:00
|
|
|
c->children = g_ptr_array_new();
|
|
|
|
gtk_widget_set_has_window(GTK_WIDGET(c), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uiContainer_dispose(GObject *obj)
|
|
|
|
{
|
|
|
|
g_ptr_array_unref(uiContainer(obj)->children);
|
2015-04-08 00:16:22 -05:00
|
|
|
if (uiContainer(obj)->child != NULL) {
|
|
|
|
uiControlDestroy(uiContainer(obj)->child);
|
|
|
|
uiContainer(obj)->child = NULL;
|
|
|
|
}
|
2015-04-07 11:59:01 -05:00
|
|
|
G_OBJECT_CLASS(uiContainer_parent_class)->dispose(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uiContainer_finalize(GObject *obj)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS(uiContainer_parent_class)->finalize(obj);
|
2015-04-07 22:40:18 -05:00
|
|
|
#ifdef uiLogAllocations
|
|
|
|
fprintf(stderr, "%p free\n", obj);
|
|
|
|
#endif
|
2015-04-07 11:59:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uiContainer_add(GtkContainer *container, GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_widget_set_parent(widget, GTK_WIDGET(container));
|
|
|
|
g_ptr_array_add(uiContainer(container)->children, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uiContainer_remove(GtkContainer *container, GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_widget_unparent(widget);
|
|
|
|
g_ptr_array_remove(uiContainer(container)->children, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uiContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
|
|
|
|
{
|
2015-04-07 12:22:46 -05:00
|
|
|
uiControl *c;
|
|
|
|
uiSizing d;
|
|
|
|
|
2015-04-07 11:59:01 -05:00
|
|
|
gtk_widget_set_allocation(widget, allocation);
|
2015-04-07 12:22:46 -05:00
|
|
|
c = uiContainer(widget)->child;
|
2015-04-07 12:58:50 -05:00
|
|
|
if (c != NULL)
|
|
|
|
(*(c->resize))(c, allocation->x, allocation->y, allocation->width, allocation->height, &d);
|
2015-04-07 11:59:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct forall {
|
|
|
|
GtkCallback callback;
|
|
|
|
gpointer data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void doforall(gpointer obj, gpointer data)
|
|
|
|
{
|
|
|
|
struct forall *s = (struct forall *) data;
|
|
|
|
|
2015-04-07 12:37:03 -05:00
|
|
|
(*(s->callback))(GTK_WIDGET(obj), s->data);
|
2015-04-07 11:59:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uiContainer_forall(GtkContainer *container, gboolean includeInternals, GtkCallback callback, gpointer data)
|
|
|
|
{
|
|
|
|
struct forall s;
|
|
|
|
|
|
|
|
s.callback = callback;
|
|
|
|
s.data = data;
|
|
|
|
g_ptr_array_foreach(uiContainer(container)->children, doforall, &s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uiContainer_class_init(uiContainerClass *class)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS(class)->dispose = uiContainer_dispose;
|
|
|
|
G_OBJECT_CLASS(class)->finalize = uiContainer_finalize;
|
|
|
|
GTK_WIDGET_CLASS(class)->size_allocate = uiContainer_size_allocate;
|
|
|
|
GTK_CONTAINER_CLASS(class)->add = uiContainer_add;
|
|
|
|
GTK_CONTAINER_CLASS(class)->remove = uiContainer_remove;
|
|
|
|
GTK_CONTAINER_CLASS(class)->forall = uiContainer_forall;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *newContainer(void)
|
|
|
|
{
|
|
|
|
uiContainer *c;
|
|
|
|
|
|
|
|
c = uiContainer(g_object_new(uiContainerType, NULL));
|
|
|
|
return GTK_WIDGET(c);
|
|
|
|
}
|