142 |
142 |
143 return store; |
143 return store; |
144 } |
144 } |
145 |
145 |
146 |
146 |
147 UIWIDGET ui_listview_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) { |
147 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) { |
|
148 UiObject* current = uic_current_obj(obj); |
|
149 |
148 // create treeview |
150 // create treeview |
149 GtkWidget *view = gtk_tree_view_new(); |
151 GtkWidget *view = gtk_tree_view_new(); |
150 GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
152 GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
151 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 0, NULL); |
153 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 0, NULL); |
152 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); |
154 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); |
161 #else |
163 #else |
162 // TODO: implement for gtk2 |
164 // TODO: implement for gtk2 |
163 #endif |
165 #endif |
164 |
166 |
165 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
167 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
166 model->getvalue = getvalue; |
168 model->getvalue = args.getvalue; |
167 UiList *list = var->value; |
169 |
|
170 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
|
171 |
|
172 UiList *list = var ? var->value : NULL; |
168 GtkListStore *listmodel = create_list_store(list, model); |
173 GtkListStore *listmodel = create_list_store(list, model); |
169 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); |
174 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); |
170 |
175 |
171 UiListView *listview = malloc(sizeof(UiListView)); |
176 UiListView *listview = malloc(sizeof(UiListView)); |
172 listview->obj = obj; |
177 listview->obj = obj; |
182 // bind var |
187 // bind var |
183 list->update = ui_listview_update; |
188 list->update = ui_listview_update; |
184 list->obj = listview; |
189 list->obj = listview; |
185 |
190 |
186 // add callback |
191 // add callback |
187 if(f) { |
192 if(args.onactivate) { |
188 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData)); |
193 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData)); |
189 event->obj = obj; |
194 event->obj = obj; |
190 event->activatedata = udata; |
195 event->activatedata = args.onactivatedata; |
191 event->activate = f; |
196 event->activate = args.onactivate; |
192 event->selection = NULL; |
197 event->selection = NULL; |
193 |
198 |
194 g_signal_connect( |
199 g_signal_connect( |
195 view, |
200 view, |
196 "row-activated", |
201 "row-activated", |
204 GTK_SCROLLED_WINDOW(scroll_area), |
209 GTK_SCROLLED_WINDOW(scroll_area), |
205 GTK_POLICY_AUTOMATIC, |
210 GTK_POLICY_AUTOMATIC, |
206 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
211 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
207 gtk_container_add(GTK_CONTAINER(scroll_area), view); |
212 gtk_container_add(GTK_CONTAINER(scroll_area), view); |
208 |
213 |
209 UiContainer *ct = uic_get_current_container(obj); |
214 UI_APPLY_LAYOUT1(current, args); |
210 ct->add(ct, scroll_area, TRUE); |
215 current->container->add(current->container, scroll_area, FALSE); |
211 |
216 |
212 // ct->current should point to view, not scroll_area, to make it possible |
217 // ct->current should point to view, not scroll_area, to make it possible |
213 // to add a context menu |
218 // to add a context menu |
214 ct->current = view; |
219 current->container->current = view; |
215 |
220 |
216 return scroll_area; |
221 return scroll_area; |
217 } |
|
218 |
|
219 UIWIDGET ui_listview_deprecated(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata) { |
|
220 UiVar *var = malloc(sizeof(UiVar)); |
|
221 var->value = list; |
|
222 var->type = UI_VAR_SPECIAL; |
|
223 return ui_listview_var(obj, var, getvalue, f, udata); |
|
224 } |
|
225 |
|
226 UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata) { |
|
227 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST); |
|
228 if(var) { |
|
229 return ui_listview_var(obj, var, getvalue, f, udata); |
|
230 } else { |
|
231 // TODO: error |
|
232 } |
|
233 return NULL; |
|
234 } |
222 } |
235 |
223 |
236 static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer udata) { |
224 static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer udata) { |
237 printf("drag begin\n"); |
225 printf("drag begin\n"); |
238 |
226 |