summaryrefslogtreecommitdiff
path: root/new/button_unix.c
blob: 2d341cc3da9167d70ac1da70dc573edcba5aae73 (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
// 7 april 2015
#include "uipriv_unix.h"

struct button {
	uiControl *c;
	void (*onClicked)(uiControl *, void *);
	void *onClickedData;
};

#define B(x) ((struct button *) (x))

static void onClicked(GtkButton *b, gpointer data)
{
	(*(B(data)->onClicked))(B(data)->c, B(data)->onClickedData);
}

static void defaultOnClicked(uiControl *c, void *data)
{
	// do nothing
}

// TODO destruction
uiControl *uiNewButton(const char *text)
{
	struct button *b;
	GParameter props[1];
	GtkWidget *widget;

	b = g_new0(struct button, 1);

	props[0].name = "label";
	g_value_init(&(props[0].value), G_TYPE_STRING);
	g_value_set_string(&(props[0].value), text);
	b->c = uiUnixNewControl(GTK_TYPE_BUTTON,
		1, props,
		FALSE, FALSE, FALSE, b);
	g_value_unset(&(props[0].value));		// thanks to gregier in irc.gimp.net/#gtk+

	widget = GTK_WIDGET(uiControlHandle(b->c));
	g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b);

	b->onClicked = defaultOnClicked;

	return b->c;
}

// TODO text

void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
{
	struct button *b;

	b = (struct button *) uiUnixControlData(c);
	b->onClicked = f;
	b->onClickedData = data;
}