Re: Find referring form

Steve Lamont (spl@szechuan.ucsd.edu)
Wed, 14 May 97 09:47:29 PDT

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

> How do I get a pointer to other objects in the form from an object in the
> form?

The Object always points to the Form so the construction

FL_FORM *the_form = obj->form;

should always work. What kind of compiler errors were you getting?

If you're using fdesign to build your Forms, then the FL_FORM data
structure will have a pointer back to the FD_whatever data structure
so this should work:

FD_my_dui *my_dui = ( FD_my_dui *) the_form->fdui;

This should allow you to access any Object defined within FD_my_dui.

Accessing other Forms and Objects within those Forms is up to the
user.

My general tack on this is to create what I usually call a Context
data structure which contains all of the active DUI structures in
which I'm interested along with whatever other data I might want to
pass between Forms or Objects. When I create a new Form one of the
first things I do is to hang a pointer to the Context onto the DUI
structure and log the Form's DUI into the Context:

FD_my_dui *my_dui = create_form_my_dui()

my_dui->vdata = ( void *) context_ptr;
context_ptr->my_dui = my_dui;

Then, as shown in a framentary manner above, in a callback I can do

void some_callback_cb( FL_OBJECT *obj, long data )

{

FL_FORM *the_form = obj->form;
FD_my_dui *my_dui = ( FD_my_dui *) the_form->fdui;
ContextP context_ptr = ( ContextP ) my_dui->vdata;

[...]

}

Note: ContextP is typedefed as

typedef struct _Context Context;
typedef Context *ContextP;

for notational convenience -- I generally use opaque data structures
and have a standard set of access routines to maintain them.

Note that since all FD_whatever types have the same form

typedef struct {
FL_FORM *form;
void *vdata;
long ldata;
[...]
} FD_whatever;

you can construct a "generic" FD object:

typedef struct {
FL_FORM *form;
void *vdata;
long ldata;
} FD_Generic;

and find the Context even if you don't know what the FD type is (which
would be the case where you use a single callback from several
different forms):

FL_FORM *the_form = obj->form;
ContextP context_ptr =
( ContextP ) ( ( FD_Generic *) obj->form->fdui )->vdata;

and off you go.

> PS. I hope my explaination of the program is clear enough.

Mine too.

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/xforms-archive/