Implemented uiEntryOnChanged() on GTK+.

This commit is contained in:
Pietro Gagliardi 2015-05-06 20:37:42 -04:00
parent 5128fed0af
commit 180a17a235
1 changed files with 26 additions and 0 deletions

View File

@ -5,8 +5,22 @@ struct entry {
uiEntry e;
GtkWidget *widget;
GtkEntry *entry;
void (*onChanged)(uiEntry *, void *);
void *onChangedData;
};
static void onChanged(GtkEditable *editable, gpointer data)
{
struct entry *e = (struct entry *) data;
(*(e->onChanged))(uiEntry(e), e->onChangedData);
}
static void defaultOnChanged(uiEntry *e, void *data)
{
// do nothing
}
static void onDestroy(void *data)
{
struct entry *e = (struct entry *) data;
@ -28,6 +42,14 @@ static void entrySetText(uiEntry *ee, const char *text)
gtk_entry_set_text(e->entry, text);
}
static void entryOnChanged(uiEntry *ee, void (*f)(uiEntry *, void *), void *data)
{
struct entry *e = (struct entry *) ee;
e->onChanged = f;
e->onChangedData = data;
}
uiEntry *uiNewEntry(void)
{
struct entry *e;
@ -41,8 +63,12 @@ uiEntry *uiNewEntry(void)
e->widget = GTK_WIDGET(uiControlHandle(uiControl(e)));
e->entry = GTK_ENTRY(e->widget);
g_signal_connect(e->widget, "changed", G_CALLBACK(onChanged), e);
e->onChanged = defaultOnChanged;
uiEntry(e)->Text = entryText;
uiEntry(e)->SetText = entrySetText;
uiEntry(e)->OnChanged = entryOnChanged;
return uiEntry(e);
}