55 { "text/plain", 0, 1 }, |
55 { "text/plain", 0, 1 }, |
56 { "text/uri-list", 0, 2 }, |
56 { "text/uri-list", 0, 2 }, |
57 }; |
57 }; |
58 */ |
58 */ |
59 |
59 |
|
60 static void listview_copy_static_elements(UiListView *listview, char **elm, size_t nelm) { |
|
61 listview->elements = calloc(nelm, sizeof(char*)); |
|
62 listview->nelm = nelm; |
|
63 for(int i=0;i<nelm;i++) { |
|
64 listview->elements[i] = strdup(elm[i]); |
|
65 } |
|
66 } |
|
67 |
60 #if GTK_CHECK_VERSION(4, 10, 0) |
68 #if GTK_CHECK_VERSION(4, 10, 0) |
61 |
69 |
62 |
70 |
63 /* BEGIN GObject wrapper for generic pointers */ |
71 /* BEGIN GObject wrapper for generic pointers */ |
64 |
72 |
197 tableview->ondrop = args.ondrop; |
205 tableview->ondrop = args.ondrop; |
198 tableview->ondropdata = args.ondropsdata; |
206 tableview->ondropdata = args.ondropsdata; |
199 tableview->selection.count = 0; |
207 tableview->selection.count = 0; |
200 tableview->selection.rows = NULL; |
208 tableview->selection.rows = NULL; |
201 return tableview; |
209 return tableview; |
202 } |
|
203 |
|
204 static void listview_copy_static_elements(UiListView *listview, char **elm, size_t nelm) { |
|
205 listview->elements = calloc(nelm, sizeof(char*)); |
|
206 listview->nelm = nelm; |
|
207 for(int i=0;i<nelm;i++) { |
|
208 listview->elements[i] = strdup(elm[i]); |
|
209 } |
|
210 } |
210 } |
211 |
211 |
212 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) { |
212 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) { |
213 UiObject* current = uic_current_obj(obj); |
213 UiObject* current = uic_current_obj(obj); |
214 |
214 |
768 GtkListStore *listmodel = create_list_store(list, model); |
768 GtkListStore *listmodel = create_list_store(list, model); |
769 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); |
769 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); |
770 g_object_unref(listmodel); |
770 g_object_unref(listmodel); |
771 |
771 |
772 UiListView *listview = malloc(sizeof(UiListView)); |
772 UiListView *listview = malloc(sizeof(UiListView)); |
|
773 memset(listview, 0, sizeof(UiListView)); |
773 listview->obj = obj; |
774 listview->obj = obj; |
774 listview->widget = view; |
775 listview->widget = view; |
775 listview->var = var; |
776 listview->var = var; |
776 listview->model = model; |
777 listview->model = model; |
777 listview->selection.count = 0; |
778 listview->selection.count = 0; |
915 //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL); |
916 //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL); |
916 |
917 |
917 // add TreeView as observer to the UiList to update the TreeView if the |
918 // add TreeView as observer to the UiList to update the TreeView if the |
918 // data changes |
919 // data changes |
919 UiListView *tableview = malloc(sizeof(UiListView)); |
920 UiListView *tableview = malloc(sizeof(UiListView)); |
|
921 memset(tableview, 0, sizeof(UiListView)); |
920 tableview->obj = obj; |
922 tableview->obj = obj; |
921 tableview->widget = view; |
923 tableview->widget = view; |
922 tableview->var = var; |
924 tableview->var = var; |
923 tableview->model = model; |
925 tableview->model = model; |
924 tableview->ondragstart = args.ondragstart; |
926 tableview->ondragstart = args.ondragstart; |
1041 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
1043 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
1042 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; |
1044 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; |
1043 |
1045 |
1044 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
1046 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
1045 |
1047 |
1046 GtkWidget *combobox = ui_create_combobox(obj, model, var, args.onactivate, args.onactivatedata); |
1048 GtkWidget *combobox = ui_create_combobox(obj, model, var, args.static_elements, args.static_nelm, args.onactivate, args.onactivatedata); |
1047 ui_set_name_and_style(combobox, args.name, args.style_class); |
1049 ui_set_name_and_style(combobox, args.name, args.style_class); |
1048 ui_set_widget_groups(obj->ctx, combobox, args.groups); |
1050 ui_set_widget_groups(obj->ctx, combobox, args.groups); |
1049 UI_APPLY_LAYOUT1(current, args); |
1051 UI_APPLY_LAYOUT1(current, args); |
1050 current->container->add(current->container, combobox, FALSE); |
1052 current->container->add(current->container, combobox, FALSE); |
1051 current->container->current = combobox; |
1053 current->container->current = combobox; |
1052 return combobox; |
1054 return combobox; |
1053 } |
1055 } |
1054 |
1056 |
1055 GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, ui_callback f, void *udata) { |
1057 GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, char **elm, size_t nelm, ui_callback f, void *udata) { |
1056 GtkWidget *combobox = gtk_combo_box_new(); |
1058 GtkWidget *combobox = gtk_combo_box_new(); |
1057 |
1059 |
1058 UiListView *uicbox = malloc(sizeof(UiListView)); |
1060 UiListView *uicbox = malloc(sizeof(UiListView)); |
|
1061 memset(uicbox, 0, sizeof(UiListView)); |
1059 uicbox->obj = obj; |
1062 uicbox->obj = obj; |
1060 uicbox->widget = combobox; |
1063 uicbox->widget = combobox; |
1061 |
1064 |
1062 UiList *list = var ? var->value : NULL; |
1065 UiList *list = var ? var->value : NULL; |
1063 GtkListStore *listmodel = create_list_store(list, model); |
1066 GtkListStore *listmodel = create_list_store(list, model); |
|
1067 |
|
1068 if(!list && elm && nelm > 0) { |
|
1069 listview_copy_static_elements(uicbox, elm, nelm); |
|
1070 for(int i=0;i<nelm;i++) { |
|
1071 GtkTreeIter iter; |
|
1072 GValue value = G_VALUE_INIT; |
|
1073 gtk_list_store_insert(listmodel, &iter, -1); |
|
1074 g_value_init(&value, G_TYPE_STRING); |
|
1075 g_value_set_string(&value, uicbox->elements[i]); |
|
1076 gtk_list_store_set_value(listmodel, &iter, 0, &value); |
|
1077 } |
|
1078 } |
1064 |
1079 |
1065 if(listmodel) { |
1080 if(listmodel) { |
1066 gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel)); |
1081 gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel)); |
1067 g_object_unref(listmodel); |
1082 g_object_unref(listmodel); |
1068 } |
1083 } |
1112 |
1127 |
1113 return combobox; |
1128 return combobox; |
1114 } |
1129 } |
1115 |
1130 |
1116 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) { |
1131 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) { |
|
1132 int index = gtk_combo_box_get_active(widget); |
|
1133 UiListView *listview = e->customdata; |
|
1134 void *eventdata = NULL; |
|
1135 if(listview->var && listview->var->value) { |
|
1136 UiList *list = listview->var->value; |
|
1137 eventdata = ui_list_get(list, index); |
|
1138 } else if(listview->elements && listview->nelm > index) { |
|
1139 eventdata = listview->elements[index]; |
|
1140 } |
|
1141 |
1117 UiEvent event; |
1142 UiEvent event; |
1118 event.obj = e->obj; |
1143 event.obj = e->obj; |
1119 event.window = event.obj->window; |
1144 event.window = event.obj->window; |
1120 event.document = event.obj->ctx->document; |
1145 event.document = event.obj->ctx->document; |
1121 event.eventdata = NULL; |
1146 event.eventdata = eventdata; |
1122 event.intval = gtk_combo_box_get_active(widget); |
1147 event.intval = index; |
1123 e->callback(&event, e->userdata); |
1148 e->callback(&event, e->userdata); |
1124 } |
1149 } |
1125 |
1150 |
1126 void ui_combobox_modelupdate(UiList *list, int i) { |
1151 void ui_combobox_modelupdate(UiList *list, int i) { |
1127 UiListView *view = list->obj; |
1152 UiListView *view = list->obj; |