]> Pileus Git - ~andy/gtk/blob - tests/testscale.c
gtk: remove "gboolean homogeneous" from gtk_box_new()
[~andy/gtk] / tests / testscale.c
1 /* testscale.c - scale mark demo
2  * Copyright (C) 2009 Red Hat, Inc.
3  * Author: Matthias Clasen
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <gtk/gtk.h>
22
23 int main (int argc, char *argv[])
24 {
25   GtkWidget *window;
26   GtkWidget *box;
27   GtkWidget *box2;
28   GtkWidget *frame;
29   GtkWidget *scale;
30   gdouble marks[3] = { 0.0, 50.0, 100.0 };
31   const gchar *labels[3] = { 
32     "<small>Left</small>", 
33     "<small>Middle</small>", 
34     "<small>Right</small>" 
35   };
36
37   gdouble bath_marks[4] = { 0.0, 33.3, 66.6, 100.0 };
38   const gchar *bath_labels[4] = { 
39     "<span color='blue' size='small'>Cold</span>", 
40     "<span size='small'>Baby bath</span>", 
41     "<span size='small'>Hot tub</span>", 
42     "<span color='Red' size='small'>Hot</span>" 
43   };
44
45   gtk_init (&argc, &argv);
46
47   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
48   gtk_window_set_title (GTK_WINDOW (window), "Ranges with marks");
49   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
50
51   frame = gtk_frame_new ("No marks");
52   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
53                                     0, 100, 1);
54   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
55   gtk_container_add (GTK_CONTAINER (frame), scale);
56   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
57
58   frame = gtk_frame_new ("Simple marks");
59   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
60                                     0, 100, 1);
61   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
62   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, NULL);
63   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, NULL);
64   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, NULL);
65   gtk_container_add (GTK_CONTAINER (frame), scale);
66   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
67  
68   frame = gtk_frame_new ("Labeled marks");
69   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
70                                     0, 100, 1);
71   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
72   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, labels[0]);
73   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, labels[1]);
74   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, labels[2]);
75   gtk_container_add (GTK_CONTAINER (frame), scale);
76   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
77   
78   frame = gtk_frame_new ("Some labels");
79   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
80                                     0, 100, 1);
81   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
82   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, labels[0]);
83   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, NULL);
84   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, labels[2]);
85   gtk_container_add (GTK_CONTAINER (frame), scale);
86   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
87   
88   frame = gtk_frame_new ("Above and below");
89   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
90                                     0, 100, 1);
91   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
92   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[0], GTK_POS_TOP, bath_labels[0]);
93   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[1], GTK_POS_BOTTOM, bath_labels[1]);
94   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[2], GTK_POS_BOTTOM, bath_labels[2]);
95   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[3], GTK_POS_TOP, bath_labels[3]);
96   gtk_container_add (GTK_CONTAINER (frame), scale);
97   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
98
99   box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
100   gtk_box_pack_start (GTK_BOX (box), box2, TRUE, TRUE, 0);
101
102   frame = gtk_frame_new ("No marks");
103   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
104                                     0, 100, 1);
105   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
106   gtk_container_add (GTK_CONTAINER (frame), scale);
107   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
108
109   frame = gtk_frame_new ("Simple marks");
110   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
111                                     0, 100, 1);
112   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
113   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_LEFT, NULL);
114   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_LEFT, NULL);
115   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_LEFT, NULL);
116   gtk_container_add (GTK_CONTAINER (frame), scale);
117   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
118  
119   frame = gtk_frame_new ("Labeled marks");
120   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
121                                     0, 100, 1);
122   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
123   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_LEFT, labels[0]);
124   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_LEFT, labels[1]);
125   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_LEFT, labels[2]);
126   gtk_container_add (GTK_CONTAINER (frame), scale);
127   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
128   
129   frame = gtk_frame_new ("Some labels");
130   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
131                                     0, 100, 1);
132   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
133   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_LEFT, labels[0]);
134   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_LEFT, NULL);
135   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_LEFT, labels[2]);
136   gtk_container_add (GTK_CONTAINER (frame), scale);
137   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
138   
139   frame = gtk_frame_new ("Right and left");
140   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
141                                     0, 100, 1);
142   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
143   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[0], GTK_POS_RIGHT, bath_labels[0]);
144   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[1], GTK_POS_LEFT, bath_labels[1]);
145   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[2], GTK_POS_LEFT, bath_labels[2]);
146   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[3], GTK_POS_RIGHT, bath_labels[3]);
147   gtk_container_add (GTK_CONTAINER (frame), scale);
148   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
149
150   gtk_container_add (GTK_CONTAINER (window), box);
151   gtk_widget_show_all (window);
152
153   gtk_main ();
154
155   return 0;
156 }
157
158