ui/gtk/list.c

branch
newapi
changeset 370
822fcb83bdf1
parent 369
f16a1cde664e
equal deleted inserted replaced
369:f16a1cde664e 370:822fcb83bdf1
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);
189 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); 189 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
190 g_object_unref(listmodel);
190 191
191 UiListView *listview = malloc(sizeof(UiListView)); 192 UiListView *listview = malloc(sizeof(UiListView));
192 listview->obj = obj; 193 listview->obj = obj;
193 listview->widget = view; 194 listview->widget = view;
194 listview->var = var; 195 listview->var = var;
338 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); 339 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
339 340
340 UiList *list = var ? var->value : NULL; 341 UiList *list = var ? var->value : NULL;
341 GtkListStore *listmodel = create_list_store(list, model); 342 GtkListStore *listmodel = create_list_store(list, model);
342 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); 343 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
344 g_object_unref(listmodel);
343 345
344 //g_signal_connect(view, "drag-begin", G_CALLBACK(drag_begin), NULL); 346 //g_signal_connect(view, "drag-begin", G_CALLBACK(drag_begin), NULL);
345 //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL); 347 //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL);
346 348
347 // add TreeView as observer to the UiList to update the TreeView if the 349 // add TreeView as observer to the UiList to update the TreeView if the
496 void ui_listview_update(UiList *list, int i) { 498 void ui_listview_update(UiList *list, int i) {
497 UiListView *view = list->obj; 499 UiListView *view = list->obj;
498 GtkListStore *store = create_list_store(list, view->model); 500 GtkListStore *store = create_list_store(list, view->model);
499 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store)); 501 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store));
500 g_object_unref(G_OBJECT(store)); 502 g_object_unref(G_OBJECT(store));
501 // TODO: free old model
502 } 503 }
503 504
504 UiListSelection ui_listview_getselection(UiList *list) { 505 UiListSelection ui_listview_getselection(UiList *list) {
505 UiListView *view = list->obj; 506 UiListView *view = list->obj;
506 UiListSelection selection = ui_listview_selection( 507 UiListSelection selection = ui_listview_selection(
516 gtk_tree_selection_select_path(sel, path); 517 gtk_tree_selection_select_path(sel, path);
517 //g_object_unref(path); 518 //g_object_unref(path);
518 } 519 }
519 520
520 void ui_listview_destroy(GtkWidget *w, UiListView *v) { 521 void ui_listview_destroy(GtkWidget *w, UiListView *v) {
521 gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); 522 //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL);
522 ui_destroy_boundvar(v->obj->ctx, v->var); 523 ui_destroy_boundvar(v->obj->ctx, v->var);
523 // TODO: destroy model?
524 free(v); 524 free(v);
525 } 525 }
526 526
527 void ui_combobox_destroy(GtkWidget *w, UiListView *v) { 527 void ui_combobox_destroy(GtkWidget *w, UiListView *v) {
528 gtk_combo_box_set_model(GTK_COMBO_BOX(w), NULL);
529 ui_destroy_boundvar(v->obj->ctx, v->var); 528 ui_destroy_boundvar(v->obj->ctx, v->var);
530 // TODO: destroy model?
531 free(v); 529 free(v);
532 } 530 }
533 531
534 532
535 void ui_listview_activate_event( 533 void ui_listview_activate_event(
634 UiList *list = var ? var->value : NULL; 632 UiList *list = var ? var->value : NULL;
635 GtkListStore *listmodel = create_list_store(list, model); 633 GtkListStore *listmodel = create_list_store(list, model);
636 634
637 if(listmodel) { 635 if(listmodel) {
638 gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel)); 636 gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel));
637 g_object_unref(listmodel);
639 } 638 }
640 639
641 uicbox->var = var; 640 uicbox->var = var;
642 uicbox->model = model; 641 uicbox->model = model;
643 642
696 695
697 void ui_combobox_modelupdate(UiList *list, int i) { 696 void ui_combobox_modelupdate(UiList *list, int i) {
698 UiListView *view = list->obj; 697 UiListView *view = list->obj;
699 GtkListStore *store = create_list_store(view->var->value, view->model); 698 GtkListStore *store = create_list_store(view->var->value, view->model);
700 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store)); 699 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store));
700 g_object_unref(store);
701 } 701 }
702 702
703 UiListSelection ui_combobox_getselection(UiList *list) { 703 UiListSelection ui_combobox_getselection(UiList *list) {
704 UiListView *combobox = list->obj; 704 UiListView *combobox = list->obj;
705 UiListSelection ret; 705 UiListSelection ret;

mercurial