2016-06-03 01:32:56 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2017-02-22 19:13:51 +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
|
|
|
|
test_size (GtkOrientation orientation,
|
|
|
|
TestProperty prop)
|
|
|
|
{
|
|
|
|
GtkWidget *scrolledwindow, *box;
|
2017-02-22 19:13:51 +00:00
|
|
|
int size, child_size;
|
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);
|
2016-06-03 01:32:56 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolledwindow), box);
|
|
|
|
gtk_widget_show_all (scrolledwindow);
|
|
|
|
|
|
|
|
/* Testing the content-width property */
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
if (prop & MINIMUM_CONTENT)
|
|
|
|
{
|
2017-02-22 19:13:51 +00:00
|
|
|
gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (scrolledwindow), MIN_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-02-22 19:13:51 +00:00
|
|
|
gtk_widget_get_preferred_width (scrolledwindow, &size, NULL);
|
|
|
|
|
|
|
|
g_assert_cmpint (size, ==, MIN_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prop & MAXIMUM_CONTENT)
|
|
|
|
{
|
2017-02-22 19:13:51 +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-02-22 19:13:51 +00:00
|
|
|
gtk_widget_get_preferred_width (scrolledwindow, NULL, &size);
|
2016-06-03 01:32:56 +00:00
|
|
|
gtk_widget_get_preferred_width (box, &child_size, NULL);
|
|
|
|
|
2017-02-22 19:13:51 +00:00
|
|
|
g_assert_cmpint (child_size, ==, BOX_SIZE);
|
|
|
|
g_assert_cmpint (size, ==, MAX_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Testing the content-height property */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (prop & MINIMUM_CONTENT)
|
|
|
|
{
|
2017-02-22 19:13:51 +00:00
|
|
|
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolledwindow), MIN_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-02-22 19:13:51 +00:00
|
|
|
gtk_widget_get_preferred_height (scrolledwindow, &size, NULL);
|
|
|
|
|
|
|
|
g_assert_cmpint (size, ==, MIN_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prop & MAXIMUM_CONTENT)
|
|
|
|
{
|
2017-02-22 19:13:51 +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-02-22 19:13:51 +00:00
|
|
|
gtk_widget_get_preferred_height (scrolledwindow, NULL, &size);
|
2016-06-03 01:32:56 +00:00
|
|
|
gtk_widget_get_preferred_height (box, &child_size, NULL);
|
|
|
|
|
2017-02-22 19:13:51 +00:00
|
|
|
g_assert_cmpint (child_size, ==, BOX_SIZE);
|
|
|
|
g_assert_cmpint (size, ==, MAX_SIZE);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2017-02-22 19:13:51 +00:00
|
|
|
min_content_width (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-22 19:13:51 +00:00
|
|
|
test_size (GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-22 19:13:51 +00:00
|
|
|
min_content_height (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-22 19:13:51 +00:00
|
|
|
test_size (GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-22 19:13:51 +00:00
|
|
|
max_content_width (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-22 19:13:51 +00:00
|
|
|
test_size (GTK_ORIENTATION_HORIZONTAL, MAXIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-22 19:13:51 +00:00
|
|
|
max_content_height (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-22 19:13:51 +00:00
|
|
|
test_size (GTK_ORIENTATION_VERTICAL, MAXIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-22 19:13:51 +00:00
|
|
|
min_max_content_width (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-22 19:13:51 +00:00
|
|
|
test_size (GTK_ORIENTATION_HORIZONTAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-22 19:13:51 +00:00
|
|
|
min_max_content_height (void)
|
2016-06-03 01:32:56 +00:00
|
|
|
{
|
2017-02-22 19:13:51 +00:00
|
|
|
test_size (GTK_ORIENTATION_VERTICAL, MINIMUM_CONTENT | MAXIMUM_CONTENT);
|
2016-06-03 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
2017-02-22 19:13:51 +00:00
|
|
|
g_test_add_func ("/sizing/scrolledwindow/min_content_width", min_content_width);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/min_content_height", min_content_height);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-02-22 19:13:51 +00:00
|
|
|
g_test_add_func ("/sizing/scrolledwindow/max_content_width", max_content_width);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/max_content_height", max_content_height);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
2017-02-22 19:13:51 +00:00
|
|
|
g_test_add_func ("/sizing/scrolledwindow/min_max_content_width", min_max_content_width);
|
|
|
|
g_test_add_func ("/sizing/scrolledwindow/min_max_content_height", min_max_content_height);
|
2016-06-03 01:32:56 +00:00
|
|
|
|
|
|
|
return g_test_run ();
|
|
|
|
}
|