fixed list, text and added ui_close (Motif)

Sun, 11 May 2014 11:35:33 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 11 May 2014 11:35:33 +0200
changeset 36
e4198fc2ead4
parent 35
3e8b5c9b4033
child 37
56016468753d

fixed list, text and added ui_close (Motif)

ui/motif/container.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/toolbar.c file | annotate | diff | comparison | revisions
ui/motif/toolkit.c file | annotate | diff | comparison | revisions
ui/motif/toolkit.h file | annotate | diff | comparison | revisions
ui/motif/window.c file | annotate | diff | comparison | revisions
--- a/ui/motif/container.c	Sun May 11 10:41:29 2014 +0200
+++ b/ui/motif/container.c	Sun May 11 11:35:33 2014 +0200
@@ -63,7 +63,7 @@
     XtSetArg(args[0], XmNshadowType, XmSHADOW_ETCHED_OUT);
     XtSetArg(args[1], XmNshadowThickness, 0);
     Widget sidebar = XmCreateFrame(pane, "sidebar", args, 2);
-    //XtManageChild(sidebar);
+    XtManageChild(sidebar);
     
     UiObject *left = uic_object_new(obj, sidebar);
     left->container = ui_frame_container(left, sidebar);
--- a/ui/motif/list.c	Sun May 11 10:41:29 2014 +0200
+++ b/ui/motif/list.c	Sun May 11 11:35:33 2014 +0200
@@ -47,21 +47,14 @@
 UIWIDGET ui_listview_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
     UiList *ls = list->list;
     
-    //int count;
-    //XmStringTable items = ui_create_stringlist(list->list, getvalue, &count);
-    int count = list->list->count(list->list);
-    XmStringTable items = (XmStringTable)XtMalloc(count * sizeof(XmString));
-    void *data = list->list->first(list->list);
-    for(int i=0;i<count;i++) {
-        items[i] = XmStringCreateLocalized(getvalue(data, 0));
-        data = list->list->next(list->list);
-    }
+    int count;
+    XmStringTable items = ui_create_stringlist(list->list, getvalue, &count);
     
     Arg args[8];
     int n = 0;
     XtSetArg(args[n], XmNitemCount, count);
     n++;
-    XtSetArg(args[n], XmNitems, NULL);
+    XtSetArg(args[n], XmNitems, count == 0 ? NULL : items);
     n++;
     
     UiContainer *ct = uic_get_current_container(obj);
@@ -142,7 +135,12 @@
             view->getvalue,
             &count);
     
-    XtVaSetValues(view->widget, XmNitems, items, XmNitemCount, count, NULL);
+    XtVaSetValues(
+            view->widget,
+            XmNitems, count == 0 ? NULL : items,
+            XmNitemCount,
+            count,
+            NULL);
     
     for (int i=0;i<count;i++) {
         XmStringFree(items[i]);
--- a/ui/motif/text.c	Sun May 11 10:41:29 2014 +0200
+++ b/ui/motif/text.c	Sun May 11 11:35:33 2014 +0200
@@ -59,6 +59,10 @@
     
     // bind value
     if(value) {
+        if(value->value) {
+            XmTextSetString(text_area, value->value);
+        }
+        
         value->set = ui_textarea_set;
         value->get = ui_textarea_get;
         value->getsubstr = ui_textarea_getsubstr;
--- a/ui/motif/toolbar.c	Sun May 11 10:41:29 2014 +0200
+++ b/ui/motif/toolbar.c	Sun May 11 11:35:33 2014 +0200
@@ -191,7 +191,8 @@
     XmString label = XmStringCreateLocalized(item->label);
     XtSetArg(args[0], XmNlabelString, label);
     XtSetArg(args[1], XmNshadowThickness, 1);
-    Widget button = XmCreatePushButton(parent, "toolbar_button", args, 2);
+    XtSetArg(args[2], XmNtraversalOn, FALSE);
+    Widget button = XmCreatePushButton(parent, "toolbar_button", args, 3);
     
     XmStringFree(label);
     
@@ -224,8 +225,8 @@
     XmString label = XmStringCreateLocalized(stock_item->label);
     XtSetArg(args[0], XmNlabelString, label);
     XtSetArg(args[1], XmNshadowThickness, 1);
-    //XtSetArg(args[2], XmNhighlightThickness, 0);
-    Widget button = XmCreatePushButton(parent, "toolbar_button", args, 2);
+    XtSetArg(args[2], XmNtraversalOn, FALSE);
+    Widget button = XmCreatePushButton(parent, "toolbar_button", args, 3);
     
     XmStringFree(label);
     
@@ -256,8 +257,9 @@
     XmString label = XmStringCreateLocalized(item->label);
     XtSetArg(args[0], XmNlabelString, label);
     XtSetArg(args[1], XmNshadowThickness, 1);
-    XtSetArg(args[2], XmNindicatorOn, XmINDICATOR_NONE);
-    Widget button = XmCreateToggleButton(parent, "toolbar_toggle_button", args, 3);
+    XtSetArg(args[2], XmNtraversalOn, FALSE);
+    XtSetArg(args[3], XmNindicatorOn, XmINDICATOR_NONE);
+    Widget button = XmCreateToggleButton(parent, "toolbar_toggle_button", args, 4);
     
     XmStringFree(label);
     
--- a/ui/motif/toolkit.c	Sun May 11 10:41:29 2014 +0200
+++ b/ui/motif/toolkit.c	Sun May 11 11:35:33 2014 +0200
@@ -83,7 +83,12 @@
         fprintf(stderr, "UiError: Cannot create event pipe\n");
         exit(-1);
     }
-    XtAppAddInput(app, event_pipe[0], XtInputReadMask, input_proc, NULL);
+    XtAppAddInput(
+            app,
+            event_pipe[0],
+            (XtPointer)XtInputReadMask,
+            input_proc,
+            NULL);
 }
 
 char* ui_appname() {
@@ -111,6 +116,10 @@
     uic_store_app_properties();
 }
 
+void ui_exit_mainloop() {
+    XtAppSetExitFlag(app);
+}
+
 void ui_secondary_event_loop(int *loop) {
     while(*loop && !XtAppGetExitFlag(app)) {
         XEvent event;
@@ -124,9 +133,8 @@
     XtRealizeWidget(obj->widget);
 }
 
-void ui_close(UiObject *obj) {
-    // TODO
-}
+// implemented in window.c
+//void ui_close(UiObject *obj)
 
 void ui_set_enabled(UIWIDGET widget, int enabled) {
     XtSetSensitive(widget, enabled);
--- a/ui/motif/toolkit.h	Sun May 11 10:41:29 2014 +0200
+++ b/ui/motif/toolkit.h	Sun May 11 11:35:33 2014 +0200
@@ -54,6 +54,8 @@
     void          *finish_data;
 } UiJob;
 
+void ui_exit_mainloop();
+
 void ui_set_active_window(Widget w);
 Widget ui_get_active_window();
 
--- a/ui/motif/window.c	Sun May 11 10:41:29 2014 +0200
+++ b/ui/motif/window.c	Sun May 11 11:35:33 2014 +0200
@@ -44,7 +44,7 @@
 static void window_close_handler(Widget window, void *udata, void *cdata) {
     nwindows--;
     if(nwindows == 0) {
-        exit(0);
+        ui_exit_mainloop();
     }
 }
 
@@ -128,6 +128,11 @@
     return obj;
 }
 
+void ui_close(UiObject *obj) {
+    XtDestroyWidget(obj->widget);
+    window_close_handler(obj->widget, obj, NULL);
+}
+
 typedef struct FileDialogData {
     int  running;
     char *file;

mercurial