One other thing I didn't clarify...
The reason when you connect to "button-press-event" nothing happens,
that's because the function prototype (as described in the API docs for
GtkWidget) is different. It has 3 parameters:
(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
Where your 'Happened' function only has 2 parameters.
When you're starting out, it's easiest to build your prototypes for
callbacks exactly as they appear in the API. That way you know what
you're dealing with.
gboolean on_button_press_event (GtkWidget *widget, GdkEventButton
*event, gpointer user_data)
{
g_print ("on_button_press_event: %s", (gchar*)user_data);
return FALSE; /* propogate signal to default handlers */
}
void on_pressed (GtkWidget *widget, gpointer user_data)
{
g_print ("on_pressed: %s", (gchar*)user_data);
return FALSE; /* propogate signal to default handlers */
}
/* ... down in main() ... */
GtkWidget *B = gtk_button_new_with_label (Label);
g_signal_connect (GTK_OBJECT (B), "button-press-event",
G_CALLBACK (on_button_press_event), "The mouse was
clicked on a GtkWidget.");
g_signal_connect (GTK_OBJECT (B), "button-press-event",
G_CALLBACK (on_pressed), "The button was pressed on a
GtkButton.");
- Micah Carrick
Developer - http://www.micahcarrick.com
GTK+ Forums - http://www.gtkforums.com
Micah Carrick wrote:
Start with the API documentation for a GtkButton:
http://library.gnome.org/devel/gtk/stable/GtkButton.html
Scroll down to "Signals" to see each signal you can connect a callback
to for a GtkButton as well as the prototype for writing such a callback
function. That is where "pressed" is coming from... the GtkButton.
You can also look at the section called "Object Hierarchy" in the API to
see which objects a GtkButton is derived from. You can also use the
signals for any of those objects. If you were to click on GtkWidget,
you'll find the "button-press-event" signal there with the description:
" The ::button-press-event signal will be emitted when a button
(typically from a mouse) is pressed."
So as you can see, the "pressed" signal from GtkButton is what you want
to connect to for a user clicking a button. If you want to capture the
mouse clicking on a widget... any widget... you use "button-press-event".
Whenever you find a signal that you don't know to which object it
belongs, one easy way out is to search for it in Devhelp.
- Micah Carrick
Developer - http://www.micahcarrick.com
GTK+ Forums - http://www.gtkforums.com
Charles Packer wrote:
If I code a button widget like this (I'm using the version
of GTK that came with Fedora Core 5)...
GtkWidget *B = gtk_button_new_with_label (Label);
g_signal_connect (GTK_OBJECT (B), "button-press-event",
G_CALLBACK (Happened), "HELLO");
and the callback is this...
Happened (GtkWidget *W, gpointer Data) {
g_print ("ButtonHappened...|%s|\n", (char *) Data);
}
when Happened is executed, it doesn't print the data. That is, I get
"ButtonHappened...||". But when I replace the parameter
"button-press-event" in the call to g_signal_connect with "pressed",
on execution the printout is as desired, "ButtonHappened...|HELLO|".
Now, "button-press-event" is in lists of event types such as you
find in the GTK 2.0 tutorial at
http://www.gtk.org/tutorial/a2769.html
As for "pressed", I don't know where I got it. It must have
come along with some example I found in a newsgroup or on the Web.
I haven't been able to find an event-type list anywhere that
contains it, so I can't solve the mystery of why I get what I
want when I use that parameter, but not with the "legitimate"
parameter.
--
Charles Packer
http://cpacker.org/whatnews
mailboxATcpacker.org
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list