added textfield and some container fixes (Motif)

Mon, 05 Jan 2015 11:49:46 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 05 Jan 2015 11:49:46 +0100
changeset 63
46a42f0c4f93
parent 62
70d2aee84432
child 64
6ef2c7f73a30

added textfield and some container fixes (Motif)

application/main.c file | annotate | diff | comparison | revisions
ui/motif/container.c file | annotate | diff | comparison | revisions
ui/motif/label.c file | annotate | diff | comparison | revisions
ui/motif/list.c file | annotate | diff | comparison | revisions
ui/motif/text.c file | annotate | diff | comparison | revisions
ui/motif/text.h file | annotate | diff | comparison | revisions
ui/ui/text.h file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Sun Jan 04 22:12:07 2015 +0100
+++ b/application/main.c	Mon Jan 05 11:49:46 2015 +0100
@@ -133,20 +133,16 @@
     */
     ui_layout_fill(window, FALSE);
     ui_grid(window);
-    ui_button(window, "Test", NULL, NULL);
-    ui_label(window, "Test");
-    ui_button(window, "Test", NULL, NULL);
+    ui_label(window, "Name");
+    ui_textfield(window, NULL);
     ui_newline(window);
-    ui_button(window, "Test_______", NULL, NULL);
-    ui_button(window, "Test", NULL, NULL);
+    ui_label(window, "Email");
+    ui_textfield(window, NULL);
     ui_newline(window);
-    ui_button(window, "Test", NULL, NULL);
-    ui_button(window, "Test", NULL, NULL);
-    ui_button(window, "Test", NULL, NULL);
     ui_end(window);
     
     ui_textarea_nv(window, "text");
-    
+    ui_button(window, "Submit", NULL, NULL);
     //ui_end(window);
     /*
     UiTabbedPane *view = ui_tabbed_document_view(window);
--- a/ui/motif/container.c	Sun Jan 04 22:12:07 2015 +0100
+++ b/ui/motif/container.c	Mon Jan 05 11:49:46 2015 +0100
@@ -247,7 +247,6 @@
             if(widget_height > rheight) {
                 rheight = widget_height;
             }
-            rowdim = ucx_list_append(rowdim, (void*)(intptr_t)rheight);
             
             // get the maximum width in this column
             if(widget_width > coldim[i]) {
@@ -263,6 +262,7 @@
                 numcol = i;
             }
         }
+        rowdim = ucx_list_append(rowdim, (void*)(intptr_t)rheight);
         sumh += rheight;
     }
     
@@ -284,7 +284,13 @@
         int i=0;
         UCX_FOREACH(elm, row->data) {
             Widget w = elm->data;
-            XtVaSetValues(w, XmNx, x, XmNy, y, NULL);
+            XtVaSetValues(
+                    w,
+                    XmNx, x,
+                    XmNy, y,
+                    XmNwidth, coldim[i],
+                    XmNheight, rowdim->data,
+                    NULL);
             
             x += coldim[i];
             i++;
--- a/ui/motif/label.c	Sun Jan 04 22:12:07 2015 +0100
+++ b/ui/motif/label.c	Mon Jan 05 11:49:46 2015 +0100
@@ -51,3 +51,20 @@
     
     return widget;
 }
+
+UIWIDGET ui_space(UiObject *obj) {
+    UiContainer *ct = uic_get_current_container(obj);
+    XmString str = XmStringCreateLocalized("");
+    
+    int n = 0;
+    Arg args[16]; 
+    XtSetArg(args[n], XmNlabelString, str);
+    n++;
+    
+    Widget parent = ct->prepare(ct, args, &n, TRUE);
+    Widget widget = XmCreateLabel(parent, "space_label", args, n);
+    ct->add(ct, widget);  
+    XtManageChild(widget);
+    
+    return widget;
+}
\ No newline at end of file
--- a/ui/motif/list.c	Sun Jan 04 22:12:07 2015 +0100
+++ b/ui/motif/list.c	Mon Jan 05 11:49:46 2015 +0100
@@ -60,7 +60,7 @@
     UiContainer *ct = uic_get_current_container(obj);
     Widget parent = ct->prepare(ct, args, &n, TRUE);
     Widget widget = XmCreateScrolledList(parent, "listview", args, n);
-    ct->add(ct, widget);
+    ct->add(ct, XtParent(widget));
     XtManageChild(widget);
     
     UiListView *listview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListView));
--- a/ui/motif/text.c	Sun Jan 04 22:12:07 2015 +0100
+++ b/ui/motif/text.c	Mon Jan 05 11:49:46 2015 +0100
@@ -44,7 +44,7 @@
     
     Widget parent = ct->prepare(ct, args, &n, TRUE);
     Widget text_area = XmCreateScrolledText(parent, "text_area", args, n);
-    ct->add(ct, text_area);
+    ct->add(ct, XtParent(text_area));
     XtManageChild(text_area);
     
     UiTextArea *uitext = ucx_mempool_malloc(
@@ -62,6 +62,7 @@
     if(value) {
         if(value->value) {
             XmTextSetString(text_area, value->value);
+            XtFree(value->value);
         }
         
         value->set = ui_textarea_set;
@@ -325,3 +326,63 @@
         mgr->cur = elm;
     }
 }
+
+
+/* ------------------------- textfield ------------------------- */
+
+UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
+    UiContainer *ct = uic_get_current_container(obj);
+    int n = 0;
+    Arg args[16];
+    XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT);
+    n++;
+    
+    Widget parent = ct->prepare(ct, args, &n, FALSE);
+    Widget textfield = XmCreateText(parent, "text_field", args, n);
+    ct->add(ct, textfield);
+    XtManageChild(textfield);
+    
+    // bind value
+    if(value) {
+        if(value->value) {
+            XmTextSetString(textfield, value->value);
+            XtFree(value->value);
+        }
+        
+        value->set = ui_textfield_set;
+        value->get = ui_textfield_get;
+        value->value = NULL;
+        value->obj = 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) {
+        XtFree(str->value);
+    }
+    char *value = XmTextGetString(str->obj);
+    str->value = value;
+    return value;
+}
+
+void ui_textfield_set(UiString *str, char *value) {
+    if(str->value) {
+        XtFree(str->value);
+    }
+    str->value = NULL;
+    XmTextSetString(str->obj, value);
+}
+
--- a/ui/motif/text.h	Sun Jan 04 22:12:07 2015 +0100
+++ b/ui/motif/text.h	Mon Jan 05 11:49:46 2015 +0100
@@ -76,6 +76,9 @@
 int ui_check_insertstr(char *oldstr, int oldlen, char *newstr, int newlen);
 void ui_free_textbuf_op(UiTextBufOp *op);
 
+char* ui_textfield_get(UiString *str);
+void ui_textfield_set(UiString *str, char *value);
+
 #ifdef	__cplusplus
 }
 #endif
--- a/ui/ui/text.h	Sun Jan 04 22:12:07 2015 +0100
+++ b/ui/ui/text.h	Mon Jan 05 11:49:46 2015 +0100
@@ -41,6 +41,9 @@
 void ui_text_undo(UiText *value);
 void ui_text_redo(UiText *value);
 
+UIWIDGET ui_textfield(UiObject *obj, UiString *value);
+UIWIDGET ui_textfield_nv(UiObject *obj, char *varname);
+
 #ifdef	__cplusplus
 }
 #endif
--- a/ui/ui/toolkit.h	Sun Jan 04 22:12:07 2015 +0100
+++ b/ui/ui/toolkit.h	Mon Jan 05 11:49:46 2015 +0100
@@ -310,6 +310,7 @@
 
 
 UIWIDGET ui_label(UiObject *obj, char *label);
+UIWIDGET ui_space(UiObject *obj);
 
 #ifdef	__cplusplus
 }

mercurial