]> Pileus Git - ~andy/gtk/blob - tests/testorientable.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testorientable.c
1 /* testorientable.c
2  * Copyright (C) 2004  Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <gtk/gtk.h>
19
20 static void
21 orient_toggled (GtkToggleButton *button, gpointer user_data)
22 {
23   GList *orientables = (GList *) user_data, *ptr;
24   gboolean state = gtk_toggle_button_get_active (button);
25   GtkOrientation orientation;
26
27   if (state)
28     {
29       orientation = GTK_ORIENTATION_VERTICAL;
30       gtk_button_set_label (GTK_BUTTON (button), "Vertical");
31     }
32   else
33     {
34       orientation = GTK_ORIENTATION_HORIZONTAL;
35       gtk_button_set_label (GTK_BUTTON (button), "Horizontal");
36     }
37
38   for (ptr = orientables; ptr; ptr = ptr->next)
39     {
40       GtkOrientable *orientable = GTK_ORIENTABLE (ptr->data);
41
42       gtk_orientable_set_orientation (orientable, orientation);
43     }
44 }
45
46 int
47 main (int argc, char **argv)
48 {
49   GtkWidget *window;
50   GtkWidget *grid;
51   GtkWidget *box, *button;
52   GList *orientables = NULL;
53
54   gtk_init (&argc, &argv);
55
56   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
57   grid= gtk_grid_new ();
58   gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
59   gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
60
61   /* GtkBox */
62   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
63   orientables = g_list_prepend (orientables, box);
64   gtk_grid_attach (GTK_GRID (grid), box, 0, 1, 1, 1);
65   gtk_box_pack_start (GTK_BOX (box),
66                   gtk_button_new_with_label ("GtkBox 1"),
67                   TRUE, TRUE, 0);
68   gtk_box_pack_start (GTK_BOX (box),
69                   gtk_button_new_with_label ("GtkBox 2"),
70                   TRUE, TRUE, 0);
71   gtk_box_pack_start (GTK_BOX (box),
72                   gtk_button_new_with_label ("GtkBox 3"),
73                   TRUE, TRUE, 0);
74
75   /* GtkButtonBox */
76   box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
77   orientables = g_list_prepend (orientables, box);
78   gtk_grid_attach (GTK_GRID (grid), box, 1, 1, 1, 1);
79   gtk_box_pack_start (GTK_BOX (box),
80                   gtk_button_new_with_label ("GtkButtonBox 1"),
81                   TRUE, TRUE, 0);
82   gtk_box_pack_start (GTK_BOX (box),
83                   gtk_button_new_with_label ("GtkButtonBox 2"),
84                   TRUE, TRUE, 0);
85   gtk_box_pack_start (GTK_BOX (box),
86                   gtk_button_new_with_label ("GtkButtonBox 3"),
87                   TRUE, TRUE, 0);
88
89   /* GtkSeparator */
90   box = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
91   orientables = g_list_prepend (orientables, box);
92   gtk_grid_attach (GTK_GRID (grid), box, 2, 1, 1, 1);
93
94   button = gtk_toggle_button_new_with_label ("Horizontal");
95   gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
96   g_signal_connect (button, "toggled",
97                   G_CALLBACK (orient_toggled), orientables);
98
99   gtk_container_add (GTK_CONTAINER (window), grid);
100   gtk_widget_show_all (window);
101
102   g_signal_connect (window, "destroy",
103                   G_CALLBACK (gtk_main_quit), NULL);
104
105   gtk_main ();
106
107   return 0;
108 }