ui/gtk/text.c

changeset 65
4697592e24ba
parent 59
eb6611be50c7
child 90
2019fdbaadfd
--- a/ui/gtk/text.c	Mon Jan 05 14:47:19 2015 +0100
+++ b/ui/gtk/text.c	Mon Jan 05 18:47:07 2015 +0100
@@ -445,3 +445,52 @@
         mgr->cur = elm;
     }
 }
+
+
+UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
+    GtkWidget *textfield = gtk_entry_new();
+    UiContainer *ct = uic_get_current_container(obj);
+    ct->add(ct, textfield, FALSE);
+    
+    if(value) {
+        if(value->value) {
+            gtk_entry_set_text(GTK_ENTRY(textfield), value->value);
+            g_free(value->value);
+            // TODO: free value
+        }
+        
+        value->get = ui_textfield_get;
+        value->set = ui_textfield_set;
+        value->value = NULL;
+        value->obj = GTK_ENTRY(textfield);
+    }
+    
+    return textfield;
+}
+
+UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
+    UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING);
+    if(var) {
+        UiString *value = var->value;
+        return ui_textfield(obj, value);
+    } else {
+        // TODO: error
+    }
+    return NULL;
+}
+
+char* ui_textfield_get(UiString *str) {
+    if(str->value) {
+        g_free(str->value);
+    }
+    str->value = g_strdup(gtk_entry_get_text(str->obj));
+    return str->value;
+}
+
+void ui_textfield_set(UiString *str, char *value) {
+    if(str->value) {
+        g_free(str->value);
+    }
+    str->value = NULL;
+    gtk_entry_set_text(str->obj, value);
+}

mercurial