Re: XForms: getting the name of a form

Steve Lamont (spl@szechuan.ucsd.edu)
Sat, 6 Jun 98 20:29:45 PDT

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

> The reason: Every input field on every form has to write to the same
> pipe.. therefore it makes sence to have every input field call the same
> callback. ...

Actually, you'll no doubt be unsurprised to note, I disagree that this
necessarily makes sense. Just because they share a single common
function (the write to the pipe), this does not particularly mean that
this militates for a common callback.

Presumably, since each input field has a different function, the code
must somehow differentiate between input functions, for message
formatting purposes, if for no other reason. It seems to me that for
organizational purposes as well as code readability and maintainablity
that it would be appropriate to assign each input field a separate
callback -- or at least a callback for each class of inputs.

The file descriptor can be passed to the callback as a member of the
FD_* structure or in some other appropriate manner (even, *gasp*, a
global).

If you *still* feel compelled to have one giant, grand unified
callback, you could assign a callback argument to each input field
denoting its form and function:

#define FORM_1 0x00010000
#define FORM_2 0x00020000
#define FORM_3 0x00030000
#define FORM_4 0x00040000
...
#define FORM_MASK 0xffff0000

#define INPUT_1 0x00000001
#define INPUT_2 0x00000002
#define INPUT_3 0x00000003
#define INPUT_4 0x00000004
...
#define INPUT_MASK 0x0000ffff

#define FORM_1_INPUT_1 ( FORM_1 | INPUT_1 )
#define FORM_1_INPUT_2 ( FORM_1 | INPUT_2 )
#define FORM_1_INPUT_3 ( FORM_1 | INPUT_3 )
...

Then you could do

void grand_unified_callback( FL_OBJECT *ob, long data )

{

switch ( FORM_MASK & data ) {

case FORM_1: {

switch ( INPUT_MASK & data ) {

case INPUT_1: {

...
write( pipe_fd, msg, msg_size );
break;

}
...

}
break;

}
...

}

}

You'd, of course, assign the data values to the callback in the
standard manner -- in fdesign or in some other manner.

Since this is probably boring the rest of the list to distraction, I
shall correspond no more on this matter.

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/