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
|
// 10 june 2015
#include "uipriv_unix.h"
struct uiButton {
uiUnixControl c;
GtkWidget *widget;
GtkButton *button;
void (*onClicked)(uiButton *, void *);
void *onClickedData;
};
uiUnixControlAllDefaults(uiButton)
static void onClicked(GtkButton *button, gpointer data)
{
uiButton *b = uiButton(data);
(*(b->onClicked))(b, b->onClickedData);
}
static void defaultOnClicked(uiButton *b, void *data)
{
// do nothing
}
char *uiButtonText(uiButton *b)
{
return uiUnixStrdupText(gtk_button_get_label(b->button));
}
void uiButtonSetText(uiButton *b, const char *text)
{
gtk_button_set_label(b->button, text);
}
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
{
b->onClicked = f;
b->onClickedData = data;
}
uiButton *uiNewButton(const char *text)
{
uiButton *b;
uiUnixNewControl(uiButton, b);
b->widget = gtk_button_new_with_label(text);
b->button = GTK_BUTTON(b->widget);
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
uiButtonOnClicked(b, defaultOnClicked, NULL);
return b;
}
|