1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #define GTK_MENU_INTERNALS
30 #include <string.h> /* memset */
31 #include "gdk/gdkkeysyms.h"
32 #include "gtkaccellabel.h"
33 #include "gtkaccelmap.h"
34 #include "gtkbindings.h"
37 #include "gtkmarshalers.h"
39 #include "gtkmenuitem.h"
40 #include "gtktearoffmenuitem.h"
41 #include "gtkwindow.h"
43 #include "gtkvscrollbar.h"
44 #include "gtksettings.h"
45 #include "gtkprivate.h"
50 #define MENU_ITEM_CLASS(w) GTK_MENU_ITEM_GET_CLASS (w)
52 #define DEFAULT_POPUP_DELAY 225
53 #define DEFAULT_POPDOWN_DELAY 1000
55 #define NAVIGATION_REGION_OVERSHOOT 50 /* How much the navigation region
56 * extends below the submenu
59 #define MENU_SCROLL_STEP1 8
60 #define MENU_SCROLL_STEP2 15
61 #define MENU_SCROLL_ARROW_HEIGHT 16
62 #define MENU_SCROLL_FAST_ZONE 8
63 #define MENU_SCROLL_TIMEOUT1 50
64 #define MENU_SCROLL_TIMEOUT2 20
66 #define ATTACH_INFO_KEY "gtk-menu-child-attach-info-key"
67 #define ATTACHED_MENUS "gtk-attached-menus"
69 typedef struct _GtkMenuAttachData GtkMenuAttachData;
70 typedef struct _GtkMenuPrivate GtkMenuPrivate;
72 struct _GtkMenuAttachData
74 GtkWidget *attach_widget;
75 GtkMenuDetachFunc detacher;
78 struct _GtkMenuPrivate
80 gboolean seen_item_enter;
82 gboolean have_position;
86 /* info used for the table */
92 /* Cached layout information */
104 gint effective_left_attach;
105 gint effective_right_attach;
106 gint effective_top_attach;
107 gint effective_bottom_attach;
123 CHILD_PROP_LEFT_ATTACH,
124 CHILD_PROP_RIGHT_ATTACH,
125 CHILD_PROP_TOP_ATTACH,
126 CHILD_PROP_BOTTOM_ATTACH
129 static void gtk_menu_class_init (GtkMenuClass *klass);
130 static void gtk_menu_init (GtkMenu *menu);
131 static void gtk_menu_set_property (GObject *object,
135 static void gtk_menu_get_property (GObject *object,
139 static void gtk_menu_set_child_property(GtkContainer *container,
144 static void gtk_menu_get_child_property(GtkContainer *container,
149 static void gtk_menu_destroy (GtkObject *object);
150 static void gtk_menu_finalize (GObject *object);
151 static void gtk_menu_realize (GtkWidget *widget);
152 static void gtk_menu_unrealize (GtkWidget *widget);
153 static void gtk_menu_size_request (GtkWidget *widget,
154 GtkRequisition *requisition);
155 static void gtk_menu_size_allocate (GtkWidget *widget,
156 GtkAllocation *allocation);
157 static void gtk_menu_paint (GtkWidget *widget,
158 GdkEventExpose *expose);
159 static void gtk_menu_show (GtkWidget *widget);
160 static gboolean gtk_menu_expose (GtkWidget *widget,
161 GdkEventExpose *event);
162 static gboolean gtk_menu_key_press (GtkWidget *widget,
164 static gboolean gtk_menu_scroll (GtkWidget *widget,
165 GdkEventScroll *event);
166 static gboolean gtk_menu_button_press (GtkWidget *widget,
167 GdkEventButton *event);
168 static gboolean gtk_menu_button_release (GtkWidget *widget,
169 GdkEventButton *event);
170 static gboolean gtk_menu_motion_notify (GtkWidget *widget,
171 GdkEventMotion *event);
172 static gboolean gtk_menu_enter_notify (GtkWidget *widget,
173 GdkEventCrossing *event);
174 static gboolean gtk_menu_leave_notify (GtkWidget *widget,
175 GdkEventCrossing *event);
176 static void gtk_menu_scroll_to (GtkMenu *menu,
179 static void gtk_menu_stop_scrolling (GtkMenu *menu);
180 static void gtk_menu_remove_scroll_timeout (GtkMenu *menu);
181 static gboolean gtk_menu_scroll_timeout (gpointer data);
183 static void gtk_menu_scroll_item_visible (GtkMenuShell *menu_shell,
184 GtkWidget *menu_item);
185 static void gtk_menu_select_item (GtkMenuShell *menu_shell,
186 GtkWidget *menu_item);
187 static void gtk_menu_real_insert (GtkMenuShell *menu_shell,
190 static void gtk_menu_scrollbar_changed (GtkAdjustment *adjustment,
192 static void gtk_menu_handle_scrolling (GtkMenu *menu,
196 static void gtk_menu_set_tearoff_hints (GtkMenu *menu,
198 static void gtk_menu_style_set (GtkWidget *widget,
199 GtkStyle *previous_style);
200 static gboolean gtk_menu_focus (GtkWidget *widget,
201 GtkDirectionType direction);
202 static gint gtk_menu_get_popup_delay (GtkMenuShell *menu_shell);
203 static void gtk_menu_move_current (GtkMenuShell *menu_shell,
204 GtkMenuDirectionType direction);
205 static void gtk_menu_real_move_scroll (GtkMenu *menu,
208 static void gtk_menu_stop_navigating_submenu (GtkMenu *menu);
209 static gboolean gtk_menu_stop_navigating_submenu_cb (gpointer user_data);
210 static gboolean gtk_menu_navigating_submenu (GtkMenu *menu,
213 static void gtk_menu_set_submenu_navigation_region (GtkMenu *menu,
214 GtkMenuItem *menu_item,
215 GdkEventCrossing *event);
217 static void gtk_menu_deactivate (GtkMenuShell *menu_shell);
218 static void gtk_menu_show_all (GtkWidget *widget);
219 static void gtk_menu_hide_all (GtkWidget *widget);
220 static void gtk_menu_position (GtkMenu *menu);
221 static void gtk_menu_reparent (GtkMenu *menu,
222 GtkWidget *new_parent,
224 static void gtk_menu_remove (GtkContainer *menu,
227 static void gtk_menu_update_title (GtkMenu *menu);
229 static void menu_grab_transfer_window_destroy (GtkMenu *menu);
230 static GdkWindow *menu_grab_transfer_window_get (GtkMenu *menu);
232 static gboolean gtk_menu_real_can_activate_accel (GtkWidget *widget,
234 static void _gtk_menu_refresh_accel_paths (GtkMenu *menu,
235 gboolean group_changed);
237 static GtkMenuShellClass *parent_class = NULL;
238 static const gchar attach_data_key[] = "gtk-menu-attach-data";
240 static guint menu_signals[LAST_SIGNAL] = { 0 };
243 gtk_menu_free_private (gpointer data)
245 GtkMenuPrivate *priv = (GtkMenuPrivate *)data;
247 g_free (priv->heights);
252 static GtkMenuPrivate *
253 gtk_menu_get_private (GtkMenu *menu)
255 GtkMenuPrivate *private;
256 static GQuark private_quark = 0;
259 private_quark = g_quark_from_static_string ("gtk-menu-private");
261 private = g_object_get_qdata (G_OBJECT (menu), private_quark);
265 private = g_new0 (GtkMenuPrivate, 1);
266 private->have_position = FALSE;
268 g_object_set_qdata_full (G_OBJECT (menu), private_quark,
269 private, gtk_menu_free_private);
276 gtk_menu_get_type (void)
278 static GType menu_type = 0;
282 static const GTypeInfo menu_info =
284 sizeof (GtkMenuClass),
285 NULL, /* base_init */
286 NULL, /* base_finalize */
287 (GClassInitFunc) gtk_menu_class_init,
288 NULL, /* class_finalize */
289 NULL, /* class_data */
292 (GInstanceInitFunc) gtk_menu_init,
295 menu_type = g_type_register_static (GTK_TYPE_MENU_SHELL, "GtkMenu",
303 menu_queue_resize (GtkMenu *menu)
305 GtkMenuPrivate *priv = gtk_menu_get_private (menu);
307 priv->have_layout = FALSE;
308 gtk_widget_queue_resize (GTK_WIDGET (menu));
312 get_attach_info (GtkWidget *child)
314 GObject *object = G_OBJECT (child);
315 AttachInfo *ai = g_object_get_data (object, ATTACH_INFO_KEY);
319 ai = g_new0 (AttachInfo, 1);
320 g_object_set_data_full (object, ATTACH_INFO_KEY, ai, g_free);
327 is_grid_attached (AttachInfo *ai)
329 return (ai->left_attach >= 0 &&
330 ai->right_attach >= 0 &&
331 ai->top_attach >= 0 &&
332 ai->bottom_attach >= 0);
336 menu_ensure_layout (GtkMenu *menu)
338 GtkMenuPrivate *priv = gtk_menu_get_private (menu);
340 if (!priv->have_layout)
342 GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
346 gint max_right_attach;
347 gint max_bottom_attach;
349 /* Find extents of gridded portion
351 max_right_attach = 1;
352 max_bottom_attach = 0;
354 for (l = menu_shell->children; l; l = l->next)
356 GtkWidget *child = l->data;
357 AttachInfo *ai = get_attach_info (child);
359 if (is_grid_attached (ai))
361 max_bottom_attach = MAX (max_bottom_attach, ai->bottom_attach);
362 max_right_attach = MAX (max_right_attach, ai->right_attach);
368 row_occupied = g_malloc0 (max_bottom_attach);
370 for (l = menu_shell->children; l; l = l->next)
372 GtkWidget *child = l->data;
373 AttachInfo *ai = get_attach_info (child);
375 if (is_grid_attached (ai))
379 for (i = ai->top_attach; i < ai->bottom_attach; i++)
380 row_occupied[i] = TRUE;
384 /* Lay non-grid-items out in those rows
387 for (l = menu_shell->children; l; l = l->next)
389 GtkWidget *child = l->data;
390 AttachInfo *ai = get_attach_info (child);
392 if (!is_grid_attached (ai))
394 while (current_row < max_bottom_attach && row_occupied[current_row])
397 ai->effective_left_attach = 0;
398 ai->effective_right_attach = max_right_attach;
399 ai->effective_top_attach = current_row;
400 ai->effective_bottom_attach = current_row + 1;
406 ai->effective_left_attach = ai->left_attach;
407 ai->effective_right_attach = ai->right_attach;
408 ai->effective_top_attach = ai->top_attach;
409 ai->effective_bottom_attach = ai->bottom_attach;
413 g_free (row_occupied);
415 priv->n_rows = MAX (current_row, max_bottom_attach);
416 priv->n_columns = max_right_attach;
417 priv->have_layout = TRUE;
423 gtk_menu_get_n_columns (GtkMenu *menu)
425 GtkMenuPrivate *priv = gtk_menu_get_private (menu);
427 menu_ensure_layout (menu);
429 return priv->n_columns;
433 gtk_menu_get_n_rows (GtkMenu *menu)
435 GtkMenuPrivate *priv = gtk_menu_get_private (menu);
437 menu_ensure_layout (menu);
443 get_effective_child_attach (GtkWidget *child,
449 GtkMenu *menu = GTK_MENU (child->parent);
452 menu_ensure_layout (menu);
454 ai = get_attach_info (child);
457 *l = ai->effective_left_attach;
459 *r = ai->effective_right_attach;
461 *t = ai->effective_top_attach;
463 *b = ai->effective_bottom_attach;
468 gtk_menu_class_init (GtkMenuClass *class)
470 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
471 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
472 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
473 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
474 GtkMenuShellClass *menu_shell_class = GTK_MENU_SHELL_CLASS (class);
475 GtkBindingSet *binding_set;
477 parent_class = g_type_class_peek_parent (class);
479 gobject_class->finalize = gtk_menu_finalize;
480 gobject_class->set_property = gtk_menu_set_property;
481 gobject_class->get_property = gtk_menu_get_property;
483 object_class->destroy = gtk_menu_destroy;
485 widget_class->realize = gtk_menu_realize;
486 widget_class->unrealize = gtk_menu_unrealize;
487 widget_class->size_request = gtk_menu_size_request;
488 widget_class->size_allocate = gtk_menu_size_allocate;
489 widget_class->show = gtk_menu_show;
490 widget_class->expose_event = gtk_menu_expose;
491 widget_class->scroll_event = gtk_menu_scroll;
492 widget_class->key_press_event = gtk_menu_key_press;
493 widget_class->button_press_event = gtk_menu_button_press;
494 widget_class->button_release_event = gtk_menu_button_release;
495 widget_class->motion_notify_event = gtk_menu_motion_notify;
496 widget_class->show_all = gtk_menu_show_all;
497 widget_class->hide_all = gtk_menu_hide_all;
498 widget_class->enter_notify_event = gtk_menu_enter_notify;
499 widget_class->leave_notify_event = gtk_menu_leave_notify;
500 widget_class->motion_notify_event = gtk_menu_motion_notify;
501 widget_class->style_set = gtk_menu_style_set;
502 widget_class->focus = gtk_menu_focus;
503 widget_class->can_activate_accel = gtk_menu_real_can_activate_accel;
505 container_class->remove = gtk_menu_remove;
506 container_class->get_child_property = gtk_menu_get_child_property;
507 container_class->set_child_property = gtk_menu_set_child_property;
509 menu_shell_class->submenu_placement = GTK_LEFT_RIGHT;
510 menu_shell_class->deactivate = gtk_menu_deactivate;
511 menu_shell_class->select_item = gtk_menu_select_item;
512 menu_shell_class->insert = gtk_menu_real_insert;
513 menu_shell_class->get_popup_delay = gtk_menu_get_popup_delay;
514 menu_shell_class->move_current = gtk_menu_move_current;
516 menu_signals[MOVE_SCROLL] =
517 _gtk_binding_signal_new ("move_scroll",
518 G_OBJECT_CLASS_TYPE (object_class),
519 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
520 G_CALLBACK (gtk_menu_real_move_scroll),
522 _gtk_marshal_VOID__ENUM,
524 GTK_TYPE_SCROLL_TYPE);
526 g_object_class_install_property (gobject_class,
528 g_param_spec_string ("tearoff-title",
530 P_("A title that may be displayed by the window manager when this menu is torn-off"),
532 GTK_PARAM_READWRITE));
535 * GtkMenu:tearoff-state:
537 * A boolean that indicates whether the menu is torn-off.
541 g_object_class_install_property (gobject_class,
543 g_param_spec_boolean ("tearoff-state",
545 P_("A boolean that indicates whether the menu is torn-off"),
547 GTK_PARAM_READWRITE));
549 gtk_widget_class_install_style_property (widget_class,
550 g_param_spec_int ("vertical-padding",
551 P_("Vertical Padding"),
552 P_("Extra space at the top and bottom of the menu"),
556 GTK_PARAM_READABLE));
558 gtk_widget_class_install_style_property (widget_class,
559 g_param_spec_int ("vertical-offset",
560 P_("Vertical Offset"),
561 P_("When the menu is a submenu, position it this number of pixels offset vertically"),
565 GTK_PARAM_READABLE));
567 gtk_widget_class_install_style_property (widget_class,
568 g_param_spec_int ("horizontal-offset",
569 P_("Horizontal Offset"),
570 P_("When the menu is a submenu, position it this number of pixels offset horizontally"),
574 GTK_PARAM_READABLE));
577 gtk_container_class_install_child_property (container_class,
578 CHILD_PROP_LEFT_ATTACH,
579 g_param_spec_int ("left-attach",
581 P_("The column number to attach the left side of the child to"),
583 GTK_PARAM_READWRITE));
585 gtk_container_class_install_child_property (container_class,
586 CHILD_PROP_RIGHT_ATTACH,
587 g_param_spec_int ("right-attach",
589 P_("The column number to attach the right side of the child to"),
591 GTK_PARAM_READWRITE));
593 gtk_container_class_install_child_property (container_class,
594 CHILD_PROP_TOP_ATTACH,
595 g_param_spec_int ("top-attach",
597 P_("The row number to attach the top of the child to"),
599 GTK_PARAM_READWRITE));
601 gtk_container_class_install_child_property (container_class,
602 CHILD_PROP_BOTTOM_ATTACH,
603 g_param_spec_int ("bottom-attach",
605 P_("The row number to attach the bottom of the child to"),
607 GTK_PARAM_READWRITE));
609 binding_set = gtk_binding_set_by_class (class);
610 gtk_binding_entry_add_signal (binding_set,
613 GTK_TYPE_MENU_DIRECTION_TYPE,
615 gtk_binding_entry_add_signal (binding_set,
618 GTK_TYPE_MENU_DIRECTION_TYPE,
620 gtk_binding_entry_add_signal (binding_set,
623 GTK_TYPE_MENU_DIRECTION_TYPE,
625 gtk_binding_entry_add_signal (binding_set,
628 GTK_TYPE_MENU_DIRECTION_TYPE,
630 gtk_binding_entry_add_signal (binding_set,
633 GTK_TYPE_MENU_DIRECTION_TYPE,
634 GTK_MENU_DIR_PARENT);
635 gtk_binding_entry_add_signal (binding_set,
638 GTK_TYPE_MENU_DIRECTION_TYPE,
639 GTK_MENU_DIR_PARENT);
640 gtk_binding_entry_add_signal (binding_set,
643 GTK_TYPE_MENU_DIRECTION_TYPE,
645 gtk_binding_entry_add_signal (binding_set,
648 GTK_TYPE_MENU_DIRECTION_TYPE,
650 gtk_binding_entry_add_signal (binding_set,
653 GTK_TYPE_SCROLL_TYPE,
655 gtk_binding_entry_add_signal (binding_set,
658 GTK_TYPE_SCROLL_TYPE,
660 gtk_binding_entry_add_signal (binding_set,
663 GTK_TYPE_SCROLL_TYPE,
665 gtk_binding_entry_add_signal (binding_set,
668 GTK_TYPE_SCROLL_TYPE,
670 gtk_binding_entry_add_signal (binding_set,
673 GTK_TYPE_SCROLL_TYPE,
675 gtk_binding_entry_add_signal (binding_set,
678 GTK_TYPE_SCROLL_TYPE,
680 gtk_binding_entry_add_signal (binding_set,
683 GTK_TYPE_SCROLL_TYPE,
684 GTK_SCROLL_PAGE_DOWN);
685 gtk_binding_entry_add_signal (binding_set,
688 GTK_TYPE_SCROLL_TYPE,
689 GTK_SCROLL_PAGE_DOWN);
691 gtk_settings_install_property (g_param_spec_boolean ("gtk-can-change-accels",
692 P_("Can change accelerators"),
693 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
695 GTK_PARAM_READWRITE));
697 gtk_settings_install_property (g_param_spec_int ("gtk-menu-popup-delay",
698 P_("Delay before submenus appear"),
699 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
703 GTK_PARAM_READWRITE));
705 gtk_settings_install_property (g_param_spec_int ("gtk-menu-popdown-delay",
706 P_("Delay before hiding a submenu"),
707 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
710 DEFAULT_POPDOWN_DELAY,
711 GTK_PARAM_READWRITE));
717 gtk_menu_set_property (GObject *object,
724 menu = GTK_MENU (object);
728 case PROP_TEAROFF_STATE:
729 gtk_menu_set_tearoff_state (menu, g_value_get_boolean (value));
731 case PROP_TEAROFF_TITLE:
732 gtk_menu_set_title (menu, g_value_get_string (value));
735 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
741 gtk_menu_get_property (GObject *object,
748 menu = GTK_MENU (object);
752 case PROP_TEAROFF_STATE:
753 g_value_set_boolean (value, gtk_menu_get_tearoff_state (menu));
755 case PROP_TEAROFF_TITLE:
756 g_value_set_string (value, gtk_menu_get_title (menu));
759 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
765 gtk_menu_set_child_property (GtkContainer *container,
771 GtkMenu *menu = GTK_MENU (container);
772 AttachInfo *ai = get_attach_info (child);
776 case CHILD_PROP_LEFT_ATTACH:
777 ai->left_attach = g_value_get_int (value);
779 case CHILD_PROP_RIGHT_ATTACH:
780 ai->right_attach = g_value_get_int (value);
782 case CHILD_PROP_TOP_ATTACH:
783 ai->top_attach = g_value_get_int (value);
785 case CHILD_PROP_BOTTOM_ATTACH:
786 ai->bottom_attach = g_value_get_int (value);
790 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
794 menu_queue_resize (menu);
798 gtk_menu_get_child_property (GtkContainer *container,
804 AttachInfo *ai = get_attach_info (child);
808 case CHILD_PROP_LEFT_ATTACH:
809 g_value_set_int (value, ai->left_attach);
811 case CHILD_PROP_RIGHT_ATTACH:
812 g_value_set_int (value, ai->right_attach);
814 case CHILD_PROP_TOP_ATTACH:
815 g_value_set_int (value, ai->top_attach);
817 case CHILD_PROP_BOTTOM_ATTACH:
818 g_value_set_int (value, ai->bottom_attach);
822 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
828 gtk_menu_window_event (GtkWidget *window,
832 gboolean handled = FALSE;
834 g_object_ref (window);
840 case GDK_KEY_RELEASE:
841 handled = gtk_widget_event (menu, event);
847 g_object_unref (window);
848 g_object_unref (menu);
854 gtk_menu_window_size_request (GtkWidget *window,
855 GtkRequisition *requisition,
858 GtkMenuPrivate *private = gtk_menu_get_private (menu);
860 if (private->have_position)
862 GdkScreen *screen = gtk_widget_get_screen (window);
863 GdkRectangle monitor;
865 gdk_screen_get_monitor_geometry (screen, private->monitor_num, &monitor);
867 if (private->y + requisition->height > monitor.y + monitor.height)
868 requisition->height = monitor.y + monitor.height - private->y;
870 if (private->y < monitor.y)
871 requisition->height -= monitor.y - private->y;
876 gtk_menu_init (GtkMenu *menu)
878 GtkMenuPrivate *priv = gtk_menu_get_private (menu);
880 menu->parent_menu_item = NULL;
881 menu->old_active_menu_item = NULL;
882 menu->accel_group = NULL;
883 menu->position_func = NULL;
884 menu->position_func_data = NULL;
885 menu->toggle_size = 0;
887 menu->toplevel = g_object_connect (g_object_new (GTK_TYPE_WINDOW,
888 "type", GTK_WINDOW_POPUP,
891 "signal::event", gtk_menu_window_event, menu,
892 "signal::size_request", gtk_menu_window_size_request, menu,
893 "signal::destroy", gtk_widget_destroyed, &menu->toplevel,
895 gtk_window_set_resizable (GTK_WINDOW (menu->toplevel), FALSE);
896 gtk_window_set_mnemonic_modifier (GTK_WINDOW (menu->toplevel), 0);
898 /* Refloat the menu, so that reference counting for the menu isn't
899 * affected by it being a child of the toplevel
901 GTK_WIDGET_SET_FLAGS (menu, GTK_FLOATING);
902 menu->needs_destruction_ref_count = TRUE;
904 menu->view_window = NULL;
905 menu->bin_window = NULL;
907 menu->scroll_offset = 0;
908 menu->scroll_step = 0;
909 menu->timeout_id = 0;
910 menu->scroll_fast = FALSE;
912 menu->tearoff_window = NULL;
913 menu->tearoff_hbox = NULL;
914 menu->torn_off = FALSE;
915 menu->tearoff_active = FALSE;
916 menu->tearoff_adjustment = NULL;
917 menu->tearoff_scrollbar = NULL;
919 menu->upper_arrow_visible = FALSE;
920 menu->lower_arrow_visible = FALSE;
921 menu->upper_arrow_prelight = FALSE;
922 menu->lower_arrow_prelight = FALSE;
924 priv->have_layout = FALSE;
928 gtk_menu_destroy (GtkObject *object)
931 GtkMenuAttachData *data;
932 GtkMenuPrivate *priv;
934 g_return_if_fail (GTK_IS_MENU (object));
936 menu = GTK_MENU (object);
938 gtk_menu_stop_scrolling (menu);
940 data = g_object_get_data (G_OBJECT (object), attach_data_key);
942 gtk_menu_detach (menu);
944 gtk_menu_stop_navigating_submenu (menu);
946 if (menu->old_active_menu_item)
948 g_object_unref (menu->old_active_menu_item);
949 menu->old_active_menu_item = NULL;
952 /* Add back the reference count for being a child */
953 if (menu->needs_destruction_ref_count)
955 menu->needs_destruction_ref_count = FALSE;
956 g_object_ref (object);
959 if (menu->accel_group)
961 g_object_unref (menu->accel_group);
962 menu->accel_group = NULL;
966 gtk_widget_destroy (menu->toplevel);
967 if (menu->tearoff_window)
968 gtk_widget_destroy (menu->tearoff_window);
970 priv = gtk_menu_get_private (menu);
972 GTK_OBJECT_CLASS (parent_class)->destroy (object);
976 gtk_menu_finalize (GObject *object)
978 GtkMenu *menu = GTK_MENU (object);
980 g_free (menu->accel_path);
982 G_OBJECT_CLASS (parent_class)->finalize (object);
986 menu_change_screen (GtkMenu *menu,
987 GdkScreen *new_screen)
989 GtkMenuPrivate *private = gtk_menu_get_private (menu);
991 if (gtk_widget_has_screen (GTK_WIDGET (menu)))
993 if (new_screen == gtk_widget_get_screen (GTK_WIDGET (menu)))
999 gtk_window_set_screen (GTK_WINDOW (menu->tearoff_window), new_screen);
1000 gtk_menu_position (menu);
1003 gtk_window_set_screen (GTK_WINDOW (menu->toplevel), new_screen);
1004 private->monitor_num = -1;
1008 attach_widget_screen_changed (GtkWidget *attach_widget,
1009 GdkScreen *previous_screen,
1012 if (gtk_widget_has_screen (attach_widget) &&
1013 !g_object_get_data (G_OBJECT (menu), "gtk-menu-explicit-screen"))
1015 menu_change_screen (menu, gtk_widget_get_screen (attach_widget));
1020 gtk_menu_attach_to_widget (GtkMenu *menu,
1021 GtkWidget *attach_widget,
1022 GtkMenuDetachFunc detacher)
1024 GtkMenuAttachData *data;
1027 g_return_if_fail (GTK_IS_MENU (menu));
1028 g_return_if_fail (GTK_IS_WIDGET (attach_widget));
1029 g_return_if_fail (detacher != NULL);
1031 /* keep this function in sync with gtk_widget_set_parent()
1034 data = g_object_get_data (G_OBJECT (menu), attach_data_key);
1037 g_warning ("gtk_menu_attach_to_widget(): menu already attached to %s",
1038 g_type_name (G_TYPE_FROM_INSTANCE (data->attach_widget)));
1042 g_object_ref (menu);
1043 gtk_object_sink (GTK_OBJECT (menu));
1045 data = g_new (GtkMenuAttachData, 1);
1046 data->attach_widget = attach_widget;
1048 g_signal_connect (attach_widget, "screen_changed",
1049 G_CALLBACK (attach_widget_screen_changed), menu);
1050 attach_widget_screen_changed (attach_widget, NULL, menu);
1052 data->detacher = detacher;
1053 g_object_set_data (G_OBJECT (menu), attach_data_key, data);
1054 list = g_object_steal_data (G_OBJECT (attach_widget), ATTACHED_MENUS);
1055 if (!g_list_find (list, menu))
1057 list = g_list_prepend (list, menu);
1059 g_object_set_data_full (G_OBJECT (attach_widget), ATTACHED_MENUS, list, (GtkDestroyNotify) g_list_free);
1061 if (GTK_WIDGET_STATE (menu) != GTK_STATE_NORMAL)
1062 gtk_widget_set_state (GTK_WIDGET (menu), GTK_STATE_NORMAL);
1064 /* we don't need to set the style here, since
1065 * we are a toplevel widget.
1068 /* Fallback title for menu comes from attach widget */
1069 gtk_menu_update_title (menu);
1073 gtk_menu_get_attach_widget (GtkMenu *menu)
1075 GtkMenuAttachData *data;
1077 g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
1079 data = g_object_get_data (G_OBJECT (menu), attach_data_key);
1081 return data->attach_widget;
1086 gtk_menu_detach (GtkMenu *menu)
1088 GtkMenuAttachData *data;
1091 g_return_if_fail (GTK_IS_MENU (menu));
1093 /* keep this function in sync with gtk_widget_unparent()
1095 data = g_object_get_data (G_OBJECT (menu), attach_data_key);
1098 g_warning ("gtk_menu_detach(): menu is not attached");
1101 g_object_set_data (G_OBJECT (menu), attach_data_key, NULL);
1103 g_signal_handlers_disconnect_by_func (data->attach_widget,
1104 (gpointer) attach_widget_screen_changed,
1107 data->detacher (data->attach_widget, menu);
1108 list = g_object_steal_data (G_OBJECT (data->attach_widget), ATTACHED_MENUS);
1109 list = g_list_remove (list, menu);
1111 g_object_set_data_full (G_OBJECT (data->attach_widget), ATTACHED_MENUS, list, (GtkDestroyNotify) g_list_free);
1113 g_object_set_data (G_OBJECT (data->attach_widget), ATTACHED_MENUS, NULL);
1115 if (GTK_WIDGET_REALIZED (menu))
1116 gtk_widget_unrealize (GTK_WIDGET (menu));
1120 /* Fallback title for menu comes from attach widget */
1121 gtk_menu_update_title (menu);
1123 g_object_unref (menu);
1127 gtk_menu_remove (GtkContainer *container,
1131 GtkMenuPrivate *priv;
1133 g_return_if_fail (GTK_IS_MENU (container));
1134 g_return_if_fail (GTK_IS_MENU_ITEM (widget));
1136 menu = GTK_MENU (container);
1137 priv = gtk_menu_get_private (menu);
1139 /* Clear out old_active_menu_item if it matches the item we are removing
1141 if (menu->old_active_menu_item == widget)
1143 g_object_unref (menu->old_active_menu_item);
1144 menu->old_active_menu_item = NULL;
1147 GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
1148 g_object_set_data (G_OBJECT (widget), ATTACH_INFO_KEY, NULL);
1150 menu_queue_resize (menu);
1156 return g_object_new (GTK_TYPE_MENU, NULL);
1160 gtk_menu_real_insert (GtkMenuShell *menu_shell,
1164 GtkMenu *menu = GTK_MENU (menu_shell);
1165 AttachInfo *ai = get_attach_info (child);
1167 ai->left_attach = -1;
1168 ai->right_attach = -1;
1169 ai->top_attach = -1;
1170 ai->bottom_attach = -1;
1172 if (GTK_WIDGET_REALIZED (menu_shell))
1173 gtk_widget_set_parent_window (child, menu->bin_window);
1175 GTK_MENU_SHELL_CLASS (parent_class)->insert (menu_shell, child, position);
1177 menu_queue_resize (menu);
1181 gtk_menu_tearoff_bg_copy (GtkMenu *menu)
1186 widget = GTK_WIDGET (menu);
1192 GdkGCValues gc_values;
1194 menu->tearoff_active = FALSE;
1195 menu->saved_scroll_offset = menu->scroll_offset;
1197 gc_values.subwindow_mode = GDK_INCLUDE_INFERIORS;
1198 gc = gdk_gc_new_with_values (widget->window,
1199 &gc_values, GDK_GC_SUBWINDOW);
1201 gdk_drawable_get_size (menu->tearoff_window->window, &width, &height);
1203 pixmap = gdk_pixmap_new (menu->tearoff_window->window,
1208 gdk_draw_drawable (pixmap, gc,
1209 menu->tearoff_window->window,
1210 0, 0, 0, 0, -1, -1);
1211 g_object_unref (gc);
1213 gtk_widget_set_size_request (menu->tearoff_window,
1217 gdk_window_set_back_pixmap (menu->tearoff_window->window, pixmap, FALSE);
1218 g_object_unref (pixmap);
1223 popup_grab_on_window (GdkWindow *window,
1224 guint32 activate_time)
1226 if ((gdk_pointer_grab (window, TRUE,
1227 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1228 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1229 GDK_POINTER_MOTION_MASK,
1230 NULL, NULL, activate_time) == 0))
1232 if (gdk_keyboard_grab (window, TRUE,
1233 activate_time) == 0)
1237 gdk_display_pointer_ungrab (gdk_drawable_get_display (window),
1248 * @menu: a #GtkMenu.
1249 * @parent_menu_shell: the menu shell containing the triggering menu item, or %NULL
1250 * @parent_menu_item: the menu item whose activation triggered the popup, or %NULL
1251 * @func: a user supplied function used to position the menu, or %NULL
1252 * @data: user supplied data to be passed to @func.
1253 * @button: the mouse button which was pressed to initiate the event.
1254 * @activate_time: the time at which the activation event occurred.
1256 * Displays a menu and makes it available for selection. Applications can use
1257 * this function to display context-sensitive menus, and will typically supply
1258 * %NULL for the @parent_menu_shell, @parent_menu_item, @func and @data
1259 * parameters. The default menu positioning function will position the menu
1260 * at the current mouse cursor position.
1262 * The @button parameter should be the mouse button pressed to initiate
1263 * the menu popup. If the menu popup was initiated by something other than
1264 * a mouse button press, such as a mouse button release or a keypress,
1265 * @button should be 0.
1267 * The @activate_time parameter should be the time stamp of the event that
1268 * initiated the popup. If such an event is not available, use
1269 * gtk_get_current_event_time() instead.
1273 gtk_menu_popup (GtkMenu *menu,
1274 GtkWidget *parent_menu_shell,
1275 GtkWidget *parent_menu_item,
1276 GtkMenuPositionFunc func,
1279 guint32 activate_time)
1282 GtkWidget *xgrab_shell;
1284 GdkEvent *current_event;
1285 GtkMenuShell *menu_shell;
1286 GtkMenuPrivate *priv = gtk_menu_get_private (menu);
1288 g_return_if_fail (GTK_IS_MENU (menu));
1290 widget = GTK_WIDGET (menu);
1291 menu_shell = GTK_MENU_SHELL (menu);
1293 menu_shell->parent_menu_shell = parent_menu_shell;
1295 priv->seen_item_enter = FALSE;
1297 /* Find the last viewable ancestor, and make an X grab on it
1299 parent = GTK_WIDGET (menu);
1303 gboolean viewable = TRUE;
1304 GtkWidget *tmp = parent;
1308 if (!GTK_WIDGET_MAPPED (tmp))
1317 xgrab_shell = parent;
1319 parent = GTK_MENU_SHELL (parent)->parent_menu_shell;
1322 /* We want to receive events generated when we map the menu; unfortunately,
1323 * since there is probably already an implicit grab in place from the
1324 * button that the user used to pop up the menu, we won't receive then --
1325 * in particular, the EnterNotify when the menu pops up under the pointer.
1327 * If we are grabbing on a parent menu shell, no problem; just grab on
1328 * that menu shell first before popping up the window with owner_events = TRUE.
1330 * When grabbing on the menu itself, things get more convuluted - we
1331 * we do an explicit grab on a specially created window with
1332 * owner_events = TRUE, which we override further down with a grab
1333 * on the menu. (We can't grab on the menu until it is mapped; we
1334 * probably could just leave the grab on the other window, with a
1335 * little reorganization of the code in gtkmenu*).
1337 if (xgrab_shell && xgrab_shell != widget)
1339 if (popup_grab_on_window (xgrab_shell->window, activate_time))
1340 GTK_MENU_SHELL (xgrab_shell)->have_xgrab = TRUE;
1344 GdkWindow *transfer_window;
1346 xgrab_shell = widget;
1347 transfer_window = menu_grab_transfer_window_get (menu);
1348 if (popup_grab_on_window (transfer_window, activate_time))
1349 GTK_MENU_SHELL (xgrab_shell)->have_xgrab = TRUE;
1352 if (!GTK_MENU_SHELL (xgrab_shell)->have_xgrab)
1354 /* We failed to make our pointer/keyboard grab. Rather than leaving the user
1355 * with a stuck up window, we just abort here. Presumably the user will
1358 menu_shell->parent_menu_shell = NULL;
1359 menu_grab_transfer_window_destroy (menu);
1363 menu_shell->active = TRUE;
1364 menu_shell->button = button;
1366 /* If we are popping up the menu from something other than, a button
1367 * press then, as a heuristic, we ignore enter events for the menu
1368 * until we get a MOTION_NOTIFY.
1371 current_event = gtk_get_current_event ();
1374 if ((current_event->type != GDK_BUTTON_PRESS) &&
1375 (current_event->type != GDK_ENTER_NOTIFY))
1376 menu_shell->ignore_enter = TRUE;
1378 gdk_event_free (current_event);
1381 menu_shell->ignore_enter = TRUE;
1385 gtk_menu_tearoff_bg_copy (menu);
1387 gtk_menu_reparent (menu, menu->toplevel, FALSE);
1390 if (parent_menu_shell)
1392 GtkWidget *toplevel;
1394 toplevel = gtk_widget_get_toplevel (parent_menu_shell);
1395 if (GTK_IS_WINDOW (toplevel))
1396 gtk_window_group_add_window (_gtk_window_get_group (GTK_WINDOW (toplevel)),
1397 GTK_WINDOW (menu->toplevel));
1400 menu->parent_menu_item = parent_menu_item;
1401 menu->position_func = func;
1402 menu->position_func_data = data;
1403 menu_shell->activate_time = activate_time;
1405 /* We need to show the menu here rather in the init function because
1406 * code expects to be able to tell if the menu is onscreen by
1407 * looking at the GTK_WIDGET_VISIBLE (menu)
1409 gtk_widget_show (GTK_WIDGET (menu));
1411 /* Position the menu, possibly changing the size request
1413 gtk_menu_position (menu);
1415 /* Compute the size of the toplevel and realize it so we
1416 * can scroll correctly.
1419 GtkRequisition tmp_request;
1420 GtkAllocation tmp_allocation = { 0, };
1422 gtk_widget_size_request (menu->toplevel, &tmp_request);
1424 tmp_allocation.width = tmp_request.width;
1425 tmp_allocation.height = tmp_request.height;
1427 gtk_widget_size_allocate (menu->toplevel, &tmp_allocation);
1429 gtk_widget_realize (GTK_WIDGET (menu));
1432 gtk_menu_scroll_to (menu, menu->scroll_offset);
1434 /* Once everything is set up correctly, map the toplevel window on
1437 gtk_widget_show (menu->toplevel);
1439 if (xgrab_shell == widget)
1440 popup_grab_on_window (widget->window, activate_time); /* Should always succeed */
1441 gtk_grab_add (GTK_WIDGET (menu));
1445 gtk_menu_popdown (GtkMenu *menu)
1447 GtkMenuPrivate *private;
1448 GtkMenuShell *menu_shell;
1450 g_return_if_fail (GTK_IS_MENU (menu));
1452 menu_shell = GTK_MENU_SHELL (menu);
1453 private = gtk_menu_get_private (menu);
1455 menu_shell->parent_menu_shell = NULL;
1456 menu_shell->active = FALSE;
1457 menu_shell->ignore_enter = FALSE;
1459 private->have_position = FALSE;
1461 gtk_menu_stop_scrolling (menu);
1463 gtk_menu_stop_navigating_submenu (menu);
1465 if (menu_shell->active_menu_item)
1467 if (menu->old_active_menu_item)
1468 g_object_unref (menu->old_active_menu_item);
1469 menu->old_active_menu_item = menu_shell->active_menu_item;
1470 g_object_ref (menu->old_active_menu_item);
1473 gtk_menu_shell_deselect (menu_shell);
1475 /* The X Grab, if present, will automatically be removed when we hide
1477 gtk_widget_hide (menu->toplevel);
1478 gtk_window_group_add_window (_gtk_window_get_group (NULL), GTK_WINDOW (menu->toplevel));
1482 gtk_widget_set_size_request (menu->tearoff_window, -1, -1);
1484 if (GTK_BIN (menu->toplevel)->child)
1486 gtk_menu_reparent (menu, menu->tearoff_hbox, TRUE);
1490 /* We popped up the menu from the tearoff, so we need to
1491 * release the grab - we aren't actually hiding the menu.
1493 if (menu_shell->have_xgrab)
1495 GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (menu));
1497 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
1498 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
1502 /* gtk_menu_popdown is called each time a menu item is selected from
1503 * a torn off menu. Only scroll back to the saved position if the
1504 * non-tearoff menu was popped down.
1506 if (!menu->tearoff_active)
1507 gtk_menu_scroll_to (menu, menu->saved_scroll_offset);
1508 menu->tearoff_active = TRUE;
1511 gtk_widget_hide (GTK_WIDGET (menu));
1513 menu_shell->have_xgrab = FALSE;
1514 gtk_grab_remove (GTK_WIDGET (menu));
1516 menu_grab_transfer_window_destroy (menu);
1520 gtk_menu_get_active (GtkMenu *menu)
1525 g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
1527 if (!menu->old_active_menu_item)
1530 children = GTK_MENU_SHELL (menu)->children;
1534 child = children->data;
1535 children = children->next;
1537 if (GTK_BIN (child)->child)
1542 menu->old_active_menu_item = child;
1543 if (menu->old_active_menu_item)
1544 g_object_ref (menu->old_active_menu_item);
1547 return menu->old_active_menu_item;
1551 gtk_menu_set_active (GtkMenu *menu,
1557 g_return_if_fail (GTK_IS_MENU (menu));
1559 tmp_list = g_list_nth (GTK_MENU_SHELL (menu)->children, index);
1562 child = tmp_list->data;
1563 if (GTK_BIN (child)->child)
1565 if (menu->old_active_menu_item)
1566 g_object_unref (menu->old_active_menu_item);
1567 menu->old_active_menu_item = child;
1568 g_object_ref (menu->old_active_menu_item);
1574 gtk_menu_set_accel_group (GtkMenu *menu,
1575 GtkAccelGroup *accel_group)
1577 g_return_if_fail (GTK_IS_MENU (menu));
1579 if (menu->accel_group != accel_group)
1581 if (menu->accel_group)
1582 g_object_unref (menu->accel_group);
1583 menu->accel_group = accel_group;
1584 if (menu->accel_group)
1585 g_object_ref (menu->accel_group);
1586 _gtk_menu_refresh_accel_paths (menu, TRUE);
1591 gtk_menu_get_accel_group (GtkMenu *menu)
1593 g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
1595 return menu->accel_group;
1599 gtk_menu_real_can_activate_accel (GtkWidget *widget,
1602 /* Menu items chain here to figure whether they can activate their
1603 * accelerators. Unlike ordinary widgets, menus allow accel
1604 * activation even if invisible since that's the usual case for
1605 * submenus/popup-menus. however, the state of the attach widget
1606 * affects the "activeness" of the menu.
1608 GtkWidget *awidget = gtk_menu_get_attach_widget (GTK_MENU (widget));
1611 return gtk_widget_can_activate_accel (awidget, signal_id);
1613 return GTK_WIDGET_IS_SENSITIVE (widget);
1617 * gtk_menu_set_accel_path
1618 * @menu: a valid #GtkMenu
1619 * @accel_path: a valid accelerator path
1621 * Sets an accelerator path for this menu from which accelerator paths
1622 * for its immediate children, its menu items, can be constructed.
1623 * The main purpose of this function is to spare the programmer the
1624 * inconvenience of having to call gtk_menu_item_set_accel_path() on
1625 * each menu item that should support runtime user changable accelerators.
1626 * Instead, by just calling gtk_menu_set_accel_path() on their parent,
1627 * each menu item of this menu, that contains a label describing its purpose,
1628 * automatically gets an accel path assigned. For example, a menu containing
1629 * menu items "New" and "Exit", will, after
1630 * <literal>gtk_menu_set_accel_path (menu, "<Gnumeric-Sheet>/File");</literal>
1631 * has been called, assign its items the accel paths:
1632 * <literal>"<Gnumeric-Sheet>/File/New"</literal> and <literal>"<Gnumeric-Sheet>/File/Exit"</literal>.
1633 * Assigning accel paths to menu items then enables the user to change
1634 * their accelerators at runtime. More details about accelerator paths
1635 * and their default setups can be found at gtk_accel_map_add_entry().
1638 gtk_menu_set_accel_path (GtkMenu *menu,
1639 const gchar *accel_path)
1641 g_return_if_fail (GTK_IS_MENU (menu));
1643 g_return_if_fail (accel_path[0] == '<' && strchr (accel_path, '/')); /* simplistic check */
1645 g_free (menu->accel_path);
1646 menu->accel_path = g_strdup (accel_path);
1647 if (menu->accel_path)
1648 _gtk_menu_refresh_accel_paths (menu, FALSE);
1653 gboolean group_changed;
1657 refresh_accel_paths_foreach (GtkWidget *widget,
1660 AccelPropagation *prop = data;
1662 if (GTK_IS_MENU_ITEM (widget)) /* should always be true */
1663 _gtk_menu_item_refresh_accel_path (GTK_MENU_ITEM (widget),
1664 prop->menu->accel_path,
1665 prop->menu->accel_group,
1666 prop->group_changed);
1670 _gtk_menu_refresh_accel_paths (GtkMenu *menu,
1671 gboolean group_changed)
1673 g_return_if_fail (GTK_IS_MENU (menu));
1675 if (menu->accel_path && menu->accel_group)
1677 AccelPropagation prop;
1680 prop.group_changed = group_changed;
1681 gtk_container_foreach (GTK_CONTAINER (menu),
1682 refresh_accel_paths_foreach,
1688 gtk_menu_reposition (GtkMenu *menu)
1690 g_return_if_fail (GTK_IS_MENU (menu));
1692 if (GTK_WIDGET_DRAWABLE (menu) && !menu->torn_off)
1693 gtk_menu_position (menu);
1697 gtk_menu_scrollbar_changed (GtkAdjustment *adjustment,
1700 g_return_if_fail (GTK_IS_MENU (menu));
1702 if (adjustment->value != menu->scroll_offset)
1703 gtk_menu_scroll_to (menu, adjustment->value);
1707 gtk_menu_set_tearoff_hints (GtkMenu *menu,
1710 GdkGeometry geometry_hints;
1712 if (!menu->tearoff_window)
1715 if (GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
1717 gtk_widget_size_request (menu->tearoff_scrollbar, NULL);
1718 width += menu->tearoff_scrollbar->requisition.width;
1721 geometry_hints.min_width = width;
1722 geometry_hints.max_width = width;
1724 geometry_hints.min_height = 0;
1725 geometry_hints.max_height = GTK_WIDGET (menu)->requisition.height;
1727 gtk_window_set_geometry_hints (GTK_WINDOW (menu->tearoff_window),
1730 GDK_HINT_MAX_SIZE|GDK_HINT_MIN_SIZE);
1734 gtk_menu_update_title (GtkMenu *menu)
1736 if (menu->tearoff_window)
1739 GtkWidget *attach_widget;
1741 title = gtk_menu_get_title (menu);
1744 attach_widget = gtk_menu_get_attach_widget (menu);
1745 if (GTK_IS_MENU_ITEM (attach_widget))
1747 GtkWidget *child = GTK_BIN (attach_widget)->child;
1748 if (GTK_IS_LABEL (child))
1749 title = gtk_label_get_text (GTK_LABEL (child));
1754 gtk_window_set_title (GTK_WINDOW (menu->tearoff_window), title);
1759 gtk_menu_get_toplevel (GtkWidget *menu)
1761 GtkWidget *attach, *toplevel;
1763 attach = gtk_menu_get_attach_widget (GTK_MENU (menu));
1765 if (GTK_IS_MENU_ITEM (attach))
1766 attach = attach->parent;
1768 if (GTK_IS_MENU (attach))
1769 return gtk_menu_get_toplevel (attach);
1770 else if (GTK_IS_WIDGET (attach))
1772 toplevel = gtk_widget_get_toplevel (attach);
1773 if (GTK_WIDGET_TOPLEVEL (toplevel))
1781 tearoff_window_destroyed (GtkWidget *widget,
1784 gtk_menu_set_tearoff_state (menu, FALSE);
1788 gtk_menu_set_tearoff_state (GtkMenu *menu,
1793 g_return_if_fail (GTK_IS_MENU (menu));
1795 if (menu->torn_off != torn_off)
1797 menu->torn_off = torn_off;
1798 menu->tearoff_active = torn_off;
1802 if (GTK_WIDGET_VISIBLE (menu))
1803 gtk_menu_popdown (menu);
1805 if (!menu->tearoff_window)
1807 GtkWidget *toplevel;
1809 menu->tearoff_window = gtk_widget_new (GTK_TYPE_WINDOW,
1810 "type", GTK_WINDOW_TOPLEVEL,
1811 "screen", gtk_widget_get_screen (menu->toplevel),
1812 "app_paintable", TRUE,
1816 gtk_window_set_type_hint (GTK_WINDOW (menu->tearoff_window),
1817 GDK_WINDOW_TYPE_HINT_MENU);
1818 gtk_window_set_mnemonic_modifier (GTK_WINDOW (menu->tearoff_window), 0);
1819 g_signal_connect (menu->tearoff_window, "destroy",
1820 G_CALLBACK (tearoff_window_destroyed), menu);
1821 g_signal_connect (menu->tearoff_window, "event",
1822 G_CALLBACK (gtk_menu_window_event), menu);
1824 gtk_menu_update_title (menu);
1826 gtk_widget_realize (menu->tearoff_window);
1828 toplevel = gtk_menu_get_toplevel (GTK_WIDGET (menu));
1829 if (toplevel != NULL)
1830 gtk_window_set_transient_for (GTK_WINDOW (menu->tearoff_window),
1831 GTK_WINDOW (toplevel));
1833 menu->tearoff_hbox = gtk_hbox_new (FALSE, FALSE);
1834 gtk_container_add (GTK_CONTAINER (menu->tearoff_window), menu->tearoff_hbox);
1836 gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
1837 menu->tearoff_adjustment =
1838 GTK_ADJUSTMENT (gtk_adjustment_new (0,
1840 GTK_WIDGET (menu)->requisition.height,
1844 g_object_connect (menu->tearoff_adjustment,
1845 "signal::value_changed", gtk_menu_scrollbar_changed, menu,
1847 menu->tearoff_scrollbar = gtk_vscrollbar_new (menu->tearoff_adjustment);
1849 gtk_box_pack_end (GTK_BOX (menu->tearoff_hbox),
1850 menu->tearoff_scrollbar,
1853 if (menu->tearoff_adjustment->upper > height)
1854 gtk_widget_show (menu->tearoff_scrollbar);
1856 gtk_widget_show (menu->tearoff_hbox);
1859 gtk_menu_reparent (menu, menu->tearoff_hbox, FALSE);
1861 gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, NULL);
1863 /* Update menu->requisition
1865 gtk_widget_size_request (GTK_WIDGET (menu), NULL);
1867 gtk_menu_set_tearoff_hints (menu, width);
1869 gtk_widget_realize (menu->tearoff_window);
1870 gtk_menu_position (menu);
1872 gtk_widget_show (GTK_WIDGET (menu));
1873 gtk_widget_show (menu->tearoff_window);
1875 gtk_menu_scroll_to (menu, 0);
1880 gtk_widget_hide (GTK_WIDGET (menu));
1881 gtk_widget_hide (menu->tearoff_window);
1882 if (GTK_IS_CONTAINER (menu->toplevel))
1883 gtk_menu_reparent (menu, menu->toplevel, FALSE);
1884 gtk_widget_destroy (menu->tearoff_window);
1886 menu->tearoff_window = NULL;
1887 menu->tearoff_hbox = NULL;
1888 menu->tearoff_scrollbar = NULL;
1889 menu->tearoff_adjustment = NULL;
1892 g_object_notify (G_OBJECT (menu), "tearoff_state");
1897 * gtk_menu_get_tearoff_state:
1900 * Returns whether the menu is torn off. See
1901 * gtk_menu_set_tearoff_state ().
1903 * Return value: %TRUE if the menu is currently torn off.
1906 gtk_menu_get_tearoff_state (GtkMenu *menu)
1908 g_return_val_if_fail (GTK_IS_MENU (menu), FALSE);
1910 return menu->torn_off;
1914 * gtk_menu_set_title:
1916 * @title: a string containing the title for the menu.
1918 * Sets the title string for the menu. The title is displayed when the menu
1919 * is shown as a tearoff menu.
1922 gtk_menu_set_title (GtkMenu *menu,
1925 g_return_if_fail (GTK_IS_MENU (menu));
1928 g_object_set_data_full (G_OBJECT (menu), "gtk-menu-title",
1929 g_strdup (title), (GtkDestroyNotify) g_free);
1931 g_object_set_data (G_OBJECT (menu), "gtk-menu-title", NULL);
1933 gtk_menu_update_title (menu);
1934 g_object_notify (G_OBJECT (menu), "tearoff_title");
1938 * gtk_menu_get_title:
1941 * Returns the title of the menu. See gtk_menu_set_title().
1943 * Return value: the title of the menu, or %NULL if the menu has no
1944 * title set on it. This string is owned by the widget and should
1945 * not be modified or freed.
1947 G_CONST_RETURN gchar *
1948 gtk_menu_get_title (GtkMenu *menu)
1950 g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
1952 return g_object_get_data (G_OBJECT (menu), "gtk-menu-title");
1956 gtk_menu_reorder_child (GtkMenu *menu,
1960 GtkMenuShell *menu_shell;
1962 g_return_if_fail (GTK_IS_MENU (menu));
1963 g_return_if_fail (GTK_IS_MENU_ITEM (child));
1965 menu_shell = GTK_MENU_SHELL (menu);
1967 if (g_list_find (menu_shell->children, child))
1969 menu_shell->children = g_list_remove (menu_shell->children, child);
1970 menu_shell->children = g_list_insert (menu_shell->children, child, position);
1972 menu_queue_resize (menu);
1977 gtk_menu_style_set (GtkWidget *widget,
1978 GtkStyle *previous_style)
1980 if (GTK_WIDGET_REALIZED (widget))
1982 GtkMenu *menu = GTK_MENU (widget);
1984 gtk_style_set_background (widget->style, menu->bin_window, GTK_STATE_NORMAL);
1985 gtk_style_set_background (widget->style, menu->view_window, GTK_STATE_NORMAL);
1986 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
1991 gtk_menu_realize (GtkWidget *widget)
1993 GdkWindowAttr attributes;
1994 gint attributes_mask;
1999 guint vertical_padding;
2001 g_return_if_fail (GTK_IS_MENU (widget));
2003 menu = GTK_MENU (widget);
2005 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2007 attributes.window_type = GDK_WINDOW_CHILD;
2008 attributes.x = widget->allocation.x;
2009 attributes.y = widget->allocation.y;
2010 attributes.width = widget->allocation.width;
2011 attributes.height = widget->allocation.height;
2012 attributes.wclass = GDK_INPUT_OUTPUT;
2013 attributes.visual = gtk_widget_get_visual (widget);
2014 attributes.colormap = gtk_widget_get_colormap (widget);
2016 attributes.event_mask = gtk_widget_get_events (widget);
2018 attributes.event_mask |= (GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK |
2019 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK );
2021 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2022 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2023 gdk_window_set_user_data (widget->window, widget);
2025 border_width = GTK_CONTAINER (widget)->border_width;
2027 gtk_widget_style_get (GTK_WIDGET (menu),
2028 "vertical-padding", &vertical_padding,
2031 attributes.x = border_width + widget->style->xthickness;
2032 attributes.y = border_width + widget->style->ythickness + vertical_padding;
2033 attributes.width = MAX (1, widget->allocation.width - attributes.x * 2);
2034 attributes.height = MAX (1, widget->allocation.height - attributes.y * 2);
2036 if (menu->upper_arrow_visible)
2038 attributes.y += MENU_SCROLL_ARROW_HEIGHT;
2039 attributes.height -= MENU_SCROLL_ARROW_HEIGHT;
2041 if (menu->lower_arrow_visible)
2042 attributes.height -= MENU_SCROLL_ARROW_HEIGHT;
2044 menu->view_window = gdk_window_new (widget->window, &attributes, attributes_mask);
2045 gdk_window_set_user_data (menu->view_window, menu);
2049 attributes.height = MAX (1, widget->requisition.height - (border_width + widget->style->ythickness + vertical_padding) * 2);
2051 menu->bin_window = gdk_window_new (menu->view_window, &attributes, attributes_mask);
2052 gdk_window_set_user_data (menu->bin_window, menu);
2054 children = GTK_MENU_SHELL (menu)->children;
2057 child = children->data;
2058 children = children->next;
2060 gtk_widget_set_parent_window (child, menu->bin_window);
2063 widget->style = gtk_style_attach (widget->style, widget->window);
2064 gtk_style_set_background (widget->style, menu->bin_window, GTK_STATE_NORMAL);
2065 gtk_style_set_background (widget->style, menu->view_window, GTK_STATE_NORMAL);
2066 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
2068 if (GTK_MENU_SHELL (widget)->active_menu_item)
2069 gtk_menu_scroll_item_visible (GTK_MENU_SHELL (widget),
2070 GTK_MENU_SHELL (widget)->active_menu_item);
2072 gdk_window_show (menu->bin_window);
2073 gdk_window_show (menu->view_window);
2077 gtk_menu_focus (GtkWidget *widget,
2078 GtkDirectionType direction)
2081 * A menu or its menu items cannot have focus
2086 /* See notes in gtk_menu_popup() for information about the "grab transfer window"
2089 menu_grab_transfer_window_get (GtkMenu *menu)
2091 GdkWindow *window = g_object_get_data (G_OBJECT (menu), "gtk-menu-transfer-window");
2094 GdkWindowAttr attributes;
2095 gint attributes_mask;
2097 attributes.x = -100;
2098 attributes.y = -100;
2099 attributes.width = 10;
2100 attributes.height = 10;
2101 attributes.window_type = GDK_WINDOW_TEMP;
2102 attributes.wclass = GDK_INPUT_ONLY;
2103 attributes.override_redirect = TRUE;
2104 attributes.event_mask = 0;
2106 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
2108 window = gdk_window_new (gtk_widget_get_root_window (GTK_WIDGET (menu)),
2109 &attributes, attributes_mask);
2110 gdk_window_set_user_data (window, menu);
2112 gdk_window_show (window);
2114 g_object_set_data (G_OBJECT (menu), "gtk-menu-transfer-window", window);
2121 menu_grab_transfer_window_destroy (GtkMenu *menu)
2123 GdkWindow *window = g_object_get_data (G_OBJECT (menu), "gtk-menu-transfer-window");
2126 gdk_window_set_user_data (window, NULL);
2127 gdk_window_destroy (window);
2128 g_object_set_data (G_OBJECT (menu), "gtk-menu-transfer-window", NULL);
2133 gtk_menu_unrealize (GtkWidget *widget)
2137 g_return_if_fail (GTK_IS_MENU (widget));
2139 menu = GTK_MENU (widget);
2141 menu_grab_transfer_window_destroy (menu);
2143 gdk_window_set_user_data (menu->view_window, NULL);
2144 gdk_window_destroy (menu->view_window);
2145 menu->view_window = NULL;
2147 gdk_window_set_user_data (menu->bin_window, NULL);
2148 gdk_window_destroy (menu->bin_window);
2149 menu->bin_window = NULL;
2151 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
2155 gtk_menu_size_request (GtkWidget *widget,
2156 GtkRequisition *requisition)
2160 GtkMenuShell *menu_shell;
2163 guint max_toggle_size;
2164 guint max_accel_width;
2165 guint vertical_padding;
2166 GtkRequisition child_requisition;
2167 GtkMenuPrivate *priv;
2169 g_return_if_fail (GTK_IS_MENU (widget));
2170 g_return_if_fail (requisition != NULL);
2172 menu = GTK_MENU (widget);
2173 menu_shell = GTK_MENU_SHELL (widget);
2174 priv = gtk_menu_get_private (menu);
2176 requisition->width = 0;
2177 requisition->height = 0;
2179 max_toggle_size = 0;
2180 max_accel_width = 0;
2182 g_free (priv->heights);
2183 priv->heights = g_new0 (guint, gtk_menu_get_n_rows (menu));
2184 priv->heights_length = gtk_menu_get_n_rows (menu);
2186 children = menu_shell->children;
2193 child = children->data;
2194 children = children->next;
2196 if (! GTK_WIDGET_VISIBLE (child))
2199 get_effective_child_attach (child, &l, &r, &t, &b);
2201 /* It's important to size_request the child
2202 * before doing the toggle size request, in
2203 * case the toggle size request depends on the size
2204 * request of a child of the child (e.g. for ImageMenuItem)
2207 GTK_MENU_ITEM (child)->show_submenu_indicator = TRUE;
2208 gtk_widget_size_request (child, &child_requisition);
2210 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child), &toggle_size);
2211 max_toggle_size = MAX (max_toggle_size, toggle_size);
2212 max_accel_width = MAX (max_accel_width,
2213 GTK_MENU_ITEM (child)->accelerator_width);
2215 part = child_requisition.width / (r - l);
2216 requisition->width = MAX (requisition->width, part);
2218 part = MAX (child_requisition.height, toggle_size) / (b - t);
2219 priv->heights[t] = MAX (priv->heights[t], part);
2222 for (i = 0; i < gtk_menu_get_n_rows (menu); i++)
2223 requisition->height += priv->heights[i];
2225 requisition->width += max_toggle_size + max_accel_width;
2226 requisition->width *= gtk_menu_get_n_columns (menu);
2227 requisition->width += (GTK_CONTAINER (menu)->border_width +
2228 widget->style->xthickness) * 2;
2230 gtk_widget_style_get (GTK_WIDGET (menu),
2231 "vertical-padding", &vertical_padding,
2233 requisition->height += (GTK_CONTAINER (menu)->border_width + vertical_padding +
2234 widget->style->ythickness) * 2;
2236 menu->toggle_size = max_toggle_size;
2238 /* Don't resize the tearoff if it is not active, because it won't redraw (it is only a background pixmap).
2240 if (menu->tearoff_active)
2241 gtk_menu_set_tearoff_hints (menu, requisition->width);
2245 gtk_menu_size_allocate (GtkWidget *widget,
2246 GtkAllocation *allocation)
2249 GtkMenuShell *menu_shell;
2251 GtkAllocation child_allocation;
2252 GtkRequisition child_requisition;
2253 GtkMenuPrivate *priv;
2257 guint vertical_padding;
2259 g_return_if_fail (GTK_IS_MENU (widget));
2260 g_return_if_fail (allocation != NULL);
2262 menu = GTK_MENU (widget);
2263 menu_shell = GTK_MENU_SHELL (widget);
2264 priv = gtk_menu_get_private (menu);
2266 widget->allocation = *allocation;
2267 gtk_widget_get_child_requisition (GTK_WIDGET (menu), &child_requisition);
2269 gtk_widget_style_get (GTK_WIDGET (menu),
2270 "vertical-padding", &vertical_padding,
2273 x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness;
2274 y = GTK_CONTAINER (menu)->border_width + widget->style->ythickness + vertical_padding;
2276 width = MAX (1, allocation->width - x * 2);
2277 height = MAX (1, allocation->height - y * 2);
2279 child_requisition.width -= x * 2;
2280 child_requisition.height -= y * 2;
2282 if (menu_shell->active)
2283 gtk_menu_scroll_to (menu, menu->scroll_offset);
2285 if (menu->upper_arrow_visible && !menu->tearoff_active)
2287 y += MENU_SCROLL_ARROW_HEIGHT;
2288 height -= MENU_SCROLL_ARROW_HEIGHT;
2291 if (menu->lower_arrow_visible && !menu->tearoff_active)
2292 height -= MENU_SCROLL_ARROW_HEIGHT;
2294 if (GTK_WIDGET_REALIZED (widget))
2296 gdk_window_move_resize (widget->window,
2297 allocation->x, allocation->y,
2298 allocation->width, allocation->height);
2300 gdk_window_move_resize (menu->view_window,
2307 if (menu_shell->children)
2309 gint base_width = width / gtk_menu_get_n_columns (menu);
2311 children = menu_shell->children;
2314 child = children->data;
2315 children = children->next;
2317 if (GTK_WIDGET_VISIBLE (child))
2322 get_effective_child_attach (child, &l, &r, &t, &b);
2324 if (gtk_widget_get_direction (GTK_WIDGET (menu)) == GTK_TEXT_DIR_RTL)
2327 tmp = gtk_menu_get_n_columns (menu) - l;
2328 l = gtk_menu_get_n_columns (menu) - r;
2332 child_allocation.width = (r - l) * base_width;
2333 child_allocation.height = 0;
2334 child_allocation.x = l * base_width;
2335 child_allocation.y = 0;
2337 for (i = 0; i < b; i++)
2340 child_allocation.y += priv->heights[i];
2342 child_allocation.height += priv->heights[i];
2345 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
2348 gtk_widget_size_allocate (child, &child_allocation);
2349 gtk_widget_queue_draw (child);
2353 /* Resize the item window */
2354 if (GTK_WIDGET_REALIZED (widget))
2360 for (i = 0; i < gtk_menu_get_n_rows (menu); i++)
2361 height += priv->heights[i];
2363 width = gtk_menu_get_n_columns (menu) * base_width;
2364 gdk_window_resize (menu->bin_window, width, height);
2367 if (menu->tearoff_active)
2369 if (allocation->height >= widget->requisition.height)
2371 if (GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
2373 gtk_widget_hide (menu->tearoff_scrollbar);
2374 gtk_menu_set_tearoff_hints (menu, allocation->width);
2376 gtk_menu_scroll_to (menu, 0);
2381 menu->tearoff_adjustment->upper = widget->requisition.height;
2382 menu->tearoff_adjustment->page_size = allocation->height;
2384 if (menu->tearoff_adjustment->value + menu->tearoff_adjustment->page_size >
2385 menu->tearoff_adjustment->upper)
2388 value = menu->tearoff_adjustment->upper - menu->tearoff_adjustment->page_size;
2391 gtk_menu_scroll_to (menu, value);
2394 gtk_adjustment_changed (menu->tearoff_adjustment);
2396 if (!GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
2398 gtk_widget_show (menu->tearoff_scrollbar);
2399 gtk_menu_set_tearoff_hints (menu, allocation->width);
2407 gtk_menu_paint (GtkWidget *widget,
2408 GdkEventExpose *event)
2412 gint border_x, border_y;
2413 guint vertical_padding;
2415 g_return_if_fail (GTK_IS_MENU (widget));
2417 menu = GTK_MENU (widget);
2419 gtk_widget_style_get (GTK_WIDGET (menu),
2420 "vertical-padding", &vertical_padding,
2423 border_x = GTK_CONTAINER (widget)->border_width + widget->style->xthickness;
2424 border_y = GTK_CONTAINER (widget)->border_width + widget->style->ythickness + vertical_padding;
2425 gdk_drawable_get_size (widget->window, &width, &height);
2427 if (event->window == widget->window)
2429 gint arrow_space = MENU_SCROLL_ARROW_HEIGHT - 2 * widget->style->ythickness;
2430 gint arrow_size = 0.7 * arrow_space;
2432 gtk_paint_box (widget->style,
2436 NULL, widget, "menu",
2438 if (menu->upper_arrow_visible && !menu->tearoff_active)
2440 gtk_paint_box (widget->style,
2442 menu->upper_arrow_prelight ?
2443 GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
2445 NULL, widget, "menu",
2448 width - 2 * border_x,
2449 MENU_SCROLL_ARROW_HEIGHT);
2451 gtk_paint_arrow (widget->style,
2453 menu->upper_arrow_prelight ?
2454 GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
2456 NULL, widget, "menu_scroll_arrow_up",
2459 (width - arrow_size ) / 2,
2460 border_y + widget->style->ythickness + (arrow_space - arrow_size)/2,
2461 arrow_size, arrow_size);
2464 if (menu->lower_arrow_visible && !menu->tearoff_active)
2466 gtk_paint_box (widget->style,
2468 menu->lower_arrow_prelight ?
2469 GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
2471 NULL, widget, "menu",
2473 height - border_y - MENU_SCROLL_ARROW_HEIGHT,
2475 MENU_SCROLL_ARROW_HEIGHT);
2477 gtk_paint_arrow (widget->style,
2479 menu->lower_arrow_prelight ?
2480 GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
2482 NULL, widget, "menu_scroll_arrow_down",
2485 (width - arrow_size) / 2,
2486 height - border_y - MENU_SCROLL_ARROW_HEIGHT +
2487 widget->style->ythickness + (arrow_space - arrow_size)/2,
2488 arrow_size, arrow_size);
2494 gtk_menu_expose (GtkWidget *widget,
2495 GdkEventExpose *event)
2497 g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
2498 g_return_val_if_fail (event != NULL, FALSE);
2500 if (GTK_WIDGET_DRAWABLE (widget))
2502 gtk_menu_paint (widget, event);
2504 (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
2511 gtk_menu_show (GtkWidget *widget)
2513 GtkMenu *menu = GTK_MENU (widget);
2515 _gtk_menu_refresh_accel_paths (menu, FALSE);
2517 GTK_WIDGET_CLASS (parent_class)->show (widget);
2521 gtk_menu_button_press (GtkWidget *widget,
2522 GdkEventButton *event)
2524 /* Don't pop down the menu for releases over scroll arrows
2526 if (GTK_IS_MENU (widget))
2528 GtkMenu *menu = GTK_MENU (widget);
2530 if (menu->upper_arrow_prelight || menu->lower_arrow_prelight)
2534 return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
2538 gtk_menu_button_release (GtkWidget *widget,
2539 GdkEventButton *event)
2541 /* Don't pop down the menu for releases over scroll arrows
2543 if (GTK_IS_MENU (widget))
2545 GtkMenu *menu = GTK_MENU (widget);
2547 if (menu->upper_arrow_prelight || menu->lower_arrow_prelight)
2551 return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
2554 static const gchar *
2555 get_accel_path (GtkWidget *menu_item,
2560 GClosure *accel_closure;
2561 GtkAccelGroup *accel_group;
2563 path = _gtk_widget_get_accel_path (menu_item, locked);
2566 path = GTK_MENU_ITEM (menu_item)->accel_path;
2572 label = GTK_BIN (menu_item)->child;
2574 if (GTK_IS_ACCEL_LABEL (label))
2576 g_object_get (label,
2577 "accel_closure", &accel_closure,
2581 accel_group = gtk_accel_group_from_accel_closure (accel_closure);
2583 *locked = accel_group->lock_count > 0;
2593 gtk_menu_key_press (GtkWidget *widget,
2596 GtkMenuShell *menu_shell;
2598 gboolean delete = FALSE;
2599 gboolean can_change_accels;
2600 gchar *accel = NULL;
2601 guint accel_key, accel_mods;
2602 GdkModifierType consumed_modifiers;
2603 GdkDisplay *display;
2605 g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
2606 g_return_val_if_fail (event != NULL, FALSE);
2608 menu_shell = GTK_MENU_SHELL (widget);
2609 menu = GTK_MENU (widget);
2611 gtk_menu_stop_navigating_submenu (menu);
2613 if (GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event))
2616 display = gtk_widget_get_display (widget);
2618 g_object_get (gtk_widget_get_settings (widget),
2619 "gtk-menu-bar-accel", &accel,
2620 "gtk-can-change-accels", &can_change_accels,
2626 GdkModifierType mods = 0;
2627 gboolean handled = FALSE;
2629 gtk_accelerator_parse (accel, &keyval, &mods);
2632 g_warning ("Failed to parse menu bar accelerator '%s'\n", accel);
2634 /* FIXME this is wrong, needs to be in the global accel resolution
2635 * thing, to properly consider i18n etc., but that probably requires
2636 * AccelGroup changes etc.
2638 if (event->keyval == keyval &&
2639 (mods & event->state) == mods)
2640 gtk_menu_shell_cancel (menu_shell);
2648 switch (event->keyval)
2659 /* Figure out what modifiers went into determining the key symbol */
2660 gdk_keymap_translate_keyboard_state (gdk_keymap_get_for_display (display),
2661 event->hardware_keycode, event->state, event->group,
2662 NULL, NULL, NULL, &consumed_modifiers);
2664 accel_key = gdk_keyval_to_lower (event->keyval);
2665 accel_mods = event->state & gtk_accelerator_get_default_mod_mask () & ~consumed_modifiers;
2667 /* If lowercasing affects the keysym, then we need to include SHIFT in the modifiers,
2668 * We re-upper case when we match against the keyval, but display and save in caseless form.
2670 if (accel_key != event->keyval)
2671 accel_mods |= GDK_SHIFT_MASK;
2673 /* Modify the accelerators */
2674 if (can_change_accels &&
2675 menu_shell->active_menu_item &&
2676 GTK_BIN (menu_shell->active_menu_item)->child && /* no separators */
2677 GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu == NULL && /* no submenus */
2678 (delete || gtk_accelerator_valid (accel_key, accel_mods)))
2680 GtkWidget *menu_item = menu_shell->active_menu_item;
2681 gboolean locked, replace_accels = TRUE;
2684 path = get_accel_path (menu_item, &locked);
2685 if (!path || locked)
2687 /* can't change accelerators on menu_items without paths
2688 * (basically, those items are accelerator-locked).
2690 /* g_print("item has no path or is locked, menu prefix: %s\n", menu->accel_path); */
2691 gdk_display_beep (display);
2697 /* For the keys that act to delete the current setting, we delete
2698 * the current setting if there is one, otherwise, we set the
2699 * key as the accelerator.
2705 if (gtk_accel_map_lookup_entry (path, &key) &&
2706 (key.accel_key || key.accel_mods))
2712 changed = gtk_accel_map_change_entry (path, accel_key, accel_mods, replace_accels);
2716 /* we failed, probably because this key is in use and
2719 /* g_print("failed to change\n"); */
2720 gdk_display_beep (display);
2729 check_threshold (GtkWidget *widget,
2730 int start_x, int start_y,
2736 ABS (start_x - x) > THRESHOLD ||
2737 ABS (start_y - y) > THRESHOLD;
2741 definitely_within_item (GtkWidget *widget,
2745 GdkWindow *window = GTK_MENU_ITEM (widget)->event_window;
2748 gdk_drawable_get_size (window, &w, &h);
2751 check_threshold (widget, 0, 0, x, y) &&
2752 check_threshold (widget, w - 1, 0, x, y) &&
2753 check_threshold (widget, w - 1, h - 1, x, y) &&
2754 check_threshold (widget, 0, h - 1, x, y);
2758 gtk_menu_motion_notify (GtkWidget *widget,
2759 GdkEventMotion *event)
2761 GtkWidget *menu_item;
2763 GtkMenuShell *menu_shell;
2764 GtkMenuPrivate *priv;
2766 gboolean need_enter;
2768 if (GTK_IS_MENU (widget))
2769 gtk_menu_handle_scrolling (GTK_MENU (widget), event->x_root, event->y_root, TRUE);
2771 /* We received the event for one of two reasons:
2773 * a) We are the active menu, and did gtk_grab_add()
2774 * b) The widget is a child of ours, and the event was propagated
2776 * Since for computation of navigation regions, we want the menu which
2777 * is the parent of the menu item, for a), we need to find that menu,
2778 * which may be different from 'widget'.
2780 menu_item = gtk_get_event_widget ((GdkEvent*) event);
2781 if (!menu_item || !GTK_IS_MENU_ITEM (menu_item) ||
2782 !GTK_IS_MENU (menu_item->parent))
2785 menu_shell = GTK_MENU_SHELL (menu_item->parent);
2786 menu = GTK_MENU (menu_shell);
2788 priv = gtk_menu_get_private (GTK_MENU (widget));
2790 if (definitely_within_item (menu_item, event->x, event->y))
2791 menu_shell->activate_time = 0;
2793 need_enter = (menu->navigation_region != NULL || menu_shell->ignore_enter);
2795 /* Check to see if we are within an active submenu's navigation region
2797 if (gtk_menu_navigating_submenu (menu, event->x_root, event->y_root))
2800 /* Make sure we pop down if we enter a non-selectable menu item, so we
2801 * don't show a submenu when the cursor is outside the stay-up triangle.
2803 if (!_gtk_menu_item_is_selectable (menu_item))
2805 gtk_menu_shell_deselect (menu_shell);
2811 /* The menu is now sensitive to enter events on its items, but
2812 * was previously sensitive. So we fake an enter event.
2816 menu_shell->ignore_enter = FALSE;
2818 gdk_drawable_get_size (event->window, &width, &height);
2819 if (event->x >= 0 && event->x < width &&
2820 event->y >= 0 && event->y < height)
2822 GdkEvent *send_event = gdk_event_new (GDK_ENTER_NOTIFY);
2825 send_event->crossing.window = g_object_ref (event->window);
2826 send_event->crossing.time = event->time;
2827 send_event->crossing.send_event = TRUE;
2828 send_event->crossing.x_root = event->x_root;
2829 send_event->crossing.y_root = event->y_root;
2830 send_event->crossing.x = event->x;
2831 send_event->crossing.y = event->y;
2833 /* We send the event to 'widget', the currently active menu,
2834 * instead of 'menu', the menu that the pointer is in. This
2835 * will ensure that the event will be ignored unless the
2836 * menuitem is a child of the active menu or some parent
2837 * menu of the active menu.
2839 result = gtk_widget_event (widget, send_event);
2840 gdk_event_free (send_event);
2850 gtk_menu_scroll_by (GtkMenu *menu,
2855 gint view_width, view_height;
2857 widget = GTK_WIDGET (menu);
2858 offset = menu->scroll_offset + step;
2860 /* If we scroll upward and the non-visible top part
2861 * is smaller than the scroll arrow it would be
2862 * pretty stupid to show the arrow and taking more
2863 * screen space than just scrolling to the top.
2865 if ((step < 0) && (offset < MENU_SCROLL_ARROW_HEIGHT))
2868 /* Don't scroll over the top if we weren't before: */
2869 if ((menu->scroll_offset >= 0) && (offset < 0))
2872 gdk_drawable_get_size (widget->window, &view_width, &view_height);
2874 /* Don't scroll past the bottom if we weren't before: */
2875 if (menu->scroll_offset > 0)
2876 view_height -= MENU_SCROLL_ARROW_HEIGHT;
2878 if ((menu->scroll_offset + view_height <= widget->requisition.height) &&
2879 (offset + view_height > widget->requisition.height))
2880 offset = widget->requisition.height - view_height;
2882 if (offset != menu->scroll_offset)
2883 gtk_menu_scroll_to (menu, offset);
2887 gtk_menu_scroll_timeout (gpointer data)
2891 GDK_THREADS_ENTER ();
2893 menu = GTK_MENU (data);
2894 gtk_menu_scroll_by (menu, menu->scroll_step);
2896 GDK_THREADS_LEAVE ();
2902 gtk_menu_scroll (GtkWidget *widget,
2903 GdkEventScroll *event)
2905 GtkMenu *menu = GTK_MENU (widget);
2907 switch (event->direction)
2909 case GDK_SCROLL_RIGHT:
2910 case GDK_SCROLL_DOWN:
2911 gtk_menu_scroll_by (menu, MENU_SCROLL_STEP2);
2913 case GDK_SCROLL_LEFT:
2915 gtk_menu_scroll_by (menu, - MENU_SCROLL_STEP2);
2923 gtk_menu_handle_scrolling (GtkMenu *menu,
2928 GtkMenuShell *menu_shell;
2933 gboolean scroll_fast = FALSE;
2934 guint vertical_padding;
2938 menu_shell = GTK_MENU_SHELL (menu);
2940 gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
2942 gtk_widget_style_get (GTK_WIDGET (menu),
2943 "vertical-padding", &vertical_padding,
2946 border = GTK_CONTAINER (menu)->border_width +
2947 GTK_WIDGET (menu)->style->ythickness + vertical_padding;
2949 gdk_window_get_position (menu->toplevel->window, &top_x, &top_y);
2950 gdk_window_get_position (GTK_WIDGET (menu)->window, &win_x, &win_y);
2954 if (menu->upper_arrow_visible && !menu->tearoff_active)
2959 rect.height = MENU_SCROLL_ARROW_HEIGHT + border;
2962 if ((x >= rect.x) && (x < rect.x + rect.width) &&
2963 (y >= rect.y) && (y < rect.y + rect.height))
2966 scroll_fast = (y < rect.y + MENU_SCROLL_FAST_ZONE);
2969 if (enter && in_arrow &&
2970 (!menu->upper_arrow_prelight || menu->scroll_fast != scroll_fast))
2972 menu->upper_arrow_prelight = TRUE;
2973 menu->scroll_fast = scroll_fast;
2974 gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
2976 /* Deselect the active item so that any submenus are poped down */
2977 gtk_menu_shell_deselect (menu_shell);
2979 gtk_menu_remove_scroll_timeout (menu);
2980 menu->scroll_step = (scroll_fast) ? -MENU_SCROLL_STEP2 : -MENU_SCROLL_STEP1;
2981 menu->timeout_id = g_timeout_add ((scroll_fast) ? MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
2982 gtk_menu_scroll_timeout,
2985 else if (!enter && !in_arrow && menu->upper_arrow_prelight)
2987 gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
2989 gtk_menu_stop_scrolling (menu);
2993 if (menu->lower_arrow_visible && !menu->tearoff_active)
2996 rect.y = win_y + height - border - MENU_SCROLL_ARROW_HEIGHT;
2998 rect.height = MENU_SCROLL_ARROW_HEIGHT + border;
3001 if ((x >= rect.x) && (x < rect.x + rect.width) &&
3002 (y >= rect.y) && (y < rect.y + rect.height))
3005 scroll_fast = (y > rect.y + rect.height - MENU_SCROLL_FAST_ZONE);
3008 if (enter && in_arrow &&
3009 (!menu->lower_arrow_prelight || menu->scroll_fast != scroll_fast))
3011 menu->lower_arrow_prelight = TRUE;
3012 menu->scroll_fast = scroll_fast;
3013 gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
3015 /* Deselect the active item so that any submenus are poped down */
3016 gtk_menu_shell_deselect (menu_shell);
3018 gtk_menu_remove_scroll_timeout (menu);
3019 menu->scroll_step = (scroll_fast) ? MENU_SCROLL_STEP2 : MENU_SCROLL_STEP1;
3020 menu->timeout_id = g_timeout_add ((scroll_fast) ? MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
3021 gtk_menu_scroll_timeout,
3024 else if (!enter && !in_arrow && menu->lower_arrow_prelight)
3026 gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
3028 gtk_menu_stop_scrolling (menu);
3034 gtk_menu_enter_notify (GtkWidget *widget,
3035 GdkEventCrossing *event)
3037 GtkWidget *menu_item;
3039 menu_item = gtk_get_event_widget ((GdkEvent*) event);
3040 if (widget && GTK_IS_MENU (widget))
3042 GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
3044 if (!menu_shell->ignore_enter)
3045 gtk_menu_handle_scrolling (GTK_MENU (widget), event->x_root, event->y_root, TRUE);
3048 if (menu_item && GTK_IS_MENU_ITEM (menu_item))
3050 GtkWidget *menu = menu_item->parent;
3052 if (menu && GTK_IS_MENU (menu))
3054 GtkMenuPrivate *priv = gtk_menu_get_private (GTK_MENU (menu));
3055 GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
3057 if (priv->seen_item_enter)
3059 /* This is the second enter we see for an item
3060 * on this menu. This means a release should always
3063 menu_shell->activate_time = 0;
3065 else if ((event->detail != GDK_NOTIFY_NONLINEAR &&
3066 event->detail != GDK_NOTIFY_NONLINEAR_VIRTUAL))
3068 if (definitely_within_item (menu_item, event->x, event->y))
3070 /* This is an actual user-enter (ie. not a pop-under)
3071 * In this case, the user must either have entered
3072 * sufficiently far enough into the item, or he must move
3073 * far enough away from the enter point. (see
3074 * gtk_menu_motion_notify())
3076 menu_shell->activate_time = 0;
3080 priv->seen_item_enter = TRUE;
3084 /* If this is a faked enter (see gtk_menu_motion_notify), 'widget'
3085 * will not correspond to the event widget's parent. Check to see
3086 * if we are in the parent's navigation region.
3088 if (menu_item && GTK_IS_MENU_ITEM (menu_item) && GTK_IS_MENU (menu_item->parent) &&
3089 gtk_menu_navigating_submenu (GTK_MENU (menu_item->parent), event->x_root, event->y_root))
3092 return GTK_WIDGET_CLASS (parent_class)->enter_notify_event (widget, event);
3096 gtk_menu_leave_notify (GtkWidget *widget,
3097 GdkEventCrossing *event)
3099 GtkMenuShell *menu_shell;
3101 GtkMenuItem *menu_item;
3102 GtkWidget *event_widget;
3104 menu = GTK_MENU (widget);
3105 menu_shell = GTK_MENU_SHELL (widget);
3107 if (gtk_menu_navigating_submenu (menu, event->x_root, event->y_root))
3110 gtk_menu_handle_scrolling (menu, event->x_root, event->y_root, FALSE);
3112 event_widget = gtk_get_event_widget ((GdkEvent*) event);
3114 if (!event_widget || !GTK_IS_MENU_ITEM (event_widget))
3117 menu_item = GTK_MENU_ITEM (event_widget);
3119 /* Here we check to see if we're leaving an active menu item with a submenu,
3120 * in which case we enter submenu navigation mode.
3122 if (menu_shell->active_menu_item != NULL
3123 && menu_item->submenu != NULL
3124 && menu_item->submenu_placement == GTK_LEFT_RIGHT)
3126 if (GTK_MENU_SHELL (menu_item->submenu)->active)
3128 gtk_menu_set_submenu_navigation_region (menu, menu_item, event);
3131 else if (menu_item == GTK_MENU_ITEM (menu_shell->active_menu_item))
3133 /* We are leaving an active menu item with nonactive submenu.
3134 * Deselect it so we don't surprise the user with by popping
3135 * up a submenu _after_ he left the item.
3137 gtk_menu_shell_deselect (menu_shell);
3142 return GTK_WIDGET_CLASS (parent_class)->leave_notify_event (widget, event);
3146 gtk_menu_stop_navigating_submenu (GtkMenu *menu)
3148 if (menu->navigation_region)
3150 gdk_region_destroy (menu->navigation_region);
3151 menu->navigation_region = NULL;
3154 if (menu->navigation_timeout)
3156 g_source_remove (menu->navigation_timeout);
3157 menu->navigation_timeout = 0;
3161 /* When the timeout is elapsed, the navigation region is destroyed
3162 * and the menuitem under the pointer (if any) is selected.
3165 gtk_menu_stop_navigating_submenu_cb (gpointer user_data)
3167 GtkMenu *menu = user_data;
3168 GdkWindow *child_window;
3170 GDK_THREADS_ENTER ();
3172 gtk_menu_stop_navigating_submenu (menu);
3174 if (GTK_WIDGET_REALIZED (menu))
3176 child_window = gdk_window_get_pointer (menu->bin_window, NULL, NULL, NULL);
3180 GdkEvent *send_event = gdk_event_new (GDK_ENTER_NOTIFY);
3182 send_event->crossing.window = g_object_ref (child_window);
3183 send_event->crossing.time = GDK_CURRENT_TIME; /* Bogus */
3184 send_event->crossing.send_event = TRUE;
3186 GTK_WIDGET_CLASS (parent_class)->enter_notify_event (GTK_WIDGET (menu), (GdkEventCrossing *)send_event);
3188 gdk_event_free (send_event);
3192 GDK_THREADS_LEAVE ();
3198 gtk_menu_navigating_submenu (GtkMenu *menu,
3202 if (menu->navigation_region)
3204 if (gdk_region_point_in (menu->navigation_region, event_x, event_y))
3208 gtk_menu_stop_navigating_submenu (menu);
3215 #undef DRAW_STAY_UP_TRIANGLE
3217 #ifdef DRAW_STAY_UP_TRIANGLE
3220 draw_stay_up_triangle (GdkWindow *window,
3223 /* Draw ugly color all over the stay-up triangle */
3224 GdkColor ugly_color = { 0, 50000, 10000, 10000 };
3225 GdkGCValues gc_values;
3227 GdkRectangle clipbox;
3229 gc_values.subwindow_mode = GDK_INCLUDE_INFERIORS;
3230 ugly_gc = gdk_gc_new_with_values (window, &gc_values, 0 | GDK_GC_SUBWINDOW);
3231 gdk_gc_set_rgb_fg_color (ugly_gc, &ugly_color);
3232 gdk_gc_set_clip_region (ugly_gc, region);
3234 gdk_region_get_clipbox (region, &clipbox);
3236 gdk_draw_rectangle (window,
3239 clipbox.x, clipbox.y,
3240 clipbox.width, clipbox.height);
3242 g_object_unref (ugly_gc);
3247 flip_region (GdkRegion *region,
3252 GdkRectangle *rectangles;
3253 GdkRectangle clipbox;
3254 GdkRegion *new_region;
3257 new_region = gdk_region_new ();
3259 gdk_region_get_rectangles (region, &rectangles, &n_rectangles);
3260 gdk_region_get_clipbox (region, &clipbox);
3262 for (i = 0; i < n_rectangles; ++i)
3264 GdkRectangle rect = rectangles[i];
3267 rect.y -= 2 * (rect.y - clipbox.y) + rect.height;
3270 rect.x -= 2 * (rect.x - clipbox.x) + rect.width;
3272 gdk_region_union_with_rect (new_region, &rect);
3275 g_free (rectangles);
3281 gtk_menu_set_submenu_navigation_region (GtkMenu *menu,
3282 GtkMenuItem *menu_item,
3283 GdkEventCrossing *event)
3285 gint submenu_left = 0;
3286 gint submenu_right = 0;
3287 gint submenu_top = 0;
3288 gint submenu_bottom = 0;
3292 GtkWidget *event_widget;
3294 g_return_if_fail (menu_item->submenu != NULL);
3295 g_return_if_fail (event != NULL);
3297 event_widget = gtk_get_event_widget ((GdkEvent*) event);
3299 gdk_window_get_origin (menu_item->submenu->window, &submenu_left, &submenu_top);
3300 gdk_drawable_get_size (menu_item->submenu->window, &width, &height);
3302 submenu_right = submenu_left + width;
3303 submenu_bottom = submenu_top + height;
3305 gdk_drawable_get_size (event_widget->window, &width, &height);
3307 if (event->x >= 0 && event->x < width)
3310 gboolean flip_y = FALSE;
3311 gboolean flip_x = FALSE;
3313 gtk_menu_stop_navigating_submenu (menu);
3315 if (menu_item->submenu_direction == GTK_DIRECTION_RIGHT)
3318 point[0].x = event->x_root;
3319 point[1].x = submenu_left;
3324 point[0].x = event->x_root + 1;
3325 point[1].x = 2 * (event->x_root + 1) - submenu_right;
3333 point[0].y = event->y_root + 1;
3334 point[1].y = 2 * (event->y_root + 1) - submenu_top + NAVIGATION_REGION_OVERSHOOT;
3336 if (point[0].y >= point[1].y - NAVIGATION_REGION_OVERSHOOT)
3344 point[0].y = event->y_root;
3345 point[1].y = submenu_bottom + NAVIGATION_REGION_OVERSHOOT;
3347 if (point[0].y >= submenu_bottom)
3351 point[2].x = point[1].x;
3352 point[2].y = point[0].y;
3354 menu->navigation_region = gdk_region_polygon (point, 3, GDK_WINDING_RULE);
3356 if (flip_x || flip_y)
3358 GdkRegion *new_region = flip_region (menu->navigation_region, flip_x, flip_y);
3359 gdk_region_destroy (menu->navigation_region);
3360 menu->navigation_region = new_region;
3363 g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
3364 "gtk-menu-popdown-delay", &popdown_delay,
3367 menu->navigation_timeout = g_timeout_add (popdown_delay,
3368 gtk_menu_stop_navigating_submenu_cb, menu);
3370 #ifdef DRAW_STAY_UP_TRIANGLE
3371 draw_stay_up_triangle (gdk_get_default_root_window(),
3372 menu->navigation_region);
3378 gtk_menu_deactivate (GtkMenuShell *menu_shell)
3382 g_return_if_fail (GTK_IS_MENU (menu_shell));
3384 parent = menu_shell->parent_menu_shell;
3386 menu_shell->activate_time = 0;
3387 gtk_menu_popdown (GTK_MENU (menu_shell));
3390 gtk_menu_shell_deactivate (GTK_MENU_SHELL (parent));
3394 gtk_menu_position (GtkMenu *menu)
3397 GtkRequisition requisition;
3398 GtkMenuPrivate *private;
3404 GdkScreen *pointer_screen;
3405 GdkRectangle monitor;
3407 g_return_if_fail (GTK_IS_MENU (menu));
3409 widget = GTK_WIDGET (menu);
3411 screen = gtk_widget_get_screen (widget);
3412 gdk_display_get_pointer (gdk_screen_get_display (screen),
3413 &pointer_screen, &x, &y, NULL);
3415 /* We need the requisition to figure out the right place to
3416 * popup the menu. In fact, we always need to ask here, since
3417 * if a size_request was queued while we weren't popped up,
3418 * the requisition won't have been recomputed yet.
3420 gtk_widget_size_request (widget, &requisition);
3422 if (pointer_screen != screen)
3424 /* Pointer is on a different screen; roughly center the
3425 * menu on the screen. If someone was using multiscreen
3426 * + Xinerama together they'd probably want something
3427 * fancier; but that is likely to be vanishingly rare.
3429 x = MAX (0, (gdk_screen_get_width (screen) - requisition.width) / 2);
3430 y = MAX (0, (gdk_screen_get_height (screen) - requisition.height) / 2);
3433 private = gtk_menu_get_private (menu);
3434 private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
3438 if (menu->position_func)
3440 (* menu->position_func) (menu, &x, &y, &push_in, menu->position_func_data);
3441 if (private->monitor_num < 0)
3442 private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
3444 gdk_screen_get_monitor_geometry (screen, private->monitor_num, &monitor);
3448 gint space_left, space_right, space_above, space_below;
3451 gint xthickness = widget->style->xthickness;
3452 gint ythickness = widget->style->ythickness;
3453 gboolean rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3455 /* The placement of popup menus horizontally works like this (with
3456 * RTL in parentheses)
3458 * - If there is enough room to the right (left) of the mouse cursor,
3459 * position the menu there.
3461 * - Otherwise, if if there is enough room to the left (right) of the
3462 * mouse cursor, position the menu there.
3464 * - Otherwise if the menu is smaller than the monitor, position it
3465 * on the side of the mouse cursor that has the most space available
3467 * - Otherwise (if there is simply not enough room for the menu on the
3468 * monitor), position it as far left (right) as possible.
3470 * Positioning in the vertical direction is similar: first try below
3471 * mouse cursor, then above.
3473 gdk_screen_get_monitor_geometry (screen, private->monitor_num, &monitor);
3475 space_left = x - monitor.x;
3476 space_right = monitor.x + monitor.width - x - 1;
3477 space_above = y - monitor.y;
3478 space_below = monitor.y + monitor.height - y - 1;
3480 /* position horizontally */
3482 /* the amount of space we need to position the menu. Note the
3483 * menu is offset "xthickness" pixels
3485 needed_width = requisition.width - xthickness;
3487 if (needed_width <= space_left ||
3488 needed_width <= space_right)
3490 if ((rtl && needed_width <= space_left) ||
3491 (!rtl && needed_width > space_right))
3494 x = x + xthickness - requisition.width + 1;
3498 /* position right */
3502 /* x is clamped on-screen further down */
3504 else if (requisition.width <= monitor.width)
3506 /* the menu is too big to fit on either side of the mouse
3507 * cursor, but smaller than the monitor. Position it on
3508 * the side that has the most space
3510 if (space_left > space_right)
3518 x = monitor.x + monitor.width - requisition.width;
3521 else /* menu is simply too big for the monitor */
3526 x = monitor.x + monitor.width - requisition.width;
3535 /* Position vertically. The algorithm is the same as above, but
3536 * simpler because we don't have to take RTL into account.
3538 needed_height = requisition.height - ythickness;
3540 if (needed_height <= space_above ||
3541 needed_height <= space_below)
3543 if (needed_height <= space_below)
3546 y = y + ythickness - requisition.height + 1;
3548 y = CLAMP (y, monitor.y,
3549 monitor.y + monitor.height - requisition.height);
3551 else if (needed_height > space_below && needed_height > space_above)
3553 if (space_below >= space_above)
3554 y = monitor.y + monitor.height - requisition.height;
3568 menu_height = GTK_WIDGET (menu)->requisition.height;
3570 if (y + menu_height > monitor.y + monitor.height)
3572 scroll_offset -= y + menu_height - (monitor.y + monitor.height);
3573 y = (monitor.y + monitor.height) - menu_height;
3578 scroll_offset += monitor.y - y;
3583 /* FIXME: should this be done in the various position_funcs ? */
3584 x = CLAMP (x, monitor.x, MAX (monitor.x, monitor.x + monitor.width - requisition.width));
3586 if (GTK_MENU_SHELL (menu)->active)
3588 private->have_position = TRUE;
3593 if (y + requisition.height > monitor.y + monitor.height)
3594 requisition.height = (monitor.y + monitor.height) - y;
3598 scroll_offset += monitor.y - y;
3599 requisition.height -= monitor.y - y;
3603 if (scroll_offset > 0)
3604 scroll_offset += MENU_SCROLL_ARROW_HEIGHT;
3606 gtk_window_move (GTK_WINDOW (GTK_MENU_SHELL (menu)->active ? menu->toplevel : menu->tearoff_window),
3609 if (!GTK_MENU_SHELL (menu)->active)
3611 gtk_window_resize (GTK_WINDOW (menu->tearoff_window),
3612 requisition.width, requisition.height);
3615 menu->scroll_offset = scroll_offset;
3619 gtk_menu_remove_scroll_timeout (GtkMenu *menu)
3621 if (menu->timeout_id)
3623 g_source_remove (menu->timeout_id);
3624 menu->timeout_id = 0;
3629 gtk_menu_stop_scrolling (GtkMenu *menu)
3631 gtk_menu_remove_scroll_timeout (menu);
3633 menu->upper_arrow_prelight = FALSE;
3634 menu->lower_arrow_prelight = FALSE;
3638 gtk_menu_scroll_to (GtkMenu *menu,
3643 gint view_width, view_height;
3645 gboolean last_visible;
3647 guint vertical_padding;
3649 widget = GTK_WIDGET (menu);
3651 if (menu->tearoff_active &&
3652 menu->tearoff_adjustment &&
3653 (menu->tearoff_adjustment->value != offset))
3655 menu->tearoff_adjustment->value =
3657 0, menu->tearoff_adjustment->upper - menu->tearoff_adjustment->page_size);
3658 gtk_adjustment_value_changed (menu->tearoff_adjustment);
3661 /* Move/resize the viewport according to arrows: */
3662 view_width = widget->allocation.width;
3663 view_height = widget->allocation.height;
3665 gtk_widget_style_get (GTK_WIDGET (menu),
3666 "vertical-padding", &vertical_padding,
3669 border_width = GTK_CONTAINER (menu)->border_width;
3670 view_width -= (border_width + widget->style->xthickness) * 2;
3671 view_height -= (border_width + widget->style->ythickness + vertical_padding) * 2;
3672 menu_height = widget->requisition.height -
3673 (border_width + widget->style->ythickness + vertical_padding) * 2;
3675 x = border_width + widget->style->xthickness;
3676 y = border_width + widget->style->ythickness + vertical_padding;
3678 if (!menu->tearoff_active)
3680 last_visible = menu->upper_arrow_visible;
3681 menu->upper_arrow_visible = offset > 0;
3683 if (menu->upper_arrow_visible)
3684 view_height -= MENU_SCROLL_ARROW_HEIGHT;
3686 if ( (last_visible != menu->upper_arrow_visible) &&
3687 !menu->upper_arrow_visible)
3689 menu->upper_arrow_prelight = FALSE;
3691 /* If we hid the upper arrow, possibly remove timeout */
3692 if (menu->scroll_step < 0)
3694 gtk_menu_stop_scrolling (menu);
3695 gtk_widget_queue_draw (GTK_WIDGET (menu));
3699 last_visible = menu->lower_arrow_visible;
3700 menu->lower_arrow_visible = offset < menu_height - view_height;
3702 if (menu->lower_arrow_visible)
3703 view_height -= MENU_SCROLL_ARROW_HEIGHT;
3705 if ( (last_visible != menu->lower_arrow_visible) &&
3706 !menu->lower_arrow_visible)
3708 menu->lower_arrow_prelight = FALSE;
3710 /* If we hid the lower arrow, possibly remove timeout */
3711 if (menu->scroll_step > 0)
3713 gtk_menu_stop_scrolling (menu);
3714 gtk_widget_queue_draw (GTK_WIDGET (menu));
3718 if (menu->upper_arrow_visible)
3719 y += MENU_SCROLL_ARROW_HEIGHT;
3722 /* Scroll the menu: */
3723 if (GTK_WIDGET_REALIZED (menu))
3724 gdk_window_move (menu->bin_window, 0, -offset);
3726 if (GTK_WIDGET_REALIZED (menu))
3727 gdk_window_move_resize (menu->view_window,
3733 menu->scroll_offset = offset;
3737 compute_child_offset (GtkMenu *menu,
3738 GtkWidget *menu_item,
3741 gboolean *is_last_child)
3743 GtkMenuPrivate *priv = gtk_menu_get_private (menu);
3744 guint item_top_attach;
3745 guint item_bottom_attach;
3746 gint child_offset = 0;
3749 get_effective_child_attach (menu_item, NULL, NULL,
3750 &item_top_attach, &item_bottom_attach);
3752 /* there is a possibility that we get called before _size_request, so
3753 * check the height table for safety.
3755 if (!priv->heights || priv->heights_length < gtk_menu_get_n_rows (menu))
3758 /* when we have a row with only invisible children, it's height will
3759 * be zero, so there's no need to check WIDGET_VISIBLE here
3761 for (i = 0; i < item_top_attach; i++)
3762 child_offset += priv->heights[i];
3765 *is_last_child = (item_bottom_attach == gtk_menu_get_n_rows (menu));
3767 *offset = child_offset;
3769 *height = priv->heights[item_top_attach];
3775 gtk_menu_scroll_item_visible (GtkMenuShell *menu_shell,
3776 GtkWidget *menu_item)
3779 gint child_offset, child_height;
3783 gboolean last_child = 0;
3785 menu = GTK_MENU (menu_shell);
3787 /* We need to check if the selected item fully visible.
3788 * If not we need to scroll the menu so that it becomes fully
3792 if (compute_child_offset (menu, menu_item,
3793 &child_offset, &child_height, &last_child))
3795 guint vertical_padding;
3797 y = menu->scroll_offset;
3798 gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
3800 gtk_widget_style_get (GTK_WIDGET (menu),
3801 "vertical-padding", &vertical_padding,
3804 height -= 2*GTK_CONTAINER (menu)->border_width + 2*GTK_WIDGET (menu)->style->ythickness + 2*vertical_padding;
3806 if (child_offset < y)
3808 /* Ignore the enter event we might get if the pointer is on the menu
3810 menu_shell->ignore_enter = TRUE;
3811 gtk_menu_scroll_to (menu, child_offset);
3816 if (menu->upper_arrow_visible && !menu->tearoff_active)
3817 arrow_height += MENU_SCROLL_ARROW_HEIGHT;
3818 if (menu->lower_arrow_visible && !menu->tearoff_active)
3819 arrow_height += MENU_SCROLL_ARROW_HEIGHT;
3821 if (child_offset + child_height > y + height - arrow_height)
3824 if (!last_child && !menu->tearoff_active)
3825 arrow_height += MENU_SCROLL_ARROW_HEIGHT;
3827 y = child_offset + child_height - height + arrow_height;
3828 if ((y > 0) && !menu->tearoff_active)
3830 /* Need upper arrow */
3831 arrow_height += MENU_SCROLL_ARROW_HEIGHT;
3832 y = child_offset + child_height - height + arrow_height;
3834 /* Ignore the enter event we might get if the pointer is on the menu
3836 menu_shell->ignore_enter = TRUE;
3837 gtk_menu_scroll_to (menu, y);
3845 gtk_menu_select_item (GtkMenuShell *menu_shell,
3846 GtkWidget *menu_item)
3848 GtkMenu *menu = GTK_MENU (menu_shell);
3850 if (GTK_WIDGET_REALIZED (GTK_WIDGET (menu)))
3851 gtk_menu_scroll_item_visible (menu_shell, menu_item);
3853 GTK_MENU_SHELL_CLASS (parent_class)->select_item (menu_shell, menu_item);
3857 /* Reparent the menu, taking care of the refcounting
3859 * If unrealize is true we force a unrealize while reparenting the parent.
3860 * This can help eliminate flicker in some cases.
3862 * What happens is that when the menu is unrealized and then re-realized,
3863 * the allocations are as follows:
3865 * parent - 1x1 at (0,0)
3866 * child1 - 100x20 at (0,0)
3867 * child2 - 100x20 at (0,20)
3868 * child3 - 100x20 at (0,40)
3870 * That is, the parent is small but the children are full sized. Then,
3871 * when the queued_resize gets processed, the parent gets resized to
3874 * But in order to eliminate flicker when scrolling, gdkgeometry-x11.c
3875 * contains the following logic:
3877 * - if a move or resize operation on a window would change the clip
3878 * region on the children, then before the window is resized
3879 * the background for children is temporarily set to None, the
3880 * move/resize done, and the background for the children restored.
3882 * So, at the point where the parent is resized to final size, the
3883 * background for the children is temporarily None, and thus they
3884 * are not cleared to the background color and the previous background
3885 * (the image of the menu) is left in place.
3888 gtk_menu_reparent (GtkMenu *menu,
3889 GtkWidget *new_parent,
3892 GtkObject *object = GTK_OBJECT (menu);
3893 GtkWidget *widget = GTK_WIDGET (menu);
3894 gboolean was_floating = GTK_OBJECT_FLOATING (object);
3896 g_object_ref (object);
3897 gtk_object_sink (object);
3901 g_object_ref (object);
3902 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3903 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3904 g_object_unref (object);
3907 gtk_widget_reparent (GTK_WIDGET (menu), new_parent);
3910 GTK_OBJECT_SET_FLAGS (object, GTK_FLOATING);
3912 g_object_unref (object);
3916 gtk_menu_show_all (GtkWidget *widget)
3918 /* Show children, but not self. */
3919 gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_show_all, NULL);
3924 gtk_menu_hide_all (GtkWidget *widget)
3926 /* Hide children, but not self. */
3927 gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_hide_all, NULL);
3931 * gtk_menu_set_screen:
3932 * @menu: a #GtkMenu.
3933 * @screen: a #GdkScreen, or %NULL if the screen should be
3934 * determined by the widget the menu is attached to.
3936 * Sets the #GdkScreen on which the menu will be displayed.
3941 gtk_menu_set_screen (GtkMenu *menu,
3944 g_return_if_fail (GTK_IS_MENU (menu));
3945 g_return_if_fail (!screen || GDK_IS_SCREEN (screen));
3947 g_object_set_data (G_OBJECT (menu), "gtk-menu-explicit-screen", screen);
3951 menu_change_screen (menu, screen);
3955 GtkWidget *attach_widget = gtk_menu_get_attach_widget (menu);
3957 attach_widget_screen_changed (attach_widget, NULL, menu);
3963 * @menu: a #GtkMenu.
3964 * @child: a #GtkMenuItem.
3965 * @left_attach: The column number to attach the left side of the item to.
3966 * @right_attach: The column number to attach the right side of the item to.
3967 * @top_attach: The row number to attach the top of the item to.
3968 * @bottom_attach: The row number to attach the bottom of the item to.
3970 * Adds a new #GtkMenuItem to a (table) menu. The number of 'cells' that
3971 * an item will occupy is specified by @left_attach, @right_attach,
3972 * @top_attach and @bottom_attach. These each represent the leftmost,
3973 * rightmost, uppermost and lower column and row numbers of the table.
3974 * (Columns and rows are indexed from zero).
3976 * Note that this function is not related to gtk_menu_detach().
3981 gtk_menu_attach (GtkMenu *menu,
3986 guint bottom_attach)
3988 GtkMenuShell *menu_shell;
3990 g_return_if_fail (GTK_IS_MENU (menu));
3991 g_return_if_fail (GTK_IS_MENU_ITEM (child));
3992 g_return_if_fail (child->parent == NULL ||
3993 child->parent == GTK_WIDGET (menu));
3994 g_return_if_fail (left_attach < right_attach);
3995 g_return_if_fail (top_attach < bottom_attach);
3997 menu_shell = GTK_MENU_SHELL (menu);
4001 AttachInfo *ai = get_attach_info (child);
4003 ai->left_attach = left_attach;
4004 ai->right_attach = right_attach;
4005 ai->top_attach = top_attach;
4006 ai->bottom_attach = bottom_attach;
4008 menu_shell->children = g_list_append (menu_shell->children, child);
4010 gtk_widget_set_parent (child, GTK_WIDGET (menu));
4012 menu_queue_resize (menu);
4016 gtk_container_child_set (GTK_CONTAINER (child->parent), child,
4017 "left_attach", left_attach,
4018 "right_attach", right_attach,
4019 "top_attach", top_attach,
4020 "bottom_attach", bottom_attach,
4026 gtk_menu_get_popup_delay (GtkMenuShell *menu_shell)
4030 g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
4031 "gtk-menu-popup-delay", &popup_delay,
4038 find_child_containing (GtkMenuShell *menu_shell,
4046 /* find a child which includes the area given by
4047 * left, right, top, bottom.
4050 for (list = menu_shell->children; list; list = list->next)
4054 if (!_gtk_menu_item_is_selectable (list->data))
4057 get_effective_child_attach (list->data, &l, &r, &t, &b);
4059 if (l <= left && right <= r
4060 && t <= top && bottom <= b)
4061 return GTK_WIDGET (list->data);
4068 gtk_menu_move_current (GtkMenuShell *menu_shell,
4069 GtkMenuDirectionType direction)
4071 GtkMenu *menu = GTK_MENU (menu_shell);
4074 GtkWidget *match = NULL;
4076 if (gtk_widget_get_direction (GTK_WIDGET (menu_shell)) == GTK_TEXT_DIR_RTL)
4080 case GTK_MENU_DIR_CHILD:
4081 direction = GTK_MENU_DIR_PARENT;
4083 case GTK_MENU_DIR_PARENT:
4084 direction = GTK_MENU_DIR_CHILD;
4090 /* use special table menu key bindings */
4091 if (menu_shell->active_menu_item && gtk_menu_get_n_columns (menu) > 1)
4093 get_effective_child_attach (menu_shell->active_menu_item, &l, &r, &t, &b);
4095 if (direction == GTK_MENU_DIR_NEXT)
4097 for (i = b; i < gtk_menu_get_n_rows (menu); i++)
4099 match = find_child_containing (menu_shell, l, l + 1, i, i + 1);
4107 for (i = 0; i < t; i++)
4109 match = find_child_containing (menu_shell,
4110 l, l + 1, i, i + 1);
4116 else if (direction == GTK_MENU_DIR_PREV)
4118 for (i = t; i > 0; i--)
4120 match = find_child_containing (menu_shell, l, l + 1, i - 1, i);
4128 for (i = gtk_menu_get_n_rows (menu); i > b; i--)
4130 match = find_child_containing (menu_shell,
4131 l, l + 1, i - 1, i);
4137 else if (direction == GTK_MENU_DIR_PARENT)
4139 /* we go one left if possible */
4141 match = find_child_containing (menu_shell, l - 1, l, t, t + 1);
4145 GtkWidget *parent = menu_shell->parent_menu_shell;
4148 || g_list_length (GTK_MENU_SHELL (parent)->children) <= 1)
4149 match = menu_shell->active_menu_item;
4152 else if (direction == GTK_MENU_DIR_CHILD)
4154 /* we go one right if possible */
4155 if (r < gtk_menu_get_n_columns (menu))
4156 match = find_child_containing (menu_shell, r, r + 1, t, t + 1);
4160 GtkWidget *parent = menu_shell->parent_menu_shell;
4162 if (! GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu &&
4164 g_list_length (GTK_MENU_SHELL (parent)->children) <= 1))
4165 match = menu_shell->active_menu_item;
4171 gtk_menu_shell_select_item (menu_shell, match);
4176 GTK_MENU_SHELL_CLASS (parent_class)->move_current (menu_shell, direction);
4180 get_visible_size (GtkMenu *menu)
4182 GtkWidget *widget = GTK_WIDGET (menu);
4183 GtkContainer *container = GTK_CONTAINER (menu);
4185 gint menu_height = (widget->allocation.height
4186 - 2 * (container->border_width
4187 + widget->style->ythickness));
4189 if (menu->upper_arrow_visible && !menu->tearoff_active)
4190 menu_height -= MENU_SCROLL_ARROW_HEIGHT;
4191 if (menu->lower_arrow_visible && !menu->tearoff_active)
4192 menu_height -= MENU_SCROLL_ARROW_HEIGHT;
4197 /* Find the sensitive on-screen child containing @y, or if none,
4198 * the nearest selectable onscreen child. (%NULL if none)
4201 child_at (GtkMenu *menu,
4204 GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
4205 GtkWidget *child = NULL;
4206 gint child_offset = 0;
4209 gint lower, upper; /* Onscreen bounds */
4211 menu_height = get_visible_size (menu);
4212 lower = menu->scroll_offset;
4213 upper = menu->scroll_offset + menu_height;
4215 for (children = menu_shell->children; children; children = children->next)
4217 if (GTK_WIDGET_VISIBLE (children->data))
4219 GtkRequisition child_requisition;
4221 gtk_widget_size_request (children->data, &child_requisition);
4223 if (_gtk_menu_item_is_selectable (children->data) &&
4224 child_offset >= lower &&
4225 child_offset + child_requisition.height <= upper)
4227 child = children->data;
4229 if (child_offset + child_requisition.height > y &&
4230 !GTK_IS_TEAROFF_MENU_ITEM (child))
4234 child_offset += child_requisition.height;
4242 get_menu_height (GtkMenu *menu)
4245 GtkWidget *widget = GTK_WIDGET (menu);
4247 height = widget->requisition.height;
4248 height -= (GTK_CONTAINER (widget)->border_width + widget->style->ythickness) * 2;
4250 if (menu->upper_arrow_visible && !menu->tearoff_active)
4251 height -= MENU_SCROLL_ARROW_HEIGHT;
4253 if (menu->lower_arrow_visible && !menu->tearoff_active)
4254 height -= MENU_SCROLL_ARROW_HEIGHT;
4260 gtk_menu_real_move_scroll (GtkMenu *menu,
4263 gint page_size = get_visible_size (menu);
4264 gint end_position = get_menu_height (menu);
4265 GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
4269 case GTK_SCROLL_PAGE_UP:
4270 case GTK_SCROLL_PAGE_DOWN:
4274 gint child_offset = 0;
4275 gboolean old_upper_arrow_visible;
4278 if (type == GTK_SCROLL_PAGE_UP)
4283 if (menu_shell->active_menu_item)
4287 compute_child_offset (menu, menu_shell->active_menu_item,
4288 &child_offset, &child_height, NULL);
4289 child_offset += child_height / 2;
4292 menu_shell->ignore_enter = TRUE;
4293 old_upper_arrow_visible = menu->upper_arrow_visible && !menu->tearoff_active;
4294 old_offset = menu->scroll_offset;
4296 new_offset = menu->scroll_offset + step;
4297 new_offset = CLAMP (new_offset, 0, end_position - page_size);
4299 gtk_menu_scroll_to (menu, new_offset);
4301 if (menu_shell->active_menu_item)
4303 GtkWidget *new_child;
4304 gboolean new_upper_arrow_visible = menu->upper_arrow_visible && !menu->tearoff_active;
4306 if (menu->scroll_offset != old_offset)
4307 step = menu->scroll_offset - old_offset;
4309 step -= (new_upper_arrow_visible - old_upper_arrow_visible) * MENU_SCROLL_ARROW_HEIGHT;
4311 new_child = child_at (menu, child_offset + step);
4313 gtk_menu_shell_select_item (menu_shell, new_child);
4317 case GTK_SCROLL_START:
4318 /* Ignore the enter event we might get if the pointer is on the menu
4320 menu_shell->ignore_enter = TRUE;
4321 gtk_menu_scroll_to (menu, 0);
4322 gtk_menu_shell_select_first (menu_shell, TRUE);
4324 case GTK_SCROLL_END:
4325 /* Ignore the enter event we might get if the pointer is on the menu
4327 menu_shell->ignore_enter = TRUE;
4328 gtk_menu_scroll_to (menu, end_position - page_size);
4329 _gtk_menu_shell_select_last (menu_shell, TRUE);
4338 * gtk_menu_set_monitor:
4340 * @monitor_num: the number of the monitor on which the menu should
4343 * Informs GTK+ on which monitor a menu should be popped up.
4344 * See gdk_screen_get_monitor_geometry().
4346 * This function should be called from a #GtkMenuPositionFunc if the
4347 * menu should not appear on the same monitor as the pointer. This
4348 * information can't be reliably inferred from the coordinates returned
4349 * by a #GtkMenuPositionFunc, since, for very long menus, these coordinates
4350 * may extend beyond the monitor boundaries or even the screen boundaries.
4355 gtk_menu_set_monitor (GtkMenu *menu,
4358 GtkMenuPrivate *priv;
4359 g_return_if_fail (GTK_IS_MENU (menu));
4361 priv = gtk_menu_get_private (menu);
4363 priv->monitor_num = monitor_num;
4367 * gtk_menu_get_for_attach_widget:
4368 * @widget: a #GtkWidget
4370 * Returns a list of the menus which are attached to this widget.
4371 * This list is owned by GTK+ and must not be modified.
4373 * Return value: the list of menus attached to his widget.
4378 gtk_menu_get_for_attach_widget (GtkWidget *widget)
4382 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4384 list = g_object_get_data (G_OBJECT (widget), ATTACHED_MENUS);
4388 #define __GTK_MENU_C__
4389 #include "gtkaliasdef.c"