I have succeeded in handling mouse clicks in an application but have been
unable to catch mouse wheel scrolling events.  Based on extensive reading
of previous postings in this list, the following example program should
work for mouse wheel scrolling but it doesn't.  The click-handling part
works.  Note that this example program is not intended to do anything
useful, just to show that the events are being received.  Does anyone see
anything I've done wrong in attaching the wheel scrolling event or
anything I've overlooked?

#include <glib.h>
#include <gtk/gtk.h>


/*
        HandleMouseButton
        
        This is the callback for handling mouse clicks.
*/
static gboolean         HandleMouseButton(
                                                GtkWidget *
pWidget,        // the GTK widget that was clicked
                                                GdkEventButton *
pEvent,         // the button event structure
                                                gpointer
pUserData       
                                        )
{
        // GDK_BUTTON_PRESS = 4, GDK_2BUTTON_PRESS = 5
        g_print("HandleMouseButton event = %d, button = %d\n",
int(pEvent->type), int(pEvent->button));
        
        return false;   // false means continue propagating the event
        
} // HandleMouseButton


/*
        HandleMouseScrollWheel
        
        This is the callback for handling mouse scrolling.
*/
static gboolean         HandleMouseScrollWheel(
                                                GtkWidget *
pWidget,        // the GTK widget
                                                GdkEventScroll *
pEvent,         // the scroll event structure
                                                gpointer
pUserData       
                                        )
{
        g_print("HandleMouseScrollWheel\n");
        
        return false;   // false means continue propagating the event
        
} // HandleMouseScrollWheel



int             main(
                int                     argc,
                char *          argv    []
        )
{
        gtk_init(&(argc), &(argv));

        GtkWidget *             pWindow         =
gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(pWindow), "test window");
        
        // add handling of mouse clicks
        gtk_widget_add_events(pWindow, GDK_BUTTON_PRESS_MASK);
        g_signal_connect(       G_OBJECT(pWindow), 
                                                "button_press_event", 
        
G_CALLBACK(HandleMouseButton), 
                                                NULL);

        // add handling of mouse scroll wheel events
        gtk_widget_add_events(pWindow, GDK_SCROLL_MASK);
        g_signal_connect(       G_OBJECT(pWindow), 
                                                "scroll_event", 
        
G_CALLBACK(HandleMouseScrollWheel), 
                                                NULL);

        gtk_widget_show(pWindow);

        gtk_main();

        return 0;

}
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to