From 069a593b0fc73cffe2015558a0c8160c92c61465 Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Thu, 30 Jul 2009 14:17:00 +0200 Subject: [PATCH] =?UTF-8?q?Bug=20539377=20=E2=80=93=20Unnecessary=20warnin?= =?UTF-8?q?gs=20when=20GtkTreeView=20is=20not=20realized?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adapt gtk_tree_view_get_path_at_pos() and gtk_tree_view_get_drag_dest_row() to just return FALSE when bin_window is NULL and not hit a warning. Makes this case consistent with the tree view not having a model. Documentation has been updated to clarify this, unit test has been added. Fixes bug 539377, based on a patch by Bjorn Lindqvist. --- gtk/gtktreeview.c | 19 +++++++++++++------ gtk/tests/treeview.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index b7a0a7e283..2cd794b01d 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -12642,7 +12642,8 @@ gtk_tree_view_get_bin_window (GtkTreeView *tree_view) * with the column at that point. @cell_x and @cell_y return the coordinates * relative to the cell background (i.e. the @background_area passed to * gtk_cell_renderer_render()). This function is only meaningful if - * @tree_view is realized. + * @tree_view is realized. Therefore this function will always return %FALSE + * if @tree_view is not realized or does not have a model. * * For converting widget coordinates (eg. the ones you get from * GtkWidget::query-tooltip), please see @@ -12664,13 +12665,15 @@ gtk_tree_view_get_path_at_pos (GtkTreeView *tree_view, gint y_offset; g_return_val_if_fail (tree_view != NULL, FALSE); - g_return_val_if_fail (tree_view->priv->bin_window != NULL, FALSE); if (path) *path = NULL; if (column) *column = NULL; + if (tree_view->priv->bin_window == NULL) + return FALSE; + if (tree_view->priv->tree == NULL) return FALSE; @@ -13493,9 +13496,12 @@ gtk_tree_view_get_drag_dest_row (GtkTreeView *tree_view, * @pos: Return location for the drop position, or %NULL * * Determines the destination row for a given position. @drag_x and - * @drag_y are expected to be in widget coordinates. + * @drag_y are expected to be in widget coordinates. This function is only + * meaningful if @tree_view is realized. Therefore this function will always + * return %FALSE if @tree_view is not realized or does not have a model. * - * Return value: whether there is a row at the given position. + * Return value: whether there is a row at the given position, %TRUE if this + * is indeed the case. **/ gboolean gtk_tree_view_get_dest_row_at_pos (GtkTreeView *tree_view, @@ -13519,12 +13525,13 @@ gtk_tree_view_get_dest_row_at_pos (GtkTreeView *tree_view, g_return_val_if_fail (tree_view != NULL, FALSE); g_return_val_if_fail (drag_x >= 0, FALSE); g_return_val_if_fail (drag_y >= 0, FALSE); - g_return_val_if_fail (tree_view->priv->bin_window != NULL, FALSE); - if (path) *path = NULL; + if (tree_view->priv->bin_window == NULL) + return FALSE; + if (tree_view->priv->tree == NULL) return FALSE; diff --git a/gtk/tests/treeview.c b/gtk/tests/treeview.c index c64d7ba72d..14020084e9 100644 --- a/gtk/tests/treeview.c +++ b/gtk/tests/treeview.c @@ -69,6 +69,33 @@ test_bug_546005 (void) gtk_tree_path_free (path); } +static void +test_bug_539377 (void) +{ + GtkWidget *view; + GtkTreePath *path; + GtkListStore *list_store; + + /* Test provided by Bjorn Lindqvist */ + + /* Non-realized view, no model */ + view = gtk_tree_view_new (); + g_assert (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view), 10, 10, &path, + NULL, NULL, NULL) == FALSE); + g_assert (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (view), 10, 10, + &path, NULL) == FALSE); + + /* Non-realized view, with model */ + list_store = gtk_list_store_new (1, G_TYPE_STRING); + gtk_tree_view_set_model (GTK_TREE_VIEW (view), + GTK_TREE_MODEL (list_store)); + + g_assert (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view), 10, 10, &path, + NULL, NULL, NULL) == FALSE); + g_assert (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (view), 10, 10, + &path, NULL) == FALSE); +} + int main (int argc, char **argv) @@ -76,6 +103,7 @@ main (int argc, gtk_test_init (&argc, &argv, NULL); g_test_add_func ("/TreeView/cursor/bug-546005", test_bug_546005); + g_test_add_func ("/TreeView/cursor/bug-539377", test_bug_539377); return g_test_run (); }