Getting the data a user selected in a dialog box



Hello,

I'm working on an application using gtk+, and I'm not experienced
enough yet to figure out this little problem I'm having.  I could be
doing things all wrong, too, so feel free to point out the correct way
to do this:

I've got a program with menus.  One menu item is "New".  When "New" is
selected, a dialog pops up with radio buttons in it.  The user chooses
the desired parameters, clicks "OK", and another window pops up.
Sound familiar?

Anyway, I'm using gtk_object_set_data() to set information for each
radio button, like so:

    group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
    button = gtk_radio_button_new_with_label(group, "Button Label");

    gtk_signal_connect (GTK_OBJECT (button), "clicked",
			GTK_SIGNAL_FUNC(set_button_cb),
			(gpointer) dataHolder);
    gtk_object_set_data(GTK_OBJECT(button),"Param1", "1234");

Multiple radio buttons are constructed with the same key (Param1) but
with different data (1234...).  In the set_button_cb, I use
gtk_object_get_data() on the widget, and look for "Param1":

  static gint
  set_button_cb(GtkWidget *widget, DataHolder_t * dataObj)
  {
      gchar* str = (gchar*)gtk_object_get_data(GTK_OBJECT(widget),"Param1");
      g_print("Got data %s\n", str);

      dataObj->param1_choice = (int)strtol(str,NULL,10);
    
      return(TRUE);
  }

It returns, in this case, "1234", which gets converted to int and
stored with the data object.

That's the background.  Now when I run the program and select "New",
the dialog pops up fine, but right away I get "Got data" messages from
the callback.  In fact, the callback function for each radio button
group in the dialog gets called, apparently because the first button
in each group received a "clicked" event, even though I haven't
clicked on any of them.  Honest!

I wouldn't really care, except that I've set up certain default
selections using gtk_toggle_button_set_state(), and they don't match
any of the buttons that get the bogus "clicked" events.  If the user
clicks "OK", the choices selected are NOT my chosen defaults.

Anyone know what's going on here?  Any ideas for fixing it?  Is this
the right way to get the info about what a user selected from a dialog
box?  I'm trying to write the program so that I can have multiple
windows open working on different things all at the same time, and
this was the best I could come up with.

Thanks,

Charles Wright



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