aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/unix/child.c
blob: b4a09677409cb9b4f030108488692ccdc71c0c74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// 28 august 2015
#include "uipriv_unix.h"

// This file contains helpers for managing child controls.

struct child {
	uiControl *c;
	GtkWidget *widget;

	gboolean oldhexpand;
	GtkAlign oldhalign;
	gboolean oldvexpand;
	GtkAlign oldvalign;

	// Some children can be boxed; that is, they can have an optionally-margined box around them.
	// uiGroup, uiTab, and uiWindow all do this.
	GtkWidget *box;

	// If the child is not boxed, this is its parent.
	// If the child is boxed, this is the box.
	GtkContainer *parent;

	// This flag is for users of these functions.
	// For uiBox, this is "spaced".
	// For uiTab, this is "margined". (uiGroup and uiWindow have to maintain their margined state themselves, since the margined state is independent of whether there is a child for those two.)
	int flag;
};

struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parentContainer)
{
	struct child *c;

	if (child == NULL)
		return NULL;

	c = uiNew(struct child);
	c->c = child;
	c->widget = GTK_WIDGET(uiControlHandle(c->c));

	c->oldhexpand = gtk_widget_get_hexpand(c->widget);
	c->oldhalign = gtk_widget_get_halign(c->widget);
	c->oldvexpand = gtk_widget_get_vexpand(c->widget);
	c->oldvalign = gtk_widget_get_valign(c->widget);

	uiControlSetParent(c->c, parent);
	uiUnixControlSetContainer(uiUnixControl(c->c), parentContainer, FALSE);
	c->parent = parentContainer;

	return c;
}

struct child *newChildWithBox(uiControl *child, uiControl *parent, GtkContainer *parentContainer, int margined)
{
	struct child *c;
	GtkWidget *box;

	if (child == NULL)
		return NULL;
	box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
	gtk_widget_show(box);
	c = newChild(child, parent, GTK_CONTAINER(box));
	gtk_widget_set_hexpand(c->widget, TRUE);
	gtk_widget_set_halign(c->widget, GTK_ALIGN_FILL);
	gtk_widget_set_vexpand(c->widget, TRUE);
	gtk_widget_set_valign(c->widget, GTK_ALIGN_FILL);
	c->box = box;
	gtk_container_add(parentContainer, c->box);
	childSetMargined(c, margined);
	return c;
}

void childRemove(struct child *c)
{
	uiControlSetParent(c->c, NULL);
	uiUnixControlSetContainer(uiUnixControl(c->c), c->parent, TRUE);

	gtk_widget_set_hexpand(c->widget, c->oldhexpand);
	gtk_widget_set_halign(c->widget, c->oldhalign);
	gtk_widget_set_vexpand(c->widget, c->oldvexpand);
	gtk_widget_set_valign(c->widget, c->oldvalign);

	if (c->box != NULL)
		gtk_widget_destroy(c->box);

	uiFree(c);
}

void childDestroy(struct child *c)
{
	uiControl *child;

	child = c->c;
	childRemove(c);
	uiControlDestroy(child);
}

GtkWidget *childWidget(struct child *c)
{
	return c->widget;
}

int childFlag(struct child *c)
{
	return c->flag;
}

void childSetFlag(struct child *c, int flag)
{
	c->flag = flag;
}

GtkWidget *childBox(struct child *c)
{
	return c->box;
}

void childSetMargined(struct child *c, int margined)
{
	setMargined(GTK_CONTAINER(c->box), margined);
}