Re: Getting the visible portion of a scrolled window



On Wed, 2008-05-21 at 12:29 -0400, Lindley M French wrote:
> I figured out what I needed, but it was bizarrely difficult. I first
> had to use gtk_bin_get_child on the scrolled window to get the
> viewport; then I had to use gdk_window_get_position() on
> viewport->bin_window to get the (negative) x and y coordinates of the
> visible region, then gdk_window_get_size() on viewport->view_window to
> get the width and height of the visible region.
> 
> There *must* be a better way do get this information...

Not quite what you're up against, but a similar scenario: we've recently
been poking away at GtkTextView and friends; it turns out that there are
four optional GdkWindows surrounding the central one that displays the
text. You use functions like gtk_text_view_buffer_to_window_coords() to
take the GtkTextView's idea of where a point in the overall text canvas
and translate it into a vertical or horizontal component so you can
figure out what co-ordinates to move a child Widget you've placed in
that such a side GdkWindow.

As I was working with it, I found that the conversion would give
positive answers larger than the viewport if the location was scrolled
off the viewport below, and *negative* answers if the location was
scrolled off the thing above.

At first, I was surprised by this, but upon reflection it makes sense.
If you place a 30 pixel high widget at position -15, then you only want
to show half of it. GDK appears to clip it on this basis and properly
only showed half of it. If you get -300 back, well, you're scrolled
significantly further into your GtkTetxView, and so, surprise, you're
side bar child widget now needs to be off the screen - I was a bit wary
of passing said -300 along as a co-ordinate, but GDK seems smart enough
to Do The Right Thing™ and just not draw the child.

Anyway, this is all very voodoo, but it does seem another example of
negative co-ordinates showing up, and perhaps makes you feel you're not
the only one :)

In case you have no idea what I'm referring to, you might start with
http://library.gnome.org/devel/gtk/stable/GtkTextView.html#gtk-text-view-add-child-in-window

AfC
Sydney

-- 
Andrew Frederick Cowie

Operational Dynamics is an operations and engineering consultancy
focusing on IT strategy, organizational architecture, systems
review, and effective procedures for change management. We actively
carry out research and development in these areas on behalf of our
clients, and enable successful use of open source in their mission
critical enterprises, worldwide.

http://www.operationaldynamics.com/

Sydney   New York   Toronto   London

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]