fix combobox get/set selection functions (Motif)

Tue, 18 Nov 2025 15:41:45 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 18 Nov 2025 15:41:45 +0100
changeset 911
c8e1d40eeab6
parent 910
311bebe6aa82
child 912
06c37c12d149

fix combobox get/set selection functions (Motif)

application/demo_bindings.c file | annotate | diff | comparison | revisions
ui/motif/list.c file | annotate | diff | comparison | revisions
ui/motif/list.h file | annotate | diff | comparison | revisions
--- a/application/demo_bindings.c	Tue Nov 18 13:52:49 2025 +0100
+++ b/application/demo_bindings.c	Tue Nov 18 15:41:45 2025 +0100
@@ -97,7 +97,7 @@
         ui_llabel(obj, .varname = "name", .hfill = TRUE, .vfill = TRUE);
         ui_newline(obj);
         
-        ui_listview(obj, .height = 200, .varname = "doclist", .colspan = 2, .onactivate = switch_document, .getvalue = doclist_get_value, .colspan = 2, .hfill = TRUE);
+        ui_combobox(obj, .varname = "doclist", .colspan = 2, .onactivate = switch_document, .getvalue = doclist_get_value, .colspan = 2, .hfill = TRUE);
         ui_newline(obj);
         
         ui_frame(obj, .label = "Document", .colspan = 2, .fill = TRUE) {
@@ -117,7 +117,9 @@
     Document *doc = ui_list_get(wdata->doclist, 0);
     ui_attach_document(obj->ctx, doc);
     
-    //ui_list_setselection(wdata->doclist, 0);
+    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 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;
+}
--- a/ui/motif/list.h	Tue Nov 18 13:52:49 2025 +0100
+++ b/ui/motif/list.h	Tue Nov 18 15:41:45 2025 +0100
@@ -69,6 +69,9 @@
 UiListSelection ui_listview_getselection(UiList *list);
 void ui_listview_setselection(UiList *list, UiListSelection selection);
 
+void ui_dropdown_setselection(UiList *list, UiListSelection selection);
+UiListSelection ui_dropdown_getselection(UiList *list);
+
 void* ui_strmodel_getvalue(void *elm, int column);
 
 #ifdef	__cplusplus

mercurial