2016-06-03 01:32:56 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2017-02-22 19:26:14 +00:00
|
|
|
#define MIN_SIZE 150
|
|
|
|
#define MAX_SIZE 300
|
|
|
|
#define BOX_SIZE 600
|
2016-06-03 01:32:56 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
MINIMUM_CONTENT = 1 << 0,
|
|
|
|
MAXIMUM_CONTENT = 1 << 1
|
|
|
|
} TestProperty;
|
|
|
|
|
|
|
|
static void
|
2017-02-24 22:46:05 +00:00
|
|
|
test_size (gboolean overlay,
|
|
|
|
GtkPolicyType policy,
|
|
|
|
GtkOrientation orientation,
|
2016-06-03 01:32:56 +00:00
|
|
|
TestProperty prop)
|
|
|
|
{
|
|
|
|
GtkWidget *scrolledwindow, *box;
|
2017-02-24 22:46:05 +00:00
|
|
|
int min_size, max_size, child_size;
|
|
|
|
int scrollbar_size = 0;
|
2016-06-03 01:32:56 +00:00
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_widget_set_hexpand (box, TRUE);
|
|
|
|
gtk_widget_set_vexpand (box, TRUE);
|
|
|
|
|
|
|
|
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
|
2016-08-31 19:04:57 +00:00
|
|
|
gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (scrolledwindow), TRUE);
|
|
|
|
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (scrolledwindow), TRUE);
|
2017-02-24 22:46:05 +00:00
|
|
|
gtk_scrolled_window_set_overlay_scrolling (GTK_SCROLLED_WINDOW (scrolledwindow), overlay);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), policy, policy);
|
2016-06-03 01:32:56 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolledwindow), box);
|
|
|
|
|
|
|
|
/* Testing the content-width property */
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
if (prop & MINIMUM_CONTENT)
|
|
|
|
{
|
2017-02-22 19:26:14 +00:00
|
|
|
gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (scrolledwindow), MIN_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-05-02 19:50:50 +00:00
|
|
|
gtk_widget_measure (scrolledwindow, GTK_ORIENTATION_HORIZONTAL, -1,
|
2017-02-24 22:46:05 +00:00
|
|
|
&min_size, NULL, NULL, NULL);
|
2017-02-22 19:26:14 +00:00
|
|
|
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prop & MAXIMUM_CONTENT)
|
|
|
|
{
|
2017-02-22 19:26:14 +00:00
|
|
|
gtk_scrolled_window_set_max_content_width (GTK_SCROLLED_WINDOW (scrolledwindow), MAX_SIZE);
|
|
|
|
gtk_widget_set_size_request (box, BOX_SIZE, -1);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here, the content is purposely bigger than the scrolled window,
|
|
|
|
* so it should grow up to max-content-width.
|
|
|
|
*/
|
2017-05-02 19:50:50 +00:00
|
|
|
gtk_widget_measure (scrolledwindow, GTK_ORIENTATION_HORIZONTAL, -1,
|
2017-02-24 22:46:05 +00:00
|
|
|
NULL, &max_size, NULL, NULL);
|
2017-05-02 19:50:50 +00:00
|
|
|
gtk_widget_measure (box, GTK_ORIENTATION_HORIZONTAL, -1,
|
|
|
|
&child_size, NULL, NULL, NULL);
|
2017-02-24 22:46:05 +00:00
|
|
|
}
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-02-24 22:46:05 +00:00
|
|
|
/* If the relevant scrollbar is non-overlay and always shown, it is added
|
|
|
|
* to the preferred size. When comparing to the expected size, we need to
|
|
|
|
* to exclude that extra, as we are only interested in the content size */
|
|
|
|
if (!overlay && policy == GTK_POLICY_ALWAYS)
|
|
|
|
{
|
|
|
|
GtkWidget *scrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (scrolledwindow));
|
|
|
|
gtk_widget_measure (scrollbar, GTK_ORIENTATION_HORIZONTAL, -1,
|
|
|
|
&scrollbar_size, NULL, NULL, NULL);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Testing the content-height property */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (prop & MINIMUM_CONTENT)
|
|
|
|
{
|
2017-02-22 19:26:14 +00:00
|
|
|
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolledwindow), MIN_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-05-10 18:11:16 +00:00
|
|
|
gtk_widget_measure (scrolledwindow, GTK_ORIENTATION_VERTICAL, -1,
|
2017-02-24 22:46:05 +00:00
|
|
|
&min_size, NULL, NULL, NULL);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prop & MAXIMUM_CONTENT)
|
|
|
|
{
|
2017-02-22 19:26:14 +00:00
|
|
|
gtk_scrolled_window_set_max_content_height (GTK_SCROLLED_WINDOW (scrolledwindow), MAX_SIZE);
|
|
|
|
gtk_widget_set_size_request (box, -1, BOX_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here, the content is purposely bigger than the scrolled window,
|
|
|
|
* so it should grow up to max-content-height.
|
|
|
|
*/
|
2017-05-02 19:50:50 +00:00
|
|
|
gtk_widget_measure (scrolledwindow, GTK_ORIENTATION_VERTICAL, -1,
|
2017-02-24 22:46:05 +00:00
|
|
|
NULL, &max_size, NULL, NULL);
|
2017-05-02 19:50:50 +00:00
|
|
|
gtk_widget_measure (box, GTK_ORIENTATION_VERTICAL, -1,
|
|
|
|
&child_size, NULL, NULL, NULL);
|
2017-02-24 22:46:05 +00:00
|
|
|
}
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-02-24 22:46:05 +00:00
|
|
|
if (!overlay && policy == GTK_POLICY_ALWAYS)
|
|
|
|
{
|
|
|
|
GtkWidget *scrollbar = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (scrolledwindow));
|
|
|
|
gtk_widget_measure (scrollbar, GTK_ORIENTATION_VERTICAL, -1,
|
|
|
|
&scrollbar_size, NULL, NULL, NULL);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-24 22:46:05 +00:00
|
|
|
|
|
|
|
if (prop & MINIMUM_CONTENT)
|
|
|
|
{
|
|
|
|
min_size -= scrollbar_size;
|
|
|
|
g_assert_cmpint (min_size, ==, MIN_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop & MAXIMUM_CONTENT)
|
|
|
|
{
|
|
|
|
g_assert_cmpint (child_size, ==, BOX_SIZE);
|
|
|
|
|
|
|
|
max_size -= scrollbar_size;
|
|
|
|
g_assert_cmpint (max_size, ==, MAX_SIZE);
|
|
|
|
}
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2017-02-24 22:46:05 +00:00
|
|
|
overlay_automatic_width_min (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-24 22:46:05 +00:00
|
|
|
test_size (TRUE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-24 22:46:05 +00:00
|
|
|
overlay_automatic_height_min (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-24 22:46:05 +00:00
|
|
|
test_size (TRUE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-24 22:46:05 +00:00
|
|
|
overlay_automatic_width_max (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-24 22:46:05 +00:00
|
|
|
test_size (TRUE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_HORIZONTAL, MAXIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-24 22:46:05 +00:00
|
|
|
overlay_automatic_height_max (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-24 22:46:05 +00:00
|
|
|
test_size (TRUE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_VERTICAL, MAXIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-24 22:46:05 +00:00
|
|
|
overlay_automatic_width_min_max (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-24 22:46:05 +00:00
|
|
|
test_size (TRUE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-24 22:46:05 +00:00
|
|
|
overlay_automatic_height_min_max (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-24 22:46:05 +00:00
|
|
|
test_size (TRUE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 22:46:05 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_automatic_width_min (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_automatic_height_min (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_automatic_width_max (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_HORIZONTAL, MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_automatic_height_max (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_VERTICAL, MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_automatic_width_min_max (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_automatic_height_min_max (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_AUTOMATIC, GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
overlay_always_width_min (void)
|
|
|
|
{
|
|
|
|
test_size (TRUE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
overlay_always_height_min (void)
|
|
|
|
{
|
|
|
|
test_size (TRUE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
overlay_always_width_max (void)
|
|
|
|
{
|
|
|
|
test_size (TRUE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_HORIZONTAL, MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
overlay_always_height_max (void)
|
|
|
|
{
|
|
|
|
test_size (TRUE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_VERTICAL, MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
overlay_always_width_min_max (void)
|
|
|
|
{
|
|
|
|
test_size (TRUE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
overlay_always_height_min_max (void)
|
|
|
|
{
|
|
|
|
test_size (TRUE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_always_width_min (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_always_height_min (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_always_width_max (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_HORIZONTAL, MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_always_height_max (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_VERTICAL, MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_always_width_min_max (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nonoverlay_always_height_min_max (void)
|
|
|
|
{
|
|
|
|
test_size (FALSE, GTK_POLICY_ALWAYS, GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-03 01:32:56 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2016-06-03 01:32:56 +00:00
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
2017-02-24 22:46:05 +00:00
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_automatic_width_min", overlay_automatic_width_min);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_automatic_height_min", overlay_automatic_height_min);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_automatic_width_max", overlay_automatic_width_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_automatic_height_max", overlay_automatic_height_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_automatic_width_min_max", overlay_automatic_width_min_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_automatic_height_min_max", overlay_automatic_height_min_max);
|
|
|
|
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_automatic_width_min", nonoverlay_automatic_width_min);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_automatic_height_min", nonoverlay_automatic_height_min);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_automatic_width_max", nonoverlay_automatic_width_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_automatic_height_max", nonoverlay_automatic_height_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_automatic_width_min_max", nonoverlay_automatic_width_min_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_automatic_height_min_max", nonoverlay_automatic_height_min_max);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-02-24 22:46:05 +00:00
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_always_width_min", overlay_always_width_min);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_always_height_min", overlay_always_height_min);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_always_width_max", overlay_always_width_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_always_height_max", overlay_always_height_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_always_width_min_max", overlay_always_width_min_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/overlay_always_height_min_max", overlay_always_height_min_max);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-02-24 22:46:05 +00:00
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_always_width_min", nonoverlay_always_width_min);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_always_height_min", nonoverlay_always_height_min);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_always_width_max", nonoverlay_always_width_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_always_height_max", nonoverlay_always_height_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_always_width_min_max", nonoverlay_always_width_min_max);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/nonoverlay_always_height_min_max", nonoverlay_always_height_min_max);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
|
|
|
return g_test_run ();
|
|
|
|
}
|