ui/gtk/model.c

changeset 128
c284c15509a8
parent 124
80609f9675f1
child 129
5babf09f5f19
equal deleted inserted replaced
127:ce342364fad5 128:c284c15509a8
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(GType type, void *data, GValue *value) { 108 static void ui_model_set_value(UiModelType type, void *data, GValue *value) {
109 switch(type) { 109 switch(type) {
110 case G_TYPE_STRING: { 110 case UI_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 G_TYPE_INT: { 115 case UI_INTEGER: {
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 = calloc(sizeof(GType), 2 * info->columns); 129 model->columntypes = malloc(sizeof(GType));
130 int ncol = 0; 130 model->numcolumns = info->columns;
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 model->columntypes[i] = ui_gtk_type(info->types[i]);
133 if(type == UI_ICON_TEXT) { 133 }
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;
143 return model; 134 return model;
144 } 135 }
145 136
146 137
147 GtkTreeModelFlags ui_list_model_get_flags(GtkTreeModel *tree_model) { 138 GtkTreeModelFlags ui_list_model_get_flags(GtkTreeModel *tree_model) {
244 list->iter = iter->user_data; 235 list->iter = iter->user_data;
245 //list->index = (int)(intptr_t)iter->user_data2; 236 //list->index = (int)(intptr_t)iter->user_data2;
246 //list->current = iter->user_data3; 237 //list->current = iter->user_data3;
247 if(model->info->getvalue) { 238 if(model->info->getvalue) {
248 void *data = model->info->getvalue(iter->user_data3, column); 239 void *data = model->info->getvalue(iter->user_data3, column);
249 ui_model_set_value(model->columntypes[column], data, value); 240 ui_model_set_value(model->info->types[column], data, value);
250 } else { 241 } else {
251 value->g_type = G_TYPE_INVALID; 242 value->g_type = G_TYPE_INVALID;
252 } 243 }
253 } 244 }
254 245

mercurial