viewport: Rewrite adjustment modification code for sealing

This commit is contained in:
Benjamin Otte 2011-01-05 21:53:04 +01:00
parent a317499031
commit 2b4bb071a3

View File

@ -341,23 +341,6 @@ viewport_get_view_allocation (GtkViewport *viewport,
view_allocation->height = MAX (1, allocation.height - view_allocation->y * 2 - border_width * 2);
}
static void
viewport_reclamp_adjustment (GtkAdjustment *adjustment,
gboolean *value_changed)
{
gdouble value = adjustment->value;
value = CLAMP (value, 0, adjustment->upper - adjustment->page_size);
if (value != adjustment->value)
{
adjustment->value = value;
if (value_changed)
*value_changed = TRUE;
}
else if (value_changed)
*value_changed = FALSE;
}
/**
* gtk_viewport_get_hadjustment:
* @viewport: a #GtkViewport.
@ -409,28 +392,16 @@ gtk_viewport_get_vadjustment (GtkViewport *viewport)
}
static void
viewport_set_hadjustment_values (GtkViewport *viewport,
gboolean *value_changed)
viewport_set_hadjustment_values (GtkViewport *viewport)
{
GtkBin *bin = GTK_BIN (viewport);
GtkAllocation view_allocation;
GtkAdjustment *hadjustment = gtk_viewport_get_hadjustment (viewport);
GtkWidget *child;
gdouble old_page_size;
gdouble old_upper;
gdouble old_value;
gdouble upper, value;
viewport_get_view_allocation (viewport, &view_allocation);
old_page_size = hadjustment->page_size;
old_upper = hadjustment->upper;
old_value = hadjustment->value;
hadjustment->page_size = view_allocation.width;
hadjustment->step_increment = view_allocation.width * 0.1;
hadjustment->page_increment = view_allocation.width * 0.9;
hadjustment->lower = 0;
child = gtk_bin_get_child (bin);
if (child && gtk_widget_get_visible (child))
{
@ -448,41 +419,43 @@ viewport_set_hadjustment_values (GtkViewport *viewport,
&natural_width);
if (viewport->priv->hscroll_policy == GTK_SCROLL_MINIMUM)
hadjustment->upper = MAX (minimum_width, view_allocation.width);
upper = MAX (minimum_width, view_allocation.width);
else
hadjustment->upper = MAX (natural_width, view_allocation.width);
upper = MAX (natural_width, view_allocation.width);
}
else
hadjustment->upper = view_allocation.width;
upper = view_allocation.width;
if (gtk_widget_get_direction (GTK_WIDGET (viewport)) == GTK_TEXT_DIR_RTL)
value = gtk_adjustment_get_value (hadjustment);
/* We clamp to the left in RTL mode */
if (gtk_widget_get_direction (GTK_WIDGET (viewport)) == GTK_TEXT_DIR_RTL)
{
gdouble dist = old_upper - (old_value + old_page_size);
hadjustment->value = hadjustment->upper - dist - hadjustment->page_size;
viewport_reclamp_adjustment (hadjustment, value_changed);
*value_changed = (old_value != hadjustment->value);
gdouble dist = gtk_adjustment_get_upper (hadjustment)
- value
- gtk_adjustment_get_page_size (hadjustment);
value = upper - dist - view_allocation.width;
}
else
viewport_reclamp_adjustment (hadjustment, value_changed);
gtk_adjustment_configure (hadjustment,
value,
0,
upper,
view_allocation.width * 0.1,
view_allocation.width * 0.9,
view_allocation.width);
}
static void
viewport_set_vadjustment_values (GtkViewport *viewport,
gboolean *value_changed)
viewport_set_vadjustment_values (GtkViewport *viewport)
{
GtkBin *bin = GTK_BIN (viewport);
GtkAllocation view_allocation;
GtkAdjustment *vadjustment = gtk_viewport_get_vadjustment (viewport);
GtkWidget *child;
gdouble upper;
viewport_get_view_allocation (viewport, &view_allocation);
vadjustment->page_size = view_allocation.height;
vadjustment->step_increment = view_allocation.height * 0.1;
vadjustment->page_increment = view_allocation.height * 0.9;
vadjustment->lower = 0;
child = gtk_bin_get_child (bin);
if (child && gtk_widget_get_visible (child))
{
@ -500,14 +473,20 @@ viewport_set_vadjustment_values (GtkViewport *viewport,
&natural_height);
if (viewport->priv->vscroll_policy == GTK_SCROLL_MINIMUM)
vadjustment->upper = MAX (minimum_height, view_allocation.height);
upper = MAX (minimum_height, view_allocation.height);
else
vadjustment->upper = MAX (natural_height, view_allocation.height);
upper = MAX (natural_height, view_allocation.height);
}
else
vadjustment->upper = view_allocation.height;
upper = view_allocation.height;
viewport_reclamp_adjustment (vadjustment, value_changed);
gtk_adjustment_configure (vadjustment,
gtk_adjustment_get_value (vadjustment),
0,
upper,
view_allocation.height * 0.1,
view_allocation.height * 0.9,
view_allocation.height);
}
static void
@ -516,7 +495,6 @@ viewport_set_adjustment (GtkViewport *viewport,
GtkAdjustment *adjustment)
{
GtkAdjustment **adjustmentp = ADJUSTMENT_POINTER (viewport, orientation);
gboolean value_changed;
if (adjustment && adjustment == *adjustmentp)
return;
@ -528,20 +506,15 @@ viewport_set_adjustment (GtkViewport *viewport,
g_object_ref_sink (adjustment);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
viewport_set_hadjustment_values (viewport, &value_changed);
viewport_set_hadjustment_values (viewport);
else
viewport_set_vadjustment_values (viewport, &value_changed);
viewport_set_vadjustment_values (viewport);
g_signal_connect (adjustment, "value-changed",
G_CALLBACK (gtk_viewport_adjustment_value_changed),
viewport);
gtk_adjustment_changed (adjustment);
if (value_changed)
gtk_adjustment_value_changed (adjustment);
else
gtk_viewport_adjustment_value_changed (adjustment, viewport);
gtk_viewport_adjustment_value_changed (adjustment, viewport);
}
/**
@ -847,7 +820,6 @@ gtk_viewport_size_allocate (GtkWidget *widget,
GtkViewportPrivate *priv = viewport->priv;
GtkBin *bin = GTK_BIN (widget);
guint border_width;
gboolean hadjustment_value_changed, vadjustment_value_changed;
GtkAdjustment *hadjustment = gtk_viewport_get_hadjustment (viewport);
GtkAdjustment *vadjustment = gtk_viewport_get_vadjustment (viewport);
GtkAllocation child_allocation;
@ -867,8 +839,11 @@ gtk_viewport_size_allocate (GtkWidget *widget,
gtk_widget_set_allocation (widget, allocation);
viewport_set_hadjustment_values (viewport, &hadjustment_value_changed);
viewport_set_vadjustment_values (viewport, &vadjustment_value_changed);
g_object_freeze_notify (G_OBJECT (hadjustment));
g_object_freeze_notify (G_OBJECT (vadjustment));
viewport_set_hadjustment_values (viewport);
viewport_set_vadjustment_values (viewport);
child_allocation.x = 0;
child_allocation.y = 0;
@ -901,12 +876,8 @@ gtk_viewport_size_allocate (GtkWidget *widget,
if (child && gtk_widget_get_visible (child))
gtk_widget_size_allocate (child, &child_allocation);
gtk_adjustment_changed (hadjustment);
gtk_adjustment_changed (vadjustment);
if (hadjustment_value_changed)
gtk_adjustment_value_changed (hadjustment);
if (vadjustment_value_changed)
gtk_adjustment_value_changed (vadjustment);
g_object_thaw_notify (G_OBJECT (hadjustment));
g_object_thaw_notify (G_OBJECT (vadjustment));
}
static void