Re: How to use and process GTK enter or leave signals?



On Fri, Dec 18, 2009 at 05:25:57AM -0800, Ken Resander wrote:
> Just for testing I used a GtkButton and substituted signal enter-notify-event for signal clicked (clicked works).  A warning appears: "enter-notify-event is invalid for instance" after g_signal_connect is executed. The callback handler is not called.
> Simplified:
> 
> [code]
> GtkWidget * b = gtk_new_button ();
> ....
> g_signal_connect (b, "enter-notify-event",
>                   G_CALLBACK (enterleave), myuserdata) ;
> ...
> [/code]
> 
> with callback handler
> 
> [code]
> static gboolean enterleave ( GtkWidget * w, 
>                              GdkEventCrossing * event,
>                              char * data )
>    {
>   printf ( "Now in enterleave callback\n" ) ;
>    ....
>    return false;
>    }
> [/code]
> 
> 
> I also tried:
> [code]
> gtk_widget_set_events ( b, _ENTER_NOTIFY_MASK );
> g_signal_connect (b , "enter-notify-event",
>                    G_CALLBACK (enterleave), myuserdata) ;
> [/code]
> 
> and also signal "enter" (deprecated), but result was same.
> 
> Cannot see what is wrong, so help would be most appreciated.

Your don't post compilable code.  gtk_new_button() does not exist.
gtk_widget_set_events() will likely break GtkButton, use
gtk_widget_add_events(). _ENTER_NOTIFY_MASK does not exist.  How can we
tell what else is wrong?

The events works for me.

Yeti


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

static gboolean
enter(GtkWidget *ebox,
      GdkEventCrossing *event)
{
    g_print("Gotcha!\n");
    return FALSE;
}

static gboolean
leave(GtkWidget *ebox,
      GdkEventCrossing *event)
{
    g_print("Oops!\n");
    return FALSE;
}

int
main(int argc, char *argv[])
{
    GtkWidget *window, *button;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    button = gtk_button_new_with_label("Don't Click Me");
    gtk_container_add(GTK_CONTAINER(window), button);
    g_signal_connect(button, "enter-notify-event", G_CALLBACK(enter), NULL);
    g_signal_connect(button, "leave-notify-event", G_CALLBACK(leave), NULL);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}



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