1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * gtkD 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
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with gtkD; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
17  */
18 
19 module TestScales;
20 
21 private import gtk.Table;
22 
23 private import gtk.VScale;
24 private import gtk.HScale;
25 private import gtk.MenuItem;
26 private import gtk.Menu;
27 private import gtk.CheckButton;
28 private import gtk.ComboBox;
29 private import gtk.ComboBoxText;
30 private import gtk.Box;
31 private import gtk.Button;
32 private import gtk.Scrollbar;
33 private import gtk.Separator;
34 private import gtk.Label;
35 private import gtk.Scale;
36 private import gtk.Adjustment;
37 private import gtk.VBox;
38 private import gtk.HBox;
39 private import gtk.HScrollbar;
40 private import gtk.Range;
41 
42 debug import std.stdio;
43 
44 /**
45  * This tests the gtkD scales and scrollbar widgets
46  */
47 
48 class TestScales : Table //, MenuItemListener
49 {
50 	VScale vscale;
51 	HScale hscale;
52 
53 	this()
54 	{
55 
56 		debug(1)
57 		{
58 			writeln("instantiating TestScales");
59 		}
60 
61 		super(1,1,0);
62 
63 		createRangeControls();
64 	}
65 
66 	void createRangeControls()
67 	{
68 			Box box1,box2,box3;
69 			Button button;
70 			Scrollbar scrollbar;
71 			Separator separator;
72 			ComboBoxText positionSelection;
73 
74 			Label label;
75 			Scale scale;
76 			Adjustment adj1, adj2;
77 
78 			box1 = new VBox(false,0);
79 			add(box1);
80 
81 			box2 = new HBox(false,0);
82 			box2.setBorderWidth(10);
83 			box1.packStart(box2, true,true,0);
84 
85 			/* value, lower, upper, step_increment, page_increment, page_size */
86 			/* Note that the page_size value only makes a difference for
87 			 * scrollbar widgets, and the highest value you'll get is actually
88 			 * (upper - page_size). */
89 			adj1 = new Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
90 
91 			vscale = new VScale(adj1);
92 			//scale_set_default_values (GTK_SCALE (vscale));
93 			box2.packStart(vscale, true, true, 0);
94 
95 			box3 = new VBox(false,10);
96 			box2.packStart(box3,true,true,0);
97 
98 			/* Reuse the same adjustment */
99 			hscale = new HScale(adj1);
100 			hscale.setSizeRequest(200,-1);
101 			//scale_set_default_values (GTK_SCALE (hscale));
102 			box3.packStart(hscale,true,true,0);
103 
104 			/* Reuse the same adjustment again */
105 			scrollbar = new HScrollbar(adj1);
106 			/* Notice how this causes the scales to always be updated
107 			 * continuously when the scrollbar is moved */
108 			box3.packStart(scrollbar,true,true,0);
109 
110 			box2 = new HBox(false,10);
111 			box2.setBorderWidth(10);
112 			box1.packStart(box2,true,true,0);
113 
114 			/* A checkbutton to control whether the value is displayed or not */
115 			CheckButton cButton = new CheckButton("Display value on scale widgets");
116 			cButton.setActive(true);
117 			cButton.addOnClicked(&displayValues);
118 			box2.packStart(cButton,true,true,0);
119 
120 			box2 = new HBox(false,10);
121 			box2.setBorderWidth(10);
122 
123 			/* An option menu to change the position of the value */
124 			label = new Label("Scale Value Position:");
125 			box2.packStart(label,false,false,0);
126 
127 			positionSelection = new ComboBoxText();
128 			positionSelection.appendText("Top");
129 			positionSelection.appendText("Bottom");
130 			positionSelection.appendText("Left");
131 			positionSelection.appendText("Right");
132 			positionSelection.addOnChanged(&onPositionSelectionChanged);
133 			positionSelection.setActive(0);
134 
135 			box2.packStart(positionSelection,false,false,0);
136 
137 			box1.packStart(box2,false,false,0);
138 	}
139 
140 	void onPositionSelectionChanged(ComboBoxText comboBoxText)
141 	{
142 		switch ( comboBoxText.getActiveText() )
143 		{
144 			case "Top":
145 				vscale.setValuePos(PositionType.TOP);
146 				hscale.setValuePos(PositionType.TOP);
147 				break;
148 			case "Bottom":
149 				vscale.setValuePos(PositionType.BOTTOM);
150 				hscale.setValuePos(PositionType.BOTTOM);
151 				break;
152 			case "Left":
153 				vscale.setValuePos(PositionType.LEFT);
154 				hscale.setValuePos(PositionType.LEFT);
155 				break;
156 			case "Right":
157 				vscale.setValuePos(PositionType.RIGHT);
158 				hscale.setValuePos(PositionType.RIGHT);
159 				break;
160 			default:
161 				break;
162 
163 		}
164 	}
165 
166 	void displayValues(Button checkButton)
167 	{
168 		vscale.setDrawValue((cast(CheckButton)checkButton).getActive());
169 		hscale.setDrawValue((cast(CheckButton)checkButton).getActive());
170 	}
171 }