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)) (scroll == GTK_SCROLL_PAGE_FORWARD))
return FALSE; return FALSE;
g_object_freeze_notify (G_OBJECT (shell->hsbdata));
gimp_display_shell_scroll_setup_hscrollbar (shell, value); 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; return FALSE;
} }
@ -2028,9 +2030,11 @@ gimp_display_shell_vscrollbar_update_range (GtkRange *range,
(scroll == GTK_SCROLL_PAGE_FORWARD)) (scroll == GTK_SCROLL_PAGE_FORWARD))
return FALSE; return FALSE;
g_object_freeze_notify (G_OBJECT (shell->vsbdata));
gimp_display_shell_scroll_setup_vscrollbar (shell, value); 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; return FALSE;
} }

View File

@ -134,24 +134,32 @@ gimp_display_shell_scale_update_scrollbars (GimpDisplayShell *shell)
/* Horizontal scrollbar */ /* Horizontal scrollbar */
shell->hsbdata->value = shell->offset_x; g_object_freeze_notify (G_OBJECT (shell->hsbdata));
shell->hsbdata->page_size = shell->disp_width;
shell->hsbdata->page_increment = shell->disp_width / 2; 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); 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 */ /* Vertcal scrollbar */
shell->vsbdata->value = shell->offset_y; g_object_freeze_notify (G_OBJECT (shell->vsbdata));
shell->vsbdata->page_size = shell->disp_height;
shell->vsbdata->page_increment = shell->disp_height / 2; 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); 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, gimp_display_shell_scroll_setup_hscrollbar (GimpDisplayShell *shell,
gdouble value) gdouble value)
{ {
gint sw; gint sw;
gdouble lower;
gdouble upper;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); 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) if (shell->disp_width < sw)
{ {
shell->hsbdata->lower = MIN (value, lower = MIN (value, 0);
0); upper = MAX (value + shell->disp_width, sw);
shell->hsbdata->upper = MAX (value + shell->disp_width,
sw);
} }
else else
{ {
shell->hsbdata->lower = MIN (value, lower = MIN (value, -(shell->disp_width - sw) / 2);
-(shell->disp_width - sw) / 2); upper = MAX (value + shell->disp_width,
sw + (shell->disp_width - sw) / 2);
shell->hsbdata->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, gimp_display_shell_scroll_setup_vscrollbar (GimpDisplayShell *shell,
gdouble value) gdouble value)
{ {
gint sh; gint sh;
gdouble lower;
gdouble upper;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); 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) if (shell->disp_height < sh)
{ {
shell->vsbdata->lower = MIN (value, lower = MIN (value, 0);
0); upper = MAX (value + shell->disp_height, sh);
shell->vsbdata->upper = MAX (value + shell->disp_height,
sh);
} }
else else
{ {
shell->vsbdata->lower = MIN (value, lower = MIN (value, -(shell->disp_height - sh) / 2);
-(shell->disp_height - sh) / 2); upper = MAX (value + shell->disp_height,
sh + (shell->disp_height - sh) / 2);
shell->vsbdata->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);
} }