Canvas widget problem (example included)



Federico Mena Quintero wrote:
> 
> [gnome-gui-list is not the best place for this.  You should ask on
> gnome-list or gnome-devel-list.]
> 
> >   Here's the gist of it. I do a gnome_canvas_item_grab with
> >  GDK_POINTER_MOTION_MASK in the second arg. I would expect all motion
> >  events to go to my canvas item until I do an ungrab, that isn't
> >  what happens. I ONLY get motion events while I'm over the canvas
> >  item, just as if I hadn't done a grab at all.
> 
> This is weird.  Could you please provide a small test program that
> exhibits this behavior?
> 
> Also, what is the return value of gnome_canvas_item_grab() when you
> initially call it?
> 
>   Federico
> 
> --
>         FAQ: Frequently-Asked Questions at http://www.gnome.org/gnomefaq
>          To unsubscribe: mail gnome-gui-list-request@gnome.org with
>                        "unsubscribe" as the Subject.

Federico,
   I've made a simple rectangle example of this problem. Compile the
test.c and run it. Click the square and it will do a grab. It then
registers an additional callback to receive the motion events. Notice
that
only motion events inside the box get received (there is a prinf to show
you). Also, it should be obvious that a grab did occur since you can't
do anything else inside X. Click the box again to ungrab.
  Everyting seems to work, I just expected that since I did a grab, ALL
motion events should be sent no matter where they occur.

(test.c and simple Makefile included)

 Thanks in advance,
  -SOTTEK
#include <gnome.h>
#include <X11/X.h>

void motion_event(GtkWidget *widget, GdkEvent *event, gpointer data) {
  GdkEventMotion *m_event = (GdkEventMotion *)event;
  printf("Motion at %2.2f %2.2f\n",m_event->x,m_event->y);
}

void click_event(GtkWidget *widget, GdkEvent *event, gpointer data) {
  GnomeCanvasItem *item = GNOME_CANVAS_ITEM(widget);

  if((event->type == GDK_BUTTON_PRESS)&&(event->button.button == 1)) {
    if(gnome_canvas_item_grab(item, 
			      GDK_POINTER_MOTION_MASK|GDK_BUTTON_PRESS_MASK,
			      NULL,GDK_CURRENT_TIME) ==
       AlreadyGrabbed ) {
      printf("UNGRAB\n");
      gnome_canvas_item_ungrab(item,GDK_CURRENT_TIME);
      gtk_signal_disconnect_by_func(GTK_OBJECT(item),
				    GTK_SIGNAL_FUNC(motion_event),NULL);
    }
    else {
      printf("GRAB\n");
      gtk_signal_connect_after(GTK_OBJECT(item),"event",
			       GTK_SIGNAL_FUNC(motion_event),NULL);

    }
  } 
}

int main (int argc, char *argv[]) {
  GtkWidget * toplevel;
  GnomeCanvas *canvas;
  GnomeCanvasItem *item;
  
  gnome_init("test", "1.0", argc, argv);

  toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_signal_connect (GTK_OBJECT(toplevel), "delete_event",
		      GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

  //Make canvas
  gtk_widget_push_visual(gdk_imlib_get_visual());
  gtk_widget_push_colormap(gdk_imlib_get_colormap());
  canvas = GNOME_CANVAS(gnome_canvas_new());	
  gtk_widget_pop_colormap();
  gtk_widget_pop_visual();

  gtk_container_add(GTK_CONTAINER(toplevel),GTK_WIDGET(canvas));
 
  gnome_canvas_set_pixels_per_unit(canvas,1);
  gnome_canvas_set_scroll_region(canvas,0.0,0.0,100.0,100.0);
  gtk_widget_set_usize(GTK_WIDGET(canvas), 100, 100);

  gtk_widget_show(toplevel);
  gtk_widget_show(GTK_WIDGET(canvas));

  item = gnome_canvas_item_new(gnome_canvas_root(canvas),
                               GNOME_TYPE_CANVAS_RECT,
                               "x1", 10.0,
                               "y1", 10.0,
                               "x2", 90.0,
                               "y2", 90.0,
                               "fill_color", "black",
                               NULL);

 
  gtk_signal_connect(GTK_OBJECT(item),"event",
		     GTK_SIGNAL_FUNC(click_event),
		     NULL);
  gtk_main();
  return 0;
}


CFLAGS=-g -Wall `gnome-config --cflags gnome gnomeui`
LDFLAGS=`gnome-config --libs gnome gnomeui`

all: test

test: test.c


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