From: mcfar@leadse5.UUCP (Lincoln McFarland)
Newsgroups: comp.windows.x.motif
Subject: Re: Passing more than one widget to a callback
Keywords: nn
Date: 19 Aug 92 21:51:19 GMT
Organization: LMSC, Sunnyvale

Thanks to everyone for their input to my passing-more-than-one-widget-to-a-
callback problem.  What I needed was to pass a pointer to a structure of 
widgets, not a structure of widgets or a structure of pointers to widgets.  
A few more big mistakes like this one, and I might really get a handle on 
this motif stuff ;-)

------------------------------------------------------------------------------
The system I used was:

typedef struct {
  Widget flnm;   /* filename */
  Widget sr;     /* sample rate */
} sass_data_bus;


Widget create_sass_selector( filename_display, sr_display )
Widget filename_display; /* widget to display selected filename */
Widget sr_display;       /* widget to display sample rate */
{
  extern Widget toplevel;

  Widget select_dialog;

  sass_data_bus *input_display;
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */

  char message[256];

  Arg al[10];
  int ac;

  if ( (input_display
        = (sass_data_bus *)XtMalloc(sizeof(sass_data_bus))) == NULL) {
       /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
    sprintf(message, "Unable to allocate memory for sass_data_bus.");
    display_error_msg( message);
    return;
  }

  input_display->flnm = filename_display;
  input_display->sr   = sr_display;

  /* create the file selection box dialog widget */
  ac = 0;

  select_dialog = XmCreateFileSelectionDialog( toplevel,
                                              "select_input", al, ac);

  XtAddCallback( select_dialog, XmNokCallback, sass_ok_CB, input_display);  
                                                         /*^^^^^^^^^^^^^^*/
  XtAddCallback( select_dialog, XmNcancelCallback, sass_cancel_CB, 0);
  XtAddCallback( select_dialog, XmNdestroyCallback, sass_destroy_CB,
                input_display);

  return select_dialog;

} /* end create_sass_selector() */



and accessed the widgets in the sass_ok_CB as input_display->flnm.  

/* dialog box for the file selection call back */
void sass_ok_CB( w, input_display, call_data)
Widget w;
sass_data_bus *input_display;
/*^^^^^^^^^^^^^^^^^^^^^^^^^^*/
XmAnyCallbackStruct *call_data;
{
  ...

  XmTextSetString( input_display->flnm, filename);
                 /*^^^^^^^^^^^^^^^^^^^*/
  XmTextShowPosition( input_display->flnm, strlen(filename) );

  ...

}

I also added the sass_destroy_CB to properly handle the memory.

/* dialog box for the file selection call back */
void sass_destroy_CB( w, input_display, call_data)
Widget w;
sass_data_bus *input_display;
XmAnyCallbackStruct *call_data;
{

  XtFree( input_display );

} /* end select_destroy_CB() */


Thanks again to the following people who replied and helped me solve this
(in reverse order of messages received):

Lee Beaudette      leebeau@world.std.comsb.edu
Michael D'Errico   mike@zorbas.ece.uc
Mark Levison       mark@bhanu.andyne.on.ca
Dave Tiktin        tiktin@cs.uoregon.edu
Terry J. Deveau    deveau@koala.drea.dnd.ca
Richard M. Rybacki rrybacki@ringer.cs.utsa.edu
Ik Su Yoo          ik@ctt.bellcore.com
Jorgen Eriksson    Jorgen.Eriksson@eua.ericsson.se
Marc Gemis         gemis@bietel.uia.ac.be


+-----------------------------------------------------------------------------+
| "Just a Pedantics major from Berkeley" |            Randy McFarland         |
|                        - Spalding Gray | mcfar@sunfse.ese.lmsc.lockheed.com |
+-----------------------------------------------------------------------------+

+-----------------------------------------------------------------------------+
| "Just a Pedantics major from Berkeley" |            Randy McFarland         |
|                        - Spalding Gray | mcfar@sunfse.ese.lmsc.lockheed.com |
+-----------------------------------------------------------------------------+
Newsgroups: comp.windows.x.motif,comp.windows.x