Re: 1 callback,many spins




I'm trying to create a dialog that has a variable number of spinbuttons.
with one callback function to handle them.But how to get the value from
a specific spinbutton into a specific variable. The value from the
first or topmost spin goes into say data[1], then the next value goes
into data[2], etc.Creating the spins with a function is easy as Wright 
shows in his book on Beginning GTk+ but assigning the values is the
problem.
Is there a snippet library where GTK+ code can be found? Or must
one wade through an entire program for examples.


Just set some flag on the spinbuttons that allows your callback to
distinguish them. There are any number of ways to do that; one of the
easiest might be:

void
set_widget_tag (GtkWidget *widget, const char *tag)
{
  gtk_object_set_data (GTK_OBJECT (widget), "tag", tag);
}

const char *
get_widget_tag (GtkWidget *widget)
{
  return gtk_object_get_data (GTK_OBJECT (widget), "tag");
}

For examples, GTK itself comes with testgtk that has a number of
examples, and the various books have examples. And of course there are
several thousand open source apps out there to look at; some of them
are very small and simple.

Havoc




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