mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-30 15:31:34 +00:00
viewport: Rewrite adjustment modification code for sealing
This commit is contained in:
parent
a317499031
commit
2b4bb071a3
@ -341,23 +341,6 @@ viewport_get_view_allocation (GtkViewport *viewport,
|
|||||||
view_allocation->height = MAX (1, allocation.height - view_allocation->y * 2 - border_width * 2);
|
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:
|
* gtk_viewport_get_hadjustment:
|
||||||
* @viewport: a #GtkViewport.
|
* @viewport: a #GtkViewport.
|
||||||
@ -409,28 +392,16 @@ gtk_viewport_get_vadjustment (GtkViewport *viewport)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
viewport_set_hadjustment_values (GtkViewport *viewport,
|
viewport_set_hadjustment_values (GtkViewport *viewport)
|
||||||
gboolean *value_changed)
|
|
||||||
{
|
{
|
||||||
GtkBin *bin = GTK_BIN (viewport);
|
GtkBin *bin = GTK_BIN (viewport);
|
||||||
GtkAllocation view_allocation;
|
GtkAllocation view_allocation;
|
||||||
GtkAdjustment *hadjustment = gtk_viewport_get_hadjustment (viewport);
|
GtkAdjustment *hadjustment = gtk_viewport_get_hadjustment (viewport);
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
gdouble old_page_size;
|
gdouble upper, value;
|
||||||
gdouble old_upper;
|
|
||||||
gdouble old_value;
|
|
||||||
|
|
||||||
viewport_get_view_allocation (viewport, &view_allocation);
|
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);
|
child = gtk_bin_get_child (bin);
|
||||||
if (child && gtk_widget_get_visible (child))
|
if (child && gtk_widget_get_visible (child))
|
||||||
{
|
{
|
||||||
@ -448,41 +419,43 @@ viewport_set_hadjustment_values (GtkViewport *viewport,
|
|||||||
&natural_width);
|
&natural_width);
|
||||||
|
|
||||||
if (viewport->priv->hscroll_policy == GTK_SCROLL_MINIMUM)
|
if (viewport->priv->hscroll_policy == GTK_SCROLL_MINIMUM)
|
||||||
hadjustment->upper = MAX (minimum_width, view_allocation.width);
|
upper = MAX (minimum_width, view_allocation.width);
|
||||||
else
|
else
|
||||||
hadjustment->upper = MAX (natural_width, view_allocation.width);
|
upper = MAX (natural_width, view_allocation.width);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hadjustment->upper = view_allocation.width;
|
upper = view_allocation.width;
|
||||||
|
|
||||||
|
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)
|
if (gtk_widget_get_direction (GTK_WIDGET (viewport)) == GTK_TEXT_DIR_RTL)
|
||||||
{
|
{
|
||||||
gdouble dist = old_upper - (old_value + old_page_size);
|
gdouble dist = gtk_adjustment_get_upper (hadjustment)
|
||||||
hadjustment->value = hadjustment->upper - dist - hadjustment->page_size;
|
- value
|
||||||
viewport_reclamp_adjustment (hadjustment, value_changed);
|
- gtk_adjustment_get_page_size (hadjustment);
|
||||||
*value_changed = (old_value != hadjustment->value);
|
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
|
static void
|
||||||
viewport_set_vadjustment_values (GtkViewport *viewport,
|
viewport_set_vadjustment_values (GtkViewport *viewport)
|
||||||
gboolean *value_changed)
|
|
||||||
{
|
{
|
||||||
GtkBin *bin = GTK_BIN (viewport);
|
GtkBin *bin = GTK_BIN (viewport);
|
||||||
GtkAllocation view_allocation;
|
GtkAllocation view_allocation;
|
||||||
GtkAdjustment *vadjustment = gtk_viewport_get_vadjustment (viewport);
|
GtkAdjustment *vadjustment = gtk_viewport_get_vadjustment (viewport);
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
|
gdouble upper;
|
||||||
|
|
||||||
viewport_get_view_allocation (viewport, &view_allocation);
|
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);
|
child = gtk_bin_get_child (bin);
|
||||||
if (child && gtk_widget_get_visible (child))
|
if (child && gtk_widget_get_visible (child))
|
||||||
{
|
{
|
||||||
@ -500,14 +473,20 @@ viewport_set_vadjustment_values (GtkViewport *viewport,
|
|||||||
&natural_height);
|
&natural_height);
|
||||||
|
|
||||||
if (viewport->priv->vscroll_policy == GTK_SCROLL_MINIMUM)
|
if (viewport->priv->vscroll_policy == GTK_SCROLL_MINIMUM)
|
||||||
vadjustment->upper = MAX (minimum_height, view_allocation.height);
|
upper = MAX (minimum_height, view_allocation.height);
|
||||||
else
|
else
|
||||||
vadjustment->upper = MAX (natural_height, view_allocation.height);
|
upper = MAX (natural_height, view_allocation.height);
|
||||||
}
|
}
|
||||||
else
|
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
|
static void
|
||||||
@ -516,7 +495,6 @@ viewport_set_adjustment (GtkViewport *viewport,
|
|||||||
GtkAdjustment *adjustment)
|
GtkAdjustment *adjustment)
|
||||||
{
|
{
|
||||||
GtkAdjustment **adjustmentp = ADJUSTMENT_POINTER (viewport, orientation);
|
GtkAdjustment **adjustmentp = ADJUSTMENT_POINTER (viewport, orientation);
|
||||||
gboolean value_changed;
|
|
||||||
|
|
||||||
if (adjustment && adjustment == *adjustmentp)
|
if (adjustment && adjustment == *adjustmentp)
|
||||||
return;
|
return;
|
||||||
@ -528,19 +506,14 @@ viewport_set_adjustment (GtkViewport *viewport,
|
|||||||
g_object_ref_sink (adjustment);
|
g_object_ref_sink (adjustment);
|
||||||
|
|
||||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
viewport_set_hadjustment_values (viewport, &value_changed);
|
viewport_set_hadjustment_values (viewport);
|
||||||
else
|
else
|
||||||
viewport_set_vadjustment_values (viewport, &value_changed);
|
viewport_set_vadjustment_values (viewport);
|
||||||
|
|
||||||
g_signal_connect (adjustment, "value-changed",
|
g_signal_connect (adjustment, "value-changed",
|
||||||
G_CALLBACK (gtk_viewport_adjustment_value_changed),
|
G_CALLBACK (gtk_viewport_adjustment_value_changed),
|
||||||
viewport);
|
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;
|
GtkViewportPrivate *priv = viewport->priv;
|
||||||
GtkBin *bin = GTK_BIN (widget);
|
GtkBin *bin = GTK_BIN (widget);
|
||||||
guint border_width;
|
guint border_width;
|
||||||
gboolean hadjustment_value_changed, vadjustment_value_changed;
|
|
||||||
GtkAdjustment *hadjustment = gtk_viewport_get_hadjustment (viewport);
|
GtkAdjustment *hadjustment = gtk_viewport_get_hadjustment (viewport);
|
||||||
GtkAdjustment *vadjustment = gtk_viewport_get_vadjustment (viewport);
|
GtkAdjustment *vadjustment = gtk_viewport_get_vadjustment (viewport);
|
||||||
GtkAllocation child_allocation;
|
GtkAllocation child_allocation;
|
||||||
@ -867,8 +839,11 @@ gtk_viewport_size_allocate (GtkWidget *widget,
|
|||||||
|
|
||||||
gtk_widget_set_allocation (widget, allocation);
|
gtk_widget_set_allocation (widget, allocation);
|
||||||
|
|
||||||
viewport_set_hadjustment_values (viewport, &hadjustment_value_changed);
|
g_object_freeze_notify (G_OBJECT (hadjustment));
|
||||||
viewport_set_vadjustment_values (viewport, &vadjustment_value_changed);
|
g_object_freeze_notify (G_OBJECT (vadjustment));
|
||||||
|
|
||||||
|
viewport_set_hadjustment_values (viewport);
|
||||||
|
viewport_set_vadjustment_values (viewport);
|
||||||
|
|
||||||
child_allocation.x = 0;
|
child_allocation.x = 0;
|
||||||
child_allocation.y = 0;
|
child_allocation.y = 0;
|
||||||
@ -901,12 +876,8 @@ gtk_viewport_size_allocate (GtkWidget *widget,
|
|||||||
if (child && gtk_widget_get_visible (child))
|
if (child && gtk_widget_get_visible (child))
|
||||||
gtk_widget_size_allocate (child, &child_allocation);
|
gtk_widget_size_allocate (child, &child_allocation);
|
||||||
|
|
||||||
gtk_adjustment_changed (hadjustment);
|
g_object_thaw_notify (G_OBJECT (hadjustment));
|
||||||
gtk_adjustment_changed (vadjustment);
|
g_object_thaw_notify (G_OBJECT (vadjustment));
|
||||||
if (hadjustment_value_changed)
|
|
||||||
gtk_adjustment_value_changed (hadjustment);
|
|
||||||
if (vadjustment_value_changed)
|
|
||||||
gtk_adjustment_value_changed (vadjustment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user