[gtk+] Add an interactive window sizing test



commit 526958cd53a147dc410d1ee8d24c7db519c1298e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 25 11:42:28 2013 -0400

    Add an interactive window sizing test

 tests/Makefile.am      |    6 ++-
 tests/testwindowsize.c |  116 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7e8f28a..d68c4a8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -134,7 +134,8 @@ noinst_PROGRAMS =  $(TEST_PROGS)    \
        testgmenu                       \
        testlogout                      \
        teststack                       \
-       testrevealer
+       testrevealer                    \
+       testwindowsize
 
 if USE_X11
 noinst_PROGRAMS += testerrors
@@ -262,6 +263,7 @@ testgmenu_DEPENDENCIES = $(TEST_DEPS)
 testlogout_DEPENDENCIES = $(TEST_DEPS)
 teststack_DEPENDENCIES = $(TEST_DEPS)
 testrevealer_DEPENDENCIES = $(TEST_DEPS)
+testwindowsize_DEPENDENCIES = $(TEST_DEPS)
 
 animated_resizing_SOURCES =    \
        animated-resizing.c     \
@@ -476,6 +478,8 @@ teststack_SOURCES = teststack.c
 
 testrevealer_SOURCES = testrevealer.c
 
+testwindowsize_SOURCES = testwindowsize.c
+
 EXTRA_DIST +=                  \
        gradient1.png           \
        prop-editor.h           \
diff --git a/tests/testwindowsize.c b/tests/testwindowsize.c
new file mode 100644
index 0000000..f205e30
--- /dev/null
+++ b/tests/testwindowsize.c
@@ -0,0 +1,116 @@
+/*  gcc -g -Wall -O2 -o dialog-test dialog-test.c `pkg-config --cflags --libs gtk+-3.0` */
+#include <gtk/gtk.h>
+
+static GtkWidget *window;
+static GtkWidget *width_chars_spin;
+static GtkWidget *default_width_spin;
+static GtkWidget *default_height_spin;
+static GtkWidget *resizable_check;
+
+static void
+show_dialog (void)
+{
+  GtkWidget *dialog;
+  GtkWidget *label;
+  gint width_chars, default_width, default_height;
+  gboolean resizable;
+
+  width_chars = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (width_chars_spin));
+  default_width = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (default_width_spin));
+  default_height = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (default_height_spin));
+  resizable = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (resizable_check));
+
+  dialog = gtk_dialog_new_with_buttons ("Test", GTK_WINDOW (window),
+                                        GTK_DIALOG_MODAL,
+                                        GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
+                                        NULL);
+
+  label = gtk_label_new ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+                         "Nulla innn urna ac dui malesuada ornare. Nullam dictum "
+                         "tempor mi et tincidunt. Aliquam metus nulla, auctor "
+                         "vitae pulvinar nec, egestas at mi. Class aptent taciti "
+                         "sociosqu ad litora torquent per conubia nostra, per "
+                         "inceptos himenaeos. Aliquam sagittis, tellus congue "
+                         "cursus congue, diam massa mollis enim, sit amet gravida "
+                         "magna turpis egestas sapien. Aenean vel molestie nunc. "
+                         "In hac habitasse platea dictumst. Suspendisse lacinia"
+                         "mi eu ipsum vestibulum in venenatis enim commodo. "
+                         "Vivamus non malesuada ligula.");
+
+  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+  gtk_label_set_width_chars (GTK_LABEL (label), width_chars);
+  gtk_window_set_default_size (GTK_WINDOW (dialog), default_width, default_height);
+  gtk_window_set_resizable (GTK_WINDOW (dialog), resizable);
+
+  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+                      label, 0, TRUE, TRUE);
+
+  gtk_widget_show (label);
+
+  gtk_dialog_run (GTK_DIALOG (dialog));
+
+  gtk_widget_destroy (dialog);
+}
+
+static void
+create_window (void)
+{
+  GtkWidget *grid;
+  GtkWidget *label;
+  GtkWidget *button;
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_title (GTK_WINDOW (window), "Window size");
+  gtk_container_set_border_width (GTK_CONTAINER (window), 12);
+  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+
+  grid = gtk_grid_new ();
+  gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
+  gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
+  gtk_container_add (GTK_CONTAINER (window), grid);
+
+  label = gtk_label_new ("Width chars");
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  width_chars_spin = gtk_spin_button_new_with_range (-1, 1000, 1);
+  gtk_widget_set_halign (width_chars_spin, GTK_ALIGN_START);
+
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), width_chars_spin, 1, 0, 1, 1);
+
+  label = gtk_label_new ("Default size");
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  default_width_spin = gtk_spin_button_new_with_range (-1, 1000, 1);
+  gtk_widget_set_halign (default_width_spin, GTK_ALIGN_START);
+  default_height_spin = gtk_spin_button_new_with_range (-1, 1000, 1);
+  gtk_widget_set_halign (default_height_spin, GTK_ALIGN_START);
+
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), default_width_spin, 1, 1, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), default_height_spin, 2, 1, 1, 1);
+
+  label = gtk_label_new ("Resizable");
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  resizable_check = gtk_check_button_new ();
+  gtk_widget_set_halign (resizable_check, GTK_ALIGN_START);
+
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), resizable_check, 1, 2, 1, 1);
+
+  button = gtk_button_new_with_label ("Show");
+  g_signal_connect (button, "clicked", G_CALLBACK (show_dialog), NULL);
+  gtk_grid_attach (GTK_GRID (grid), button, 2, 3, 1, 1);
+
+  gtk_widget_show_all (window);
+}
+
+int
+main (int argc, char *argv[])
+{
+  gtk_init (NULL, NULL);
+
+  create_window ();
+
+  gtk_main ();
+
+  return 0;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]