[comp.windows.x] floats and XtSetArg

sheehyjp%v701.DECnet@NUSC.NAVY.MIL ("V701::SHEEHYJP") (07/02/90)

	I'm in the process of writing my first widget and I would like to use
a variable type float as one of my resources.  I have the converter (I'm using
R3) and everything works fine when I use the default or if I place the float
in a resource file, but when I try to hard code a value in my application
using XtSetArg, the widget always gets a zero.  How can I use XtSetArg to
send a float to my widget?  I hope there is someone out there who can help.

Thank you,
Jim
sheehyjp@nusc.navy.mil

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (07/02/90)

> How can I use XtSetArg to send a float to my widget? 

Here is some code that sets the "shown" resource of the Athena Scrollbar widget.
This is in the Athena R4 widget documentation, for those of you who have it.

	top = 0.5;
	if (sizeof(float) > sizeof(XtArgVal)) {
	/*
	 * If a float is larger than an XtArgVal then pass this 
	 * resource value by reference.
	 */
		XtSetArg(args[0], XtNshown, &top);
	}
	else {
	/*
	 * Convince C not to perform an automatic conversion, which
	 * would truncate 0.5 to 0. 
	 */
		XtArgVal * l_top = (XtArgVal *) ⊤
		XtSetArg(args[0], XtNshown, *l_top);
	}


						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213

asente@wrl.dec.com (Paul Asente) (07/04/90)

In article <9007021151.AA13264@expo.lcs.mit.edu> sheehyjp%v701.DECnet@NUSC.NAVY.MIL ("V701::SHEEHYJP") writes:
>
>	I'm in the process of writing my first widget and I would like to use
>a variable type float as one of my resources.  I have the converter (I'm using
>R3) and everything works fine when I use the default or if I place the float
>in a resource file, but when I try to hard code a value in my application
>using XtSetArg, the widget always gets a zero.  How can I use XtSetArg to
>send a float to my widget?  I hope there is someone out there who can help.

You *really* don't want to do this.  *Really*, *really*, *really*.

By now you've probably seen the other responses that show you how to make
this work, so I won't go through them again.  But do you want to make everyone
who uses your widget have to go through all that complexity?

Consider either creating a new resource type, a pointer to a float (you
should still be able to create a converter just fine, but you'll also
need a destructor) or replacing the resource with two integers, either
numerator/denominator or value/scale.

It's unfortunate that specifying float resources is so hard, but it is.
Better to avoid them than to constantly expose the problem to people.

	-paul asente
	    asente@decwrl.dec.com	...!decwrl!asente