summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-11-17 01:18:49 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-11-17 01:18:49 +0000
commit61b2f259e546d5d4f3713c8c64ea7abe58fb47ac (patch)
tree3fc3d6a0af181909d59ea78352e9ad720f128821 /gtk
parentf2d5aec4cbef03e93d9bc1af3678ec30430bb763 (diff)
downloadgtk+-61b2f259e546d5d4f3713c8c64ea7abe58fb47ac.tar.gz
Move notification of "has_default" to here, so it is safe to call
Fri Nov 16 19:44:35 2001 Owen Taylor <otaylor@redhat.com> * gtk/gtkwindow.c (gtk_window_set_default): Move notification of "has_default" to here, so it is safe to call gtk_window_set_default() instead of gtk_widget_grab_default(). * gtk/gtkwindow.c (gtk_window_set_focus): Make it call gtk_widget_grab_focus(), which then calls _gtk_widget_internal_set_focus(). This makes gtk_window_set_focus() a safe way of both setting and unsetting the focus widget. * gtk/gtkwidget.c (gtk_widget_propagate_state): Use gtk_widget_get_toplevel(), instead of gtk_widget_ancestor to find the toplevel. * gtk/gtkwindow.h: Move gtk_window_set_focus/default from the "internal functions" section.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkwidget.c24
-rw-r--r--gtk/gtkwindow.c62
-rw-r--r--gtk/gtkwindow.h8
3 files changed, 59 insertions, 35 deletions
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index b8d4aab318..0e1cada291 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3345,12 +3345,12 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget)
if (widget == focus_widget)
{
- /* We call gtk_window_set_focus() here so that the
+ /* We call _gtk_window_internal_set_focus() here so that the
* toplevel window can request the focus if necessary.
* This is needed when the toplevel is a GtkPlug
*/
if (!GTK_WIDGET_HAS_FOCUS (widget))
- gtk_window_set_focus (GTK_WINDOW (toplevel), focus_widget);
+ _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
return;
}
@@ -3385,7 +3385,7 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget)
widget = widget->parent;
}
if (GTK_IS_WINDOW (widget))
- gtk_window_set_focus (GTK_WINDOW (widget), focus_widget);
+ _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
}
}
@@ -3455,22 +3455,14 @@ void
gtk_widget_grab_default (GtkWidget *widget)
{
GtkWidget *window;
- GtkType window_type;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
- window_type = GTK_TYPE_WINDOW;
- window = widget->parent;
+ window = gtk_widget_get_toplevel (widget);
- while (window && !gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
- window = window->parent;
-
- if (window && gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
- {
- gtk_window_set_default (GTK_WINDOW (window), widget);
- g_object_notify (G_OBJECT (widget), "has_default");
- }
+ if (window && GTK_WIDGET_TOPLEVEL (window))
+ gtk_window_set_default (GTK_WINDOW (window), widget);
else
g_warning (G_STRLOC ": widget not within a GtkWindow");
}
@@ -5775,8 +5767,8 @@ gtk_widget_propagate_state (GtkWidget *widget,
{
GtkWidget *window;
- window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
- if (window)
+ window = gtk_widget_get_toplevel (widget);
+ if (window && GTK_WIDGET_TOPLEVEL (window))
gtk_window_set_focus (GTK_WINDOW (window), NULL);
}
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 77c18503dd..a6153685c4 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -922,14 +922,14 @@ gtk_window_get_role (GtkWindow *window)
/**
* gtk_window_set_focus:
* @window: a #GtkWindow
- * @focus: widget to be the new focus widget
+ * @focus: widget to be the new focus widget, or %NULL to unset
+ * any focus widget for the toplevel window.
*
- * If @focus is not the current focus widget, and is focusable, emits
- * the "set_focus" signal to set @focus as the focus widget for the
- * window. This function is more or less GTK-internal; to focus an
- * entry widget or the like, you should use gtk_widget_grab_focus()
- * instead of this function.
- *
+ * If @focus is not the current focus widget, and is focusable, sets
+ * it as the focus widget for the window. If @focus is %NULL, unsets
+ * the focus widget for this window. To set the focus to a particular
+ * widget in the toplevel, it is usually more convenient to use
+ * gtk_widget_grab_focus() instead of this function.
**/
void
gtk_window_set_focus (GtkWindow *window,
@@ -942,6 +942,18 @@ gtk_window_set_focus (GtkWindow *window,
g_return_if_fail (GTK_WIDGET_CAN_FOCUS (focus));
}
+ if (focus)
+ gtk_widget_grab_focus (focus);
+ else
+ _gtk_window_internal_set_focus (window, NULL);
+}
+
+void
+_gtk_window_internal_set_focus (GtkWindow *window,
+ GtkWidget *focus)
+{
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
if ((window->focus_widget != focus) ||
(focus && !GTK_WIDGET_HAS_FOCUS (focus)))
gtk_signal_emit (GTK_OBJECT (window), window_signals[SET_FOCUS], focus);
@@ -950,30 +962,39 @@ gtk_window_set_focus (GtkWindow *window,
/**
* gtk_window_set_default:
* @window: a #GtkWindow
- * @default_widget: widget to be the default
+ * @default_widget: widget to be the default, or %NULL to unset the
+ * default widget for the toplevel.
*
* The default widget is the widget that's activated when the user
- * presses Enter in a dialog (for example). This function tells a
- * #GtkWindow about the current default widget; it's really a GTK
- * internal function and you shouldn't need it. Instead, to change the
- * default widget, first set the #GTK_CAN_DEFAULT flag on the widget
- * you'd like to make the default using GTK_WIDGET_SET_FLAGS(), then
- * call gtk_widget_grab_default() to move the default.
- *
+ * presses Enter in a dialog (for example). This function sets or
+ * unsets the default widget for a #GtkWindow about. When setting
+ * (rather than unsetting) the default widget it's generally easier to
+ * call gtk_widget_grab_focus() on the widget. Before making a widget
+ * the default widget, you must set the #GTK_CAN_DEFAULT flag on the
+ * widget you'd like to make the default using GTK_WIDGET_SET_FLAGS().
**/
void
gtk_window_set_default (GtkWindow *window,
GtkWidget *default_widget)
{
+ GtkWidget *old_default;
+
g_return_if_fail (GTK_IS_WINDOW (window));
if (default_widget)
g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (default_widget));
-
+
if (window->default_widget != default_widget)
{
+ GtkWidget *old_default_widget = NULL;
+
+ if (default_widget)
+ g_object_ref (default_widget);
+
if (window->default_widget)
{
+ old_default_widget = window->default_widget;
+
if (window->focus_widget != window->default_widget ||
!GTK_WIDGET_RECEIVES_DEFAULT (window->default_widget))
GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
@@ -989,6 +1010,15 @@ gtk_window_set_default (GtkWindow *window,
GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
gtk_widget_queue_draw (window->default_widget);
}
+
+ if (old_default_widget)
+ g_object_notify (G_OBJECT (old_default_widget), "has_default");
+
+ if (default_widget)
+ {
+ g_object_notify (G_OBJECT (default_widget), "has_default");
+ g_object_unref (default_widget);
+ }
}
}
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 8e62e60d03..3a6dd6de9e 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -166,7 +166,11 @@ void gtk_window_remove_accel_group (GtkWindow *window,
void gtk_window_set_position (GtkWindow *window,
GtkWindowPosition position);
gboolean gtk_window_activate_focus (GtkWindow *window);
+void gtk_window_set_focus (GtkWindow *window,
+ GtkWidget *focus);
GtkWidget *gtk_window_get_focus (GtkWindow *window);
+void gtk_window_set_default (GtkWindow *window,
+ GtkWidget *default_widget);
gboolean gtk_window_activate_default (GtkWindow *window);
void gtk_window_set_transient_for (GtkWindow *window,
@@ -305,10 +309,8 @@ void gtk_window_group_remove_window (GtkWindowGroup *window_grou
GtkWindow *window);
/* --- internal functions --- */
-void gtk_window_set_focus (GtkWindow *window,
+void _gtk_window_internal_set_focus (GtkWindow *window,
GtkWidget *focus);
-void gtk_window_set_default (GtkWindow *window,
- GtkWidget *defaultw);
void gtk_window_remove_embedded_xid (GtkWindow *window,
guint xid);
void gtk_window_add_embedded_xid (GtkWindow *window,