From e14b006bccd24b1a16506ba94536dc87dcf8b5c9 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 20 Dec 2019 16:16:07 -0300 Subject: [PATCH] Implemening action list view. --- src/include/pw3270/actions.h | 5 +++++ src/objects/actions/abstract.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/objects/actions/lib3270/pfkey.c | 2 +- src/objects/actions/view.c | 33 ++++++++++++++++++--------------- 4 files changed, 79 insertions(+), 16 deletions(-) diff --git a/src/include/pw3270/actions.h b/src/include/pw3270/actions.h index dc60b9a..a47f6d8 100644 --- a/src/include/pw3270/actions.h +++ b/src/include/pw3270/actions.h @@ -264,6 +264,11 @@ Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view); + // + // Tools + // + GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size); + G_END_DECLS #endif // PW3270_ACTIONS_H_INCLUDED diff --git a/src/objects/actions/abstract.c b/src/objects/actions/abstract.c index 33a9023..b46f299 100644 --- a/src/objects/actions/abstract.c +++ b/src/objects/actions/abstract.c @@ -492,3 +492,58 @@ GAction * pw3270_action_new() { return G_ACTION(g_object_new(PW3270_TYPE_ACTION, NULL)); } + + static GdkPixbuf * pixbuf_from_icon_name(GValue *value, GtkIconSize icon_size) { + + const gchar * icon_name = g_value_get_string(value); + + if(!icon_name) + return NULL; + + return gtk_icon_theme_load_icon( + gtk_icon_theme_get_default(), + icon_name, + icon_size, + GTK_ICON_LOOKUP_GENERIC_FALLBACK, + NULL + ); + + } + + GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size) { + + struct Properties { + const gchar * name; + GType value_type; + GdkPixbuf * (*translate)(GValue *value, GtkIconSize icon_size); + } properties[] = { + { + .name = "icon-name", + .value_type = G_TYPE_STRING, + .translate = pixbuf_from_icon_name + } + }; + + size_t ix; + GdkPixbuf * pixbuf = NULL; + + for(ix = 0; ix < G_N_ELEMENTS(properties) && !pixbuf; ix++) { + + GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(action),properties[ix].name); + if(spec && spec->value_type == properties[ix].value_type && (spec->flags & G_PARAM_READABLE) != 0) { + + GValue value = G_VALUE_INIT; + g_value_init(&value, properties[ix].value_type); + + g_object_get_property(G_OBJECT(action),properties[ix].name,&value); + + pixbuf = properties[ix].translate(&value,icon_size); + + g_value_unset(&value); + + } + + } + + return pixbuf; + } diff --git a/src/objects/actions/lib3270/pfkey.c b/src/objects/actions/lib3270/pfkey.c index dc23b4a..09b8225 100644 --- a/src/objects/actions/lib3270/pfkey.c +++ b/src/objects/actions/lib3270/pfkey.c @@ -99,7 +99,7 @@ } - void Lib3270PfAction_init(Lib3270PfAction *action) { + void Lib3270PfAction_init(Lib3270PfAction G_GNUC_UNUSED(*action)) { } GAction * pw3270_action_new_pfkey(void) { diff --git a/src/objects/actions/view.c b/src/objects/actions/view.c index 60b69f4..5888b49 100644 --- a/src/objects/actions/view.c +++ b/src/objects/actions/view.c @@ -45,7 +45,7 @@ struct ListElement { GAction * action; - GtkImage * image; + GdkPixbuf * pixbuf; gchar name[1]; }; @@ -88,6 +88,7 @@ Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view) { GSList * item = (GSList *) action_list; + GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view))); while(item) { @@ -118,6 +119,15 @@ debug("label=\"%s\"",g_value_get_string(&properties[0].value)); + GtkTreeIter iter; + gtk_list_store_append(store, &iter); + gtk_list_store_set( + store, + &iter, + COLUMN_PIXBUF, element->pixbuf, + COLUMN_LABEL, g_value_get_string(&properties[0].value), + -1 + ); for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { g_value_unset(&properties[ix].value); @@ -162,16 +172,9 @@ return list; const gchar *name = g_action_get_name(action); -// debug("%s=%p",name,action); - GValue value = G_VALUE_INIT; - g_value_init(&value, GTK_TYPE_IMAGE); - - g_object_get_property(G_OBJECT(action),"toolbar-icon",&value); - GObject * image = g_value_get_object(&value); - g_value_unset (&value); - - if(!image) + GdkPixbuf * pixbuf = g_action_get_pixbuf(action, GTK_ICON_SIZE_MENU); + if(!pixbuf) return list; struct ListElement * element = (struct ListElement *) g_malloc0(sizeof(struct ListElement) + strlen(type) + strlen(name)); @@ -181,8 +184,8 @@ element->action = action; - element->image = GTK_IMAGE(image); - g_object_ref_sink(G_OBJECT(element->image)); + element->pixbuf = pixbuf; + g_object_ref_sink(G_OBJECT(element->pixbuf)); return g_slist_prepend(list,element); @@ -222,9 +225,9 @@ void list_element_free(struct ListElement *element) { - if(element->image) { - g_object_unref(element->image); - element->image = NULL; + if(element->pixbuf) { + g_object_unref(element->pixbuf); + element->pixbuf = NULL; } g_free(element); -- libgit2 0.21.2