textview: Call gtk_widget_size_allocate() on children widgets invariably

There was this hack, taken verbatim from GtkCList according to the comment,
that would recursively translate the allocation during scrolling, and set
it on children widgets through the direct gtk_widget_set_allocation() setter.

Since commit 4f89eb05cf, this has caused the wrong clipping areas to children
widgets of a textview. The reasons for this seem lost in time, and the approach
seems indeed wrong for windowed widgets as the repositioning of those windows
couldn't happen.

So replace all of this with just a gtk_widget_size_allocate() call, which does
work ok for the children widgets embedded in the "multiple views" gtk demo, and
ought to work for every other widget.

https://bugzilla.gnome.org/show_bug.cgi?id=732900
This commit is contained in:
Carlos Garnacho 2014-07-08 16:06:00 +02:00 committed by Matthias Clasen
parent edc5cb4e47
commit 7178e342b1

View File

@ -8153,82 +8153,20 @@ gtk_text_view_set_vadjustment_values (GtkTextView *text_view)
gtk_adjustment_set_value (priv->vadjustment, new_value);
}
/* FIXME this adjust_allocation is a big cut-and-paste from
* GtkCList, needs to be some official way to do this
* factored out.
*/
typedef struct
{
GdkWindow *window;
int dx;
int dy;
} ScrollData;
/* The window to which widget->window is relative */
#define ALLOCATION_WINDOW(widget) \
(!gtk_widget_get_has_window (widget) ? \
gtk_widget_get_window (widget) : \
gdk_window_get_parent (gtk_widget_get_window (widget)))
static void
adjust_allocation_recurse (GtkWidget *widget,
gpointer data)
{
GtkAllocation allocation;
ScrollData *scroll_data = data;
/* Need to really size allocate instead of just poking
* into widget->allocation if the widget is not realized.
* FIXME someone figure out why this was.
*/
gtk_widget_get_allocation (widget, &allocation);
if (!gtk_widget_get_realized (widget))
{
if (gtk_widget_get_visible (widget))
{
GdkRectangle tmp_rectangle;
tmp_rectangle = allocation;
tmp_rectangle.x += scroll_data->dx;
tmp_rectangle.y += scroll_data->dy;
gtk_widget_size_allocate (widget, &tmp_rectangle);
}
}
else
{
if (ALLOCATION_WINDOW (widget) == scroll_data->window)
{
allocation.x += scroll_data->dx;
allocation.y += scroll_data->dy;
gtk_widget_set_allocation (widget, &allocation);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget),
adjust_allocation_recurse,
data);
}
}
}
static void
adjust_allocation (GtkWidget *widget,
int dx,
int dx,
int dy)
{
ScrollData scroll_data;
GtkAllocation allocation;
if (gtk_widget_get_realized (widget))
scroll_data.window = ALLOCATION_WINDOW (widget);
else
scroll_data.window = NULL;
scroll_data.dx = dx;
scroll_data.dy = dy;
adjust_allocation_recurse (widget, &scroll_data);
if (!gtk_widget_is_drawable (widget))
return;
gtk_widget_get_allocation (widget, &allocation);
allocation.x += dx;
allocation.y += dy;
gtk_widget_size_allocate (widget, &allocation);
}
static void