# HG changeset patch # User Olaf Wintermann # Date 1708802434 -3600 # Node ID 9389313ac00f16358f97eb35ed0a24eb8b996443 # Parent 3380100e20f5c6fb81f1e0fba48be164426e2d28 port combobox to new API (GTK) diff -r 3380100e20f5 -r 9389313ac00f application/main.c --- a/application/main.c Thu Feb 22 22:25:53 2024 +0100 +++ b/application/main.c Sat Feb 24 20:20:34 2024 +0100 @@ -83,7 +83,7 @@ */ char *str = elm; - return col == 1 ? str : "x"; + return col == 0 ? str : "x"; } void application_startup(UiEvent *event, void *data) { @@ -120,7 +120,7 @@ //UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "Col 1", UI_STRING, "Col 2", -1); //model->getvalue = list_getvalue; - ui_listview(obj, .hexpand = true, .vexpand = true, .colspan = 2, .varname = "list", .getvalue = list_getvalue); + ui_combobox(obj, .hexpand = true, .vexpand = false, .colspan = 2, .varname = "list", .getvalue = list_getvalue); } ui_show(obj); diff -r 3380100e20f5 -r 9389313ac00f ui/gtk/tree.c --- a/ui/gtk/tree.c Thu Feb 22 22:25:53 2024 +0100 +++ b/ui/gtk/tree.c Sat Feb 24 20:20:34 2024 +0100 @@ -555,47 +555,37 @@ /* --------------------------- ComboBox --------------------------- */ -UIWIDGET ui_combobox_deprecated(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata) { - UiVar *var = malloc(sizeof(UiVar)); - var->value = list; - var->type = UI_VAR_SPECIAL; - return ui_combobox_var(obj, var, getvalue, f, udata); -} - -UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata) { - UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST); - if(var) { - return ui_combobox_var(obj, var, getvalue, f, udata); - } else { - // TODO: error - } - return NULL; +UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) { + UiObject* current = uic_current_obj(obj); + + UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); + model->getvalue = args.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_APPLY_LAYOUT1(current, args); + current->container->add(current->container, combobox, FALSE); + current->container->current = combobox; + return combobox; } -UIWIDGET ui_combobox_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) { - /* - UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); - model->getvalue = getvalue; - UiList *list = var ? var->value : NULL; - GtkListStore *store = create_list_store(list, model); - - //GtkWidget *combobox = ui_create_combobox(obj, listmodel, f, udata); - UiContainer *ct = uic_get_current_container(obj); - ct->add(ct, combobox, FALSE); - return combobox; - */ - return NULL; -} - -GtkWidget* ui_create_combobox(UiObject *obj, GtkListStore *store, ui_callback f, void *udata) { - GtkWidget *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); - +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; - // TODO - //uicbox->var = model->var; - //uicbox->model = model->model; + + UiList *list = var ? var->value : NULL; + GtkListStore *listmodel = create_list_store(list, model); + + if(listmodel) { + gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel)); + } + + uicbox->var = var; + uicbox->model = model; g_signal_connect( combobox, @@ -604,9 +594,10 @@ uicbox); // bind var - //UiList *list = model->var->value; - //list->update = ui_combobox_modelupdate; - //list->obj = uicbox; + if(list) { + list->update = ui_combobox_modelupdate; + list->obj = uicbox; + } GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE); diff -r 3380100e20f5 -r 9389313ac00f ui/gtk/tree.h --- a/ui/gtk/tree.h Thu Feb 22 22:25:53 2024 +0100 +++ b/ui/gtk/tree.h Sat Feb 24 20:20:34 2024 +0100 @@ -76,7 +76,7 @@ int ui_tree_path_list_index(GtkTreePath *path); UIWIDGET ui_combobox_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata); -GtkWidget* ui_create_combobox(UiObject *obj, GtkListStore *store, ui_callback f, void *udata); +GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, ui_callback f, void *udata); void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e); void ui_combobox_modelupdate(UiList *list, int i);