577 } |
577 } |
578 } |
578 } |
579 |
579 |
580 void ui_listview_update2(UiList *list, int i) { |
580 void ui_listview_update2(UiList *list, int i) { |
581 UiListView *view = list->obj; |
581 UiListView *view = list->obj; |
582 ui_update_liststore(view->liststore, list); |
582 if(i < 0) { |
|
583 ui_update_liststore(view->liststore, list); |
|
584 } else { |
|
585 void *value = list->get(list, i); |
|
586 if(value) { |
|
587 ObjWrapper *obj = obj_wrapper_new(value); |
|
588 g_list_store_remove(view->liststore, i); |
|
589 g_list_store_insert(view->liststore, i, obj); |
|
590 } |
|
591 } |
583 } |
592 } |
584 |
593 |
585 UiListSelection ui_listview_getselection2(UiList *list) { |
594 UiListSelection ui_listview_getselection2(UiList *list) { |
586 UiListView *view = list->obj; |
595 UiListView *view = list->obj; |
587 UiListSelection selection; |
596 UiListSelection selection; |
636 } |
645 } |
637 ui_setop_enable(FALSE); |
646 ui_setop_enable(FALSE); |
638 } |
647 } |
639 |
648 |
640 #else |
649 #else |
|
650 |
|
651 static void update_list_row(GtkListStore *store, GtkTreeIter *iter, UiModel *model, void *elm) { |
|
652 // set column values |
|
653 int c = 0; |
|
654 for(int i=0;i<model->columns;i++,c++) { |
|
655 void *data = model->getvalue(elm, c); |
|
656 |
|
657 GValue value = G_VALUE_INIT; |
|
658 switch(model->types[i]) { |
|
659 case UI_STRING: |
|
660 case UI_STRING_FREE: { |
|
661 g_value_init(&value, G_TYPE_STRING); |
|
662 g_value_set_string(&value, data); |
|
663 if(model->types[i] == UI_STRING_FREE) { |
|
664 free(data); |
|
665 } |
|
666 break; |
|
667 } |
|
668 case UI_INTEGER: { |
|
669 g_value_init(&value, G_TYPE_INT); |
|
670 intptr_t intptr = (intptr_t)data; |
|
671 g_value_set_int(&value, (int)intptr); |
|
672 break; |
|
673 } |
|
674 case UI_ICON: { |
|
675 g_value_init(&value, G_TYPE_OBJECT); |
|
676 UiIcon *icon = data; |
|
677 #if GTK_MAJOR_VERSION >= 4 |
|
678 g_value_set_object(&value, icon->info); // TODO: does this work? |
|
679 #else |
|
680 if(!icon->pixbuf && icon->info) { |
|
681 GError *error = NULL; |
|
682 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); |
|
683 icon->pixbuf = pixbuf; |
|
684 } |
|
685 |
|
686 if(icon->pixbuf) { |
|
687 g_value_set_object(&value, icon->pixbuf); |
|
688 } |
|
689 #endif |
|
690 break; |
|
691 } |
|
692 case UI_ICON_TEXT: |
|
693 case UI_ICON_TEXT_FREE: { |
|
694 UiIcon *icon = data; |
|
695 #if GTK_MAJOR_VERSION >= 4 |
|
696 if(icon) { |
|
697 GValue iconvalue = G_VALUE_INIT; |
|
698 g_value_init(&iconvalue, G_TYPE_OBJECT); |
|
699 g_value_set_object(&iconvalue, ui_icon_pixbuf(icon)); |
|
700 gtk_list_store_set_value(store, &iter, c, &iconvalue); |
|
701 } |
|
702 #else |
|
703 GValue pixbufvalue = G_VALUE_INIT; |
|
704 if(icon) { |
|
705 if(!icon->pixbuf && icon->info) { |
|
706 GError *error = NULL; |
|
707 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); |
|
708 icon->pixbuf = pixbuf; |
|
709 } |
|
710 g_value_init(&pixbufvalue, G_TYPE_OBJECT); |
|
711 g_value_set_object(&pixbufvalue, icon->pixbuf); |
|
712 gtk_list_store_set_value(store, iter, c, &pixbufvalue); |
|
713 } |
|
714 #endif |
|
715 c++; |
|
716 |
|
717 char *str = model->getvalue(elm, c); |
|
718 g_value_init(&value, G_TYPE_STRING); |
|
719 g_value_set_string(&value, str); |
|
720 if(model->types[i] == UI_ICON_TEXT_FREE) { |
|
721 free(str); |
|
722 } |
|
723 break; |
|
724 } |
|
725 } |
|
726 |
|
727 gtk_list_store_set_value(store, iter, c, &value); |
|
728 } |
|
729 } |
641 |
730 |
642 static GtkListStore* create_list_store(UiList *list, UiModel *model) { |
731 static GtkListStore* create_list_store(UiList *list, UiModel *model) { |
643 int columns = model->columns; |
732 int columns = model->columns; |
644 GType types[2*columns]; |
733 GType types[2*columns]; |
645 int c = 0; |
734 int c = 0; |
664 while(elm) { |
753 while(elm) { |
665 // insert new row |
754 // insert new row |
666 GtkTreeIter iter; |
755 GtkTreeIter iter; |
667 gtk_list_store_insert (store, &iter, -1); |
756 gtk_list_store_insert (store, &iter, -1); |
668 |
757 |
669 // set column values |
758 update_list_row(store, &iter, model, elm); |
670 int c = 0; |
|
671 for(int i=0;i<columns;i++,c++) { |
|
672 void *data = model->getvalue(elm, c); |
|
673 |
|
674 GValue value = G_VALUE_INIT; |
|
675 switch(model->types[i]) { |
|
676 case UI_STRING: |
|
677 case UI_STRING_FREE: { |
|
678 g_value_init(&value, G_TYPE_STRING); |
|
679 g_value_set_string(&value, data); |
|
680 if(model->types[i] == UI_STRING_FREE) { |
|
681 free(data); |
|
682 } |
|
683 break; |
|
684 } |
|
685 case UI_INTEGER: { |
|
686 g_value_init(&value, G_TYPE_INT); |
|
687 intptr_t intptr = (intptr_t)data; |
|
688 g_value_set_int(&value, (int)intptr); |
|
689 break; |
|
690 } |
|
691 case UI_ICON: { |
|
692 g_value_init(&value, G_TYPE_OBJECT); |
|
693 UiIcon *icon = data; |
|
694 #if GTK_MAJOR_VERSION >= 4 |
|
695 g_value_set_object(&value, icon->info); // TODO: does this work? |
|
696 #else |
|
697 if(!icon->pixbuf && icon->info) { |
|
698 GError *error = NULL; |
|
699 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); |
|
700 icon->pixbuf = pixbuf; |
|
701 } |
|
702 |
|
703 if(icon->pixbuf) { |
|
704 g_value_set_object(&value, icon->pixbuf); |
|
705 } |
|
706 #endif |
|
707 break; |
|
708 } |
|
709 case UI_ICON_TEXT: |
|
710 case UI_ICON_TEXT_FREE: { |
|
711 UiIcon *icon = data; |
|
712 #if GTK_MAJOR_VERSION >= 4 |
|
713 if(icon) { |
|
714 GValue iconvalue = G_VALUE_INIT; |
|
715 g_value_init(&iconvalue, G_TYPE_OBJECT); |
|
716 g_value_set_object(&iconvalue, ui_icon_pixbuf(icon)); |
|
717 gtk_list_store_set_value(store, &iter, c, &iconvalue); |
|
718 } |
|
719 #else |
|
720 GValue pixbufvalue = G_VALUE_INIT; |
|
721 if(icon) { |
|
722 if(!icon->pixbuf && icon->info) { |
|
723 GError *error = NULL; |
|
724 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); |
|
725 icon->pixbuf = pixbuf; |
|
726 } |
|
727 g_value_init(&pixbufvalue, G_TYPE_OBJECT); |
|
728 g_value_set_object(&pixbufvalue, icon->pixbuf); |
|
729 gtk_list_store_set_value(store, &iter, c, &pixbufvalue); |
|
730 } |
|
731 #endif |
|
732 c++; |
|
733 |
|
734 char *str = model->getvalue(elm, c); |
|
735 g_value_init(&value, G_TYPE_STRING); |
|
736 g_value_set_string(&value, str); |
|
737 if(model->types[i] == UI_ICON_TEXT_FREE) { |
|
738 free(str); |
|
739 } |
|
740 break; |
|
741 } |
|
742 } |
|
743 |
|
744 gtk_list_store_set_value(store, &iter, c, &value); |
|
745 } |
|
746 |
759 |
747 // next row |
760 // next row |
748 elm = list->next(list); |
761 elm = list->next(list); |
749 } |
762 } |
750 } |
763 } |
1037 |
1050 |
1038 |
1051 |
1039 |
1052 |
1040 void ui_listview_update(UiList *list, int i) { |
1053 void ui_listview_update(UiList *list, int i) { |
1041 UiListView *view = list->obj; |
1054 UiListView *view = list->obj; |
1042 GtkListStore *store = create_list_store(list, view->model); |
1055 if(i < 0) { |
1043 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store)); |
1056 GtkListStore *store = create_list_store(list, view->model); |
1044 g_object_unref(G_OBJECT(store)); |
1057 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store)); |
|
1058 g_object_unref(G_OBJECT(store)); |
|
1059 } else { |
|
1060 void *elm = list->get(list, i); |
|
1061 GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(view->widget)); |
|
1062 GtkTreeIter iter; |
|
1063 if(gtk_tree_model_iter_nth_child(store, &iter, NULL, i)) { |
|
1064 update_list_row(GTK_LIST_STORE(store), &iter, view->model, elm); |
|
1065 } |
|
1066 } |
1045 } |
1067 } |
1046 |
1068 |
1047 UiListSelection ui_listview_getselection(UiList *list) { |
1069 UiListSelection ui_listview_getselection(UiList *list) { |
1048 UiListView *view = list->obj; |
1070 UiListView *view = list->obj; |
1049 UiListSelection selection = ui_listview_selection( |
1071 UiListSelection selection = ui_listview_selection( |