]> Pileus Git - ~andy/gtk/blobdiff - tests/testadjustsize.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testadjustsize.c
index c13d9d8c73e4d045507c57bf691910e1ede967e5..9191199b20d0d2b318b406bc23ee43525c428458 100644 (file)
@@ -15,9 +15,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library 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.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <gtk/gtk.h>
@@ -67,25 +65,12 @@ create_button (void)
 }
 
 static gboolean
-on_expose_alignment (GtkWidget      *widget,
-                     GdkEventExpose *event,
-                     void           *data)
+on_draw_alignment (GtkWidget      *widget,
+                   cairo_t        *cr,
+                   void           *data)
 {
-  cairo_t *cr;
-  GtkAllocation allocation;
-
-  cr = gdk_cairo_create (event->window);
-
   cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
-  gtk_widget_get_allocation (widget, &allocation);
-  cairo_rectangle (cr,
-                   allocation.x,
-                   allocation.y,
-                   allocation.width,
-                   allocation.height);
-  cairo_fill (cr);
-
-  cairo_destroy (cr);
+  cairo_paint (cr);
 
   return FALSE;
 }
@@ -100,8 +85,8 @@ create_alignment (void)
   /* make the alignment visible */
   gtk_widget_set_redraw_on_allocate (alignment, TRUE);
   g_signal_connect (G_OBJECT (alignment),
-                    "expose-event",
-                    G_CALLBACK (on_expose_alignment),
+                    "draw",
+                    G_CALLBACK (on_draw_alignment),
                     NULL);
 
   return alignment;
@@ -110,7 +95,7 @@ create_alignment (void)
 static void
 open_test_window (void)
 {
-  GtkWidget *table;
+  GtkWidget *grid;
   int i;
 
   test_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -128,19 +113,13 @@ open_test_window (void)
   test_widgets[TEST_WIDGET_BUTTON] = create_button ();
   test_widgets[TEST_WIDGET_ALIGNMENT] = create_alignment ();
 
-  table = gtk_table_new (2, 3, FALSE);
+  grid = gtk_grid_new ();
 
-  gtk_container_add (GTK_CONTAINER (test_window), table);
+  gtk_container_add (GTK_CONTAINER (test_window), grid);
 
   for (i = 0; i < TEST_WIDGET_LAST; ++i)
     {
-      gtk_table_attach (GTK_TABLE (table),
-                        test_widgets[i],
-                        i % 3,
-                        i % 3 + 1,
-                        i / 3,
-                        i / 3 + 1,
-                        0, 0, 0, 0);
+      gtk_grid_attach (GTK_GRID (grid), test_widgets[i], i % 3, i / 3, 1, 1);
     }
 
   gtk_widget_show_all (test_window);
@@ -212,7 +191,7 @@ open_control_window (void)
   g_signal_connect (window, "delete-event",
                     G_CALLBACK (gtk_main_quit), window);
 
-  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
+  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (window), box);
 
   toggle =
@@ -249,23 +228,23 @@ create_widget_visible_border (const char *text)
   GtkWidget *inner_box;
   GtkWidget *test_widget;
   GtkWidget *label;
-  GdkColor color;
+  GdkRGBA color;
 
   outer_box = gtk_event_box_new ();
-  gdk_color_parse ("black", &color);
-  gtk_widget_modify_bg (outer_box, GTK_STATE_NORMAL, &color);
+  gdk_rgba_parse (&color, "black");
+  gtk_widget_override_background_color (outer_box, 0, &color);
 
   inner_box = gtk_event_box_new ();
   gtk_container_set_border_width (GTK_CONTAINER (inner_box), 5);
-  gdk_color_parse ("blue", &color);
-  gtk_widget_modify_bg (inner_box, GTK_STATE_NORMAL, &color);
+  gdk_rgba_parse (&color, "blue");
+  gtk_widget_override_background_color (inner_box, 0, &color);
 
   gtk_container_add (GTK_CONTAINER (outer_box), inner_box);
 
 
   test_widget = gtk_event_box_new ();
-  gdk_color_parse ("red", &color);
-  gtk_widget_modify_bg (test_widget, GTK_STATE_NORMAL, &color);
+  gdk_rgba_parse (&color, "red");
+  gtk_widget_override_background_color (test_widget, 0, &color);
 
   gtk_container_add (GTK_CONTAINER (inner_box), test_widget);
 
@@ -306,6 +285,8 @@ create_aligned (GtkAlign halign,
   g_object_set (G_OBJECT (TEST_WIDGET (widget)),
                 "halign", halign,
                 "valign", valign,
+                "hexpand", TRUE,
+                "vexpand", TRUE,
                 NULL);
 
   return widget;
@@ -314,7 +295,7 @@ create_aligned (GtkAlign halign,
 static void
 open_alignment_window (void)
 {
-  GtkWidget *table;
+  GtkWidget *grid;
   int i;
   GEnumClass *align_class;
 
@@ -329,9 +310,11 @@ open_alignment_window (void)
 
   align_class = g_type_class_peek (GTK_TYPE_ALIGN);
 
-  table = gtk_table_new (align_class->n_values, align_class->n_values, TRUE);
+  grid = gtk_grid_new ();
+  gtk_grid_set_row_homogeneous (GTK_GRID (grid), TRUE);
+  gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
 
-  gtk_container_add (GTK_CONTAINER (test_window), table);
+  gtk_container_add (GTK_CONTAINER (test_window), grid);
 
   for (i = 0; i < align_class->n_values; ++i)
     {
@@ -342,11 +325,7 @@ open_alignment_window (void)
             create_aligned(align_class->values[i].value,
                            align_class->values[j].value);
 
-          gtk_table_attach (GTK_TABLE (table),
-                            child,
-                            i, i + 1,
-                            j, j + 1,
-                            GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+          gtk_grid_attach (GTK_GRID (grid), child, i, j, 1, 1);
         }
     }
 
@@ -362,6 +341,8 @@ create_margined (const char *propname)
 
   g_object_set (G_OBJECT (TEST_WIDGET (widget)),
                 propname, 15,
+                "hexpand", TRUE,
+                "vexpand", TRUE,
                 NULL);
 
   return widget;
@@ -370,7 +351,7 @@ create_margined (const char *propname)
 static void
 open_margin_window (void)
 {
-  GtkWidget *table;
+  GtkWidget *box;
   int i;
   const char * margins[] = {
     "margin-left",
@@ -388,34 +369,71 @@ open_margin_window (void)
 
   gtk_window_set_resizable (GTK_WINDOW (test_window), TRUE);
 
-  table = gtk_table_new (G_N_ELEMENTS (margins), 1, FALSE);
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
-  gtk_container_add (GTK_CONTAINER (test_window), table);
+  gtk_container_add (GTK_CONTAINER (test_window), box);
 
   for (i = 0; i < (int) G_N_ELEMENTS (margins); ++i)
     {
       GtkWidget *child =
         create_margined(margins[i]);
 
-      gtk_table_attach (GTK_TABLE (table),
-                        child,
-                        0, 1,
-                        i, i + 1,
-                        GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+      gtk_container_add (GTK_CONTAINER (box), child);
     }
 
   gtk_widget_show_all (test_window);
 }
 
+static void
+open_valigned_label_window (void)
+{
+  GtkWidget *window, *box, *label, *frame;
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+  g_signal_connect (test_window, "delete-event",
+                    G_CALLBACK (gtk_main_quit), test_window);
+
+  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+  gtk_widget_show (box);
+  gtk_container_add (GTK_CONTAINER (window), box);
+
+  label = gtk_label_new ("Both labels expand");
+  gtk_widget_show (label);
+  gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
+
+  label = gtk_label_new ("Some wrapping text with width-chars = 15 and max-width-chars = 35");
+  gtk_label_set_line_wrap  (GTK_LABEL (label), TRUE);
+  gtk_label_set_width_chars  (GTK_LABEL (label), 15);
+  gtk_label_set_max_width_chars  (GTK_LABEL (label), 35);
+
+  gtk_widget_show (label);
+
+  frame  = gtk_frame_new (NULL);
+  gtk_widget_show (frame);
+  gtk_container_add (GTK_CONTAINER (frame), label);
+
+  gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
+  gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
+
+  gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 0);
+
+  gtk_window_present (GTK_WINDOW (window));
+}
+
 int
 main (int argc, char *argv[])
 {
   gtk_init (&argc, &argv);
 
+  if (g_getenv ("RTL"))
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
+
   open_test_window ();
   open_control_window ();
   open_alignment_window ();
   open_margin_window ();
+  open_valigned_label_window ();
 
   gtk_main ();