]> Pileus Git - ~andy/gtk/blob - gtk/gtkmenuitem.c
Updated Serbian translation
[~andy/gtk] / gtk / gtkmenuitem.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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 #include <string.h>
28
29 #include "gtkaccellabel.h"
30 #include "gtkmain.h"
31 #include "gtkmarshalers.h"
32 #include "gtkmenuprivate.h"
33 #include "gtkmenushellprivate.h"
34 #include "gtkmenuitemprivate.h"
35 #include "gtkmenubar.h"
36 #include "gtkmenuprivate.h"
37 #include "gtkseparatormenuitem.h"
38 #include "gtkprivate.h"
39 #include "gtkbuildable.h"
40 #include "gtkactivatable.h"
41 #include "gtkwidgetprivate.h"
42 #include "gtkintl.h"
43 #include "gtksettings.h"
44 #include "gtktypebuiltins.h"
45 #include "a11y/gtkmenuitemaccessible.h"
46
47
48 /**
49  * SECTION:gtkmenuitem
50  * @Short_description: The widget used for item in menus
51  * @Title: GtkMenuItem
52  * @See_also: #GtkBin, #GtkMenuShell
53  *
54  * The #GtkMenuItem widget and the derived widgets are the only valid
55  * childs for menus. Their function is to correctly handle highlighting,
56  * alignment, events and submenus.
57  *
58  * As it derives from #GtkBin it can hold any valid child widget, altough
59  * only a few are really useful.
60  *
61  * <refsect2 id="GtkMenuItem-BUILDER-UI">
62  * <title>GtkMenuItem as GtkBuildable</title>
63  * The GtkMenuItem implementation of the GtkBuildable interface
64  * supports adding a submenu by specifying "submenu" as the "type"
65  * attribute of a &lt;child&gt; element.
66  * <example>
67  * <title>A UI definition fragment with submenus</title>
68  * <programlisting><![CDATA[
69  * <object class="GtkMenuItem">
70  *   <child type="submenu">
71  *     <object class="GtkMenu"/>
72  *   </child>
73  * </object>
74  * ]]></programlisting>
75  * </example>
76  * </refsect2>
77  */
78
79
80 enum {
81   ACTIVATE,
82   ACTIVATE_ITEM,
83   TOGGLE_SIZE_REQUEST,
84   TOGGLE_SIZE_ALLOCATE,
85   SELECT,
86   DESELECT,
87   LAST_SIGNAL
88 };
89
90 enum {
91   PROP_0,
92   PROP_RIGHT_JUSTIFIED,
93   PROP_SUBMENU,
94   PROP_ACCEL_PATH,
95   PROP_LABEL,
96   PROP_USE_UNDERLINE,
97
98   /* activatable properties */
99   PROP_ACTIVATABLE_RELATED_ACTION,
100   PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
101 };
102
103
104 static void gtk_menu_item_dispose        (GObject          *object);
105 static void gtk_menu_item_set_property   (GObject          *object,
106                                           guint             prop_id,
107                                           const GValue     *value,
108                                           GParamSpec       *pspec);
109 static void gtk_menu_item_get_property   (GObject          *object,
110                                           guint             prop_id,
111                                           GValue           *value,
112                                           GParamSpec       *pspec);
113 static void gtk_menu_item_destroy        (GtkWidget        *widget);
114 static void gtk_menu_item_size_allocate  (GtkWidget        *widget,
115                                           GtkAllocation    *allocation);
116 static void gtk_menu_item_realize        (GtkWidget        *widget);
117 static void gtk_menu_item_unrealize      (GtkWidget        *widget);
118 static void gtk_menu_item_map            (GtkWidget        *widget);
119 static void gtk_menu_item_unmap          (GtkWidget        *widget);
120 static gboolean gtk_menu_item_enter      (GtkWidget        *widget,
121                                           GdkEventCrossing *event);
122 static gboolean gtk_menu_item_leave      (GtkWidget        *widget,
123                                           GdkEventCrossing *event);
124 static gboolean gtk_menu_item_draw       (GtkWidget        *widget,
125                                           cairo_t          *cr);
126 static void gtk_menu_item_parent_set     (GtkWidget        *widget,
127                                           GtkWidget        *previous_parent);
128
129
130 static void gtk_real_menu_item_select               (GtkMenuItem *item);
131 static void gtk_real_menu_item_deselect             (GtkMenuItem *item);
132 static void gtk_real_menu_item_activate             (GtkMenuItem *item);
133 static void gtk_real_menu_item_activate_item        (GtkMenuItem *item);
134 static void gtk_real_menu_item_toggle_size_request  (GtkMenuItem *menu_item,
135                                                      gint        *requisition);
136 static void gtk_real_menu_item_toggle_size_allocate (GtkMenuItem *menu_item,
137                                                      gint         allocation);
138 static gboolean gtk_menu_item_mnemonic_activate     (GtkWidget   *widget,
139                                                      gboolean     group_cycling);
140
141 static void gtk_menu_item_ensure_label   (GtkMenuItem      *menu_item);
142 static gint gtk_menu_item_popup_timeout  (gpointer          data);
143 static void gtk_menu_item_position_menu  (GtkMenu          *menu,
144                                           gint             *x,
145                                           gint             *y,
146                                           gboolean         *push_in,
147                                           gpointer          user_data);
148 static void gtk_menu_item_show_all       (GtkWidget        *widget);
149 static void gtk_menu_item_forall         (GtkContainer    *container,
150                                           gboolean         include_internals,
151                                           GtkCallback      callback,
152                                           gpointer         callback_data);
153 static gboolean gtk_menu_item_can_activate_accel (GtkWidget *widget,
154                                                   guint      signal_id);
155
156 static void gtk_real_menu_item_set_label (GtkMenuItem     *menu_item,
157                                           const gchar     *label);
158 static const gchar * gtk_real_menu_item_get_label (GtkMenuItem *menu_item);
159
160 static void gtk_menu_item_get_preferred_width            (GtkWidget           *widget,
161                                                           gint                *minimum_size,
162                                                           gint                *natural_size);
163 static void gtk_menu_item_get_preferred_height           (GtkWidget           *widget,
164                                                           gint                *minimum_size,
165                                                           gint                *natural_size);
166 static void gtk_menu_item_get_preferred_height_for_width (GtkWidget           *widget,
167                                                           gint                 for_size,
168                                                           gint                *minimum_size,
169                                                           gint                *natural_size);
170
171 static void gtk_menu_item_buildable_interface_init (GtkBuildableIface   *iface);
172 static void gtk_menu_item_buildable_add_child      (GtkBuildable        *buildable,
173                                                     GtkBuilder          *builder,
174                                                     GObject             *child,
175                                                     const gchar         *type);
176 static void gtk_menu_item_buildable_custom_finished(GtkBuildable        *buildable,
177                                                     GtkBuilder          *builder,
178                                                     GObject             *child,
179                                                     const gchar         *tagname,
180                                                     gpointer             user_data);
181
182 static void gtk_menu_item_activatable_interface_init (GtkActivatableIface  *iface);
183 static void gtk_menu_item_update                     (GtkActivatable       *activatable,
184                                                       GtkAction            *action,
185                                                       const gchar          *property_name);
186 static void gtk_menu_item_sync_action_properties     (GtkActivatable       *activatable,
187                                                       GtkAction            *action);
188 static void gtk_menu_item_set_related_action         (GtkMenuItem          *menu_item, 
189                                                       GtkAction            *action);
190 static void gtk_menu_item_set_use_action_appearance  (GtkMenuItem          *menu_item, 
191                                                       gboolean              use_appearance);
192
193 static guint menu_item_signals[LAST_SIGNAL] = { 0 };
194
195 static GtkBuildableIface *parent_buildable_iface;
196
197 G_DEFINE_TYPE_WITH_CODE (GtkMenuItem, gtk_menu_item, GTK_TYPE_BIN,
198                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
199                                                 gtk_menu_item_buildable_interface_init)
200                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
201                                                 gtk_menu_item_activatable_interface_init))
202
203 static void
204 gtk_menu_item_class_init (GtkMenuItemClass *klass)
205 {
206   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
207   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
208   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
209
210   gobject_class->dispose = gtk_menu_item_dispose;
211   gobject_class->set_property = gtk_menu_item_set_property;
212   gobject_class->get_property = gtk_menu_item_get_property;
213
214   widget_class->destroy = gtk_menu_item_destroy;
215   widget_class->size_allocate = gtk_menu_item_size_allocate;
216   widget_class->draw = gtk_menu_item_draw;
217   widget_class->realize = gtk_menu_item_realize;
218   widget_class->unrealize = gtk_menu_item_unrealize;
219   widget_class->map = gtk_menu_item_map;
220   widget_class->unmap = gtk_menu_item_unmap;
221   widget_class->enter_notify_event = gtk_menu_item_enter;
222   widget_class->leave_notify_event = gtk_menu_item_leave;
223   widget_class->show_all = gtk_menu_item_show_all;
224   widget_class->mnemonic_activate = gtk_menu_item_mnemonic_activate;
225   widget_class->parent_set = gtk_menu_item_parent_set;
226   widget_class->can_activate_accel = gtk_menu_item_can_activate_accel;
227   widget_class->get_preferred_width = gtk_menu_item_get_preferred_width;
228   widget_class->get_preferred_height = gtk_menu_item_get_preferred_height;
229   widget_class->get_preferred_height_for_width = gtk_menu_item_get_preferred_height_for_width;
230
231   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_MENU_ITEM_ACCESSIBLE);
232
233   container_class->forall = gtk_menu_item_forall;
234
235   klass->activate = gtk_real_menu_item_activate;
236   klass->activate_item = gtk_real_menu_item_activate_item;
237   klass->toggle_size_request = gtk_real_menu_item_toggle_size_request;
238   klass->toggle_size_allocate = gtk_real_menu_item_toggle_size_allocate;
239   klass->set_label = gtk_real_menu_item_set_label;
240   klass->get_label = gtk_real_menu_item_get_label;
241   klass->select = gtk_real_menu_item_select;
242   klass->deselect = gtk_real_menu_item_deselect;
243
244   klass->hide_on_activate = TRUE;
245
246   /**
247    * GtkMenuItem::activate:
248    * @menuitem: the object which received the signal.
249    *
250    * Emitted when the item is activated.
251    */
252   menu_item_signals[ACTIVATE] =
253     g_signal_new (I_("activate"),
254                   G_OBJECT_CLASS_TYPE (gobject_class),
255                   G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
256                   G_STRUCT_OFFSET (GtkMenuItemClass, activate),
257                   NULL, NULL,
258                   _gtk_marshal_VOID__VOID,
259                   G_TYPE_NONE, 0);
260   widget_class->activate_signal = menu_item_signals[ACTIVATE];
261
262   /**
263    * GtkMenuItem::activate-item:
264    * @menuitem: the object which received the signal.
265    *
266    * Emitted when the item is activated, but also if the menu item has a
267    * submenu. For normal applications, the relevant signal is
268    * #GtkMenuItem::activate.
269    */
270   menu_item_signals[ACTIVATE_ITEM] =
271     g_signal_new (I_("activate-item"),
272                   G_OBJECT_CLASS_TYPE (gobject_class),
273                   G_SIGNAL_RUN_FIRST,
274                   G_STRUCT_OFFSET (GtkMenuItemClass, activate_item),
275                   NULL, NULL,
276                   _gtk_marshal_VOID__VOID,
277                   G_TYPE_NONE, 0);
278
279   menu_item_signals[TOGGLE_SIZE_REQUEST] =
280     g_signal_new (I_("toggle-size-request"),
281                   G_OBJECT_CLASS_TYPE (gobject_class),
282                   G_SIGNAL_RUN_FIRST,
283                   G_STRUCT_OFFSET (GtkMenuItemClass, toggle_size_request),
284                   NULL, NULL,
285                   _gtk_marshal_VOID__POINTER,
286                   G_TYPE_NONE, 1,
287                   G_TYPE_POINTER);
288
289   menu_item_signals[TOGGLE_SIZE_ALLOCATE] =
290     g_signal_new (I_("toggle-size-allocate"),
291                   G_OBJECT_CLASS_TYPE (gobject_class),
292                   G_SIGNAL_RUN_FIRST,
293                   G_STRUCT_OFFSET (GtkMenuItemClass, toggle_size_allocate),
294                   NULL, NULL,
295                   _gtk_marshal_VOID__INT,
296                   G_TYPE_NONE, 1,
297                   G_TYPE_INT);
298
299   menu_item_signals[SELECT] =
300     g_signal_new (I_("select"),
301                   G_OBJECT_CLASS_TYPE (gobject_class),
302                   G_SIGNAL_RUN_FIRST,
303                   G_STRUCT_OFFSET (GtkMenuItemClass, select),
304                   NULL, NULL,
305                   _gtk_marshal_VOID__VOID,
306                   G_TYPE_NONE, 0);
307
308   menu_item_signals[DESELECT] =
309     g_signal_new (I_("deselect"),
310                   G_OBJECT_CLASS_TYPE (gobject_class),
311                   G_SIGNAL_RUN_FIRST,
312                   G_STRUCT_OFFSET (GtkMenuItemClass, deselect),
313                   NULL, NULL,
314                   _gtk_marshal_VOID__VOID,
315                   G_TYPE_NONE, 0);
316
317   /**
318    * GtkMenuItem:right-justified:
319    *
320    * Sets whether the menu item appears justified
321    * at the right side of a menu bar.
322    *
323    * Since: 2.14
324    */
325   g_object_class_install_property (gobject_class,
326                                    PROP_RIGHT_JUSTIFIED,
327                                    g_param_spec_boolean ("right-justified",
328                                                          P_("Right Justified"),
329                                                          P_("Sets whether the menu item appears justified at the right side of a menu bar"),
330                                                          FALSE,
331                                                          GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
332
333   /**
334    * GtkMenuItem:submenu:
335    *
336    * The submenu attached to the menu item, or %NULL if it has none.
337    *
338    * Since: 2.12
339    */
340   g_object_class_install_property (gobject_class,
341                                    PROP_SUBMENU,
342                                    g_param_spec_object ("submenu",
343                                                         P_("Submenu"),
344                                                         P_("The submenu attached to the menu item, or NULL if it has none"),
345                                                         GTK_TYPE_MENU,
346                                                         GTK_PARAM_READWRITE));
347
348   /**
349    * GtkMenuItem:accel-path:
350    *
351    * Sets the accelerator path of the menu item, through which runtime
352    * changes of the menu item's accelerator caused by the user can be
353    * identified and saved to persistant storage.
354    *
355    * Since: 2.14
356    */
357   g_object_class_install_property (gobject_class,
358                                    PROP_ACCEL_PATH,
359                                    g_param_spec_string ("accel-path",
360                                                         P_("Accel Path"),
361                                                         P_("Sets the accelerator path of the menu item"),
362                                                         NULL,
363                                                         GTK_PARAM_READWRITE));
364
365   /**
366    * GtkMenuItem:label:
367    *
368    * The text for the child label.
369    *
370    * Since: 2.16
371    */
372   g_object_class_install_property (gobject_class,
373                                    PROP_LABEL,
374                                    g_param_spec_string ("label",
375                                                         P_("Label"),
376                                                         P_("The text for the child label"),
377                                                         "",
378                                                         GTK_PARAM_READWRITE));
379
380   /**
381    * GtkMenuItem:use-underline:
382    *
383    * %TRUE if underlines in the text indicate mnemonics.
384    *
385    * Since: 2.16
386    */
387   g_object_class_install_property (gobject_class,
388                                    PROP_USE_UNDERLINE,
389                                    g_param_spec_boolean ("use-underline",
390                                                          P_("Use underline"),
391                                                          P_("If set, an underline in the text indicates "
392                                                             "the next character should be used for the "
393                                                             "mnemonic accelerator key"),
394                                                          FALSE,
395                                                          GTK_PARAM_READWRITE));
396
397   g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
398   g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
399
400   gtk_widget_class_install_style_property_parser (widget_class,
401                                                   g_param_spec_enum ("selected-shadow-type",
402                                                                      "Selected Shadow Type",
403                                                                      "Shadow type when item is selected",
404                                                                      GTK_TYPE_SHADOW_TYPE,
405                                                                      GTK_SHADOW_NONE,
406                                                                      GTK_PARAM_READABLE),
407                                                   gtk_rc_property_parse_enum);
408
409   gtk_widget_class_install_style_property (widget_class,
410                                            g_param_spec_int ("horizontal-padding",
411                                                              "Horizontal Padding",
412                                                              "Padding to left and right of the menu item",
413                                                              0,
414                                                              G_MAXINT,
415                                                              3,
416                                                              GTK_PARAM_READABLE));
417
418   gtk_widget_class_install_style_property (widget_class,
419                                            g_param_spec_int ("toggle-spacing",
420                                                              "Icon Spacing",
421                                                              "Space between icon and label",
422                                                              0,
423                                                              G_MAXINT,
424                                                              5,
425                                                              GTK_PARAM_READABLE));
426
427   gtk_widget_class_install_style_property (widget_class,
428                                            g_param_spec_int ("arrow-spacing",
429                                                              "Arrow Spacing",
430                                                              "Space between label and arrow",
431                                                              0,
432                                                              G_MAXINT,
433                                                              10,
434                                                              GTK_PARAM_READABLE));
435
436   gtk_widget_class_install_style_property (widget_class,
437                                            g_param_spec_float ("arrow-scaling",
438                                                                P_("Arrow Scaling"),
439                                                                P_("Amount of space used up by arrow, relative to the menu item's font size"),
440                                                                0.0, 2.0, 0.8,
441                                                                GTK_PARAM_READABLE));
442
443   /**
444    * GtkMenuItem:width-chars:
445    *
446    * The minimum desired width of the menu item in characters.
447    *
448    * Since: 2.14
449    */
450   gtk_widget_class_install_style_property (widget_class,
451                                            g_param_spec_int ("width-chars",
452                                                              P_("Width in Characters"),
453                                                              P_("The minimum desired width of the menu item in characters"),
454                                                              0, G_MAXINT, 12,
455                                                              GTK_PARAM_READABLE));
456
457   g_type_class_add_private (klass, sizeof (GtkMenuItemPrivate));
458 }
459
460 static void
461 gtk_menu_item_init (GtkMenuItem *menu_item)
462 {
463   GtkStyleContext *context;
464   GtkMenuItemPrivate *priv;
465
466   priv = G_TYPE_INSTANCE_GET_PRIVATE (menu_item,
467                                       GTK_TYPE_MENU_ITEM,
468                                       GtkMenuItemPrivate);
469   menu_item->priv = priv;
470
471   gtk_widget_set_has_window (GTK_WIDGET (menu_item), FALSE);
472
473   priv->action = NULL;
474   priv->use_action_appearance = TRUE;
475   
476   menu_item->priv->submenu = NULL;
477   menu_item->priv->toggle_size = 0;
478   menu_item->priv->accelerator_width = 0;
479   if (gtk_widget_get_direction (GTK_WIDGET (menu_item)) == GTK_TEXT_DIR_RTL)
480     priv->submenu_direction = GTK_DIRECTION_LEFT;
481   else
482     priv->submenu_direction = GTK_DIRECTION_RIGHT;
483   priv->submenu_placement = GTK_TOP_BOTTOM;
484   priv->right_justify = FALSE;
485   priv->use_action_appearance = TRUE;
486   priv->timer = 0;
487   priv->action = NULL;
488
489   context = gtk_widget_get_style_context (GTK_WIDGET (menu_item));
490   gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUITEM);
491 }
492
493 /**
494  * gtk_menu_item_new:
495  *
496  * Creates a new #GtkMenuItem.
497  *
498  * Returns: the newly created #GtkMenuItem
499  */
500 GtkWidget*
501 gtk_menu_item_new (void)
502 {
503   return g_object_new (GTK_TYPE_MENU_ITEM, NULL);
504 }
505
506 /**
507  * gtk_menu_item_new_with_label:
508  * @label: the text for the label
509  *
510  * Creates a new #GtkMenuItem whose child is a #GtkLabel.
511  *
512  * Returns: the newly created #GtkMenuItem
513  */
514 GtkWidget*
515 gtk_menu_item_new_with_label (const gchar *label)
516 {
517   return g_object_new (GTK_TYPE_MENU_ITEM,
518                        "label", label,
519                        NULL);
520 }
521
522
523 /**
524  * gtk_menu_item_new_with_mnemonic:
525  * @label: The text of the button, with an underscore in front of the
526  *     mnemonic character
527  *
528  * Creates a new #GtkMenuItem containing a label.
529  *
530  * The label will be created using gtk_label_new_with_mnemonic(),
531  * so underscores in @label indicate the mnemonic for the menu item.
532  *
533  * Returns: a new #GtkMenuItem
534  */
535 GtkWidget*
536 gtk_menu_item_new_with_mnemonic (const gchar *label)
537 {
538   return g_object_new (GTK_TYPE_MENU_ITEM,
539                        "use-underline", TRUE,
540                        "label", label,
541                        NULL);
542 }
543
544 static void
545 gtk_menu_item_dispose (GObject *object)
546 {
547   GtkMenuItem *menu_item = GTK_MENU_ITEM (object);
548   GtkMenuItemPrivate *priv = menu_item->priv;
549
550   if (priv->action)
551     {
552       gtk_action_disconnect_accelerator (priv->action);
553       gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (menu_item), NULL);
554       priv->action = NULL;
555     }
556   G_OBJECT_CLASS (gtk_menu_item_parent_class)->dispose (object);
557 }
558
559 static void
560 gtk_menu_item_do_set_right_justified (GtkMenuItem *menu_item,
561                                       gboolean     right_justified)
562 {
563   GtkMenuItemPrivate *priv = menu_item->priv;
564
565   right_justified = right_justified != FALSE;
566
567   if (priv->right_justify != right_justified)
568     {
569       priv->right_justify = right_justified;
570       gtk_widget_queue_resize (GTK_WIDGET (menu_item));
571     }
572 }
573
574 static void
575 gtk_menu_item_set_property (GObject      *object,
576                             guint         prop_id,
577                             const GValue *value,
578                             GParamSpec   *pspec)
579 {
580   GtkMenuItem *menu_item = GTK_MENU_ITEM (object);
581
582   switch (prop_id)
583     {
584     case PROP_RIGHT_JUSTIFIED:
585       gtk_menu_item_do_set_right_justified (menu_item, g_value_get_boolean (value));
586       break;
587     case PROP_SUBMENU:
588       gtk_menu_item_set_submenu (menu_item, g_value_get_object (value));
589       break;
590     case PROP_ACCEL_PATH:
591       gtk_menu_item_set_accel_path (menu_item, g_value_get_string (value));
592       break;
593     case PROP_LABEL:
594       gtk_menu_item_set_label (menu_item, g_value_get_string (value));
595       break;
596     case PROP_USE_UNDERLINE:
597       gtk_menu_item_set_use_underline (menu_item, g_value_get_boolean (value));
598       break;
599     case PROP_ACTIVATABLE_RELATED_ACTION:
600       gtk_menu_item_set_related_action (menu_item, g_value_get_object (value));
601       break;
602     case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
603       gtk_menu_item_set_use_action_appearance (menu_item, g_value_get_boolean (value));
604       break;
605     default:
606       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
607       break;
608     }
609 }
610
611 static void
612 gtk_menu_item_get_property (GObject    *object,
613                             guint       prop_id,
614                             GValue     *value,
615                             GParamSpec *pspec)
616 {
617   GtkMenuItem *menu_item = GTK_MENU_ITEM (object);
618   GtkMenuItemPrivate *priv = menu_item->priv;
619
620   switch (prop_id)
621     {
622     case PROP_RIGHT_JUSTIFIED:
623       g_value_set_boolean (value, menu_item->priv->right_justify);
624       break;
625     case PROP_SUBMENU:
626       g_value_set_object (value, gtk_menu_item_get_submenu (menu_item));
627       break;
628     case PROP_ACCEL_PATH:
629       g_value_set_string (value, gtk_menu_item_get_accel_path (menu_item));
630       break;
631     case PROP_LABEL:
632       g_value_set_string (value, gtk_menu_item_get_label (menu_item));
633       break;
634     case PROP_USE_UNDERLINE:
635       g_value_set_boolean (value, gtk_menu_item_get_use_underline (menu_item));
636       break;
637     case PROP_ACTIVATABLE_RELATED_ACTION:
638       g_value_set_object (value, priv->action);
639       break;
640     case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
641       g_value_set_boolean (value, priv->use_action_appearance);
642       break;
643     default:
644       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
645       break;
646     }
647 }
648
649 static void
650 gtk_menu_item_destroy (GtkWidget *widget)
651 {
652   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
653   GtkMenuItemPrivate *priv = menu_item->priv;
654
655   if (priv->submenu)
656     gtk_widget_destroy (priv->submenu);
657
658   GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->destroy (widget);
659 }
660
661 static void
662 gtk_menu_item_detacher (GtkWidget *widget,
663                         GtkMenu   *menu)
664 {
665   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
666   GtkMenuItemPrivate *priv = menu_item->priv;
667
668   g_return_if_fail (priv->submenu == (GtkWidget*) menu);
669
670   priv->submenu = NULL;
671 }
672
673 static void
674 get_arrow_size (GtkWidget *widget,
675                 GtkWidget *child,
676                 gint      *size,
677                 gint      *spacing)
678 {
679   GtkStyleContext  *style_context;
680   GtkStateFlags     state;
681   PangoContext     *context;
682   PangoFontMetrics *metrics;
683   gfloat            arrow_scaling;
684   gint              arrow_spacing;
685
686   g_assert (size);
687
688   gtk_widget_style_get (widget,
689                         "arrow-scaling", &arrow_scaling,
690                         "arrow-spacing", &arrow_spacing,
691                         NULL);
692
693   if (spacing != NULL)
694     *spacing = arrow_spacing;
695
696   context = gtk_widget_get_pango_context (child);
697   style_context = gtk_widget_get_style_context (child);
698   state = gtk_widget_get_state_flags (child);
699
700   metrics = pango_context_get_metrics (context,
701                                        gtk_style_context_get_font (style_context, state),
702                                        pango_context_get_language (context));
703
704   *size = (PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
705                          pango_font_metrics_get_descent (metrics)));
706
707   pango_font_metrics_unref (metrics);
708
709   *size = *size * arrow_scaling;
710 }
711
712
713 static void
714 gtk_menu_item_accel_width_foreach (GtkWidget *widget,
715                                    gpointer   data)
716 {
717   guint *width = data;
718
719   if (GTK_IS_ACCEL_LABEL (widget))
720     {
721       guint w;
722
723       w = gtk_accel_label_get_accel_width (GTK_ACCEL_LABEL (widget));
724       *width = MAX (*width, w);
725     }
726   else if (GTK_IS_CONTAINER (widget))
727     gtk_container_foreach (GTK_CONTAINER (widget),
728                            gtk_menu_item_accel_width_foreach,
729                            data);
730 }
731
732 static gint
733 get_minimum_width (GtkWidget *widget)
734 {
735   GtkStyleContext *style_context;
736   GtkStateFlags state;
737   PangoContext *context;
738   PangoFontMetrics *metrics;
739   gint width;
740   gint width_chars;
741
742   context = gtk_widget_get_pango_context (widget);
743   style_context = gtk_widget_get_style_context (widget);
744   state = gtk_widget_get_state_flags (widget);
745
746   metrics = pango_context_get_metrics (context,
747                                        gtk_style_context_get_font (style_context, state),
748                                        pango_context_get_language (context));
749
750   width = pango_font_metrics_get_approximate_char_width (metrics);
751
752   pango_font_metrics_unref (metrics);
753
754   gtk_widget_style_get (widget, "width-chars", &width_chars, NULL);
755
756   return PANGO_PIXELS (width_chars * width);
757 }
758
759 static void
760 gtk_menu_item_get_preferred_width (GtkWidget *widget,
761                                    gint      *minimum_size,
762                                    gint      *natural_size)
763 {
764   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
765   GtkMenuItemPrivate *priv = menu_item->priv;
766   GtkBin *bin;
767   GtkWidget *child;
768   GtkWidget *parent;
769   guint accel_width;
770   guint horizontal_padding;
771   guint border_width;
772   GtkPackDirection pack_dir;
773   GtkPackDirection child_pack_dir;
774   gint  min_width, nat_width;
775   GtkStyleContext *context;
776   GtkStateFlags state;
777   GtkBorder padding;
778
779   min_width = nat_width = 0;
780
781   gtk_widget_style_get (widget,
782                         "horizontal-padding", &horizontal_padding,
783                         NULL);
784
785   bin = GTK_BIN (widget);
786   parent = gtk_widget_get_parent (widget);
787
788   if (GTK_IS_MENU_BAR (parent))
789     {
790       pack_dir = gtk_menu_bar_get_pack_direction (GTK_MENU_BAR (parent));
791       child_pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
792     }
793   else
794     {
795       pack_dir = GTK_PACK_DIRECTION_LTR;
796       child_pack_dir = GTK_PACK_DIRECTION_LTR;
797     }
798
799   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
800
801   context = gtk_widget_get_style_context (widget);
802   state = gtk_widget_get_state_flags (widget);
803   gtk_style_context_get_padding (context, state, &padding);
804
805   min_width = (border_width * 2) + padding.left + padding.right;
806
807   if ((pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL) &&
808       (child_pack_dir == GTK_PACK_DIRECTION_LTR || child_pack_dir == GTK_PACK_DIRECTION_RTL))
809     min_width += 2 * horizontal_padding;
810
811   nat_width = min_width;
812           
813   child = gtk_bin_get_child (bin);
814
815   if (child != NULL && gtk_widget_get_visible (child))
816     {
817       GtkMenuItemPrivate *priv = menu_item->priv;
818       gint child_min, child_nat;
819
820       gtk_widget_get_preferred_width (child, &child_min, &child_nat);
821
822       if ((menu_item->priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
823         {
824           gint arrow_spacing, arrow_size;
825
826           get_arrow_size (widget, child, &arrow_size, &arrow_spacing);
827
828           min_width += arrow_size;
829           min_width += arrow_spacing;
830
831           min_width = MAX (min_width, get_minimum_width (widget));
832           nat_width = min_width;
833         }
834
835       min_width += child_min;
836       nat_width += child_nat;
837     }
838
839   accel_width = 0;
840   gtk_container_foreach (GTK_CONTAINER (menu_item),
841                          gtk_menu_item_accel_width_foreach,
842                          &accel_width);
843   priv->accelerator_width = accel_width;
844
845   if (minimum_size)
846     *minimum_size = min_width;
847
848   if (natural_size)
849     *natural_size = nat_width;
850 }
851
852 static void
853 gtk_menu_item_real_get_height (GtkWidget *widget,
854                                gint       for_size,
855                                gint      *minimum_size,
856                                gint      *natural_size)
857 {
858   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
859   GtkMenuItemPrivate *priv = menu_item->priv;
860   GtkBin *bin;
861   GtkStyleContext *context;
862   GtkStateFlags state;
863   GtkBorder padding;
864   GtkWidget *child;
865   GtkWidget *parent;
866   guint accel_width;
867   guint horizontal_padding;
868   guint border_width;
869   GtkPackDirection pack_dir;
870   GtkPackDirection child_pack_dir;
871   gint min_height, nat_height;
872   gint avail_size = 0;
873
874   min_height = nat_height = 0;
875
876   context = gtk_widget_get_style_context (widget);
877   state = gtk_widget_get_state_flags (widget);
878   gtk_style_context_get_padding (context, state, &padding);
879
880   gtk_widget_style_get (widget,
881                         "horizontal-padding", &horizontal_padding,
882                         NULL);
883
884   bin = GTK_BIN (widget);
885   parent = gtk_widget_get_parent (widget);
886
887   if (GTK_IS_MENU_BAR (parent))
888     {
889       pack_dir = gtk_menu_bar_get_pack_direction (GTK_MENU_BAR (parent));
890       child_pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
891     }
892   else
893     {
894       pack_dir = GTK_PACK_DIRECTION_LTR;
895       child_pack_dir = GTK_PACK_DIRECTION_LTR;
896     }
897
898   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
899   min_height   = (border_width * 2) + padding.top + padding.bottom;
900
901   if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
902       (child_pack_dir == GTK_PACK_DIRECTION_TTB || child_pack_dir == GTK_PACK_DIRECTION_BTT))
903     min_height += 2 * horizontal_padding;
904
905   if (for_size != -1)
906     {
907       avail_size = for_size;
908       avail_size -= (border_width * 2) + padding.left + padding.right;
909
910       if ((pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL) &&
911           (child_pack_dir == GTK_PACK_DIRECTION_LTR || child_pack_dir == GTK_PACK_DIRECTION_RTL))
912         avail_size -= 2 * horizontal_padding;
913     }
914
915   nat_height = min_height;
916
917   child = gtk_bin_get_child (bin);
918
919   if (child != NULL && gtk_widget_get_visible (child))
920     {
921       gint child_min, child_nat;
922       gint arrow_size = 0, arrow_spacing = 0;
923
924       if ((priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
925         get_arrow_size (widget, child, &arrow_size, &arrow_spacing);
926
927       if (for_size != -1)
928         {
929           avail_size -= (arrow_size + arrow_spacing);
930           gtk_widget_get_preferred_height_for_width (child,
931                                                      avail_size,
932                                                      &child_min,
933                                                      &child_nat);
934         }
935       else
936         {
937           gtk_widget_get_preferred_height (child, &child_min, &child_nat);
938         }
939
940       min_height += child_min;
941       nat_height += child_nat;
942
943       min_height = MAX (min_height, arrow_size);
944       nat_height = MAX (nat_height, arrow_size);
945     }
946   else /* separator item */
947     {
948       gboolean wide_separators;
949       gint     separator_height;
950
951       gtk_widget_style_get (widget,
952                             "wide-separators",  &wide_separators,
953                             "separator-height", &separator_height,
954                             NULL);
955
956       if (wide_separators)
957         {
958           min_height += separator_height;
959           nat_height += separator_height;
960         }
961       else
962         {
963           /* force odd, so that we can have the same space above and
964            * below the line.
965            */
966           if (min_height % 2 == 0)
967             min_height += 1;
968           if (nat_height % 2 == 0)
969             nat_height += 1;
970         }
971     }
972
973   accel_width = 0;
974   gtk_container_foreach (GTK_CONTAINER (menu_item),
975                          gtk_menu_item_accel_width_foreach,
976                          &accel_width);
977   priv->accelerator_width = accel_width;
978
979   if (minimum_size)
980     *minimum_size = min_height;
981
982   if (natural_size)
983     *natural_size = nat_height;
984 }
985
986 static void
987 gtk_menu_item_get_preferred_height (GtkWidget *widget,
988                                     gint      *minimum_size,
989                                     gint      *natural_size)
990 {
991   gtk_menu_item_real_get_height (widget, -1, minimum_size, natural_size);
992 }
993
994 static void
995 gtk_menu_item_get_preferred_height_for_width (GtkWidget *widget,
996                                               gint       for_size,
997                                               gint      *minimum_size,
998                                               gint      *natural_size)
999 {
1000   gtk_menu_item_real_get_height (widget, for_size, minimum_size, natural_size);
1001 }
1002
1003 static void
1004 gtk_menu_item_buildable_interface_init (GtkBuildableIface *iface)
1005 {
1006   parent_buildable_iface = g_type_interface_peek_parent (iface);
1007   iface->add_child = gtk_menu_item_buildable_add_child;
1008   iface->custom_finished = gtk_menu_item_buildable_custom_finished;
1009 }
1010
1011 static void
1012 gtk_menu_item_buildable_add_child (GtkBuildable *buildable,
1013                                    GtkBuilder   *builder,
1014                                    GObject      *child,
1015                                    const gchar  *type)
1016 {
1017   if (type && strcmp (type, "submenu") == 0)
1018         gtk_menu_item_set_submenu (GTK_MENU_ITEM (buildable),
1019                                    GTK_WIDGET (child));
1020   else
1021     parent_buildable_iface->add_child (buildable, builder, child, type);
1022 }
1023
1024
1025 static void
1026 gtk_menu_item_buildable_custom_finished (GtkBuildable *buildable,
1027                                          GtkBuilder   *builder,
1028                                          GObject      *child,
1029                                          const gchar  *tagname,
1030                                          gpointer      user_data)
1031 {
1032   GtkWidget *toplevel;
1033
1034   if (strcmp (tagname, "accelerator") == 0)
1035     {
1036       GtkMenuShell *menu_shell;
1037       GtkWidget *attach;
1038
1039       menu_shell = GTK_MENU_SHELL (gtk_widget_get_parent (GTK_WIDGET (buildable)));
1040       if (menu_shell)
1041         {
1042           while (GTK_IS_MENU (menu_shell) &&
1043                  (attach = gtk_menu_get_attach_widget (GTK_MENU (menu_shell))) != NULL)
1044             menu_shell = GTK_MENU_SHELL (gtk_widget_get_parent (attach));
1045
1046           toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu_shell));
1047         }
1048       else
1049         {
1050           /* Fall back to something ... */
1051           toplevel = gtk_widget_get_toplevel (GTK_WIDGET (buildable));
1052
1053           g_warning ("found a GtkMenuItem '%s' without a parent GtkMenuShell, assigned accelerators wont work.",
1054                      gtk_buildable_get_name (buildable));
1055         }
1056
1057       /* Feed the correct toplevel to the GtkWidget accelerator parsing code */
1058       _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
1059     }
1060   else
1061     parent_buildable_iface->custom_finished (buildable, builder, child, tagname, user_data);
1062 }
1063
1064
1065 static void
1066 gtk_menu_item_activatable_interface_init (GtkActivatableIface *iface)
1067 {
1068   iface->update = gtk_menu_item_update;
1069   iface->sync_action_properties = gtk_menu_item_sync_action_properties;
1070 }
1071
1072 static void
1073 activatable_update_label (GtkMenuItem *menu_item, GtkAction *action)
1074 {
1075   GtkWidget *child;
1076
1077   child = gtk_bin_get_child (GTK_BIN (menu_item));
1078
1079   if (GTK_IS_LABEL (child))
1080     {
1081       const gchar *label;
1082
1083       label = gtk_action_get_label (action);
1084       gtk_menu_item_set_label (menu_item, label);
1085     }
1086 }
1087
1088 gboolean _gtk_menu_is_empty (GtkWidget *menu);
1089
1090 static void
1091 gtk_menu_item_update (GtkActivatable *activatable,
1092                       GtkAction      *action,
1093                       const gchar    *property_name)
1094 {
1095   GtkMenuItem *menu_item = GTK_MENU_ITEM (activatable);
1096   GtkMenuItemPrivate *priv = menu_item->priv;
1097
1098   if (strcmp (property_name, "visible") == 0)
1099     _gtk_action_sync_menu_visible (action, GTK_WIDGET (menu_item),
1100                                    _gtk_menu_is_empty (gtk_menu_item_get_submenu (menu_item)));
1101   else if (strcmp (property_name, "sensitive") == 0)
1102     gtk_widget_set_sensitive (GTK_WIDGET (menu_item), gtk_action_is_sensitive (action));
1103   else if (priv->use_action_appearance)
1104     {
1105       if (strcmp (property_name, "label") == 0)
1106         activatable_update_label (menu_item, action);
1107     }
1108 }
1109
1110 static void
1111 gtk_menu_item_sync_action_properties (GtkActivatable *activatable,
1112                                       GtkAction      *action)
1113 {
1114   GtkMenuItem *menu_item = GTK_MENU_ITEM (activatable);
1115   GtkMenuItemPrivate *priv = menu_item->priv;
1116   GtkWidget *label;
1117
1118   if (!priv->use_action_appearance || !action)
1119     {
1120       label = gtk_bin_get_child (GTK_BIN (menu_item));
1121
1122       if (GTK_IS_ACCEL_LABEL (label))
1123         gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), GTK_WIDGET (menu_item));
1124     }
1125
1126   if (!action)
1127     return;
1128
1129   _gtk_action_sync_menu_visible (action, GTK_WIDGET (menu_item),
1130                                  _gtk_menu_is_empty (gtk_menu_item_get_submenu (menu_item)));
1131
1132   gtk_widget_set_sensitive (GTK_WIDGET (menu_item), gtk_action_is_sensitive (action));
1133
1134   if (priv->use_action_appearance)
1135     {
1136       label = gtk_bin_get_child (GTK_BIN (menu_item));
1137
1138       /* make sure label is a label, deleting it otherwise */
1139       if (label && !GTK_IS_LABEL (label))
1140         {
1141           gtk_container_remove (GTK_CONTAINER (menu_item), label);
1142           label = NULL;
1143         }
1144       /* Make sure that menu_item has a label and that any
1145        * accelerators are set */
1146       gtk_menu_item_ensure_label (menu_item);
1147       gtk_menu_item_set_use_underline (menu_item, TRUE);
1148       /* Make label point to the menu_item's label */
1149       label = gtk_bin_get_child (GTK_BIN (menu_item));
1150
1151       if (GTK_IS_ACCEL_LABEL (label) && gtk_action_get_accel_path (action))
1152         {
1153           gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), NULL);
1154           gtk_accel_label_set_accel_closure (GTK_ACCEL_LABEL (label),
1155                                              gtk_action_get_accel_closure (action));
1156         }
1157
1158       activatable_update_label (menu_item, action);
1159     }
1160 }
1161
1162 static void
1163 gtk_menu_item_set_related_action (GtkMenuItem *menu_item,
1164                                   GtkAction   *action)
1165 {
1166     GtkMenuItemPrivate *priv = menu_item->priv;
1167
1168     if (priv->action == action)
1169       return;
1170
1171     if (priv->action)
1172       {
1173         gtk_action_disconnect_accelerator (priv->action);
1174       }
1175
1176     if (action)
1177       {
1178         const gchar *accel_path;
1179
1180         accel_path = gtk_action_get_accel_path (action);
1181         if (accel_path)
1182           {
1183             gtk_action_connect_accelerator (action);
1184             gtk_menu_item_set_accel_path (menu_item, accel_path);
1185           }
1186       }
1187
1188     gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (menu_item), action);
1189
1190     priv->action = action;
1191 }
1192
1193 static void
1194 gtk_menu_item_set_use_action_appearance (GtkMenuItem *menu_item,
1195                                          gboolean     use_appearance)
1196 {
1197     GtkMenuItemPrivate *priv = menu_item->priv;
1198
1199     if (priv->use_action_appearance != use_appearance)
1200       {
1201         priv->use_action_appearance = use_appearance;
1202
1203         gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (menu_item), priv->action);
1204       }
1205 }
1206
1207
1208 /**
1209  * gtk_menu_item_set_submenu:
1210  * @menu_item: a #GtkMenuItem
1211  * @submenu: (allow-none): the submenu, or %NULL
1212  *
1213  * Sets or replaces the menu item's submenu, or removes it when a %NULL
1214  * submenu is passed.
1215  */
1216 void
1217 gtk_menu_item_set_submenu (GtkMenuItem *menu_item,
1218                            GtkWidget   *submenu)
1219 {
1220   GtkMenuItemPrivate *priv = menu_item->priv;
1221
1222   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1223   g_return_if_fail (submenu == NULL || GTK_IS_MENU (submenu));
1224
1225   if (priv->submenu != submenu)
1226     {
1227       if (priv->submenu)
1228         gtk_menu_detach (GTK_MENU (priv->submenu));
1229
1230       if (submenu)
1231         {
1232           priv->submenu = submenu;
1233           gtk_menu_attach_to_widget (GTK_MENU (submenu),
1234                                      GTK_WIDGET (menu_item),
1235                                      gtk_menu_item_detacher);
1236         }
1237
1238       if (gtk_widget_get_parent (GTK_WIDGET (menu_item)))
1239         gtk_widget_queue_resize (GTK_WIDGET (menu_item));
1240
1241       g_object_notify (G_OBJECT (menu_item), "submenu");
1242     }
1243 }
1244
1245 /**
1246  * gtk_menu_item_get_submenu:
1247  * @menu_item: a #GtkMenuItem
1248  *
1249  * Gets the submenu underneath this menu item, if any.
1250  * See gtk_menu_item_set_submenu().
1251  *
1252  * Return value: (transfer none): submenu for this menu item, or %NULL if none
1253  */
1254 GtkWidget *
1255 gtk_menu_item_get_submenu (GtkMenuItem *menu_item)
1256 {
1257   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL);
1258
1259   return menu_item->priv->submenu;
1260 }
1261
1262 void _gtk_menu_item_set_placement (GtkMenuItem         *menu_item,
1263                                    GtkSubmenuPlacement  placement);
1264
1265 void
1266 _gtk_menu_item_set_placement (GtkMenuItem         *menu_item,
1267                              GtkSubmenuPlacement  placement)
1268 {
1269   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1270
1271   menu_item->priv->submenu_placement = placement;
1272 }
1273
1274 void
1275 gtk_menu_item_select (GtkMenuItem *menu_item)
1276 {
1277   GtkWidget *parent;
1278
1279   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1280
1281   g_signal_emit (menu_item, menu_item_signals[SELECT], 0);
1282
1283   /* Enable themeing of the parent menu item depending on whether
1284    * something is selected in its submenu
1285    */
1286   parent = gtk_widget_get_parent (GTK_WIDGET (menu_item));
1287   if (GTK_IS_MENU (parent))
1288     {
1289       GtkMenu *menu = GTK_MENU (parent);
1290
1291       if (menu->priv->parent_menu_item)
1292         gtk_widget_queue_draw (GTK_WIDGET (menu->priv->parent_menu_item));
1293     }
1294 }
1295
1296 /**
1297  * gtk_menu_item_deselect:
1298  * @menu_item: the menu item
1299  *
1300  * Emits the #GtkMenuItem::deselect signal on the given item. Behaves
1301  * exactly like #gtk_item_deselect.
1302  */
1303 void
1304 gtk_menu_item_deselect (GtkMenuItem *menu_item)
1305 {
1306   GtkWidget *parent;
1307
1308   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1309
1310   g_signal_emit (menu_item, menu_item_signals[DESELECT], 0);
1311
1312   /* Enable themeing of the parent menu item depending on whether
1313    * something is selected in its submenu
1314    */
1315   parent = gtk_widget_get_parent (GTK_WIDGET (menu_item));
1316   if (GTK_IS_MENU (parent))
1317     {
1318       GtkMenu *menu = GTK_MENU (parent);
1319
1320       if (menu->priv->parent_menu_item)
1321         gtk_widget_queue_draw (GTK_WIDGET (menu->priv->parent_menu_item));
1322     }
1323 }
1324
1325 /**
1326  * gtk_menu_item_activate:
1327  * @menu_item: the menu item
1328  *
1329  * Emits the #GtkMenuItem::activate signal on the given item
1330  */
1331 void
1332 gtk_menu_item_activate (GtkMenuItem *menu_item)
1333 {
1334   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1335
1336   g_signal_emit (menu_item, menu_item_signals[ACTIVATE], 0);
1337 }
1338
1339 /**
1340  * gtk_menu_item_toggle_size_request:
1341  * @menu_item: the menu item
1342  * @requisition: the requisition to use as signal data.
1343  *
1344  * Emits the #GtkMenuItem::toggle-size-request signal on the given item.
1345  */
1346 void
1347 gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item,
1348                                    gint        *requisition)
1349 {
1350   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1351
1352   g_signal_emit (menu_item, menu_item_signals[TOGGLE_SIZE_REQUEST], 0, requisition);
1353 }
1354
1355 /**
1356  * gtk_menu_item_toggle_size_allocate:
1357  * @menu_item: the menu item.
1358  * @allocation: the allocation to use as signal data.
1359  *
1360  * Emits the #GtkMenuItem::toggle-size-allocate signal on the given item.
1361  */
1362 void
1363 gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item,
1364                                     gint         allocation)
1365 {
1366   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1367
1368   g_signal_emit (menu_item, menu_item_signals[TOGGLE_SIZE_ALLOCATE], 0, allocation);
1369 }
1370
1371 static void
1372 gtk_menu_item_size_allocate (GtkWidget     *widget,
1373                              GtkAllocation *allocation)
1374 {
1375   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1376   GtkMenuItemPrivate *priv = menu_item->priv;
1377   GtkBin *bin;
1378   GtkAllocation child_allocation;
1379   GtkTextDirection direction;
1380   GtkPackDirection pack_dir;
1381   GtkPackDirection child_pack_dir;
1382   GtkWidget *child;
1383   GtkWidget *parent;
1384
1385   g_return_if_fail (GTK_IS_MENU_ITEM (widget));
1386   g_return_if_fail (allocation != NULL);
1387
1388   bin = GTK_BIN (widget);
1389
1390   direction = gtk_widget_get_direction (widget);
1391
1392   parent = gtk_widget_get_parent (widget);
1393   if (GTK_IS_MENU_BAR (parent))
1394     {
1395       pack_dir = gtk_menu_bar_get_pack_direction (GTK_MENU_BAR (parent));
1396       child_pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
1397     }
1398   else
1399     {
1400       pack_dir = GTK_PACK_DIRECTION_LTR;
1401       child_pack_dir = GTK_PACK_DIRECTION_LTR;
1402     }
1403
1404   gtk_widget_set_allocation (widget, allocation);
1405
1406   child = gtk_bin_get_child (bin);
1407   if (child)
1408     {
1409       GtkStyleContext *context;
1410       GtkStateFlags state;
1411       GtkBorder padding;
1412       guint horizontal_padding;
1413       guint border_width;
1414
1415       context = gtk_widget_get_style_context (widget);
1416       state = gtk_widget_get_state_flags (widget);
1417       gtk_style_context_get_padding (context, state, &padding);
1418
1419       gtk_widget_style_get (widget,
1420                             "horizontal-padding", &horizontal_padding,
1421                             NULL);
1422
1423       border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1424       child_allocation.x = border_width + padding.left;
1425       child_allocation.y = border_width + padding.top;
1426
1427       child_allocation.width = allocation->width - (border_width * 2) -
1428         padding.left - padding.right;
1429       child_allocation.height = allocation->height - (border_width * 2) -
1430         padding.top - padding.bottom;
1431
1432       if ((pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL) &&
1433           (child_pack_dir == GTK_PACK_DIRECTION_LTR || child_pack_dir == GTK_PACK_DIRECTION_RTL))
1434         {
1435           child_allocation.x += horizontal_padding;
1436           child_allocation.width -= 2 * horizontal_padding;
1437         }
1438       else if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
1439                (child_pack_dir == GTK_PACK_DIRECTION_TTB || child_pack_dir == GTK_PACK_DIRECTION_BTT))
1440         {
1441           child_allocation.y += horizontal_padding;
1442           child_allocation.height -= 2 * horizontal_padding;
1443         }
1444
1445       if (child_pack_dir == GTK_PACK_DIRECTION_LTR ||
1446           child_pack_dir == GTK_PACK_DIRECTION_RTL)
1447         {
1448           if ((direction == GTK_TEXT_DIR_LTR) == (child_pack_dir != GTK_PACK_DIRECTION_RTL))
1449             child_allocation.x += priv->toggle_size;
1450           child_allocation.width -= priv->toggle_size;
1451         }
1452       else
1453         {
1454           if ((direction == GTK_TEXT_DIR_LTR) == (child_pack_dir != GTK_PACK_DIRECTION_BTT))
1455             child_allocation.y += priv->toggle_size;
1456           child_allocation.height -= priv->toggle_size;
1457         }
1458
1459       child_allocation.x += allocation->x;
1460       child_allocation.y += allocation->y;
1461
1462       if ((priv->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
1463         {
1464           gint arrow_spacing, arrow_size;
1465
1466           get_arrow_size (widget, child, &arrow_size, &arrow_spacing);
1467
1468           if (direction == GTK_TEXT_DIR_RTL)
1469             child_allocation.x += arrow_size + arrow_spacing;
1470           child_allocation.width -= arrow_size + arrow_spacing;
1471         }
1472       
1473       if (child_allocation.width < 1)
1474         child_allocation.width = 1;
1475
1476       gtk_widget_size_allocate (child, &child_allocation);
1477     }
1478
1479   if (gtk_widget_get_realized (widget))
1480     gdk_window_move_resize (priv->event_window,
1481                             allocation->x, allocation->y,
1482                             allocation->width, allocation->height);
1483
1484   if (priv->submenu)
1485     gtk_menu_reposition (GTK_MENU (priv->submenu));
1486 }
1487
1488 static void
1489 gtk_menu_item_realize (GtkWidget *widget)
1490 {
1491   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1492   GtkMenuItemPrivate *priv = menu_item->priv;
1493   GtkAllocation allocation;
1494   GdkWindow *window;
1495   GdkWindowAttr attributes;
1496   gint attributes_mask;
1497
1498   gtk_widget_set_realized (widget, TRUE);
1499
1500   window = gtk_widget_get_parent_window (widget);
1501   gtk_widget_set_window (widget, window);
1502   g_object_ref (window);
1503
1504   gtk_widget_get_allocation (widget, &allocation);
1505
1506   attributes.x = allocation.x;
1507   attributes.y = allocation.y;
1508   attributes.width = allocation.width;
1509   attributes.height = allocation.height;
1510   attributes.window_type = GDK_WINDOW_CHILD;
1511   attributes.wclass = GDK_INPUT_ONLY;
1512   attributes.event_mask = (gtk_widget_get_events (widget) |
1513                            GDK_BUTTON_PRESS_MASK |
1514                            GDK_BUTTON_RELEASE_MASK |
1515                            GDK_ENTER_NOTIFY_MASK |
1516                            GDK_LEAVE_NOTIFY_MASK |
1517                            GDK_POINTER_MOTION_MASK);
1518
1519   attributes_mask = GDK_WA_X | GDK_WA_Y;
1520
1521   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1522                                        &attributes, attributes_mask);
1523   gdk_window_set_user_data (priv->event_window, widget);
1524 }
1525
1526 static void
1527 gtk_menu_item_unrealize (GtkWidget *widget)
1528 {
1529   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1530   GtkMenuItemPrivate *priv = menu_item->priv;
1531
1532   gdk_window_set_user_data (priv->event_window, NULL);
1533   gdk_window_destroy (priv->event_window);
1534   priv->event_window = NULL;
1535
1536   GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->unrealize (widget);
1537 }
1538
1539 static void
1540 gtk_menu_item_map (GtkWidget *widget)
1541 {
1542   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1543   GtkMenuItemPrivate *priv = menu_item->priv;
1544
1545   GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->map (widget);
1546
1547   gdk_window_show (priv->event_window);
1548 }
1549
1550 static void
1551 gtk_menu_item_unmap (GtkWidget *widget)
1552 {
1553   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1554   GtkMenuItemPrivate *priv = menu_item->priv;
1555
1556   gdk_window_hide (priv->event_window);
1557
1558   GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->unmap (widget);
1559 }
1560
1561 static gboolean
1562 gtk_menu_item_enter (GtkWidget        *widget,
1563                      GdkEventCrossing *event)
1564 {
1565   g_return_val_if_fail (event != NULL, FALSE);
1566
1567   return gtk_widget_event (gtk_widget_get_parent (widget), (GdkEvent *) event);
1568 }
1569
1570 static gboolean
1571 gtk_menu_item_leave (GtkWidget        *widget,
1572                      GdkEventCrossing *event)
1573 {
1574   g_return_val_if_fail (event != NULL, FALSE);
1575
1576   return gtk_widget_event (gtk_widget_get_parent (widget), (GdkEvent*) event);
1577 }
1578
1579 static gboolean
1580 gtk_menu_item_draw (GtkWidget *widget,
1581                     cairo_t   *cr)
1582 {
1583   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1584   GtkMenuItemPrivate *priv = menu_item->priv;
1585   GtkStateFlags state;
1586   GtkStyleContext *context;
1587   GtkBorder padding;
1588   GtkWidget *child, *parent;
1589   gint x, y, w, h, width, height;
1590   guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1591
1592   state = gtk_widget_get_state_flags (widget);
1593   context = gtk_widget_get_style_context (widget);
1594   width = gtk_widget_get_allocated_width (widget);
1595   height = gtk_widget_get_allocated_height (widget);
1596
1597   x = border_width;
1598   y = border_width;
1599   w = width - border_width * 2;
1600   h = height - border_width * 2;
1601
1602   child = gtk_bin_get_child (GTK_BIN (menu_item));
1603   parent = gtk_widget_get_parent (widget);
1604
1605   gtk_style_context_get_padding (context, state, &padding);
1606
1607   if (child && (state & GTK_STATE_FLAG_PRELIGHT))
1608     {
1609       gtk_render_background (context, cr, x, y, w, h);
1610       gtk_render_frame (context, cr, x, y, w, h);
1611     }
1612
1613   if (priv->submenu && !GTK_IS_MENU_BAR (parent))
1614     {
1615       gint arrow_x, arrow_y;
1616       gint arrow_size;
1617       guint horizontal_padding;
1618       GtkTextDirection direction;
1619       gdouble angle;
1620
1621       direction = gtk_widget_get_direction (widget);
1622
1623       gtk_widget_style_get (widget,
1624                             "horizontal-padding", &horizontal_padding,
1625                             NULL);
1626
1627       get_arrow_size (widget, child, &arrow_size, NULL);
1628
1629       if (direction == GTK_TEXT_DIR_LTR)
1630         {
1631           arrow_x = x + w - horizontal_padding - arrow_size;
1632           angle = G_PI / 2;
1633         }
1634       else
1635         {
1636           arrow_x = x + horizontal_padding;
1637           angle = (3 * G_PI) / 2;
1638         }
1639
1640       arrow_y = y + (h - arrow_size) / 2;
1641
1642       gtk_render_arrow (context, cr, angle, arrow_x, arrow_y, arrow_size);
1643     }
1644   else if (!child)
1645     {
1646       gboolean wide_separators;
1647       gint     separator_height;
1648       guint    horizontal_padding;
1649
1650       gtk_widget_style_get (widget,
1651                             "wide-separators",    &wide_separators,
1652                             "separator-height",   &separator_height,
1653                             "horizontal-padding", &horizontal_padding,
1654                             NULL);
1655       if (wide_separators)
1656         gtk_render_frame (context, cr,
1657                           x + horizontal_padding + padding.left,
1658                           y + padding.top,
1659                           w - (2 * horizontal_padding) - padding.left - padding.right,
1660                           separator_height);
1661       else
1662         gtk_render_line (context, cr,
1663                          x + horizontal_padding + padding.left,
1664                          y + padding.top,
1665                          x + w - horizontal_padding - padding.right - 1,
1666                          y + padding.top);
1667     }
1668
1669   GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->draw (widget, cr);
1670
1671   return FALSE;
1672 }
1673
1674 /**
1675  * gtk_menu_item_select:
1676  * @menu_item: the menu item
1677  *
1678  * Emits the #GtkMenuItem::select signal on the given item. Behaves
1679  * exactly like #gtk_item_select.
1680  */
1681 static void
1682 gtk_real_menu_item_select (GtkMenuItem *menu_item)
1683 {
1684   GtkMenuItemPrivate *priv = menu_item->priv;
1685   GdkDevice *source_device = NULL;
1686   GdkEvent *current_event;
1687
1688   current_event = gtk_get_current_event ();
1689
1690   if (current_event)
1691     {
1692       source_device = gdk_event_get_source_device (current_event);
1693       gdk_event_free (current_event);
1694     }
1695
1696   if ((!source_device ||
1697        gdk_device_get_source (source_device) != GDK_SOURCE_TOUCHSCREEN) &&
1698       priv->submenu &&
1699       (!gtk_widget_get_mapped (priv->submenu) ||
1700        GTK_MENU (priv->submenu)->priv->tearoff_active))
1701     {
1702       _gtk_menu_item_popup_submenu (GTK_WIDGET (menu_item), TRUE);
1703     }
1704
1705   gtk_widget_set_state_flags (GTK_WIDGET (menu_item),
1706                               GTK_STATE_FLAG_PRELIGHT, FALSE);
1707   gtk_widget_queue_draw (GTK_WIDGET (menu_item));
1708 }
1709
1710 static void
1711 gtk_real_menu_item_deselect (GtkMenuItem *menu_item)
1712 {
1713   GtkMenuItemPrivate *priv = menu_item->priv;
1714
1715   if (priv->submenu)
1716     _gtk_menu_item_popdown_submenu (GTK_WIDGET (menu_item));
1717
1718   gtk_widget_unset_state_flags (GTK_WIDGET (menu_item),
1719                                 GTK_STATE_FLAG_PRELIGHT);
1720   gtk_widget_queue_draw (GTK_WIDGET (menu_item));
1721 }
1722
1723 static gboolean
1724 gtk_menu_item_mnemonic_activate (GtkWidget *widget,
1725                                  gboolean   group_cycling)
1726 {
1727   GtkWidget *parent;
1728
1729   parent = gtk_widget_get_parent (widget);
1730
1731   if (GTK_IS_MENU_SHELL (parent))
1732     _gtk_menu_shell_set_keyboard_mode (GTK_MENU_SHELL (parent), TRUE);
1733
1734   if (group_cycling &&
1735       parent &&
1736       GTK_IS_MENU_SHELL (parent) &&
1737       GTK_MENU_SHELL (parent)->priv->active)
1738     {
1739       gtk_menu_shell_select_item (GTK_MENU_SHELL (parent), widget);
1740     }
1741   else
1742     g_signal_emit (widget, menu_item_signals[ACTIVATE_ITEM], 0);
1743
1744   return TRUE;
1745 }
1746
1747 static void
1748 gtk_real_menu_item_activate (GtkMenuItem *menu_item)
1749 {
1750   GtkMenuItemPrivate *priv = menu_item->priv;
1751
1752   if (priv->action)
1753     gtk_action_activate (priv->action);
1754 }
1755
1756
1757 static void
1758 gtk_real_menu_item_activate_item (GtkMenuItem *menu_item)
1759 {
1760   GtkMenuItemPrivate *priv = menu_item->priv;
1761   GtkWidget *parent;
1762   GtkWidget *widget;
1763
1764   widget = GTK_WIDGET (menu_item);
1765   parent = gtk_widget_get_parent (widget);
1766
1767   if (parent && GTK_IS_MENU_SHELL (parent))
1768     {
1769       GtkMenuShell *menu_shell = GTK_MENU_SHELL (parent);
1770
1771       if (priv->submenu == NULL)
1772         gtk_menu_shell_activate_item (menu_shell, widget, TRUE);
1773       else
1774         {
1775           gtk_menu_shell_select_item (menu_shell, widget);
1776           _gtk_menu_item_popup_submenu (widget, FALSE);
1777
1778           gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->submenu), TRUE);
1779         }
1780     }
1781 }
1782
1783 static void
1784 gtk_real_menu_item_toggle_size_request (GtkMenuItem *menu_item,
1785                                         gint        *requisition)
1786 {
1787   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1788
1789   *requisition = 0;
1790 }
1791
1792 static void
1793 gtk_real_menu_item_toggle_size_allocate (GtkMenuItem *menu_item,
1794                                          gint         allocation)
1795 {
1796   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1797
1798   menu_item->priv->toggle_size = allocation;
1799 }
1800
1801 static void
1802 gtk_real_menu_item_set_label (GtkMenuItem *menu_item,
1803                               const gchar *label)
1804 {
1805   GtkWidget *child;
1806
1807   gtk_menu_item_ensure_label (menu_item);
1808
1809   child = gtk_bin_get_child (GTK_BIN (menu_item));
1810   if (GTK_IS_LABEL (child))
1811     {
1812       gtk_label_set_label (GTK_LABEL (child), label ? label : "");
1813
1814       g_object_notify (G_OBJECT (menu_item), "label");
1815     }
1816 }
1817
1818 static const gchar *
1819 gtk_real_menu_item_get_label (GtkMenuItem *menu_item)
1820 {
1821   GtkWidget *child;
1822
1823   gtk_menu_item_ensure_label (menu_item);
1824
1825   child = gtk_bin_get_child (GTK_BIN (menu_item));
1826   if (GTK_IS_LABEL (child))
1827     return gtk_label_get_label (GTK_LABEL (child));
1828
1829   return NULL;
1830 }
1831
1832 static void
1833 free_timeval (GTimeVal *val)
1834 {
1835   g_slice_free (GTimeVal, val);
1836 }
1837
1838 static void
1839 gtk_menu_item_real_popup_submenu (GtkWidget *widget,
1840                                   gboolean   remember_exact_time)
1841 {
1842   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1843   GtkMenuItemPrivate *priv = menu_item->priv;
1844   GtkWidget *parent;
1845
1846   parent = gtk_widget_get_parent (widget);
1847
1848   if (gtk_widget_is_sensitive (priv->submenu) && parent)
1849     {
1850       gboolean take_focus;
1851       GtkMenuPositionFunc menu_position_func;
1852
1853       take_focus = gtk_menu_shell_get_take_focus (GTK_MENU_SHELL (parent));
1854       gtk_menu_shell_set_take_focus (GTK_MENU_SHELL (priv->submenu), take_focus);
1855
1856       if (remember_exact_time)
1857         {
1858           GTimeVal *popup_time = g_slice_new0 (GTimeVal);
1859
1860           g_get_current_time (popup_time);
1861
1862           g_object_set_data_full (G_OBJECT (priv->submenu),
1863                                   "gtk-menu-exact-popup-time", popup_time,
1864                                   (GDestroyNotify) free_timeval);
1865         }
1866       else
1867         {
1868           g_object_set_data (G_OBJECT (priv->submenu),
1869                              "gtk-menu-exact-popup-time", NULL);
1870         }
1871
1872       /* gtk_menu_item_position_menu positions the submenu from the
1873        * menuitems position. If the menuitem doesn't have a window,
1874        * that doesn't work. In that case we use the default
1875        * positioning function instead which places the submenu at the
1876        * mouse cursor.
1877        */
1878       if (gtk_widget_get_window (widget))
1879         menu_position_func = gtk_menu_item_position_menu;
1880       else
1881         menu_position_func = NULL;
1882
1883       gtk_menu_popup (GTK_MENU (priv->submenu),
1884                       parent,
1885                       widget,
1886                       menu_position_func,
1887                       menu_item,
1888                       GTK_MENU_SHELL (parent)->priv->button,
1889                       0);
1890     }
1891
1892   /* Enable themeing of the parent menu item depending on whether
1893    * its submenu is shown or not.
1894    */
1895   gtk_widget_queue_draw (widget);
1896 }
1897
1898 static gint
1899 gtk_menu_item_popup_timeout (gpointer data)
1900 {
1901   GtkMenuItem *menu_item = GTK_MENU_ITEM (data);
1902   GtkMenuItemPrivate *priv = menu_item->priv;
1903   GtkWidget *parent;
1904
1905   parent = gtk_widget_get_parent (GTK_WIDGET (menu_item));
1906
1907   if ((GTK_IS_MENU_SHELL (parent) && GTK_MENU_SHELL (parent)->priv->active) ||
1908       (GTK_IS_MENU (parent) && GTK_MENU (parent)->priv->torn_off))
1909     {
1910       gtk_menu_item_real_popup_submenu (GTK_WIDGET (menu_item), TRUE);
1911       if (priv->timer_from_keypress && priv->submenu)
1912         GTK_MENU_SHELL (priv->submenu)->priv->ignore_enter = TRUE;
1913     }
1914
1915   priv->timer = 0;
1916
1917   return FALSE;
1918 }
1919
1920 static gint
1921 get_popup_delay (GtkWidget *widget)
1922 {
1923   GtkWidget *parent;
1924
1925   parent = gtk_widget_get_parent (widget);
1926   if (GTK_IS_MENU_SHELL (parent))
1927     {
1928       return _gtk_menu_shell_get_popup_delay (GTK_MENU_SHELL (parent));
1929     }
1930   else
1931     {
1932       gint popup_delay;
1933
1934       g_object_get (gtk_widget_get_settings (widget),
1935                     "gtk-menu-popup-delay", &popup_delay,
1936                     NULL);
1937
1938       return popup_delay;
1939     }
1940 }
1941
1942 void
1943 _gtk_menu_item_popup_submenu (GtkWidget *widget,
1944                               gboolean   with_delay)
1945 {
1946   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1947   GtkMenuItemPrivate *priv = menu_item->priv;
1948
1949   if (priv->timer)
1950     {
1951       g_source_remove (priv->timer);
1952       priv->timer = 0;
1953       with_delay = FALSE;
1954     }
1955
1956   if (with_delay)
1957     {
1958       gint popup_delay = get_popup_delay (widget);
1959
1960       if (popup_delay > 0)
1961         {
1962           GdkEvent *event = gtk_get_current_event ();
1963
1964           priv->timer = gdk_threads_add_timeout (popup_delay,
1965                                                  gtk_menu_item_popup_timeout,
1966                                                  menu_item);
1967
1968           if (event &&
1969               event->type != GDK_BUTTON_PRESS &&
1970               event->type != GDK_ENTER_NOTIFY)
1971             priv->timer_from_keypress = TRUE;
1972           else
1973             priv->timer_from_keypress = FALSE;
1974
1975           if (event)
1976             gdk_event_free (event);
1977
1978           return;
1979         }
1980     }
1981
1982   gtk_menu_item_real_popup_submenu (widget, FALSE);
1983 }
1984
1985 void
1986 _gtk_menu_item_popdown_submenu (GtkWidget *widget)
1987 {
1988   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1989   GtkMenuItemPrivate *priv = menu_item->priv;
1990
1991   if (priv->submenu)
1992     {
1993       g_object_set_data (G_OBJECT (priv->submenu),
1994                          "gtk-menu-exact-popup-time", NULL);
1995
1996       if (priv->timer)
1997         {
1998           g_source_remove (priv->timer);
1999           priv->timer = 0;
2000         }
2001       else
2002         gtk_menu_popdown (GTK_MENU (priv->submenu));
2003
2004       gtk_widget_queue_draw (widget);
2005     }
2006 }
2007
2008 static void
2009 get_offsets (GtkMenu *menu,
2010              gint    *horizontal_offset,
2011              gint    *vertical_offset)
2012 {
2013   gint vertical_padding;
2014   gint horizontal_padding;
2015   GtkStyleContext *context;
2016   GtkStateFlags state;
2017   GtkBorder padding;
2018
2019   gtk_widget_style_get (GTK_WIDGET (menu),
2020                         "horizontal-offset", horizontal_offset,
2021                         "vertical-offset", vertical_offset,
2022                         "horizontal-padding", &horizontal_padding,
2023                         "vertical-padding", &vertical_padding,
2024                         NULL);
2025
2026   context = gtk_widget_get_style_context (GTK_WIDGET (menu));
2027   state = gtk_widget_get_state_flags (GTK_WIDGET (menu));
2028   gtk_style_context_get_padding (context, state, &padding);
2029
2030   *vertical_offset -= padding.top;
2031   *vertical_offset -= vertical_padding;
2032   *horizontal_offset += horizontal_padding;
2033 }
2034
2035 static void
2036 gtk_menu_item_position_menu (GtkMenu  *menu,
2037                              gint     *x,
2038                              gint     *y,
2039                              gboolean *push_in,
2040                              gpointer  user_data)
2041 {
2042   GtkMenuItem *menu_item = GTK_MENU_ITEM (user_data);
2043   GtkMenuItemPrivate *priv = menu_item->priv;
2044   GtkAllocation allocation;
2045   GtkWidget *widget;
2046   GtkMenuItem *parent_menu_item;
2047   GtkWidget *parent;
2048   GdkScreen *screen;
2049   gint twidth, theight;
2050   gint tx, ty;
2051   GtkTextDirection direction;
2052   GdkRectangle monitor;
2053   gint monitor_num;
2054   gint horizontal_offset;
2055   gint vertical_offset;
2056   gint available_left, available_right;
2057   GtkStyleContext *context;
2058   GtkStateFlags state;
2059   GtkBorder parent_padding;
2060
2061   g_return_if_fail (menu != NULL);
2062   g_return_if_fail (x != NULL);
2063   g_return_if_fail (y != NULL);
2064
2065   widget = GTK_WIDGET (user_data);
2066
2067   if (push_in)
2068     *push_in = FALSE;
2069
2070   direction = gtk_widget_get_direction (widget);
2071
2072   twidth = gtk_widget_get_allocated_width (GTK_WIDGET (menu));
2073   theight = gtk_widget_get_allocated_height (GTK_WIDGET (menu));
2074
2075   screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2076   monitor_num = gdk_screen_get_monitor_at_window (screen, priv->event_window);
2077   if (monitor_num < 0)
2078     monitor_num = 0;
2079   gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
2080
2081   if (!gdk_window_get_origin (gtk_widget_get_window (widget), &tx, &ty))
2082     {
2083       g_warning ("Menu not on screen");
2084       return;
2085     }
2086
2087   gtk_widget_get_allocation (widget, &allocation);
2088
2089   tx += allocation.x;
2090   ty += allocation.y;
2091
2092   get_offsets (menu, &horizontal_offset, &vertical_offset);
2093
2094   available_left = tx - monitor.x;
2095   available_right = monitor.x + monitor.width - (tx + allocation.width);
2096
2097   parent = gtk_widget_get_parent (widget);
2098   priv->from_menubar = GTK_IS_MENU_BAR (parent);
2099
2100   switch (priv->submenu_placement)
2101     {
2102     case GTK_TOP_BOTTOM:
2103       if (direction == GTK_TEXT_DIR_LTR)
2104         priv->submenu_direction = GTK_DIRECTION_RIGHT;
2105       else
2106         {
2107           priv->submenu_direction = GTK_DIRECTION_LEFT;
2108           tx += allocation.width - twidth;
2109         }
2110       if ((ty + allocation.height + theight) <= monitor.y + monitor.height)
2111         ty += allocation.height;
2112       else if ((ty - theight) >= monitor.y)
2113         ty -= theight;
2114       else if (monitor.y + monitor.height - (ty + allocation.height) > ty)
2115         ty += allocation.height;
2116       else
2117         ty -= theight;
2118       break;
2119
2120     case GTK_LEFT_RIGHT:
2121       if (GTK_IS_MENU (parent))
2122         parent_menu_item = GTK_MENU_ITEM (GTK_MENU (parent)->priv->parent_menu_item);
2123       else
2124         parent_menu_item = NULL;
2125
2126       context = gtk_widget_get_style_context (parent);
2127       state = gtk_widget_get_state_flags (parent);
2128       gtk_style_context_get_padding (context, state, &parent_padding);
2129
2130       if (parent_menu_item && !GTK_MENU (parent)->priv->torn_off)
2131         {
2132           priv->submenu_direction = parent_menu_item->priv->submenu_direction;
2133         }
2134       else
2135         {
2136           if (direction == GTK_TEXT_DIR_LTR)
2137             priv->submenu_direction = GTK_DIRECTION_RIGHT;
2138           else
2139             priv->submenu_direction = GTK_DIRECTION_LEFT;
2140         }
2141
2142       switch (priv->submenu_direction)
2143         {
2144         case GTK_DIRECTION_LEFT:
2145           if (tx - twidth - parent_padding.left - horizontal_offset >= monitor.x ||
2146               available_left >= available_right)
2147             tx -= twidth + parent_padding.left + horizontal_offset;
2148           else
2149             {
2150               priv->submenu_direction = GTK_DIRECTION_RIGHT;
2151               tx += allocation.width + parent_padding.right + horizontal_offset;
2152             }
2153           break;
2154
2155         case GTK_DIRECTION_RIGHT:
2156           if (tx + allocation.width + parent_padding.right + horizontal_offset + twidth <= monitor.x + monitor.width ||
2157               available_right >= available_left)
2158             tx += allocation.width + parent_padding.right + horizontal_offset;
2159           else
2160             {
2161               priv->submenu_direction = GTK_DIRECTION_LEFT;
2162               tx -= twidth + parent_padding.left + horizontal_offset;
2163             }
2164           break;
2165         }
2166
2167       ty += vertical_offset;
2168
2169       /* If the height of the menu doesn't fit we move it upward. */
2170       ty = CLAMP (ty, monitor.y, MAX (monitor.y, monitor.y + monitor.height - theight));
2171       break;
2172     }
2173
2174   /* If we have negative, tx, here it is because we can't get
2175    * the menu all the way on screen. Favor the left portion.
2176    */
2177   *x = CLAMP (tx, monitor.x, MAX (monitor.x, monitor.x + monitor.width - twidth));
2178   *y = ty;
2179
2180   gtk_menu_set_monitor (menu, monitor_num);
2181
2182   if (!gtk_widget_get_visible (menu->priv->toplevel))
2183     {
2184       gtk_window_set_type_hint (GTK_WINDOW (menu->priv->toplevel), priv->from_menubar?
2185                                 GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU : GDK_WINDOW_TYPE_HINT_POPUP_MENU);
2186     }
2187 }
2188
2189 /**
2190  * gtk_menu_item_set_right_justified:
2191  * @menu_item: a #GtkMenuItem.
2192  * @right_justified: if %TRUE the menu item will appear at the
2193  *   far right if added to a menu bar
2194  *
2195  * Sets whether the menu item appears justified at the right
2196  * side of a menu bar. This was traditionally done for "Help"
2197  * menu items, but is now considered a bad idea. (If the widget
2198  * layout is reversed for a right-to-left language like Hebrew
2199  * or Arabic, right-justified-menu-items appear at the left.)
2200  *
2201  * Deprecated: 3.2: If you insist on using it, use
2202  *   gtk_widget_set_hexpand() and gtk_widget_set_halign().
2203  **/
2204 void
2205 gtk_menu_item_set_right_justified (GtkMenuItem *menu_item,
2206                                    gboolean     right_justified)
2207 {
2208   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2209
2210   gtk_menu_item_do_set_right_justified (menu_item, right_justified);
2211 }
2212
2213 /**
2214  * gtk_menu_item_get_right_justified:
2215  * @menu_item: a #GtkMenuItem
2216  *
2217  * Gets whether the menu item appears justified at the right
2218  * side of the menu bar.
2219  *
2220  * Return value: %TRUE if the menu item will appear at the
2221  *   far right if added to a menu bar.
2222  *
2223  * Deprecated: 3.2: See gtk_menu_item_set_right_justified()
2224  **/
2225 gboolean
2226 gtk_menu_item_get_right_justified (GtkMenuItem *menu_item)
2227 {
2228   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), FALSE);
2229
2230   return menu_item->priv->right_justify;
2231 }
2232
2233
2234 static void
2235 gtk_menu_item_show_all (GtkWidget *widget)
2236 {
2237   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
2238   GtkMenuItemPrivate *priv = menu_item->priv;
2239
2240   /* show children including submenu */
2241   if (priv->submenu)
2242     gtk_widget_show_all (priv->submenu);
2243   gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_show_all, NULL);
2244
2245   gtk_widget_show (widget);
2246 }
2247
2248 static gboolean
2249 gtk_menu_item_can_activate_accel (GtkWidget *widget,
2250                                   guint      signal_id)
2251 {
2252   GtkWidget *parent;
2253
2254   parent = gtk_widget_get_parent (widget);
2255
2256   /* Chain to the parent GtkMenu for further checks */
2257   return (gtk_widget_is_sensitive (widget) && gtk_widget_get_visible (widget) &&
2258           parent && gtk_widget_can_activate_accel (parent, signal_id));
2259 }
2260
2261 static void
2262 gtk_menu_item_accel_name_foreach (GtkWidget *widget,
2263                                   gpointer   data)
2264 {
2265   const gchar **path_p = data;
2266
2267   if (!*path_p)
2268     {
2269       if (GTK_IS_LABEL (widget))
2270         {
2271           *path_p = gtk_label_get_text (GTK_LABEL (widget));
2272           if (*path_p && (*path_p)[0] == 0)
2273             *path_p = NULL;
2274         }
2275       else if (GTK_IS_CONTAINER (widget))
2276         gtk_container_foreach (GTK_CONTAINER (widget),
2277                                gtk_menu_item_accel_name_foreach,
2278                                data);
2279     }
2280 }
2281
2282 static void
2283 gtk_menu_item_parent_set (GtkWidget *widget,
2284                           GtkWidget *previous_parent)
2285 {
2286   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
2287   GtkMenu *menu;
2288   GtkWidget *parent;
2289
2290   parent = gtk_widget_get_parent (widget);
2291   menu = GTK_IS_MENU (parent) ? GTK_MENU (parent) : NULL;
2292
2293   if (menu)
2294     _gtk_menu_item_refresh_accel_path (menu_item,
2295                                        menu->priv->accel_path,
2296                                        menu->priv->accel_group,
2297                                        TRUE);
2298
2299   if (GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->parent_set)
2300     GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->parent_set (widget, previous_parent);
2301 }
2302
2303 void
2304 _gtk_menu_item_refresh_accel_path (GtkMenuItem   *menu_item,
2305                                    const gchar   *prefix,
2306                                    GtkAccelGroup *accel_group,
2307                                    gboolean       group_changed)
2308 {
2309   GtkMenuItemPrivate *priv = menu_item->priv;
2310   const gchar *path;
2311   GtkWidget *widget;
2312
2313   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2314   g_return_if_fail (!accel_group || GTK_IS_ACCEL_GROUP (accel_group));
2315
2316   widget = GTK_WIDGET (menu_item);
2317
2318   if (!accel_group)
2319     {
2320       gtk_widget_set_accel_path (widget, NULL, NULL);
2321       return;
2322     }
2323
2324   path = _gtk_widget_get_accel_path (widget, NULL);
2325   if (!path)  /* no active accel_path yet */
2326     {
2327       path = priv->accel_path;
2328       if (!path && prefix)
2329         {
2330           const gchar *postfix = NULL;
2331           gchar *new_path;
2332
2333           /* try to construct one from label text */
2334           gtk_container_foreach (GTK_CONTAINER (menu_item),
2335                                  gtk_menu_item_accel_name_foreach,
2336                                  &postfix);
2337           if (postfix)
2338             {
2339               new_path = g_strconcat (prefix, "/", postfix, NULL);
2340               path = priv->accel_path = (char*)g_intern_string (new_path);
2341               g_free (new_path);
2342             }
2343         }
2344       if (path)
2345         gtk_widget_set_accel_path (widget, path, accel_group);
2346     }
2347   else if (group_changed)    /* reinstall accelerators */
2348     gtk_widget_set_accel_path (widget, path, accel_group);
2349 }
2350
2351 /**
2352  * gtk_menu_item_set_accel_path:
2353  * @menu_item:  a valid #GtkMenuItem
2354  * @accel_path: (allow-none): accelerator path, corresponding to this menu
2355  *     item's functionality, or %NULL to unset the current path.
2356  *
2357  * Set the accelerator path on @menu_item, through which runtime
2358  * changes of the menu item's accelerator caused by the user can be
2359  * identified and saved to persistent storage (see gtk_accel_map_save()
2360  * on this). To set up a default accelerator for this menu item, call
2361  * gtk_accel_map_add_entry() with the same @accel_path. See also
2362  * gtk_accel_map_add_entry() on the specifics of accelerator paths,
2363  * and gtk_menu_set_accel_path() for a more convenient variant of
2364  * this function.
2365  *
2366  * This function is basically a convenience wrapper that handles
2367  * calling gtk_widget_set_accel_path() with the appropriate accelerator
2368  * group for the menu item.
2369  *
2370  * Note that you do need to set an accelerator on the parent menu with
2371  * gtk_menu_set_accel_group() for this to work.
2372  *
2373  * Note that @accel_path string will be stored in a #GQuark.
2374  * Therefore, if you pass a static string, you can save some memory
2375  * by interning it first with g_intern_static_string().
2376  */
2377 void
2378 gtk_menu_item_set_accel_path (GtkMenuItem *menu_item,
2379                               const gchar *accel_path)
2380 {
2381   GtkMenuItemPrivate *priv = menu_item->priv;
2382   GtkWidget *parent;
2383   GtkWidget *widget;
2384
2385   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2386   g_return_if_fail (accel_path == NULL ||
2387                     (accel_path[0] == '<' && strchr (accel_path, '/')));
2388
2389   widget = GTK_WIDGET (menu_item);
2390
2391   /* store new path */
2392   priv->accel_path = (char*)g_intern_string (accel_path);
2393
2394   /* forget accelerators associated with old path */
2395   gtk_widget_set_accel_path (widget, NULL, NULL);
2396
2397   /* install accelerators associated with new path */
2398   parent = gtk_widget_get_parent (widget);
2399   if (GTK_IS_MENU (parent))
2400     {
2401       GtkMenu *menu = GTK_MENU (parent);
2402
2403       if (menu->priv->accel_group)
2404         _gtk_menu_item_refresh_accel_path (GTK_MENU_ITEM (widget),
2405                                            NULL,
2406                                            menu->priv->accel_group,
2407                                            FALSE);
2408     }
2409 }
2410
2411 /**
2412  * gtk_menu_item_get_accel_path:
2413  * @menu_item:  a valid #GtkMenuItem
2414  *
2415  * Retrieve the accelerator path that was previously set on @menu_item.
2416  *
2417  * See gtk_menu_item_set_accel_path() for details.
2418  *
2419  * Returns: the accelerator path corresponding to this menu
2420  *     item's functionality, or %NULL if not set
2421  *
2422  * Since: 2.14
2423  */
2424 const gchar *
2425 gtk_menu_item_get_accel_path (GtkMenuItem *menu_item)
2426 {
2427   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL);
2428
2429   return menu_item->priv->accel_path;
2430 }
2431
2432 static void
2433 gtk_menu_item_forall (GtkContainer *container,
2434                       gboolean      include_internals,
2435                       GtkCallback   callback,
2436                       gpointer      callback_data)
2437 {
2438   GtkWidget *child;
2439
2440   g_return_if_fail (GTK_IS_MENU_ITEM (container));
2441   g_return_if_fail (callback != NULL);
2442
2443   child = gtk_bin_get_child (GTK_BIN (container));
2444   if (child)
2445     callback (child, callback_data);
2446 }
2447
2448 gboolean
2449 _gtk_menu_item_is_selectable (GtkWidget *menu_item)
2450 {
2451   if ((!gtk_bin_get_child (GTK_BIN (menu_item)) &&
2452        G_OBJECT_TYPE (menu_item) == GTK_TYPE_MENU_ITEM) ||
2453       GTK_IS_SEPARATOR_MENU_ITEM (menu_item) ||
2454       !gtk_widget_is_sensitive (menu_item) ||
2455       !gtk_widget_get_visible (menu_item))
2456     return FALSE;
2457
2458   return TRUE;
2459 }
2460
2461 static void
2462 gtk_menu_item_ensure_label (GtkMenuItem *menu_item)
2463 {
2464   GtkWidget *accel_label;
2465
2466   if (!gtk_bin_get_child (GTK_BIN (menu_item)))
2467     {
2468       accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
2469       gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
2470
2471       gtk_container_add (GTK_CONTAINER (menu_item), accel_label);
2472       gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label),
2473                                         GTK_WIDGET (menu_item));
2474       gtk_widget_show (accel_label);
2475     }
2476 }
2477
2478 /**
2479  * gtk_menu_item_set_label:
2480  * @menu_item: a #GtkMenuItem
2481  * @label: the text you want to set
2482  *
2483  * Sets @text on the @menu_item label
2484  *
2485  * Since: 2.16
2486  */
2487 void
2488 gtk_menu_item_set_label (GtkMenuItem *menu_item,
2489                          const gchar *label)
2490 {
2491   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2492
2493   GTK_MENU_ITEM_GET_CLASS (menu_item)->set_label (menu_item, label);
2494 }
2495
2496 /**
2497  * gtk_menu_item_get_label:
2498  * @menu_item: a #GtkMenuItem
2499  *
2500  * Sets @text on the @menu_item label
2501  *
2502  * Returns: The text in the @menu_item label. This is the internal
2503  *   string used by the label, and must not be modified.
2504  *
2505  * Since: 2.16
2506  */
2507 const gchar *
2508 gtk_menu_item_get_label (GtkMenuItem *menu_item)
2509 {
2510   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL);
2511
2512   return GTK_MENU_ITEM_GET_CLASS (menu_item)->get_label (menu_item);
2513 }
2514
2515 /**
2516  * gtk_menu_item_set_use_underline:
2517  * @menu_item: a #GtkMenuItem
2518  * @setting: %TRUE if underlines in the text indicate mnemonics
2519  *
2520  * If true, an underline in the text indicates the next character
2521  * should be used for the mnemonic accelerator key.
2522  *
2523  * Since: 2.16
2524  */
2525 void
2526 gtk_menu_item_set_use_underline (GtkMenuItem *menu_item,
2527                                  gboolean     setting)
2528 {
2529   GtkWidget *child;
2530
2531   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2532
2533   gtk_menu_item_ensure_label (menu_item);
2534
2535   child = gtk_bin_get_child (GTK_BIN (menu_item));
2536   if (GTK_IS_LABEL (child))
2537     {
2538       gtk_label_set_use_underline (GTK_LABEL (child), setting);
2539
2540       g_object_notify (G_OBJECT (menu_item), "use-underline");
2541     }
2542 }
2543
2544 /**
2545  * gtk_menu_item_get_use_underline:
2546  * @menu_item: a #GtkMenuItem
2547  *
2548  * Checks if an underline in the text indicates the next character
2549  * should be used for the mnemonic accelerator key.
2550  *
2551  * Return value: %TRUE if an embedded underline in the label
2552  *     indicates the mnemonic accelerator key.
2553  *
2554  * Since: 2.16
2555  */
2556 gboolean
2557 gtk_menu_item_get_use_underline (GtkMenuItem *menu_item)
2558 {
2559   GtkWidget *child;
2560
2561   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), FALSE);
2562
2563   gtk_menu_item_ensure_label (menu_item);
2564
2565   child = gtk_bin_get_child (GTK_BIN (menu_item));
2566   if (GTK_IS_LABEL (child))
2567     return gtk_label_get_use_underline (GTK_LABEL (child));
2568
2569   return FALSE;
2570 }
2571
2572 /**
2573  * gtk_menu_item_set_reserve_indicator:
2574  * @menu_item: a #GtkMenuItem
2575  * @reserve: the new value
2576  *
2577  * Sets whether the @menu_item should reserve space for
2578  * the submenu indicator, regardless if it actually has
2579  * a submenu or not.
2580  *
2581  * There should be little need for applications to call
2582  * this functions.
2583  *
2584  * Since: 3.0
2585  */
2586 void
2587 gtk_menu_item_set_reserve_indicator (GtkMenuItem *menu_item,
2588                                      gboolean     reserve)
2589 {
2590   GtkMenuItemPrivate *priv;
2591
2592   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2593
2594   priv = menu_item->priv;
2595
2596   if (priv->reserve_indicator != reserve)
2597     {
2598       priv->reserve_indicator = reserve;
2599       gtk_widget_queue_resize (GTK_WIDGET (menu_item));
2600     }
2601 }
2602
2603 /**
2604  * gtk_menu_item_get_reserve_indicator:
2605  * @menu_item: a #GtkMenuItem
2606  *
2607  * Returns whether the @menu_item reserves space for
2608  * the submenu indicator, regardless if it has a submenu
2609  * or not.
2610  *
2611  * Returns: %TRUE if @menu_item always reserves space for the
2612  *     submenu indicator
2613  *
2614  * Since: 3.0
2615  */
2616 gboolean
2617 gtk_menu_item_get_reserve_indicator (GtkMenuItem *menu_item)
2618 {
2619   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), FALSE);
2620
2621   return menu_item->priv->reserve_indicator;
2622 }