summaryrefslogtreecommitdiff
path: root/redo/container_unix.c
blob: c7a71dd694100529b35187560a773496f6f3bf87 (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
/* 13 august 2014 */

#include "gtk_unix.h"
#include "_cgo_export.h"

#define GOCONTAINER_TYPE (goContainer_get_type())
#define GOCONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GOCONTAINER_TYPE, goContainer))
#define IS_GOCONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GOCONTAINER_TYPE))
#define GOCONTAINER_CLASS(class) (G_TYPE_CHECK_CLASS_CAST((class), GOCONTAINER_TYPE, goContainerClass))
#define IS_GOCONTAINER_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE((class), GOCONTAINER_TYPE))
#define GOCONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GOCONTAINER_TYPE, goContainerClass))

typedef struct goContainer goContainer;
typedef struct goContainerClass goContainerClass;

struct goContainer {
	GtkContainer parent_instance;
	void *gocontainer;
	GPtrArray *children;		/* for forall() */
};

struct goContainerClass {
	GtkContainerClass parent_class;
};

G_DEFINE_TYPE(goContainer, goContainer, GTK_TYPE_CONTAINER)

static void goContainer_init(goContainer *c)
{
	c->children = g_ptr_array_new();
	gtk_widget_set_has_window(GTK_WIDGET(c), FALSE);
}

static void goContainer_dispose(GObject *obj)
{
	g_ptr_array_unref(GOCONTAINER(obj)->children);
	G_OBJECT_CLASS(goContainer_parent_class)->dispose(obj);
}

static void goContainer_finalize(GObject *obj)
{
	G_OBJECT_CLASS(goContainer_parent_class)->finalize(obj);
}

static void goContainer_add(GtkContainer *container, GtkWidget *widget)
{
	gtk_widget_set_parent(widget, GTK_WIDGET(container));
	g_ptr_array_add(GOCONTAINER(container)->children, widget);
}

static void goContainer_remove(GtkContainer *container, GtkWidget *widget)
{
	gtk_widget_unparent(widget);
	g_ptr_array_remove(GOCONTAINER(container)->children, widget);
}

static void goContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
	gtk_widget_set_allocation(widget, allocation);
	containerResizing(GOCONTAINER(widget)->gocontainer, allocation);
}

/*
static void goContainer_get_preferred_width(GtkWidget *widget, gint *min, gint *nat)
{
	if (GOCONTAINER(widget)->child != NULL) {
		gtk_widget_get_preferred_width(GOCONTAINER(widget)->child, min, nat);
		return;
	}
	if (min != NULL)
		*min = 0;
	if (nat != NULL)
		*nat = 0;
}

static void goContainer_get_preferred_height(GtkWidget *widget, gint *min, gint *nat)
{
	if (GOCONTAINER(widget)->child != NULL) {
		gtk_widget_get_preferred_height(GOCONTAINER(widget)->child, min, nat);
		return;
	}
	if (min != NULL)
		*min = 0;
	if (nat != NULL)
		*nat = 0;
}
*/

static void goContainer_forall(GtkContainer *container, gboolean includeInternals, GtkCallback callback, gpointer data)
{
	/* TODO is this safe? */
	g_ptr_array_foreach(GOCONTAINER(container)->children, callback, data);
}

static void goContainer_class_init(goContainerClass *class)
{
	G_OBJECT_CLASS(class)->dispose = goContainer_dispose;
	G_OBJECT_CLASS(class)->finalize = goContainer_finalize;
	GTK_WIDGET_CLASS(class)->size_allocate = goContainer_size_allocate;
//	GTK_WIDGET_CLASS(class)->get_preferred_width = goContainer_get_preferred_width;
//	GTK_WIDGET_CLASS(class)->get_preferred_height = goContainer_get_preferred_height;
	GTK_CONTAINER_CLASS(class)->add = goContainer_add;
	GTK_CONTAINER_CLASS(class)->remove = goContainer_remove;
	GTK_CONTAINER_CLASS(class)->forall = goContainer_forall;
}

GtkWidget *newContainer(void *gocontainer)
{
	goContainer *c;

	c = (goContainer *) g_object_new(GOCONTAINER_TYPE, NULL);
	c->gocontainer = gocontainer;
	return GTK_WIDGET(c);
}