1 | #include <gtk/gtk.h> |
2 | |
3 | #define MIN_SIZE 150 |
4 | #define MAX_SIZE 300 |
5 | #define BOX_SIZE 600 |
6 | |
7 | typedef enum |
8 | { |
9 | MINIMUM_CONTENT = 1 << 0, |
10 | MAXIMUM_CONTENT = 1 << 1 |
11 | } TestProperty; |
12 | |
13 | static void |
14 | test_size (gboolean overlay, |
15 | GtkPolicyType policy, |
16 | GtkOrientation orientation, |
17 | TestProperty prop) |
18 | { |
19 | GtkWidget *scrolledwindow, *box; |
20 | int min_size, max_size, child_size; |
21 | int scrollbar_size = 0; |
22 | |
23 | box = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 0); |
24 | gtk_widget_set_hexpand (widget: box, TRUE); |
25 | gtk_widget_set_vexpand (widget: box, TRUE); |
26 | |
27 | scrolledwindow = gtk_scrolled_window_new (); |
28 | gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (scrolledwindow), TRUE); |
29 | gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (scrolledwindow), TRUE); |
30 | gtk_scrolled_window_set_overlay_scrolling (GTK_SCROLLED_WINDOW (scrolledwindow), overlay_scrolling: overlay); |
31 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), hscrollbar_policy: policy, vscrollbar_policy: policy); |
32 | gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolledwindow), child: box); |
33 | |
34 | /* Testing the content-width property */ |
35 | if (orientation == GTK_ORIENTATION_HORIZONTAL) |
36 | { |
37 | if (prop & MINIMUM_CONTENT) |
38 | { |
39 | gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (scrolledwindow), MIN_SIZE); |
40 | |
41 | gtk_widget_measure (widget: scrolledwindow, orientation: GTK_ORIENTATION_HORIZONTAL, for_size: -1, |
42 | minimum: &min_size, NULL, NULL, NULL); |
43 | |
44 | } |
45 | |
46 | if (prop & MAXIMUM_CONTENT) |
47 | { |
48 | gtk_scrolled_window_set_max_content_width (GTK_SCROLLED_WINDOW (scrolledwindow), MAX_SIZE); |
49 | gtk_widget_set_size_request (widget: box, BOX_SIZE, height: -1); |
50 | |
51 | /* |
52 | * Here, the content is purposely bigger than the scrolled window, |
53 | * so it should grow up to max-content-width. |
54 | */ |
55 | gtk_widget_measure (widget: scrolledwindow, orientation: GTK_ORIENTATION_HORIZONTAL, for_size: -1, |
56 | NULL, natural: &max_size, NULL, NULL); |
57 | gtk_widget_measure (widget: box, orientation: GTK_ORIENTATION_HORIZONTAL, for_size: -1, |
58 | minimum: &child_size, NULL, NULL, NULL); |
59 | } |
60 | |
61 | /* If the relevant scrollbar is non-overlay and always shown, it is added |
62 | * to the preferred size. When comparing to the expected size, we need to |
63 | * to exclude that extra, as we are only interested in the content size */ |
64 | if (!overlay && policy == GTK_POLICY_ALWAYS) |
65 | { |
66 | GtkWidget *scrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (scrolledwindow)); |
67 | gtk_widget_measure (widget: scrollbar, orientation: GTK_ORIENTATION_HORIZONTAL, for_size: -1, |
68 | minimum: &scrollbar_size, NULL, NULL, NULL); |
69 | } |
70 | } |
71 | /* Testing the content-height property */ |
72 | else |
73 | { |
74 | if (prop & MINIMUM_CONTENT) |
75 | { |
76 | gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolledwindow), MIN_SIZE); |
77 | |
78 | gtk_widget_measure (widget: scrolledwindow, orientation: GTK_ORIENTATION_VERTICAL, for_size: -1, |
79 | minimum: &min_size, NULL, NULL, NULL); |
80 | } |
81 | |
82 | if (prop & MAXIMUM_CONTENT) |
83 | { |
84 | gtk_scrolled_window_set_max_content_height (GTK_SCROLLED_WINDOW (scrolledwindow), MAX_SIZE); |
85 | gtk_widget_set_size_request (widget: box, width: -1, BOX_SIZE); |
86 | |
87 | /* |
88 | * Here, the content is purposely bigger than the scrolled window, |
89 | * so it should grow up to max-content-height. |
90 | */ |
91 | gtk_widget_measure (widget: scrolledwindow, orientation: GTK_ORIENTATION_VERTICAL, for_size: -1, |
92 | NULL, natural: &max_size, NULL, NULL); |
93 | gtk_widget_measure (widget: box, orientation: GTK_ORIENTATION_VERTICAL, for_size: -1, |
94 | minimum: &child_size, NULL, NULL, NULL); |
95 | } |
96 | |
97 | if (!overlay && policy == GTK_POLICY_ALWAYS) |
98 | { |
99 | GtkWidget *scrollbar = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (scrolledwindow)); |
100 | gtk_widget_measure (widget: scrollbar, orientation: GTK_ORIENTATION_VERTICAL, for_size: -1, |
101 | minimum: &scrollbar_size, NULL, NULL, NULL); |
102 | } |
103 | } |
104 | |
105 | if (prop & MINIMUM_CONTENT) |
106 | { |
107 | min_size -= scrollbar_size; |
108 | g_assert_cmpint (min_size, ==, MIN_SIZE); |
109 | } |
110 | |
111 | if (prop & MAXIMUM_CONTENT) |
112 | { |
113 | g_assert_cmpint (child_size, ==, BOX_SIZE); |
114 | |
115 | max_size -= scrollbar_size; |
116 | g_assert_cmpint (max_size, ==, MAX_SIZE); |
117 | } |
118 | } |
119 | |
120 | |
121 | static void |
122 | overlay_automatic_width_min (void) |
123 | { |
124 | test_size (TRUE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MINIMUM_CONTENT); |
125 | } |
126 | |
127 | static void |
128 | overlay_automatic_height_min (void) |
129 | { |
130 | test_size (TRUE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_VERTICAL, prop: MINIMUM_CONTENT); |
131 | } |
132 | |
133 | static void |
134 | overlay_automatic_width_max (void) |
135 | { |
136 | test_size (TRUE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MAXIMUM_CONTENT); |
137 | } |
138 | |
139 | static void |
140 | overlay_automatic_height_max (void) |
141 | { |
142 | test_size (TRUE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_VERTICAL, prop: MAXIMUM_CONTENT); |
143 | } |
144 | |
145 | static void |
146 | overlay_automatic_width_min_max (void) |
147 | { |
148 | test_size (TRUE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MINIMUM_CONTENT | MAXIMUM_CONTENT); |
149 | } |
150 | |
151 | static void |
152 | overlay_automatic_height_min_max (void) |
153 | { |
154 | test_size (TRUE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_VERTICAL, prop: MINIMUM_CONTENT | MAXIMUM_CONTENT); |
155 | } |
156 | |
157 | |
158 | static void |
159 | nonoverlay_automatic_width_min (void) |
160 | { |
161 | test_size (FALSE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MINIMUM_CONTENT); |
162 | } |
163 | |
164 | static void |
165 | nonoverlay_automatic_height_min (void) |
166 | { |
167 | test_size (FALSE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_VERTICAL, prop: MINIMUM_CONTENT); |
168 | } |
169 | |
170 | static void |
171 | nonoverlay_automatic_width_max (void) |
172 | { |
173 | test_size (FALSE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MAXIMUM_CONTENT); |
174 | } |
175 | |
176 | static void |
177 | nonoverlay_automatic_height_max (void) |
178 | { |
179 | test_size (FALSE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_VERTICAL, prop: MAXIMUM_CONTENT); |
180 | } |
181 | |
182 | static void |
183 | nonoverlay_automatic_width_min_max (void) |
184 | { |
185 | test_size (FALSE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MINIMUM_CONTENT | MAXIMUM_CONTENT); |
186 | } |
187 | |
188 | static void |
189 | nonoverlay_automatic_height_min_max (void) |
190 | { |
191 | test_size (FALSE, policy: GTK_POLICY_AUTOMATIC, orientation: GTK_ORIENTATION_VERTICAL, prop: MINIMUM_CONTENT | MAXIMUM_CONTENT); |
192 | } |
193 | |
194 | |
195 | static void |
196 | overlay_always_width_min (void) |
197 | { |
198 | test_size (TRUE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MINIMUM_CONTENT); |
199 | } |
200 | |
201 | static void |
202 | overlay_always_height_min (void) |
203 | { |
204 | test_size (TRUE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_VERTICAL, prop: MINIMUM_CONTENT); |
205 | } |
206 | |
207 | static void |
208 | overlay_always_width_max (void) |
209 | { |
210 | test_size (TRUE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MAXIMUM_CONTENT); |
211 | } |
212 | |
213 | static void |
214 | overlay_always_height_max (void) |
215 | { |
216 | test_size (TRUE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_VERTICAL, prop: MAXIMUM_CONTENT); |
217 | } |
218 | |
219 | static void |
220 | overlay_always_width_min_max (void) |
221 | { |
222 | test_size (TRUE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MINIMUM_CONTENT | MAXIMUM_CONTENT); |
223 | } |
224 | |
225 | static void |
226 | overlay_always_height_min_max (void) |
227 | { |
228 | test_size (TRUE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_VERTICAL, prop: MINIMUM_CONTENT | MAXIMUM_CONTENT); |
229 | } |
230 | |
231 | |
232 | static void |
233 | nonoverlay_always_width_min (void) |
234 | { |
235 | test_size (FALSE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MINIMUM_CONTENT); |
236 | } |
237 | |
238 | static void |
239 | nonoverlay_always_height_min (void) |
240 | { |
241 | test_size (FALSE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_VERTICAL, prop: MINIMUM_CONTENT); |
242 | } |
243 | |
244 | static void |
245 | nonoverlay_always_width_max (void) |
246 | { |
247 | test_size (FALSE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MAXIMUM_CONTENT); |
248 | } |
249 | |
250 | static void |
251 | nonoverlay_always_height_max (void) |
252 | { |
253 | test_size (FALSE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_VERTICAL, prop: MAXIMUM_CONTENT); |
254 | } |
255 | |
256 | static void |
257 | nonoverlay_always_width_min_max (void) |
258 | { |
259 | test_size (FALSE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_HORIZONTAL, prop: MINIMUM_CONTENT | MAXIMUM_CONTENT); |
260 | } |
261 | |
262 | static void |
263 | nonoverlay_always_height_min_max (void) |
264 | { |
265 | test_size (FALSE, policy: GTK_POLICY_ALWAYS, orientation: GTK_ORIENTATION_VERTICAL, prop: MINIMUM_CONTENT | MAXIMUM_CONTENT); |
266 | } |
267 | |
268 | |
269 | int |
270 | main (int argc, char **argv) |
271 | { |
272 | gtk_init (); |
273 | (g_test_init) (argc: &argc, argv: &argv, NULL); |
274 | |
275 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_automatic_width_min" , test_func: overlay_automatic_width_min); |
276 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_automatic_height_min" , test_func: overlay_automatic_height_min); |
277 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_automatic_width_max" , test_func: overlay_automatic_width_max); |
278 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_automatic_height_max" , test_func: overlay_automatic_height_max); |
279 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_automatic_width_min_max" , test_func: overlay_automatic_width_min_max); |
280 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_automatic_height_min_max" , test_func: overlay_automatic_height_min_max); |
281 | |
282 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_automatic_width_min" , test_func: nonoverlay_automatic_width_min); |
283 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_automatic_height_min" , test_func: nonoverlay_automatic_height_min); |
284 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_automatic_width_max" , test_func: nonoverlay_automatic_width_max); |
285 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_automatic_height_max" , test_func: nonoverlay_automatic_height_max); |
286 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_automatic_width_min_max" , test_func: nonoverlay_automatic_width_min_max); |
287 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_automatic_height_min_max" , test_func: nonoverlay_automatic_height_min_max); |
288 | |
289 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_always_width_min" , test_func: overlay_always_width_min); |
290 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_always_height_min" , test_func: overlay_always_height_min); |
291 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_always_width_max" , test_func: overlay_always_width_max); |
292 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_always_height_max" , test_func: overlay_always_height_max); |
293 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_always_width_min_max" , test_func: overlay_always_width_min_max); |
294 | g_test_add_func (testpath: "/sizing/scrolledwindow/overlay_always_height_min_max" , test_func: overlay_always_height_min_max); |
295 | |
296 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_always_width_min" , test_func: nonoverlay_always_width_min); |
297 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_always_height_min" , test_func: nonoverlay_always_height_min); |
298 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_always_width_max" , test_func: nonoverlay_always_width_max); |
299 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_always_height_max" , test_func: nonoverlay_always_height_max); |
300 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_always_width_min_max" , test_func: nonoverlay_always_width_min_max); |
301 | g_test_add_func (testpath: "/sizing/scrolledwindow/nonoverlay_always_height_min_max" , test_func: nonoverlay_always_height_min_max); |
302 | |
303 | return g_test_run (); |
304 | } |
305 | |