[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
GdkEventButton handler
- From: Carlos Pereira <carlos pehoe civil ist utl pt>
- To: gtk-app-devel-list redhat com
- Subject: GdkEventButton handler
- Date: Sun, 3 Oct 1999 14:41:17 +0100
> Can you get more info from a "clicked" signal ? As in, what button clicked it ?
This is a working example showing a button widget which is able to distinguish
between mouse buttons 1, 2 and 3, and which looks the same when mouse button 1, 2
or 3 is pressed. It also recognizes double and triple clicks on the three buttons.
I tried to concentrate only in the essential aspects, so no additional routines are
included (to close the window, for example).
Carlos Pereira,
Technical University of Lisboa,
Portugal
---------------------------button.c-------------------------------
#include <gtk/gtk.h>
/* see gtk/include/gdk/gdktypes.h for GdkEventButton type */
gint signal_handler_event (GtkWidget *widget, GdkEventButton *event)
{
printf ("button %d ", event->button);
switch (event->type)
{
case (4): printf ("pressed! (Come on... you can be faster than that...\n");
/* to force buttons 2, 3 to go down */
gtk_button_pressed (GTK_BUTTON (widget));
break;
case (5): printf ("double clicked! (Much better! You are improving...)\n");
break;
case (6): printf ("triple clicked! (Uau! that is really fast!)\n");
break;
case (7): printf ("released!\n");
/* to force buttons 2, 3 to come up */
gtk_button_released (GTK_BUTTON (widget));
}
}
int main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *button;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label ("GTK Rocks!");
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_signal_connect (GTK_OBJECT(button), "button_press_event",
GTK_SIGNAL_FUNC(signal_handler_event), NULL);
gtk_signal_connect(GTK_OBJECT(button), "button_release_event",
GTK_SIGNAL_FUNC(signal_handler_event), NULL);
gtk_main ();
}
---------------------------------------------------------------
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]