ui/motif/list.c

changeset 911
c8e1d40eeab6
parent 910
311bebe6aa82
child 912
06c37c12d149
--- a/ui/motif/list.c	Tue Nov 18 13:52:49 2025 +0100
+++ b/ui/motif/list.c	Tue Nov 18 15:41:45 2025 +0100
@@ -61,7 +61,7 @@
     if(args->multiselection) {
         XtSetArg(xargs[n], XmNselectionPolicy, XmEXTENDED_SELECT); n++;
     } else {
-        //XtSetArg(xargs[n], XmNselectionPolicy, XmSINGLE_SELECT); n++;
+        XtSetArg(xargs[n], XmNselectionPolicy, XmSINGLE_SELECT); n++;
     }
     if(args->height > 0) {
         XtSetArg(xargs[n], XmNheight, args->height); n++;
@@ -307,8 +307,8 @@
         UiList *list = var->value;
         list->obj = listview;
         list->update = ui_listview_update;
-        list->getselection = ui_listview_getselection;
-        list->setselection = ui_listview_setselection;
+        list->getselection = ui_dropdown_getselection;
+        list->setselection = ui_dropdown_setselection;
         ui_listview_update(list, 0);
     }
     
@@ -325,3 +325,25 @@
     
     return widget;
 }
+
+void ui_dropdown_setselection(UiList *list, UiListSelection selection) {
+    UiListView *listview = list->obj;
+    if(selection.count > 0) {
+        XtVaSetValues(listview->widget, XmNselectedPosition, selection.rows[0], NULL);
+    } else {
+        XtVaSetValues(listview->widget, XmNselectedPosition, 0, NULL);
+    }
+}
+
+UiListSelection ui_dropdown_getselection(UiList *list) {
+    UiListView *listview = list->obj;
+    int pos = -1;
+    XtVaGetValues(listview->widget, XmNselectedPosition, &pos, NULL);
+    UiListSelection sel = { 0, NULL };
+    if(pos >= 0) {
+        sel.rows = malloc(sizeof(int));
+        sel.rows[0] = pos;
+        sel.count = 1;
+    }
+    return sel;
+}

mercurial