*/
#define GTK_MENU_INTERNALS
-
+#include <config.h>
#include <string.h> /* memset */
#include "gdk/gdkkeysyms.h"
#include "gtkaccellabel.h"
#include "gtkhbox.h"
#include "gtkvscrollbar.h"
#include "gtksettings.h"
+#include "gtkprivate.h"
#include "gtkintl.h"
+#include "gtkalias.h"
#define MENU_ITEM_CLASS(w) GTK_MENU_ITEM_GET_CLASS (w)
-#define MENU_NEEDS_RESIZE(m) GTK_MENU_SHELL (m)->menu_flag
#define DEFAULT_POPUP_DELAY 225
#define DEFAULT_POPDOWN_DELAY 1000
#define MENU_SCROLL_STEP1 8
#define MENU_SCROLL_STEP2 15
-#define MENU_SCROLL_ARROW_HEIGHT 16
#define MENU_SCROLL_FAST_ZONE 8
#define MENU_SCROLL_TIMEOUT1 50
-#define MENU_SCROLL_TIMEOUT2 50
+#define MENU_SCROLL_TIMEOUT2 20
#define ATTACH_INFO_KEY "gtk-menu-child-attach-info-key"
+#define ATTACHED_MENUS "gtk-attached-menus"
typedef struct _GtkMenuAttachData GtkMenuAttachData;
typedef struct _GtkMenuPrivate GtkMenuPrivate;
struct _GtkMenuPrivate
{
+ gboolean seen_item_enter;
+
gboolean have_position;
gint x;
gint y;
/* info used for the table */
- guint rows;
- guint columns;
-
guint *heights;
gint heights_length;
gint monitor_num;
+
+ /* Cached layout information */
+ gboolean have_layout;
+ gint n_rows;
+ gint n_columns;
+
+ gchar *title;
+
+ /* Arrow states */
+ GtkStateType lower_arrow_state;
+ GtkStateType upper_arrow_state;
+
+ gboolean ignore_button_release;
+ gboolean initially_pushed_in;
};
typedef struct
{
- guint left_attach;
- guint right_attach;
- guint top_attach;
- guint bottom_attach;
-}
-AttachInfo;
+ gint left_attach;
+ gint right_attach;
+ gint top_attach;
+ gint bottom_attach;
+ gint effective_left_attach;
+ gint effective_right_attach;
+ gint effective_top_attach;
+ gint effective_bottom_attach;
+} AttachInfo;
enum {
MOVE_SCROLL,
enum {
PROP_0,
+ PROP_TEAROFF_STATE,
PROP_TEAROFF_TITLE
};
-enum
-{
+enum {
CHILD_PROP_0,
CHILD_PROP_LEFT_ATTACH,
CHILD_PROP_RIGHT_ATTACH,
CHILD_PROP_BOTTOM_ATTACH
};
-static void gtk_menu_class_init (GtkMenuClass *klass);
-static void gtk_menu_init (GtkMenu *menu);
static void gtk_menu_set_property (GObject *object,
guint prop_id,
const GValue *value,
GdkEventExpose *event);
static gboolean gtk_menu_key_press (GtkWidget *widget,
GdkEventKey *event);
+static gboolean gtk_menu_scroll (GtkWidget *widget,
+ GdkEventScroll *event);
static gboolean gtk_menu_button_press (GtkWidget *widget,
GdkEventButton *event);
static gboolean gtk_menu_button_release (GtkWidget *widget,
GdkEventCrossing *event);
static void gtk_menu_scroll_to (GtkMenu *menu,
gint offset);
+static void gtk_menu_grab_notify (GtkWidget *widget,
+ gboolean was_grabbed);
-static void gtk_menu_stop_scrolling (GtkMenu *menu);
-static void gtk_menu_remove_scroll_timeout (GtkMenu *menu);
-static gboolean gtk_menu_scroll_timeout (gpointer data);
+static void gtk_menu_stop_scrolling (GtkMenu *menu);
+static void gtk_menu_remove_scroll_timeout (GtkMenu *menu);
+static gboolean gtk_menu_scroll_timeout (gpointer data);
+static gboolean gtk_menu_scroll_timeout_initial (gpointer data);
+static void gtk_menu_start_scrolling (GtkMenu *menu);
static void gtk_menu_scroll_item_visible (GtkMenuShell *menu_shell,
GtkWidget *menu_item);
static void gtk_menu_select_item (GtkMenuShell *menu_shell,
GtkWidget *menu_item);
-static void gtk_menu_do_insert (GtkMenuShell *menu_shell,
- GtkWidget *child,
- gint position);
static void gtk_menu_real_insert (GtkMenuShell *menu_shell,
GtkWidget *child,
gint position);
static void gtk_menu_scrollbar_changed (GtkAdjustment *adjustment,
GtkMenu *menu);
static void gtk_menu_handle_scrolling (GtkMenu *menu,
- gboolean enter);
+ gint event_x,
+ gint event_y,
+ gboolean enter,
+ gboolean motion);
static void gtk_menu_set_tearoff_hints (GtkMenu *menu,
gint width);
static void gtk_menu_style_set (GtkWidget *widget,
static void _gtk_menu_refresh_accel_paths (GtkMenu *menu,
gboolean group_changed);
-static GtkMenuShellClass *parent_class = NULL;
-static const gchar *attach_data_key = "gtk-menu-attach-data";
+static const gchar attach_data_key[] = "gtk-menu-attach-data";
static guint menu_signals[LAST_SIGNAL] = { 0 };
-static void
-gtk_menu_free_private (gpointer data)
+static GtkMenuPrivate *
+gtk_menu_get_private (GtkMenu *menu)
{
- GtkMenuPrivate *priv = (GtkMenuPrivate *)data;
-
- g_free (priv->heights);
-
- g_free (priv);
+ return G_TYPE_INSTANCE_GET_PRIVATE (menu, GTK_TYPE_MENU, GtkMenuPrivate);
}
-GtkMenuPrivate *
-gtk_menu_get_private (GtkMenu *menu)
+G_DEFINE_TYPE (GtkMenu, gtk_menu, GTK_TYPE_MENU_SHELL)
+
+static void
+menu_queue_resize (GtkMenu *menu)
{
- GtkMenuPrivate *private;
- static GQuark private_quark = 0;
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
- if (!private_quark)
- private_quark = g_quark_from_static_string ("gtk-menu-private");
+ priv->have_layout = FALSE;
+ gtk_widget_queue_resize (GTK_WIDGET (menu));
+}
- private = g_object_get_qdata (G_OBJECT (menu), private_quark);
+static AttachInfo *
+get_attach_info (GtkWidget *child)
+{
+ GObject *object = G_OBJECT (child);
+ AttachInfo *ai = g_object_get_data (object, ATTACH_INFO_KEY);
- if (!private)
+ if (!ai)
{
- private = g_new0 (GtkMenuPrivate, 1);
- private->have_position = FALSE;
-
- g_object_set_qdata_full (G_OBJECT (menu), private_quark,
- private, gtk_menu_free_private);
+ ai = g_new0 (AttachInfo, 1);
+ g_object_set_data_full (object, I_(ATTACH_INFO_KEY), ai, g_free);
}
- return private;
+ return ai;
}
-GType
-gtk_menu_get_type (void)
+static gboolean
+is_grid_attached (AttachInfo *ai)
{
- static GType menu_type = 0;
-
- if (!menu_type)
+ return (ai->left_attach >= 0 &&
+ ai->right_attach >= 0 &&
+ ai->top_attach >= 0 &&
+ ai->bottom_attach >= 0);
+}
+
+static void
+menu_ensure_layout (GtkMenu *menu)
+{
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+
+ if (!priv->have_layout)
{
- static const GTypeInfo menu_info =
- {
- sizeof (GtkMenuClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_menu_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkMenu),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_menu_init,
- };
-
- menu_type = g_type_register_static (GTK_TYPE_MENU_SHELL, "GtkMenu",
- &menu_info, 0);
+ GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
+ GList *l;
+ gchar *row_occupied;
+ gint current_row;
+ gint max_right_attach;
+ gint max_bottom_attach;
+
+ /* Find extents of gridded portion
+ */
+ max_right_attach = 1;
+ max_bottom_attach = 0;
+
+ for (l = menu_shell->children; l; l = l->next)
+ {
+ GtkWidget *child = l->data;
+ AttachInfo *ai = get_attach_info (child);
+
+ if (is_grid_attached (ai))
+ {
+ max_bottom_attach = MAX (max_bottom_attach, ai->bottom_attach);
+ max_right_attach = MAX (max_right_attach, ai->right_attach);
+ }
+ }
+
+ /* Find empty rows
+ */
+ row_occupied = g_malloc0 (max_bottom_attach);
+
+ for (l = menu_shell->children; l; l = l->next)
+ {
+ GtkWidget *child = l->data;
+ AttachInfo *ai = get_attach_info (child);
+
+ if (is_grid_attached (ai))
+ {
+ gint i;
+
+ for (i = ai->top_attach; i < ai->bottom_attach; i++)
+ row_occupied[i] = TRUE;
+ }
+ }
+
+ /* Lay non-grid-items out in those rows
+ */
+ current_row = 0;
+ for (l = menu_shell->children; l; l = l->next)
+ {
+ GtkWidget *child = l->data;
+ AttachInfo *ai = get_attach_info (child);
+
+ if (!is_grid_attached (ai))
+ {
+ while (current_row < max_bottom_attach && row_occupied[current_row])
+ current_row++;
+
+ ai->effective_left_attach = 0;
+ ai->effective_right_attach = max_right_attach;
+ ai->effective_top_attach = current_row;
+ ai->effective_bottom_attach = current_row + 1;
+
+ current_row++;
+ }
+ else
+ {
+ ai->effective_left_attach = ai->left_attach;
+ ai->effective_right_attach = ai->right_attach;
+ ai->effective_top_attach = ai->top_attach;
+ ai->effective_bottom_attach = ai->bottom_attach;
+ }
+ }
+
+ g_free (row_occupied);
+
+ priv->n_rows = MAX (current_row, max_bottom_attach);
+ priv->n_columns = max_right_attach;
+ priv->have_layout = TRUE;
}
+}
+
+
+static gint
+gtk_menu_get_n_columns (GtkMenu *menu)
+{
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+
+ menu_ensure_layout (menu);
+
+ return priv->n_columns;
+}
+
+static gint
+gtk_menu_get_n_rows (GtkMenu *menu)
+{
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+
+ menu_ensure_layout (menu);
+
+ return priv->n_rows;
+}
+
+static void
+get_effective_child_attach (GtkWidget *child,
+ int *l,
+ int *r,
+ int *t,
+ int *b)
+{
+ GtkMenu *menu = GTK_MENU (child->parent);
+ AttachInfo *ai;
- return menu_type;
+ menu_ensure_layout (menu);
+
+ ai = get_attach_info (child);
+
+ if (l)
+ *l = ai->effective_left_attach;
+ if (r)
+ *r = ai->effective_right_attach;
+ if (t)
+ *t = ai->effective_top_attach;
+ if (b)
+ *b = ai->effective_bottom_attach;
+
}
static void
GtkMenuShellClass *menu_shell_class = GTK_MENU_SHELL_CLASS (class);
GtkBindingSet *binding_set;
- parent_class = g_type_class_peek_parent (class);
-
gobject_class->finalize = gtk_menu_finalize;
gobject_class->set_property = gtk_menu_set_property;
gobject_class->get_property = gtk_menu_get_property;
widget_class->size_allocate = gtk_menu_size_allocate;
widget_class->show = gtk_menu_show;
widget_class->expose_event = gtk_menu_expose;
+ widget_class->scroll_event = gtk_menu_scroll;
widget_class->key_press_event = gtk_menu_key_press;
widget_class->button_press_event = gtk_menu_button_press;
widget_class->button_release_event = gtk_menu_button_release;
widget_class->hide_all = gtk_menu_hide_all;
widget_class->enter_notify_event = gtk_menu_enter_notify;
widget_class->leave_notify_event = gtk_menu_leave_notify;
- widget_class->motion_notify_event = gtk_menu_motion_notify;
widget_class->style_set = gtk_menu_style_set;
widget_class->focus = gtk_menu_focus;
widget_class->can_activate_accel = gtk_menu_real_can_activate_accel;
+ widget_class->grab_notify = gtk_menu_grab_notify;
container_class->remove = gtk_menu_remove;
container_class->get_child_property = gtk_menu_get_child_property;
menu_shell_class->move_current = gtk_menu_move_current;
menu_signals[MOVE_SCROLL] =
- _gtk_binding_signal_new ("move_scroll",
+ _gtk_binding_signal_new (I_("move_scroll"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_CALLBACK (gtk_menu_real_move_scroll),
P_("Tearoff Title"),
P_("A title that may be displayed by the window manager when this menu is torn-off"),
"",
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkMenu:tearoff-state:
+ *
+ * A boolean that indicates whether the menu is torn-off.
+ *
+ * Since: 2.6
+ **/
+ g_object_class_install_property (gobject_class,
+ PROP_TEAROFF_STATE,
+ g_param_spec_boolean ("tearoff-state",
+ P_("Tearoff State"),
+ P_("A boolean that indicates whether the menu is torn-off"),
+ FALSE,
+ GTK_PARAM_READWRITE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("vertical-padding",
0,
G_MAXINT,
1,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
+
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_int ("horizontal-padding",
+ P_("Horizontal Padding"),
+ P_("Extra space at the left and right edges of the menu"),
+ 0,
+ G_MAXINT,
+ 0,
+ GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("vertical-offset",
G_MININT,
G_MAXINT,
0,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("horizontal-offset",
G_MININT,
G_MAXINT,
-2,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
+
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_boolean ("double-arrows",
+ P_("Double Arrows"),
+ P_("When scrolling, always show both arrows."),
+ TRUE,
+ GTK_PARAM_READABLE));
gtk_container_class_install_child_property (container_class,
CHILD_PROP_LEFT_ATTACH,
- g_param_spec_uint ("left_attach",
+ g_param_spec_int ("left-attach",
P_("Left Attach"),
P_("The column number to attach the left side of the child to"),
- 0, UINT_MAX, 0,
- G_PARAM_READWRITE));
+ -1, INT_MAX, -1,
+ GTK_PARAM_READWRITE));
gtk_container_class_install_child_property (container_class,
CHILD_PROP_RIGHT_ATTACH,
- g_param_spec_uint ("right_attach",
+ g_param_spec_int ("right-attach",
P_("Right Attach"),
P_("The column number to attach the right side of the child to"),
- 0, UINT_MAX, 0,
- G_PARAM_READWRITE));
+ -1, INT_MAX, -1,
+ GTK_PARAM_READWRITE));
gtk_container_class_install_child_property (container_class,
CHILD_PROP_TOP_ATTACH,
- g_param_spec_uint ("top_attach",
+ g_param_spec_int ("top-attach",
P_("Top Attach"),
P_("The row number to attach the top of the child to"),
- 0, UINT_MAX, 0,
- G_PARAM_READWRITE));
+ -1, INT_MAX, -1,
+ GTK_PARAM_READWRITE));
gtk_container_class_install_child_property (container_class,
CHILD_PROP_BOTTOM_ATTACH,
- g_param_spec_uint ("bottom_attach",
+ g_param_spec_int ("bottom-attach",
P_("Bottom Attach"),
P_("The row number to attach the bottom of the child to"),
- 0, UINT_MAX, 0,
- G_PARAM_READWRITE));
+ -1, INT_MAX, -1,
+ GTK_PARAM_READWRITE));
binding_set = gtk_binding_set_by_class (class);
gtk_binding_entry_add_signal (binding_set,
GDK_Up, 0,
- "move_current", 1,
+ I_("move_current"), 1,
GTK_TYPE_MENU_DIRECTION_TYPE,
GTK_MENU_DIR_PREV);
gtk_binding_entry_add_signal (binding_set,
P_("Can change accelerators"),
P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
FALSE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
gtk_settings_install_property (g_param_spec_int ("gtk-menu-popup-delay",
P_("Delay before submenus appear"),
0,
G_MAXINT,
DEFAULT_POPUP_DELAY,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
gtk_settings_install_property (g_param_spec_int ("gtk-menu-popdown-delay",
P_("Delay before hiding a submenu"),
0,
G_MAXINT,
DEFAULT_POPDOWN_DELAY,
- G_PARAM_READWRITE));
-
+ GTK_PARAM_READWRITE));
+
+ g_type_class_add_private (gobject_class, sizeof (GtkMenuPrivate));
}
switch (prop_id)
{
+ case PROP_TEAROFF_STATE:
+ gtk_menu_set_tearoff_state (menu, g_value_get_boolean (value));
+ break;
case PROP_TEAROFF_TITLE:
gtk_menu_set_title (menu, g_value_get_string (value));
break;
switch (prop_id)
{
+ case PROP_TEAROFF_STATE:
+ g_value_set_boolean (value, gtk_menu_get_tearoff_state (menu));
+ break;
case PROP_TEAROFF_TITLE:
g_value_set_string (value, gtk_menu_get_title (menu));
break;
}
}
-static AttachInfo *
-get_attach_info (GObject *child)
-{
- AttachInfo *ai = g_object_get_data (child, ATTACH_INFO_KEY);
-
- if (!ai)
- {
- ai = g_new0 (AttachInfo, 1);
- g_object_set_data_full (child, ATTACH_INFO_KEY, ai, g_free);
- }
-
- return ai;
-}
-
static void
gtk_menu_set_child_property (GtkContainer *container,
GtkWidget *child,
GParamSpec *pspec)
{
GtkMenu *menu = GTK_MENU (container);
- GtkMenuPrivate *priv;
- AttachInfo *ai = get_attach_info (G_OBJECT (child));
-
- priv = gtk_menu_get_private (menu);
+ AttachInfo *ai = get_attach_info (child);
switch (property_id)
{
- case CHILD_PROP_LEFT_ATTACH:
- ai->left_attach = g_value_get_uint (value);
- break;
- case CHILD_PROP_RIGHT_ATTACH:
- ai->right_attach = g_value_get_uint (value);
- priv->columns = MAX (priv->columns, ai->right_attach);
- break;
- case CHILD_PROP_TOP_ATTACH:
- ai->top_attach = g_value_get_uint (value);
- break;
- case CHILD_PROP_BOTTOM_ATTACH:
- ai->bottom_attach = g_value_get_uint (value);
- priv->rows = MAX (priv->rows, ai->bottom_attach);
- break;
- default:
- GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
- return;
+ case CHILD_PROP_LEFT_ATTACH:
+ ai->left_attach = g_value_get_int (value);
+ break;
+ case CHILD_PROP_RIGHT_ATTACH:
+ ai->right_attach = g_value_get_int (value);
+ break;
+ case CHILD_PROP_TOP_ATTACH:
+ ai->top_attach = g_value_get_int (value);
+ break;
+ case CHILD_PROP_BOTTOM_ATTACH:
+ ai->bottom_attach = g_value_get_int (value);
+ break;
+
+ default:
+ GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
+ return;
}
- gtk_widget_queue_resize (GTK_WIDGET (menu));
+ menu_queue_resize (menu);
}
static void
GValue *value,
GParamSpec *pspec)
{
- AttachInfo *ai = get_attach_info (G_OBJECT (child));
+ AttachInfo *ai = get_attach_info (child);
switch (property_id)
{
- case CHILD_PROP_LEFT_ATTACH:
- g_value_set_uint (value, ai->left_attach);
- break;
- case CHILD_PROP_RIGHT_ATTACH:
- g_value_set_uint (value, ai->right_attach);
- break;
- case CHILD_PROP_TOP_ATTACH:
- g_value_set_uint (value, ai->top_attach);
- break;
- case CHILD_PROP_BOTTOM_ATTACH:
- g_value_set_uint (value, ai->bottom_attach);
- break;
-
- default:
- GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
- return;
+ case CHILD_PROP_LEFT_ATTACH:
+ g_value_set_int (value, ai->left_attach);
+ break;
+ case CHILD_PROP_RIGHT_ATTACH:
+ g_value_set_int (value, ai->right_attach);
+ break;
+ case CHILD_PROP_TOP_ATTACH:
+ g_value_set_int (value, ai->top_attach);
+ break;
+ case CHILD_PROP_BOTTOM_ATTACH:
+ g_value_set_int (value, ai->bottom_attach);
+ break;
+
+ default:
+ GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
+ return;
}
}
-static void
-get_child_attach (GtkWidget *child,
- gint *l,
- gint *r,
- gint *t,
- gint *b)
-{
- gtk_container_child_get (GTK_CONTAINER (child->parent), child,
- "left_attach", l,
- "right_attach", r,
- "top_attach", t,
- "bottom_attach", b,
- NULL);
-}
-
static gboolean
gtk_menu_window_event (GtkWidget *window,
GdkEvent *event,
static void
gtk_menu_init (GtkMenu *menu)
{
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+
menu->parent_menu_item = NULL;
menu->old_active_menu_item = NULL;
menu->accel_group = NULL;
/* Refloat the menu, so that reference counting for the menu isn't
* affected by it being a child of the toplevel
*/
- GTK_WIDGET_SET_FLAGS (menu, GTK_FLOATING);
+ g_object_force_floating (G_OBJECT (menu));
menu->needs_destruction_ref_count = TRUE;
menu->view_window = NULL;
menu->lower_arrow_visible = FALSE;
menu->upper_arrow_prelight = FALSE;
menu->lower_arrow_prelight = FALSE;
-
- MENU_NEEDS_RESIZE (menu) = TRUE;
+
+ priv->upper_arrow_state = GTK_STATE_NORMAL;
+ priv->lower_arrow_state = GTK_STATE_NORMAL;
+
+ priv->have_layout = FALSE;
}
static void
{
GtkMenu *menu;
GtkMenuAttachData *data;
+ GtkMenuPrivate *priv;
g_return_if_fail (GTK_IS_MENU (object));
menu = GTK_MENU (object);
- gtk_menu_stop_scrolling (menu);
+ gtk_menu_remove_scroll_timeout (menu);
data = g_object_get_data (G_OBJECT (object), attach_data_key);
if (data)
if (menu->toplevel)
gtk_widget_destroy (menu->toplevel);
+
if (menu->tearoff_window)
gtk_widget_destroy (menu->tearoff_window);
- GTK_OBJECT_CLASS (parent_class)->destroy (object);
+ priv = gtk_menu_get_private (menu);
+
+ if (priv->heights)
+ {
+ g_free (priv->heights);
+ priv->heights = NULL;
+ }
+
+ if (priv->title)
+ {
+ g_free (priv->title);
+ priv->title = NULL;
+ }
+
+ GTK_OBJECT_CLASS (gtk_menu_parent_class)->destroy (object);
}
static void
g_free (menu->accel_path);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_menu_parent_class)->finalize (object);
}
static void
{
GtkMenuPrivate *private = gtk_menu_get_private (menu);
+ if (gtk_widget_has_screen (GTK_WIDGET (menu)))
+ {
+ if (new_screen == gtk_widget_get_screen (GTK_WIDGET (menu)))
+ return;
+ }
+
if (menu->torn_off)
{
gtk_window_set_screen (GTK_WINDOW (menu->tearoff_window), new_screen);
GtkMenuDetachFunc detacher)
{
GtkMenuAttachData *data;
+ GList *list;
g_return_if_fail (GTK_IS_MENU (menu));
g_return_if_fail (GTK_IS_WIDGET (attach_widget));
- g_return_if_fail (detacher != NULL);
/* keep this function in sync with gtk_widget_set_parent()
*/
return;
}
- g_object_ref (menu);
- gtk_object_sink (GTK_OBJECT (menu));
+ g_object_ref_sink (menu);
data = g_new (GtkMenuAttachData, 1);
data->attach_widget = attach_widget;
attach_widget_screen_changed (attach_widget, NULL, menu);
data->detacher = detacher;
- g_object_set_data (G_OBJECT (menu), attach_data_key, data);
+ g_object_set_data (G_OBJECT (menu), I_(attach_data_key), data);
+ list = g_object_steal_data (G_OBJECT (attach_widget), ATTACHED_MENUS);
+ if (!g_list_find (list, menu))
+ {
+ list = g_list_prepend (list, menu);
+ }
+ g_object_set_data_full (G_OBJECT (attach_widget), I_(ATTACHED_MENUS), list, (GtkDestroyNotify) g_list_free);
if (GTK_WIDGET_STATE (menu) != GTK_STATE_NORMAL)
gtk_widget_set_state (GTK_WIDGET (menu), GTK_STATE_NORMAL);
gtk_menu_detach (GtkMenu *menu)
{
GtkMenuAttachData *data;
+ GList *list;
g_return_if_fail (GTK_IS_MENU (menu));
g_warning ("gtk_menu_detach(): menu is not attached");
return;
}
- g_object_set_data (G_OBJECT (menu), attach_data_key, NULL);
+ g_object_set_data (G_OBJECT (menu), I_(attach_data_key), NULL);
g_signal_handlers_disconnect_by_func (data->attach_widget,
(gpointer) attach_widget_screen_changed,
menu);
- data->detacher (data->attach_widget, menu);
+ if (data->detacher)
+ data->detacher (data->attach_widget, menu);
+ list = g_object_steal_data (G_OBJECT (data->attach_widget), ATTACHED_MENUS);
+ list = g_list_remove (list, menu);
+ if (list)
+ g_object_set_data_full (G_OBJECT (data->attach_widget), I_(ATTACHED_MENUS), list, (GtkDestroyNotify) g_list_free);
+ else
+ g_object_set_data (G_OBJECT (data->attach_widget), I_(ATTACHED_MENUS), NULL);
if (GTK_WIDGET_REALIZED (menu))
gtk_widget_unrealize (GTK_WIDGET (menu));
}
static void
-gtk_menu_do_remove (GtkMenuShell *menu_shell,
- GtkWidget *child)
-{
- AttachInfo *ai;
- GList *children;
- GtkMenuPrivate *priv;
- gint delta;
- gboolean single_column;
-
- ai = get_attach_info (G_OBJECT (child));
- priv = gtk_menu_get_private (GTK_MENU (menu_shell));
- delta = ai->bottom_attach - ai->top_attach;
- single_column = priv->columns == 1;
-
- /* Recalculate these, assuming the child has already been removed.
- * Note that an empty menu is assumed to have one column.
- */
- priv->rows = 0;
- priv->columns = 1;
-
- for (children = menu_shell->children; children; children = children->next)
- {
- AttachInfo *child_ai = get_attach_info (children->data);
-
- /* Do not move items in table menus */
- if (single_column && child_ai->bottom_attach > ai->bottom_attach)
- gtk_container_child_set (GTK_CONTAINER (menu_shell), children->data,
- "top_attach", child_ai->top_attach - delta,
- "bottom_attach", child_ai->bottom_attach - delta,
- NULL);
- else
- {
- priv->columns = MAX (priv->columns, child_ai->right_attach);
- priv->rows = MAX (priv->rows, child_ai->bottom_attach);
- }
- }
-}
-
-static void
gtk_menu_remove (GtkContainer *container,
GtkWidget *widget)
{
menu->old_active_menu_item = NULL;
}
- GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
- gtk_menu_do_remove (GTK_MENU_SHELL (container), widget);
- g_object_set_data (G_OBJECT (widget), ATTACH_INFO_KEY, NULL);
-}
+ GTK_CONTAINER_CLASS (gtk_menu_parent_class)->remove (container, widget);
+ g_object_set_data (G_OBJECT (widget), I_(ATTACH_INFO_KEY), NULL);
+ menu_queue_resize (menu);
+}
GtkWidget*
gtk_menu_new (void)
}
static void
-gtk_menu_do_insert (GtkMenuShell *menu_shell,
- GtkWidget *child,
- gint position)
+gtk_menu_real_insert (GtkMenuShell *menu_shell,
+ GtkWidget *child,
+ gint position)
{
- GList *children;
- GtkMenuPrivate *priv;
-
- priv = gtk_menu_get_private (GTK_MENU (menu_shell));
-
- if (position < 0 || position >= priv->rows)
- {
- /* attach after the last row */
- gtk_menu_attach (GTK_MENU (menu_shell), child,
- 0, priv->columns,
- priv->rows, priv->rows + 1);
-
- return;
- }
-
- /* We need to make space for this new item; move all items with
- * top >= position one down.
- * Note that this does not prevent overlaps when the menu contains
- * vertically spanning items.
- */
- for (children = menu_shell->children; children; children = children->next)
- {
- AttachInfo *child_ai = get_attach_info (children->data);
-
- if (child_ai->top_attach >= position)
- gtk_container_child_set (GTK_CONTAINER (menu_shell), children->data,
- "top_attach", child_ai->top_attach + 1,
- "bottom_attach", child_ai->bottom_attach + 1,
- NULL);
- }
+ GtkMenu *menu = GTK_MENU (menu_shell);
+ AttachInfo *ai = get_attach_info (child);
- /* attach the new item */
- gtk_menu_attach (GTK_MENU (menu_shell), child,
- 0, priv->columns,
- position, position + 1);
-}
+ ai->left_attach = -1;
+ ai->right_attach = -1;
+ ai->top_attach = -1;
+ ai->bottom_attach = -1;
-static void
-gtk_menu_real_insert (GtkMenuShell *menu_shell,
- GtkWidget *child,
- gint position)
-{
if (GTK_WIDGET_REALIZED (menu_shell))
- gtk_widget_set_parent_window (child, GTK_MENU (menu_shell)->bin_window);
+ gtk_widget_set_parent_window (child, menu->bin_window);
- GTK_MENU_SHELL_CLASS (parent_class)->insert (menu_shell, child, position);
+ GTK_MENU_SHELL_CLASS (gtk_menu_parent_class)->insert (menu_shell, child, position);
- gtk_menu_do_insert (menu_shell, child, position);
+ menu_queue_resize (menu);
}
static void
static gboolean
popup_grab_on_window (GdkWindow *window,
- guint32 activate_time)
+ guint32 activate_time,
+ gboolean grab_keyboard)
{
if ((gdk_pointer_grab (window, TRUE,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK,
NULL, NULL, activate_time) == 0))
{
- if (gdk_keyboard_grab (window, TRUE,
+ if (!grab_keyboard ||
+ gdk_keyboard_grab (window, TRUE,
activate_time) == 0)
return TRUE;
else
GtkWidget *parent;
GdkEvent *current_event;
GtkMenuShell *menu_shell;
+ gboolean grab_keyboard;
+ GtkMenuPrivate *priv;
+ GtkWidget *parent_toplevel;
g_return_if_fail (GTK_IS_MENU (menu));
-
+
widget = GTK_WIDGET (menu);
menu_shell = GTK_MENU_SHELL (menu);
-
+ priv = gtk_menu_get_private (menu);
+
menu_shell->parent_menu_shell = parent_menu_shell;
+
+ priv->seen_item_enter = FALSE;
/* Find the last viewable ancestor, and make an X grab on it
*/
* probably could just leave the grab on the other window, with a
* little reorganization of the code in gtkmenu*).
*/
+ grab_keyboard = gtk_menu_shell_get_take_focus (menu_shell);
+ gtk_window_set_accept_focus (GTK_WINDOW (menu->toplevel), grab_keyboard);
+
if (xgrab_shell && xgrab_shell != widget)
{
- if (popup_grab_on_window (xgrab_shell->window, activate_time))
+ if (popup_grab_on_window (xgrab_shell->window, activate_time, grab_keyboard))
GTK_MENU_SHELL (xgrab_shell)->have_xgrab = TRUE;
}
else
xgrab_shell = widget;
transfer_window = menu_grab_transfer_window_get (menu);
- if (popup_grab_on_window (transfer_window, activate_time))
+ if (popup_grab_on_window (transfer_window, activate_time, grab_keyboard))
GTK_MENU_SHELL (xgrab_shell)->have_xgrab = TRUE;
}
gtk_menu_reparent (menu, menu->toplevel, FALSE);
}
+
+ parent_toplevel = NULL;
+ if (parent_menu_shell)
+ parent_toplevel = gtk_widget_get_toplevel (parent_menu_shell);
+ else if (!g_object_get_data (G_OBJECT (menu), "gtk-menu-explicit-screen"))
+ {
+ GtkWidget *attach_widget = gtk_menu_get_attach_widget (menu);
+ if (attach_widget)
+ parent_toplevel = gtk_widget_get_toplevel (attach_widget);
+ }
+
+ /* Set transient for to get the right window group and parent relationship */
+ if (parent_toplevel && GTK_IS_WINDOW (parent_toplevel))
+ gtk_window_set_transient_for (GTK_WINDOW (menu->toplevel),
+ GTK_WINDOW (parent_toplevel));
menu->parent_menu_item = parent_menu_item;
menu->position_func = func;
gtk_widget_show (menu->toplevel);
if (xgrab_shell == widget)
- popup_grab_on_window (widget->window, activate_time); /* Should always succeed */
+ popup_grab_on_window (widget->window, activate_time, grab_keyboard); /* Should always succeed */
gtk_grab_add (GTK_WIDGET (menu));
}
menu_shell = GTK_MENU_SHELL (menu);
private = gtk_menu_get_private (menu);
-
+
menu_shell->parent_menu_shell = NULL;
menu_shell->active = FALSE;
menu_shell->ignore_enter = FALSE;
/* The X Grab, if present, will automatically be removed when we hide
* the window */
gtk_widget_hide (menu->toplevel);
+ gtk_window_set_transient_for (GTK_WINDOW (menu->toplevel), NULL);
if (menu->torn_off)
{
attach = attach->parent;
if (GTK_IS_MENU (attach))
- return gtk_menu_get_toplevel (attach->parent);
+ return gtk_menu_get_toplevel (attach);
else if (GTK_IS_WIDGET (attach))
{
- toplevel = gtk_widget_get_toplevel (attach->parent);
+ toplevel = gtk_widget_get_toplevel (attach);
if (GTK_WIDGET_TOPLEVEL (toplevel))
return toplevel;
}
return NULL;
}
+static void
+tearoff_window_destroyed (GtkWidget *widget,
+ GtkMenu *menu)
+{
+ gtk_menu_set_tearoff_state (menu, FALSE);
+}
+
void
gtk_menu_set_tearoff_state (GtkMenu *menu,
gboolean torn_off)
menu->tearoff_window = gtk_widget_new (GTK_TYPE_WINDOW,
"type", GTK_WINDOW_TOPLEVEL,
"screen", gtk_widget_get_screen (menu->toplevel),
- "app_paintable", TRUE,
+ "app-paintable", TRUE,
NULL);
-
gtk_window_set_type_hint (GTK_WINDOW (menu->tearoff_window),
GDK_WINDOW_TYPE_HINT_MENU);
gtk_window_set_mnemonic_modifier (GTK_WINDOW (menu->tearoff_window), 0);
g_signal_connect (menu->tearoff_window, "destroy",
- G_CALLBACK (gtk_widget_destroyed), &menu->tearoff_window);
+ G_CALLBACK (tearoff_window_destroyed), menu);
g_signal_connect (menu->tearoff_window, "event",
G_CALLBACK (gtk_menu_window_event), menu);
{
gtk_widget_hide (GTK_WIDGET (menu));
gtk_widget_hide (menu->tearoff_window);
- gtk_menu_reparent (menu, menu->toplevel, FALSE);
+ if (GTK_IS_CONTAINER (menu->toplevel))
+ gtk_menu_reparent (menu, menu->toplevel, FALSE);
gtk_widget_destroy (menu->tearoff_window);
menu->tearoff_window = NULL;
menu->tearoff_scrollbar = NULL;
menu->tearoff_adjustment = NULL;
}
+
+ g_object_notify (G_OBJECT (menu), "tearoff-state");
}
}
* @title: a string containing the title for the menu.
*
* Sets the title string for the menu. The title is displayed when the menu
- * is shown as a tearoff menu.
+ * is shown as a tearoff menu. If @title is %NULL, the menu will see if it is
+ * attached to a parent menu item, and if so it will try to use the same text as
+ * that menu item's label.
**/
-void
+void
gtk_menu_set_title (GtkMenu *menu,
const gchar *title)
{
+ GtkMenuPrivate *priv;
+ char *old_title;
+
g_return_if_fail (GTK_IS_MENU (menu));
- if (title)
- g_object_set_data_full (G_OBJECT (menu), "gtk-menu-title",
- g_strdup (title), (GtkDestroyNotify) g_free);
- else
- g_object_set_data (G_OBJECT (menu), "gtk-menu-title", NULL);
-
+ priv = gtk_menu_get_private (menu);
+
+ old_title = priv->title;
+ priv->title = g_strdup (title);
+ g_free (old_title);
+
gtk_menu_update_title (menu);
- g_object_notify (G_OBJECT (menu), "tearoff_title");
+ g_object_notify (G_OBJECT (menu), "tearoff-title");
}
/**
G_CONST_RETURN gchar *
gtk_menu_get_title (GtkMenu *menu)
{
+ GtkMenuPrivate *priv;
+
g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
- return g_object_get_data (G_OBJECT (menu), "gtk-menu-title");
+ priv = gtk_menu_get_private (menu);
+
+ return priv->title;
}
void
{
menu_shell->children = g_list_remove (menu_shell->children, child);
menu_shell->children = g_list_insert (menu_shell->children, child, position);
- gtk_menu_do_insert (menu_shell, child, position);
- if (GTK_WIDGET_VISIBLE (menu_shell))
- gtk_widget_queue_resize (GTK_WIDGET (menu_shell));
+ menu_queue_resize (menu);
}
}
GtkWidget *child;
GList *children;
guint vertical_padding;
-
+ guint horizontal_padding;
+ guint scroll_arrow_height;
+
g_return_if_fail (GTK_IS_MENU (widget));
menu = GTK_MENU (widget);
gtk_widget_style_get (GTK_WIDGET (menu),
"vertical-padding", &vertical_padding,
+ "horizontal-padding", &horizontal_padding,
+ "scroll-arrow-vlength", &scroll_arrow_height,
NULL);
-
- attributes.x = border_width + widget->style->xthickness;
+
+ attributes.x = border_width + widget->style->xthickness + horizontal_padding;
attributes.y = border_width + widget->style->ythickness + vertical_padding;
attributes.width = MAX (1, widget->allocation.width - attributes.x * 2);
attributes.height = MAX (1, widget->allocation.height - attributes.y * 2);
if (menu->upper_arrow_visible)
{
- attributes.y += MENU_SCROLL_ARROW_HEIGHT;
- attributes.height -= MENU_SCROLL_ARROW_HEIGHT;
+ attributes.y += scroll_arrow_height;
+ attributes.height -= scroll_arrow_height;
}
+
if (menu->lower_arrow_visible)
- attributes.height -= MENU_SCROLL_ARROW_HEIGHT;
+ attributes.height -= scroll_arrow_height;
menu->view_window = gdk_window_new (widget->window, &attributes, attributes_mask);
gdk_window_set_user_data (menu->view_window, menu);
attributes.x = 0;
attributes.y = 0;
+ attributes.width = MAX (1, widget->allocation.width - (border_width + widget->style->xthickness + horizontal_padding) * 2);
attributes.height = MAX (1, widget->requisition.height - (border_width + widget->style->ythickness + vertical_padding) * 2);
menu->bin_window = gdk_window_new (menu->view_window, &attributes, attributes_mask);
gdk_window_show (window);
- g_object_set_data (G_OBJECT (menu), "gtk-menu-transfer-window", window);
+ g_object_set_data (G_OBJECT (menu), I_("gtk-menu-transfer-window"), window);
}
return window;
{
gdk_window_set_user_data (window, NULL);
gdk_window_destroy (window);
- g_object_set_data (G_OBJECT (menu), "gtk-menu-transfer-window", NULL);
+ g_object_set_data (G_OBJECT (menu), I_("gtk-menu-transfer-window"), NULL);
}
}
gdk_window_destroy (menu->bin_window);
menu->bin_window = NULL;
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+ (* GTK_WIDGET_CLASS (gtk_menu_parent_class)->unrealize) (widget);
}
static void
guint max_toggle_size;
guint max_accel_width;
guint vertical_padding;
+ guint horizontal_padding;
GtkRequisition child_requisition;
GtkMenuPrivate *priv;
max_accel_width = 0;
g_free (priv->heights);
- priv->heights = g_new0 (guint, priv->rows);
- priv->heights_length = priv->rows;
+ priv->heights = g_new0 (guint, gtk_menu_get_n_rows (menu));
+ priv->heights_length = gtk_menu_get_n_rows (menu);
children = menu_shell->children;
while (children)
{
gint part;
gint toggle_size;
- guint l, r, t, b;
+ gint l, r, t, b;
child = children->data;
children = children->next;
if (! GTK_WIDGET_VISIBLE (child))
continue;
- get_child_attach (child, &l, &r, &t, &b);
+ get_effective_child_attach (child, &l, &r, &t, &b);
/* It's important to size_request the child
* before doing the toggle size request, in
part = child_requisition.width / (r - l);
requisition->width = MAX (requisition->width, part);
- part = child_requisition.height / (b - t);
+ part = MAX (child_requisition.height, toggle_size) / (b - t);
priv->heights[t] = MAX (priv->heights[t], part);
}
- for (i = 0; i < priv->rows; i++)
+ for (i = 0; i < gtk_menu_get_n_rows (menu); i++)
requisition->height += priv->heights[i];
requisition->width += max_toggle_size + max_accel_width;
- requisition->width *= priv->columns;
- requisition->width += (GTK_CONTAINER (menu)->border_width +
- widget->style->xthickness) * 2;
+ requisition->width *= gtk_menu_get_n_columns (menu);
gtk_widget_style_get (GTK_WIDGET (menu),
"vertical-padding", &vertical_padding,
+ "horizontal-padding", &horizontal_padding,
NULL);
+
+ requisition->width += (GTK_CONTAINER (menu)->border_width + horizontal_padding +
+ widget->style->xthickness) * 2;
requisition->height += (GTK_CONTAINER (menu)->border_width + vertical_padding +
widget->style->ythickness) * 2;
gint x, y;
gint width, height;
guint vertical_padding;
-
+ guint horizontal_padding;
+ gint scroll_arrow_height;
+
g_return_if_fail (GTK_IS_MENU (widget));
g_return_if_fail (allocation != NULL);
gtk_widget_style_get (GTK_WIDGET (menu),
"vertical-padding", &vertical_padding,
+ "horizontal-padding", &horizontal_padding,
+ "scroll-arrow-vlength", &scroll_arrow_height,
NULL);
-
- x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness;
+
+ x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness + horizontal_padding;
y = GTK_CONTAINER (menu)->border_width + widget->style->ythickness + vertical_padding;
width = MAX (1, allocation->width - x * 2);
if (menu_shell->active)
gtk_menu_scroll_to (menu, menu->scroll_offset);
-
+
if (menu->upper_arrow_visible && !menu->tearoff_active)
{
- y += MENU_SCROLL_ARROW_HEIGHT;
- height -= MENU_SCROLL_ARROW_HEIGHT;
+ y += scroll_arrow_height;
+ height -= scroll_arrow_height;
}
-
+
if (menu->lower_arrow_visible && !menu->tearoff_active)
- height -= MENU_SCROLL_ARROW_HEIGHT;
-
+ height -= scroll_arrow_height;
+
if (GTK_WIDGET_REALIZED (widget))
{
gdk_window_move_resize (widget->window,
if (menu_shell->children)
{
- gint base_width = width / priv->columns;
+ gint base_width = width / gtk_menu_get_n_columns (menu);
children = menu_shell->children;
while (children)
if (GTK_WIDGET_VISIBLE (child))
{
gint i;
- guint l, r, t, b;
+ gint l, r, t, b;
- get_child_attach (child, &l, &r, &t, &b);
+ get_effective_child_attach (child, &l, &r, &t, &b);
if (gtk_widget_get_direction (GTK_WIDGET (menu)) == GTK_TEXT_DIR_RTL)
{
guint tmp;
- tmp = priv->columns - l;
- l = priv->columns - r;
+ tmp = gtk_menu_get_n_columns (menu) - l;
+ l = gtk_menu_get_n_columns (menu) - r;
r = tmp;
}
gint width, height;
height = 0;
- for (i = 0; i < priv->rows; i++)
+ for (i = 0; i < gtk_menu_get_n_rows (menu); i++)
height += priv->heights[i];
- width = priv->columns * base_width;
+ width = gtk_menu_get_n_columns (menu) * base_width;
gdk_window_resize (menu->bin_window, width, height);
}
GdkEventExpose *event)
{
GtkMenu *menu;
+ GtkMenuPrivate *priv;
gint width, height;
gint border_x, border_y;
guint vertical_padding;
+ guint horizontal_padding;
+ gint scroll_arrow_height;
g_return_if_fail (GTK_IS_MENU (widget));
menu = GTK_MENU (widget);
+ priv = gtk_menu_get_private (menu);
gtk_widget_style_get (GTK_WIDGET (menu),
"vertical-padding", &vertical_padding,
- NULL);
-
- border_x = GTK_CONTAINER (widget)->border_width + widget->style->xthickness;
+ "horizontal-padding", &horizontal_padding,
+ "scroll-arrow-vlength", &scroll_arrow_height,
+ NULL);
+
+ border_x = GTK_CONTAINER (widget)->border_width + widget->style->xthickness + horizontal_padding;
border_y = GTK_CONTAINER (widget)->border_width + widget->style->ythickness + vertical_padding;
gdk_drawable_get_size (widget->window, &width, &height);
if (event->window == widget->window)
{
- gint arrow_space = MENU_SCROLL_ARROW_HEIGHT - 2 * widget->style->ythickness;
+ gint arrow_space = scroll_arrow_height - 2 * widget->style->ythickness;
gint arrow_size = 0.7 * arrow_space;
-
+
gtk_paint_box (widget->style,
widget->window,
GTK_STATE_NORMAL,
GTK_SHADOW_OUT,
NULL, widget, "menu",
0, 0, -1, -1);
+
if (menu->upper_arrow_visible && !menu->tearoff_active)
{
gtk_paint_box (widget->style,
widget->window,
- menu->upper_arrow_prelight ?
- GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
+ priv->upper_arrow_state,
GTK_SHADOW_OUT,
NULL, widget, "menu",
border_x,
border_y,
width - 2 * border_x,
- MENU_SCROLL_ARROW_HEIGHT);
-
+ scroll_arrow_height);
+
gtk_paint_arrow (widget->style,
widget->window,
- menu->upper_arrow_prelight ?
- GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
+ priv->upper_arrow_state,
GTK_SHADOW_OUT,
NULL, widget, "menu_scroll_arrow_up",
GTK_ARROW_UP,
border_y + widget->style->ythickness + (arrow_space - arrow_size)/2,
arrow_size, arrow_size);
}
-
+
if (menu->lower_arrow_visible && !menu->tearoff_active)
{
gtk_paint_box (widget->style,
widget->window,
- menu->lower_arrow_prelight ?
- GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
+ priv->lower_arrow_state,
GTK_SHADOW_OUT,
NULL, widget, "menu",
border_x,
- height - border_y - MENU_SCROLL_ARROW_HEIGHT,
+ height - border_y - scroll_arrow_height,
width - 2*border_x,
- MENU_SCROLL_ARROW_HEIGHT);
-
+ scroll_arrow_height);
+
gtk_paint_arrow (widget->style,
widget->window,
- menu->lower_arrow_prelight ?
- GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
+ priv->lower_arrow_state,
GTK_SHADOW_OUT,
NULL, widget, "menu_scroll_arrow_down",
GTK_ARROW_DOWN,
TRUE,
(width - arrow_size) / 2,
- height - border_y - MENU_SCROLL_ARROW_HEIGHT +
+ height - border_y - scroll_arrow_height +
widget->style->ythickness + (arrow_space - arrow_size)/2,
arrow_size, arrow_size);
}
}
+ else if (event->window == menu->bin_window)
+ {
+ gtk_paint_box (widget->style,
+ menu->bin_window,
+ GTK_STATE_NORMAL,
+ GTK_SHADOW_OUT,
+ NULL, widget, "menu",
+ - border_x, menu->scroll_offset - border_y,
+ width, height);
+ }
}
static gboolean
{
gtk_menu_paint (widget, event);
- (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
+ (* GTK_WIDGET_CLASS (gtk_menu_parent_class)->expose_event) (widget, event);
}
return FALSE;
_gtk_menu_refresh_accel_paths (menu, FALSE);
- GTK_WIDGET_CLASS (parent_class)->show (widget);
+ GTK_WIDGET_CLASS (gtk_menu_parent_class)->show (widget);
}
static gboolean
-gtk_menu_button_press (GtkWidget *widget,
- GdkEventButton *event)
+gtk_menu_button_scroll (GtkWidget *widget,
+ GdkEventButton *event)
{
- /* Don't pop down the menu for releases over scroll arrows
- */
if (GTK_IS_MENU (widget))
{
GtkMenu *menu = GTK_MENU (widget);
- if (menu->upper_arrow_prelight || menu->lower_arrow_prelight)
- return TRUE;
+ if (menu->upper_arrow_prelight || menu->lower_arrow_prelight)
+ {
+ GtkSettings *settings = gtk_widget_get_settings (widget);
+ gboolean touchscreen_mode;
+
+ g_object_get (G_OBJECT (settings),
+ "gtk-touchscreen-mode", &touchscreen_mode,
+ NULL);
+
+ if (touchscreen_mode)
+ gtk_menu_handle_scrolling (menu,
+ event->x_root, event->y_root,
+ event->type == GDK_BUTTON_PRESS,
+ FALSE);
+
+ return TRUE;
+ }
}
- return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
+ return FALSE;
+}
+
+static gboolean
+gtk_menu_button_press (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ if (event->type != GDK_BUTTON_PRESS)
+ return FALSE;
+
+ /* Don't pop down the menu for presses over scroll arrows
+ */
+ if (gtk_menu_button_scroll (widget, event))
+ return TRUE;
+
+ return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_press_event (widget, event);
}
static gboolean
gtk_menu_button_release (GtkWidget *widget,
GdkEventButton *event)
{
- /* Don't pop down the menu for releases over scroll arrows
- */
if (GTK_IS_MENU (widget))
{
- GtkMenu *menu = GTK_MENU (widget);
+ GtkMenuPrivate *priv = gtk_menu_get_private (GTK_MENU (widget));
- if (menu->upper_arrow_prelight || menu->lower_arrow_prelight)
- return TRUE;
+ if (priv->ignore_button_release)
+ {
+ priv->ignore_button_release = FALSE;
+ return FALSE;
+ }
}
- return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
+ if (event->type != GDK_BUTTON_RELEASE)
+ return FALSE;
+
+ /* Don't pop down the menu for releases over scroll arrows
+ */
+ if (gtk_menu_button_scroll (widget, event))
+ return TRUE;
+
+ return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_release_event (widget, event);
}
static const gchar *
if (GTK_IS_ACCEL_LABEL (label))
{
g_object_get (label,
- "accel_closure", &accel_closure,
+ "accel-closure", &accel_closure,
NULL);
- accel_group = gtk_accel_group_from_accel_closure (accel_closure);
-
- *locked = accel_group->lock_count > 0;
+ if (accel_closure)
+ {
+ accel_group = gtk_accel_group_from_accel_closure (accel_closure);
+
+ *locked = accel_group->lock_count > 0;
+ }
}
}
}
gtk_menu_stop_navigating_submenu (menu);
- if (GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event))
+ if (GTK_WIDGET_CLASS (gtk_menu_parent_class)->key_press_event (widget, event))
return TRUE;
display = gtk_widget_get_display (widget);
"gtk-can-change-accels", &can_change_accels,
NULL);
- if (accel)
+ if (accel && *accel)
{
guint keyval = 0;
GdkModifierType mods = 0;
* (basically, those items are accelerator-locked).
*/
/* g_print("item has no path or is locked, menu prefix: %s\n", menu->accel_path); */
- gdk_display_beep (display);
+ gtk_widget_error_bell (widget);
}
else
{
* locked already
*/
/* g_print("failed to change\n"); */
- gdk_display_beep (display);
+ gtk_widget_error_bell (widget);
}
}
}
return TRUE;
}
+static gboolean
+check_threshold (GtkWidget *widget,
+ int start_x, int start_y,
+ int x, int y)
+{
+#define THRESHOLD 8
+
+ return
+ ABS (start_x - x) > THRESHOLD ||
+ ABS (start_y - y) > THRESHOLD;
+}
+
+static gboolean
+definitely_within_item (GtkWidget *widget,
+ int x,
+ int y)
+{
+ GdkWindow *window = GTK_MENU_ITEM (widget)->event_window;
+ int w, h;
+
+ gdk_drawable_get_size (window, &w, &h);
+
+ return
+ check_threshold (widget, 0, 0, x, y) &&
+ check_threshold (widget, w - 1, 0, x, y) &&
+ check_threshold (widget, w - 1, h - 1, x, y) &&
+ check_threshold (widget, 0, h - 1, x, y);
+}
+
static gboolean
gtk_menu_motion_notify (GtkWidget *widget,
GdkEventMotion *event)
gboolean need_enter;
if (GTK_IS_MENU (widget))
- gtk_menu_handle_scrolling (GTK_MENU (widget), TRUE);
+ {
+ GtkMenuPrivate *priv = gtk_menu_get_private (GTK_MENU (widget));
+
+ if (priv->ignore_button_release)
+ priv->ignore_button_release = FALSE;
+
+ gtk_menu_handle_scrolling (GTK_MENU (widget), event->x_root, event->y_root,
+ TRUE, TRUE);
+ }
/* We received the event for one of two reasons:
*
* which may be different from 'widget'.
*/
menu_item = gtk_get_event_widget ((GdkEvent*) event);
- if (!menu_item || !GTK_IS_MENU_ITEM (menu_item) ||
- !_gtk_menu_item_is_selectable (menu_item) ||
+ if (!GTK_IS_MENU_ITEM (menu_item) ||
!GTK_IS_MENU (menu_item->parent))
return FALSE;
menu_shell = GTK_MENU_SHELL (menu_item->parent);
menu = GTK_MENU (menu_shell);
+
+ if (definitely_within_item (menu_item, event->x, event->y))
+ menu_shell->activate_time = 0;
need_enter = (menu->navigation_region != NULL || menu_shell->ignore_enter);
if (gtk_menu_navigating_submenu (menu, event->x_root, event->y_root))
return TRUE;
+ /* Make sure we pop down if we enter a non-selectable menu item, so we
+ * don't show a submenu when the cursor is outside the stay-up triangle.
+ */
+ if (!_gtk_menu_item_is_selectable (menu_item))
+ {
+ gtk_menu_shell_deselect (menu_shell);
+ return FALSE;
+ }
+
if (need_enter)
{
/* The menu is now sensitive to enter events on its items, but
}
static gboolean
-gtk_menu_scroll_timeout (gpointer data)
+get_double_arrows (GtkMenu *menu)
+{
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+ gboolean double_arrows;
+
+ gtk_widget_style_get (GTK_WIDGET (menu),
+ "double-arrows", &double_arrows,
+ NULL);
+
+ return double_arrows || (priv->initially_pushed_in &&
+ menu->scroll_offset != 0);
+}
+
+static void
+gtk_menu_scroll_by (GtkMenu *menu,
+ gint step)
{
- GtkMenu *menu;
GtkWidget *widget;
gint offset;
gint view_width, view_height;
-
- GDK_THREADS_ENTER ();
-
- menu = GTK_MENU (data);
+ gboolean double_arrows;
+ gint scroll_arrow_height;
+
widget = GTK_WIDGET (menu);
+ offset = menu->scroll_offset + step;
- offset = menu->scroll_offset + menu->scroll_step;
+ gtk_widget_style_get (GTK_WIDGET (menu),
+ "scroll-arrow-vlength", &scroll_arrow_height,
+ NULL);
+
+ double_arrows = get_double_arrows (menu);
/* If we scroll upward and the non-visible top part
* is smaller than the scroll arrow it would be
* pretty stupid to show the arrow and taking more
* screen space than just scrolling to the top.
*/
- if ((menu->scroll_step < 0) && (offset < MENU_SCROLL_ARROW_HEIGHT))
- offset = 0;
+ if (!double_arrows)
+ if ((step < 0) && (offset < scroll_arrow_height))
+ offset = 0;
/* Don't scroll over the top if we weren't before: */
if ((menu->scroll_offset >= 0) && (offset < 0))
gdk_drawable_get_size (widget->window, &view_width, &view_height);
+ if (menu->scroll_offset == 0 &&
+ view_height >= widget->requisition.height)
+ return;
+
/* Don't scroll past the bottom if we weren't before: */
if (menu->scroll_offset > 0)
- view_height -= MENU_SCROLL_ARROW_HEIGHT;
-
+ view_height -= scroll_arrow_height;
+
+ /* When both arrows are always shown, reduce
+ * view height even more.
+ */
+ if (double_arrows)
+ view_height -= scroll_arrow_height;
+
if ((menu->scroll_offset + view_height <= widget->requisition.height) &&
(offset + view_height > widget->requisition.height))
offset = widget->requisition.height - view_height;
- gtk_menu_scroll_to (menu, offset);
+ if (offset != menu->scroll_offset)
+ gtk_menu_scroll_to (menu, offset);
+}
+
+static void
+gtk_menu_do_timeout_scroll (GtkMenu *menu,
+ gboolean touchscreen_mode)
+{
+ gboolean upper_visible;
+ gboolean lower_visible;
+
+ upper_visible = menu->upper_arrow_visible;
+ lower_visible = menu->lower_arrow_visible;
- GDK_THREADS_LEAVE ();
+ gtk_menu_scroll_by (menu, menu->scroll_step);
+
+ if (touchscreen_mode &&
+ (upper_visible != menu->upper_arrow_visible ||
+ lower_visible != menu->lower_arrow_visible))
+ {
+ /* We are about to hide a scroll arrow while the mouse is pressed,
+ * this would cause the uncovered menu item to be activated on button
+ * release. Therefore we need to ignore button release here
+ */
+ GTK_MENU_SHELL (menu)->ignore_enter = TRUE;
+ gtk_menu_get_private (menu)->ignore_button_release = TRUE;
+ }
+}
+
+static gboolean
+gtk_menu_scroll_timeout (gpointer data)
+{
+ GtkMenu *menu;
+ GtkSettings *settings;
+ gboolean touchscreen_mode;
+
+ menu = GTK_MENU (data);
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (menu));
+ g_object_get (settings,
+ "gtk-touchscreen-mode", &touchscreen_mode,
+ NULL);
+
+ gtk_menu_do_timeout_scroll (menu, touchscreen_mode);
return TRUE;
}
+static gboolean
+gtk_menu_scroll_timeout_initial (gpointer data)
+{
+ GtkMenu *menu;
+ GtkSettings *settings;
+ guint timeout;
+ gboolean touchscreen_mode;
+
+ menu = GTK_MENU (data);
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (menu));
+ g_object_get (settings,
+ "gtk-timeout-repeat", &timeout,
+ "gtk-touchscreen-mode", &touchscreen_mode,
+ NULL);
+
+ gtk_menu_do_timeout_scroll (menu, touchscreen_mode);
+
+ gtk_menu_remove_scroll_timeout (menu);
+
+ menu->timeout_id = gdk_threads_add_timeout (timeout, gtk_menu_scroll_timeout, menu);
+
+ return FALSE;
+}
+
static void
-gtk_menu_handle_scrolling (GtkMenu *menu, gboolean enter)
+gtk_menu_start_scrolling (GtkMenu *menu)
+{
+ GtkSettings *settings;
+ guint timeout;
+ gboolean touchscreen_mode;
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (menu));
+ g_object_get (settings,
+ "gtk-timeout-repeat", &timeout,
+ "gtk-touchscreen-mode", &touchscreen_mode,
+ NULL);
+
+ gtk_menu_do_timeout_scroll (menu, touchscreen_mode);
+
+ menu->timeout_id = gdk_threads_add_timeout (timeout, gtk_menu_scroll_timeout_initial,
+ menu);
+}
+
+static gboolean
+gtk_menu_scroll (GtkWidget *widget,
+ GdkEventScroll *event)
+{
+ GtkMenu *menu = GTK_MENU (widget);
+
+ switch (event->direction)
+ {
+ case GDK_SCROLL_RIGHT:
+ case GDK_SCROLL_DOWN:
+ gtk_menu_scroll_by (menu, MENU_SCROLL_STEP2);
+ break;
+ case GDK_SCROLL_LEFT:
+ case GDK_SCROLL_UP:
+ gtk_menu_scroll_by (menu, - MENU_SCROLL_STEP2);
+ break;
+ }
+
+ return TRUE;
+}
+
+static void
+gtk_menu_handle_scrolling (GtkMenu *menu,
+ gint x,
+ gint y,
+ gboolean enter,
+ gboolean motion)
{
GtkMenuShell *menu_shell;
+ GtkMenuPrivate *priv;
gint width, height;
- gint x, y;
gint border;
GdkRectangle rect;
gboolean in_arrow;
gboolean scroll_fast = FALSE;
guint vertical_padding;
+ gint top_x, top_y;
+ gint win_x, win_y;
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (menu));
+ gboolean touchscreen_mode;
+ gint scroll_arrow_height;
+
+ priv = gtk_menu_get_private (menu);
menu_shell = GTK_MENU_SHELL (menu);
- gdk_window_get_pointer (GTK_WIDGET (menu)->window, &x, &y, NULL);
gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
+ g_object_get (G_OBJECT (settings),
+ "gtk-touchscreen-mode", &touchscreen_mode,
+ NULL);
+
gtk_widget_style_get (GTK_WIDGET (menu),
"vertical-padding", &vertical_padding,
+ "scroll-arrow-vlength", &scroll_arrow_height,
NULL);
-
+
border = GTK_CONTAINER (menu)->border_width +
GTK_WIDGET (menu)->style->ythickness + vertical_padding;
- if (menu->upper_arrow_visible && !menu->tearoff_active)
+ gdk_window_get_position (menu->toplevel->window, &top_x, &top_y);
+ x -= top_x;
+ y -= top_y;
+
+ gdk_window_get_position (GTK_WIDGET (menu)->window, &win_x, &win_y);
+
+ /* upper arrow handling */
+
+ rect.x = win_x;
+ rect.y = win_y;
+ rect.width = width;
+ rect.height = scroll_arrow_height + border;
+
+ in_arrow = FALSE;
+ if (menu->upper_arrow_visible && !menu->tearoff_active &&
+ (x >= rect.x) && (x < rect.x + rect.width) &&
+ (y >= rect.y) && (y < rect.y + rect.height))
{
- rect.x = 0;
- rect.y = 0;
- rect.width = width;
- rect.height = MENU_SCROLL_ARROW_HEIGHT + border;
-
- in_arrow = FALSE;
- if ((x >= rect.x) && (x < rect.x + rect.width) &&
- (y >= rect.y) && (y < rect.y + rect.height))
- {
- in_arrow = TRUE;
- scroll_fast = (y < rect.y + MENU_SCROLL_FAST_ZONE);
- }
-
- if (enter && in_arrow &&
- (!menu->upper_arrow_prelight || menu->scroll_fast != scroll_fast))
- {
- menu->upper_arrow_prelight = TRUE;
- menu->scroll_fast = scroll_fast;
- gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
-
- /* Deselect the active item so that any submenus are poped down */
- gtk_menu_shell_deselect (menu_shell);
+ in_arrow = TRUE;
+ }
- gtk_menu_remove_scroll_timeout (menu);
- menu->scroll_step = (scroll_fast) ? -MENU_SCROLL_STEP2 : -MENU_SCROLL_STEP1;
- menu->timeout_id = g_timeout_add ((scroll_fast) ? MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
- gtk_menu_scroll_timeout,
- menu);
- }
- else if (!enter && !in_arrow && menu->upper_arrow_prelight)
- {
- gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
-
- gtk_menu_stop_scrolling (menu);
- }
+ if (touchscreen_mode)
+ menu->upper_arrow_prelight = in_arrow;
+
+ if (priv->upper_arrow_state != GTK_STATE_INSENSITIVE)
+ {
+ if (menu->upper_arrow_visible && !menu->tearoff_active)
+ {
+ if (touchscreen_mode)
+ {
+ if (enter && menu->upper_arrow_prelight &&
+ menu->timeout_id == 0)
+ {
+ /* Deselect the active item so that
+ * any submenus are popped down
+ */
+ gtk_menu_shell_deselect (menu_shell);
+
+ gtk_menu_remove_scroll_timeout (menu);
+ menu->scroll_step = -MENU_SCROLL_STEP2; /* always fast */
+
+ if (!motion)
+ {
+ /* Only do stuff on click. */
+ gtk_menu_start_scrolling (menu);
+ priv->upper_arrow_state = GTK_STATE_ACTIVE;
+ }
+
+ gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+ &rect, FALSE);
+ }
+ else if (!enter)
+ {
+ gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+ &rect, FALSE);
+
+ gtk_menu_stop_scrolling (menu);
+ }
+ }
+ else /* !touchscreen_mode */
+ {
+ scroll_fast = (y < rect.y + MENU_SCROLL_FAST_ZONE);
+
+ if (enter && in_arrow &&
+ (!menu->upper_arrow_prelight ||
+ menu->scroll_fast != scroll_fast))
+ {
+ menu->upper_arrow_prelight = TRUE;
+ menu->scroll_fast = scroll_fast;
+ gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+ &rect, FALSE);
+
+ /* Deselect the active item so that
+ * any submenus are popped down
+ */
+ gtk_menu_shell_deselect (menu_shell);
+
+ gtk_menu_remove_scroll_timeout (menu);
+ menu->scroll_step = scroll_fast ?
+ -MENU_SCROLL_STEP2 : -MENU_SCROLL_STEP1;
+
+ menu->timeout_id =
+ gdk_threads_add_timeout (scroll_fast ?
+ MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
+ gtk_menu_scroll_timeout, menu);
+ }
+ else if (!enter && !in_arrow && menu->upper_arrow_prelight)
+ {
+ gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+ &rect, FALSE);
+
+ gtk_menu_stop_scrolling (menu);
+ }
+ }
+ }
+
+ priv->upper_arrow_state = menu->upper_arrow_prelight ?
+ GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
}
-
- if (menu->lower_arrow_visible && !menu->tearoff_active)
+
+ /* lower arrow handling */
+
+ rect.x = win_x;
+ rect.y = win_y + height - border - scroll_arrow_height;
+ rect.width = width;
+ rect.height = scroll_arrow_height + border;
+
+ in_arrow = FALSE;
+ if (menu->lower_arrow_visible && !menu->tearoff_active &&
+ (x >= rect.x) && (x < rect.x + rect.width) &&
+ (y >= rect.y) && (y < rect.y + rect.height))
{
- rect.x = 0;
- rect.y = height - border - MENU_SCROLL_ARROW_HEIGHT;
- rect.width = width;
- rect.height = MENU_SCROLL_ARROW_HEIGHT + border;
+ in_arrow = TRUE;
+ }
- in_arrow = FALSE;
- if ((x >= rect.x) && (x < rect.x + rect.width) &&
- (y >= rect.y) && (y < rect.y + rect.height))
- {
- in_arrow = TRUE;
- scroll_fast = (y > rect.y + rect.height - MENU_SCROLL_FAST_ZONE);
- }
+ if (touchscreen_mode)
+ menu->lower_arrow_prelight = in_arrow;
- if (enter && in_arrow &&
- (!menu->lower_arrow_prelight || menu->scroll_fast != scroll_fast))
- {
- menu->lower_arrow_prelight = TRUE;
- menu->scroll_fast = scroll_fast;
- gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
+ if (priv->lower_arrow_state != GTK_STATE_INSENSITIVE)
+ {
+ if (menu->lower_arrow_visible && !menu->tearoff_active)
+ {
+ if (touchscreen_mode)
+ {
+ if (enter && menu->lower_arrow_prelight &&
+ menu->timeout_id == 0)
+ {
+ /* Deselect the active item so that
+ * any submenus are popped down
+ */
+ gtk_menu_shell_deselect (menu_shell);
+
+ gtk_menu_remove_scroll_timeout (menu);
+ menu->scroll_step = MENU_SCROLL_STEP2; /* always fast */
+
+ if (!motion)
+ {
+ /* Only do stuff on click. */
+ gtk_menu_start_scrolling (menu);
+ priv->lower_arrow_state = GTK_STATE_ACTIVE;
+ }
+
+ gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+ &rect, FALSE);
+ }
+ else if (!enter)
+ {
+ gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+ &rect, FALSE);
- /* Deselect the active item so that any submenus are poped down */
- gtk_menu_shell_deselect (menu_shell);
+ gtk_menu_stop_scrolling (menu);
+ }
+ }
+ else /* !touchscreen_mode */
+ {
+ scroll_fast = (y > rect.y + rect.height - MENU_SCROLL_FAST_ZONE);
- gtk_menu_remove_scroll_timeout (menu);
- menu->scroll_step = (scroll_fast) ? MENU_SCROLL_STEP2 : MENU_SCROLL_STEP1;
- menu->timeout_id = g_timeout_add ((scroll_fast) ? MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
- gtk_menu_scroll_timeout,
- menu);
- }
- else if (!enter && !in_arrow && menu->lower_arrow_prelight)
- {
- gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
-
- gtk_menu_stop_scrolling (menu);
- }
+ if (enter && in_arrow &&
+ (!menu->lower_arrow_prelight ||
+ menu->scroll_fast != scroll_fast))
+ {
+ menu->lower_arrow_prelight = TRUE;
+ menu->scroll_fast = scroll_fast;
+ gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+ &rect, FALSE);
+
+ /* Deselect the active item so that
+ * any submenus are popped down
+ */
+ gtk_menu_shell_deselect (menu_shell);
+
+ gtk_menu_remove_scroll_timeout (menu);
+ menu->scroll_step = scroll_fast ?
+ MENU_SCROLL_STEP2 : MENU_SCROLL_STEP1;
+
+ menu->timeout_id =
+ gdk_threads_add_timeout (scroll_fast ?
+ MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
+ gtk_menu_scroll_timeout, menu);
+ }
+ else if (!enter && !in_arrow && menu->lower_arrow_prelight)
+ {
+ gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+ &rect, FALSE);
+
+ gtk_menu_stop_scrolling (menu);
+ }
+ }
+ }
+
+ priv->lower_arrow_state = menu->lower_arrow_prelight ?
+ GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
}
}
gtk_menu_enter_notify (GtkWidget *widget,
GdkEventCrossing *event)
{
+ GtkSettings *settings = gtk_widget_get_settings (widget);
GtkWidget *menu_item;
+ gboolean touchscreen_mode;
+
+ g_object_get (G_OBJECT (settings),
+ "gtk-touchscreen-mode", &touchscreen_mode,
+ NULL);
- if (widget && GTK_IS_MENU (widget))
+ menu_item = gtk_get_event_widget ((GdkEvent*) event);
+ if (GTK_IS_MENU (widget))
{
GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
if (!menu_shell->ignore_enter)
- gtk_menu_handle_scrolling (GTK_MENU (widget), TRUE);
+ gtk_menu_handle_scrolling (GTK_MENU (widget),
+ event->x_root, event->y_root, TRUE, TRUE);
+ }
+
+ if (!touchscreen_mode && GTK_IS_MENU_ITEM (menu_item))
+ {
+ GtkWidget *menu = menu_item->parent;
+
+ if (GTK_IS_MENU (menu))
+ {
+ GtkMenuPrivate *priv = gtk_menu_get_private (GTK_MENU (menu));
+ GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
+
+ if (priv->seen_item_enter)
+ {
+ /* This is the second enter we see for an item
+ * on this menu. This means a release should always
+ * mean activate.
+ */
+ menu_shell->activate_time = 0;
+ }
+ else if ((event->detail != GDK_NOTIFY_NONLINEAR &&
+ event->detail != GDK_NOTIFY_NONLINEAR_VIRTUAL))
+ {
+ if (definitely_within_item (menu_item, event->x, event->y))
+ {
+ /* This is an actual user-enter (ie. not a pop-under)
+ * In this case, the user must either have entered
+ * sufficiently far enough into the item, or he must move
+ * far enough away from the enter point. (see
+ * gtk_menu_motion_notify())
+ */
+ menu_shell->activate_time = 0;
+ }
+ }
+
+ priv->seen_item_enter = TRUE;
+ }
}
/* If this is a faked enter (see gtk_menu_motion_notify), 'widget'
* will not correspond to the event widget's parent. Check to see
* if we are in the parent's navigation region.
*/
- menu_item = gtk_get_event_widget ((GdkEvent*) event);
- if (menu_item && GTK_IS_MENU_ITEM (menu_item) && GTK_IS_MENU (menu_item->parent) &&
- gtk_menu_navigating_submenu (GTK_MENU (menu_item->parent), event->x_root, event->y_root))
+ if (GTK_IS_MENU_ITEM (menu_item) && GTK_IS_MENU (menu_item->parent) &&
+ gtk_menu_navigating_submenu (GTK_MENU (menu_item->parent),
+ event->x_root, event->y_root))
return TRUE;
- return GTK_WIDGET_CLASS (parent_class)->enter_notify_event (widget, event);
+ return GTK_WIDGET_CLASS (gtk_menu_parent_class)->enter_notify_event (widget, event);
}
static gboolean
if (gtk_menu_navigating_submenu (menu, event->x_root, event->y_root))
return TRUE;
- gtk_menu_handle_scrolling (menu, FALSE);
-
+ gtk_menu_handle_scrolling (menu, event->x_root, event->y_root, FALSE, TRUE);
+
event_widget = gtk_get_event_widget ((GdkEvent*) event);
- if (!event_widget || !GTK_IS_MENU_ITEM (event_widget))
+ if (!GTK_IS_MENU_ITEM (event_widget))
return TRUE;
menu_item = GTK_MENU_ITEM (event_widget);
gtk_menu_set_submenu_navigation_region (menu, menu_item, event);
return TRUE;
}
+ else if (menu_item == GTK_MENU_ITEM (menu_shell->active_menu_item))
+ {
+ /* We are leaving an active menu item with nonactive submenu.
+ * Deselect it so we don't surprise the user with by popping
+ * up a submenu _after_ he left the item.
+ */
+ gtk_menu_shell_deselect (menu_shell);
+ return TRUE;
+ }
}
- return GTK_WIDGET_CLASS (parent_class)->leave_notify_event (widget, event);
+ return GTK_WIDGET_CLASS (gtk_menu_parent_class)->leave_notify_event (widget, event);
}
static void
{
gdk_region_destroy (menu->navigation_region);
menu->navigation_region = NULL;
- }
-
+ }
if (menu->navigation_timeout)
{
g_source_remove (menu->navigation_timeout);
GtkMenu *menu = user_data;
GdkWindow *child_window;
- GDK_THREADS_ENTER ();
-
gtk_menu_stop_navigating_submenu (menu);
if (GTK_WIDGET_REALIZED (menu))
send_event->crossing.time = GDK_CURRENT_TIME; /* Bogus */
send_event->crossing.send_event = TRUE;
- GTK_WIDGET_CLASS (parent_class)->enter_notify_event (GTK_WIDGET (menu), (GdkEventCrossing *)send_event);
+ GTK_WIDGET_CLASS (gtk_menu_parent_class)->enter_notify_event (GTK_WIDGET (menu), (GdkEventCrossing *)send_event);
gdk_event_free (send_event);
}
}
- GDK_THREADS_LEAVE ();
-
return FALSE;
}
"gtk-menu-popdown-delay", &popdown_delay,
NULL);
- menu->navigation_timeout = g_timeout_add (popdown_delay,
+ menu->navigation_timeout = gdk_threads_add_timeout (popdown_delay,
gtk_menu_stop_navigating_submenu_cb, menu);
#ifdef DRAW_STAY_UP_TRIANGLE
gint x, y;
gint scroll_offset;
gint menu_height;
- gboolean push_in;
GdkScreen *screen;
GdkScreen *pointer_screen;
GdkRectangle monitor;
-
+ gint scroll_arrow_height;
+
g_return_if_fail (GTK_IS_MENU (menu));
widget = GTK_WIDGET (menu);
gdk_display_get_pointer (gdk_screen_get_display (screen),
&pointer_screen, &x, &y, NULL);
+ gtk_widget_style_get (GTK_WIDGET (menu),
+ "scroll-arrow-vlength", &scroll_arrow_height,
+ NULL);
+
/* We need the requisition to figure out the right place to
* popup the menu. In fact, we always need to ask here, since
* if a size_request was queued while we weren't popped up,
private = gtk_menu_get_private (menu);
private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
- push_in = FALSE;
+ private->initially_pushed_in = FALSE;
+
+ /* Set the type hint here to allow custom position functions to set a different hint */
+ if (!GTK_WIDGET_VISIBLE (menu->toplevel))
+ gtk_window_set_type_hint (GTK_WINDOW (menu->toplevel), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
if (menu->position_func)
{
- (* menu->position_func) (menu, &x, &y, &push_in, menu->position_func_data);
+ (* menu->position_func) (menu, &x, &y, &private->initially_pushed_in,
+ menu->position_func_data);
+ if (private->monitor_num < 0)
+ private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
+
gdk_screen_get_monitor_geometry (screen, private->monitor_num, &monitor);
}
else
scroll_offset = 0;
- if (push_in)
+ if (private->initially_pushed_in)
{
menu_height = GTK_WIDGET (menu)->requisition.height;
}
if (scroll_offset > 0)
- scroll_offset += MENU_SCROLL_ARROW_HEIGHT;
+ scroll_offset += scroll_arrow_height;
gtk_window_move (GTK_WINDOW (GTK_MENU_SHELL (menu)->active ? menu->toplevel : menu->tearoff_window),
x, y);
static void
gtk_menu_stop_scrolling (GtkMenu *menu)
{
- gtk_menu_remove_scroll_timeout (menu);
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (menu));
+ gboolean touchscreen_mode;
- menu->upper_arrow_prelight = FALSE;
- menu->lower_arrow_prelight = FALSE;
+ gtk_menu_remove_scroll_timeout (menu);
+
+ g_object_get (G_OBJECT (settings),
+ "gtk-touchscreen-mode", &touchscreen_mode,
+ NULL);
+
+ if (!touchscreen_mode)
+ {
+ menu->upper_arrow_prelight = FALSE;
+ menu->lower_arrow_prelight = FALSE;
+ }
}
static void
gint x, y;
gint view_width, view_height;
gint border_width;
- gboolean last_visible;
gint menu_height;
guint vertical_padding;
-
+ guint horizontal_padding;
+ gboolean double_arrows;
+ gint scroll_arrow_height;
+
widget = GTK_WIDGET (menu);
if (menu->tearoff_active &&
view_height = widget->allocation.height;
gtk_widget_style_get (GTK_WIDGET (menu),
- "vertical-padding", &vertical_padding,
- NULL);
-
+ "vertical-padding", &vertical_padding,
+ "horizontal-padding", &horizontal_padding,
+ "scroll-arrow-vlength", &scroll_arrow_height,
+ NULL);
+
+ double_arrows = get_double_arrows (menu);
+
border_width = GTK_CONTAINER (menu)->border_width;
- view_width -= (border_width + widget->style->xthickness) * 2;
+ view_width -= (border_width + widget->style->xthickness + horizontal_padding) * 2;
view_height -= (border_width + widget->style->ythickness + vertical_padding) * 2;
menu_height = widget->requisition.height -
- (border_width + widget->style->ythickness + vertical_padding) * 2;
+ (border_width + widget->style->ythickness + vertical_padding) * 2;
- x = border_width + widget->style->xthickness;
+ x = border_width + widget->style->xthickness + horizontal_padding;
y = border_width + widget->style->ythickness + vertical_padding;
- if (!menu->tearoff_active)
+ if (double_arrows && !menu->tearoff_active)
{
+ if (view_height < menu_height ||
+ (offset > 0 && menu->scroll_offset > 0) ||
+ (offset < 0 && menu->scroll_offset < 0))
+ {
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+ GtkStateType upper_arrow_previous_state = priv->upper_arrow_state;
+ GtkStateType lower_arrow_previous_state = priv->lower_arrow_state;
+
+ if (!menu->upper_arrow_visible || !menu->lower_arrow_visible)
+ gtk_widget_queue_draw (GTK_WIDGET (menu));
+
+ view_height -= 2 * scroll_arrow_height;
+ y += scroll_arrow_height;
+
+ menu->upper_arrow_visible = menu->lower_arrow_visible = TRUE;
+
+ if (offset <= 0)
+ priv->upper_arrow_state = GTK_STATE_INSENSITIVE;
+ else
+ priv->upper_arrow_state = menu->upper_arrow_prelight ?
+ GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
+
+ if (offset >= menu_height - view_height)
+ priv->lower_arrow_state = GTK_STATE_INSENSITIVE;
+ else
+ priv->lower_arrow_state = menu->lower_arrow_prelight ?
+ GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
+
+ if ((priv->upper_arrow_state != upper_arrow_previous_state) ||
+ (priv->lower_arrow_state != lower_arrow_previous_state))
+ gtk_widget_queue_draw (GTK_WIDGET (menu));
+
+ if (upper_arrow_previous_state != GTK_STATE_INSENSITIVE &&
+ priv->upper_arrow_state == GTK_STATE_INSENSITIVE)
+ {
+ /* At the upper border, possibly remove timeout */
+ if (menu->scroll_step < 0)
+ {
+ gtk_menu_stop_scrolling (menu);
+ gtk_widget_queue_draw (GTK_WIDGET (menu));
+ }
+ }
+
+ if (lower_arrow_previous_state != GTK_STATE_INSENSITIVE &&
+ priv->lower_arrow_state == GTK_STATE_INSENSITIVE)
+ {
+ /* At the lower border, possibly remove timeout */
+ if (menu->scroll_step > 0)
+ {
+ gtk_menu_stop_scrolling (menu);
+ gtk_widget_queue_draw (GTK_WIDGET (menu));
+ }
+ }
+ }
+ else if (menu->upper_arrow_visible || menu->lower_arrow_visible)
+ {
+ offset = 0;
+
+ menu->upper_arrow_visible = menu->lower_arrow_visible = FALSE;
+ menu->upper_arrow_prelight = menu->lower_arrow_prelight = FALSE;
+
+ gtk_menu_stop_scrolling (menu);
+ gtk_widget_queue_draw (GTK_WIDGET (menu));
+ }
+ }
+ else if (!menu->tearoff_active)
+ {
+ gboolean last_visible;
+
last_visible = menu->upper_arrow_visible;
menu->upper_arrow_visible = offset > 0;
if (menu->upper_arrow_visible)
- view_height -= MENU_SCROLL_ARROW_HEIGHT;
+ view_height -= scroll_arrow_height;
- if ( (last_visible != menu->upper_arrow_visible) &&
- !menu->upper_arrow_visible)
+ if ((last_visible != menu->upper_arrow_visible) &&
+ !menu->upper_arrow_visible)
{
- menu->upper_arrow_prelight = FALSE;
-
+ menu->upper_arrow_prelight = FALSE;
+
/* If we hid the upper arrow, possibly remove timeout */
if (menu->scroll_step < 0)
{
menu->lower_arrow_visible = offset < menu_height - view_height;
if (menu->lower_arrow_visible)
- view_height -= MENU_SCROLL_ARROW_HEIGHT;
+ view_height -= scroll_arrow_height;
- if ( (last_visible != menu->lower_arrow_visible) &&
+ if ((last_visible != menu->lower_arrow_visible) &&
!menu->lower_arrow_visible)
{
- menu->lower_arrow_prelight = FALSE;
-
+ menu->lower_arrow_prelight = FALSE;
+
/* If we hid the lower arrow, possibly remove timeout */
if (menu->scroll_step > 0)
{
}
if (menu->upper_arrow_visible)
- y += MENU_SCROLL_ARROW_HEIGHT;
+ y += scroll_arrow_height;
}
/* Scroll the menu: */
gboolean *is_last_child)
{
GtkMenuPrivate *priv = gtk_menu_get_private (menu);
- guint item_top_attach;
- guint item_bottom_attach;
+ gint item_top_attach;
+ gint item_bottom_attach;
gint child_offset = 0;
gint i;
- gtk_container_child_get (GTK_CONTAINER (menu), menu_item,
- "top_attach", &item_top_attach,
- "bottom_attach", &item_bottom_attach,
- NULL);
+ get_effective_child_attach (menu_item, NULL, NULL,
+ &item_top_attach, &item_bottom_attach);
/* there is a possibility that we get called before _size_request, so
* check the height table for safety.
*/
- if (!priv->heights || priv->heights_length < priv->rows)
+ if (!priv->heights || priv->heights_length < gtk_menu_get_n_rows (menu))
return FALSE;
/* when we have a row with only invisible children, it's height will
child_offset += priv->heights[i];
if (is_last_child)
- *is_last_child = (item_bottom_attach == priv->rows);
+ *is_last_child = (item_bottom_attach == gtk_menu_get_n_rows (menu));
if (offset)
*offset = child_offset;
if (height)
&child_offset, &child_height, &last_child))
{
guint vertical_padding;
+ gboolean double_arrows;
+ gint scroll_arrow_height;
y = menu->scroll_offset;
gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
gtk_widget_style_get (GTK_WIDGET (menu),
"vertical-padding", &vertical_padding,
- NULL);
-
+ "scroll-arrow-vlength", &scroll_arrow_height,
+ NULL);
+
+ double_arrows = get_double_arrows (menu);
+
height -= 2*GTK_CONTAINER (menu)->border_width + 2*GTK_WIDGET (menu)->style->ythickness + 2*vertical_padding;
if (child_offset < y)
{
arrow_height = 0;
if (menu->upper_arrow_visible && !menu->tearoff_active)
- arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+ arrow_height += scroll_arrow_height;
if (menu->lower_arrow_visible && !menu->tearoff_active)
- arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+ arrow_height += scroll_arrow_height;
if (child_offset + child_height > y + height - arrow_height)
{
arrow_height = 0;
- if (!last_child && !menu->tearoff_active)
- arrow_height += MENU_SCROLL_ARROW_HEIGHT;
-
+ if ((!last_child && !menu->tearoff_active) || double_arrows)
+ arrow_height += scroll_arrow_height;
+
y = child_offset + child_height - height + arrow_height;
- if ((y > 0) && !menu->tearoff_active)
+ if (((y > 0) && !menu->tearoff_active) || double_arrows)
{
/* Need upper arrow */
- arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+ arrow_height += scroll_arrow_height;
y = child_offset + child_height - height + arrow_height;
}
/* Ignore the enter event we might get if the pointer is on the menu
if (GTK_WIDGET_REALIZED (GTK_WIDGET (menu)))
gtk_menu_scroll_item_visible (menu_shell, menu_item);
- GTK_MENU_SHELL_CLASS (parent_class)->select_item (menu_shell, menu_item);
+ GTK_MENU_SHELL_CLASS (gtk_menu_parent_class)->select_item (menu_shell, menu_item);
}
{
GtkObject *object = GTK_OBJECT (menu);
GtkWidget *widget = GTK_WIDGET (menu);
- gboolean was_floating = GTK_OBJECT_FLOATING (object);
+ gboolean was_floating = g_object_is_floating (object);
- g_object_ref (object);
- gtk_object_sink (object);
+ g_object_ref_sink (object);
if (unrealize)
{
gtk_widget_reparent (GTK_WIDGET (menu), new_parent);
if (was_floating)
- GTK_OBJECT_SET_FLAGS (object, GTK_FLOATING);
+ g_object_force_floating (G_OBJECT (object));
else
g_object_unref (object);
}
g_return_if_fail (GTK_IS_MENU (menu));
g_return_if_fail (!screen || GDK_IS_SCREEN (screen));
- g_object_set_data (G_OBJECT (menu), "gtk-menu-explicit-screen", screen);
+ g_object_set_data (G_OBJECT (menu), I_("gtk-menu-explicit-screen"), screen);
if (screen)
{
guint top_attach,
guint bottom_attach)
{
+ GtkMenuShell *menu_shell;
+
g_return_if_fail (GTK_IS_MENU (menu));
g_return_if_fail (GTK_IS_MENU_ITEM (child));
g_return_if_fail (child->parent == NULL ||
g_return_if_fail (left_attach < right_attach);
g_return_if_fail (top_attach < bottom_attach);
+ menu_shell = GTK_MENU_SHELL (menu);
+
if (!child->parent)
{
- GTK_MENU_SHELL (menu)->children =
- g_list_append (GTK_MENU_SHELL (menu)->children, child);
+ AttachInfo *ai = get_attach_info (child);
+
+ ai->left_attach = left_attach;
+ ai->right_attach = right_attach;
+ ai->top_attach = top_attach;
+ ai->bottom_attach = bottom_attach;
+
+ menu_shell->children = g_list_append (menu_shell->children, child);
gtk_widget_set_parent (child, GTK_WIDGET (menu));
- }
- gtk_container_child_set (GTK_CONTAINER (menu), child,
- "left_attach", left_attach,
- "right_attach", right_attach,
- "top_attach", top_attach,
- "bottom_attach", bottom_attach,
- NULL);
+ menu_queue_resize (menu);
+ }
+ else
+ {
+ gtk_container_child_set (GTK_CONTAINER (child->parent), child,
+ "left-attach", left_attach,
+ "right-attach", right_attach,
+ "top-attach", top_attach,
+ "bottom-attach", bottom_attach,
+ NULL);
+ }
}
static gint
for (list = menu_shell->children; list; list = list->next)
{
- guint l, r, t, b;
+ gint l, r, t, b;
if (!_gtk_menu_item_is_selectable (list->data))
continue;
- get_child_attach (list->data, &l, &r, &t, &b);
+ get_effective_child_attach (list->data, &l, &r, &t, &b);
if (l <= left && right <= r
&& t <= top && bottom <= b)
gtk_menu_move_current (GtkMenuShell *menu_shell,
GtkMenuDirectionType direction)
{
- GtkMenuPrivate *priv = gtk_menu_get_private (GTK_MENU (menu_shell));
+ GtkMenu *menu = GTK_MENU (menu_shell);
+ gint i;
+ gint l, r, t, b;
+ GtkWidget *match = NULL;
- /* use special table menu key bindings */
- if (menu_shell->active_menu_item && priv->columns > 1)
+ if (gtk_widget_get_direction (GTK_WIDGET (menu_shell)) == GTK_TEXT_DIR_RTL)
{
- int i;
- guint l, r, t, b;
- gboolean rtl = (gtk_widget_get_direction (GTK_WIDGET (menu_shell)) == GTK_TEXT_DIR_RTL);
- GtkWidget *match = NULL;
+ switch (direction)
+ {
+ case GTK_MENU_DIR_CHILD:
+ direction = GTK_MENU_DIR_PARENT;
+ break;
+ case GTK_MENU_DIR_PARENT:
+ direction = GTK_MENU_DIR_CHILD;
+ break;
+ default: ;
+ }
+ }
- get_child_attach (menu_shell->active_menu_item, &l, &r, &t, &b);
+ /* use special table menu key bindings */
+ if (menu_shell->active_menu_item && gtk_menu_get_n_columns (menu) > 1)
+ {
+ get_effective_child_attach (menu_shell->active_menu_item, &l, &r, &t, &b);
if (direction == GTK_MENU_DIR_NEXT)
{
- for (i = b; i < priv->rows; i++)
+ for (i = b; i < gtk_menu_get_n_rows (menu); i++)
{
match = find_child_containing (menu_shell, l, l + 1, i, i + 1);
if (match)
if (!match)
{
/* wrap around */
- for (i = priv->rows; i > b; i--)
+ for (i = gtk_menu_get_n_rows (menu); i > b; i--)
{
match = find_child_containing (menu_shell,
l, l + 1, i - 1, i);
}
}
}
- else if ((!rtl && direction == GTK_MENU_DIR_PARENT)
- || (rtl && direction == GTK_MENU_DIR_CHILD))
+ else if (direction == GTK_MENU_DIR_PARENT)
{
/* we go one left if possible */
if (l > 0)
match = menu_shell->active_menu_item;
}
}
- else if ((!rtl && direction == GTK_MENU_DIR_CHILD)
- || (rtl && direction == GTK_MENU_DIR_PARENT))
+ else if (direction == GTK_MENU_DIR_CHILD)
{
/* we go one right if possible */
- if (r < priv->columns)
+ if (r < gtk_menu_get_n_columns (menu))
match = find_child_containing (menu_shell, r, r + 1, t, t + 1);
if (!match)
}
}
- GTK_MENU_SHELL_CLASS (parent_class)->move_current (menu_shell, direction);
+ GTK_MENU_SHELL_CLASS (gtk_menu_parent_class)->move_current (menu_shell, direction);
}
static gint
{
GtkWidget *widget = GTK_WIDGET (menu);
GtkContainer *container = GTK_CONTAINER (menu);
+ gint scroll_arrow_height;
gint menu_height = (widget->allocation.height
- 2 * (container->border_width
+ widget->style->ythickness));
+ gtk_widget_style_get (GTK_WIDGET (menu),
+ "scroll-arrow-vlength", &scroll_arrow_height,
+ NULL);
+
if (menu->upper_arrow_visible && !menu->tearoff_active)
- menu_height -= MENU_SCROLL_ARROW_HEIGHT;
+ menu_height -= scroll_arrow_height;
if (menu->lower_arrow_visible && !menu->tearoff_active)
- menu_height -= MENU_SCROLL_ARROW_HEIGHT;
+ menu_height -= scroll_arrow_height;
return menu_height;
}
{
gint height;
GtkWidget *widget = GTK_WIDGET (menu);
+ gint scroll_arrow_height;
+ gtk_widget_style_get (GTK_WIDGET (menu),
+ "scroll-arrow-vlength", &scroll_arrow_height,
+ NULL);
+
height = widget->requisition.height;
height -= (GTK_CONTAINER (widget)->border_width + widget->style->ythickness) * 2;
if (menu->upper_arrow_visible && !menu->tearoff_active)
- height -= MENU_SCROLL_ARROW_HEIGHT;
+ height -= scroll_arrow_height;
if (menu->lower_arrow_visible && !menu->tearoff_active)
- height -= MENU_SCROLL_ARROW_HEIGHT;
+ height -= scroll_arrow_height;
return height;
}
gint page_size = get_visible_size (menu);
gint end_position = get_menu_height (menu);
GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
+ gint scroll_arrow_height;
+
+ gtk_widget_style_get (GTK_WIDGET (menu),
+ "scroll-arrow-vlength", &scroll_arrow_height,
+ NULL);
switch (type)
{
if (menu->scroll_offset != old_offset)
step = menu->scroll_offset - old_offset;
- step -= (new_upper_arrow_visible - old_upper_arrow_visible) * MENU_SCROLL_ARROW_HEIGHT;
+ step -= (new_upper_arrow_visible - old_upper_arrow_visible) * scroll_arrow_height;
new_child = child_at (menu, child_offset + step);
if (new_child)
*
* Since: 2.4
**/
-void gtk_menu_set_monitor (GtkMenu *menu,
- gint monitor_num)
+void
+gtk_menu_set_monitor (GtkMenu *menu,
+ gint monitor_num)
{
GtkMenuPrivate *priv;
g_return_if_fail (GTK_IS_MENU (menu));
priv->monitor_num = monitor_num;
}
+
+/**
+ * gtk_menu_get_for_attach_widget:
+ * @widget: a #GtkWidget
+ *
+ * Returns a list of the menus which are attached to this widget.
+ * This list is owned by GTK+ and must not be modified.
+ *
+ * Return value: the list of menus attached to his widget.
+ *
+ * Since: 2.6
+ **/
+GList*
+gtk_menu_get_for_attach_widget (GtkWidget *widget)
+{
+ GList *list;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+ list = g_object_get_data (G_OBJECT (widget), ATTACHED_MENUS);
+ return list;
+}
+
+static void
+gtk_menu_grab_notify (GtkWidget *widget,
+ gboolean was_grabbed)
+{
+ GtkWidget *toplevel;
+ GtkWindowGroup *group;
+ GtkWidget *grab;
+
+ toplevel = gtk_widget_get_toplevel (widget);
+ group = gtk_window_get_group (GTK_WINDOW (toplevel));
+ grab = _gtk_window_group_get_current_grab (group);
+
+ if (!was_grabbed)
+ {
+ if (GTK_MENU_SHELL (widget)->active && !GTK_IS_MENU_SHELL (grab))
+ gtk_menu_shell_cancel (GTK_MENU_SHELL (widget));
+ }
+}
+
+#define __GTK_MENU_C__
+#include "gtkaliasdef.c"