gtkwindow: Only allow unrestricted positioning to text handle popovers

This behavior has been made optional on add_popover() time, text handles
will keep being able to overflow the window, in order to allow text
selection on views too close to the window edge.

Regular GtkPopovers are reinstaurated to the previous size positioning
logic though, that is, limited by the visible area of the window.
This commit is contained in:
Carlos Garnacho 2015-07-06 16:39:06 +02:00
parent dec95caf94
commit 7f57f63eba
4 changed files with 36 additions and 9 deletions

View File

@ -1699,7 +1699,7 @@ _gtk_popover_parent_hierarchy_changed (GtkWidget *widget,
_gtk_window_remove_popover (priv->window, GTK_WIDGET (popover)); _gtk_window_remove_popover (priv->window, GTK_WIDGET (popover));
if (new_window) if (new_window)
_gtk_window_add_popover (new_window, GTK_WIDGET (popover), priv->widget); _gtk_window_add_popover (new_window, GTK_WIDGET (popover), priv->widget, TRUE);
priv->window = new_window; priv->window = new_window;
@ -1970,7 +1970,7 @@ gtk_popover_update_relative_to (GtkPopover *popover,
} }
if (priv->window) if (priv->window)
_gtk_window_add_popover (priv->window, GTK_WIDGET (popover), priv->widget); _gtk_window_add_popover (priv->window, GTK_WIDGET (popover), priv->widget, TRUE);
if (relative_to) if (relative_to)
scrollable = GTK_SCROLLABLE (gtk_widget_get_ancestor (priv->widget, GTK_TYPE_SCROLLABLE)); scrollable = GTK_SCROLLABLE (gtk_widget_get_ancestor (priv->widget, GTK_TYPE_SCROLLABLE));

View File

@ -307,7 +307,7 @@ _gtk_text_handle_ensure_widget (GtkTextHandle *handle,
priv->windows[pos].widget = g_object_ref_sink (widget); priv->windows[pos].widget = g_object_ref_sink (widget);
window = gtk_widget_get_ancestor (priv->parent, GTK_TYPE_WINDOW); window = gtk_widget_get_ancestor (priv->parent, GTK_TYPE_WINDOW);
_gtk_window_add_popover (GTK_WINDOW (window), widget, priv->parent); _gtk_window_add_popover (GTK_WINDOW (window), widget, priv->parent, FALSE);
gtk_style_context_set_parent (gtk_widget_get_style_context (widget), gtk_style_context_set_parent (gtk_widget_get_style_context (widget),
gtk_widget_get_style_context (priv->parent)); gtk_widget_get_style_context (priv->parent));

View File

@ -143,6 +143,7 @@ struct _GtkWindowPopover
GtkPositionType pos; GtkPositionType pos;
cairo_rectangle_int_t rect; cairo_rectangle_int_t rect;
gulong unmap_id; gulong unmap_id;
guint clamp_allocation : 1;
}; };
struct _GtkWindowPrivate struct _GtkWindowPrivate
@ -6356,6 +6357,7 @@ popover_get_rect (GtkWindowPopover *popover,
GtkAllocation win_alloc; GtkAllocation win_alloc;
GtkRequisition req; GtkRequisition req;
GtkBorder win_border; GtkBorder win_border;
gdouble min, max;
gtk_widget_get_preferred_size (popover->widget, NULL, &req); gtk_widget_get_preferred_size (popover->widget, NULL, &req);
gtk_widget_get_allocation (GTK_WIDGET (window), &win_alloc); gtk_widget_get_allocation (GTK_WIDGET (window), &win_alloc);
@ -6378,8 +6380,19 @@ popover_get_rect (GtkWindowPopover *popover,
rect->height = win_alloc.height; rect->height = win_alloc.height;
} }
else else
rect->y = CLAMP (popover->rect.y + (popover->rect.height / 2) - {
(req.height / 2), 0, win_alloc.y + win_alloc.height + win_border.bottom - req.height); min = 0;
max = win_alloc.y + win_alloc.height + win_border.bottom - req.height;
if (popover->clamp_allocation)
{
min += win_border.top;
max -= win_border.bottom;
}
rect->y = CLAMP (popover->rect.y + (popover->rect.height / 2) -
(req.height / 2), min, max);
}
if ((popover->pos == GTK_POS_LEFT) == if ((popover->pos == GTK_POS_LEFT) ==
(gtk_widget_get_direction (popover->widget) == GTK_TEXT_DIR_LTR)) (gtk_widget_get_direction (popover->widget) == GTK_TEXT_DIR_LTR))
@ -6410,8 +6423,19 @@ popover_get_rect (GtkWindowPopover *popover,
rect->width = win_alloc.width; rect->width = win_alloc.width;
} }
else else
rect->x = CLAMP (popover->rect.x + (popover->rect.width / 2) - {
(req.width / 2), 0, win_alloc.x + win_alloc.width + win_border.right - req.width); min = 0;
max = win_alloc.x + win_alloc.width + win_border.right - req.width;
if (popover->clamp_allocation)
{
min += win_border.left;
max -= win_border.right;
}
rect->x = CLAMP (popover->rect.x + (popover->rect.width / 2) -
(req.width / 2), min, max);
}
if (popover->pos == GTK_POS_TOP) if (popover->pos == GTK_POS_TOP)
{ {
@ -11822,7 +11846,8 @@ _gtk_window_get_shadow_width (GtkWindow *window,
void void
_gtk_window_add_popover (GtkWindow *window, _gtk_window_add_popover (GtkWindow *window,
GtkWidget *popover, GtkWidget *popover,
GtkWidget *parent) GtkWidget *parent,
gboolean clamp_allocation)
{ {
GtkWindowPrivate *priv; GtkWindowPrivate *priv;
GtkWindowPopover *data; GtkWindowPopover *data;
@ -11842,6 +11867,7 @@ _gtk_window_add_popover (GtkWindow *window,
data = g_new0 (GtkWindowPopover, 1); data = g_new0 (GtkWindowPopover, 1);
data->widget = popover; data->widget = popover;
data->parent = parent; data->parent = parent;
data->clamp_allocation = !!clamp_allocation;
priv->popovers = g_list_prepend (priv->popovers, data); priv->popovers = g_list_prepend (priv->popovers, data);
if (gtk_widget_get_realized (GTK_WIDGET (window))) if (gtk_widget_get_realized (GTK_WIDGET (window)))

View File

@ -105,7 +105,8 @@ void _gtk_window_set_window_group (GtkWindow *window,
/* Popovers */ /* Popovers */
void _gtk_window_add_popover (GtkWindow *window, void _gtk_window_add_popover (GtkWindow *window,
GtkWidget *popover, GtkWidget *popover,
GtkWidget *popover_parent); GtkWidget *popover_parent,
gboolean clamp_allocation);
void _gtk_window_remove_popover (GtkWindow *window, void _gtk_window_remove_popover (GtkWindow *window,
GtkWidget *popover); GtkWidget *popover);
void _gtk_window_set_popover_position (GtkWindow *window, void _gtk_window_set_popover_position (GtkWindow *window,