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
|
// 11 june 2015
#include "uipriv_unix.h"
struct uiCombobox {
uiUnixControl c;
GtkWidget *widget;
GtkComboBox *combobox;
GtkComboBoxText *comboboxText;
void (*onSelected)(uiCombobox *, void *);
void *onSelectedData;
gulong onSelectedSignal;
};
uiUnixControlAllDefaults(uiCombobox)
static void onChanged(GtkComboBox *cbox, gpointer data)
{
uiCombobox *c = uiCombobox(data);
(*(c->onSelected))(c, c->onSelectedData);
}
static void defaultOnSelected(uiCombobox *c, void *data)
{
// do nothing
}
void uiComboboxAppend(uiCombobox *c, const char *text)
{
gtk_combo_box_text_append(c->comboboxText, NULL, text);
}
int uiComboboxSelected(uiCombobox *c)
{
return gtk_combo_box_get_active(c->combobox);
}
void uiComboboxSetSelected(uiCombobox *c, int n)
{
// we need to inhibit sending of ::changed because this WILL send a ::changed otherwise
g_signal_handler_block(c->combobox, c->onSelectedSignal);
gtk_combo_box_set_active(c->combobox, n);
g_signal_handler_unblock(c->combobox, c->onSelectedSignal);
}
void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data)
{
c->onSelected = f;
c->onSelectedData = data;
}
uiCombobox *uiNewCombobox(void)
{
uiCombobox *c;
uiUnixNewControl(uiCombobox, c);
c->widget = gtk_combo_box_text_new();
c->combobox = GTK_COMBO_BOX(c->widget);
c->comboboxText = GTK_COMBO_BOX_TEXT(c->widget);
c->onSelectedSignal = g_signal_connect(c->widget, "changed", G_CALLBACK(onChanged), c);
uiComboboxOnSelected(c, defaultOnSelected, NULL);
return c;
}
|