bubblewindow: Improve overflow cases

If the bubble window doesn't fit into one direction, it must
lay at the other side of the pointed_to rectangle.
This commit is contained in:
Carlos Garnacho
2013-11-12 12:15:53 +01:00
parent 923da6a8b8
commit d55f39d26d

View File

@ -478,15 +478,14 @@ gtk_bubble_window_update_shape (GtkBubbleWindow *window)
static void static void
gtk_bubble_window_update_position (GtkBubbleWindow *window) gtk_bubble_window_update_position (GtkBubbleWindow *window)
{ {
GtkAllocation allocation, window_alloc;
GtkBubbleWindowPrivate *priv; GtkBubbleWindowPrivate *priv;
cairo_rectangle_int_t rect; cairo_rectangle_int_t rect;
GtkAllocation allocation;
gint win_x, win_y, x, y; gint win_x, win_y, x, y;
GdkScreen *screen;
priv = window->priv; priv = window->priv;
screen = gtk_widget_get_screen (GTK_WIDGET (window));
gtk_widget_get_allocation (GTK_WIDGET (window), &allocation); gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
gtk_widget_get_allocation (GTK_WIDGET (priv->window), &window_alloc);
priv->final_position = priv->preferred_position; priv->final_position = priv->preferred_position;
rect = priv->pointing_to; rect = priv->pointing_to;
@ -498,32 +497,35 @@ gtk_bubble_window_update_position (GtkBubbleWindow *window)
if (priv->preferred_position == GTK_POS_TOP && rect.y < allocation.height) if (priv->preferred_position == GTK_POS_TOP && rect.y < allocation.height)
priv->final_position = GTK_POS_BOTTOM; priv->final_position = GTK_POS_BOTTOM;
else if (priv->preferred_position == GTK_POS_BOTTOM && else if (priv->preferred_position == GTK_POS_BOTTOM &&
rect.y > gdk_screen_get_height (screen) - allocation.height) rect.y > window_alloc.height - allocation.height)
priv->final_position = GTK_POS_TOP; priv->final_position = GTK_POS_TOP;
else if (priv->preferred_position == GTK_POS_LEFT && rect.x < allocation.width) else if (priv->preferred_position == GTK_POS_LEFT && rect.x < allocation.width)
priv->final_position = GTK_POS_RIGHT; priv->final_position = GTK_POS_RIGHT;
else if (priv->preferred_position == GTK_POS_RIGHT && else if (priv->preferred_position == GTK_POS_RIGHT &&
rect.x > gdk_screen_get_width (screen) - allocation.width) rect.x > window_alloc.width - allocation.width)
priv->final_position = GTK_POS_LEFT; priv->final_position = GTK_POS_LEFT;
if (POS_IS_VERTICAL (priv->final_position)) if (POS_IS_VERTICAL (priv->final_position))
{ {
win_x = CLAMP (x - allocation.width / 2, win_x = CLAMP (x - allocation.width / 2,
0, gdk_screen_get_width (screen) - allocation.width); 0, window_alloc.width - allocation.width);
win_y = y; win_y = y;
if (priv->final_position == GTK_POS_TOP) if (priv->final_position == GTK_POS_TOP)
win_y -= allocation.height; win_y -= allocation.height;
else if (priv->final_position == GTK_POS_BOTTOM)
win_y += rect.height;
} }
else else
{ {
win_y = CLAMP (y - allocation.height / 2, win_y = CLAMP (y - allocation.height / 2,
0, gdk_screen_get_height (screen) - allocation.height); 0, window_alloc.height - allocation.height);
win_x = x; win_x = x;
if (priv->final_position == GTK_POS_LEFT) if (priv->final_position == GTK_POS_LEFT)
win_x -= allocation.width; win_x -= allocation.width;
else if (priv->final_position == GTK_POS_RIGHT)
win_x += rect.width;
} }
priv->win_x = win_x; priv->win_x = win_x;
@ -721,6 +723,9 @@ gtk_bubble_window_size_allocate (GtkWidget *widget,
gtk_widget_set_allocation (widget, allocation); gtk_widget_set_allocation (widget, allocation);
child = gtk_bin_get_child (GTK_BIN (widget)); child = gtk_bin_get_child (GTK_BIN (widget));
if (gtk_widget_get_visible (widget))
gtk_bubble_window_update_position (GTK_BUBBLE_WINDOW (widget));
if (child) if (child)
{ {
GtkAllocation child_alloc; GtkAllocation child_alloc;
@ -752,9 +757,6 @@ gtk_bubble_window_size_allocate (GtkWidget *widget,
0, 0, allocation->width, allocation->height); 0, 0, allocation->width, allocation->height);
gtk_bubble_window_update_shape (GTK_BUBBLE_WINDOW (widget)); gtk_bubble_window_update_shape (GTK_BUBBLE_WINDOW (widget));
} }
if (gtk_widget_get_visible (widget))
gtk_bubble_window_update_position (GTK_BUBBLE_WINDOW (widget));
} }
static gboolean static gboolean