diff options
author | Owen Taylor <otaylor@redhat.com> | 2002-06-06 15:38:39 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2002-06-06 15:38:39 +0000 |
commit | c0f78ae00e839052a66ded3792888e7240821323 (patch) | |
tree | 27271721705d79ba16dd8d97d7cc597ac5e970c5 /gtk/gtkwindow.c | |
parent | 3f6c03182b2f507ae263fc13736bb5f8110ca08a (diff) | |
download | gtk+-c0f78ae00e839052a66ded3792888e7240821323.tar.gz |
Add a "is_focus" property indicating whether a widget is the focus widget
Fri May 17 17:27:21 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c gtk/gtkwidget.c: Add a "is_focus"
property indicating whether a widget is the focus
widget within the toplevel.
* gtk/gtkwindow.[ch]: Add "is_active" "has_toplevel_focus"
properties to indicate (separately) the idea of
being the part of the toplevel with the input focus
and being the active widget. (Needed for full XEMBED
compliance.)
* gtk/gtkplug.c gtk/gtksocket.c: Update to work
in terms of is_active/has_toplevel_focus, and thus
handle the active/focused XEMBED distinction
correctly.
* gtk/gtkplug.c (gtk_plug_realize): Remove
FOCUS_CHANGE_MASK, since we don't need it.
Fri May 17 18:07:34 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtksocket.c (gtk_socket_add_window): Send
XEMBED_EMBEDDED_NOTIFY.
* gtk/gtksocket.c: Assume windows without _XEMBED_INFO
property want to be mapped, for better
current-Qt compatibility.
Diffstat (limited to 'gtk/gtkwindow.c')
-rw-r--r-- | gtk/gtkwindow.c | 126 |
1 files changed, 113 insertions, 13 deletions
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 78822c462b..70ff43b46c 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -70,6 +70,10 @@ enum { PROP_DESTROY_WITH_PARENT, PROP_ICON, PROP_SCREEN, + + /* Readonly properties */ + PROP_IS_ACTIVE, + PROP_HAS_TOPLEVEL_FOCUS, LAST_ARG }; @@ -504,6 +508,22 @@ gtk_window_class_init (GtkWindowClass *klass) GDK_TYPE_SCREEN, G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, + PROP_IS_ACTIVE, + g_param_spec_boolean ("is_active", + _("Is Active"), + _("Whether the toplevel is the current active window"), + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property (gobject_class, + PROP_HAS_TOPLEVEL_FOCUS, + g_param_spec_boolean ("has_toplevel_focus", + _("Focus in Toplevel"), + _("Whether the input focus is within this GtkWindow"), + FALSE, + G_PARAM_READABLE)); + window_signals[SET_FOCUS] = g_signal_new ("set_focus", G_TYPE_FROM_CLASS (object_class), @@ -770,6 +790,12 @@ gtk_window_get_property (GObject *object, case PROP_SCREEN: g_value_set_object (value, window->screen); break; + case PROP_IS_ACTIVE: + g_value_set_boolean (value, window->is_active); + break; + case PROP_HAS_TOPLEVEL_FOCUS: + g_value_set_boolean (value, window->has_toplevel_focus); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -3772,14 +3798,10 @@ gtk_window_focus_in_event (GtkWidget *widget, */ if (GTK_WIDGET_VISIBLE (widget)) { - window->has_focus = TRUE; - - if (window->focus_widget && - window->focus_widget != widget && - !GTK_WIDGET_HAS_FOCUS (window->focus_widget)) - do_focus_change (window->focus_widget, TRUE); + _gtk_window_set_has_toplevel_focus (window, TRUE); + _gtk_window_set_is_active (window, TRUE); } - + return FALSE; } @@ -3789,12 +3811,8 @@ gtk_window_focus_out_event (GtkWidget *widget, { GtkWindow *window = GTK_WINDOW (widget); - window->has_focus = FALSE; - - if (window->focus_widget && - window->focus_widget != widget && - GTK_WIDGET_HAS_FOCUS (window->focus_widget)) - do_focus_change (window->focus_widget, FALSE); + _gtk_window_set_has_toplevel_focus (window, FALSE); + _gtk_window_set_is_active (window, FALSE); return FALSE; } @@ -3934,6 +3952,8 @@ gtk_window_real_set_focus (GtkWindow *window, if (window->has_focus) do_focus_change (window->focus_widget, FALSE); + + g_object_notify (G_OBJECT (window->focus_widget), "is_focus"); } window->focus_widget = focus; @@ -3952,6 +3972,8 @@ gtk_window_real_set_focus (GtkWindow *window, if (window->has_focus) do_focus_change (window->focus_widget, TRUE); + + g_object_notify (G_OBJECT (window->focus_widget), "is_focus"); } if (window->default_widget && @@ -6084,3 +6106,81 @@ _gtk_window_activate_key (GtkWindow *window, else return FALSE; } + +static void +window_update_has_focus (GtkWindow *window) +{ + GtkWidget *widget = GTK_WIDGET (window); + gboolean has_focus = window->has_toplevel_focus && window->is_active; + + if (has_focus != window->has_focus) + { + window->has_focus = has_focus; + + if (has_focus) + { + if (window->focus_widget && + window->focus_widget != widget && + !GTK_WIDGET_HAS_FOCUS (window->focus_widget)) + do_focus_change (window->focus_widget, TRUE); + } + else + { + if (window->focus_widget && + window->focus_widget != widget && + GTK_WIDGET_HAS_FOCUS (window->focus_widget)) + do_focus_change (window->focus_widget, FALSE); + } + } +} + +/** + * _gtk_window_set_is_active: + * @window: a #GtkWindow + * @is_active: %TRUE if the window is in the currently active toplevel + * + * Internal function that sets whether the #GtkWindow is part + * of the currently active toplevel window (taking into account inter-process + * embedding.) + **/ +void +_gtk_window_set_is_active (GtkWindow *window, + gboolean is_active) +{ + g_return_if_fail (GTK_IS_WINDOW (window)); + + is_active = is_active != FALSE; + + if (is_active != window->is_active) + { + window->is_active = is_active; + window_update_has_focus (window); + + g_object_notify (G_OBJECT (window), "is_active"); + } +} + +/** + * _gtk_window_set_has_toplevel_focus: + * @window: a #GtkWindow + * @has_toplevel_focus: %TRUE if the in + * + * Internal function that sets whether the keyboard focus for the + * toplevel window (taking into account inter-process embedding.) + **/ +void +_gtk_window_set_has_toplevel_focus (GtkWindow *window, + gboolean has_toplevel_focus) +{ + g_return_if_fail (GTK_IS_WINDOW (window)); + + has_toplevel_focus = has_toplevel_focus != FALSE; + + if (has_toplevel_focus != window->has_toplevel_focus) + { + window->has_toplevel_focus = has_toplevel_focus; + window_update_has_focus (window); + + g_object_notify (G_OBJECT (window), "has_toplevel_focus"); + } +} |