ui/gtk/model.c

changeset 146
dd0ae1c62a72
parent 142
46448d38885c
child 147
2e384acc89a6
equal deleted inserted replaced
145:853685152c1d 146:dd0ae1c62a72
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include "model.h" 32 #include "model.h"
33 #include "image.h"
33 34
34 #define IS_UI_LIST_MODEL(obj) \ 35 #define IS_UI_LIST_MODEL(obj) \
35 (G_TYPE_CHECK_INSTANCE_TYPE((obj), list_model_type)) 36 (G_TYPE_CHECK_INSTANCE_TYPE((obj), list_model_type))
36 #define UI_LIST_MODEL(obj) \ 37 #define UI_LIST_MODEL(obj) \
37 (G_TYPE_CHECK_INSTANCE_CAST((obj), list_model_type, UiListModel)) 38 (G_TYPE_CHECK_INSTANCE_CAST((obj), list_model_type, UiListModel))
105 return G_TYPE_INVALID; 106 return G_TYPE_INVALID;
106 } 107 }
107 108
108 static void ui_model_set_value(GType type, void *data, GValue *value) { 109 static void ui_model_set_value(GType type, void *data, GValue *value) {
109 switch(type) { 110 switch(type) {
111 case G_TYPE_OBJECT: {
112 value->g_type = G_TYPE_OBJECT;
113 g_value_set_object(value, data);
114 return;
115 }
110 case G_TYPE_STRING: { 116 case G_TYPE_STRING: {
111 value->g_type = G_TYPE_STRING; 117 value->g_type = G_TYPE_STRING;
112 g_value_set_string(value, data); 118 g_value_set_string(value, data);
113 return; 119 return;
114 } 120 }
129 model->columntypes = calloc(sizeof(GType), 2 * info->columns); 135 model->columntypes = calloc(sizeof(GType), 2 * info->columns);
130 int ncol = 0; 136 int ncol = 0;
131 for(int i=0;i<info->columns;i++) { 137 for(int i=0;i<info->columns;i++) {
132 UiModelType type = info->types[i]; 138 UiModelType type = info->types[i];
133 if(type == UI_ICON_TEXT) { 139 if(type == UI_ICON_TEXT) {
134 model->columntypes[ncol] = G_TYPE_STRING; 140 model->columntypes[ncol] = G_TYPE_OBJECT;
135 ncol++; 141 ncol++;
136 model->columntypes[ncol] = G_TYPE_STRING; 142 model->columntypes[ncol] = G_TYPE_STRING;
137 } else { 143 } else {
138 model->columntypes[ncol] = ui_gtk_type(info->types[i]); 144 model->columntypes[ncol] = ui_gtk_type(info->types[i]);
139 } 145 }
243 list->iter = iter->user_data; 249 list->iter = iter->user_data;
244 //list->index = (int)(intptr_t)iter->user_data2; 250 //list->index = (int)(intptr_t)iter->user_data2;
245 //list->current = iter->user_data3; 251 //list->current = iter->user_data3;
246 if(model->info->getvalue) { 252 if(model->info->getvalue) {
247 void *data = model->info->getvalue(iter->user_data3, column); 253 void *data = model->info->getvalue(iter->user_data3, column);
248 ui_model_set_value(model->columntypes[column], data, value); 254 if(model->columntypes[column] == G_TYPE_OBJECT) {
255 UiImage *img = data;
256 ui_model_set_value(model->columntypes[column], img->pixbuf, value);
257 } else {
258 ui_model_set_value(model->columntypes[column], data, value);
259 }
249 } else { 260 } else {
250 value->g_type = G_TYPE_INVALID; 261 value->g_type = G_TYPE_INVALID;
251 } 262 }
252 } 263 }
253 264
255 GtkTreeModel *tree_model, 266 GtkTreeModel *tree_model,
256 GtkTreeIter *iter) 267 GtkTreeIter *iter)
257 { 268 {
258 g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); 269 g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE);
259 g_return_val_if_fail(iter != NULL, FALSE); 270 g_return_val_if_fail(iter != NULL, FALSE);
260 g_return_val_if_fail(iter->user_data != NULL, FALSE); 271 //g_return_val_if_fail(iter->user_data != NULL, FALSE);
272
273 if(!iter->user_data) {
274 return FALSE;
275 }
261 276
262 UiListModel *model = UI_LIST_MODEL(tree_model); 277 UiListModel *model = UI_LIST_MODEL(tree_model);
263 UiList *list = model->var->value; 278 UiList *list = model->var->value;
264 list->iter = iter->user_data; 279 list->iter = iter->user_data;
265 //list->index = (int)(intptr_t)iter->user_data2; 280 //list->index = (int)(intptr_t)iter->user_data2;

mercurial