2015-07-30 11:31:39 -05:00
|
|
|
// 7 april 2015
|
2015-07-30 11:43:40 -05:00
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2016-05-05 13:04:07 -05:00
|
|
|
struct boxChild {
|
|
|
|
uiControl *c;
|
|
|
|
int stretchy;
|
|
|
|
gboolean oldhexpand;
|
|
|
|
GtkAlign oldhalign;
|
|
|
|
gboolean oldvexpand;
|
|
|
|
GtkAlign oldvalign;
|
|
|
|
};
|
2015-07-30 11:31:39 -05:00
|
|
|
|
2015-08-27 14:30:55 -05:00
|
|
|
struct uiBox {
|
|
|
|
uiUnixControl c;
|
2015-07-30 11:31:39 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkContainer *container;
|
|
|
|
GtkBox *box;
|
2016-05-05 13:04:07 -05:00
|
|
|
GArray *controls;
|
2015-07-30 11:31:39 -05:00
|
|
|
int vertical;
|
|
|
|
int padded;
|
|
|
|
GtkSizeGroup *stretchygroup; // ensures all stretchy controls have the same size
|
|
|
|
};
|
|
|
|
|
2016-04-25 19:09:20 -05:00
|
|
|
uiUnixControlAllDefaultsExceptDestroy(uiBox)
|
2015-07-30 11:31:39 -05:00
|
|
|
|
2016-05-05 13:04:07 -05:00
|
|
|
#define ctrl(b, i) &g_array_index(b->controls, struct boxChild, i)
|
|
|
|
|
2016-04-25 19:09:20 -05:00
|
|
|
static void uiBoxDestroy(uiControl *c)
|
2015-07-30 11:31:39 -05:00
|
|
|
{
|
2016-04-25 19:09:20 -05:00
|
|
|
uiBox *b = uiBox(c);
|
2016-05-05 13:04:07 -05:00
|
|
|
struct boxChild *bc;
|
|
|
|
guint i;
|
2015-07-30 11:31:39 -05:00
|
|
|
|
|
|
|
// kill the size group
|
|
|
|
g_object_unref(b->stretchygroup);
|
2016-05-05 13:04:07 -05:00
|
|
|
// free all controls
|
|
|
|
for (i = 0; i < b->controls->len; i++) {
|
|
|
|
bc = ctrl(b, i);
|
|
|
|
uiControlSetParent(bc->c, NULL);
|
|
|
|
// and make sure the widget itself stays alive
|
|
|
|
uiUnixControlSetContainer(uiUnixControl(bc->c), b->container, TRUE);
|
|
|
|
uiControlDestroy(bc->c);
|
|
|
|
}
|
|
|
|
g_array_free(b->controls, TRUE);
|
2016-04-25 19:09:20 -05:00
|
|
|
// and then ourselves
|
|
|
|
g_object_unref(b->widget);
|
|
|
|
uiFreeControl(uiControl(b));
|
2015-07-30 11:31:39 -05:00
|
|
|
}
|
|
|
|
|
2015-08-27 14:30:55 -05:00
|
|
|
void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
|
2015-07-30 11:31:39 -05:00
|
|
|
{
|
2016-05-05 13:04:07 -05:00
|
|
|
struct boxChild bc;
|
2015-07-30 11:43:40 -05:00
|
|
|
GtkWidget *widget;
|
2015-07-30 11:31:39 -05:00
|
|
|
|
2016-05-05 13:04:07 -05:00
|
|
|
bc.c = c;
|
|
|
|
bc.stretchy = stretchy;
|
|
|
|
widget = GTK_WIDGET(uiControlHandle(bc.c));
|
|
|
|
bc.oldhexpand = gtk_widget_get_hexpand(widget);
|
|
|
|
bc.oldhalign = gtk_widget_get_halign(widget);
|
|
|
|
bc.oldvexpand = gtk_widget_get_vexpand(widget);
|
|
|
|
bc.oldvalign = gtk_widget_get_valign(widget);
|
|
|
|
|
|
|
|
if (bc.stretchy) {
|
2015-07-30 11:43:40 -05:00
|
|
|
if (b->vertical) {
|
|
|
|
gtk_widget_set_vexpand(widget, TRUE);
|
|
|
|
gtk_widget_set_valign(widget, GTK_ALIGN_FILL);
|
|
|
|
} else {
|
|
|
|
gtk_widget_set_hexpand(widget, TRUE);
|
|
|
|
gtk_widget_set_halign(widget, GTK_ALIGN_FILL);
|
|
|
|
}
|
|
|
|
gtk_size_group_add_widget(b->stretchygroup, widget);
|
2015-08-28 17:12:24 -05:00
|
|
|
} else
|
2015-07-30 11:43:40 -05:00
|
|
|
if (b->vertical)
|
|
|
|
gtk_widget_set_vexpand(widget, FALSE);
|
|
|
|
else
|
|
|
|
gtk_widget_set_hexpand(widget, FALSE);
|
2016-05-05 13:04:07 -05:00
|
|
|
// and make them fill the opposite direction
|
|
|
|
if (b->vertical) {
|
|
|
|
gtk_widget_set_hexpand(widget, TRUE);
|
|
|
|
gtk_widget_set_halign(widget, GTK_ALIGN_FILL);
|
|
|
|
} else {
|
|
|
|
gtk_widget_set_vexpand(widget, TRUE);
|
|
|
|
gtk_widget_set_valign(widget, GTK_ALIGN_FILL);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiControlSetParent(bc.c, uiControl(b));
|
|
|
|
uiUnixControlSetContainer(uiUnixControl(bc.c), b->container, FALSE);
|
|
|
|
g_array_append_val(b->controls, bc);
|
2015-07-30 11:31:39 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 19:46:11 -05:00
|
|
|
void uiBoxDelete(uiBox *b, int index)
|
2015-07-30 11:31:39 -05:00
|
|
|
{
|
2016-05-05 13:04:07 -05:00
|
|
|
struct boxChild *bc;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
bc = ctrl(b, index);
|
|
|
|
widget = GTK_WIDGET(uiControlHandle(bc->c));
|
|
|
|
|
|
|
|
uiControlSetParent(bc->c, NULL);
|
|
|
|
uiUnixControlSetContainer(uiUnixControl(bc->c), b->container, TRUE);
|
|
|
|
|
|
|
|
if (bc->stretchy)
|
|
|
|
gtk_size_group_remove_widget(b->stretchygroup, widget);
|
|
|
|
gtk_widget_set_hexpand(widget, bc->oldhexpand);
|
|
|
|
gtk_widget_set_halign(widget, bc->oldhalign);
|
|
|
|
gtk_widget_set_vexpand(widget, bc->oldvexpand);
|
|
|
|
gtk_widget_set_valign(widget, bc->oldvalign);
|
2015-07-30 11:31:39 -05:00
|
|
|
|
2016-05-05 13:04:07 -05:00
|
|
|
g_array_remove_index(b->controls, index);
|
2015-07-30 11:31:39 -05:00
|
|
|
}
|
|
|
|
|
2015-08-27 14:30:55 -05:00
|
|
|
int uiBoxPadded(uiBox *b)
|
2015-07-30 11:31:39 -05:00
|
|
|
{
|
|
|
|
return b->padded;
|
|
|
|
}
|
|
|
|
|
2015-08-27 14:30:55 -05:00
|
|
|
void uiBoxSetPadded(uiBox *b, int padded)
|
2015-07-30 11:31:39 -05:00
|
|
|
{
|
|
|
|
b->padded = padded;
|
|
|
|
if (b->padded)
|
|
|
|
if (b->vertical)
|
|
|
|
gtk_box_set_spacing(b->box, gtkYPadding);
|
|
|
|
else
|
|
|
|
gtk_box_set_spacing(b->box, gtkXPadding);
|
|
|
|
else
|
|
|
|
gtk_box_set_spacing(b->box, 0);
|
|
|
|
}
|
|
|
|
|
2015-07-30 11:43:40 -05:00
|
|
|
static uiBox *finishNewBox(GtkOrientation orientation)
|
2015-07-30 11:31:39 -05:00
|
|
|
{
|
2015-08-27 14:30:55 -05:00
|
|
|
uiBox *b;
|
2015-07-30 11:31:39 -05:00
|
|
|
|
2016-04-25 19:09:20 -05:00
|
|
|
uiUnixNewControl(uiBox, b);
|
2015-07-30 11:31:39 -05:00
|
|
|
|
|
|
|
b->widget = gtk_box_new(orientation, 0);
|
|
|
|
b->container = GTK_CONTAINER(b->widget);
|
|
|
|
b->box = GTK_BOX(b->widget);
|
|
|
|
|
|
|
|
b->vertical = orientation == GTK_ORIENTATION_VERTICAL;
|
|
|
|
|
|
|
|
if (b->vertical)
|
|
|
|
b->stretchygroup = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL);
|
|
|
|
else
|
|
|
|
b->stretchygroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
|
2016-05-05 13:04:07 -05:00
|
|
|
b->controls = g_array_new(FALSE, TRUE, sizeof (struct boxChild));
|
2015-07-30 11:31:39 -05:00
|
|
|
|
2015-08-27 14:30:55 -05:00
|
|
|
return b;
|
2015-07-30 11:31:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiBox *uiNewHorizontalBox(void)
|
|
|
|
{
|
|
|
|
return finishNewBox(GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiBox *uiNewVerticalBox(void)
|
|
|
|
{
|
|
|
|
return finishNewBox(GTK_ORIENTATION_VERTICAL);
|
|
|
|
}
|