Commit 2a44e74e authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

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.
parent d3f37b04
......@@ -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);
}
......
......@@ -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);
......
......@@ -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));
}
......
......@@ -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);
......
......@@ -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,
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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:"),
......
......@@ -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));
}
......
......@@ -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);
}
......
......@@ -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);
}
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment