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 /**
43  * This tests the gtkD scales and scrollbar widgets
44  */
45 
46 class TestScales : Table //, MenuItemListener
47 {
48 	VScale vscale;
49 	HScale hscale;
50 
51 	this()
52 	{
53 
54 		debug(1)
55 		{
56 			printf("instantiating TestScales\n");
57 		}
58 
59 		super(1,1,0);
60 
61 		createRangeControls();
62 	}
63 
64 	void createRangeControls()
65 	{
66 			Box box1,box2,box3;
67 			Button button;
68 			Scrollbar scrollbar;
69 			Separator separator;
70 			ComboBoxText positionSelection;
71 
72 			Label label;
73 			Scale scale;
74 			Adjustment adj1, adj2;
75 
76 			box1 = new VBox(false,0);
77 			add(box1);
78 
79 			box2 = new HBox(false,0);
80 			box2.setBorderWidth(10);
81 			box1.packStart(box2, true,true,0);
82 
83 			/* value, lower, upper, step_increment, page_increment, page_size */
84 			/* Note that the page_size value only makes a difference for
85 			 * scrollbar widgets, and the highest value you'll get is actually
86 			 * (upper - page_size). */
87 			adj1 = new Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
88 
89 			vscale = new VScale(adj1);
90 			//scale_set_default_values (GTK_SCALE (vscale));
91 			box2.packStart(vscale, true, true, 0);
92 
93 			box3 = new VBox(false,10);
94 			box2.packStart(box3,true,true,0);
95 
96 			/* Reuse the same adjustment */
97 			hscale = new HScale(adj1);
98 			hscale.setSizeRequest(200,-1);
99 			//scale_set_default_values (GTK_SCALE (hscale));
100 			box3.packStart(hscale,true,true,0);
101 
102 			/* Reuse the same adjustment again */
103 			scrollbar = new HScrollbar(adj1);
104 			/* Notice how this causes the scales to always be updated
105 			 * continuously when the scrollbar is moved */
106 			box3.packStart(scrollbar,true,true,0);
107 
108 			box2 = new HBox(false,10);
109 			box2.setBorderWidth(10);
110 			box1.packStart(box2,true,true,0);
111 
112 			/* A checkbutton to control whether the value is displayed or not */
113 			CheckButton cButton = new CheckButton("Display value on scale widgets");
114 			cButton.setActive(true);
115 			cButton.addOnClicked(&displayValues);
116 			box2.packStart(cButton,true,true,0);
117 
118 			box2 = new HBox(false,10);
119 			box2.setBorderWidth(10);
120 
121 			/* An option menu to change the position of the value */
122 			label = new Label("Scale Value Position:");
123 			box2.packStart(label,false,false,0);
124 
125 			positionSelection = new ComboBoxText();
126 			positionSelection.appendText("Top");
127 			positionSelection.appendText("Bottom");
128 			positionSelection.appendText("Left");
129 			positionSelection.appendText("Right");
130 			positionSelection.addOnChanged(&onPositionSelectionChanged);
131 			positionSelection.setActive(0);
132 
133 			box2.packStart(positionSelection,false,false,0);
134 
135 			box1.packStart(box2,false,false,0);
136 	}
137 
138 	void onPositionSelectionChanged(ComboBoxText comboBoxText)
139 	{
140 		switch ( comboBoxText.getActiveText() )
141 		{
142 			case "Top":
143 				vscale.setValuePos(PositionType.TOP);
144 				hscale.setValuePos(PositionType.TOP);
145 				break;
146 			case "Bottom":
147 				vscale.setValuePos(PositionType.BOTTOM);
148 				hscale.setValuePos(PositionType.BOTTOM);
149 				break;
150 			case "Left":
151 				vscale.setValuePos(PositionType.LEFT);
152 				hscale.setValuePos(PositionType.LEFT);
153 				break;
154 			case "Right":
155 				vscale.setValuePos(PositionType.RIGHT);
156 				hscale.setValuePos(PositionType.RIGHT);
157 				break;
158 			default:
159 				break;
160 
161 		}
162 	}
163 
164 	void displayValues(Button checkButton)
165 	{
166 		vscale.setDrawValue((cast(CheckButton)checkButton).getActive());
167 		hscale.setDrawValue((cast(CheckButton)checkButton).getActive());
168 	}
169 }