Problem with canvas



Hi,

My problem is Canvas (i.e.) Gnome-related, however it is also related to Gtk
event handling, so I hope it is ok to post it here.

What I want to do : pack widget in a GnomeCanvas and be able to move them
around the canvas with the mouse. So I think I need to catch
GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE and GDK_MOTION_NOTIFY. However, I'm
unable to catch all these events.

Here's the relevant part of the code :

/* Need an event box since pic is a windowless widget */
event_box = gtk_event_box_new();
pic = gnome_pixmap_new_from_xpm_d_at_size(blue_xpm, 16, 16); 
gtk_container_add(GTK_CONTAINER(event_box), pic);

item = gnome_canvas_item_new(root, 
                                gnome_canvas_widget_get_type(),
                                "widget", event_box,
                                "x", 2.0 + CASE_SIZE * (teams[0]->players->pos % X_SIZE),
                                "y", 2.0 + CASE_SIZE * (teams[0]->players->pos / X_SIZE),
                                "width", 16.0,
                                "height", 16.0,
                                "anchor", GTK_ANCHOR_NW,
                                "size_pixels", TRUE,
                                NULL);

gtk_signal_connect(GTK_OBJECT(item), "event", GTK_SIGNAL_FUNC(c_press_cb),
                        NULL);
gtk_widget_show(pic);
gtk_widget_show(event_box);

/* And the callback is just a test ATM : */

static void c_press_cb(GtkWidget *widget, GdkEvent *event)
{
        switch (event->type) {
                case GDK_BUTTON_PRESS :
                        printf("Button press\n");
                        break;
                case GDK_BUTTON_RELEASE :
                        printf("Button release\n");
                        break;
                case GDK_MOTION_NOTIFY :
                        printf("Motion notify\n");
                        break;
        }
}

Result of this test :
MOTION_NOTIFY is caught anytime.
BUTTON_PRESS is NEVER caught. 
BUTTON_RELEASE is only caught when the button is released outside the
pixmap.

Why ?!

It seems that the eventbox catches the missing events instead of the canvas
widget item. I don't understand why, since I didn't call
gtk_widget_set_events on it. What should I add to this code to prevent this
?

Thanks,

--
David




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