2015-06-11 18:07:06 -05:00
|
|
|
// 11 june 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-08-27 15:17:18 -05:00
|
|
|
struct uiCombobox {
|
|
|
|
uiUnixControl c;
|
2015-06-11 18:07:06 -05:00
|
|
|
GtkWidget *widget;
|
2015-06-27 18:57:10 -05:00
|
|
|
GtkComboBox *combobox;
|
|
|
|
GtkComboBoxText *comboboxText;
|
2015-10-08 13:55:18 -05:00
|
|
|
void (*onSelected)(uiCombobox *, void *);
|
|
|
|
void *onSelectedData;
|
2015-10-09 12:54:34 -05:00
|
|
|
gulong onSelectedSignal;
|
2015-06-11 18:07:06 -05:00
|
|
|
};
|
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixControlAllDefaults(uiCombobox)
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-10-08 13:55:18 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:17:18 -05:00
|
|
|
void uiComboboxAppend(uiCombobox *c, const char *text)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-07-01 10:29:19 -05:00
|
|
|
gtk_combo_box_text_append(c->comboboxText, NULL, text);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 20:05:40 -05:00
|
|
|
int uiComboboxSelected(uiCombobox *c)
|
2015-10-08 13:55:18 -05:00
|
|
|
{
|
|
|
|
return gtk_combo_box_get_active(c->combobox);
|
|
|
|
}
|
|
|
|
|
2016-06-13 20:05:40 -05:00
|
|
|
void uiComboboxSetSelected(uiCombobox *c, int n)
|
2015-10-09 12:54:34 -05:00
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2015-10-08 13:55:18 -05:00
|
|
|
void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data)
|
|
|
|
{
|
|
|
|
c->onSelected = f;
|
|
|
|
c->onSelectedData = data;
|
|
|
|
}
|
|
|
|
|
2016-05-24 00:35:05 -05:00
|
|
|
uiCombobox *uiNewCombobox(void)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-08-27 15:17:18 -05:00
|
|
|
uiCombobox *c;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixNewControl(uiCombobox, c);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2016-05-24 00:35:05 -05:00
|
|
|
c->widget = gtk_combo_box_text_new();
|
2015-06-27 18:57:10 -05:00
|
|
|
c->combobox = GTK_COMBO_BOX(c->widget);
|
|
|
|
c->comboboxText = GTK_COMBO_BOX_TEXT(c->widget);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-10-09 12:54:34 -05:00
|
|
|
c->onSelectedSignal = g_signal_connect(c->widget, "changed", G_CALLBACK(onChanged), c);
|
2015-10-08 13:55:18 -05:00
|
|
|
uiComboboxOnSelected(c, defaultOnSelected, NULL);
|
|
|
|
|
2015-08-27 15:17:18 -05:00
|
|
|
return c;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|