Re: XForms: Forms!

Steve Lamont (spl@szechuan.ucsd.edu)
Fri, 12 Feb 99 07:18:26 PST

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

> I wish you could help me with a problem. I need to show a form in a
> program by pressing a determinate button. In the button's callback, I
> put the fl_show_form(...) routine but there is a problem:
>
> one of the arguments of the callback is FL_OBJECT *ob, isn't it? And the
> argument of the fl_show_form(..) is the FL_FORM *form.
> How can i access a form from another struct than that wich the parameter
> ob belongs to??????

There are several ways, depending upon your program style. The first
and easiest way is to simply make the FD_* structure a global
variable. Then any function which can "see" the variable can access
any of its contents.

The second way is to use the u_vdata structure member of the FL_OBJECT
or FL_FORM data structure or the vdata structure member of the FD_*
structure generated by `fdesign' to maintain a link via a pointer to
to a data structure of your own devising containing whatever useful
context information you might want to carry there, including the
pointers to other FD_* structures. For example:

typedef struct {
FD_whatever *whatever;
FD_other *other;
} Context;

[...]

Context *context = ( Context *) malloc( sizeof( Context ) );

/* Create the form structures */

context->whatever = create_form_whatever();
context->other = create_form_other();

/* Now cross link the context with the form definitions */

context->whatever->vdata = context;
context->other->vdata = context;

[... do your form startup stuff ...]

void some_callback( FL_OBJECT *ob, long data )

{

Context *context = ( Context *) ( ( FD_Any *) ob->form->fdui )->vdata;

fl_...( context->whatever->some_object_in_whatever, ... );
fl_...( context->other->some_object_in_other, ... );

[...]

}

I cast the `ob->form->fdui' dereference to a pointer to `FD_Any',
which is a generic FD_* structure declared in `forms.h'. I could
have, of course, cast it to the actual structure type to which the
object belongs but this more general syntax allows me to embed this in
a macro which is used in any object in any form. For example:

#define CONTEXT(ob) ( ( Context *) ( ( FD_Any *) ob->form->fdui )->vdata )

[...]

void some_callback( FL_OBJECT *ob, long data )

{

Context *context = CONTEXT( ob );

[...]

Hope this is helpful.

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/