[comp.windows.x] Xtk Scrollbars broken: double to float chopping

lmjm@doc.imperial.ac.UK (Lee McLoughlin) (08/17/88)

VERSION:
	X11 release 2

CLIENT MACHINE:
	HLH Orion 1/05 (Fairchild Clipper processor).

CLIENT OPERATING SYSTEM:
	4.2 BSD Unix

DISPLAY:
	StarPoint

SYNOPSIS:
	Can't move slider in an Xtk scrollbar.

DESCRIPTION:
	When trying to move the slider in an Xtk scrollbr (such as in
	xterm) you get weird results.  The xterm slider leaps back and forth
	from where it should be (at the cursor) to the top of the
	scrollbar.

REPEAT-BY:
	Move the xterm slider.

[[This is the original message from Steve Thomas <steve@hlh.co.uk>.]]
I've discovered what's wrong with scroll bars.  Turn to p25 of 'X Toolkit
Widgets - C Language X Interface'.  Some of the routines take float
arguments.  The trouble is, they are passed through the XtCallBack
mechanism, which states that the "opaque data" is the actual data
if it's one word, or a pointer to the data if it's more than one.

Unfortunately, floats get promoted to doubles, so half the datum
disappears.  Typically, it's the half with the exponent and high order
bits of the fraction.

For concreteness, inside lib/Xaw/Scroll.c is the statement
    XtCallCallbacks( gw, XtNthumbProc, w->scrollbar.top);
where w->scrollbar.top is a float.

Inside lib/Xt/Callback.c is

    void XtCallCallbacks(widget, name, call_data)
        Widget   widget;
        String   name;
        caddr_t  call_data;
    {
        CallbackList *callbacks;
    
        callbacks = FetchCallbackList(widget, name);
	...
        _XtCallCallbacks(callbacks, call_data);
    } /* XtCallCallbacks */
    
    void _XtCallCallbacks (callbacks, call_data)
        CallbackList *callbacks;
        caddr_t       call_data;
    {
	...
	(*(cl->callback)) (cl->widget, cl->closure, call_data);
	...
    }
[[end of original message]]



Both Steve and I would like to know what the ``correct'' solution to
this is?  I guess it must be to go thru and pass pointers to floats
since you cannot pass them as an arg without the risk of it being
widened.  If you force it not to widen on passing by:
    XtCallCallbacks( gw, XtNthumbProc, (int)(w->scrollbar.top));
It would still go wrong on calling the callback because the compiler
will widen the argument type from float to double.  But now it is only
being passed a float.

	Lee & Steve.
--
--
UKUUCP SUPPORT  Lee McLoughlin
	"What you once thought was only a nightmare is now a reality!"

Janet: lmjm@uk.ac.ic.doc, lmcl@uk.ac.ukc
DARPA: lmjm@doc.ic.ac.uk (or lmjm%uk.ac.ic.doc@nss.cs.ucl.ac.uk)
Uucp:  lmjm@icdoc.UUCP, ukc!icdoc!lmjm