95 instance->list = NULL; |
95 instance->list = 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 UiListModel* ui_list_model_new(UiListPtr *list, ui_model_getvalue_f getvalue) { |
100 static GType ui_gtk_type(UiModelType type) { |
|
101 switch(type) { |
|
102 case UI_STRING: return G_TYPE_STRING; |
|
103 case UI_INTEGER: return G_TYPE_INT; |
|
104 } |
|
105 return G_TYPE_INVALID; |
|
106 } |
|
107 |
|
108 static void ui_model_set_value(UiModelType type, void *data, GValue *value) { |
|
109 switch(type) { |
|
110 case UI_STRING: { |
|
111 value->g_type = G_TYPE_STRING; |
|
112 g_value_set_string(value, data); |
|
113 return; |
|
114 } |
|
115 case UI_INTEGER: { |
|
116 value->g_type = G_TYPE_INT; |
|
117 int *i = data; |
|
118 g_value_set_int(value, *i); |
|
119 return; |
|
120 } |
|
121 } |
|
122 value->g_type = G_TYPE_INVALID; |
|
123 } |
|
124 |
|
125 UiListModel* ui_list_model_new(UiListPtr *list, UiModelInfo *info) { |
101 UiListModel *model = g_object_new(list_model_type, NULL); |
126 UiListModel *model = g_object_new(list_model_type, NULL); |
|
127 model->info = info; |
102 model->list = list; |
128 model->list = list; |
103 model->getvalue = getvalue; |
|
104 model->columntypes = malloc(sizeof(GType)); |
129 model->columntypes = malloc(sizeof(GType)); |
105 model->numcolumns = 1; |
130 model->numcolumns = info->columns; |
106 model->columntypes[0] = G_TYPE_STRING; |
131 for(int i=0;i<info->columns;i++) { |
|
132 model->columntypes[i] = ui_gtk_type(info->types[i]); |
|
133 } |
107 return model; |
134 return model; |
108 } |
135 } |
109 |
136 |
110 |
137 |
111 GtkTreeModelFlags ui_list_model_get_flags(GtkTreeModel *tree_model) { |
138 GtkTreeModelFlags ui_list_model_get_flags(GtkTreeModel *tree_model) { |
202 |
229 |
203 g_return_if_fail(column < model->numcolumns); |
230 g_return_if_fail(column < model->numcolumns); |
204 |
231 |
205 // TODO: return correct value from column |
232 // TODO: return correct value from column |
206 |
233 |
207 value->g_type = G_TYPE_STRING; |
234 //value->g_type = G_TYPE_STRING; |
208 list->iter = iter->user_data; |
235 list->iter = iter->user_data; |
209 //list->index = (int)(intptr_t)iter->user_data2; |
236 //list->index = (int)(intptr_t)iter->user_data2; |
210 //list->current = iter->user_data3; |
237 //list->current = iter->user_data3; |
211 if(model->getvalue) { |
238 if(model->info->getvalue) { |
212 char *str = model->getvalue(iter->user_data3, column); |
239 void *data = model->info->getvalue(iter->user_data3, column); |
213 g_value_set_string(value, str); |
240 ui_model_set_value(model->info->types[column], data, value); |
214 } else { |
241 } else { |
215 g_value_set_string(value, iter->user_data3); |
242 value->g_type = G_TYPE_INVALID; |
216 } |
243 } |
217 } |
244 } |
218 |
245 |
219 gboolean ui_list_model_iter_next( |
246 gboolean ui_list_model_iter_next( |
220 GtkTreeModel *tree_model, |
247 GtkTreeModel *tree_model, |