GNOME Bugzilla – Bug 110737
gtk_viewport_realize() does not honor initial scroll offset
Last modified: 2011-02-04 16:11:59 UTC
gtk_viewport_realize() creates viewport->bin_window always at position (0,0), this makes it impossible to change the viewport's adjustment to acheive an initial, computed scroll offset. When doing so, a scrolled window shows up with its scrollbars scrolled to the correct initial position, but the content of the viewport still being at position (0,0).
Created attachment 15697 [details] [review] patch to fix the bug
The attached patch fixes the problem, the computation of attributes.x and .y was taken from gtk_viewport_adjustment_value_changed(). OK to commit?
Looks fine to commit to me (gtk-2-2 and HEAD). Can you figure out why the value_changed handler has the check for? if (viewport->hadjustment->lower != (viewport->hadjustment->upper - viewport->hadjustment->page_size)) I can't ...
Hm, they actually say: if (the adjustment can be moved at all) set_the_value_from_adjustment's_value; else leave_the_value_at_0; Looks as if the code is assuming that adjustment->lower is *always* equal to 0, which is not true, since the lower/upper bounds of adjustments set using gtk_viewport_set_[vh]adjustment() are never checked to be correct unless the viewport receives a size_allocate(). So IMHO the checks need to be removed since they are useless given the adjustment->lower == 0 constraint is true, plus, external adjustments set using gtk_viewport_set_[vh]adjustment() need to be modified to have proper lower/upper/page_size.
I'm thinking that likely at one point GtkViewport scaled the adjustment coordinates or that this is a cut-and-paste from some widget that did, since what: if (viewport->hadjustment->lower != (viewport->hadjustment->upper - viewport->hadjustment->page_size)) Looks most like to me is a division-by-zero check for a division that is no longer there.
Fri Jun 6 16:25:44 2003 Owen Taylor <otaylor@redhat.com> * gtk/gtkviewport.c: Many fixes, along with extensive cleanups and refactoring of code to reduce duplication; fixes include: - gtk_viewport_realize(): Position the window correct from adjustment values. (#110737, Michael Natterer) - Remove some division-by-zero checks in places where there is no longer division. (#110737)