]> Pileus Git - ~andy/gtk/blob - tests/testscale.c
Merge branch 'master' into treeview-refactor
[~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 static void
24 show_trough_toggled (GtkToggleButton *button,
25                      GtkScale        *scale)
26 {
27   gboolean value;
28
29   value = gtk_toggle_button_get_active (button);
30   gtk_range_set_range (GTK_RANGE (scale), 0., value ? 100.0 : 0.);
31 }
32
33 int main (int argc, char *argv[])
34 {
35   GtkWidget *window;
36   GtkWidget *box;
37   GtkWidget *box2;
38   GtkWidget *frame;
39   GtkWidget *scale;
40   GtkWidget *toggle;
41   gdouble marks[3] = { 0.0, 50.0, 100.0 };
42   const gchar *labels[3] = { 
43     "<small>Left</small>", 
44     "<small>Middle</small>", 
45     "<small>Right</small>" 
46   };
47
48   gdouble bath_marks[4] = { 0.0, 33.3, 66.6, 100.0 };
49   const gchar *bath_labels[4] = { 
50     "<span color='blue' size='small'>Cold</span>", 
51     "<span size='small'>Baby bath</span>", 
52     "<span size='small'>Hot tub</span>", 
53     "<span color='Red' size='small'>Hot</span>" 
54   };
55
56   gtk_init (&argc, &argv);
57
58   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
59   gtk_window_set_title (GTK_WINDOW (window), "Ranges with marks");
60   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
61
62   frame = gtk_frame_new ("No marks");
63   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
64                                     0, 100, 1);
65   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
66   gtk_container_add (GTK_CONTAINER (frame), scale);
67   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
68
69   frame = gtk_frame_new ("Simple marks");
70   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
71                                     0, 100, 1);
72   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
73   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, NULL);
74   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, NULL);
75   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, NULL);
76   gtk_container_add (GTK_CONTAINER (frame), scale);
77   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
78  
79   frame = gtk_frame_new ("Labeled marks");
80   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
81                                     0, 100, 1);
82   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
83   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, labels[0]);
84   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, labels[1]);
85   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, labels[2]);
86   gtk_container_add (GTK_CONTAINER (frame), scale);
87   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
88   
89   frame = gtk_frame_new ("Some labels");
90   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
91                                     0, 100, 1);
92   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
93   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, labels[0]);
94   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, NULL);
95   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, labels[2]);
96   gtk_container_add (GTK_CONTAINER (frame), scale);
97   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
98   
99   frame = gtk_frame_new ("Above and below");
100   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
101                                     0, 100, 1);
102   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
103   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[0], GTK_POS_TOP, bath_labels[0]);
104   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[1], GTK_POS_BOTTOM, bath_labels[1]);
105   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[2], GTK_POS_BOTTOM, bath_labels[2]);
106   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[3], GTK_POS_TOP, bath_labels[3]);
107   gtk_container_add (GTK_CONTAINER (frame), scale);
108   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
109
110   frame = gtk_frame_new ("Show/hide trough");
111   box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
112   scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
113                                     0, 100, 1);
114   gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
115   toggle = gtk_toggle_button_new_with_label ("Show slider trough");
116   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), TRUE);
117   g_signal_connect (G_OBJECT (toggle), "toggled",
118                     G_CALLBACK (show_trough_toggled), scale);
119   gtk_box_pack_start (GTK_BOX (box2), toggle, TRUE, TRUE, 0);
120   gtk_container_add (GTK_CONTAINER (frame), box2);
121   gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
122
123   box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
124   gtk_box_pack_start (GTK_BOX (box), box2, TRUE, TRUE, 0);
125
126   frame = gtk_frame_new ("No marks");
127   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
128                                     0, 100, 1);
129   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
130   gtk_container_add (GTK_CONTAINER (frame), scale);
131   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
132
133   frame = gtk_frame_new ("Simple marks");
134   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
135                                     0, 100, 1);
136   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
137   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_LEFT, NULL);
138   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_LEFT, NULL);
139   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_LEFT, NULL);
140   gtk_container_add (GTK_CONTAINER (frame), scale);
141   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
142  
143   frame = gtk_frame_new ("Labeled marks");
144   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
145                                     0, 100, 1);
146   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
147   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_LEFT, labels[0]);
148   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_LEFT, labels[1]);
149   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_LEFT, labels[2]);
150   gtk_container_add (GTK_CONTAINER (frame), scale);
151   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
152   
153   frame = gtk_frame_new ("Some labels");
154   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
155                                     0, 100, 1);
156   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
157   gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_LEFT, labels[0]);
158   gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_LEFT, NULL);
159   gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_LEFT, labels[2]);
160   gtk_container_add (GTK_CONTAINER (frame), scale);
161   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
162   
163   frame = gtk_frame_new ("Right and left");
164   scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
165                                     0, 100, 1);
166   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
167   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[0], GTK_POS_RIGHT, bath_labels[0]);
168   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[1], GTK_POS_LEFT, bath_labels[1]);
169   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[2], GTK_POS_LEFT, bath_labels[2]);
170   gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[3], GTK_POS_RIGHT, bath_labels[3]);
171   gtk_container_add (GTK_CONTAINER (frame), scale);
172   gtk_box_pack_start (GTK_BOX (box2), frame, FALSE, FALSE, 0);
173
174   gtk_container_add (GTK_CONTAINER (window), box);
175   gtk_widget_show_all (window);
176
177   gtk_main ();
178
179   return 0;
180 }
181
182