1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/* Basic GtkTreeView unit tests.
* Copyright (C) 2009 Kristian Rietveld <kris@gtk.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gtk/gtk.h>
static void
test_bug_546005 (void)
{
GtkTreeIter iter;
GtkTreePath *path;
GtkTreePath *cursor_path;
GtkListStore *list_store;
GtkWidget *view;
/* Tests provided by Bjorn Lindqvist, Paul Pogonyshev */
view = gtk_tree_view_new ();
/* Invalid path on tree view without model */
path = gtk_tree_path_new_from_indices (1, -1);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
NULL, FALSE);
gtk_tree_path_free (path);
list_store = gtk_list_store_new (1, G_TYPE_STRING);
gtk_tree_view_set_model (GTK_TREE_VIEW (view),
GTK_TREE_MODEL (list_store));
/* Invalid path on tree view with empty model */
path = gtk_tree_path_new_from_indices (1, -1);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
NULL, FALSE);
gtk_tree_path_free (path);
/* Valid path */
gtk_list_store_insert_with_values (list_store, &iter, 0,
0, "hi",
-1);
path = gtk_tree_path_new_from_indices (0, -1);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
NULL, FALSE);
gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &cursor_path, NULL);
//gtk_assert_cmptreepath (cursor_path, ==, path);
gtk_tree_path_free (path);
gtk_tree_path_free (cursor_path);
/* Invalid path on tree view with model */
path = gtk_tree_path_new_from_indices (1, -1);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
NULL, FALSE);
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);
}
static void
test_select_collapsed_row (void)
{
GtkTreeIter child, parent;
GtkTreePath *path;
GtkTreeStore *tree_store;
GtkTreeSelection *selection;
GtkWidget *view;
/* Reported by Michael Natterer */
tree_store = gtk_tree_store_new (1, G_TYPE_STRING);
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (tree_store));
gtk_tree_store_insert_with_values (tree_store, &parent, NULL, 0,
0, "Parent",
-1);
gtk_tree_store_insert_with_values (tree_store, &child, &parent, 0,
0, "Child",
-1);
gtk_tree_store_insert_with_values (tree_store, &child, &parent, 0,
0, "Child",
-1);
/* Try to select a child path. */
path = gtk_tree_path_new_from_indices (0, 1, -1);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
/* Check that the parent is not selected. */
gtk_tree_path_up (path);
g_return_if_fail (gtk_tree_selection_path_is_selected (selection, path) == FALSE);
/* Nothing should be selected at this point. */
g_return_if_fail (gtk_tree_selection_count_selected_rows (selection) == 0);
/* Check that selection really still works. */
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
g_return_if_fail (gtk_tree_selection_path_is_selected (selection, path) == TRUE);
g_return_if_fail (gtk_tree_selection_count_selected_rows (selection) == 1);
/* Expand and select child node now. */
gtk_tree_path_append_index (path, 1);
gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
g_return_if_fail (gtk_tree_selection_path_is_selected (selection, path) == TRUE);
g_return_if_fail (gtk_tree_selection_count_selected_rows (selection) == 1);
gtk_tree_path_free (path);
}
static gboolean
test_row_separator_height_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
gboolean ret = FALSE;
GtkTreePath *path;
path = gtk_tree_model_get_path (model, iter);
if (gtk_tree_path_get_indices (path)[0] == 2)
ret = TRUE;
gtk_tree_path_free (path);
return ret;
}
static void
test_row_separator_height (void)
{
int focus_pad, separator_height, height;
gboolean wide_separators;
GtkTreeIter iter;
GtkTreePath *path;
GtkListStore *store;
GtkWidget *window;
GtkWidget *tree_view;
GdkRectangle rect, cell_rect;
store = gtk_list_store_new (1, G_TYPE_STRING);
gtk_list_store_insert_with_values (store, &iter, 0, 0, "Row content", -1);
gtk_list_store_insert_with_values (store, &iter, 1, 0, "Row content", -1);
gtk_list_store_insert_with_values (store, &iter, 2, 0, "Row content", -1);
gtk_list_store_insert_with_values (store, &iter, 3, 0, "Row content", -1);
gtk_list_store_insert_with_values (store, &iter, 4, 0, "Row content", -1);
window = gtk_offscreen_window_new ();
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (tree_view),
test_row_separator_height_func,
NULL,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
0,
"Test",
gtk_cell_renderer_text_new (),
"text", 0,
NULL);
gtk_container_add (GTK_CONTAINER (window), tree_view);
gtk_widget_show_all (window);
path = gtk_tree_path_new_from_indices (2, -1);
gtk_tree_view_get_background_area (GTK_TREE_VIEW (tree_view),
path, NULL, &rect);
gtk_tree_view_get_cell_area (GTK_TREE_VIEW (tree_view),
path, NULL, &cell_rect);
gtk_tree_path_free (path);
gtk_widget_style_get (tree_view,
"focus-padding", &focus_pad,
"wide-separators", &wide_separators,
"separator-height", &separator_height,
NULL);
if (wide_separators)
height = separator_height + 2 * focus_pad;
else
height = 2 + 2 * focus_pad;
g_assert_cmpint (rect.height, ==, height);
g_assert_cmpint (cell_rect.height, ==, height);
gtk_widget_destroy (tree_view);
}
int
main (int argc,
char **argv)
{
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);
g_test_add_func ("/TreeView/cursor/select-collapsed_row",
test_select_collapsed_row);
g_test_add_func ("/TreeView/sizing/row-separator-height",
test_row_separator_height);
return g_test_run ();
}
|