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

Re: Wanna catch a motion event



On Sat, 05 Feb 2000 21:37:43 +0100, Andreas Sliwka wrote:
>   Id like to let the user pick out on of 18 specified rectangels in a pixmap.
> So I display a window, put a GtkPixmap in it and connect a callback to the
> motion_notify_event. But that did not work. So I created a event box, put the 
> pixmap in it and connected the eventobox to the event. Now it works. As long 
> as I press a mouse button. How can I accomplish it that my callback gets 
> called even if no mouse button is pressed ?
> 
>   please have a look at the code snippet and show me where I´m wrong.
> 
> ------------------- Code --------------------
>     eventbox=gtk_event_box_new();
>     small_bricks=gdk_pixmap_create_from_xpm (window->window, NULL,
>                                              &style->bg[GTK_STATE_NORMAL],
>                                              "small_bricks.xpm");
>     small_bricks_widget=gtk_pixmap_new(small_bricks,NULL);
>     gtk_container_add(GTK_CONTAINER(window),eventbox);

Add this line somewhere around here:

  gtk_widget_show(eventbox);

>     gtk_container_add(GTK_CONTAINER(eventbox),small_bricks_widget);
>     gtk_widget_show(small_bricks_widget);
>     gtk_signal_connect(GTK_OBJECT(eventbox),"motion_notify_event",
>     GTK_SIGNAL_FUNC(small_bricks_motion ),NULL);
>     g_print("before\n");
>     gtk_widget_set_events (eventbox, GDK_POINTER_MOTION_MASK
>                                    | GDK_POINTER_MOTION_HINT_MASK);
>     g_print("after\n");
> ------------------- Code --------------------
> produces the following output:
>   before
> 
>   Gtk-CRITICAL **: file gtkwidget.c: line 3827 (gtk_widget_set_events):
> assertion `!GTK_WIDGET_REALIZED (widget)' failed.
>   after
> 
> What did I do wrong ?

You forgot to show the eventbox. Although the eventbox itself is
invisible, it still needs to be shown (so it will be realized). Chances
are that you also get the motion events in the way you like.


Erik

-- 
There is a style of design I call "wishful thinking engineering. It starts
with something like "pigs can fly if you feed them enough beans" and develops
utopian plans such as like having everyone commute to work riding on personal
pigs, and along the way ignores minor details such as the consequent rain of
the non-gaseous byproducts. -- Vernon Schryver in n.a.n-a.e





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