ui/gtk/list.c

changeset 969
7385c26d998d
parent 968
128a0de73cc8
child 973
aa39a986da78
equal deleted inserted replaced
968:128a0de73cc8 969:7385c26d998d
541 ct->add(ct, scroll_area, &layout); 541 ct->add(ct, scroll_area, &layout);
542 542
543 return scroll_area; 543 return scroll_area;
544 } 544 }
545 545
546 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) { 546 UIWIDGET ui_dropdown_create(UiObject *obj, UiListArgs *args) {
547 // to simplify things and share code with ui_tableview_create, we also 547 // to simplify things and share code with ui_tableview_create, we also
548 // use a UiModel for the listview 548 // use a UiModel for the listview
549 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); 549 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
550 args->model = model; 550 args->model = model;
551 551
590 if(var && var->value) { 590 if(var && var->value) {
591 UiList *list = var->value; 591 UiList *list = var->value;
592 592
593 list->obj = listview; 593 list->obj = listview;
594 list->update = ui_listview_update2; 594 list->update = ui_listview_update2;
595 list->getselection = ui_combobox_getselection; 595 list->getselection = ui_dropdown_getselection;
596 list->setselection = ui_combobox_setselection; 596 list->setselection = ui_dropdown_setselection;
597 597
598 ui_update_liststore(ls, list); 598 ui_update_liststore(ls, list);
599 } else if (args->static_elements && args->static_nelm > 0) { 599 } else if (args->static_elements && args->static_nelm > 0) {
600 listview_copy_static_elements(listview, args->static_elements, args->static_nelm); 600 listview_copy_static_elements(listview, args->static_elements, args->static_nelm);
601 listview->getvalue = str_getvalue; // force string values 601 listview->getvalue = str_getvalue; // force string values
618 void ui_listview_select(UIWIDGET listview, int index) { 618 void ui_listview_select(UIWIDGET listview, int index) {
619 GtkSelectionModel *model = gtk_list_view_get_model(GTK_LIST_VIEW(listview)); 619 GtkSelectionModel *model = gtk_list_view_get_model(GTK_LIST_VIEW(listview));
620 gtk_selection_model_select_item(model, index, TRUE); 620 gtk_selection_model_select_item(model, index, TRUE);
621 } 621 }
622 622
623 void ui_combobox_select(UIWIDGET dropdown, int index) { 623 void ui_dropdown_select(UIWIDGET dropdown, int index) {
624 gtk_drop_down_set_selected(GTK_DROP_DOWN(dropdown), index); 624 gtk_drop_down_set_selected(GTK_DROP_DOWN(dropdown), index);
625 } 625 }
626 626
627 static void add_column(UiListView *tableview, int index) { 627 static void add_column(UiListView *tableview, int index) {
628 UiModel *model = tableview->model; 628 UiModel *model = tableview->model;
957 } 957 }
958 } 958 }
959 ui_setop_enable(FALSE); 959 ui_setop_enable(FALSE);
960 } 960 }
961 961
962 UiListSelection ui_combobox_getselection(UiList *list) { 962 UiListSelection ui_dropdown_getselection(UiList *list) {
963 UiListView *view = list->obj; 963 UiListView *view = list->obj;
964 guint selection = gtk_drop_down_get_selected(GTK_DROP_DOWN(view->widget)); 964 guint selection = gtk_drop_down_get_selected(GTK_DROP_DOWN(view->widget));
965 UiListSelection sel = { 0, NULL }; 965 UiListSelection sel = { 0, NULL };
966 if(selection != GTK_INVALID_LIST_POSITION) { 966 if(selection != GTK_INVALID_LIST_POSITION) {
967 sel.count = 1; 967 sel.count = 1;
969 sel.rows[0] = (int)selection; 969 sel.rows[0] = (int)selection;
970 } 970 }
971 return sel; 971 return sel;
972 } 972 }
973 973
974 void ui_combobox_setselection(UiList *list, UiListSelection selection) { 974 void ui_dropdown_setselection(UiList *list, UiListSelection selection) {
975 ui_setop_enable(TRUE); 975 ui_setop_enable(TRUE);
976 UiListView *view = list->obj; 976 UiListView *view = list->obj;
977 if(selection.count > 0) { 977 if(selection.count > 0) {
978 gtk_drop_down_set_selected(GTK_DROP_DOWN(view->widget), selection.rows[0]); 978 gtk_drop_down_set_selected(GTK_DROP_DOWN(view->widget), selection.rows[0]);
979 } else { 979 } else {
1314 GtkTreePath *path = gtk_tree_path_new_from_indicesv(&index, 1); 1314 GtkTreePath *path = gtk_tree_path_new_from_indicesv(&index, 1);
1315 gtk_tree_selection_select_path(sel, path); 1315 gtk_tree_selection_select_path(sel, path);
1316 //g_object_unref(path); 1316 //g_object_unref(path);
1317 } 1317 }
1318 1318
1319 void ui_combobox_select(UIWIDGET dropdown, int index) { 1319 void ui_dropdown_select(UIWIDGET dropdown, int index) {
1320 gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown), index); 1320 gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown), index);
1321 } 1321 }
1322 1322
1323 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { 1323 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) {
1324 // create treeview 1324 // create treeview
1558 1558
1559 1559
1560 1560
1561 /* --------------------------- ComboBox --------------------------- */ 1561 /* --------------------------- ComboBox --------------------------- */
1562 1562
1563 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) { 1563 UIWIDGET ui_dropdown_create(UiObject *obj, UiListArgs *args) {
1564 GtkWidget *combobox = gtk_combo_box_new(); 1564 GtkWidget *combobox = gtk_combo_box_new();
1565 if(args->width > 0) { 1565 if(args->width > 0) {
1566 gtk_widget_set_size_request(combobox, args->width, -1); 1566 gtk_widget_set_size_request(combobox, args->width, -1);
1567 } 1567 }
1568 1568
1586 UiList *list = var ? var->value : NULL; 1586 UiList *list = var ? var->value : NULL;
1587 GtkListStore *listmodel = create_list_store(listview, list); 1587 GtkListStore *listmodel = create_list_store(listview, list);
1588 if(var) { 1588 if(var) {
1589 listview->var = var; 1589 listview->var = var;
1590 list->update = ui_combobox_modelupdate; 1590 list->update = ui_combobox_modelupdate;
1591 list->getselection = ui_combobox_getselection; 1591 list->getselection = ui_dropdown_getselection;
1592 list->setselection = ui_combobox_setselection; 1592 list->setselection = ui_dropdown_setselection;
1593 list->obj = listview; 1593 list->obj = listview;
1594 list->update(list, -1); 1594 list->update(list, -1);
1595 } else if(args->static_nelm > 0) { 1595 } else if(args->static_nelm > 0) {
1596 listview_copy_static_elements(listview, args->static_elements, args->static_nelm); 1596 listview_copy_static_elements(listview, args->static_elements, args->static_nelm);
1597 for(int i=0;i<args->static_nelm;i++) { 1597 for(int i=0;i<args->static_nelm;i++) {
1664 GtkListStore *store = create_list_store(view, list); 1664 GtkListStore *store = create_list_store(view, list);
1665 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store)); 1665 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store));
1666 g_object_unref(store); 1666 g_object_unref(store);
1667 } 1667 }
1668 1668
1669 UiListSelection ui_combobox_getselection(UiList *list) { 1669 UiListSelection ui_dropdown_getselection(UiList *list) {
1670 UiListView *combobox = list->obj; 1670 UiListView *combobox = list->obj;
1671 UiListSelection ret; 1671 UiListSelection ret;
1672 ret.rows = malloc(sizeof(int*)); 1672 ret.rows = malloc(sizeof(int*));
1673 ret.count = 1; 1673 ret.count = 1;
1674 ret.rows[0] = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox->widget)); 1674 ret.rows[0] = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox->widget));
1675 return ret; 1675 return ret;
1676 } 1676 }
1677 1677
1678 void ui_combobox_setselection(UiList *list, UiListSelection selection) { 1678 void ui_dropdown_setselection(UiList *list, UiListSelection selection) {
1679 ui_setop_enable(TRUE); 1679 ui_setop_enable(TRUE);
1680 UiListView *combobox = list->obj; 1680 UiListView *combobox = list->obj;
1681 if(selection.count > 0) { 1681 if(selection.count > 0) {
1682 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox->widget), selection.rows[0]); 1682 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox->widget), selection.rows[0]);
1683 } 1683 }

mercurial