implement ui_getvaluefunc2 (Motif)

Thu, 26 Jun 2025 18:42:20 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 26 Jun 2025 18:42:20 +0200
changeset 639
55eb8a87d3e5
parent 638
51adf061e18f
child 640
c948819bdfb2

implement ui_getvaluefunc2 (Motif)

ui/motif/list.c file | annotate | diff | comparison | revisions
ui/motif/list.h file | annotate | diff | comparison | revisions
--- a/ui/motif/list.c	Thu Jun 26 18:29:37 2025 +0200
+++ b/ui/motif/list.c	Thu Jun 26 18:42:20 2025 +0200
@@ -34,6 +34,22 @@
 #include "list.h"
 #include "../common/object.h"
 
+static void* getvalue_wrapper(UiList *list, void *elm, int row, int col, void *userdata, UiBool *freeResult) {
+    ui_getvaluefunc getvalue = (ui_getvaluefunc)userdata;
+    return getvalue(elm, col);
+}
+
+/*
+static void* model_getvalue(UiModel *model, UiList *list, void *elm, int row, int col, UiBool *freeResult) {
+    if(model->getvalue2) {
+        return model->getvalue2(list, elm, row, col, model->getvalue2data, freeResult);
+    } else if(model->getvalue) {
+        return model->getvalue(elm, col);
+    }
+    return NULL;
+}
+*/
+
 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs *args) {
     Arg xargs[16];
     int n = 0;
@@ -58,7 +74,16 @@
     memset(listview, 0, sizeof(UiListView));
     listview->obj = obj;
     listview->widget = widget;
-    listview->getvalue = args->getvalue ? args->getvalue : ui_strmodel_getvalue;
+    if(args->getvalue2) {
+        listview->getvalue = args->getvalue2;
+        listview->getvaluedata = args->getvalue2data;
+    } else if(args->getvalue) {
+        listview->getvalue = getvalue_wrapper;
+        listview->getvaluedata = args->getvalue;
+    } else {
+        listview->getvalue = getvalue_wrapper;
+        listview->getvaluedata = ui_strmodel_getvalue;
+    }
     listview->var = var;
     listview->onactivate = args->onactivate;
     listview->onactivatedata = args->onactivatedata;
@@ -139,13 +164,17 @@
     }
 }
 
-static XmStringTable create_stringlist(UiList *list, ui_getvaluefunc getvalue, int *count) { 
+static XmStringTable create_stringlist(UiList *list, ui_getvaluefunc2 getvalue, void *getvaluedata, int *count) { 
     int num = list->count(list);
     XmStringTable items = (XmStringTable)XtMalloc(num * sizeof(XmString));
     void *data = list->first(list);
     for(int i=0;i<num;i++) {
-        char *s = getvalue(data, 0);
+        UiBool freevalue = FALSE;
+        char *s = getvalue(list, data, i, 0, getvaluedata, &freevalue);
         items[i] = XmStringCreateLocalized(s ? s : "");
+        if(freevalue) {
+            free(s);
+        }
         data = list->next(list);
     }
     
@@ -160,6 +189,7 @@
     XmStringTable items = create_stringlist(
             list,
             listview->getvalue,
+            listview->getvaluedata,
             &count);
     
     XtVaSetValues(
@@ -245,7 +275,16 @@
     memset(listview, 0, sizeof(UiListView));
     listview->obj = obj;
     listview->widget = widget;
-    listview->getvalue = args->getvalue ? args->getvalue : ui_strmodel_getvalue;
+    if(args->getvalue2) {
+        listview->getvalue = args->getvalue2;
+        listview->getvaluedata = args->getvalue2data;
+    } else if(args->getvalue) {
+        listview->getvalue = getvalue_wrapper;
+        listview->getvaluedata = args->getvalue;
+    } else {
+        listview->getvalue = getvalue_wrapper;
+        listview->getvaluedata = ui_strmodel_getvalue;
+    }
     listview->var = var;
     listview->onactivate = args->onactivate;
     listview->onactivatedata = args->onactivatedata;
--- a/ui/motif/list.h	Thu Jun 26 18:29:37 2025 +0200
+++ b/ui/motif/list.h	Thu Jun 26 18:42:20 2025 +0200
@@ -42,7 +42,8 @@
     Widget widget;
     UiVar *var;
     UiModel* model;
-    ui_getvaluefunc getvalue;
+    ui_getvaluefunc2 getvalue;
+    void *getvaluedata;
     
     UiListSelection current_selection;
     

mercurial