From 0a963192af67150d29a5749d52b1fcf279efb7f3 Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" Date: Wed, 27 May 2009 20:36:06 +0000 Subject: Adds gtk_util::ParentWindow to find the parent window of a GtkWidget. BUG=none TEST=none Review URL: http://codereview.chromium.org/113919 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17019 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/gtk_util.cc | 9 +++++++++ chrome/common/gtk_util.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index 01d952e..1deb58f 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -122,4 +122,13 @@ void InitRCStyles() { gtk_rc_parse_string(kRCText); } +GtkWindow* ParentWindow(GtkWidget* widget) { + while (widget) { + if (GTK_IS_WINDOW(widget)) + return GTK_WINDOW(widget); + widget = gtk_widget_get_parent(widget); + } + return NULL; +} + } // namespace gtk_util diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h index d72045b..5770030 100644 --- a/chrome/common/gtk_util.h +++ b/chrome/common/gtk_util.h @@ -44,6 +44,10 @@ gfx::Rect GetWidgetScreenBounds(GtkWidget* widget); // Initialize some GTK settings so that our dialogs are consistent. void InitRCStyles(); +// Returns the closest ancestor of |widget| which is a top level window or NULL +// if there is no such ancestor. The search starts at |widget|. +GtkWindow* ParentWindow(GtkWidget* widget); + } // namespace gtk_util #endif // CHROME_COMMON_GTK_UTIL_H_ -- cgit v1.1