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

I was wondering if it is possible to pass more than one widget to a call
back using a user defined data structure like:

/* structure to pass mulitple widgets to call back */
typedef struct {
  Widget flnm;   /* filename */
  Widget sr;     /* sample rate */
} data_bus;

So you can use a function like:

/* create input selector function */
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; /* defined in ir.h */

  Widget select_dialog;

  data_bus input_display;

  Arg al[10];
  int ac;

  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, data_bus);
  XtAddCallback( select_dialog, XmNcancelCallback, sass_cancel_CB, 0);

  return select_dialog;

} /* end create_sass_selector() */


And then dereference it like:

/* dialog box for the file selection call back */
void sass_ok_CB( w, input_display, call_data)
Widget w;
data_bus input_display;
XmAnyCallbackStruct *call_data;
{
  char *filename;               /* full filename */
  char message[256];
  char SigSr[20];
  SASS_HEADER header;
  void display_error_msg();

  XmSelectionBoxCallbackStruct *selection;

  selection = (XmSelectionBoxCallbackStruct *) call_data;
  XmStringGetLtoR( selection->value, XmSTRING_DEFAULT_CHARSET, &filename);

  /* open sass file and get the sample rate */
  if( (open_sass_file( filename, &header,
                      TIME_SAMPLED_FILE, READ)!= 0 ) ) {
    sprintf(message, "File: %s \nis not in the SASS format.", filename);
    display_error_msg(message);
  }
  else {
    sprintf( SigSr, "%10.1f", header.s_rate );
    XmTextSetString( input_display.sr, SigSr);
  }

  XmTextSetString( input_display.flnm, filename);
  XmTextShowPosition( input_display.flnm, strlen(filename) );


  XtFree(selection);

  XtUnmanageChild(w);

}/* end file select_ok_CB()  */

This gives a segmentation fault.  I tried playing around with pointers to
widgets, so the data bus becomes:

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

and things are assigned as:

  input_display.flnm = &filename_display;
  input_display.sr   = &sr_display;

and dereferenced as:

  input_display->flnm

but that dosn't work either.  I don't want to resort to global variables if
I don't have to, but I don't think I have a good enough grasp on what widgets
are in terms of C things like pointers to do this.  Any insight would be
greatly appreciated.


thanks.



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