]> Pileus Git - ~andy/gtk/blob - gtk/gtkmenuitem.c
388c2a503859d85eda4a8f5e8f1271ff1e98c7b0
[~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_save (context);
1606
1607   gtk_style_context_get_padding (context, state, &padding);
1608
1609   if (GTK_IS_MENU_BAR (parent))
1610     gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUBAR);
1611
1612   if (child && (state & GTK_STATE_FLAG_PRELIGHT))
1613     {
1614       gtk_render_background (context, cr, x, y, w, h);
1615       gtk_render_frame (context, cr, x, y, w, h);
1616     }
1617
1618   if (priv->submenu && !GTK_IS_MENU_BAR (parent))
1619     {
1620       gint arrow_x, arrow_y;
1621       gint arrow_size;
1622       guint horizontal_padding;
1623       GtkTextDirection direction;
1624       gdouble angle;
1625
1626       direction = gtk_widget_get_direction (widget);
1627
1628       gtk_widget_style_get (widget,
1629                             "horizontal-padding", &horizontal_padding,
1630                             NULL);
1631
1632       get_arrow_size (widget, child, &arrow_size, NULL);
1633
1634       if (direction == GTK_TEXT_DIR_LTR)
1635         {
1636           arrow_x = x + w - horizontal_padding - arrow_size;
1637           angle = G_PI / 2;
1638         }
1639       else
1640         {
1641           arrow_x = x + horizontal_padding;
1642           angle = (3 * G_PI) / 2;
1643         }
1644
1645       arrow_y = y + (h - arrow_size) / 2;
1646
1647       gtk_render_arrow (context, cr, angle, arrow_x, arrow_y, arrow_size);
1648     }
1649   else if (!child)
1650     {
1651       gboolean wide_separators;
1652       gint     separator_height;
1653       guint    horizontal_padding;
1654
1655       gtk_widget_style_get (widget,
1656                             "wide-separators",    &wide_separators,
1657                             "separator-height",   &separator_height,
1658                             "horizontal-padding", &horizontal_padding,
1659                             NULL);
1660       if (wide_separators)
1661         gtk_render_frame (context, cr,
1662                           x + horizontal_padding + padding.left,
1663                           y + padding.top,
1664                           w - (2 * horizontal_padding) - padding.left - padding.right,
1665                           separator_height);
1666       else
1667         gtk_render_line (context, cr,
1668                          x + horizontal_padding + padding.left,
1669                          y + padding.top,
1670                          x + w - horizontal_padding - padding.right - 1,
1671                          y + padding.top);
1672     }
1673
1674   GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->draw (widget, cr);
1675
1676   gtk_style_context_restore (context);
1677
1678   return FALSE;
1679 }
1680
1681 /**
1682  * gtk_menu_item_select:
1683  * @menu_item: the menu item
1684  *
1685  * Emits the #GtkMenuItem::select signal on the given item. Behaves
1686  * exactly like #gtk_item_select.
1687  */
1688 static void
1689 gtk_real_menu_item_select (GtkMenuItem *menu_item)
1690 {
1691   GtkMenuItemPrivate *priv = menu_item->priv;
1692   GdkDevice *source_device = NULL;
1693   GdkEvent *current_event;
1694
1695   current_event = gtk_get_current_event ();
1696
1697   if (current_event)
1698     {
1699       source_device = gdk_event_get_source_device (current_event);
1700       gdk_event_free (current_event);
1701     }
1702
1703   if ((!source_device ||
1704        gdk_device_get_source (source_device) != GDK_SOURCE_TOUCHSCREEN) &&
1705       priv->submenu &&
1706       (!gtk_widget_get_mapped (priv->submenu) ||
1707        GTK_MENU (priv->submenu)->priv->tearoff_active))
1708     {
1709       _gtk_menu_item_popup_submenu (GTK_WIDGET (menu_item), TRUE);
1710     }
1711
1712   gtk_widget_set_state_flags (GTK_WIDGET (menu_item),
1713                               GTK_STATE_FLAG_PRELIGHT, FALSE);
1714   gtk_widget_queue_draw (GTK_WIDGET (menu_item));
1715 }
1716
1717 static void
1718 gtk_real_menu_item_deselect (GtkMenuItem *menu_item)
1719 {
1720   GtkMenuItemPrivate *priv = menu_item->priv;
1721
1722   if (priv->submenu)
1723     _gtk_menu_item_popdown_submenu (GTK_WIDGET (menu_item));
1724
1725   gtk_widget_unset_state_flags (GTK_WIDGET (menu_item),
1726                                 GTK_STATE_FLAG_PRELIGHT);
1727   gtk_widget_queue_draw (GTK_WIDGET (menu_item));
1728 }
1729
1730 static gboolean
1731 gtk_menu_item_mnemonic_activate (GtkWidget *widget,
1732                                  gboolean   group_cycling)
1733 {
1734   GtkWidget *parent;
1735
1736   parent = gtk_widget_get_parent (widget);
1737
1738   if (GTK_IS_MENU_SHELL (parent))
1739     _gtk_menu_shell_set_keyboard_mode (GTK_MENU_SHELL (parent), TRUE);
1740
1741   if (group_cycling &&
1742       parent &&
1743       GTK_IS_MENU_SHELL (parent) &&
1744       GTK_MENU_SHELL (parent)->priv->active)
1745     {
1746       gtk_menu_shell_select_item (GTK_MENU_SHELL (parent), widget);
1747     }
1748   else
1749     g_signal_emit (widget, menu_item_signals[ACTIVATE_ITEM], 0);
1750
1751   return TRUE;
1752 }
1753
1754 static void
1755 gtk_real_menu_item_activate (GtkMenuItem *menu_item)
1756 {
1757   GtkMenuItemPrivate *priv = menu_item->priv;
1758
1759   if (priv->action)
1760     gtk_action_activate (priv->action);
1761 }
1762
1763
1764 static void
1765 gtk_real_menu_item_activate_item (GtkMenuItem *menu_item)
1766 {
1767   GtkMenuItemPrivate *priv = menu_item->priv;
1768   GtkWidget *parent;
1769   GtkWidget *widget;
1770
1771   widget = GTK_WIDGET (menu_item);
1772   parent = gtk_widget_get_parent (widget);
1773
1774   if (parent && GTK_IS_MENU_SHELL (parent))
1775     {
1776       GtkMenuShell *menu_shell = GTK_MENU_SHELL (parent);
1777
1778       if (priv->submenu == NULL)
1779         gtk_menu_shell_activate_item (menu_shell, widget, TRUE);
1780       else
1781         {
1782           gtk_menu_shell_select_item (menu_shell, widget);
1783           _gtk_menu_item_popup_submenu (widget, FALSE);
1784
1785           gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->submenu), TRUE);
1786         }
1787     }
1788 }
1789
1790 static void
1791 gtk_real_menu_item_toggle_size_request (GtkMenuItem *menu_item,
1792                                         gint        *requisition)
1793 {
1794   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1795
1796   *requisition = 0;
1797 }
1798
1799 static void
1800 gtk_real_menu_item_toggle_size_allocate (GtkMenuItem *menu_item,
1801                                          gint         allocation)
1802 {
1803   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1804
1805   menu_item->priv->toggle_size = allocation;
1806 }
1807
1808 static void
1809 gtk_real_menu_item_set_label (GtkMenuItem *menu_item,
1810                               const gchar *label)
1811 {
1812   GtkWidget *child;
1813
1814   gtk_menu_item_ensure_label (menu_item);
1815
1816   child = gtk_bin_get_child (GTK_BIN (menu_item));
1817   if (GTK_IS_LABEL (child))
1818     {
1819       gtk_label_set_label (GTK_LABEL (child), label ? label : "");
1820
1821       g_object_notify (G_OBJECT (menu_item), "label");
1822     }
1823 }
1824
1825 static const gchar *
1826 gtk_real_menu_item_get_label (GtkMenuItem *menu_item)
1827 {
1828   GtkWidget *child;
1829
1830   gtk_menu_item_ensure_label (menu_item);
1831
1832   child = gtk_bin_get_child (GTK_BIN (menu_item));
1833   if (GTK_IS_LABEL (child))
1834     return gtk_label_get_label (GTK_LABEL (child));
1835
1836   return NULL;
1837 }
1838
1839 static void
1840 free_timeval (GTimeVal *val)
1841 {
1842   g_slice_free (GTimeVal, val);
1843 }
1844
1845 static void
1846 gtk_menu_item_real_popup_submenu (GtkWidget *widget,
1847                                   gboolean   remember_exact_time)
1848 {
1849   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1850   GtkMenuItemPrivate *priv = menu_item->priv;
1851   GtkWidget *parent;
1852
1853   parent = gtk_widget_get_parent (widget);
1854
1855   if (gtk_widget_is_sensitive (priv->submenu) && parent)
1856     {
1857       gboolean take_focus;
1858       GtkMenuPositionFunc menu_position_func;
1859
1860       take_focus = gtk_menu_shell_get_take_focus (GTK_MENU_SHELL (parent));
1861       gtk_menu_shell_set_take_focus (GTK_MENU_SHELL (priv->submenu), take_focus);
1862
1863       if (remember_exact_time)
1864         {
1865           GTimeVal *popup_time = g_slice_new0 (GTimeVal);
1866
1867           g_get_current_time (popup_time);
1868
1869           g_object_set_data_full (G_OBJECT (priv->submenu),
1870                                   "gtk-menu-exact-popup-time", popup_time,
1871                                   (GDestroyNotify) free_timeval);
1872         }
1873       else
1874         {
1875           g_object_set_data (G_OBJECT (priv->submenu),
1876                              "gtk-menu-exact-popup-time", NULL);
1877         }
1878
1879       /* gtk_menu_item_position_menu positions the submenu from the
1880        * menuitems position. If the menuitem doesn't have a window,
1881        * that doesn't work. In that case we use the default
1882        * positioning function instead which places the submenu at the
1883        * mouse cursor.
1884        */
1885       if (gtk_widget_get_window (widget))
1886         menu_position_func = gtk_menu_item_position_menu;
1887       else
1888         menu_position_func = NULL;
1889
1890       gtk_menu_popup (GTK_MENU (priv->submenu),
1891                       parent,
1892                       widget,
1893                       menu_position_func,
1894                       menu_item,
1895                       GTK_MENU_SHELL (parent)->priv->button,
1896                       0);
1897     }
1898
1899   /* Enable themeing of the parent menu item depending on whether
1900    * its submenu is shown or not.
1901    */
1902   gtk_widget_queue_draw (widget);
1903 }
1904
1905 static gint
1906 gtk_menu_item_popup_timeout (gpointer data)
1907 {
1908   GtkMenuItem *menu_item = GTK_MENU_ITEM (data);
1909   GtkMenuItemPrivate *priv = menu_item->priv;
1910   GtkWidget *parent;
1911
1912   parent = gtk_widget_get_parent (GTK_WIDGET (menu_item));
1913
1914   if ((GTK_IS_MENU_SHELL (parent) && GTK_MENU_SHELL (parent)->priv->active) ||
1915       (GTK_IS_MENU (parent) && GTK_MENU (parent)->priv->torn_off))
1916     {
1917       gtk_menu_item_real_popup_submenu (GTK_WIDGET (menu_item), TRUE);
1918       if (priv->timer_from_keypress && priv->submenu)
1919         GTK_MENU_SHELL (priv->submenu)->priv->ignore_enter = TRUE;
1920     }
1921
1922   priv->timer = 0;
1923
1924   return FALSE;
1925 }
1926
1927 static gint
1928 get_popup_delay (GtkWidget *widget)
1929 {
1930   GtkWidget *parent;
1931
1932   parent = gtk_widget_get_parent (widget);
1933   if (GTK_IS_MENU_SHELL (parent))
1934     {
1935       return _gtk_menu_shell_get_popup_delay (GTK_MENU_SHELL (parent));
1936     }
1937   else
1938     {
1939       gint popup_delay;
1940
1941       g_object_get (gtk_widget_get_settings (widget),
1942                     "gtk-menu-popup-delay", &popup_delay,
1943                     NULL);
1944
1945       return popup_delay;
1946     }
1947 }
1948
1949 void
1950 _gtk_menu_item_popup_submenu (GtkWidget *widget,
1951                               gboolean   with_delay)
1952 {
1953   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1954   GtkMenuItemPrivate *priv = menu_item->priv;
1955
1956   if (priv->timer)
1957     {
1958       g_source_remove (priv->timer);
1959       priv->timer = 0;
1960       with_delay = FALSE;
1961     }
1962
1963   if (with_delay)
1964     {
1965       gint popup_delay = get_popup_delay (widget);
1966
1967       if (popup_delay > 0)
1968         {
1969           GdkEvent *event = gtk_get_current_event ();
1970
1971           priv->timer = gdk_threads_add_timeout (popup_delay,
1972                                                  gtk_menu_item_popup_timeout,
1973                                                  menu_item);
1974
1975           if (event &&
1976               event->type != GDK_BUTTON_PRESS &&
1977               event->type != GDK_ENTER_NOTIFY)
1978             priv->timer_from_keypress = TRUE;
1979           else
1980             priv->timer_from_keypress = FALSE;
1981
1982           if (event)
1983             gdk_event_free (event);
1984
1985           return;
1986         }
1987     }
1988
1989   gtk_menu_item_real_popup_submenu (widget, FALSE);
1990 }
1991
1992 void
1993 _gtk_menu_item_popdown_submenu (GtkWidget *widget)
1994 {
1995   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
1996   GtkMenuItemPrivate *priv = menu_item->priv;
1997
1998   if (priv->submenu)
1999     {
2000       g_object_set_data (G_OBJECT (priv->submenu),
2001                          "gtk-menu-exact-popup-time", NULL);
2002
2003       if (priv->timer)
2004         {
2005           g_source_remove (priv->timer);
2006           priv->timer = 0;
2007         }
2008       else
2009         gtk_menu_popdown (GTK_MENU (priv->submenu));
2010
2011       gtk_widget_queue_draw (widget);
2012     }
2013 }
2014
2015 static void
2016 get_offsets (GtkMenu *menu,
2017              gint    *horizontal_offset,
2018              gint    *vertical_offset)
2019 {
2020   gint vertical_padding;
2021   gint horizontal_padding;
2022   GtkStyleContext *context;
2023   GtkStateFlags state;
2024   GtkBorder padding;
2025
2026   gtk_widget_style_get (GTK_WIDGET (menu),
2027                         "horizontal-offset", horizontal_offset,
2028                         "vertical-offset", vertical_offset,
2029                         "horizontal-padding", &horizontal_padding,
2030                         "vertical-padding", &vertical_padding,
2031                         NULL);
2032
2033   context = gtk_widget_get_style_context (GTK_WIDGET (menu));
2034   state = gtk_widget_get_state_flags (GTK_WIDGET (menu));
2035   gtk_style_context_get_padding (context, state, &padding);
2036
2037   *vertical_offset -= padding.top;
2038   *vertical_offset -= vertical_padding;
2039   *horizontal_offset += horizontal_padding;
2040 }
2041
2042 static void
2043 gtk_menu_item_position_menu (GtkMenu  *menu,
2044                              gint     *x,
2045                              gint     *y,
2046                              gboolean *push_in,
2047                              gpointer  user_data)
2048 {
2049   GtkMenuItem *menu_item = GTK_MENU_ITEM (user_data);
2050   GtkMenuItemPrivate *priv = menu_item->priv;
2051   GtkAllocation allocation;
2052   GtkWidget *widget;
2053   GtkMenuItem *parent_menu_item;
2054   GtkWidget *parent;
2055   GdkScreen *screen;
2056   gint twidth, theight;
2057   gint tx, ty;
2058   GtkTextDirection direction;
2059   GdkRectangle monitor;
2060   gint monitor_num;
2061   gint horizontal_offset;
2062   gint vertical_offset;
2063   gint available_left, available_right;
2064   GtkStyleContext *context;
2065   GtkStateFlags state;
2066   GtkBorder parent_padding;
2067
2068   g_return_if_fail (menu != NULL);
2069   g_return_if_fail (x != NULL);
2070   g_return_if_fail (y != NULL);
2071
2072   widget = GTK_WIDGET (user_data);
2073
2074   if (push_in)
2075     *push_in = FALSE;
2076
2077   direction = gtk_widget_get_direction (widget);
2078
2079   twidth = gtk_widget_get_allocated_width (GTK_WIDGET (menu));
2080   theight = gtk_widget_get_allocated_height (GTK_WIDGET (menu));
2081
2082   screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2083   monitor_num = gdk_screen_get_monitor_at_window (screen, priv->event_window);
2084   if (monitor_num < 0)
2085     monitor_num = 0;
2086   gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
2087
2088   if (!gdk_window_get_origin (gtk_widget_get_window (widget), &tx, &ty))
2089     {
2090       g_warning ("Menu not on screen");
2091       return;
2092     }
2093
2094   gtk_widget_get_allocation (widget, &allocation);
2095
2096   tx += allocation.x;
2097   ty += allocation.y;
2098
2099   get_offsets (menu, &horizontal_offset, &vertical_offset);
2100
2101   available_left = tx - monitor.x;
2102   available_right = monitor.x + monitor.width - (tx + allocation.width);
2103
2104   parent = gtk_widget_get_parent (widget);
2105   priv->from_menubar = GTK_IS_MENU_BAR (parent);
2106
2107   switch (priv->submenu_placement)
2108     {
2109     case GTK_TOP_BOTTOM:
2110       if (direction == GTK_TEXT_DIR_LTR)
2111         priv->submenu_direction = GTK_DIRECTION_RIGHT;
2112       else
2113         {
2114           priv->submenu_direction = GTK_DIRECTION_LEFT;
2115           tx += allocation.width - twidth;
2116         }
2117       if ((ty + allocation.height + theight) <= monitor.y + monitor.height)
2118         ty += allocation.height;
2119       else if ((ty - theight) >= monitor.y)
2120         ty -= theight;
2121       else if (monitor.y + monitor.height - (ty + allocation.height) > ty)
2122         ty += allocation.height;
2123       else
2124         ty -= theight;
2125       break;
2126
2127     case GTK_LEFT_RIGHT:
2128       if (GTK_IS_MENU (parent))
2129         parent_menu_item = GTK_MENU_ITEM (GTK_MENU (parent)->priv->parent_menu_item);
2130       else
2131         parent_menu_item = NULL;
2132
2133       context = gtk_widget_get_style_context (parent);
2134       state = gtk_widget_get_state_flags (parent);
2135       gtk_style_context_get_padding (context, state, &parent_padding);
2136
2137       if (parent_menu_item && !GTK_MENU (parent)->priv->torn_off)
2138         {
2139           priv->submenu_direction = parent_menu_item->priv->submenu_direction;
2140         }
2141       else
2142         {
2143           if (direction == GTK_TEXT_DIR_LTR)
2144             priv->submenu_direction = GTK_DIRECTION_RIGHT;
2145           else
2146             priv->submenu_direction = GTK_DIRECTION_LEFT;
2147         }
2148
2149       switch (priv->submenu_direction)
2150         {
2151         case GTK_DIRECTION_LEFT:
2152           if (tx - twidth - parent_padding.left - horizontal_offset >= monitor.x ||
2153               available_left >= available_right)
2154             tx -= twidth + parent_padding.left + horizontal_offset;
2155           else
2156             {
2157               priv->submenu_direction = GTK_DIRECTION_RIGHT;
2158               tx += allocation.width + parent_padding.right + horizontal_offset;
2159             }
2160           break;
2161
2162         case GTK_DIRECTION_RIGHT:
2163           if (tx + allocation.width + parent_padding.right + horizontal_offset + twidth <= monitor.x + monitor.width ||
2164               available_right >= available_left)
2165             tx += allocation.width + parent_padding.right + horizontal_offset;
2166           else
2167             {
2168               priv->submenu_direction = GTK_DIRECTION_LEFT;
2169               tx -= twidth + parent_padding.left + horizontal_offset;
2170             }
2171           break;
2172         }
2173
2174       ty += vertical_offset;
2175
2176       /* If the height of the menu doesn't fit we move it upward. */
2177       ty = CLAMP (ty, monitor.y, MAX (monitor.y, monitor.y + monitor.height - theight));
2178       break;
2179     }
2180
2181   /* If we have negative, tx, here it is because we can't get
2182    * the menu all the way on screen. Favor the left portion.
2183    */
2184   *x = CLAMP (tx, monitor.x, MAX (monitor.x, monitor.x + monitor.width - twidth));
2185   *y = ty;
2186
2187   gtk_menu_set_monitor (menu, monitor_num);
2188
2189   if (!gtk_widget_get_visible (menu->priv->toplevel))
2190     {
2191       gtk_window_set_type_hint (GTK_WINDOW (menu->priv->toplevel), priv->from_menubar?
2192                                 GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU : GDK_WINDOW_TYPE_HINT_POPUP_MENU);
2193     }
2194 }
2195
2196 /**
2197  * gtk_menu_item_set_right_justified:
2198  * @menu_item: a #GtkMenuItem.
2199  * @right_justified: if %TRUE the menu item will appear at the
2200  *   far right if added to a menu bar
2201  *
2202  * Sets whether the menu item appears justified at the right
2203  * side of a menu bar. This was traditionally done for "Help"
2204  * menu items, but is now considered a bad idea. (If the widget
2205  * layout is reversed for a right-to-left language like Hebrew
2206  * or Arabic, right-justified-menu-items appear at the left.)
2207  *
2208  * Deprecated: 3.2: If you insist on using it, use
2209  *   gtk_widget_set_hexpand() and gtk_widget_set_halign().
2210  **/
2211 void
2212 gtk_menu_item_set_right_justified (GtkMenuItem *menu_item,
2213                                    gboolean     right_justified)
2214 {
2215   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2216
2217   gtk_menu_item_do_set_right_justified (menu_item, right_justified);
2218 }
2219
2220 /**
2221  * gtk_menu_item_get_right_justified:
2222  * @menu_item: a #GtkMenuItem
2223  *
2224  * Gets whether the menu item appears justified at the right
2225  * side of the menu bar.
2226  *
2227  * Return value: %TRUE if the menu item will appear at the
2228  *   far right if added to a menu bar.
2229  *
2230  * Deprecated: 3.2: See gtk_menu_item_set_right_justified()
2231  **/
2232 gboolean
2233 gtk_menu_item_get_right_justified (GtkMenuItem *menu_item)
2234 {
2235   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), FALSE);
2236
2237   return menu_item->priv->right_justify;
2238 }
2239
2240
2241 static void
2242 gtk_menu_item_show_all (GtkWidget *widget)
2243 {
2244   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
2245   GtkMenuItemPrivate *priv = menu_item->priv;
2246
2247   /* show children including submenu */
2248   if (priv->submenu)
2249     gtk_widget_show_all (priv->submenu);
2250   gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_show_all, NULL);
2251
2252   gtk_widget_show (widget);
2253 }
2254
2255 static gboolean
2256 gtk_menu_item_can_activate_accel (GtkWidget *widget,
2257                                   guint      signal_id)
2258 {
2259   GtkWidget *parent;
2260
2261   parent = gtk_widget_get_parent (widget);
2262
2263   /* Chain to the parent GtkMenu for further checks */
2264   return (gtk_widget_is_sensitive (widget) && gtk_widget_get_visible (widget) &&
2265           parent && gtk_widget_can_activate_accel (parent, signal_id));
2266 }
2267
2268 static void
2269 gtk_menu_item_accel_name_foreach (GtkWidget *widget,
2270                                   gpointer   data)
2271 {
2272   const gchar **path_p = data;
2273
2274   if (!*path_p)
2275     {
2276       if (GTK_IS_LABEL (widget))
2277         {
2278           *path_p = gtk_label_get_text (GTK_LABEL (widget));
2279           if (*path_p && (*path_p)[0] == 0)
2280             *path_p = NULL;
2281         }
2282       else if (GTK_IS_CONTAINER (widget))
2283         gtk_container_foreach (GTK_CONTAINER (widget),
2284                                gtk_menu_item_accel_name_foreach,
2285                                data);
2286     }
2287 }
2288
2289 static void
2290 gtk_menu_item_parent_set (GtkWidget *widget,
2291                           GtkWidget *previous_parent)
2292 {
2293   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
2294   GtkMenu *menu;
2295   GtkWidget *parent;
2296
2297   parent = gtk_widget_get_parent (widget);
2298   menu = GTK_IS_MENU (parent) ? GTK_MENU (parent) : NULL;
2299
2300   if (menu)
2301     _gtk_menu_item_refresh_accel_path (menu_item,
2302                                        menu->priv->accel_path,
2303                                        menu->priv->accel_group,
2304                                        TRUE);
2305
2306   if (GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->parent_set)
2307     GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->parent_set (widget, previous_parent);
2308 }
2309
2310 void
2311 _gtk_menu_item_refresh_accel_path (GtkMenuItem   *menu_item,
2312                                    const gchar   *prefix,
2313                                    GtkAccelGroup *accel_group,
2314                                    gboolean       group_changed)
2315 {
2316   GtkMenuItemPrivate *priv = menu_item->priv;
2317   const gchar *path;
2318   GtkWidget *widget;
2319
2320   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2321   g_return_if_fail (!accel_group || GTK_IS_ACCEL_GROUP (accel_group));
2322
2323   widget = GTK_WIDGET (menu_item);
2324
2325   if (!accel_group)
2326     {
2327       gtk_widget_set_accel_path (widget, NULL, NULL);
2328       return;
2329     }
2330
2331   path = _gtk_widget_get_accel_path (widget, NULL);
2332   if (!path)  /* no active accel_path yet */
2333     {
2334       path = priv->accel_path;
2335       if (!path && prefix)
2336         {
2337           const gchar *postfix = NULL;
2338           gchar *new_path;
2339
2340           /* try to construct one from label text */
2341           gtk_container_foreach (GTK_CONTAINER (menu_item),
2342                                  gtk_menu_item_accel_name_foreach,
2343                                  &postfix);
2344           if (postfix)
2345             {
2346               new_path = g_strconcat (prefix, "/", postfix, NULL);
2347               path = priv->accel_path = (char*)g_intern_string (new_path);
2348               g_free (new_path);
2349             }
2350         }
2351       if (path)
2352         gtk_widget_set_accel_path (widget, path, accel_group);
2353     }
2354   else if (group_changed)    /* reinstall accelerators */
2355     gtk_widget_set_accel_path (widget, path, accel_group);
2356 }
2357
2358 /**
2359  * gtk_menu_item_set_accel_path:
2360  * @menu_item:  a valid #GtkMenuItem
2361  * @accel_path: (allow-none): accelerator path, corresponding to this menu
2362  *     item's functionality, or %NULL to unset the current path.
2363  *
2364  * Set the accelerator path on @menu_item, through which runtime
2365  * changes of the menu item's accelerator caused by the user can be
2366  * identified and saved to persistent storage (see gtk_accel_map_save()
2367  * on this). To set up a default accelerator for this menu item, call
2368  * gtk_accel_map_add_entry() with the same @accel_path. See also
2369  * gtk_accel_map_add_entry() on the specifics of accelerator paths,
2370  * and gtk_menu_set_accel_path() for a more convenient variant of
2371  * this function.
2372  *
2373  * This function is basically a convenience wrapper that handles
2374  * calling gtk_widget_set_accel_path() with the appropriate accelerator
2375  * group for the menu item.
2376  *
2377  * Note that you do need to set an accelerator on the parent menu with
2378  * gtk_menu_set_accel_group() for this to work.
2379  *
2380  * Note that @accel_path string will be stored in a #GQuark.
2381  * Therefore, if you pass a static string, you can save some memory
2382  * by interning it first with g_intern_static_string().
2383  */
2384 void
2385 gtk_menu_item_set_accel_path (GtkMenuItem *menu_item,
2386                               const gchar *accel_path)
2387 {
2388   GtkMenuItemPrivate *priv = menu_item->priv;
2389   GtkWidget *parent;
2390   GtkWidget *widget;
2391
2392   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2393   g_return_if_fail (accel_path == NULL ||
2394                     (accel_path[0] == '<' && strchr (accel_path, '/')));
2395
2396   widget = GTK_WIDGET (menu_item);
2397
2398   /* store new path */
2399   priv->accel_path = (char*)g_intern_string (accel_path);
2400
2401   /* forget accelerators associated with old path */
2402   gtk_widget_set_accel_path (widget, NULL, NULL);
2403
2404   /* install accelerators associated with new path */
2405   parent = gtk_widget_get_parent (widget);
2406   if (GTK_IS_MENU (parent))
2407     {
2408       GtkMenu *menu = GTK_MENU (parent);
2409
2410       if (menu->priv->accel_group)
2411         _gtk_menu_item_refresh_accel_path (GTK_MENU_ITEM (widget),
2412                                            NULL,
2413                                            menu->priv->accel_group,
2414                                            FALSE);
2415     }
2416 }
2417
2418 /**
2419  * gtk_menu_item_get_accel_path:
2420  * @menu_item:  a valid #GtkMenuItem
2421  *
2422  * Retrieve the accelerator path that was previously set on @menu_item.
2423  *
2424  * See gtk_menu_item_set_accel_path() for details.
2425  *
2426  * Returns: the accelerator path corresponding to this menu
2427  *     item's functionality, or %NULL if not set
2428  *
2429  * Since: 2.14
2430  */
2431 const gchar *
2432 gtk_menu_item_get_accel_path (GtkMenuItem *menu_item)
2433 {
2434   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL);
2435
2436   return menu_item->priv->accel_path;
2437 }
2438
2439 static void
2440 gtk_menu_item_forall (GtkContainer *container,
2441                       gboolean      include_internals,
2442                       GtkCallback   callback,
2443                       gpointer      callback_data)
2444 {
2445   GtkWidget *child;
2446
2447   g_return_if_fail (GTK_IS_MENU_ITEM (container));
2448   g_return_if_fail (callback != NULL);
2449
2450   child = gtk_bin_get_child (GTK_BIN (container));
2451   if (child)
2452     callback (child, callback_data);
2453 }
2454
2455 gboolean
2456 _gtk_menu_item_is_selectable (GtkWidget *menu_item)
2457 {
2458   if ((!gtk_bin_get_child (GTK_BIN (menu_item)) &&
2459        G_OBJECT_TYPE (menu_item) == GTK_TYPE_MENU_ITEM) ||
2460       GTK_IS_SEPARATOR_MENU_ITEM (menu_item) ||
2461       !gtk_widget_is_sensitive (menu_item) ||
2462       !gtk_widget_get_visible (menu_item))
2463     return FALSE;
2464
2465   return TRUE;
2466 }
2467
2468 static void
2469 gtk_menu_item_ensure_label (GtkMenuItem *menu_item)
2470 {
2471   GtkWidget *accel_label;
2472
2473   if (!gtk_bin_get_child (GTK_BIN (menu_item)))
2474     {
2475       accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
2476       gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
2477
2478       gtk_container_add (GTK_CONTAINER (menu_item), accel_label);
2479       gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label),
2480                                         GTK_WIDGET (menu_item));
2481       gtk_widget_show (accel_label);
2482     }
2483 }
2484
2485 /**
2486  * gtk_menu_item_set_label:
2487  * @menu_item: a #GtkMenuItem
2488  * @label: the text you want to set
2489  *
2490  * Sets @text on the @menu_item label
2491  *
2492  * Since: 2.16
2493  */
2494 void
2495 gtk_menu_item_set_label (GtkMenuItem *menu_item,
2496                          const gchar *label)
2497 {
2498   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2499
2500   GTK_MENU_ITEM_GET_CLASS (menu_item)->set_label (menu_item, label);
2501 }
2502
2503 /**
2504  * gtk_menu_item_get_label:
2505  * @menu_item: a #GtkMenuItem
2506  *
2507  * Sets @text on the @menu_item label
2508  *
2509  * Returns: The text in the @menu_item label. This is the internal
2510  *   string used by the label, and must not be modified.
2511  *
2512  * Since: 2.16
2513  */
2514 const gchar *
2515 gtk_menu_item_get_label (GtkMenuItem *menu_item)
2516 {
2517   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL);
2518
2519   return GTK_MENU_ITEM_GET_CLASS (menu_item)->get_label (menu_item);
2520 }
2521
2522 /**
2523  * gtk_menu_item_set_use_underline:
2524  * @menu_item: a #GtkMenuItem
2525  * @setting: %TRUE if underlines in the text indicate mnemonics
2526  *
2527  * If true, an underline in the text indicates the next character
2528  * should be used for the mnemonic accelerator key.
2529  *
2530  * Since: 2.16
2531  */
2532 void
2533 gtk_menu_item_set_use_underline (GtkMenuItem *menu_item,
2534                                  gboolean     setting)
2535 {
2536   GtkWidget *child;
2537
2538   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2539
2540   gtk_menu_item_ensure_label (menu_item);
2541
2542   child = gtk_bin_get_child (GTK_BIN (menu_item));
2543   if (GTK_IS_LABEL (child))
2544     {
2545       gtk_label_set_use_underline (GTK_LABEL (child), setting);
2546
2547       g_object_notify (G_OBJECT (menu_item), "use-underline");
2548     }
2549 }
2550
2551 /**
2552  * gtk_menu_item_get_use_underline:
2553  * @menu_item: a #GtkMenuItem
2554  *
2555  * Checks if an underline in the text indicates the next character
2556  * should be used for the mnemonic accelerator key.
2557  *
2558  * Return value: %TRUE if an embedded underline in the label
2559  *     indicates the mnemonic accelerator key.
2560  *
2561  * Since: 2.16
2562  */
2563 gboolean
2564 gtk_menu_item_get_use_underline (GtkMenuItem *menu_item)
2565 {
2566   GtkWidget *child;
2567
2568   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), FALSE);
2569
2570   gtk_menu_item_ensure_label (menu_item);
2571
2572   child = gtk_bin_get_child (GTK_BIN (menu_item));
2573   if (GTK_IS_LABEL (child))
2574     return gtk_label_get_use_underline (GTK_LABEL (child));
2575
2576   return FALSE;
2577 }
2578
2579 /**
2580  * gtk_menu_item_set_reserve_indicator:
2581  * @menu_item: a #GtkMenuItem
2582  * @reserve: the new value
2583  *
2584  * Sets whether the @menu_item should reserve space for
2585  * the submenu indicator, regardless if it actually has
2586  * a submenu or not.
2587  *
2588  * There should be little need for applications to call
2589  * this functions.
2590  *
2591  * Since: 3.0
2592  */
2593 void
2594 gtk_menu_item_set_reserve_indicator (GtkMenuItem *menu_item,
2595                                      gboolean     reserve)
2596 {
2597   GtkMenuItemPrivate *priv;
2598
2599   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
2600
2601   priv = menu_item->priv;
2602
2603   if (priv->reserve_indicator != reserve)
2604     {
2605       priv->reserve_indicator = reserve;
2606       gtk_widget_queue_resize (GTK_WIDGET (menu_item));
2607     }
2608 }
2609
2610 /**
2611  * gtk_menu_item_get_reserve_indicator:
2612  * @menu_item: a #GtkMenuItem
2613  *
2614  * Returns whether the @menu_item reserves space for
2615  * the submenu indicator, regardless if it has a submenu
2616  * or not.
2617  *
2618  * Returns: %TRUE if @menu_item always reserves space for the
2619  *     submenu indicator
2620  *
2621  * Since: 3.0
2622  */
2623 gboolean
2624 gtk_menu_item_get_reserve_indicator (GtkMenuItem *menu_item)
2625 {
2626   g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), FALSE);
2627
2628   return menu_item->priv->reserve_indicator;
2629 }