summaryrefslogtreecommitdiff
path: root/gtk/gtkmenuitem.c
diff options
context:
space:
mode:
authorSoeren Sandmann <sandmann@daimi.au.dk>2003-07-12 23:25:14 +0000
committerSøren Sandmann Pedersen <ssp@src.gnome.org>2003-07-12 23:25:14 +0000
commitd77b4c1448291db67763d9f4f688d09b1a06f310 (patch)
tree96467171e7631df20c1cf807d3de641e6af94e68 /gtk/gtkmenuitem.c
parent497de299e8b271a693833fe8b5128988eba3a3e4 (diff)
downloadgtk+-d77b4c1448291db67763d9f4f688d09b1a06f310.tar.gz
new properties "horizontal-offset" and "vertical-offset" that determines
Sun Jul 13 01:37:51 2003 Soeren Sandmann <sandmann@daimi.au.dk> * gtk/gtkmenu.c (gtk_menu_class_init): new properties "horizontal-offset" and "vertical-offset" that determines the position of the menu when it is a submenu. * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): position submenus according to new vertical- and horizontal-offset properties.
Diffstat (limited to 'gtk/gtkmenuitem.c')
-rw-r--r--gtk/gtkmenuitem.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index a2a98a9cda..eca9b46629 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -972,6 +972,23 @@ gtk_menu_item_popup_submenu (gpointer data)
}
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,
gint *y,
@@ -987,6 +1004,9 @@ gtk_menu_item_position_menu (GtkMenu *menu,
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);
@@ -995,6 +1015,9 @@ gtk_menu_item_position_menu (GtkMenu *menu,
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;
@@ -1015,6 +1038,8 @@ gtk_menu_item_position_menu (GtkMenu *menu,
tx += widget->allocation.x;
ty += widget->allocation.y;
+ get_offsets (menu, &horizontal_offset, &vertical_offset);
+
switch (menu_item->submenu_placement)
{
case GTK_TOP_BOTTOM:
@@ -1038,6 +1063,7 @@ gtk_menu_item_position_menu (GtkMenu *menu,
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)
@@ -1050,28 +1076,28 @@ gtk_menu_item_position_menu (GtkMenu *menu,
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;