| 433 g_signal_connect(selection_model, "selection-changed", G_CALLBACK(ui_listview_selection_changed), listview); |
433 g_signal_connect(selection_model, "selection-changed", G_CALLBACK(ui_listview_selection_changed), listview); |
| 434 return selection_model; |
434 return selection_model; |
| 435 } |
435 } |
| 436 |
436 |
| 437 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
437 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
| 438 UiObject* current = uic_current_obj(obj); |
|
| 439 |
|
| 440 // to simplify things and share code with ui_table_create, we also |
438 // to simplify things and share code with ui_table_create, we also |
| 441 // use a UiModel for the listview |
439 // use a UiModel for the listview |
| 442 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
440 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
| 443 args->model = model; |
441 args->model = model; |
| 444 |
442 |
| 462 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns); |
460 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns); |
| 463 |
461 |
| 464 GtkSelectionModel *selection_model = create_selection_model(listview, ls, args->multiselection); |
462 GtkSelectionModel *selection_model = create_selection_model(listview, ls, args->multiselection); |
| 465 GtkWidget *view = gtk_list_view_new(GTK_SELECTION_MODEL(selection_model), factory); |
463 GtkWidget *view = gtk_list_view_new(GTK_SELECTION_MODEL(selection_model), factory); |
| 466 |
464 |
| 467 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST); |
465 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST); |
| 468 |
466 |
| 469 // init listview |
467 // init listview |
| 470 listview->widget = view; |
468 listview->widget = view; |
| 471 listview->var = var; |
469 listview->var = var; |
| 472 listview->liststore = ls; |
470 listview->liststore = ls; |
| 511 GTK_SCROLLED_WINDOW(scroll_area), |
509 GTK_SCROLLED_WINDOW(scroll_area), |
| 512 GTK_POLICY_AUTOMATIC, |
510 GTK_POLICY_AUTOMATIC, |
| 513 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
511 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
| 514 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); |
512 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); |
| 515 |
513 |
| 516 UI_APPLY_LAYOUT2(current, args); |
514 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 517 current->container->add(current->container, scroll_area); |
515 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 518 |
516 ct->add(ct, scroll_area, &layout); |
| 519 // ct->current should point to view, not scroll_area, to make it possible |
|
| 520 // to add a context menu |
|
| 521 current->container->current = view; |
|
| 522 |
517 |
| 523 return scroll_area; |
518 return scroll_area; |
| 524 } |
519 } |
| 525 |
520 |
| 526 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) { |
521 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) { |
| 527 UiObject* current = uic_current_obj(obj); |
|
| 528 |
|
| 529 // to simplify things and share code with ui_tableview_create, we also |
522 // to simplify things and share code with ui_tableview_create, we also |
| 530 // use a UiModel for the listview |
523 // use a UiModel for the listview |
| 531 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
524 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
| 532 args->model = model; |
525 args->model = model; |
| 533 |
526 |
| 552 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns); |
545 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns); |
| 553 |
546 |
| 554 GtkWidget *view = gtk_drop_down_new(G_LIST_MODEL(ls), NULL); |
547 GtkWidget *view = gtk_drop_down_new(G_LIST_MODEL(ls), NULL); |
| 555 gtk_drop_down_set_factory(GTK_DROP_DOWN(view), factory); |
548 gtk_drop_down_set_factory(GTK_DROP_DOWN(view), factory); |
| 556 |
549 |
| 557 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST); |
550 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST); |
| 558 |
551 |
| 559 // init listview |
552 // init listview |
| 560 listview->widget = view; |
553 listview->widget = view; |
| 561 listview->var = var; |
554 listview->var = var; |
| 562 listview->liststore = ls; |
555 listview->liststore = ls; |
| 587 if(args->onactivate) { |
580 if(args->onactivate) { |
| 588 g_signal_connect(view, "notify::selected", G_CALLBACK(ui_dropdown_notify), listview); |
581 g_signal_connect(view, "notify::selected", G_CALLBACK(ui_dropdown_notify), listview); |
| 589 } |
582 } |
| 590 |
583 |
| 591 // add widget to parent |
584 // add widget to parent |
| 592 UI_APPLY_LAYOUT2(current, args); |
585 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 593 current->container->add(current->container, view); |
586 UiLayout layout = UI_ARGS2LAYOUT(args); |
| |
587 ct->add(ct, view, &layout); |
| |
588 |
| 594 return view; |
589 return view; |
| 595 } |
590 } |
| 596 |
591 |
| 597 void ui_listview_select(UIWIDGET listview, int index) { |
592 void ui_listview_select(UIWIDGET listview, int index) { |
| 598 GtkSelectionModel *model = gtk_list_view_get_model(GTK_LIST_VIEW(listview)); |
593 GtkSelectionModel *model = gtk_list_view_get_model(GTK_LIST_VIEW(listview)); |
| 602 void ui_combobox_select(UIWIDGET dropdown, int index) { |
597 void ui_combobox_select(UIWIDGET dropdown, int index) { |
| 603 gtk_drop_down_set_selected(GTK_DROP_DOWN(dropdown), index); |
598 gtk_drop_down_set_selected(GTK_DROP_DOWN(dropdown), index); |
| 604 } |
599 } |
| 605 |
600 |
| 606 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { |
601 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { |
| 607 UiObject* current = uic_current_obj(obj); |
|
| 608 |
|
| 609 GListStore *ls = g_list_store_new(G_TYPE_OBJECT); |
602 GListStore *ls = g_list_store_new(G_TYPE_OBJECT); |
| 610 //g_list_store_append(ls, v1); |
603 //g_list_store_append(ls, v1); |
| 611 |
604 |
| 612 // create obj to store all relevant data we need for handling events |
605 // create obj to store all relevant data we need for handling events |
| 613 // and list updates |
606 // and list updates |
| 614 UiListView *tableview = create_listview(obj, args); |
607 UiListView *tableview = create_listview(obj, args); |
| 615 |
608 |
| 616 GtkSelectionModel *selection_model = create_selection_model(tableview, ls, args->multiselection); |
609 GtkSelectionModel *selection_model = create_selection_model(tableview, ls, args->multiselection); |
| 617 GtkWidget *view = gtk_column_view_new(GTK_SELECTION_MODEL(selection_model)); |
610 GtkWidget *view = gtk_column_view_new(GTK_SELECTION_MODEL(selection_model)); |
| 618 |
611 |
| 619 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST); |
612 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST); |
| 620 |
613 |
| 621 // init tableview |
614 // init tableview |
| 622 tableview->widget = view; |
615 tableview->widget = view; |
| 623 tableview->var = var; |
616 tableview->var = var; |
| 624 tableview->liststore = ls; |
617 tableview->liststore = ls; |
| 695 GTK_SCROLLED_WINDOW(scroll_area), |
688 GTK_SCROLLED_WINDOW(scroll_area), |
| 696 GTK_POLICY_AUTOMATIC, |
689 GTK_POLICY_AUTOMATIC, |
| 697 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
690 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
| 698 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); |
691 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); |
| 699 |
692 |
| 700 UI_APPLY_LAYOUT2(current, args); |
693 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 701 current->container->add(current->container, scroll_area); |
694 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 702 |
695 ct->add(ct, scroll_area, &layout); |
| 703 // ct->current should point to view, not scroll_area, to make it possible |
|
| 704 // to add a context menu |
|
| 705 current->container->current = view; |
|
| 706 |
696 |
| 707 return scroll_area; |
697 return scroll_area; |
| 708 } |
698 } |
| 709 |
699 |
| 710 static UiListSelection selectionmodel_get_selection(GtkSelectionModel *model) { |
700 static UiListSelection selectionmodel_get_selection(GtkSelectionModel *model) { |
| 1124 return store; |
1114 return store; |
| 1125 } |
1115 } |
| 1126 |
1116 |
| 1127 |
1117 |
| 1128 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
1118 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
| 1129 UiObject* current = uic_current_obj(obj); |
|
| 1130 |
|
| 1131 // create treeview |
1119 // create treeview |
| 1132 GtkWidget *view = gtk_tree_view_new(); |
1120 GtkWidget *view = gtk_tree_view_new(); |
| 1133 ui_set_name_and_style(view, args->name, args->style_class); |
1121 ui_set_name_and_style(view, args->name, args->style_class); |
| 1134 ui_set_widget_groups(obj->ctx, view, args->groups); |
1122 ui_set_widget_groups(obj->ctx, view, args->groups); |
| 1135 GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
1123 GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
| 1159 view, |
1147 view, |
| 1160 "destroy", |
1148 "destroy", |
| 1161 G_CALLBACK(ui_listview_destroy), |
1149 G_CALLBACK(ui_listview_destroy), |
| 1162 listview); |
1150 listview); |
| 1163 |
1151 |
| 1164 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST); |
1152 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST); |
| 1165 |
1153 |
| 1166 // init listview |
1154 // init listview |
| 1167 listview->widget = view; |
1155 listview->widget = view; |
| 1168 listview->var = var; |
1156 listview->var = var; |
| 1169 |
1157 |
| 1219 GTK_SCROLLED_WINDOW(scroll_area), |
1207 GTK_SCROLLED_WINDOW(scroll_area), |
| 1220 GTK_POLICY_AUTOMATIC, |
1208 GTK_POLICY_AUTOMATIC, |
| 1221 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
1209 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
| 1222 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); |
1210 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); |
| 1223 |
1211 |
| 1224 UI_APPLY_LAYOUT2(current, args); |
1212 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 1225 current->container->add(current->container, scroll_area); |
1213 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 1226 |
1214 ct->add(ct, scroll_area, &layout); |
| 1227 // ct->current should point to view, not scroll_area, to make it possible |
|
| 1228 // to add a context menu |
|
| 1229 current->container->current = view; |
|
| 1230 |
1215 |
| 1231 return scroll_area; |
1216 return scroll_area; |
| 1232 } |
1217 } |
| 1233 |
1218 |
| 1234 void ui_listview_select(UIWIDGET listview, int index) { |
1219 void ui_listview_select(UIWIDGET listview, int index) { |
| 1241 void ui_combobox_select(UIWIDGET dropdown, int index) { |
1226 void ui_combobox_select(UIWIDGET dropdown, int index) { |
| 1242 gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown), index); |
1227 gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown), index); |
| 1243 } |
1228 } |
| 1244 |
1229 |
| 1245 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { |
1230 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { |
| 1246 UiObject* current = uic_current_obj(obj); |
|
| 1247 |
|
| 1248 // create treeview |
1231 // create treeview |
| 1249 GtkWidget *view = gtk_tree_view_new(); |
1232 GtkWidget *view = gtk_tree_view_new(); |
| 1250 |
1233 |
| 1251 UiModel *model = args->model; |
1234 UiModel *model = args->model; |
| 1252 int columns = model ? model->columns : 0; |
1235 int columns = model ? model->columns : 0; |
| 1341 //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE); |
1324 //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE); |
| 1342 #else |
1325 #else |
| 1343 |
1326 |
| 1344 #endif |
1327 #endif |
| 1345 |
1328 |
| 1346 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST); |
1329 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST); |
| 1347 |
1330 |
| 1348 //g_signal_connect(view, "drag-begin", G_CALLBACK(drag_begin), NULL); |
1331 //g_signal_connect(view, "drag-begin", G_CALLBACK(drag_begin), NULL); |
| 1349 //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL); |
1332 //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL); |
| 1350 |
1333 |
| 1351 // add TreeView as observer to the UiList to update the TreeView if the |
1334 // add TreeView as observer to the UiList to update the TreeView if the |
| 1423 #else |
1406 #else |
| 1424 ui_widget_set_contextmenu(view, menu); |
1407 ui_widget_set_contextmenu(view, menu); |
| 1425 #endif |
1408 #endif |
| 1426 } |
1409 } |
| 1427 |
1410 |
| 1428 UI_APPLY_LAYOUT2(current, args); |
1411 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 1429 current->container->add(current->container, scroll_area); |
1412 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 1430 |
1413 ct->add(ct, scroll_area, &layout); |
| 1431 // ct->current should point to view, not scroll_area, to make it possible |
|
| 1432 // to add a context menu |
|
| 1433 current->container->current = view; |
|
| 1434 |
1414 |
| 1435 return scroll_area; |
1415 return scroll_area; |
| 1436 } |
1416 } |
| 1437 |
1417 |
| 1438 |
1418 |
| 1474 |
1454 |
| 1475 |
1455 |
| 1476 /* --------------------------- ComboBox --------------------------- */ |
1456 /* --------------------------- ComboBox --------------------------- */ |
| 1477 |
1457 |
| 1478 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) { |
1458 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) { |
| 1479 UiObject* current = uic_current_obj(obj); |
|
| 1480 |
|
| 1481 GtkWidget *combobox = gtk_combo_box_new(); |
1459 GtkWidget *combobox = gtk_combo_box_new(); |
| 1482 |
1460 |
| 1483 ui_set_name_and_style(combobox, args->name, args->style_class); |
1461 ui_set_name_and_style(combobox, args->name, args->style_class); |
| 1484 ui_set_widget_groups(obj->ctx, combobox, args->groups); |
1462 ui_set_widget_groups(obj->ctx, combobox, args->groups); |
| 1485 UI_APPLY_LAYOUT2(current, args); |
1463 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 1486 current->container->add(current->container, combobox); |
1464 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 1487 current->container->current = combobox; |
1465 ct->add(ct, combobox, &layout); |
| 1488 |
1466 |
| 1489 UiListView *listview = create_listview(obj, args); |
1467 UiListView *listview = create_listview(obj, args); |
| 1490 listview->widget = combobox; |
1468 listview->widget = combobox; |
| 1491 listview->style_offset = 1; |
1469 listview->style_offset = 1; |
| 1492 listview->model = ui_model(obj->ctx, UI_STRING, "", -1); |
1470 listview->model = ui_model(obj->ctx, UI_STRING, "", -1); |
| 1494 combobox, |
1472 combobox, |
| 1495 "destroy", |
1473 "destroy", |
| 1496 G_CALLBACK(ui_listview_destroy), |
1474 G_CALLBACK(ui_listview_destroy), |
| 1497 listview); |
1475 listview); |
| 1498 |
1476 |
| 1499 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST); |
1477 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->list, args->varname, UI_VAR_LIST); |
| 1500 UiList *list = var ? var->value : NULL; |
1478 UiList *list = var ? var->value : NULL; |
| 1501 GtkListStore *listmodel = create_list_store(listview, list); |
1479 GtkListStore *listmodel = create_list_store(listview, list); |
| 1502 if(var) { |
1480 if(var) { |
| 1503 listview->var = var; |
1481 listview->var = var; |
| 1504 list->update = ui_combobox_modelupdate; |
1482 list->update = ui_combobox_modelupdate; |
| 2108 list->update = ui_listbox_list_update; |
2086 list->update = ui_listbox_list_update; |
| 2109 } |
2087 } |
| 2110 } |
2088 } |
| 2111 |
2089 |
| 2112 UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args) { |
2090 UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args) { |
| 2113 UiObject* current = uic_current_obj(obj); |
|
| 2114 |
|
| 2115 #ifdef UI_GTK3 |
2091 #ifdef UI_GTK3 |
| 2116 GtkWidget *listbox = g_object_new(ui_sidebar_list_box_get_type(), NULL); |
2092 GtkWidget *listbox = g_object_new(ui_sidebar_list_box_get_type(), NULL); |
| 2117 #else |
2093 #else |
| 2118 GtkWidget *listbox = gtk_list_box_new(); |
2094 GtkWidget *listbox = gtk_list_box_new(); |
| 2119 #endif |
2095 #endif |
| 2128 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); |
2104 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); |
| 2129 SCROLLEDWINDOW_SET_CHILD(scroll_area, listbox); |
2105 SCROLLEDWINDOW_SET_CHILD(scroll_area, listbox); |
| 2130 |
2106 |
| 2131 ui_set_name_and_style(listbox, args->name, args->style_class); |
2107 ui_set_name_and_style(listbox, args->name, args->style_class); |
| 2132 ui_set_widget_groups(obj->ctx, listbox, args->groups); |
2108 ui_set_widget_groups(obj->ctx, listbox, args->groups); |
| 2133 UI_APPLY_LAYOUT2(current, args); |
2109 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 2134 current->container->add(current->container, scroll_area); |
2110 UiLayout layout = UI_ARGS2LAYOUT(args); |
| |
2111 ct->add(ct, scroll_area, &layout); |
| 2135 |
2112 |
| 2136 UiListBox *uilistbox = malloc(sizeof(UiListBox)); |
2113 UiListBox *uilistbox = malloc(sizeof(UiListBox)); |
| 2137 uilistbox->obj = obj; |
2114 uilistbox->obj = obj; |
| 2138 uilistbox->listbox = GTK_LIST_BOX(listbox); |
2115 uilistbox->listbox = GTK_LIST_BOX(listbox); |
| 2139 uilistbox->getvalue = args->getvalue; |
2116 uilistbox->getvalue = args->getvalue; |
| 2162 } |
2139 } |
| 2163 |
2140 |
| 2164 // fill items |
2141 // fill items |
| 2165 ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists)); |
2142 ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists)); |
| 2166 } else { |
2143 } else { |
| 2167 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->dynamic_sublist, args->varname, UI_VAR_LIST); |
2144 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->dynamic_sublist, args->varname, UI_VAR_LIST); |
| 2168 if(var) { |
2145 if(var) { |
| 2169 UiList *list = var->value; |
2146 UiList *list = var->value; |
| 2170 list->obj = uilistbox; |
2147 list->obj = uilistbox; |
| 2171 list->update = ui_listbox_dynamic_update; |
2148 list->update = ui_listbox_dynamic_update; |
| 2172 |
2149 |