Re: XForms: keyboard slider control?

Steve Lamont (spl@szechuan.ucsd.edu)
Mon, 3 Nov 97 06:25:13 PST

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> Is there anyway to get a slider to respond to left and right arrow keys?
> Similar to the way motif works where after you select a slider you can
> move it with the arrow keys. Trying to move a slider up exactly 3 steps
> with the mouse is a real pain, compared to simply pushing right 3 times.

You can set an object shortcut key with fl_set_object_shortcutkey()
and use a preemptive handler to discriminate between the keys.

[...]
#include <X11/keysym.h> /* You need this for the KeySyms */
[...]

int slider_handler( FL_OBJECT *obj, int event,
FL_Coord mx, FL_Coord my,
int key, void *raw_event )

{

if ( key == XK_Right ) {

double value = fl_get_slider_value( obj );

fl_set_slider_value( obj, value + 0.1 );

} else if ( key == XK_Left ) {

double value = fl_get_slider_value( obj );

fl_set_slider_value( obj, value - 0.1 );

}
return !FL_PREEMPT;

}

void slider_cb( FL_OBJECT *obj, long data )

{

[...]

}

int main(int argc, char *argv[])

{

FD_try *fd_try;

fl_initialize(&argc, argv, 0, 0, 0);
fd_try = create_form_try();

fl_set_object_prehandler( fd_try->slider, slider_handler );
fl_set_object_shortcutkey( fd_try->slider, XK_Right );
fl_set_object_shortcutkey( fd_try->slider, XK_Left );

fl_show_form(fd_try->try,FL_PLACE_CENTERFREE,FL_FULLBORDER,"try");

fl_do_forms();
exit( 0 );

}

I'm not sure what you'd do if you had multiple sliders. I suppose you
could track FL_ENTER and FL_LEAVE events and return FL_PREEMPT for all
but the slider which has the current focus. I haven't tried it so
I'm not sure how well it would work.

This is sort of a kluge (sort of?). I believe the correct solution
would be to either create your own `ArrowSlider' class wrapped around
the real Slider class or for TC to add the arrow keys as an extension
to the current class.

BTW, I noticed as I was crufting up this little example with fdesign
that when you click on the `Spec' tab in the Slider attributes dialog
that fdesign emits a couple of what appear to be debug messages:

min=0.000000 max=1.000000
min=0.000000 max=1.000000

This happens in the 0.87.5 version. I don't recall seeing it in
earlier versions.

Forget to #ifdef something out, TC? :-)

Another thing that might be useful in Sliders, especially in this
case, would be to be able to query step size since you can set it with
fl_set_slider_step(). Same probably goes for increment and
precision. My general suggestion is that if you can set a parameter,
you should be able to query it elsewhere in the code without doing a
lot of extraneous application program bookkeeping.

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/