[comp.windows.x] Setting the viewable region of the Athena viewport

gnb@bby.oz.au (Gregory N. Bond) (06/17/91)

One of our users is writing an application that has a List widget
inside a viewport widget.  He wants to be able to scroll a particular
line of the list to the (top,center,bottom) of the viewport, but I
can't see any calls &/| resources to do this. 

Hints gladly accepted.  Should this go in the FAQ?

Greg.
--
Gregory Bond, Burdett Buckeridge & Young Ltd, Melbourne, Australia
Internet: gnb@melba.bby.oz.au    non-MX: gnb%melba.bby.oz@uunet.uu.net
Uucp: {uunet,pyramid,ubc-cs,ukc,mcvax,prlb2,nttlab...}!munnari!melba.bby.oz!gnb

gdmr@cs.ed.ac.uk (George Ross) (06/18/91)

In article <1991Jun17.084423.11830@melba.bby.oz.au>, gnb@bby.oz.au (Gregory N. Bond) writes:
> One of our users is writing an application that has a List widget
> inside a viewport widget.  He wants to be able to scroll a particular
> line of the list to the (top,center,bottom) of the viewport, but I
> can't see any calls &/| resources to do this. 

Funny how just as you're about to post something somebody else gets in first
to say the same thing.  Anyway, the following hack is what I'm currently
using (I have a Label inside the Viewport).  There must be a better way!

                /* This is revolting, but there doesn't seem to be any
                 * other way to get the thing to scroll right to the bottom */
                scrollbar = XtNameToWidget(viewport, "vertical");
                if (scrollbar) {
                        n = 0;
                        XtSetArg(args[n], XtNwidth, &scrollWidth);      n++;
                        XtSetArg(args[n], XtNheight, &scrollHeight);    n++;
                        XtGetValues(scrollbar, args, n);
                        /* Fake up a button event -- enough to pacify the
                         * Scrollbar widget, at any rate... */
                        be.type = ButtonPress;
                        be.x = scrollWidth / 2;
                        be.y = scrollHeight - 1;
                        XtCallActionProc(scrollbar, "StartScroll", &be, &cont, 1);
                        XtCallActionProc(scrollbar, "MoveThumb", &be, NULL, 0);
                        XtCallActionProc(scrollbar, "NotifyThumb", &be, NULL, 0);
                        XtCallActionProc(scrollbar, "EndScroll", &be, NULL, 0);
                }
                /* YUK! */

-- 
George D M Ross, Department of Computer Science, University of Edinburgh
     Kings Buildings, Mayfield Road, Edinburgh, Scotland, EH9 3JZ
Tel: 031-650 5147   Internet: gdmr@cs.ed.ac.uk   JANET: gdmr@uk.ac.ed.cs

afzal@cui.unige.ch (Afzal Ballim) (06/18/91)

gnb@bby.oz.au (Gregory N. Bond) writes
>One of our users is writing an application that has a List widget
>inside a viewport widget.  He wants to be able to scroll a particular
>line of the list to the (top,center,bottom) of the viewport, but I
>can't see any calls &/| resources to do this.
>
>Hints gladly accepted.  Should this go in the FAQ?

The following allows one to change the position of a viewport
to some absolute position over its child. (Note: bounds checking 
should also be done).

 .
 .
 .
 .
ViewportWidget viewport;
Widget child;
Widget w;
Position vport_vpos,	/* where the viewport is */
	 absolute_vpos; /* absolute position to move to */
Arg arg;

absolute_vpos = 111;	/* to move to position 111 */
w = XtNameToWidget(viewport,"vertical");
XtSetArg(arg,XtNy,&vport_vpos);
XtGetValues(child,&arg,1);

XtCallCallbacks(w,XtNscrollProc,absolute_vpos+vport_vpos);
 .
 .
 .


Yes, this should go in the FAQ

-Afzal