GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Two or more button sharing the same callback functtion

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Joel
GTK+ Guru


Joined: 06 Apr 2008
Posts: 225
Location: Fortress of solitude

PostPosted: Fri Mar 05, 2010 7:06 pm    Post subject: Two or more button sharing the same callback functtion Reply with quote

Hi all, Is there a way to know which button was pressed if they share the same callback function:
Code: (C)
1
2
3
4
5
6
7
8
9
10
11

void box_clicked (GtkButton *button, GPuntos *pGame)
{
 // need to know which button was clicked, so I can use GPuntos structure
}

// .. later

g_signal_connect (G_OBJECT (box1),"clicked",G_CALLBACK (box_clicked), game);
g_signal_connect (G_OBJECT (box2),"clicked",G_CALLBACK (box_clicked), game);

thanks :)
Back to top
fidel
Familiar Face


Joined: 07 Aug 2009
Posts: 7

PostPosted: Fri Mar 05, 2010 10:53 pm    Post subject: Reply with quote

Your box_clicked function receives a pointer to a button. So box_clicked could test a property of the button, for example its label or name.

To set/get a widget's name, use:

http://library.gnome.org/devel/gtk/2.15/GtkWidget.html#gtk-widget-set-name
http://library.gnome.org/devel/gtk/2.15/GtkWidget.html#gtk-widget-get-name

openldev explains a more general solution here:

http://www.gtkforums.com/about625.html
Back to top
Joel
GTK+ Guru


Joined: 06 Apr 2008
Posts: 225
Location: Fortress of solitude

PostPosted: Mon Mar 08, 2010 3:53 pm    Post subject: Reply with quote

Thanks it worked.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP