1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2001 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /*
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25 #include "config.h"
26
27 #define GDK_DISABLE_DEPRECATION_WARNINGS
28
29 #include "gtkimagemenuitem.h"
30
31 #include "gtkmenuitemprivate.h"
32 #include "gtkaccellabel.h"
33 #include "gtkstock.h"
34 #include "gtkiconfactory.h"
35 #include "gtkimage.h"
36 #include "gtkmenubar.h"
37 #include "gtkcontainer.h"
38 #include "gtkwindow.h"
39 #include "gtkactivatable.h"
40
41 #include "gtkintl.h"
42 #include "gtkprivate.h"
43
44
45 /**
46 * SECTION:gtkimagemenuitem
47 * @Short_description: A deprecated widget for a menu item with an icon
48 * @Title: GtkImageMenuItem
49 *
50 * A GtkImageMenuItem is a menu item which has an icon next to the text label.
51 *
52 * This is functionally equivalent to:
53 *
54 * |[<!-- language="C" -->
55 * GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
56 * GtkWidget *icon = gtk_image_new_from_icon_name ("folder-music-symbolic", GTK_ICON_SIZE_MENU);
57 * GtkWidget *label = gtk_label_new ("Music");
58 * GtkWidget *menu_item = gtk_menu_item_new ();
59 *
60 * gtk_container_add (GTK_CONTAINER (box), icon);
61 * gtk_container_add (GTK_CONTAINER (box), label);
62 *
63 * gtk_container_add (GTK_CONTAINER (menu_item), box);
64 *
65 * gtk_widget_show_all (menu_item);
66 * ]|
67 *
68 * Note that the user may disable display of menu icons using
69 * the #GtkSettings:gtk-menu-images setting, so make sure to still
70 * fill in the text label. If you want to ensure that your menu items
71 * show an icon you are strongly encouraged to use a #GtkMenuItem
72 * with a #GtkImage instead.
73 *
74 * #GtkImageMenuItem has been deprecated since GTK+ 3.10. If you want to
75 * display an icon in a menu item, you should use #GtkMenuItem and pack a
76 * #GtkBox with a #GtkImage and a #GtkLabel instead. You should also consider
77 * using #GtkBuilder and the XML #GMenu description for creating menus, by
78 * following the [GMenu guide][https://developer.gnome.org/GMenu/]. You should
79 * consider using icons in menu items only sparingly, and for "objects" (or
80 * "nouns") elements only, like bookmarks, files, and links; "actions" (or
81 * "verbs") should not have icons.
82 *
83 * Furthermore, if you would like to display keyboard accelerator, you must
84 * pack the accel label into the box using gtk_box_pack_end() and align the
85 * label, otherwise the accelerator will not display correctly. The following
86 * code snippet adds a keyboard accelerator to the menu item, with a key
87 * binding of Ctrl+M:
88 *
89 * |[<!-- language="C" -->
90 * GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
91 * GtkWidget *icon = gtk_image_new_from_icon_name ("folder-music-symbolic", GTK_ICON_SIZE_MENU);
92 * GtkWidget *label = gtk_accel_label_new ("Music");
93 * GtkWidget *menu_item = gtk_menu_item_new ();
94 * GtkAccelGroup *accel_group = gtk_accel_group_new ();
95 *
96 * gtk_container_add (GTK_CONTAINER (box), icon);
97 *
98 * gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
99 * gtk_label_set_xalign (GTK_LABEL (label), 0.0);
100 *
101 * gtk_widget_add_accelerator (menu_item, "activate", accel_group,
102 * GDK_KEY_m, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
103 * gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), menu_item);
104 *
105 * gtk_box_pack_end (GTK_BOX (box), label, TRUE, TRUE, 0);
106 *
107 * gtk_container_add (GTK_CONTAINER (menu_item), box);
108 *
109 * gtk_widget_show_all (menu_item);
110 * ]|
111 */
112
113
114 struct _GtkImageMenuItemPrivate
115 {
116 GtkWidget *image;
117
118 gchar *label;
119 guint use_stock : 1;
120 guint always_show_image : 1;
121 };
122
123 enum {
124 PROP_0,
125 PROP_IMAGE,
126 PROP_USE_STOCK,
127 PROP_ACCEL_GROUP,
128 PROP_ALWAYS_SHOW_IMAGE
129 };
130
131 static GtkActivatableIface *parent_activatable_iface;
132
133 static void gtk_image_menu_item_destroy (GtkWidget *widget);
134 static void gtk_image_menu_item_get_preferred_width (GtkWidget *widget,
135 gint *minimum,
136 gint *natural);
137 static void gtk_image_menu_item_get_preferred_height (GtkWidget *widget,
138 gint *minimum,
139 gint *natural);
140 static void gtk_image_menu_item_get_preferred_height_for_width (GtkWidget *widget,
141 gint width,
142 gint *minimum,
143 gint *natural);
144 static void gtk_image_menu_item_size_allocate (GtkWidget *widget,
145 GtkAllocation *allocation);
146 static void gtk_image_menu_item_map (GtkWidget *widget);
147 static void gtk_image_menu_item_remove (GtkContainer *container,
148 GtkWidget *child);
149 static void gtk_image_menu_item_toggle_size_request (GtkMenuItem *menu_item,
150 gint *requisition);
151 static void gtk_image_menu_item_set_label (GtkMenuItem *menu_item,
152 const gchar *label);
153 static const gchar * gtk_image_menu_item_get_label (GtkMenuItem *menu_item);
154
155 static void gtk_image_menu_item_forall (GtkContainer *container,
156 gboolean include_internals,
157 GtkCallback callback,
158 gpointer callback_data);
159
160 static void gtk_image_menu_item_finalize (GObject *object);
161 static void gtk_image_menu_item_set_property (GObject *object,
162 guint prop_id,
163 const GValue *value,
164 GParamSpec *pspec);
165 static void gtk_image_menu_item_get_property (GObject *object,
166 guint prop_id,
167 GValue *value,
168 GParamSpec *pspec);
169 static void gtk_image_menu_item_screen_changed (GtkWidget *widget,
170 GdkScreen *previous_screen);
171
172 static void gtk_image_menu_item_recalculate (GtkImageMenuItem *image_menu_item);
173
174 static void gtk_image_menu_item_activatable_interface_init (GtkActivatableIface *iface);
175 static void gtk_image_menu_item_update (GtkActivatable *activatable,
176 GtkAction *action,
177 const gchar *property_name);
178 static void gtk_image_menu_item_sync_action_properties (GtkActivatable *activatable,
179 GtkAction *action);
180
181
G_DEFINE_TYPE_WITH_CODE(GtkImageMenuItem,gtk_image_menu_item,GTK_TYPE_MENU_ITEM,G_ADD_PRIVATE (GtkImageMenuItem)G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,gtk_image_menu_item_activatable_interface_init))182 G_DEFINE_TYPE_WITH_CODE (GtkImageMenuItem, gtk_image_menu_item, GTK_TYPE_MENU_ITEM,
183 G_ADD_PRIVATE (GtkImageMenuItem)
184 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
185 gtk_image_menu_item_activatable_interface_init))
186
187
188 static void
189 gtk_image_menu_item_class_init (GtkImageMenuItemClass *klass)
190 {
191 GObjectClass *gobject_class = (GObjectClass*) klass;
192 GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
193 GtkMenuItemClass *menu_item_class = (GtkMenuItemClass*) klass;
194 GtkContainerClass *container_class = (GtkContainerClass*) klass;
195
196 widget_class->destroy = gtk_image_menu_item_destroy;
197 widget_class->screen_changed = gtk_image_menu_item_screen_changed;
198 widget_class->get_preferred_width = gtk_image_menu_item_get_preferred_width;
199 widget_class->get_preferred_height = gtk_image_menu_item_get_preferred_height;
200 widget_class->get_preferred_height_for_width = gtk_image_menu_item_get_preferred_height_for_width;
201 widget_class->size_allocate = gtk_image_menu_item_size_allocate;
202 widget_class->map = gtk_image_menu_item_map;
203
204 container_class->forall = gtk_image_menu_item_forall;
205 container_class->remove = gtk_image_menu_item_remove;
206
207 menu_item_class->toggle_size_request = gtk_image_menu_item_toggle_size_request;
208 menu_item_class->set_label = gtk_image_menu_item_set_label;
209 menu_item_class->get_label = gtk_image_menu_item_get_label;
210
211 gobject_class->finalize = gtk_image_menu_item_finalize;
212 gobject_class->set_property = gtk_image_menu_item_set_property;
213 gobject_class->get_property = gtk_image_menu_item_get_property;
214
215 /**
216 * GtkImageMenuItem:image:
217 *
218 * Child widget to appear next to the menu text.
219 *
220 * Deprecated: 3.10: Use a #GtkMenuItem containing a #GtkBox with
221 * a #GtkAccelLabel and a #GtkImage instead
222 */
223 g_object_class_install_property (gobject_class,
224 PROP_IMAGE,
225 g_param_spec_object ("image",
226 P_("Image widget"),
227 P_("Child widget to appear next to the menu text"),
228 GTK_TYPE_WIDGET,
229 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
230 /**
231 * GtkImageMenuItem:use-stock:
232 *
233 * If %TRUE, the label set in the menuitem is used as a
234 * stock id to select the stock item for the item.
235 *
236 * Since: 2.16
237 *
238 * Deprecated: 3.10: Use a named icon from the #GtkIconTheme instead
239 */
240 g_object_class_install_property (gobject_class,
241 PROP_USE_STOCK,
242 g_param_spec_boolean ("use-stock",
243 P_("Use stock"),
244 P_("Whether to use the label text to create a stock menu item"),
245 FALSE,
246 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_DEPRECATED));
247
248 /**
249 * GtkImageMenuItem:always-show-image:
250 *
251 * If %TRUE, the menu item will always show the image, if available.
252 *
253 * Use this property only if the menuitem would be useless or hard to use
254 * without the image.
255 *
256 * Since: 2.16
257 *
258 * Deprecated: 3.10: Use a #GtkMenuItem containing a #GtkBox with
259 * a #GtkAccelLabel and a #GtkImage instead
260 */
261 g_object_class_install_property (gobject_class,
262 PROP_ALWAYS_SHOW_IMAGE,
263 g_param_spec_boolean ("always-show-image",
264 P_("Always show image"),
265 P_("Whether the image will always be shown"),
266 FALSE,
267 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_DEPRECATED));
268
269 /**
270 * GtkImageMenuItem:accel-group:
271 *
272 * The Accel Group to use for stock accelerator keys
273 *
274 * Since: 2.16
275 *
276 * Deprecated: 3.10: Use gtk_widget_add_accelerator() instead
277 */
278 g_object_class_install_property (gobject_class,
279 PROP_ACCEL_GROUP,
280 g_param_spec_object ("accel-group",
281 P_("Accel Group"),
282 P_("The Accel Group to use for stock accelerator keys"),
283 GTK_TYPE_ACCEL_GROUP,
284 GTK_PARAM_WRITABLE | G_PARAM_DEPRECATED));
285
286 }
287
288 static void
gtk_image_menu_item_init(GtkImageMenuItem * image_menu_item)289 gtk_image_menu_item_init (GtkImageMenuItem *image_menu_item)
290 {
291 GtkImageMenuItemPrivate *priv;
292
293 image_menu_item->priv = gtk_image_menu_item_get_instance_private (image_menu_item);
294 priv = image_menu_item->priv;
295
296 priv->image = NULL;
297 priv->use_stock = FALSE;
298 priv->label = NULL;
299 }
300
301 static void
gtk_image_menu_item_finalize(GObject * object)302 gtk_image_menu_item_finalize (GObject *object)
303 {
304 GtkImageMenuItemPrivate *priv = GTK_IMAGE_MENU_ITEM (object)->priv;
305
306 g_free (priv->label);
307 priv->label = NULL;
308
309 G_OBJECT_CLASS (gtk_image_menu_item_parent_class)->finalize (object);
310 }
311
312 static void
gtk_image_menu_item_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)313 gtk_image_menu_item_set_property (GObject *object,
314 guint prop_id,
315 const GValue *value,
316 GParamSpec *pspec)
317 {
318 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (object);
319
320 switch (prop_id)
321 {
322 case PROP_IMAGE:
323 gtk_image_menu_item_set_image (image_menu_item, (GtkWidget *) g_value_get_object (value));
324 break;
325 case PROP_USE_STOCK:
326 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
327 gtk_image_menu_item_set_use_stock (image_menu_item, g_value_get_boolean (value));
328 G_GNUC_END_IGNORE_DEPRECATIONS;
329 break;
330 case PROP_ALWAYS_SHOW_IMAGE:
331 gtk_image_menu_item_set_always_show_image (image_menu_item, g_value_get_boolean (value));
332 break;
333 case PROP_ACCEL_GROUP:
334 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
335 gtk_image_menu_item_set_accel_group (image_menu_item, g_value_get_object (value));
336 G_GNUC_END_IGNORE_DEPRECATIONS;
337 break;
338 default:
339 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
340 break;
341 }
342 }
343
344 static void
gtk_image_menu_item_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)345 gtk_image_menu_item_get_property (GObject *object,
346 guint prop_id,
347 GValue *value,
348 GParamSpec *pspec)
349 {
350 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (object);
351
352 switch (prop_id)
353 {
354 case PROP_IMAGE:
355 g_value_set_object (value, gtk_image_menu_item_get_image (image_menu_item));
356 break;
357 case PROP_USE_STOCK:
358 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
359 g_value_set_boolean (value, gtk_image_menu_item_get_use_stock (image_menu_item));
360 G_GNUC_END_IGNORE_DEPRECATIONS;
361 break;
362 case PROP_ALWAYS_SHOW_IMAGE:
363 g_value_set_boolean (value, gtk_image_menu_item_get_always_show_image (image_menu_item));
364 break;
365 default:
366 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
367 break;
368 }
369 }
370
371 static gboolean
show_image(GtkImageMenuItem * image_menu_item)372 show_image (GtkImageMenuItem *image_menu_item)
373 {
374 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
375 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (image_menu_item));
376 gboolean show;
377
378 if (priv->always_show_image)
379 show = TRUE;
380 else
381 g_object_get (settings, "gtk-menu-images", &show, NULL);
382
383 return show;
384 }
385
386 static void
gtk_image_menu_item_map(GtkWidget * widget)387 gtk_image_menu_item_map (GtkWidget *widget)
388 {
389 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
390 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
391
392 GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->map (widget);
393
394 if (priv->image)
395 g_object_set (priv->image,
396 "visible", show_image (image_menu_item),
397 NULL);
398 }
399
400 static void
gtk_image_menu_item_destroy(GtkWidget * widget)401 gtk_image_menu_item_destroy (GtkWidget *widget)
402 {
403 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
404 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
405
406 if (priv->image)
407 gtk_container_remove (GTK_CONTAINER (image_menu_item),
408 priv->image);
409
410 GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->destroy (widget);
411 }
412
413 static void
gtk_image_menu_item_toggle_size_request(GtkMenuItem * menu_item,gint * requisition)414 gtk_image_menu_item_toggle_size_request (GtkMenuItem *menu_item,
415 gint *requisition)
416 {
417 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (menu_item);
418 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
419 GtkPackDirection pack_dir;
420 GtkWidget *parent;
421 GtkWidget *widget = GTK_WIDGET (menu_item);
422
423 parent = gtk_widget_get_parent (widget);
424
425 if (GTK_IS_MENU_BAR (parent))
426 pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
427 else
428 pack_dir = GTK_PACK_DIRECTION_LTR;
429
430 *requisition = 0;
431
432 if (priv->image && gtk_widget_get_visible (priv->image))
433 {
434 GtkRequisition image_requisition;
435 guint toggle_spacing;
436
437 gtk_widget_get_preferred_size (priv->image, &image_requisition, NULL);
438
439 gtk_widget_style_get (GTK_WIDGET (menu_item),
440 "toggle-spacing", &toggle_spacing,
441 NULL);
442
443 if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL)
444 {
445 if (image_requisition.width > 0)
446 *requisition = image_requisition.width + toggle_spacing;
447 }
448 else
449 {
450 if (image_requisition.height > 0)
451 *requisition = image_requisition.height + toggle_spacing;
452 }
453 }
454 }
455
456 static void
gtk_image_menu_item_recalculate(GtkImageMenuItem * image_menu_item)457 gtk_image_menu_item_recalculate (GtkImageMenuItem *image_menu_item)
458 {
459 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
460 GtkStockItem stock_item;
461 GtkWidget *image;
462 const gchar *resolved_label = priv->label;
463
464 if (priv->use_stock && priv->label)
465 {
466
467 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
468
469 if (!priv->image)
470 {
471 image = gtk_image_new_from_stock (priv->label, GTK_ICON_SIZE_MENU);
472 gtk_image_menu_item_set_image (image_menu_item, image);
473 }
474
475 if (gtk_stock_lookup (priv->label, &stock_item))
476 resolved_label = stock_item.label;
477
478 gtk_menu_item_set_use_underline (GTK_MENU_ITEM (image_menu_item), TRUE);
479
480 G_GNUC_END_IGNORE_DEPRECATIONS;
481 }
482
483 GTK_MENU_ITEM_CLASS
484 (gtk_image_menu_item_parent_class)->set_label (GTK_MENU_ITEM (image_menu_item), resolved_label);
485
486 }
487
488 static void
gtk_image_menu_item_set_label(GtkMenuItem * menu_item,const gchar * label)489 gtk_image_menu_item_set_label (GtkMenuItem *menu_item,
490 const gchar *label)
491 {
492 GtkImageMenuItemPrivate *priv = GTK_IMAGE_MENU_ITEM (menu_item)->priv;
493
494 if (priv->label != label)
495 {
496 g_free (priv->label);
497 priv->label = g_strdup (label);
498
499 gtk_image_menu_item_recalculate (GTK_IMAGE_MENU_ITEM (menu_item));
500
501 g_object_notify (G_OBJECT (menu_item), "label");
502
503 }
504 }
505
506 static const gchar *
gtk_image_menu_item_get_label(GtkMenuItem * menu_item)507 gtk_image_menu_item_get_label (GtkMenuItem *menu_item)
508 {
509 GtkImageMenuItemPrivate *priv = GTK_IMAGE_MENU_ITEM (menu_item)->priv;
510
511 return priv->label;
512 }
513
514 static void
gtk_image_menu_item_get_preferred_width(GtkWidget * widget,gint * minimum,gint * natural)515 gtk_image_menu_item_get_preferred_width (GtkWidget *widget,
516 gint *minimum,
517 gint *natural)
518 {
519 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
520 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
521 GtkPackDirection pack_dir;
522 GtkWidget *parent;
523
524 parent = gtk_widget_get_parent (widget);
525
526 if (GTK_IS_MENU_BAR (parent))
527 pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
528 else
529 pack_dir = GTK_PACK_DIRECTION_LTR;
530
531 GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->get_preferred_width (widget, minimum, natural);
532
533 if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
534 priv->image &&
535 gtk_widget_get_visible (priv->image))
536 {
537 gint child_minimum, child_natural;
538
539 gtk_widget_get_preferred_width (priv->image, &child_minimum, &child_natural);
540
541 *minimum = MAX (*minimum, child_minimum);
542 *natural = MAX (*natural, child_natural);
543 }
544 }
545
546 static void
gtk_image_menu_item_get_preferred_height(GtkWidget * widget,gint * minimum,gint * natural)547 gtk_image_menu_item_get_preferred_height (GtkWidget *widget,
548 gint *minimum,
549 gint *natural)
550 {
551 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
552 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
553 gint child_height = 0;
554 GtkPackDirection pack_dir;
555 GtkWidget *parent;
556
557 parent = gtk_widget_get_parent (widget);
558
559 if (GTK_IS_MENU_BAR (parent))
560 pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
561 else
562 pack_dir = GTK_PACK_DIRECTION_LTR;
563
564 if (priv->image && gtk_widget_get_visible (priv->image))
565 {
566 GtkRequisition child_requisition;
567
568 gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
569
570 child_height = child_requisition.height;
571 }
572
573 GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->get_preferred_height (widget, minimum, natural);
574
575 if (pack_dir == GTK_PACK_DIRECTION_RTL || pack_dir == GTK_PACK_DIRECTION_LTR)
576 {
577 *minimum = MAX (*minimum, child_height);
578 *natural = MAX (*natural, child_height);
579 }
580 }
581
582 static void
gtk_image_menu_item_get_preferred_height_for_width(GtkWidget * widget,gint width,gint * minimum,gint * natural)583 gtk_image_menu_item_get_preferred_height_for_width (GtkWidget *widget,
584 gint width,
585 gint *minimum,
586 gint *natural)
587 {
588 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
589 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
590 gint child_height = 0;
591 GtkPackDirection pack_dir;
592 GtkWidget *parent;
593
594 parent = gtk_widget_get_parent (widget);
595
596 if (GTK_IS_MENU_BAR (parent))
597 pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
598 else
599 pack_dir = GTK_PACK_DIRECTION_LTR;
600
601 if (priv->image && gtk_widget_get_visible (priv->image))
602 {
603 GtkRequisition child_requisition;
604
605 gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
606
607 child_height = child_requisition.height;
608 }
609
610 GTK_WIDGET_CLASS
611 (gtk_image_menu_item_parent_class)->get_preferred_height_for_width (widget, width, minimum, natural);
612
613 if (pack_dir == GTK_PACK_DIRECTION_RTL || pack_dir == GTK_PACK_DIRECTION_LTR)
614 {
615 *minimum = MAX (*minimum, child_height);
616 *natural = MAX (*natural, child_height);
617 }
618 }
619
620
621 static void
gtk_image_menu_item_size_allocate(GtkWidget * widget,GtkAllocation * allocation)622 gtk_image_menu_item_size_allocate (GtkWidget *widget,
623 GtkAllocation *allocation)
624 {
625 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
626 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
627 GtkAllocation widget_allocation;
628 GtkPackDirection pack_dir;
629 GtkWidget *parent;
630
631 parent = gtk_widget_get_parent (widget);
632
633 if (GTK_IS_MENU_BAR (parent))
634 pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
635 else
636 pack_dir = GTK_PACK_DIRECTION_LTR;
637
638 GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->size_allocate (widget, allocation);
639
640 if (priv->image && gtk_widget_get_visible (priv->image))
641 {
642 gint x, y, offset;
643 GtkStyleContext *context;
644 GtkStateFlags state;
645 GtkBorder padding;
646 GtkRequisition child_requisition;
647 GtkAllocation child_allocation;
648 guint toggle_spacing;
649 gint toggle_size;
650
651 toggle_size = GTK_MENU_ITEM (image_menu_item)->priv->toggle_size;
652 gtk_widget_style_get (widget,
653 "toggle-spacing", &toggle_spacing,
654 NULL);
655
656 /* Man this is lame hardcoding action, but I can't
657 * come up with a solution that's really better.
658 */
659
660 gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
661
662 gtk_widget_get_allocation (widget, &widget_allocation);
663
664 context = gtk_widget_get_style_context (widget);
665 state = gtk_widget_get_state_flags (widget);
666 gtk_style_context_get_padding (context, state, &padding);
667 offset = gtk_container_get_border_width (GTK_CONTAINER (image_menu_item));
668
669 if (pack_dir == GTK_PACK_DIRECTION_LTR ||
670 pack_dir == GTK_PACK_DIRECTION_RTL)
671 {
672 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) ==
673 (pack_dir == GTK_PACK_DIRECTION_LTR))
674 x = offset + padding.left +
675 (toggle_size - toggle_spacing - child_requisition.width) / 2;
676 else
677 x = widget_allocation.width - offset - padding.right -
678 toggle_size + toggle_spacing +
679 (toggle_size - toggle_spacing - child_requisition.width) / 2;
680
681 y = (widget_allocation.height - child_requisition.height) / 2;
682 }
683 else
684 {
685 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) ==
686 (pack_dir == GTK_PACK_DIRECTION_TTB))
687 y = offset + padding.top +
688 (toggle_size - toggle_spacing - child_requisition.height) / 2;
689 else
690 y = widget_allocation.height - offset - padding.bottom -
691 toggle_size + toggle_spacing +
692 (toggle_size - toggle_spacing - child_requisition.height) / 2;
693
694 x = (widget_allocation.width - child_requisition.width) / 2;
695 }
696
697 child_allocation.width = child_requisition.width;
698 child_allocation.height = child_requisition.height;
699 child_allocation.x = widget_allocation.x + MAX (x, 0);
700 child_allocation.y = widget_allocation.y + MAX (y, 0);
701
702 gtk_widget_size_allocate (priv->image, &child_allocation);
703 }
704 }
705
706 static void
gtk_image_menu_item_forall(GtkContainer * container,gboolean include_internals,GtkCallback callback,gpointer callback_data)707 gtk_image_menu_item_forall (GtkContainer *container,
708 gboolean include_internals,
709 GtkCallback callback,
710 gpointer callback_data)
711 {
712 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (container);
713 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
714
715 GTK_CONTAINER_CLASS (gtk_image_menu_item_parent_class)->forall (container,
716 include_internals,
717 callback,
718 callback_data);
719
720 if (include_internals && priv->image)
721 (* callback) (priv->image, callback_data);
722 }
723
724
725 static void
gtk_image_menu_item_activatable_interface_init(GtkActivatableIface * iface)726 gtk_image_menu_item_activatable_interface_init (GtkActivatableIface *iface)
727 {
728 parent_activatable_iface = g_type_interface_peek_parent (iface);
729 iface->update = gtk_image_menu_item_update;
730 iface->sync_action_properties = gtk_image_menu_item_sync_action_properties;
731 }
732
733 static GtkWidget *
gtk_image_menu_item_ensure_image(GtkImageMenuItem * item)734 gtk_image_menu_item_ensure_image (GtkImageMenuItem *item)
735 {
736 GtkWidget *image;
737
738 image = gtk_image_menu_item_get_image (item);
739 if (!GTK_IS_IMAGE (image))
740 {
741 image = gtk_image_new ();
742 gtk_widget_show (image);
743 gtk_image_menu_item_set_image (item, image);
744 }
745
746 return image;
747 }
748
749 static gboolean
activatable_update_stock_id(GtkImageMenuItem * image_menu_item,GtkAction * action)750 activatable_update_stock_id (GtkImageMenuItem *image_menu_item, GtkAction *action)
751 {
752 const gchar *stock_id = gtk_action_get_stock_id (action);
753
754 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
755
756 if (stock_id && gtk_icon_factory_lookup_default (stock_id))
757 {
758 GtkWidget *image;
759
760 image = gtk_image_menu_item_ensure_image (image_menu_item);
761 gtk_image_set_from_stock (GTK_IMAGE (image), stock_id, GTK_ICON_SIZE_MENU);
762 return TRUE;
763 }
764
765 G_GNUC_END_IGNORE_DEPRECATIONS;
766
767 return FALSE;
768 }
769
770 static gboolean
activatable_update_gicon(GtkImageMenuItem * image_menu_item,GtkAction * action)771 activatable_update_gicon (GtkImageMenuItem *image_menu_item, GtkAction *action)
772 {
773 GIcon *icon = gtk_action_get_gicon (action);
774 const gchar *stock_id;
775 gboolean ret = FALSE;
776
777 stock_id = gtk_action_get_stock_id (action);
778
779 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
780
781 if (icon && !(stock_id && gtk_icon_factory_lookup_default (stock_id)))
782 {
783 GtkWidget *image;
784
785 image = gtk_image_menu_item_ensure_image (image_menu_item);
786 gtk_image_set_from_gicon (GTK_IMAGE (image), icon, GTK_ICON_SIZE_MENU);
787 ret = TRUE;
788 }
789
790 G_GNUC_END_IGNORE_DEPRECATIONS;
791
792 return ret;
793 }
794
795 static gboolean
activatable_update_icon_name(GtkImageMenuItem * image_menu_item,GtkAction * action)796 activatable_update_icon_name (GtkImageMenuItem *image_menu_item, GtkAction *action)
797 {
798 const gchar *icon_name = gtk_action_get_icon_name (action);
799
800 if (icon_name)
801 {
802 GtkWidget *image;
803
804 image = gtk_image_menu_item_ensure_image (image_menu_item);
805 gtk_image_set_from_icon_name (GTK_IMAGE (image), icon_name, GTK_ICON_SIZE_MENU);
806 return TRUE;
807 }
808
809 return FALSE;
810 }
811
812 static void
gtk_image_menu_item_update(GtkActivatable * activatable,GtkAction * action,const gchar * property_name)813 gtk_image_menu_item_update (GtkActivatable *activatable,
814 GtkAction *action,
815 const gchar *property_name)
816 {
817 GtkImageMenuItem *image_menu_item;
818 gboolean use_appearance;
819
820 image_menu_item = GTK_IMAGE_MENU_ITEM (activatable);
821
822 parent_activatable_iface->update (activatable, action, property_name);
823
824 use_appearance = gtk_activatable_get_use_action_appearance (activatable);
825 if (!use_appearance)
826 return;
827
828 if (strcmp (property_name, "stock-id") == 0)
829 activatable_update_stock_id (image_menu_item, action);
830 else if (strcmp (property_name, "gicon") == 0)
831 activatable_update_gicon (image_menu_item, action);
832 else if (strcmp (property_name, "icon-name") == 0)
833 activatable_update_icon_name (image_menu_item, action);
834 }
835
836 static void
gtk_image_menu_item_sync_action_properties(GtkActivatable * activatable,GtkAction * action)837 gtk_image_menu_item_sync_action_properties (GtkActivatable *activatable,
838 GtkAction *action)
839 {
840 GtkImageMenuItem *image_menu_item;
841 gboolean use_appearance;
842
843 image_menu_item = GTK_IMAGE_MENU_ITEM (activatable);
844
845 parent_activatable_iface->sync_action_properties (activatable, action);
846
847 if (!action)
848 return;
849
850 use_appearance = gtk_activatable_get_use_action_appearance (activatable);
851 if (!use_appearance)
852 return;
853
854 if (!activatable_update_stock_id (image_menu_item, action) &&
855 !activatable_update_gicon (image_menu_item, action))
856 activatable_update_icon_name (image_menu_item, action);
857
858 gtk_image_menu_item_set_always_show_image (image_menu_item,
859 gtk_action_get_always_show_image (action));
860 }
861
862
863 /**
864 * gtk_image_menu_item_new:
865 *
866 * Creates a new #GtkImageMenuItem with an empty label.
867 *
868 * Returns: a new #GtkImageMenuItem
869 *
870 * Deprecated: 3.10: Use gtk_menu_item_new() instead.
871 */
872 GtkWidget*
gtk_image_menu_item_new(void)873 gtk_image_menu_item_new (void)
874 {
875 return g_object_new (GTK_TYPE_IMAGE_MENU_ITEM, NULL);
876 }
877
878 /**
879 * gtk_image_menu_item_new_with_label:
880 * @label: the text of the menu item.
881 *
882 * Creates a new #GtkImageMenuItem containing a label.
883 *
884 * Returns: a new #GtkImageMenuItem.
885 *
886 * Deprecated: 3.10: Use gtk_menu_item_new_with_label() instead.
887 */
888 GtkWidget*
gtk_image_menu_item_new_with_label(const gchar * label)889 gtk_image_menu_item_new_with_label (const gchar *label)
890 {
891 return g_object_new (GTK_TYPE_IMAGE_MENU_ITEM,
892 "label", label,
893 NULL);
894 }
895
896 /**
897 * gtk_image_menu_item_new_with_mnemonic:
898 * @label: the text of the menu item, with an underscore in front of the
899 * mnemonic character
900 *
901 * Creates a new #GtkImageMenuItem containing a label. The label
902 * will be created using gtk_label_new_with_mnemonic(), so underscores
903 * in @label indicate the mnemonic for the menu item.
904 *
905 * Returns: a new #GtkImageMenuItem
906 *
907 * Deprecated: 3.10: Use gtk_menu_item_new_with_mnemonic() instead.
908 */
909 GtkWidget*
gtk_image_menu_item_new_with_mnemonic(const gchar * label)910 gtk_image_menu_item_new_with_mnemonic (const gchar *label)
911 {
912 return g_object_new (GTK_TYPE_IMAGE_MENU_ITEM,
913 "use-underline", TRUE,
914 "label", label,
915 NULL);
916 }
917
918 /**
919 * gtk_image_menu_item_new_from_stock:
920 * @stock_id: the name of the stock item.
921 * @accel_group: (allow-none): the #GtkAccelGroup to add the menu items
922 * accelerator to, or %NULL.
923 *
924 * Creates a new #GtkImageMenuItem containing the image and text from a
925 * stock item. Some stock ids have preprocessor macros like #GTK_STOCK_OK
926 * and #GTK_STOCK_APPLY.
927 *
928 * If you want this menu item to have changeable accelerators, then pass in
929 * %NULL for accel_group. Next call gtk_menu_item_set_accel_path() with an
930 * appropriate path for the menu item, use gtk_stock_lookup() to look up the
931 * standard accelerator for the stock item, and if one is found, call
932 * gtk_accel_map_add_entry() to register it.
933 *
934 * Returns: a new #GtkImageMenuItem.
935 *
936 * Deprecated: 3.10: Use gtk_menu_item_new_with_mnemonic() instead.
937 */
938 GtkWidget*
gtk_image_menu_item_new_from_stock(const gchar * stock_id,GtkAccelGroup * accel_group)939 gtk_image_menu_item_new_from_stock (const gchar *stock_id,
940 GtkAccelGroup *accel_group)
941 {
942 return g_object_new (GTK_TYPE_IMAGE_MENU_ITEM,
943 "label", stock_id,
944 "use-stock", TRUE,
945 "accel-group", accel_group,
946 NULL);
947 }
948
949 /**
950 * gtk_image_menu_item_set_use_stock:
951 * @image_menu_item: a #GtkImageMenuItem
952 * @use_stock: %TRUE if the menuitem should use a stock item
953 *
954 * If %TRUE, the label set in the menuitem is used as a
955 * stock id to select the stock item for the item.
956 *
957 * Since: 2.16
958 *
959 * Deprecated: 3.10
960 */
961 void
gtk_image_menu_item_set_use_stock(GtkImageMenuItem * image_menu_item,gboolean use_stock)962 gtk_image_menu_item_set_use_stock (GtkImageMenuItem *image_menu_item,
963 gboolean use_stock)
964 {
965 GtkImageMenuItemPrivate *priv;
966
967 g_return_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item));
968
969 priv = image_menu_item->priv;
970
971 if (priv->use_stock != use_stock)
972 {
973 priv->use_stock = use_stock;
974
975 gtk_image_menu_item_recalculate (image_menu_item);
976
977 g_object_notify (G_OBJECT (image_menu_item), "use-stock");
978 }
979 }
980
981 /**
982 * gtk_image_menu_item_get_use_stock:
983 * @image_menu_item: a #GtkImageMenuItem
984 *
985 * Checks whether the label set in the menuitem is used as a
986 * stock id to select the stock item for the item.
987 *
988 * Returns: %TRUE if the label set in the menuitem is used as a
989 * stock id to select the stock item for the item
990 *
991 * Since: 2.16
992 *
993 * Deprecated: 3.10
994 */
995 gboolean
gtk_image_menu_item_get_use_stock(GtkImageMenuItem * image_menu_item)996 gtk_image_menu_item_get_use_stock (GtkImageMenuItem *image_menu_item)
997 {
998 g_return_val_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item), FALSE);
999
1000 return image_menu_item->priv->use_stock;
1001 }
1002
1003 /**
1004 * gtk_image_menu_item_set_always_show_image:
1005 * @image_menu_item: a #GtkImageMenuItem
1006 * @always_show: %TRUE if the menuitem should always show the image
1007 *
1008 * If %TRUE, the menu item will ignore the #GtkSettings:gtk-menu-images
1009 * setting and always show the image, if available.
1010 *
1011 * Use this property if the menuitem would be useless or hard to use
1012 * without the image.
1013 *
1014 * Since: 2.16
1015 *
1016 * Deprecated: 3.10
1017 */
1018 void
gtk_image_menu_item_set_always_show_image(GtkImageMenuItem * image_menu_item,gboolean always_show)1019 gtk_image_menu_item_set_always_show_image (GtkImageMenuItem *image_menu_item,
1020 gboolean always_show)
1021 {
1022 GtkImageMenuItemPrivate *priv;
1023
1024 g_return_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item));
1025
1026 priv = image_menu_item->priv;
1027
1028 if (priv->always_show_image != always_show)
1029 {
1030 priv->always_show_image = always_show;
1031
1032 if (priv->image)
1033 {
1034 if (show_image (image_menu_item))
1035 gtk_widget_show (priv->image);
1036 else
1037 gtk_widget_hide (priv->image);
1038 }
1039
1040 g_object_notify (G_OBJECT (image_menu_item), "always-show-image");
1041 }
1042 }
1043
1044 /**
1045 * gtk_image_menu_item_get_always_show_image:
1046 * @image_menu_item: a #GtkImageMenuItem
1047 *
1048 * Returns whether the menu item will ignore the #GtkSettings:gtk-menu-images
1049 * setting and always show the image, if available.
1050 *
1051 * Returns: %TRUE if the menu item will always show the image
1052 *
1053 * Since: 2.16
1054 *
1055 * Deprecated: 3.10
1056 */
1057 gboolean
gtk_image_menu_item_get_always_show_image(GtkImageMenuItem * image_menu_item)1058 gtk_image_menu_item_get_always_show_image (GtkImageMenuItem *image_menu_item)
1059 {
1060 g_return_val_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item), FALSE);
1061
1062 return image_menu_item->priv->always_show_image;
1063 }
1064
1065
1066 /**
1067 * gtk_image_menu_item_set_accel_group:
1068 * @image_menu_item: a #GtkImageMenuItem
1069 * @accel_group: the #GtkAccelGroup
1070 *
1071 * Specifies an @accel_group to add the menu items accelerator to
1072 * (this only applies to stock items so a stock item must already
1073 * be set, make sure to call gtk_image_menu_item_set_use_stock()
1074 * and gtk_menu_item_set_label() with a valid stock item first).
1075 *
1076 * If you want this menu item to have changeable accelerators then
1077 * you shouldnt need this (see gtk_image_menu_item_new_from_stock()).
1078 *
1079 * Since: 2.16
1080 *
1081 * Deprecated: 3.10
1082 */
1083 void
gtk_image_menu_item_set_accel_group(GtkImageMenuItem * image_menu_item,GtkAccelGroup * accel_group)1084 gtk_image_menu_item_set_accel_group (GtkImageMenuItem *image_menu_item,
1085 GtkAccelGroup *accel_group)
1086 {
1087 GtkImageMenuItemPrivate *priv;
1088 GtkStockItem stock_item;
1089
1090 /* Silent return for the constructor */
1091 if (!accel_group)
1092 return;
1093
1094 g_return_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item));
1095 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
1096
1097 priv = image_menu_item->priv;
1098
1099 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
1100
1101 if (priv->use_stock && priv->label && gtk_stock_lookup (priv->label, &stock_item))
1102 if (stock_item.keyval)
1103 {
1104 gtk_widget_add_accelerator (GTK_WIDGET (image_menu_item),
1105 "activate",
1106 accel_group,
1107 stock_item.keyval,
1108 stock_item.modifier,
1109 GTK_ACCEL_VISIBLE);
1110
1111 g_object_notify (G_OBJECT (image_menu_item), "accel-group");
1112 }
1113
1114 G_GNUC_END_IGNORE_DEPRECATIONS;
1115
1116 }
1117
1118 /**
1119 * gtk_image_menu_item_set_image:
1120 * @image_menu_item: a #GtkImageMenuItem.
1121 * @image: (allow-none): a widget to set as the image for the menu item.
1122 *
1123 * Sets the image of @image_menu_item to the given widget.
1124 * Note that it depends on the show-menu-images setting whether
1125 * the image will be displayed or not.
1126 *
1127 * Deprecated: 3.10
1128 */
1129 void
gtk_image_menu_item_set_image(GtkImageMenuItem * image_menu_item,GtkWidget * image)1130 gtk_image_menu_item_set_image (GtkImageMenuItem *image_menu_item,
1131 GtkWidget *image)
1132 {
1133 GtkImageMenuItemPrivate *priv;
1134
1135 g_return_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item));
1136
1137 priv = image_menu_item->priv;
1138
1139 if (image == priv->image)
1140 return;
1141
1142 if (priv->image)
1143 gtk_container_remove (GTK_CONTAINER (image_menu_item),
1144 priv->image);
1145
1146 priv->image = image;
1147
1148 if (image == NULL)
1149 return;
1150
1151 gtk_widget_set_parent (image, GTK_WIDGET (image_menu_item));
1152 g_object_set (image,
1153 "visible", show_image (image_menu_item),
1154 "no-show-all", TRUE,
1155 NULL);
1156 gtk_image_set_pixel_size (GTK_IMAGE (image), 16);
1157
1158 g_object_notify (G_OBJECT (image_menu_item), "image");
1159 }
1160
1161 /**
1162 * gtk_image_menu_item_get_image:
1163 * @image_menu_item: a #GtkImageMenuItem
1164 *
1165 * Gets the widget that is currently set as the image of @image_menu_item.
1166 * See gtk_image_menu_item_set_image().
1167 *
1168 * Returns: (transfer none): the widget set as image of @image_menu_item
1169 *
1170 * Deprecated: 3.10
1171 **/
1172 GtkWidget*
gtk_image_menu_item_get_image(GtkImageMenuItem * image_menu_item)1173 gtk_image_menu_item_get_image (GtkImageMenuItem *image_menu_item)
1174 {
1175 g_return_val_if_fail (GTK_IS_IMAGE_MENU_ITEM (image_menu_item), NULL);
1176
1177 return image_menu_item->priv->image;
1178 }
1179
1180 static void
gtk_image_menu_item_remove(GtkContainer * container,GtkWidget * child)1181 gtk_image_menu_item_remove (GtkContainer *container,
1182 GtkWidget *child)
1183 {
1184 GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (container);
1185 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
1186
1187 if (child == priv->image)
1188 {
1189 gboolean widget_was_visible;
1190
1191 widget_was_visible = gtk_widget_get_visible (child);
1192
1193 gtk_widget_unparent (child);
1194 priv->image = NULL;
1195
1196 if (widget_was_visible &&
1197 gtk_widget_get_visible (GTK_WIDGET (container)))
1198 gtk_widget_queue_resize (GTK_WIDGET (container));
1199
1200 g_object_notify (G_OBJECT (image_menu_item), "image");
1201 }
1202 else
1203 {
1204 GTK_CONTAINER_CLASS (gtk_image_menu_item_parent_class)->remove (container, child);
1205 }
1206 }
1207
1208 static void
show_image_change_notify(GtkImageMenuItem * image_menu_item)1209 show_image_change_notify (GtkImageMenuItem *image_menu_item)
1210 {
1211 GtkImageMenuItemPrivate *priv = image_menu_item->priv;
1212
1213 if (priv->image)
1214 {
1215 if (show_image (image_menu_item))
1216 gtk_widget_show (priv->image);
1217 else
1218 gtk_widget_hide (priv->image);
1219 }
1220 }
1221
1222 static void
traverse_container(GtkWidget * widget,gpointer data)1223 traverse_container (GtkWidget *widget,
1224 gpointer data)
1225 {
1226 if (GTK_IS_IMAGE_MENU_ITEM (widget))
1227 show_image_change_notify (GTK_IMAGE_MENU_ITEM (widget));
1228 else if (GTK_IS_CONTAINER (widget))
1229 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1230 }
1231
1232 static void
gtk_image_menu_item_setting_changed(GtkSettings * settings)1233 gtk_image_menu_item_setting_changed (GtkSettings *settings)
1234 {
1235 GList *list, *l;
1236
1237 list = gtk_window_list_toplevels ();
1238
1239 for (l = list; l; l = l->next)
1240 gtk_container_forall (GTK_CONTAINER (l->data),
1241 traverse_container, NULL);
1242
1243 g_list_free (list);
1244 }
1245
1246 static void
gtk_image_menu_item_screen_changed(GtkWidget * widget,GdkScreen * previous_screen)1247 gtk_image_menu_item_screen_changed (GtkWidget *widget,
1248 GdkScreen *previous_screen)
1249 {
1250 GtkSettings *settings;
1251 gulong show_image_connection;
1252
1253 if (!gtk_widget_has_screen (widget))
1254 return;
1255
1256 settings = gtk_widget_get_settings (widget);
1257
1258 show_image_connection =
1259 g_signal_handler_find (settings, G_SIGNAL_MATCH_FUNC, 0, 0,
1260 NULL, gtk_image_menu_item_setting_changed, NULL);
1261
1262 if (show_image_connection)
1263 return;
1264
1265 g_signal_connect (settings, "notify::gtk-menu-images",
1266 G_CALLBACK (gtk_image_menu_item_setting_changed), NULL);
1267
1268 show_image_change_notify (GTK_IMAGE_MENU_ITEM (widget));
1269 }
1270