[gthumb] added utility too always check that the toplevel is a window
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] added utility too always check that the toplevel is a window
- Date: Sun, 24 Nov 2019 12:26:19 +0000 (UTC)
commit 2a44e74ea820258eb9521ce4b71666ae022d4e9e
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Nov 1 14:22:58 2019 +0100
added utility too always check that the toplevel is a window
Always use _gtk_widget_get_toplevel_if_window instead
of gtk_widget_get_toplevel.
extensions/edit_metadata/gth-edit-general-page.c | 10 ++++----
extensions/image_viewer/gth-image-histogram.c | 4 +--
extensions/oauth/oauth-ask-authorization-dialog.c | 10 ++++----
extensions/search/gth-search-editor.c | 10 ++++----
extensions/slideshow/gth-slideshow-preferences.c | 2 +-
gthumb/gth-accel-button.c | 2 +-
gthumb/gth-file-tool.c | 7 ++---
gthumb/gth-folder-tree.c | 7 +----
gthumb/gth-progress-dialog.c | 6 ++---
gthumb/gth-source-tree.c | 2 +-
gthumb/gtk-utils.c | 31 +++++++++++++++--------
gthumb/gtk-utils.h | 1 +
12 files changed, 47 insertions(+), 45 deletions(-)
---
diff --git a/extensions/edit_metadata/gth-edit-general-page.c
b/extensions/edit_metadata/gth-edit-general-page.c
index e472849f..5009b10a 100644
--- a/extensions/edit_metadata/gth-edit-general-page.c
+++ b/extensions/edit_metadata/gth-edit-general-page.c
@@ -523,17 +523,17 @@ static void
tags_entry_list_collapsed_cb (GthTagsEntry *widget,
gpointer user_data)
{
- GtkWidget *toplevel;
+ GtkWindow *toplevel;
int width;
/* collapse the dialog height */
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (widget));
- if (! gtk_widget_is_toplevel (toplevel))
+ toplevel = _gtk_widget_get_toplevel_if_window (GTK_WIDGET (widget));
+ if (toplevel == NULL)
return;
- gtk_window_get_size (GTK_WINDOW (toplevel), &width, NULL);
- gtk_window_resize (GTK_WINDOW (toplevel), width, 1);
+ gtk_window_get_size (toplevel, &width, NULL);
+ gtk_window_resize (toplevel, width, 1);
}
diff --git a/extensions/image_viewer/gth-image-histogram.c b/extensions/image_viewer/gth-image-histogram.c
index ffa99c7f..08497512 100644
--- a/extensions/image_viewer/gth-image-histogram.c
+++ b/extensions/image_viewer/gth-image-histogram.c
@@ -54,8 +54,8 @@ gth_image_histogram_get_current_image (GthImageHistogram *self)
GthBrowser *browser;
GthViewerPage *viewer_page;
- browser = (GthBrowser *) gtk_widget_get_toplevel (GTK_WIDGET (self));
- if (! gtk_widget_is_toplevel (GTK_WIDGET (browser)))
+ browser = (GthBrowser *) _gtk_widget_get_toplevel_if_window (GTK_WIDGET (self));
+ if (browser == NULL)
return NULL;
viewer_page = gth_browser_get_viewer_page (browser);
diff --git a/extensions/oauth/oauth-ask-authorization-dialog.c
b/extensions/oauth/oauth-ask-authorization-dialog.c
index 3d802ded..7bb56b18 100644
--- a/extensions/oauth/oauth-ask-authorization-dialog.c
+++ b/extensions/oauth/oauth-ask-authorization-dialog.c
@@ -146,19 +146,19 @@ static void
webkit_view_ready_to_show_cb (WebKitWebView *web_view,
gpointer user_data)
{
- GtkWidget *window;
+ GtkWindow *window;
WebKitWindowProperties *prop;
GdkRectangle geometry;
- window = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
- if (! gtk_widget_is_toplevel (window))
+ window = _gtk_widget_get_toplevel_if_window (GTK_WIDGET (web_view));
+ if (window == NULL)
return;
prop = webkit_web_view_get_window_properties (web_view);
webkit_window_properties_get_geometry (prop, &geometry);
- gtk_window_set_default_size (GTK_WINDOW (window), geometry.width, geometry.height);
- gtk_widget_show_all (window);
+ gtk_window_set_default_size (window, geometry.width, geometry.height);
+ gtk_widget_show_all (GTK_WIDGET (window));
}
diff --git a/extensions/search/gth-search-editor.c b/extensions/search/gth-search-editor.c
index 0fdc8bd0..8dc7f099 100644
--- a/extensions/search/gth-search-editor.c
+++ b/extensions/search/gth-search-editor.c
@@ -227,14 +227,14 @@ _gth_search_editor_add_source (GthSearchEditor *self,
int pos)
{
GthSearchSource *source;
- GtkWidget *window;
+ GtkWindow *window;
GtkWidget *source_selector;
source = NULL;
- window = gtk_widget_get_toplevel (GTK_WIDGET (self));
- if (GTK_IS_WINDOW (window))
- window = (GtkWidget *) gtk_window_get_transient_for (GTK_WINDOW (window));
- if (GTK_IS_WINDOW (window) && GTH_IS_BROWSER (window)) {
+ window = _gtk_widget_get_toplevel_if_window (GTK_WIDGET (self));
+ if (window != NULL)
+ window = gtk_window_get_transient_for (window);
+ if ((window != NULL) && GTH_IS_BROWSER (window)) {
source = gth_search_source_new ();
gth_search_source_set_folder (source, gth_browser_get_location (GTH_BROWSER (window)));
gth_search_source_set_recursive (source, TRUE);
diff --git a/extensions/slideshow/gth-slideshow-preferences.c
b/extensions/slideshow/gth-slideshow-preferences.c
index 7357af91..27cdef37 100644
--- a/extensions/slideshow/gth-slideshow-preferences.c
+++ b/extensions/slideshow/gth-slideshow-preferences.c
@@ -183,7 +183,7 @@ add_file_button_clicked_cb (GtkButton *button,
GtkFileFilter *filter;
dialog = gtk_file_chooser_dialog_new (_("Choose the files to play"),
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))),
+ _gtk_widget_get_toplevel_if_window (GTK_WIDGET (self)),
GTK_FILE_CHOOSER_ACTION_OPEN,
_GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
_GTK_LABEL_OK, GTK_RESPONSE_OK,
diff --git a/gthumb/gth-accel-button.c b/gthumb/gth-accel-button.c
index 0610ce53..53b0f480 100644
--- a/gthumb/gth-accel-button.c
+++ b/gthumb/gth-accel-button.c
@@ -224,7 +224,7 @@ button_clicked_cb (GtkButton *button,
dialog = g_object_new (GTK_TYPE_DIALOG,
"use-header-bar", _gtk_settings_get_dialogs_use_header (),
"modal", TRUE,
- "transient-for", gtk_widget_get_toplevel (GTK_WIDGET (button)),
+ "transient-for", _gtk_widget_get_toplevel_if_window (GTK_WIDGET (button)),
"resizable", FALSE,
"title", _("Shortcut"),
NULL);
diff --git a/gthumb/gth-file-tool.c b/gthumb/gth-file-tool.c
index a3ca886b..79be0ee2 100644
--- a/gthumb/gth-file-tool.c
+++ b/gthumb/gth-file-tool.c
@@ -193,11 +193,8 @@ gth_file_tool_construct (GthFileTool *self,
GtkWidget *
gth_file_tool_get_window (GthFileTool *self)
{
- if (self->priv->window == NULL) {
- self->priv->window = gtk_widget_get_toplevel (GTK_WIDGET (self));
- if (! gtk_widget_is_toplevel (self->priv->window))
- self->priv->window = NULL;
- }
+ if (self->priv->window == NULL)
+ self->priv->window = GTK_WIDGET (_gtk_widget_get_toplevel_if_window (GTK_WIDGET (self)));
return self->priv->window;
}
diff --git a/gthumb/gth-folder-tree.c b/gthumb/gth-folder-tree.c
index 13508991..703a7a2a 100644
--- a/gthumb/gth-folder-tree.c
+++ b/gthumb/gth-folder-tree.c
@@ -1894,7 +1894,6 @@ gth_folder_tree_start_editing (GthFolderTree *folder_tree,
GtkTreeIter iter;
GthFileData *file_data;
RenameData *data;
- GtkWidget *toplevel;
GtkWidget *dialog;
const char *edit_name;
@@ -1905,11 +1904,7 @@ gth_folder_tree_start_editing (GthFolderTree *folder_tree,
data->folder_tree = g_object_ref (folder_tree);
data->file = g_object_ref (file);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (folder_tree));
- if (! gtk_widget_is_toplevel (toplevel))
- toplevel = NULL;
-
- dialog = gth_request_dialog_new (GTK_WINDOW (toplevel),
+ dialog = gth_request_dialog_new (_gtk_widget_get_toplevel_if_window (GTK_WIDGET (folder_tree)),
GTK_DIALOG_MODAL,
_("Rename"),
_("Enter the new name:"),
diff --git a/gthumb/gth-progress-dialog.c b/gthumb/gth-progress-dialog.c
index 7a9655c4..2a059da1 100644
--- a/gthumb/gth-progress-dialog.c
+++ b/gthumb/gth-progress-dialog.c
@@ -215,18 +215,18 @@ task_completed_cb (GthTask *task,
gpointer user_data)
{
GthTaskProgress *self = user_data;
- GtkWidget *toplevel;
+ GtkWindow *toplevel;
if (self->pulse_event != 0) {
g_source_remove (self->pulse_event);
self->pulse_event = 0;
}
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
+ toplevel = _gtk_widget_get_toplevel_if_window (GTK_WIDGET (self));
gtk_widget_destroy (GTK_WIDGET (self));
- if (gtk_widget_is_toplevel (toplevel) && GTH_IS_PROGRESS_DIALOG (toplevel))
+ if ((toplevel != NULL) && GTH_IS_PROGRESS_DIALOG (toplevel))
gth_progress_dialog_child_removed (GTH_PROGRESS_DIALOG (toplevel));
}
diff --git a/gthumb/gth-source-tree.c b/gthumb/gth-source-tree.c
index 3cb48c4c..618f19e4 100644
--- a/gthumb/gth-source-tree.c
+++ b/gthumb/gth-source-tree.c
@@ -182,7 +182,7 @@ file_source_rename_ready_cb (GObject *object,
GthSourceTree *source_tree = user_data;
if (error != NULL)
- _gtk_error_dialog_from_gerror_show (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET
(source_tree))), _("Could not change name"), error);
+ _gtk_error_dialog_from_gerror_show (_gtk_widget_get_toplevel_if_window (GTK_WIDGET
(source_tree)), _("Could not change name"), error);
}
diff --git a/gthumb/gtk-utils.c b/gthumb/gtk-utils.c
index 28897fcf..92356d78 100644
--- a/gthumb/gtk-utils.c
+++ b/gthumb/gtk-utils.c
@@ -251,13 +251,13 @@ _gtk_info_dialog_run (GtkWindow *parent,
void
_gtk_dialog_add_to_window_group (GtkDialog *dialog)
{
- GtkWidget *toplevel;
+ GtkWindow *toplevel;
g_return_if_fail (dialog != NULL);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (dialog));
- if (gtk_widget_is_toplevel (toplevel) && gtk_window_has_group (GTK_WINDOW (toplevel)))
- gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), GTK_WINDOW
(dialog));
+ toplevel = _gtk_widget_get_toplevel_if_window (GTK_WIDGET (dialog));
+ if ((toplevel != NULL) && gtk_window_has_group (toplevel))
+ gtk_window_group_add_window (gtk_window_get_group (toplevel), GTK_WINDOW (dialog));
}
@@ -1226,14 +1226,11 @@ _gtk_widget_get_monitor_geometry (GtkWidget *widget,
GdkRectangle *geometry)
{
gboolean result = FALSE;
- GtkWidget *window;
+ GtkWindow *window;
- window = gtk_widget_get_toplevel (widget);
- if (GTK_IS_WINDOW (window)) {
- if (_gtk_window_get_monitor_info (GTK_WINDOW (window), geometry, NULL, NULL)) {
- result = TRUE;
- }
- }
+ window = _gtk_widget_get_toplevel_if_window (widget);
+ if ((window != NULL) && (_gtk_window_get_monitor_info (window, geometry, NULL, NULL)))
+ result = TRUE;
return result;
}
@@ -1307,3 +1304,15 @@ _gtk_widget_reparent (GtkWidget *widget,
g_object_unref (widget);
}
+
+GtkWindow *
+_gtk_widget_get_toplevel_if_window (GtkWidget *widget)
+{
+ GtkWidget *window;
+
+ window = gtk_widget_get_toplevel (widget);
+ if (! GTK_IS_WINDOW (window))
+ return NULL;
+
+ return GTK_WINDOW (window);
+}
diff --git a/gthumb/gtk-utils.h b/gthumb/gtk-utils.h
index 3897a5cf..71fd2668 100644
--- a/gthumb/gtk-utils.h
+++ b/gthumb/gtk-utils.h
@@ -166,6 +166,7 @@ GdkCursor * _gdk_cursor_new_for_widget (GtkWidget
GdkCursorType cursor_type);
void _gtk_widget_reparent (GtkWidget *widget,
GtkWidget *new_parent);
+GtkWindow * _gtk_widget_get_toplevel_if_window (GtkWidget *widget);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]