Re: XForms: callback's

Steve Lamont (spl@szechuan.ucsd.edu)
Thu, 16 Jul 98 06:50:21 PDT

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

> hmm.. remember.. I do not want the focus to change if the string doesn't
> match. for example.. this is what I have been trying:
>
> [...]
> strcpy (buffer, fl_get_input (obj))
> if (!strcmp (buffer, "key") /* strcmp returns 0 if they match */
> {
> blah
> }
> else
> {
> fl_show_onliner (error stuff);
> fl_reset_focus (obj);
> }
> }
> [...]
>
> what happens is that if it fails the strcmp.. it shows the oneliner and
> then puts the focus onto the next input obj, which is not what I want it
> to do. It shouldn't leave the input field untill the strcmp is okay.

There is no such function as fl_reset_focus() in 0.88.1.

Do you mean fl_reset_focus_object()? fl_reset_focus_object is
intended, in the words of the manual, to be used "only when overriding
the FL_UNFOCUS event...." When I tested this last night, I checked to
see what events were being generated when Return was pressed and I
believe the FL_UNFOCUS only occurred when FL_RETURN_END was not
specified and Return was pressed without making any other entry in the
field.

I used

fl_set_focus_object( obj->form, obj );

and it worked exactly as expected.

Here's a little test program I cobbled up that illustrates what I'm
saying:

- - -
#include "forms.h"
#include "try.h"
#include <stdlib.h>

/** Header file generated with fdesign on Thu Jul 16 06:32:00 1998.**/

#ifndef FD_try_h_
#define FD_try_h_

/** Callbacks, globals and object handlers **/
extern void input_1_cb(FL_OBJECT *, long);
extern void input_2_cb(FL_OBJECT *, long);
extern void input_3_cb(FL_OBJECT *, long);

/**** Forms and Objects ****/
typedef struct {
FL_FORM *try;
void *vdata;
char *cdata;
long ldata;
FL_OBJECT *input_1;
FL_OBJECT *input_2;
FL_OBJECT *input_3;
} FD_try;

extern FD_try * create_form_try(void);

#endif /* FD_try_h_ */

FD_try *create_form_try(void)
{
FL_OBJECT *obj;
FD_try *fdui = (FD_try *) fl_calloc(1, sizeof(*fdui));

fdui->try = fl_bgn_form(FL_NO_BOX, 320, 250);
obj = fl_add_box(FL_UP_BOX,0,0,320,250,"");
fdui->input_1 = obj = fl_add_input(FL_NORMAL_INPUT,90,40,170,40,"Input 1");
fl_set_object_callback(obj,input_1_cb,0);
fdui->input_2 = obj = fl_add_input(FL_NORMAL_INPUT,90,100,170,40,"Input 2");
fl_set_object_callback(obj,input_2_cb,0);
fdui->input_3 = obj = fl_add_input(FL_NORMAL_INPUT,90,160,170,40,"Input 3");
fl_set_object_callback(obj,input_3_cb,0);
fl_end_form();

fdui->try->fdui = fdui;

return fdui;
}
/*---------------------------------------*/

void input_1_cb(FL_OBJECT *ob, long data)
{

if ( strcmp( fl_get_input( ob ), ob->label ) != 0 )
fl_set_focus_object( ob->form, ob );
else
fl_set_focus_object( ob->form,
( ( FD_try *) ob->form->fdui )->input_2 );

}

void input_2_cb(FL_OBJECT *ob, long data)
{

if ( strcmp( fl_get_input( ob ), ob->label ) != 0 )
fl_set_focus_object( ob->form, ob );
else
fl_set_focus_object( ob->form,
( ( FD_try *) ob->form->fdui )->input_3 );

}

void input_3_cb(FL_OBJECT *ob, long data)
{

if ( strcmp( fl_get_input( ob ), ob->label ) != 0 )
fl_set_focus_object( ob->form, ob );
else
exit( 0 );

}

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

FD_try *fd_try;

fl_initialize(&argc, argv, 0, 0, 0);

fd_try = create_form_try();

/*
* Make sure just hitting Return doesn't advance us.
*/

fl_set_input_return( fd_try->input_1, FL_RETURN_END );
fl_set_input_return( fd_try->input_2, FL_RETURN_END );
fl_set_input_return( fd_try->input_3, FL_RETURN_END );

/*
* Make sure we start where we're supposed to.
*/

fl_set_focus_object( fd_try->try, fd_try->input_1 );

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

fl_do_forms();

return 0;

}
- - -

This should compile and link in the standard manner. In this example
program the focus should not advance to the next input object until
the expected string (which, in this case is the same as the object's
label).

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/