Re: [gtk-list] gpointer and callbacks



>> examples I found only strings where used. Can you pass any type using
>> gpointer?

Yes.

here's a little coding example to show how:


I have two buttons, the clicking of one would disable itself and enable 
the other:

......

button1  = gtk_button_new_with_label("Enable 2");

button2  = gtk_button_new_with_label("Enable 1");

gtk_signal_connect (GTK_OBJECT (button1), "clicked",
    GTK_SIGNAL_FUNC (enable_disable), (GtkWidget *)button2);
    
gtk_signal_connect (GTK_OBJECT (button1), "clicked", 
   GTK_SIGNAL_FUNC (enable_disable), (GtkWidget *)button1);

/* instead of (GtkWidget *)button1, you could also use the
the type-casting macros like:  GTK_WIDGET(button1) */

.......


and the enable_disable function is defined as such:


gint enable_disable(GtkWidget *disable_this, GtkEvent *event, 
     GtkWidget *enable_this)
{
	/* the GtkEvent event can be used to determine, left clicks,
	  right clicks, double or triple clicks, etc... */
	  
	........
	  
	/* any hoo... */
	gtk_widget_set_sensitive(disable_this, FALSE);
	gtk_widget_set_sensitive(enable_this, TRUE);
	
	........
}


hope that helped.

Nwanua.




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