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.Box; 29 private import gtk.Button; 30 private import gtk.Scrollbar; 31 private import gtk.Separator; 32 //private import gtk.OptionMenu; 33 private import gtk.Label; 34 private import gtk.Scale; 35 private import gtk.Adjustment; 36 private import gtk.VBox; 37 private import gtk.HBox; 38 private import gtk.HScrollbar; 39 private import gtk.Range; 40 41 /** 42 * This tests the gtkD scales and scrollbar widgets 43 */ 44 45 class TestScales : Table //, MenuItemListener 46 { 47 VScale vscale; 48 HScale hscale; 49 50 this() 51 { 52 53 debug(1) 54 { 55 printf("instantiating TestScales\n"); 56 } 57 58 super(1,1,0); 59 60 createRangeControls(); 61 } 62 private import gtk.ComboBox; 63 void createRangeControls() 64 { 65 66 Box box1,box2,box3; 67 Button button; 68 Scrollbar scrollbar; 69 Separator separator; 70 ComboBox positionSelection; 71 ComboBox updateSelection; 72 73 Label label; 74 Scale scale; 75 Adjustment adj1, adj2; 76 77 box1 = new VBox(false,0); 78 add(box1); 79 80 box2 = new HBox(false,0); 81 box2.setBorderWidth(10); 82 box1.packStart(box2, true,true,0); 83 84 /* value, lower, upper, step_increment, page_increment, page_size */ 85 /* Note that the page_size value only makes a difference for 86 * scrollbar widgets, and the highest value you'll get is actually 87 * (upper - page_size). */ 88 adj1 = new Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0); 89 90 vscale = new VScale(adj1); 91 //scale_set_default_values (GTK_SCALE (vscale)); 92 box2.packStart(vscale, true, true, 0); 93 94 box3 = new VBox(false,10); 95 box2.packStart(box3,true,true,0); 96 97 /* Reuse the same adjustment */ 98 hscale = new HScale(adj1); 99 hscale.setSizeRequest(200,-1); 100 //scale_set_default_values (GTK_SCALE (hscale)); 101 box3.packStart(hscale,true,true,0); 102 103 /* Reuse the same adjustment again */ 104 scrollbar = new HScrollbar(adj1); 105 /* Notice how this causes the scales to always be updated 106 * continuously when the scrollbar is moved */ 107 scrollbar.setUpdatePolicy(UpdateType.CONTINUOUS); 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 ComboBox(); 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 box2 = new HBox(false,10); 140 box2.setBorderWidth(10); 141 142 /* Yet another option menu, this time for the update policy of the scale widgets */ 143 label = new Label("Scale Update Policy:"); 144 box2.packStart(label,false,false,0); 145 146 updateSelection = new ComboBox(); 147 148 updateSelection.appendText("Continuous"); 149 updateSelection.appendText("Discontinuous"); 150 updateSelection.appendText("Delayed"); 151 updateSelection.addOnChanged(&onUpdateSelectionChanged); 152 updateSelection.setActive(0); 153 154 box2.packStart(updateSelection,false,false,0); 155 box1.packStart(box2,false,false,0); 156 157 158 /** 159 * Here is a bit a pure C GTK+ code. 160 * This code would compile and execute in D, 161 * we just need to define the functions as extern. 162 */ 163 /+ 164 box2 = gtk_hbox_new (FALSE, 10); 165 gtk_container_set_border_width (GTK_CONTAINER (box2), 10); 166 167 /* An HScale widget for adjusting the number of digits on the 168 * sample scales. */ 169 label = gtk_label_new ("Scale Digits:"); 170 gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0); 171 gtk_widget_show (label); 172 173 adj2 = gtk_adjustment_new (1.0, 0.0, 5.0, 1.0, 1.0, 0.0); 174 g_signal_connect (G_OBJECT (adj2), "value_changed", 175 G_CALLBACK (cb_digits_scale), NULL); 176 scale = gtk_hscale_new (GTK_ADJUSTMENT (adj2)); 177 gtk_scale_set_digits (GTK_SCALE (scale), 0); 178 gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0); 179 gtk_widget_show (scale); 180 181 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); 182 gtk_widget_show (box2); 183 184 box2 = gtk_hbox_new (FALSE, 10); 185 gtk_container_set_border_width (GTK_CONTAINER (box2), 10); 186 187 /* And, one last HScale widget for adjusting the page size of the 188 * scrollbar. */ 189 label = gtk_label_new ("Scrollbar Page Size:"); 190 gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0); 191 gtk_widget_show (label); 192 193 adj2 = gtk_adjustment_new (1.0, 1.0, 101.0, 1.0, 1.0, 0.0); 194 g_signal_connect (G_OBJECT (adj2), "value_changed", 195 G_CALLBACK (cb_page_size), (gpointer) adj1); 196 scale = gtk_hscale_new (GTK_ADJUSTMENT (adj2)); 197 gtk_scale_set_digits (GTK_SCALE (scale), 0); 198 gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0); 199 gtk_widget_show (scale); 200 201 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); 202 gtk_widget_show (box2); 203 204 separator = gtk_hseparator_new (); 205 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); 206 gtk_widget_show (separator); 207 208 box2 = gtk_vbox_new (FALSE, 10); 209 gtk_container_set_border_width (GTK_CONTAINER (box2), 10); 210 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); 211 gtk_widget_show (box2); 212 213 button = gtk_button_new_with_label ("Quit"); 214 g_signal_connect_swapped (G_OBJECT (button), "clicked", 215 G_CALLBACK (gtk_main_quit), 216 NULL); 217 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); 218 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); 219 gtk_widget_grab_default (button); 220 gtk_widget_show (button); 221 222 gtk_widget_show (window); 223 +/ 224 225 } 226 227 void onPositionSelectionChanged(ComboBox comboBox) 228 { 229 230 switch ( comboBox.getActiveText() ) 231 { 232 case "Top": 233 vscale.setValuePos(PositionType.TOP); 234 hscale.setValuePos(PositionType.TOP); 235 break; 236 case "Bottom": 237 vscale.setValuePos(PositionType.BOTTOM); 238 hscale.setValuePos(PositionType.BOTTOM); 239 break; 240 case "Left": 241 vscale.setValuePos(PositionType.LEFT); 242 hscale.setValuePos(PositionType.LEFT); 243 break; 244 case "Right": 245 vscale.setValuePos(PositionType.RIGHT); 246 hscale.setValuePos(PositionType.RIGHT); 247 break; 248 default: 249 break; 250 251 } 252 } 253 254 void onUpdateSelectionChanged(ComboBox comboBox) 255 { 256 switch ( comboBox.getActiveText() ) 257 { 258 case "Continuous": 259 vscale.setUpdatePolicy(UpdateType.CONTINUOUS); 260 hscale.setUpdatePolicy(UpdateType.CONTINUOUS); 261 break; 262 case "Discontinuous": 263 vscale.setUpdatePolicy(UpdateType.DISCONTINUOUS); 264 hscale.setUpdatePolicy(UpdateType.DISCONTINUOUS); 265 break; 266 case "Delayed": 267 vscale.setUpdatePolicy(UpdateType.DELAYED); 268 hscale.setUpdatePolicy(UpdateType.DELAYED); 269 break; 270 default: 271 break; 272 } 273 } 274 275 276 277 /* 278 void activateItemCallback(MenuItem menuItem, char [] action) 279 { 280 } 281 282 void activateCallback(MenuItem menuItem, char [] action) 283 { 284 switch ( action ) 285 { 286 case "ValueTop": 287 vscale.setValuePos(Scale.TOP); 288 hscale.setValuePos(Scale.TOP); 289 break; 290 case "ValueBottom": 291 vscale.setValuePos(Scale.BOTTOM); 292 hscale.setValuePos(Scale.BOTTOM); 293 break; 294 case "ValueLeft": 295 vscale.setValuePos(Scale.LEFT); 296 hscale.setValuePos(Scale.LEFT); 297 break; 298 case "ValueRight": 299 vscale.setValuePos(Scale.RIGHT); 300 hscale.setValuePos(Scale.RIGHT); 301 break; 302 case "ScaleContinuous": 303 vscale.setUpdatePolicy(Scale.CONTINUOUS); 304 hscale.setUpdatePolicy(Scale.CONTINUOUS); 305 break; 306 case "ScaleDiscontinuous": 307 vscale.setUpdatePolicy(Scale.DISCONTINUOUS); 308 hscale.setUpdatePolicy(Scale.DISCONTINUOUS); 309 break; 310 case "ScaleDelayed": 311 vscale.setUpdatePolicy(Scale.DELAYED); 312 hscale.setUpdatePolicy(Scale.DELAYED); 313 break; 314 default: 315 printf("menuItem.action %.*s received\n",action); 316 break; 317 318 } 319 } 320 */ 321 void displayValues(Button checkButton) 322 { 323 //CheckButton cb = (CheckButton)button; 324 //printf("check button %X %X\n",button,(CheckButton)button); 325 //printf("button.toString %.*s\n",button.toString()); 326 vscale.setDrawValue((cast(CheckButton)checkButton).getActive()); 327 hscale.setDrawValue((cast(CheckButton)checkButton).getActive()); 328 } 329 330 }