[comp.windows.x] Problem using Xaw scrollbar widget.

hedman@cernvax.UUCP (fredrik hedman) (12/07/89)

Hi !

I would like to use the Xaw scrollbar to implement a valuator.

However, when I try to read the 'final' value directly from the
scrollbar widget instance using the routine XtGetValues() I always
get back 0.0. ( See GetFinalValue routine below )

Is this normal ?
If so, why is the value 0.0 and if not why does XtGetValues not work?

The version which I'm using is Apollo Domain/X11 which is somewhere
between X11.R2 and X11.R3. I'm running on an DN3000 under 9.7.

Please answer to me by e-mail and I'll post a summary.

Thanks in advance.

Fredrik Hedman


Below is sample program using Xaw widgets which will clarify the problem.

------ BEGIN CUT HERE -----
#ifndef lint
static char rcsid[] = "$Header: xscroll.c,v 1.6 88/02/14 15:13:11 rws Exp $";
#endif lint

#include <X11/Intrinsic.h>
#include <X11/Form.h>
#include <X11/Command.h>
#include <X11/Scroll.h>
#include <X11/StringDefs.h>
#include <X11/Cardinals.h>
#include <stdio.h>

/* Command line options table.  Only resources are entered here...there is a
   pass over the remaining options after XtParseCommand is let loose. */

static XrmOptionDescRec options[] = {
{"-label",	"label",		 XrmoptionSepArg, NULL},
{"-horiz",	"scrollbar.orientation", XrmoptionNoArg,  "horizontal"}
};

char *ProgramName;

/*
 * Report the syntax for calling xcommand
 */
Syntax()
{
    fprintf( stderr, "Usage: %s\n", ProgramName );
}

void Thumbed(w, closure, top)
    Widget w;
    caddr_t closure;
    float top;
{
    printf( "thumbed to %f%%\n", 1.0 - top );
}

void Scrolled(w, closure, call_data)
    Widget w;
    caddr_t closure;	/* Not used */
    int call_data; 	/* Not used*/
{
	/* Do nothing */
}

void GetFinalValue(widget, closure, callData)
Widget widget;
caddr_t closure;	/* Scrollbar widget */
caddr_t callData;	/* Not Used */
{
	Arg arg[1];
	float top = 0.5;

	/*
	This seems to mean XtNtop is really = 0.0
	Why do I not get the value which Thumbed 
	gives me?
	*/
	printf("Top before: %.2f ", top);
	XtSetArg(arg[0],XtNtop,(XtArgVal)&top);
	XtGetValues((Widget)closure, arg, ONE);
	printf("Top after: %.2f\n", top);
}

void main(argc, argv)
    unsigned int argc;
    char **argv;
{
    Widget top, form, bar, com;
	 Arg arglist[10];
	 Cardinal i;

    ProgramName = argv[0];

    top = XtInitialize(NULL,"Demo",options,XtNumber(options),&argc,argv);

    if (argc != 1) Syntax ();

    form = XtCreateManagedWidget("form",formWidgetClass,top,NULL,NULL);

	 i = ZERO;
	 XtSetArg(arglist[0],XtNlength,(XtArgVal)200); ++i;
    bar = XtCreateManagedWidget( "scrollbar", scrollbarWidgetClass, form,
			   arglist, i );
	 XtAddCallback(bar,XtNscrollProc,Scrolled,NULL);
	 XtAddCallback(bar,XtNthumbProc,Thumbed,NULL);
	 XtScrollBarSetThumb( bar, 0.5, 1.0 );

	 i = ZERO;
	 XtSetArg(arglist[0],XtNfromHoriz,bar); ++i;
	 com = XtCreateManagedWidget("Get Value",commandWidgetClass,form,
			   arglist, i );
	 XtAddCallback(com,XtNcallback,GetFinalValue,(caddr_t)bar);
    
    XtRealizeWidget(top);
    XtMainLoop();
}
------ END CUT HERE -----