From 180a17a2355ea5b399437f67ffa0acc7a87ca5b4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 6 May 2015 20:37:42 -0400 Subject: [PATCH] Implemented uiEntryOnChanged() on GTK+. --- unix/entry.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/unix/entry.c b/unix/entry.c index 8bbf49d7..340fc793 100644 --- a/unix/entry.c +++ b/unix/entry.c @@ -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); }