178 #else |
178 #else |
179 // TODO: implement for gtk2 |
179 // TODO: implement for gtk2 |
180 #endif |
180 #endif |
181 |
181 |
182 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
182 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
183 model->getvalue = args.getvalue; |
183 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; |
184 |
184 |
185 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
185 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
186 |
186 |
187 UiList *list = var ? var->value : NULL; |
187 UiList *list = var ? var->value : NULL; |
188 GtkListStore *listmodel = create_list_store(list, model); |
188 GtkListStore *listmodel = create_list_store(list, model); |
584 |
584 |
585 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) { |
585 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) { |
586 UiObject* current = uic_current_obj(obj); |
586 UiObject* current = uic_current_obj(obj); |
587 |
587 |
588 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
588 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
589 model->getvalue = args.getvalue; |
589 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; |
590 |
590 |
591 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
591 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
592 |
592 |
593 GtkWidget *combobox = ui_create_combobox(obj, model, var, args.onactivate, args.onactivatedata); |
593 GtkWidget *combobox = ui_create_combobox(obj, model, var, args.onactivate, args.onactivatedata); |
594 ui_set_name_and_style(combobox, args.name, args.style_class); |
594 ui_set_name_and_style(combobox, args.name, args.style_class); |
623 uicbox); |
623 uicbox); |
624 |
624 |
625 // bind var |
625 // bind var |
626 if(list) { |
626 if(list) { |
627 list->update = ui_combobox_modelupdate; |
627 list->update = ui_combobox_modelupdate; |
628 // TODO: combobox getselection |
628 list->getselection = ui_combobox_getselection; |
|
629 list->setselection = ui_combobox_setselection; |
629 list->obj = uicbox; |
630 list->obj = uicbox; |
630 } |
631 } |
631 |
632 |
632 GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
633 GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
633 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE); |
634 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE); |
672 UiListView *view = list->obj; |
673 UiListView *view = list->obj; |
673 GtkListStore *store = create_list_store(view->var->value, view->model); |
674 GtkListStore *store = create_list_store(view->var->value, view->model); |
674 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store)); |
675 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store)); |
675 } |
676 } |
676 |
677 |
|
678 UiListSelection ui_combobox_getselection(UiList *list) { |
|
679 UiListView *combobox = list->obj; |
|
680 UiListSelection ret; |
|
681 ret.rows = malloc(sizeof(int*)); |
|
682 ret.count = 1; |
|
683 ret.rows[0] = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox->widget)); |
|
684 return ret; |
|
685 } |
|
686 |
|
687 void ui_combobox_setselection(UiList *list, UiListSelection selection) { |
|
688 UiListView *combobox = list->obj; |
|
689 if(selection.count > 0) { |
|
690 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox->widget), selection.rows[0]); |
|
691 } |
|
692 } |