Don't access GtkAdjustment's members directly

but also don't use its accessors because doing that would emit
"changed" multiple times when setting up an adjustment with multiple
utility functions. Instead, use g_object_set() and freeze/thaw
notification around all calls. g_object_thaw_notify() will make sure
"changed" is emitted if anything has changed since freezing.
This commit is contained in:
Michael Natterer 2009-10-09 09:54:27 +02:00
parent 8c221ebfe5
commit 23955439d6
3 changed files with 50 additions and 34 deletions

View File

@ -2007,9 +2007,11 @@ gimp_display_shell_hscrollbar_update_range (GtkRange *range,
(scroll == GTK_SCROLL_PAGE_FORWARD))
return FALSE;
g_object_freeze_notify (G_OBJECT (shell->hsbdata));
gimp_display_shell_scroll_setup_hscrollbar (shell, value);
gtk_adjustment_changed (shell->hsbdata);
g_object_thaw_notify (G_OBJECT (shell->hsbdata)); /* emits "changed" */
return FALSE;
}
@ -2028,9 +2030,11 @@ gimp_display_shell_vscrollbar_update_range (GtkRange *range,
(scroll == GTK_SCROLL_PAGE_FORWARD))
return FALSE;
g_object_freeze_notify (G_OBJECT (shell->vsbdata));
gimp_display_shell_scroll_setup_vscrollbar (shell, value);
gtk_adjustment_changed (shell->vsbdata);
g_object_thaw_notify (G_OBJECT (shell->vsbdata)); /* emits "changed" */
return FALSE;
}

View File

@ -134,24 +134,32 @@ gimp_display_shell_scale_update_scrollbars (GimpDisplayShell *shell)
/* Horizontal scrollbar */
shell->hsbdata->value = shell->offset_x;
shell->hsbdata->page_size = shell->disp_width;
shell->hsbdata->page_increment = shell->disp_width / 2;
g_object_freeze_notify (G_OBJECT (shell->hsbdata));
g_object_set (shell->hsbdata,
"value", (gdouble) shell->offset_x,
"page-size", (gdouble) shell->disp_width,
"page-increment", (gdouble) shell->disp_width / 2,
NULL);
gimp_display_shell_scroll_setup_hscrollbar (shell, shell->offset_x);
gtk_adjustment_changed (shell->hsbdata);
g_object_thaw_notify (G_OBJECT (shell->hsbdata)); /* emits "changed" */
/* Vertcal scrollbar */
shell->vsbdata->value = shell->offset_y;
shell->vsbdata->page_size = shell->disp_height;
shell->vsbdata->page_increment = shell->disp_height / 2;
g_object_freeze_notify (G_OBJECT (shell->vsbdata));
g_object_set (shell->vsbdata,
"value", (gdouble) shell->offset_y,
"page-size", (gdouble) shell->disp_height,
"page-increment", (gdouble) shell->disp_height / 2,
NULL);
gimp_display_shell_scroll_setup_vscrollbar (shell, shell->offset_y);
gtk_adjustment_changed (shell->vsbdata);
g_object_thaw_notify (G_OBJECT (shell->vsbdata)); /* emits "changed" */
}
/**

View File

@ -546,7 +546,9 @@ void
gimp_display_shell_scroll_setup_hscrollbar (GimpDisplayShell *shell,
gdouble value)
{
gint sw;
gint sw;
gdouble lower;
gdouble upper;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
@ -558,22 +560,22 @@ gimp_display_shell_scroll_setup_hscrollbar (GimpDisplayShell *shell,
if (shell->disp_width < sw)
{
shell->hsbdata->lower = MIN (value,
0);
shell->hsbdata->upper = MAX (value + shell->disp_width,
sw);
lower = MIN (value, 0);
upper = MAX (value + shell->disp_width, sw);
}
else
{
shell->hsbdata->lower = MIN (value,
-(shell->disp_width - sw) / 2);
shell->hsbdata->upper = MAX (value + shell->disp_width,
sw + (shell->disp_width - sw) / 2);
lower = MIN (value, -(shell->disp_width - sw) / 2);
upper = MAX (value + shell->disp_width,
sw + (shell->disp_width - sw) / 2);
}
shell->hsbdata->step_increment = MAX (shell->scale_x, MINIMUM_STEP_AMOUNT);
g_object_set (shell->hsbdata,
"lower", lower,
"upper", upper,
"step-increment", (gdouble) MAX (shell->scale_x,
MINIMUM_STEP_AMOUNT),
NULL);
}
/**
@ -588,7 +590,9 @@ void
gimp_display_shell_scroll_setup_vscrollbar (GimpDisplayShell *shell,
gdouble value)
{
gint sh;
gint sh;
gdouble lower;
gdouble upper;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
@ -600,20 +604,20 @@ gimp_display_shell_scroll_setup_vscrollbar (GimpDisplayShell *shell,
if (shell->disp_height < sh)
{
shell->vsbdata->lower = MIN (value,
0);
shell->vsbdata->upper = MAX (value + shell->disp_height,
sh);
lower = MIN (value, 0);
upper = MAX (value + shell->disp_height, sh);
}
else
{
shell->vsbdata->lower = MIN (value,
-(shell->disp_height - sh) / 2);
shell->vsbdata->upper = MAX (value + shell->disp_height,
sh + (shell->disp_height - sh) / 2);
lower = MIN (value, -(shell->disp_height - sh) / 2);
upper = MAX (value + shell->disp_height,
sh + (shell->disp_height - sh) / 2);
}
shell->vsbdata->step_increment = MAX (shell->scale_y, MINIMUM_STEP_AMOUNT);
g_object_set (shell->vsbdata,
"lower", lower,
"upper", upper,
"step-increment", (gdouble) MAX (shell->scale_y,
MINIMUM_STEP_AMOUNT),
NULL);
}