1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2014 Olaf Wintermann. All rights reserved. |
4 * Copyright 2017 Olaf Wintermann. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
90 i->iter_parent = ui_list_model_iter_parent; |
90 i->iter_parent = ui_list_model_iter_parent; |
91 } |
91 } |
92 |
92 |
93 static void list_model_init(UiListModel *instance, GObjectClass *cl) { |
93 static void list_model_init(UiListModel *instance, GObjectClass *cl) { |
94 instance->columntypes = NULL; |
94 instance->columntypes = NULL; |
95 instance->list = NULL; |
95 instance->var = NULL; |
96 instance->numcolumns = 0; |
96 instance->numcolumns = 0; |
97 instance->stamp = g_random_int(); |
97 instance->stamp = g_random_int(); |
98 } |
98 } |
99 |
99 |
100 static GType ui_gtk_type(UiModelType type) { |
100 static GType ui_gtk_type(UiModelType type) { |
120 } |
120 } |
121 } |
121 } |
122 value->g_type = G_TYPE_INVALID; |
122 value->g_type = G_TYPE_INVALID; |
123 } |
123 } |
124 |
124 |
125 UiListModel* ui_list_model_new(UiListPtr *list, UiModelInfo *info) { |
125 UiListModel* ui_list_model_new(UiVar *var, UiModelInfo *info) { |
126 UiListModel *model = g_object_new(list_model_type, NULL); |
126 UiListModel *model = g_object_new(list_model_type, NULL); |
127 model->info = info; |
127 model->info = info; |
128 model->list = list; |
128 model->var = var; |
129 model->columntypes = calloc(sizeof(GType), 2 * info->columns); |
129 model->columntypes = calloc(sizeof(GType), 2 * info->columns); |
130 int ncol = 0; |
130 int ncol = 0; |
131 for(int i=0;i<info->columns;i++) { |
131 for(int i=0;i<info->columns;i++) { |
132 UiModelType type = info->types[i]; |
132 UiModelType type = info->types[i]; |
133 if(type == UI_ICON_TEXT) { |
133 if(type == UI_ICON_TEXT) { |
166 GtkTreeIter *iter, |
166 GtkTreeIter *iter, |
167 GtkTreePath *path) |
167 GtkTreePath *path) |
168 { |
168 { |
169 g_assert(IS_UI_LIST_MODEL(tree_model)); |
169 g_assert(IS_UI_LIST_MODEL(tree_model)); |
170 UiListModel *model = UI_LIST_MODEL(tree_model); |
170 UiListModel *model = UI_LIST_MODEL(tree_model); |
171 UiList *list = model->list->list; |
171 UiList *list = model->var->value; |
172 |
172 |
173 // check the depth of the path |
173 // check the depth of the path |
174 // a list must have a depth of 1 |
174 // a list must have a depth of 1 |
175 gint depth = gtk_tree_path_get_depth(path); |
175 gint depth = gtk_tree_path_get_depth(path); |
176 g_assert(depth == 1); |
176 g_assert(depth == 1); |
213 g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), NULL); |
213 g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), NULL); |
214 g_return_val_if_fail(iter != NULL, NULL); |
214 g_return_val_if_fail(iter != NULL, NULL); |
215 g_return_val_if_fail(iter->user_data != NULL, NULL); |
215 g_return_val_if_fail(iter->user_data != NULL, NULL); |
216 |
216 |
217 UiListModel *model = UI_LIST_MODEL(tree_model); |
217 UiListModel *model = UI_LIST_MODEL(tree_model); |
218 UiList *list = model->list->list; |
|
219 |
218 |
220 GtkTreePath *path = gtk_tree_path_new(); |
219 GtkTreePath *path = gtk_tree_path_new(); |
221 gtk_tree_path_append_index(path, (int)(intptr_t)iter->user_data2); // list->index |
220 gtk_tree_path_append_index(path, (int)(intptr_t)iter->user_data2); // list->index |
222 |
221 |
223 return path; |
222 return path; |
232 g_return_if_fail(IS_UI_LIST_MODEL(tree_model)); |
231 g_return_if_fail(IS_UI_LIST_MODEL(tree_model)); |
233 g_return_if_fail(iter != NULL); |
232 g_return_if_fail(iter != NULL); |
234 g_return_if_fail(iter->user_data != NULL); |
233 g_return_if_fail(iter->user_data != NULL); |
235 |
234 |
236 UiListModel *model = UI_LIST_MODEL(tree_model); |
235 UiListModel *model = UI_LIST_MODEL(tree_model); |
237 UiList *list = model->list->list; |
236 UiList *list = model->var->value; |
238 |
237 |
239 g_return_if_fail(column < model->numcolumns); |
238 g_return_if_fail(column < model->numcolumns); |
240 |
239 |
241 // TODO: return correct value from column |
240 // TODO: return correct value from column |
242 |
241 |
259 g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); |
258 g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); |
260 g_return_val_if_fail(iter != NULL, FALSE); |
259 g_return_val_if_fail(iter != NULL, FALSE); |
261 g_return_val_if_fail(iter->user_data != NULL, FALSE); |
260 g_return_val_if_fail(iter->user_data != NULL, FALSE); |
262 |
261 |
263 UiListModel *model = UI_LIST_MODEL(tree_model); |
262 UiListModel *model = UI_LIST_MODEL(tree_model); |
264 UiList *list = model->list->list; |
263 UiList *list = model->var->value; |
265 list->iter = iter->user_data; |
264 list->iter = iter->user_data; |
266 //list->index = (int)(intptr_t)iter->user_data2; |
265 //list->index = (int)(intptr_t)iter->user_data2; |
267 void *val = list->next(list); |
266 void *val = list->next(list); |
268 iter->user_data = list->iter; |
267 iter->user_data = list->iter; |
269 intptr_t index = (intptr_t)iter->user_data2; |
268 intptr_t index = (intptr_t)iter->user_data2; |
315 g_assert(IS_UI_LIST_MODEL(tree_model)); |
314 g_assert(IS_UI_LIST_MODEL(tree_model)); |
316 |
315 |
317 if(!iter) { |
316 if(!iter) { |
318 // return number of rows |
317 // return number of rows |
319 UiListModel *model = UI_LIST_MODEL(tree_model); |
318 UiListModel *model = UI_LIST_MODEL(tree_model); |
320 UiList *list = model->list->list; |
319 UiList *list = model->var->value; |
321 return list->count(list); |
320 return list->count(list); |
322 } |
321 } |
323 |
322 |
324 return 0; |
323 return 0; |
325 } |
324 } |