[comp.windows.x] Callback Arguements in WCL

david@jpl-devvax.JPL.NASA.GOV (David E. Smyth) (03/06/91)

lossau@AUSTIN.LOCKHEED.COM (Kathleen O Lossau) writes:
>
>Is there anyone familar enough with the WCL (Widget Creation Library)
>to tell me if there is a way to pass information to a callback from
>WCL.  WCL seems to handle the passing of all information. The resource
>file cannot specify any call-data.

You can only pass strings reliably.  You *can* register client data
which is sent *if* there is nothing specified in the resource file
within the parens.  Like this:

*foo.callback:	MyCallback

This will send the registered client data to the callback.  However, 
if the user does this:

*foo.callback:  MyCallback()

Then your callback will get "\0" instead.

There is absolutely no possibly way of passing client defined call
data - that is passed by the widget invoking the callback, Wcl
does not get involved with that stuff at all.

In fact, Wcl does all the string-to-callback conversion when
the widget is created, not when the callback is invoked.

>I assume that I am missing something basic. (I'm new to WCL) and would like
>it to work for me, but I'm not sure how to (other than globals --- yuch!!!)
>pass information (like another widget) to a callback.

You can pass the name of the widget as the argument to the callback
or action, and then invoke WcFullNameToWidget, which is an extension
of XtNameToWidget.

Look at the WcCallb.c file to see how Wcl implements the standard
library supplied callbacks.  These might give you some hints.

Something I regularly do is this:  When I create a widget and I need
to relate some application information to the widget, I use the
wcCallback creation time callback mechanism, and the X Context Manager.

Let's say I need to relate an object `foo' to a widget `bar'.  I might
do this:

*bar.wcCallback:	CreateFoo( something )
*bar.callback:		Respond

The callback would do this:

void CreateFooCB( w, useful, ignore )
    Widget w;
    char*  useful;
    caddr_t ignore;
{
    /* create a Foo instance */
    Foo* foo = FooCreate( useful );
    XSaveContext( dpy, w, anything, foo );
}

void RespondCB( w, nothing, ignore )
    Widget  w;
    char*   nothing;
    caddr_t ignore;
{
    /* Assume I need to fool around with the Foo instance
    ** related to this widget when the widget was created
    */
    Foo* foo;
    XFindContext( dpy, w, anything, &foo );
    FooManipulate(foo);
}

-------------------------------------------------------------------------
David Smyth				david@jpl-devvax.jpl.nasa.gov
Senior Software Engineer,		seismo!cit-vax!jpl-devvax!david
X and Object Guru.			(818)393-0983
Jet Propulsion Lab, M/S 230-103, 4800 Oak Grove Drive, Pasadena, CA 91109
------------------------------------------------------------------------- 
 What's the earliest possible date you can't prove it won't be done by?
					- Tom DeMarco
-------------------------------------------------------------------------

marbru@attc.UUCP (Martin Brunecky) (03/06/91)

In article <499@shrike.AUSTIN.LOCKHEED.COM> lossau@AUSTIN.LOCKHEED.COM (Kathleen O Lossau) writes:
>
>Is there anyone familar enough with the WCL (Widget Creation Library)
>to tell me if there is a way to pass information to a callback from
>WCL.  WCL seems to handle the passing of all information. The resource
>file cannot specify any call-data.
>
     Mhmmm. Dave's examples and tons of .PS files seem to be inadequate....
     Try:

     *button.activateCallback:   YourCallback(Your_call_data_string)

     The routine YourCallback should be called with a pointer to the
     string "Your_call_data_string" in the call_data.



-- 
=*= Opinions presented here are solely of my own and not those of Auto-trol =*=
Martin Brunecky                           {...}sunpeaks!auto-trol!marbru
(303) 252-2499                        (sometimes also:  marbru@auto-trol.COM )
Auto-trol Technology Corp. 12500 North Washington St., Denver, CO 80241-2404