fix listview get/set selection functions (Motif)

Tue, 18 Nov 2025 15:56:59 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 18 Nov 2025 15:56:59 +0100
changeset 912
06c37c12d149
parent 911
c8e1d40eeab6
child 913
3012ec57d84a

fix listview get/set selection functions (Motif)

application/demo_bindings.c file | annotate | diff | comparison | revisions
ui/motif/list.c file | annotate | diff | comparison | revisions
--- a/application/demo_bindings.c	Tue Nov 18 15:41:45 2025 +0100
+++ b/application/demo_bindings.c	Tue Nov 18 15:56:59 2025 +0100
@@ -118,9 +118,6 @@
     ui_attach_document(obj->ctx, doc);
     
     ui_list_setselection(wdata->doclist, 0);
-    UiListSelection sel = wdata->doclist->getselection(wdata->doclist);
-    int x = sel.rows[0];
-    
     
     ui_show(obj);
 }
--- a/ui/motif/list.c	Tue Nov 18 15:41:45 2025 +0100
+++ b/ui/motif/list.c	Tue Nov 18 15:56:59 2025 +0100
@@ -217,10 +217,18 @@
 
 UiListSelection ui_listview_getselection(UiList *list) {
     UiListView *listview = list->obj;
-    UiListSelection sel = { listview->current_selection.count, NULL };
-    if(sel.count > 0) {
-        sel.rows = calloc(sel.count, sizeof(int));
-        memcpy(sel.rows, listview->current_selection.rows, sel.count*sizeof(int));
+    UiListSelection sel = { 0, NULL };
+    int *selpositions = NULL;
+    int numpos = 0;
+    XtVaGetValues(listview->widget, XmNselectedPositions, &selpositions, XmNselectedPositionCount, &numpos, NULL);
+    if(numpos > 0) {
+        sel.rows = calloc(numpos, sizeof(int));
+        sel.count = numpos;
+        memcpy(sel.rows, selpositions, numpos*sizeof(int));
+        // motif selected positions start at index 1 -> translate positions
+        for(int i=0;i<numpos;i++) {
+            sel.rows[i]--;
+        }
     }
     return sel;
 }

mercurial