ui/gtk/tree.c

changeset 44
473954dc6b74
parent 41
7ada3db4cfa8
equal deleted inserted replaced
43:ef01d2c90128 44:473954dc6b74
93 break; 93 break;
94 } 94 }
95 case UI_ICON: { 95 case UI_ICON: {
96 g_value_init(&value, G_TYPE_OBJECT); 96 g_value_init(&value, G_TYPE_OBJECT);
97 UiIcon *icon = data; 97 UiIcon *icon = data;
98 #if GTK_MAJOR_VERSION >= 4
99 g_value_set_object(&value, icon->info); // TODO: does this work?
100 #else
98 if(!icon->pixbuf && icon->info) { 101 if(!icon->pixbuf && icon->info) {
99 GError *error = NULL; 102 GError *error = NULL;
100 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); 103 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
101 icon->pixbuf = pixbuf; 104 icon->pixbuf = pixbuf;
102 } 105 }
103 106
104 if(icon->pixbuf) { 107 if(icon->pixbuf) {
105 g_value_set_object(&value, icon->pixbuf); 108 g_value_set_object(&value, icon->pixbuf);
106 } 109 }
107 110 #endif
108
109 break; 111 break;
110 } 112 }
111 case UI_ICON_TEXT: 113 case UI_ICON_TEXT:
112 case UI_ICON_TEXT_FREE: { 114 case UI_ICON_TEXT_FREE: {
115 UiIcon *icon = data;
116 #if GTK_MAJOR_VERSION >= 4
117 GValue iconvalue = G_VALUE_INIT;
118 g_value_init(&iconvalue, G_TYPE_OBJECT);
119 g_value_set_object(&iconvalue, ui_icon_pixbuf(icon));
120 gtk_list_store_set_value(store, &iter, c, &iconvalue);
121 #else
113 GValue pixbufvalue = G_VALUE_INIT; 122 GValue pixbufvalue = G_VALUE_INIT;
114 UiIcon *icon = data;
115 if(!icon->pixbuf && icon->info) { 123 if(!icon->pixbuf && icon->info) {
116 GError *error = NULL; 124 GError *error = NULL;
117 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); 125 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
118 icon->pixbuf = pixbuf; 126 icon->pixbuf = pixbuf;
119 } 127 }
120 g_value_init(&pixbufvalue, G_TYPE_OBJECT); 128 g_value_init(&pixbufvalue, G_TYPE_OBJECT);
121 g_value_set_object(&pixbufvalue, icon->pixbuf); 129 g_value_set_object(&pixbufvalue, icon->pixbuf);
122 gtk_list_store_set_value(store, &iter, c, &pixbufvalue); 130 gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
131 #endif
123 c++; 132 c++;
124 133
125 char *str = model->getvalue(elm, c); 134 char *str = model->getvalue(elm, c);
126 g_value_init(&value, G_TYPE_STRING); 135 g_value_init(&value, G_TYPE_STRING);
127 g_value_set_string(&value, str); 136 g_value_set_string(&value, str);
203 G_CALLBACK(ui_listview_activate_event), 212 G_CALLBACK(ui_listview_activate_event),
204 event); 213 event);
205 } 214 }
206 215
207 // add widget to the current container 216 // add widget to the current container
208 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL); 217 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
209 gtk_scrolled_window_set_policy( 218 gtk_scrolled_window_set_policy(
210 GTK_SCROLLED_WINDOW(scroll_area), 219 GTK_SCROLLED_WINDOW(scroll_area),
211 GTK_POLICY_AUTOMATIC, 220 GTK_POLICY_AUTOMATIC,
212 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS 221 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
213 gtk_container_add(GTK_CONTAINER(scroll_area), view); 222 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
214 223
215 UI_APPLY_LAYOUT1(current, args); 224 UI_APPLY_LAYOUT1(current, args);
216 current->container->add(current->container, scroll_area, FALSE); 225 current->container->add(current->container, scroll_area, FALSE);
217 226
218 // ct->current should point to view, not scroll_area, to make it possible 227 // ct->current should point to view, not scroll_area, to make it possible
220 current->container->current = view; 229 current->container->current = view;
221 230
222 return scroll_area; 231 return scroll_area;
223 } 232 }
224 233
234 /*
225 static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer udata) { 235 static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer udata) {
226 printf("drag begin\n"); 236 printf("drag begin\n");
227 237
228 } 238 }
229 239
234 gpointer udata) 244 gpointer udata)
235 { 245 {
236 printf("drag end\n"); 246 printf("drag end\n");
237 247
238 } 248 }
239 249 */
250
251 /*
240 static GtkTargetEntry targetentries[] = 252 static GtkTargetEntry targetentries[] =
241 { 253 {
242 { "STRING", 0, 0 }, 254 { "STRING", 0, 0 },
243 { "text/plain", 0, 1 }, 255 { "text/plain", 0, 1 },
244 { "text/uri-list", 0, 2 }, 256 { "text/uri-list", 0, 2 },
245 }; 257 };
258 */
246 259
247 UIWIDGET ui_table_create(UiObject *obj, UiListArgs args) { 260 UIWIDGET ui_table_create(UiObject *obj, UiListArgs args) {
248 UiObject* current = uic_current_obj(obj); 261 UiObject* current = uic_current_obj(obj);
249 262
250 // create treeview 263 // create treeview
354 367
355 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view)); 368 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
356 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); 369 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
357 370
358 // add widget to the current container 371 // add widget to the current container
359 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL); 372 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
360 gtk_scrolled_window_set_policy( 373 gtk_scrolled_window_set_policy(
361 GTK_SCROLLED_WINDOW(scroll_area), 374 GTK_SCROLLED_WINDOW(scroll_area),
362 GTK_POLICY_AUTOMATIC, 375 GTK_POLICY_AUTOMATIC,
363 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS 376 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
364 gtk_container_add(GTK_CONTAINER(scroll_area), view); 377 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
365 378
366 UI_APPLY_LAYOUT1(current, args); 379 UI_APPLY_LAYOUT1(current, args);
367 current->container->add(current->container, scroll_area, FALSE); 380 current->container->add(current->container, scroll_area, FALSE);
368 381
369 // ct->current should point to view, not scroll_area, to make it possible 382 // ct->current should point to view, not scroll_area, to make it possible
373 return scroll_area; 386 return scroll_area;
374 } 387 }
375 388
376 389
377 GtkWidget* ui_get_tree_widget(UIWIDGET widget) { 390 GtkWidget* ui_get_tree_widget(UIWIDGET widget) {
378 GList *c = gtk_container_get_children(GTK_CONTAINER(widget)); 391 return SCROLLEDWINDOW_GET_CHILD(widget);
379 if(c) {
380 return c->data;
381 }
382 return NULL;
383 } 392 }
384 393
385 static char** targets2array(char *target0, va_list ap, int *nelm) { 394 static char** targets2array(char *target0, va_list ap, int *nelm) {
386 int al = 16; 395 int al = 16;
387 char **targets = calloc(16, sizeof(char*)); 396 char **targets = calloc(16, sizeof(char*));
400 409
401 *nelm = i; 410 *nelm = i;
402 return targets; 411 return targets;
403 } 412 }
404 413
414 /*
405 static GtkTargetEntry* targetstr2gtktargets(char **str, int nelm) { 415 static GtkTargetEntry* targetstr2gtktargets(char **str, int nelm) {
406 GtkTargetEntry *targets = calloc(nelm, sizeof(GtkTargetEntry)); 416 GtkTargetEntry *targets = calloc(nelm, sizeof(GtkTargetEntry));
407 for(int i=0;i<nelm;i++) { 417 for(int i=0;i<nelm;i++) {
408 targets[i].target = str[i]; 418 targets[i].target = str[i];
409 } 419 }
410 return targets; 420 return targets;
411 } 421 }
422 */
412 423
413 void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...) { 424 void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...) {
414 va_list ap; 425 va_list ap;
415 va_start(ap, target0); 426 va_start(ap, target0);
416 int nelm; 427 int nelm;

mercurial