Re: Focus on vbox contained widget
- From: Christian Neumair <chris gnome-de org>
- To: razvan gavril gmail com
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Focus on vbox contained widget
- Date: Sun, 18 Sep 2005 12:35:45 +0200
Am Sonntag, den 18.09.2005, 03:07 +0300 schrieb Razvan Gavril:
Hi,
I have a GtkVBox that contains all kind of widgets. Is there a way to be
notified when one of the contained widgets grabs the focus or when the user
clicks on any of the those widget ?
You can either register an event handler for the whole widget's window
if it is mapped like:
g_signal_connect_after (my_child, "map-event", G_CALLBACK
(mapped_child), NULL);
which looks like:
static gboolean
mapped_child (GtkWidget *child,
GdkEvent *event)
{
gdk_window_add_filter (child->window, my_filter_func, child);
}
which in turn contains:
static GdkFilterReturn
my_filter_func (GdkXEvent *event,
GdkEvent *event,
GdkWidget *child)
{
GdkFilterReturn ret = GDK_FILTER_REMOVE;
switch (event->type)
{
case GDK_BUTTON_PRESS_MASK:
/* foo */;
case GDK_ENTER_NOTIFY_MASK:
/* bar */;
default:
ret = GDK_FILTER_CONTINUE;
}
return ret;
}
This is extremely flexible, but you usually don't have to dig that deep
into GDK, at least not if you want notification for some very basic
events.
I'd rather suggest you to do sth. straightforward:
g_signal_connect (vbox, "add", G_CALLBACK (child_added), NULL);
g_signal_connect (vbox, "remove", G_CALLBACK (child_removed), NULL);
static void
child_added (GtkContainer *vbox,
GtkWidget *child)
{
g_signal_connect (child, "focus-in-event", G_CALLBACK
(my_focus_in_handler), vbox);
g_signal_connect (child, "button-press-event", G_CALLBACK
(my_button_press_handler), vbox);
}
static void
child_removed (GtkContainer *vbox,
GtkWidget *child)
{
g_signal_disconnect_by_func (child, my_focus_in_handler, vbox);
g_signal_disconnect_by_func (child, my_button_press_handler, vbox);
}
--
Christian Neumair <chris gnome-de org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]