1,
G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_int ("vertical-offset",
+ _("Vertical Offset"),
+ _("When the menu is a submenu, position it this number of pixels offset vertically"),
+ G_MININT,
+ G_MAXINT,
+ 0,
+ G_PARAM_READABLE));
+
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_int ("horizontal-offset",
+ _("Horizontal Offset"),
+ _("When the menu is a submenu, position it this number of pixels offset horizontally"),
+ G_MININT,
+ G_MAXINT,
+ -2,
+ G_PARAM_READABLE));
+
object_class->destroy = gtk_menu_destroy;
widget_class->realize = gtk_menu_realize;
0);
}
+static void
+get_offsets (GtkMenu *menu,
+ gint *horizontal_offset,
+ gint *vertical_offset)
+{
+ gint vertical_padding;
+
+ gtk_widget_style_get (GTK_WIDGET (menu),
+ "horizontal_offset", horizontal_offset,
+ "vertical_offset", vertical_offset,
+ "vertical_padding", &vertical_padding,
+ NULL);
+
+ *vertical_offset -= GTK_WIDGET (menu)->style->ythickness;
+ *vertical_offset -= vertical_padding;
+}
+
static void
gtk_menu_item_position_menu (GtkMenu *menu,
gint *x,
GtkTextDirection direction;
GdkRectangle monitor;
gint monitor_num;
+ gint horizontal_offset;
+ gint vertical_offset;
+ gint parent_xthickness;
g_return_if_fail (menu != NULL);
g_return_if_fail (x != NULL);
menu_item = GTK_MENU_ITEM (user_data);
widget = GTK_WIDGET (user_data);
+ if (push_in)
+ *push_in = FALSE;
+
direction = gtk_widget_get_direction (widget);
twidth = GTK_WIDGET (menu)->requisition.width;
tx += widget->allocation.x;
ty += widget->allocation.y;
+ get_offsets (menu, &horizontal_offset, &vertical_offset);
+
switch (menu_item->submenu_placement)
{
case GTK_TOP_BOTTOM:
case GTK_LEFT_RIGHT:
parent_menu_item = GTK_MENU (widget->parent)->parent_menu_item;
+ parent_xthickness = widget->parent->style->xthickness;
if (parent_menu_item &&
!GTK_MENU (widget->parent)->torn_off &&
!GTK_MENU_SHELL (menu)->active)
switch (menu_item->submenu_direction)
{
case GTK_DIRECTION_LEFT:
- if ((tx - twidth) >= monitor.x)
- tx -= twidth;
+ if ((tx - twidth - parent_xthickness - horizontal_offset) >= monitor.x)
+ tx -= twidth + parent_xthickness + horizontal_offset;
else
{
menu_item->submenu_direction = GTK_DIRECTION_RIGHT;
- tx += widget->allocation.width - 5;
+ tx += widget->allocation.width + parent_xthickness + horizontal_offset;
}
break;
case GTK_DIRECTION_RIGHT:
- if ((tx + widget->allocation.width + twidth - 5) <= monitor.x + monitor.width)
- tx += widget->allocation.width - 5;
+ if ((tx + widget->allocation.width + parent_xthickness + horizontal_offset + twidth) <= monitor.x + monitor.width)
+ tx += widget->allocation.width + parent_xthickness + horizontal_offset;
else
{
menu_item->submenu_direction = GTK_DIRECTION_LEFT;
- tx -= twidth;
+ tx -= twidth + parent_xthickness + horizontal_offset;
}
break;
}
- ty += widget->allocation.height / 4;
-
+ ty += vertical_offset;
+
/* If the height of the menu doesn't fit we move it upward. */
ty = CLAMP (ty, monitor.y, MAX (monitor.y, monitor.y + monitor.height - theight));
break;