Split uiCombobox on GTK+.

This commit is contained in:
Pietro Gagliardi 2016-05-24 01:35:05 -04:00
parent b9bc71a9ba
commit e8cedf502f
3 changed files with 82 additions and 13 deletions

View File

@ -16,6 +16,7 @@ CFILES += \
unix/drawmatrix.c \
unix/drawpath.c \
unix/drawtext.c \
unix/editablecombo.c \
unix/entry.c \
unix/fontbutton.c \
unix/group.c \

View File

@ -13,7 +13,6 @@ struct uiCombobox {
uiUnixControlAllDefaults(uiCombobox)
// TODO this is triggered when editing an editable combobox's text
static void onChanged(GtkComboBox *cbox, gpointer data)
{
uiCombobox *c = uiCombobox(data);
@ -50,13 +49,13 @@ void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), v
c->onSelectedData = data;
}
static uiCombobox *finishNewCombobox(GtkWidget *(*newfunc)(void))
uiCombobox *uiNewCombobox(void)
{
uiCombobox *c;
uiUnixNewControl(uiCombobox, c);
c->widget = (*newfunc)();
c->widget = gtk_combo_box_text_new();
c->combobox = GTK_COMBO_BOX(c->widget);
c->comboboxText = GTK_COMBO_BOX_TEXT(c->widget);
@ -65,13 +64,3 @@ static uiCombobox *finishNewCombobox(GtkWidget *(*newfunc)(void))
return c;
}
uiCombobox *uiNewCombobox(void)
{
return finishNewCombobox(gtk_combo_box_text_new);
}
uiCombobox *uiNewEditableCombobox(void)
{
return finishNewCombobox(gtk_combo_box_text_new_with_entry);
}

79
unix/editablecombo.c Normal file
View File

@ -0,0 +1,79 @@
// 11 june 2015
#include "uipriv_unix.h"
struct uiEditableCombobox {
uiUnixControl c;
GtkWidget *widget;
GtkBin *bin;
GtkComboBox *combobox;
GtkComboBoxText *comboboxText;
void (*onChanged)(uiEditableCombobox *, void *);
void *onChangedData;
gulong onChangedSignal;
};
uiUnixControlAllDefaults(uiEditableCombobox)
static void onChanged(GtkComboBox *cbox, gpointer data)
{
uiEditableCombobox *c = uiEditableCombobox(data);
(*(c->onChanged))(c, c->onChangedData);
}
static void defaultOnChanged(uiEditableCombobox *c, void *data)
{
// do nothing
}
void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text)
{
gtk_combo_box_text_append(c->comboboxText, NULL, text);
}
char *uiEditableComboboxText(uiEditableCombobox *c)
{
char *s;
char *out;
s = gtk_combo_box_text_get_active_text(c->comboboxText);
// s will always be non-NULL in the case of a combobox with an entry (according to the source code)
out = uiUnixStrdupText(s);
g_free(s);
return out;
}
void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text)
{
GtkEntry *e;
// we need to inhibit sending of ::changed because this WILL send a ::changed otherwise
g_signal_handler_block(c->combobox, c->onChangedSignal);
// since there isn't a gtk_combo_box_text_set_active_text()...
e = GTK_ENTRY(gtk_bin_get_child(c->bin));
gtk_entry_set_text(e, text);
g_signal_handler_unblock(c->combobox, c->onChangedSignal);
}
void uiEditableComboboxOnChanged(uiEditableCombobox *c, void (*f)(uiEditableCombobox *c, void *data), void *data)
{
c->onChanged = f;
c->onChangedData = data;
}
uiEditableCombobox *uiNewEditableCombobox(void)
{
uiEditableCombobox *c;
uiUnixNewControl(uiEditableCombobox, c);
c->widget = gtk_combo_box_text_new_with_entry();
c->bin = GTK_BIN(c->widget);
c->combobox = GTK_COMBO_BOX(c->widget);
c->comboboxText = GTK_COMBO_BOX_TEXT(c->widget);
c->onChangedSignal = g_signal_connect(c->widget, "changed", G_CALLBACK(onChanged), c);
uiEditableComboboxOnChanged(c, defaultOnChanged, NULL);
return c;
}