#include "gtkaccellabel.h"
#include "gtkaccelmap.h"
#include "gtkbindings.h"
+#include "gtkcheckmenuitem.h"
+#include <gobject/gvaluecollector.h>
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkmenu.h"
struct _GtkMenuPrivate
{
- gboolean seen_item_enter;
-
- gboolean have_position;
gint x;
gint y;
+ gboolean initially_pushed_in;
/* info used for the table */
guint *heights;
gint monitor_num;
/* Cached layout information */
- gboolean have_layout;
gint n_rows;
gint n_columns;
GtkStateType lower_arrow_state;
GtkStateType upper_arrow_state;
- gboolean ignore_button_release;
- gboolean initially_pushed_in;
+ guint have_layout : 1;
+ guint seen_item_enter : 1;
+ guint have_position : 1;
+ guint ignore_button_release : 1;
+ guint no_toggle_size : 1;
};
typedef struct
PROP_ATTACH_WIDGET,
PROP_TEAROFF_STATE,
PROP_TEAROFF_TITLE,
- PROP_MONITOR
+ PROP_MONITOR,
+ PROP_RESERVE_TOGGLE_SIZE
};
enum {
1,
GTK_PARAM_READABLE));
+ /**
+ * GtkMenu:reserve-toggle-size:
+ *
+ * A boolean that indicates whether the menu reserves space for
+ * toggles and icons, regardless of their actual presence.
+ *
+ * This property should only be changed from its default value
+ * for special-purposes such as tabular menus. Regular menus that
+ * are connected to a menu bar or context menus should reserve
+ * toggle space for consistency.
+ *
+ * Since: 2.18
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_RESERVE_TOGGLE_SIZE,
+ g_param_spec_boolean ("reserve-toggle-size",
+ P_("Reserve Toggle Size"),
+ P_("A boolean that indicates whether the menu reserves space for toggles and icons"),
+ TRUE,
+ GTK_PARAM_READWRITE));
+
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("horizontal-padding",
P_("Horizontal Padding"),
TRUE,
GTK_PARAM_READABLE));
+ /**
+ * GtkMenu:arrow-placement:
+ *
+ * Indicates where scroll arrows should be placed.
+ *
+ * Since: 2.16
+ **/
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_enum ("arrow-placement",
+ P_("Arrow Placement"),
+ P_("Indicates where scroll arrows should be placed"),
+ GTK_TYPE_ARROW_PLACEMENT,
+ GTK_ARROWS_BOTH,
+ GTK_PARAM_READABLE));
gtk_container_class_install_child_property (container_class,
CHILD_PROP_LEFT_ATTACH,
-1, INT_MAX, -1,
GTK_PARAM_READWRITE));
+ /**
+ * GtkMenu::arrow-scaling
+ *
+ * Arbitrary constant to scale down the size of the scroll arrow.
+ *
+ * Since: 2.16
+ */
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_float ("arrow-scaling",
+ P_("Arrow Scaling"),
+ P_("Arbitrary constant to scale down the size of the scroll arrow"),
+ 0.0, 1.0, 0.7,
+ GTK_PARAM_READABLE));
+
binding_set = gtk_binding_set_by_class (class);
gtk_binding_entry_add_signal (binding_set,
GDK_Up, 0,
case PROP_MONITOR:
gtk_menu_set_monitor (menu, g_value_get_int (value));
break;
+ case PROP_RESERVE_TOGGLE_SIZE:
+ gtk_menu_set_reserve_toggle_size (menu, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_MONITOR:
g_value_set_int (value, gtk_menu_get_monitor (menu));
break;
+ case PROP_RESERVE_TOGGLE_SIZE:
+ g_value_set_boolean (value, gtk_menu_get_reserve_toggle_size (menu));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
if (xgrab_shell == widget)
popup_grab_on_window (widget->window, activate_time, grab_keyboard); /* Should always succeed */
gtk_grab_add (GTK_WIDGET (menu));
+
+ if (parent_menu_shell)
+ {
+ gboolean keyboard_mode;
+
+ keyboard_mode = _gtk_menu_shell_get_keyboard_mode (GTK_MENU_SHELL (parent_menu_shell));
+ _gtk_menu_shell_set_keyboard_mode (menu_shell, keyboard_mode);
+ }
+ else if (menu_shell->button == 0) /* a keynav-activated context menu */
+ _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
+
+ _gtk_menu_shell_update_mnemonics (menu_shell);
}
void
}
}
+
+/**
+ * gtk_menu_set_accel_group:
+ * @accel_group: (allow-none):
+ */
void
gtk_menu_set_accel_group (GtkMenu *menu,
GtkAccelGroup *accel_group)
/**
* gtk_menu_set_accel_path
* @menu: a valid #GtkMenu
- * @accel_path: a valid accelerator path
+ * @accel_path: (allow-none): a valid accelerator path
*
* Sets an accelerator path for this menu from which accelerator paths
* for its immediate children, its menu items, can be constructed.
else if (GTK_IS_WIDGET (attach))
{
toplevel = gtk_widget_get_toplevel (attach);
- if (GTK_WIDGET_TOPLEVEL (toplevel))
+ if (gtk_widget_is_toplevel (toplevel))
return toplevel;
}
GtkBorder *border)
{
guint scroll_arrow_height;
+ GtkArrowPlacement arrow_placement;
gtk_widget_style_get (GTK_WIDGET (menu),
"scroll-arrow-vlength", &scroll_arrow_height,
+ "arrow_placement", &arrow_placement,
NULL);
- border->top = menu->upper_arrow_visible ? scroll_arrow_height : 0;
- border->bottom = menu->lower_arrow_visible ? scroll_arrow_height : 0;
+ switch (arrow_placement)
+ {
+ case GTK_ARROWS_BOTH:
+ border->top = menu->upper_arrow_visible ? scroll_arrow_height : 0;
+ border->bottom = menu->lower_arrow_visible ? scroll_arrow_height : 0;
+ break;
+
+ case GTK_ARROWS_START:
+ border->top = (menu->upper_arrow_visible ||
+ menu->lower_arrow_visible) ? scroll_arrow_height : 0;
+ border->bottom = 0;
+ break;
+
+ case GTK_ARROWS_END:
+ border->top = 0;
+ border->bottom = (menu->upper_arrow_visible ||
+ menu->lower_arrow_visible) ? scroll_arrow_height : 0;
+ break;
+ }
border->left = border->right = 0;
}
priv->heights[t] = MAX (priv->heights[t], part);
}
+ /* If the menu doesn't include any images or check items
+ * reserve the space so that all menus are consistent.
+ * We only do this for 'ordinary' menus, not for combobox
+ * menus or multi-column menus
+ */
+ if (max_toggle_size == 0 &&
+ gtk_menu_get_n_columns (menu) == 1 &&
+ !priv->no_toggle_size)
+ {
+ guint toggle_spacing;
+ guint indicator_size;
+
+ gtk_style_get (widget->style,
+ GTK_TYPE_CHECK_MENU_ITEM,
+ "toggle-spacing", &toggle_spacing,
+ "indicator-size", &indicator_size,
+ NULL);
+
+ max_toggle_size = indicator_size + toggle_spacing;
+ }
+
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 += 2 * max_toggle_size + max_accel_width;
requisition->width *= gtk_menu_get_n_columns (menu);
gtk_widget_style_get (GTK_WIDGET (menu),
guint vertical_padding;
guint horizontal_padding;
gint scroll_arrow_height;
+ GtkArrowPlacement arrow_placement;
gtk_widget_style_get (widget,
"vertical-padding", &vertical_padding,
"horizontal-padding", &horizontal_padding,
"scroll-arrow-vlength", &scroll_arrow_height,
+ "arrow-placement", &arrow_placement,
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, &border->width, &border->height);
- upper->x = border->x;
- upper->y = border->y;
- upper->width = border->width - 2 * border->x;
- upper->height = scroll_arrow_height;
+ switch (arrow_placement)
+ {
+ case GTK_ARROWS_BOTH:
+ upper->x = border->x;
+ upper->y = border->y;
+ upper->width = border->width - 2 * border->x;
+ upper->height = scroll_arrow_height;
+
+ lower->x = border->x;
+ lower->y = border->height - border->y - scroll_arrow_height;
+ lower->width = border->width - 2 * border->x;
+ lower->height = scroll_arrow_height;
+ break;
- lower->x = border->x;
- lower->y = border->height - border->y - scroll_arrow_height;
- lower->width = border->width - 2 * border->x;
- lower->height = scroll_arrow_height;
+ case GTK_ARROWS_START:
+ upper->x = border->x;
+ upper->y = border->y;
+ upper->width = (border->width - 2 * border->x) / 2;
+ upper->height = scroll_arrow_height;
+
+ lower->x = border->x + upper->width;
+ lower->y = border->y;
+ lower->width = (border->width - 2 * border->x) / 2;
+ lower->height = scroll_arrow_height;
+ break;
+
+ case GTK_ARROWS_END:
+ upper->x = border->x;
+ upper->y = border->height - border->y - scroll_arrow_height;
+ upper->width = (border->width - 2 * border->x) / 2;
+ upper->height = scroll_arrow_height;
+
+ lower->x = border->x + upper->width;
+ lower->y = border->height - border->y - scroll_arrow_height;
+ lower->width = (border->width - 2 * border->x) / 2;
+ lower->height = scroll_arrow_height;
+ break;
+
+ default:
+ g_assert_not_reached();
+ upper->x = upper->y = upper->width = upper->height = 0;
+ lower->x = lower->y = lower->width = lower->height = 0;
+ }
*arrow_space = scroll_arrow_height - 2 * widget->style->ythickness;
}
if (event->window == widget->window)
{
- gint arrow_size = 0.7 * arrow_space;
+ gfloat arrow_scaling;
+ gint arrow_size;
+
+ gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
+ arrow_size = arrow_scaling * arrow_space;
gtk_paint_box (widget->style,
widget->window,
static gboolean
get_double_arrows (GtkMenu *menu)
{
- GtkMenuPrivate *priv = gtk_menu_get_private (menu);
- gboolean double_arrows;
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+ gboolean double_arrows;
+ GtkArrowPlacement arrow_placement;
gtk_widget_style_get (GTK_WIDGET (menu),
"double-arrows", &double_arrows,
+ "arrow-placement", &arrow_placement,
NULL);
+ if (arrow_placement != GTK_ARROWS_BOTH)
+ return TRUE;
+
return double_arrows || (priv->initially_pushed_in &&
menu->scroll_offset != 0);
}
guint vertical_padding;
gint win_x, win_y;
gint scroll_arrow_height;
+ GtkArrowPlacement arrow_placement;
gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
gtk_widget_style_get (GTK_WIDGET (menu),
"vertical-padding", &vertical_padding,
"scroll-arrow-vlength", &scroll_arrow_height,
+ "arrow-placement", &arrow_placement,
NULL);
border = GTK_CONTAINER (menu)->border_width +
gdk_window_get_position (GTK_WIDGET (menu)->window, &win_x, &win_y);
- if (upper)
+ switch (arrow_placement)
{
- upper->x = win_x;
- upper->y = win_y;
- upper->width = width;
- upper->height = scroll_arrow_height + border;
- }
+ case GTK_ARROWS_BOTH:
+ if (upper)
+ {
+ upper->x = win_x;
+ upper->y = win_y;
+ upper->width = width;
+ upper->height = scroll_arrow_height + border;
+ }
- if (lower)
- {
- lower->x = win_x;
- lower->y = win_y + height - border - scroll_arrow_height;
- lower->width = width;
- lower->height = scroll_arrow_height + border;
+ if (lower)
+ {
+ lower->x = win_x;
+ lower->y = win_y + height - border - scroll_arrow_height;
+ lower->width = width;
+ lower->height = scroll_arrow_height + border;
+ }
+ break;
+
+ case GTK_ARROWS_START:
+ if (upper)
+ {
+ upper->x = win_x;
+ upper->y = win_y;
+ upper->width = width / 2;
+ upper->height = scroll_arrow_height + border;
+ }
+
+ if (lower)
+ {
+ lower->x = win_x + width / 2;
+ lower->y = win_y;
+ lower->width = width / 2;
+ lower->height = scroll_arrow_height + border;
+ }
+ break;
+
+ case GTK_ARROWS_END:
+ if (upper)
+ {
+ upper->x = win_x;
+ upper->y = win_y + height - border - scroll_arrow_height;
+ upper->width = width / 2;
+ upper->height = scroll_arrow_height + border;
+ }
+
+ if (lower)
+ {
+ lower->x = win_x + width / 2;
+ lower->y = win_y + height - border - scroll_arrow_height;
+ lower->width = width / 2;
+ lower->height = scroll_arrow_height + border;
+ }
+ break;
}
}
{
(* 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);
/**
* gtk_menu_set_screen:
* @menu: a #GtkMenu.
- * @screen: a #GdkScreen, or %NULL if the screen should be
+ * @screen: (allow-none): a #GdkScreen, or %NULL if the screen should be
* determined by the widget the menu is attached to.
*
* Sets the #GdkScreen on which the menu will be displayed.
- *
+ *
* Since: 2.2
**/
void
* 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.
+ * Return value: (element-type GtkWidget) (transfer none): the list of menus attached to his widget.
*
* Since: 2.6
**/
}
}
+/**
+ * gtk_menu_set_reserve_toggle_size:
+ * @menu: a #GtkMenu
+ * @reserve_toggle_size: whether to reserve size for toggles
+ *
+ * Sets whether the menu should reserve space for drawing toggles
+ * or icons, regardless of their actual presence.
+ *
+ * Since: 2.18
+ */
+void
+gtk_menu_set_reserve_toggle_size (GtkMenu *menu,
+ gboolean reserve_toggle_size)
+{
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+ gboolean no_toggle_size;
+
+ no_toggle_size = !reserve_toggle_size;
+
+ if (priv->no_toggle_size != no_toggle_size)
+ {
+ priv->no_toggle_size = no_toggle_size;
+
+ g_object_notify (G_OBJECT (menu), "reserve-toggle-size");
+ }
+}
+
+/**
+ * gtk_menu_get_reserve_toggle_size:
+ * @menu: a #GtkMenu
+ *
+ * Returns whether the menu reserves space for toggles and
+ * icons, regardless of their actual presence.
+ *
+ * Returns: Whether the menu reserves toggle space
+ *
+ * Since: 2.18
+ */
+gboolean
+gtk_menu_get_reserve_toggle_size (GtkMenu *menu)
+{
+ GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+
+ return !priv->no_toggle_size;
+}
+
#define __GTK_MENU_C__
#include "gtkaliasdef.c"