forked from AuroraMiddleware/gtk
viewport: Actually report the size we're gonna allocate
Don't just pass on measure() calls, but actually behave in the way we behave during size allocate. This should improve cases where GtkScrolledWindow is used with GTK_POLICY_NEVER.
This commit is contained in:
parent
9fd7e319f3
commit
b8468af411
@ -143,17 +143,55 @@ gtk_viewport_buildable_init (GtkBuildableIface *iface)
|
|||||||
iface->add_child = gtk_viewport_buildable_add_child;
|
iface->add_child = gtk_viewport_buildable_add_child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_viewport_measure_child (GtkViewport *viewport,
|
||||||
|
int size[2])
|
||||||
|
{
|
||||||
|
GtkOrientation orientation, opposite;
|
||||||
|
int min, nat;
|
||||||
|
|
||||||
|
if (viewport->child == NULL ||
|
||||||
|
!gtk_widget_is_visible (viewport->child))
|
||||||
|
{
|
||||||
|
size[0] = 0;
|
||||||
|
size[1] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gtk_widget_get_request_mode (viewport->child) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
|
||||||
|
orientation = GTK_ORIENTATION_VERTICAL;
|
||||||
|
else
|
||||||
|
orientation = GTK_ORIENTATION_HORIZONTAL;
|
||||||
|
opposite = OPPOSITE_ORIENTATION (orientation);
|
||||||
|
|
||||||
|
gtk_widget_measure (viewport->child,
|
||||||
|
orientation, -1,
|
||||||
|
&min, &nat,
|
||||||
|
NULL, NULL);
|
||||||
|
if (viewport->scroll_policy[orientation] == GTK_SCROLL_MINIMUM)
|
||||||
|
size[orientation] = min;
|
||||||
|
else
|
||||||
|
size[orientation] = nat;
|
||||||
|
|
||||||
|
gtk_widget_measure (viewport->child,
|
||||||
|
opposite, size[orientation],
|
||||||
|
&min, &nat,
|
||||||
|
NULL, NULL);
|
||||||
|
if (viewport->scroll_policy[opposite] == GTK_SCROLL_MINIMUM)
|
||||||
|
size[opposite] = min;
|
||||||
|
else
|
||||||
|
size[opposite] = nat;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
viewport_set_adjustment_values (GtkViewport *viewport,
|
viewport_set_adjustment_values (GtkViewport *viewport,
|
||||||
GtkOrientation orientation)
|
GtkOrientation orientation)
|
||||||
{
|
{
|
||||||
GtkAdjustment *adjustment;
|
GtkAdjustment *adjustment;
|
||||||
GtkScrollablePolicy scroll_policy;
|
|
||||||
GtkScrollablePolicy other_scroll_policy;
|
|
||||||
GtkOrientation other_orientation;
|
|
||||||
double upper, value;
|
double upper, value;
|
||||||
int viewport_size, other_viewport_size;
|
int viewport_size;
|
||||||
int view_width, view_height;
|
int view_width, view_height;
|
||||||
|
int child_size[2];
|
||||||
|
|
||||||
view_width = gtk_widget_get_width (GTK_WIDGET (viewport));
|
view_width = gtk_widget_get_width (GTK_WIDGET (viewport));
|
||||||
view_height = gtk_widget_get_height (GTK_WIDGET (viewport));
|
view_height = gtk_widget_get_height (GTK_WIDGET (viewport));
|
||||||
@ -161,49 +199,17 @@ viewport_set_adjustment_values (GtkViewport *viewport,
|
|||||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
{
|
{
|
||||||
adjustment = viewport->adjustment[GTK_ORIENTATION_HORIZONTAL];
|
adjustment = viewport->adjustment[GTK_ORIENTATION_HORIZONTAL];
|
||||||
other_orientation = GTK_ORIENTATION_VERTICAL;
|
|
||||||
viewport_size = view_width;
|
viewport_size = view_width;
|
||||||
other_viewport_size = view_height;
|
|
||||||
scroll_policy = viewport->scroll_policy[GTK_ORIENTATION_HORIZONTAL];
|
|
||||||
other_scroll_policy = viewport->scroll_policy[GTK_ORIENTATION_VERTICAL];
|
|
||||||
}
|
}
|
||||||
else /* VERTICAL */
|
else /* VERTICAL */
|
||||||
{
|
{
|
||||||
adjustment = viewport->adjustment[GTK_ORIENTATION_VERTICAL];
|
adjustment = viewport->adjustment[GTK_ORIENTATION_VERTICAL];
|
||||||
other_orientation = GTK_ORIENTATION_HORIZONTAL;
|
|
||||||
viewport_size = view_height;
|
viewport_size = view_height;
|
||||||
other_viewport_size = view_width;
|
|
||||||
scroll_policy = viewport->scroll_policy[GTK_ORIENTATION_VERTICAL];
|
|
||||||
other_scroll_policy = viewport->scroll_policy[GTK_ORIENTATION_HORIZONTAL];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gtk_viewport_measure_child (viewport, child_size);
|
||||||
|
|
||||||
if (viewport->child && gtk_widget_get_visible (viewport->child))
|
upper = MAX (viewport_size, child_size[orientation]);
|
||||||
{
|
|
||||||
int min_size, nat_size;
|
|
||||||
int scroll_size;
|
|
||||||
|
|
||||||
if (other_scroll_policy == GTK_SCROLL_MINIMUM)
|
|
||||||
gtk_widget_measure (viewport->child, other_orientation, -1,
|
|
||||||
&scroll_size, NULL, NULL, NULL);
|
|
||||||
else
|
|
||||||
gtk_widget_measure (viewport->child, other_orientation, -1,
|
|
||||||
NULL, &scroll_size, NULL, NULL);
|
|
||||||
|
|
||||||
gtk_widget_measure (viewport->child, orientation,
|
|
||||||
MAX (other_viewport_size, scroll_size),
|
|
||||||
&min_size, &nat_size, NULL, NULL);
|
|
||||||
|
|
||||||
if (scroll_policy == GTK_SCROLL_MINIMUM)
|
|
||||||
upper = MAX (min_size, viewport_size);
|
|
||||||
else
|
|
||||||
upper = MAX (nat_size, viewport_size);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
upper = viewport_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
value = gtk_adjustment_get_value (adjustment);
|
value = gtk_adjustment_get_value (adjustment);
|
||||||
|
|
||||||
@ -236,13 +242,12 @@ gtk_viewport_measure (GtkWidget *widget,
|
|||||||
int *natural_baseline)
|
int *natural_baseline)
|
||||||
{
|
{
|
||||||
GtkViewport *viewport = GTK_VIEWPORT (widget);
|
GtkViewport *viewport = GTK_VIEWPORT (widget);
|
||||||
|
int child_size[2];
|
||||||
|
|
||||||
if (viewport->child)
|
gtk_viewport_measure_child (viewport, child_size);
|
||||||
gtk_widget_measure (viewport->child,
|
|
||||||
orientation,
|
*minimum = child_size[orientation];
|
||||||
for_size,
|
*natural = child_size[orientation];
|
||||||
minimum, natural,
|
|
||||||
NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -267,12 +272,7 @@ gtk_viewport_compute_expand (GtkWidget *widget,
|
|||||||
static GtkSizeRequestMode
|
static GtkSizeRequestMode
|
||||||
gtk_viewport_get_request_mode (GtkWidget *widget)
|
gtk_viewport_get_request_mode (GtkWidget *widget)
|
||||||
{
|
{
|
||||||
GtkViewport *viewport = GTK_VIEWPORT (widget);
|
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
|
||||||
|
|
||||||
if (viewport->child)
|
|
||||||
return gtk_widget_get_request_mode (viewport->child);
|
|
||||||
else
|
|
||||||
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADJUSTMENT_POINTER(orientation) \
|
#define ADJUSTMENT_POINTER(orientation) \
|
||||||
|
Loading…
Reference in New Issue
Block a user