Commit e14b006bccd24b1a16506ba94536dc87dcf8b5c9
1 parent
3ecda06b
Exists in
master
and in
4 other branches
Implemening action list view.
Showing
4 changed files
with
79 additions
and
16 deletions
Show diff stats
src/include/pw3270/actions.h
... | ... | @@ -264,6 +264,11 @@ |
264 | 264 | |
265 | 265 | Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view); |
266 | 266 | |
267 | + // | |
268 | + // Tools | |
269 | + // | |
270 | + GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size); | |
271 | + | |
267 | 272 | G_END_DECLS |
268 | 273 | |
269 | 274 | #endif // PW3270_ACTIONS_H_INCLUDED | ... | ... |
src/objects/actions/abstract.c
... | ... | @@ -492,3 +492,58 @@ |
492 | 492 | GAction * pw3270_action_new() { |
493 | 493 | return G_ACTION(g_object_new(PW3270_TYPE_ACTION, NULL)); |
494 | 494 | } |
495 | + | |
496 | + static GdkPixbuf * pixbuf_from_icon_name(GValue *value, GtkIconSize icon_size) { | |
497 | + | |
498 | + const gchar * icon_name = g_value_get_string(value); | |
499 | + | |
500 | + if(!icon_name) | |
501 | + return NULL; | |
502 | + | |
503 | + return gtk_icon_theme_load_icon( | |
504 | + gtk_icon_theme_get_default(), | |
505 | + icon_name, | |
506 | + icon_size, | |
507 | + GTK_ICON_LOOKUP_GENERIC_FALLBACK, | |
508 | + NULL | |
509 | + ); | |
510 | + | |
511 | + } | |
512 | + | |
513 | + GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size) { | |
514 | + | |
515 | + struct Properties { | |
516 | + const gchar * name; | |
517 | + GType value_type; | |
518 | + GdkPixbuf * (*translate)(GValue *value, GtkIconSize icon_size); | |
519 | + } properties[] = { | |
520 | + { | |
521 | + .name = "icon-name", | |
522 | + .value_type = G_TYPE_STRING, | |
523 | + .translate = pixbuf_from_icon_name | |
524 | + } | |
525 | + }; | |
526 | + | |
527 | + size_t ix; | |
528 | + GdkPixbuf * pixbuf = NULL; | |
529 | + | |
530 | + for(ix = 0; ix < G_N_ELEMENTS(properties) && !pixbuf; ix++) { | |
531 | + | |
532 | + GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(action),properties[ix].name); | |
533 | + if(spec && spec->value_type == properties[ix].value_type && (spec->flags & G_PARAM_READABLE) != 0) { | |
534 | + | |
535 | + GValue value = G_VALUE_INIT; | |
536 | + g_value_init(&value, properties[ix].value_type); | |
537 | + | |
538 | + g_object_get_property(G_OBJECT(action),properties[ix].name,&value); | |
539 | + | |
540 | + pixbuf = properties[ix].translate(&value,icon_size); | |
541 | + | |
542 | + g_value_unset(&value); | |
543 | + | |
544 | + } | |
545 | + | |
546 | + } | |
547 | + | |
548 | + return pixbuf; | |
549 | + } | ... | ... |
src/objects/actions/lib3270/pfkey.c
src/objects/actions/view.c
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 | |
46 | 46 | struct ListElement { |
47 | 47 | GAction * action; |
48 | - GtkImage * image; | |
48 | + GdkPixbuf * pixbuf; | |
49 | 49 | gchar name[1]; |
50 | 50 | }; |
51 | 51 | |
... | ... | @@ -88,6 +88,7 @@ |
88 | 88 | Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view) { |
89 | 89 | |
90 | 90 | GSList * item = (GSList *) action_list; |
91 | + GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view))); | |
91 | 92 | |
92 | 93 | while(item) { |
93 | 94 | |
... | ... | @@ -118,6 +119,15 @@ |
118 | 119 | |
119 | 120 | debug("label=\"%s\"",g_value_get_string(&properties[0].value)); |
120 | 121 | |
122 | + GtkTreeIter iter; | |
123 | + gtk_list_store_append(store, &iter); | |
124 | + gtk_list_store_set( | |
125 | + store, | |
126 | + &iter, | |
127 | + COLUMN_PIXBUF, element->pixbuf, | |
128 | + COLUMN_LABEL, g_value_get_string(&properties[0].value), | |
129 | + -1 | |
130 | + ); | |
121 | 131 | |
122 | 132 | for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { |
123 | 133 | g_value_unset(&properties[ix].value); |
... | ... | @@ -162,16 +172,9 @@ |
162 | 172 | return list; |
163 | 173 | |
164 | 174 | const gchar *name = g_action_get_name(action); |
165 | -// debug("%s=%p",name,action); | |
166 | 175 | |
167 | - GValue value = G_VALUE_INIT; | |
168 | - g_value_init(&value, GTK_TYPE_IMAGE); | |
169 | - | |
170 | - g_object_get_property(G_OBJECT(action),"toolbar-icon",&value); | |
171 | - GObject * image = g_value_get_object(&value); | |
172 | - g_value_unset (&value); | |
173 | - | |
174 | - if(!image) | |
176 | + GdkPixbuf * pixbuf = g_action_get_pixbuf(action, GTK_ICON_SIZE_MENU); | |
177 | + if(!pixbuf) | |
175 | 178 | return list; |
176 | 179 | |
177 | 180 | struct ListElement * element = (struct ListElement *) g_malloc0(sizeof(struct ListElement) + strlen(type) + strlen(name)); |
... | ... | @@ -181,8 +184,8 @@ |
181 | 184 | |
182 | 185 | element->action = action; |
183 | 186 | |
184 | - element->image = GTK_IMAGE(image); | |
185 | - g_object_ref_sink(G_OBJECT(element->image)); | |
187 | + element->pixbuf = pixbuf; | |
188 | + g_object_ref_sink(G_OBJECT(element->pixbuf)); | |
186 | 189 | |
187 | 190 | return g_slist_prepend(list,element); |
188 | 191 | |
... | ... | @@ -222,9 +225,9 @@ |
222 | 225 | |
223 | 226 | void list_element_free(struct ListElement *element) { |
224 | 227 | |
225 | - if(element->image) { | |
226 | - g_object_unref(element->image); | |
227 | - element->image = NULL; | |
228 | + if(element->pixbuf) { | |
229 | + g_object_unref(element->pixbuf); | |
230 | + element->pixbuf = NULL; | |
228 | 231 | } |
229 | 232 | |
230 | 233 | g_free(element); | ... | ... |