Parameter passing and signal connect



Howdy All,

I have a question about event handling functions.  I am using a drawing area
widget which is configured to use the button press event and button release
events (among others).  The question is how can I pass in a struct to the
signal handlers that I need them to update?  Right now the code is as shown
below where all of the undeclared variables are global.  I am reworking the
package so that all of the data is organized in a struct of a bunch of other
structs which need to be updated by the cursor events.  Is there a way I can
pass three parameters to these functions?  Any ideas?  The struct contains
information to read data from a stack of image files, information about the
currently displayed region, last selected region etc.  It seems odd to me
that in the signal connect function I have NULL in
"GTK_SIGNAL_FUNC(cursor_up_event,NULL)"; but somehow I'm getting a
GdkEventButton in the event...  ??  Can anyone explain how this works?

Thanks all,
Everyone enjoying their summer? (Winter Southern Hemispherers...)?


void cursor_down_event(GtkWidget* widget,GdkEventButton *event)
{

  X1=(int)event->x;
  Y1=(int)event->y;

  validRegion=1; /* must be valid to be detected */
  reDrawLabels(X1,Y1);
}
void cursor_up_event(GtkWidget* widget,GdkEventButton *event)
{
  int temp;
  X2= (int) event->x;
  Y2= (int) event->y;

  if(!(X1<=X2)){
    temp=X1;
    X1=X2;
    X2=temp;
  }
  if(!(Y1<=Y2)){
    temp=Y1;
    Y1=Y2;
    Y2=temp;
  }
  if((Y1>=0) && (X1>=0) && (((Y2/zoomFactor)+startY)<=endY) 
     && (((X2/zoomFactor)+startX)<=endX)) validRegion=1;
  else validRegion = 0;
  reDrawLabels(X2,Y2);
  gdk_draw_rectangle(ImageF->window,
                     ImageF->style->white_gc,
                     FALSE,X1,Y1,X2-X1,Y2-Y1);
}

  ImageF = gtk_drawing_area_new();
 
gtk_drawing_area_size(GTK_DRAWING_AREA(ImageF),zoomFactor*(endX-startX+1),zo
omFactor*(endY-startY+1));

/*******************  This part is in main(...)
*****************************/

  ImageF = gtk_drawing_area_new();
 
gtk_drawing_area_size(GTK_DRAWING_AREA(ImageF),zoomFactor*(endX-startX+1),zo
omFactor*(endY-startY+1));
  
  gtk_widget_show(ImageF);
 
  gtk_widget_set_events(ImageF,
                        gtk_widget_get_events(ImageF) 
                        | GDK_BUTTON_PRESS_MASK 
                        | GDK_BUTTON_RELEASE_MASK );

  gtk_signal_connect(GTK_OBJECT (ImageF),"button_press_event",
                     GTK_SIGNAL_FUNC(cursor_down_event),
                     NULL);
  gtk_signal_connect(GTK_OBJECT (ImageF),"button_release_event",
                     GTK_SIGNAL_FUNC(cursor_up_event),
                     NULL);
/***************************************************************************
**/






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]