ui/gtk/list.c

changeset 60
ee4e4742391e
parent 51
e324291ca9f8
--- a/ui/gtk/list.c	Wed Oct 23 21:46:43 2024 +0200
+++ b/ui/gtk/list.c	Sun Oct 27 18:24:37 2024 +0100
@@ -162,6 +162,8 @@
     
     // create treeview
     GtkWidget *view = gtk_tree_view_new();
+    ui_set_name_and_style(view, args.name, args.style_class);
+    ui_set_widget_groups(obj->ctx, view, args.groups);
     GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
     GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 0, NULL);
     gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
@@ -178,7 +180,7 @@
 #endif
     
     UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
-    model->getvalue = args.getvalue;
+    model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
     
     UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
     
@@ -370,7 +372,9 @@
 
     
     GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
-    gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
+    if(args.multiselection) {
+        gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
+    }
     
     // add widget to the current container
     GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
@@ -582,11 +586,13 @@
     UiObject* current = uic_current_obj(obj);
     
     UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
-    model->getvalue = args.getvalue;
+    model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
     
     UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
     
     GtkWidget *combobox = ui_create_combobox(obj, model, var, args.onactivate, args.onactivatedata);
+    ui_set_name_and_style(combobox, args.name, args.style_class);
+    ui_set_widget_groups(obj->ctx, combobox, args.groups);
     UI_APPLY_LAYOUT1(current, args);
     current->container->add(current->container, combobox, FALSE);
     current->container->current = combobox;
@@ -595,7 +601,7 @@
 
 GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, ui_callback f, void *udata) {
     GtkWidget *combobox = gtk_combo_box_new();
-     
+       
     UiListView *uicbox = malloc(sizeof(UiListView));
     uicbox->obj = obj;
     uicbox->widget = combobox;
@@ -619,7 +625,8 @@
     // bind var
     if(list) {
         list->update = ui_combobox_modelupdate;
-        // TODO: combobox getselection
+        list->getselection = ui_combobox_getselection;
+        list->setselection = ui_combobox_setselection;
         list->obj = uicbox;
     }
     
@@ -668,3 +675,18 @@
     gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store));
 }
 
+UiListSelection ui_combobox_getselection(UiList *list) {
+    UiListView *combobox = list->obj;
+    UiListSelection ret;
+    ret.rows = malloc(sizeof(int*));
+    ret.count = 1;
+    ret.rows[0] = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox->widget));
+    return ret;
+}
+
+void ui_combobox_setselection(UiList *list, UiListSelection selection) {
+    UiListView *combobox = list->obj;
+    if(selection.count > 0) {
+        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox->widget), selection.rows[0]);
+    }
+}

mercurial