1 /* testspinbutton.c
2  * Copyright (C) 2004 Morten Welinder
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 "config.h"
19 #include <gtk/gtk.h>
20 
21 static gint num_windows = 0;
22 
23 static gboolean
on_delete_event(GtkWidget * w,GdkEvent * event,gpointer user_data)24 on_delete_event (GtkWidget *w,
25                  GdkEvent *event,
26                  gpointer user_data)
27 {
28   num_windows--;
29   if (num_windows == 0)
30     gtk_main_quit ();
31 
32   return FALSE;
33 }
34 
35 static void
prepare_window_for_orientation(GtkOrientation orientation)36 prepare_window_for_orientation (GtkOrientation orientation)
37 {
38   GtkWidget *window, *mainbox, *wrap_button;
39   int max;
40 
41   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
42   g_signal_connect (window, "delete_event", G_CALLBACK (on_delete_event), NULL);
43 
44   mainbox = gtk_box_new (GTK_ORIENTATION_VERTICAL ^ orientation, 2);
45   gtk_container_add (GTK_CONTAINER (window), mainbox);
46 
47   wrap_button = gtk_toggle_button_new_with_label ("Wrap");
48   gtk_container_add (GTK_CONTAINER (mainbox), wrap_button);
49 
50   for (max = 9; max <= 999999999; max = max * 10 + 9)
51     {
52       GtkAdjustment *adj = gtk_adjustment_new (max,
53                                                1, max,
54                                                1,
55                                                (max + 1) / 10,
56                                                0.0);
57 
58       GtkWidget *spin = gtk_spin_button_new (adj, 1.0, 0);
59       GtkWidget *hbox;
60       gtk_orientable_set_orientation (GTK_ORIENTABLE (spin), orientation);
61       gtk_widget_set_halign (GTK_WIDGET (spin), GTK_ALIGN_CENTER);
62 
63       g_object_bind_property (wrap_button, "active", spin, "wrap", G_BINDING_SYNC_CREATE);
64 
65       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
66       gtk_box_pack_start (GTK_BOX (hbox), spin, FALSE, FALSE, 2);
67       gtk_container_add (GTK_CONTAINER (mainbox), hbox);
68     }
69 
70   gtk_widget_show_all (window);
71   num_windows++;
72 }
73 
74 int
main(int argc,char ** argv)75 main (int argc, char **argv)
76 {
77   gtk_init (&argc, &argv);
78 
79   prepare_window_for_orientation (GTK_ORIENTATION_HORIZONTAL);
80   prepare_window_for_orientation (GTK_ORIENTATION_VERTICAL);
81 
82   gtk_main ();
83 
84   return 0;
85 }
86