Passing an array of (GtkWidget *) to a callback function



I'm using a gnome dialog to allow the user to enter five strings in five
text entries, stored as an array of GtkWidget *'s. When the user clicks
OK I want to access the array of entries in the dialog_button_clicked 
callback function. So I want to either pass the array through the user
data or obtain a pointer to it from GtkWidget *widget. I got it working
like this:

/* 'which' is either 0 -- OK was clicked or 1 -- Cancel was clicked */
static void
dialog_button_clicked(GtkWidget *widget, gint which, GtkWidget *entry)
{
   static GtkWidget *entries[5] = {NULL, NULL, NULL, NULL, NULL};
   static gint num_entries = 0;

   entries[num_entries] = entry;

   num_entries++;

   if(num_entries == 5)
   {
      num_entries = 0;
      /* process entries array */
   }
}

/* in function where dialog is created: */

GtkWidget *entries[5] = {NULL, NULL, NULL, NULL, NULL};
gint i = 0;

/* initialize entries and pack them into the dialog... */

for(i = 0; i < 5; i++)
{
   gtk_signal_connect(GTK_OBJECT(dialog),
                      "clicked",
                      GTK_SIGNAL_FUNC(dialog_button_clicked),
                      (gpointer)entries[i]);
}

but there must be a better way to "get at" the entries array from
the callback function. Although I am using a gnome dialog, I thought this
would be the better list to post to. Any help would be great.

Thanks,
Tom





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