fix treeview icons (GTK) newapi

Sun, 29 Sep 2024 13:33:34 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Sep 2024 13:33:34 +0200
branch
newapi
changeset 312
3f2b3d15668b
parent 311
450a813dc2a5
child 313
b679cc6059ab

fix treeview icons (GTK)

ui/gtk/image.c file | annotate | diff | comparison | revisions
ui/gtk/menu.c file | annotate | diff | comparison | revisions
ui/gtk/menu.h file | annotate | diff | comparison | revisions
ui/gtk/tree.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/image.c	Sun Sep 29 11:29:37 2024 +0200
+++ b/ui/gtk/image.c	Sun Sep 29 13:33:34 2024 +0200
@@ -126,7 +126,12 @@
 
 #if GTK_MAJOR_VERSION >= 4
 GdkPixbuf* ui_icon_pixbuf(UiIcon *icon) {
-    return NULL; // TODO
+    if(!icon->pixbuf) {
+        GFile *file = gtk_icon_paintable_get_file(icon->info);
+        GError *error = NULL;
+        icon->pixbuf = gdk_pixbuf_new_from_file(g_file_get_path(file), &error);
+    }
+    return icon->pixbuf;
 }
 #else
 GdkPixbuf* ui_icon_pixbuf(UiIcon *icon) {
--- a/ui/gtk/menu.c	Sun Sep 29 11:29:37 2024 +0200
+++ b/ui/gtk/menu.c	Sun Sep 29 13:33:34 2024 +0200
@@ -597,13 +597,14 @@
     ls->getvalue = il->getvalue;
     
     UiVar* var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST);
-    ls->list = var->value;
+    ls->var = var;
+    UiList *list = var->value;
     
     ls->callback = il->callback;
     ls->userdata = il->userdata;
     
-    ls->list->observers = ui_add_observer(
-            ls->list->observers,
+    list->observers = ui_add_observer(
+            list->observers,
             (ui_callback)ui_update_gmenu_item_list,
             ls);
     
@@ -616,13 +617,13 @@
     event->obj = obj;
     event->userdata = il->userdata;
     event->callback = il->callback;
-    event->customdata = NULL;
+    event->customdata = var;
     event->value = 0;
     
     g_signal_connect(
             action,
             "activate",
-            G_CALLBACK(ui_activate_event_wrapper),
+            G_CALLBACK(ui_menu_list_item_activate_event_wrapper),
             event);
     g_signal_connect(
             obj->widget,
@@ -648,16 +649,32 @@
     event->callback(&evt, event->userdata);    
 }
 
+void ui_menu_list_item_activate_event_wrapper(GSimpleAction* self, GVariant* parameter, UiEventData *event) {
+    int index = g_variant_get_int32(parameter);
+    UiVar *var = event->customdata;
+    UiList *list = var->value;
+    
+    UiEvent evt;
+    evt.obj = event->obj;
+    evt.window = event->obj->window;
+    evt.document = event->obj->ctx->document;
+    evt.eventdata = ui_list_get(list, index);
+    evt.intval = index;
+    event->callback(&evt, event->userdata);    
+    
+}
+
 void ui_update_gmenu_item_list(UiEvent *event, UiActiveGMenuItemList *list) {
     // remove old items
     for(int i=0;i<list->oldcount;i++) {
         g_menu_remove(list->menu, list->index);
     }
+    UiList *ls = list->var->value;
     
     // add list items
     ui_getvaluefunc getvalue = list->getvalue;
     int i = 0;
-    void* elm = ui_list_first(list->list);
+    void* elm = ui_list_first(ls);
     while(elm) {
         char *label = (char*) (getvalue ? getvalue(elm, 0) : elm);
         
@@ -666,7 +683,7 @@
         g_menu_item_set_action_and_target_value(item, list->action, v);
         g_menu_insert_item(list->menu, list->index+i, item);
         
-        elm = ui_list_next(list->list);
+        elm = ui_list_next(ls);
         i++;
     }
     
--- a/ui/gtk/menu.h	Sun Sep 29 11:29:37 2024 +0200
+++ b/ui/gtk/menu.h	Sun Sep 29 13:33:34 2024 +0200
@@ -88,7 +88,7 @@
     char             action[32];
     int              index;
     int              oldcount;
-    UiList           *list;
+    UiVar            *var;
     ui_getvaluefunc  getvalue;
     ui_callback      callback;
     void             *userdata;
@@ -104,6 +104,7 @@
 void ui_gmenu_add_menuitem_list(GMenu *p, int index, UiMenuItemI *item, UiObject *obj);
 
 void ui_activate_event_wrapper(GSimpleAction* self, GVariant* parameter, UiEventData *event);
+void ui_menu_list_item_activate_event_wrapper(GSimpleAction* self, GVariant* parameter, UiEventData *event);
 void ui_update_gmenu_item_list(UiEvent *event, UiActiveGMenuItemList *list);
 
 #endif
--- a/ui/gtk/tree.c	Sun Sep 29 11:29:37 2024 +0200
+++ b/ui/gtk/tree.c	Sun Sep 29 13:33:34 2024 +0200
@@ -113,11 +113,10 @@
                     case UI_ICON_TEXT:
                     case UI_ICON_TEXT_FREE: {
                         UiIcon *icon = data;
-                        char *str = model->getvalue(elm, c);
 #if GTK_MAJOR_VERSION >= 4
                         GValue iconvalue = G_VALUE_INIT;
                         g_value_init(&iconvalue, G_TYPE_OBJECT);
-                        g_value_set_object(&iconvalue, icon->info);
+                        g_value_set_object(&iconvalue, ui_icon_pixbuf(icon));
                         gtk_list_store_set_value(store, &iter, c, &iconvalue);
 #else
                         GValue pixbufvalue = G_VALUE_INIT;
@@ -131,6 +130,8 @@
                         gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
 #endif
                         c++;
+                        
+                        char *str = model->getvalue(elm, c);
                         g_value_init(&value, G_TYPE_STRING);
                         g_value_set_string(&value, str);
                         if(model->types[i] == UI_ICON_TEXT_FREE) {

mercurial