ui/gtk/model.c

changeset 129
5babf09f5f19
parent 128
c284c15509a8
child 140
c03c338a7dcf
equal deleted inserted replaced
128:c284c15509a8 129:5babf09f5f19
103 case UI_INTEGER: return G_TYPE_INT; 103 case UI_INTEGER: return G_TYPE_INT;
104 } 104 }
105 return G_TYPE_INVALID; 105 return G_TYPE_INVALID;
106 } 106 }
107 107
108 static void ui_model_set_value(UiModelType type, void *data, GValue *value) { 108 static void ui_model_set_value(GType type, void *data, GValue *value) {
109 switch(type) { 109 switch(type) {
110 case UI_STRING: { 110 case G_TYPE_STRING: {
111 value->g_type = G_TYPE_STRING; 111 value->g_type = G_TYPE_STRING;
112 g_value_set_string(value, data); 112 g_value_set_string(value, data);
113 return; 113 return;
114 } 114 }
115 case UI_INTEGER: { 115 case G_TYPE_INT: {
116 value->g_type = G_TYPE_INT; 116 value->g_type = G_TYPE_INT;
117 int *i = data; 117 int *i = data;
118 g_value_set_int(value, *i); 118 g_value_set_int(value, *i);
119 return; 119 return;
120 } 120 }
124 124
125 UiListModel* ui_list_model_new(UiListPtr *list, UiModelInfo *info) { 125 UiListModel* ui_list_model_new(UiListPtr *list, 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->list = list;
129 model->columntypes = malloc(sizeof(GType)); 129 model->columntypes = calloc(sizeof(GType), 2 * info->columns);
130 model->numcolumns = info->columns; 130 int ncol = 0;
131 for(int i=0;i<info->columns;i++) { 131 for(int i=0;i<info->columns;i++) {
132 model->columntypes[i] = ui_gtk_type(info->types[i]); 132 UiModelType type = info->types[i];
133 } 133 if(type == UI_ICON_TEXT) {
134 model->columntypes[ncol] = G_TYPE_STRING;
135 ncol++;
136 model->columntypes[ncol] = G_TYPE_STRING;
137 } else {
138 model->columntypes[ncol] = ui_gtk_type(info->types[i]);
139 }
140 ncol++;
141 }
142 model->numcolumns = ncol;
134 return model; 143 return model;
135 } 144 }
136 145
137 146
138 GtkTreeModelFlags ui_list_model_get_flags(GtkTreeModel *tree_model) { 147 GtkTreeModelFlags ui_list_model_get_flags(GtkTreeModel *tree_model) {
235 list->iter = iter->user_data; 244 list->iter = iter->user_data;
236 //list->index = (int)(intptr_t)iter->user_data2; 245 //list->index = (int)(intptr_t)iter->user_data2;
237 //list->current = iter->user_data3; 246 //list->current = iter->user_data3;
238 if(model->info->getvalue) { 247 if(model->info->getvalue) {
239 void *data = model->info->getvalue(iter->user_data3, column); 248 void *data = model->info->getvalue(iter->user_data3, column);
240 ui_model_set_value(model->info->types[column], data, value); 249 ui_model_set_value(model->columntypes[column], data, value);
241 } else { 250 } else {
242 value->g_type = G_TYPE_INVALID; 251 value->g_type = G_TYPE_INVALID;
243 } 252 }
244 } 253 }
245 254

mercurial