[comp.windows.x] Controlling Viewport scrollbars.

roy@neptune.iex.com (Roy Cantu) (07/10/90)

The Viewport widget provides horizontal 
and vertical scrollbars to control its child.
I was wondering how the application may gain
control over these scrollbars.  Looking at
the Scrollbar widget, I see that the
user may set the callback function, specify
the thumb position, specify the length of
the thump etc.  

Is it possible to gain such control over my
Viewport scrollbars without the hassle of
implementing individual Scrollbar widgets?

In particular, I would like to be notified
when the user has moved a scrollbar thumb
and by how much.  Furthermore, I would like
to be able to move the thumb and scroll the 
Viewport text from *within* the application.
   
Any suggestions are appreciated.


roy

dtj@caffeine.cray.com (Dean Johnson) (07/11/90)

#include <std/disclaimers.h>

In article <roy.647556488@neptune> roy@neptune.iex.com (Roy Cantu) writes:
>
> The Viewport widget provides horizontal and vertical scrollbars to 
> control its child.  I was wondering how the application may gain
> control over these scrollbars.  Looking at the Scrollbar widget, I see 
> that the user may set the callback function, specify the thumb position, 
> specify the length of the thump etc.  
>
> Is it possible to gain such control over my Viewport scrollbars without 
> the hassle of implementing individual Scrollbar widgets?
>
> In particular, I would like to be notified when the user has moved 
> a scrollbar thumb and by how much.  Furthermore, I would like
> to be able to move the thumb and scroll the Viewport text from *within* 
> the application.
>   
>Any suggestions are appreciated.

Here is an example of how to move a viewport vertical scrollbar to the
top. Please note that there is probably no *correct* way to do this,
so be warned that children should use this only under parental supervision. 
(flames, etc. >& /dev/null)

	-Dean Johnson
	 Tools, Libraries, and Commands Group
	 Cray Research Inc.
	 Mendota Heights, MN

-------	cut here ---------

ZeroViewportScroll(widget)
ViewportWidget  widget;
{
Widget  v_bar;

        /*
         *      It doesn't make any sense to zero a viewport that doesn't
         *      currently exist.
         */
        if (!XtIsRealized((Widget) widget)) return;

        v_bar = XtNameToWidget(widget,"vertical");
        XtMoveWidget(widget->viewport.child,0,0);
        XtScrollBarSetThumb(v_bar,0.0,-1.0);
}