Re: Gtk# Mouse fuera de un widget.



On Thu, 2006-04-27 at 20:50 +0200, Claudio Saavedra wrote:
> 
> No sé si entendí correctamente tu idea, pero creo que las señales de
> GtkWidget "enter-notify-event" y "leave-notify-event" son lo que buscas.
> 
> http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidget-enter-notify-event
> http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidget-leave-notify-event
> 

Compilar con

  $ gcc -o lala lala.c `pkg-config --cflags --libs gtk+-2.0`

Claudio

-- 
Claudio Saavedra <csaavedr wh8 tu-dresden de>
#include <gtk/gtk.h>

void
on_button_clicked (GtkButton *button,
		   gpointer data)
{
	GtkLabel *label = GTK_LABEL (data);
	const gchar* text = gtk_label_get_text (label);
	gint i;
	gint t_size = g_utf8_strlen (text, -1);

	gchar* inverted_text = g_new0 (gchar, t_size);

	for (i = 0; i < t_size; i++) {
		inverted_text[i] = text [t_size - i - 1];
	}
	
	gtk_label_set_text (label, inverted_text);

	g_free (inverted_text);
       
}

gboolean
on_enter_notify_event (GtkWidget        *widget,
		       GdkEventCrossing *event,
		       gpointer          user_data)  
{
	GtkWidget *button = GTK_WIDGET (user_data);
	gtk_widget_hide (button);

	return FALSE;
}

gboolean
on_leave_notify_event (GtkWidget        *widget,
		       GdkEventCrossing *event,
		       gpointer          user_data)  
{
	GtkWidget *button = GTK_WIDGET (user_data);
	gtk_widget_show (button);

	return FALSE;
}

GtkWidget *
construct_window (void)
{
	GtkWidget *window;
	GtkWidget *vbox;
	GtkWidget *button;
	GtkWidget *label;
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window),
			      "Mi primer ejemplo de GTK+");
	
	vbox = gtk_vbox_new (TRUE, 0);
	
	button = gtk_button_new_with_label ("Invierte texto");
	
	label = gtk_label_new ("Anita lava la tina");

	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

	gtk_container_add (GTK_CONTAINER (window), vbox);

	g_signal_connect (G_OBJECT (button), 
			  "clicked",
			  G_CALLBACK (on_button_clicked),
			  label);

	g_signal_connect (G_OBJECT (window), 
			  "enter-notify-event",
			  G_CALLBACK (on_enter_notify_event),
			  button);
	g_signal_connect (G_OBJECT (window), 
			  "leave-notify-event",
			  G_CALLBACK (on_leave_notify_event),
			  button);
	return window;
	
}

int
main (gint argc, gchar **argv)
{
	gtk_init (&argc, &argv);
	GtkWidget *window = construct_window ();

	gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
	gtk_widget_show_all (window);
	g_signal_connect (G_OBJECT (window), "delete-event", 
			  gtk_main_quit, NULL);

	gtk_main ();
}


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