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 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD 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 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = GtkSpinButton.html 27 * outPack = gtk 28 * outFile = SpinButton 29 * strct = GtkSpinButton 30 * realStrct= 31 * ctorStrct= 32 * clss = SpinButton 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_spin_button_ 41 * - gtk_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * omit signals: 46 * imports: 47 * - gtk.Widget 48 * - gtk.Adjustment 49 * structWrap: 50 * - GtkAdjustment* -> Adjustment 51 * - GtkWidget* -> Widget 52 * module aliases: 53 * local aliases: 54 * overrides: 55 */ 56 57 module gtk.SpinButton; 58 59 public import gtkc.gtktypes; 60 61 private import gtkc.gtk; 62 private import glib.ConstructionException; 63 private import gobject.ObjectG; 64 65 private import gobject.Signals; 66 public import gtkc.gdktypes; 67 68 private import gtk.Widget; 69 private import gtk.Adjustment; 70 71 72 73 private import gtk.Entry; 74 75 /** 76 * Description 77 * A GtkSpinButton is an ideal way to allow the user to set the value of some 78 * attribute. Rather than having to directly type a number into a GtkEntry, 79 * GtkSpinButton allows the user to click on one of two arrows to increment or 80 * decrement the displayed value. A value can still be typed in, with the bonus 81 * that it can be checked to ensure it is in a given range. 82 * The main properties of a GtkSpinButton are through a GtkAdjustment. See the 83 * GtkAdjustment section for more details about an adjustment's properties. 84 * $(DDOC_COMMENT example) 85 * $(DDOC_COMMENT example) 86 */ 87 public class SpinButton : Entry 88 { 89 90 /** the main Gtk struct */ 91 protected GtkSpinButton* gtkSpinButton; 92 93 94 public GtkSpinButton* getSpinButtonStruct() 95 { 96 return gtkSpinButton; 97 } 98 99 100 /** the main Gtk struct as a void* */ 101 protected override void* getStruct() 102 { 103 return cast(void*)gtkSpinButton; 104 } 105 106 /** 107 * Sets our main struct and passes it to the parent class 108 */ 109 public this (GtkSpinButton* gtkSpinButton) 110 { 111 super(cast(GtkEntry*)gtkSpinButton); 112 this.gtkSpinButton = gtkSpinButton; 113 } 114 115 protected override void setStruct(GObject* obj) 116 { 117 super.setStruct(obj); 118 gtkSpinButton = cast(GtkSpinButton*)obj; 119 } 120 121 /** 122 */ 123 int[string] connectedSignals; 124 125 void delegate(GtkScrollType, SpinButton)[] onChangeValueListeners; 126 /** 127 */ 128 void addOnChangeValue(void delegate(GtkScrollType, SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 129 { 130 if ( !("change-value" in connectedSignals) ) 131 { 132 Signals.connectData( 133 getStruct(), 134 "change-value", 135 cast(GCallback)&callBackChangeValue, 136 cast(void*)this, 137 null, 138 connectFlags); 139 connectedSignals["change-value"] = 1; 140 } 141 onChangeValueListeners ~= dlg; 142 } 143 extern(C) static void callBackChangeValue(GtkSpinButton* spinbuttonStruct, GtkScrollType arg1, SpinButton _spinButton) 144 { 145 foreach ( void delegate(GtkScrollType, SpinButton) dlg ; _spinButton.onChangeValueListeners ) 146 { 147 dlg(arg1, _spinButton); 148 } 149 } 150 151 gint delegate(void*, SpinButton)[] onInputListeners; 152 /** 153 */ 154 void addOnInput(gint delegate(void*, SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 155 { 156 if ( !("input" in connectedSignals) ) 157 { 158 Signals.connectData( 159 getStruct(), 160 "input", 161 cast(GCallback)&callBackInput, 162 cast(void*)this, 163 null, 164 connectFlags); 165 connectedSignals["input"] = 1; 166 } 167 onInputListeners ~= dlg; 168 } 169 extern(C) static void callBackInput(GtkSpinButton* spinbuttonStruct, void* arg1, SpinButton _spinButton) 170 { 171 foreach ( gint delegate(void*, SpinButton) dlg ; _spinButton.onInputListeners ) 172 { 173 dlg(arg1, _spinButton); 174 } 175 } 176 177 bool delegate(SpinButton)[] onOutputListeners; 178 /** 179 * The ::output signal can be used to change to formatting 180 * of the value that is displayed in the spin buttons entry. 181 * $(DDOC_COMMENT example) 182 * TRUE if the value has been displayed. 183 */ 184 void addOnOutput(bool delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 185 { 186 if ( !("output" in connectedSignals) ) 187 { 188 Signals.connectData( 189 getStruct(), 190 "output", 191 cast(GCallback)&callBackOutput, 192 cast(void*)this, 193 null, 194 connectFlags); 195 connectedSignals["output"] = 1; 196 } 197 onOutputListeners ~= dlg; 198 } 199 extern(C) static gboolean callBackOutput(GtkSpinButton* spinButtonStruct, SpinButton _spinButton) 200 { 201 foreach ( bool delegate(SpinButton) dlg ; _spinButton.onOutputListeners ) 202 { 203 if ( dlg(_spinButton) ) 204 { 205 return 1; 206 } 207 } 208 209 return 0; 210 } 211 212 void delegate(SpinButton)[] onValueChangedListeners; 213 /** 214 */ 215 void addOnValueChanged(void delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 216 { 217 if ( !("value-changed" in connectedSignals) ) 218 { 219 Signals.connectData( 220 getStruct(), 221 "value-changed", 222 cast(GCallback)&callBackValueChanged, 223 cast(void*)this, 224 null, 225 connectFlags); 226 connectedSignals["value-changed"] = 1; 227 } 228 onValueChangedListeners ~= dlg; 229 } 230 extern(C) static void callBackValueChanged(GtkSpinButton* spinbuttonStruct, SpinButton _spinButton) 231 { 232 foreach ( void delegate(SpinButton) dlg ; _spinButton.onValueChangedListeners ) 233 { 234 dlg(_spinButton); 235 } 236 } 237 238 void delegate(SpinButton)[] onWrappedListeners; 239 /** 240 * The wrapped signal is emitted right after the spinbutton wraps 241 * from its maximum to minimum value or vice-versa. 242 * Since 2.10 243 * See Also 244 * GtkEntry 245 * retrieve text rather than numbers. 246 */ 247 void addOnWrapped(void delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 248 { 249 if ( !("wrapped" in connectedSignals) ) 250 { 251 Signals.connectData( 252 getStruct(), 253 "wrapped", 254 cast(GCallback)&callBackWrapped, 255 cast(void*)this, 256 null, 257 connectFlags); 258 connectedSignals["wrapped"] = 1; 259 } 260 onWrappedListeners ~= dlg; 261 } 262 extern(C) static void callBackWrapped(GtkSpinButton* spinbuttonStruct, SpinButton _spinButton) 263 { 264 foreach ( void delegate(SpinButton) dlg ; _spinButton.onWrappedListeners ) 265 { 266 dlg(_spinButton); 267 } 268 } 269 270 271 /** 272 * Changes the properties of an existing spin button. The adjustment, climb rate, 273 * and number of decimal places are all changed accordingly, after this function call. 274 * Params: 275 * adjustment = a GtkAdjustment. [allow-none] 276 * climbRate = the new climb rate. 277 * digits = the number of decimal places to display in the spin button. 278 */ 279 public void configure(Adjustment adjustment, double climbRate, uint digits) 280 { 281 // void gtk_spin_button_configure (GtkSpinButton *spin_button, GtkAdjustment *adjustment, gdouble climb_rate, guint digits); 282 gtk_spin_button_configure(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits); 283 } 284 285 /** 286 * Creates a new GtkSpinButton. 287 * Params: 288 * adjustment = the GtkAdjustment object that this spin button should use. 289 * climbRate = specifies how much the spin button changes when an arrow is clicked on. 290 * digits = the number of decimal places to display. 291 * Throws: ConstructionException GTK+ fails to create the object. 292 */ 293 public this (Adjustment adjustment, double climbRate, uint digits) 294 { 295 // GtkWidget * gtk_spin_button_new (GtkAdjustment *adjustment, gdouble climb_rate, guint digits); 296 auto p = gtk_spin_button_new((adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits); 297 if(p is null) 298 { 299 throw new ConstructionException("null returned by gtk_spin_button_new((adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits)"); 300 } 301 this(cast(GtkSpinButton*) p); 302 } 303 304 /** 305 * This is a convenience constructor that allows creation of a numeric 306 * GtkSpinButton without manually creating an adjustment. The value is 307 * initially set to the minimum value and a page increment of 10 * step 308 * is the default. The precision of the spin button is equivalent to the 309 * precision of step. 310 * Note that the way in which the precision is derived works best if step 311 * is a power of ten. If the resulting precision is not suitable for your 312 * needs, use gtk_spin_button_set_digits() to correct it. 313 * Params: 314 * min = Minimum allowable value 315 * max = Maximum allowable value 316 * step = Increment added or subtracted by spinning the widget 317 * Throws: ConstructionException GTK+ fails to create the object. 318 */ 319 public this (double min, double max, double step) 320 { 321 // GtkWidget * gtk_spin_button_new_with_range (gdouble min, gdouble max, gdouble step); 322 auto p = gtk_spin_button_new_with_range(min, max, step); 323 if(p is null) 324 { 325 throw new ConstructionException("null returned by gtk_spin_button_new_with_range(min, max, step)"); 326 } 327 this(cast(GtkSpinButton*) p); 328 } 329 330 /** 331 * Replaces the GtkAdjustment associated with spin_button. 332 * Params: 333 * adjustment = a GtkAdjustment to replace the existing adjustment 334 */ 335 public void setAdjustment(Adjustment adjustment) 336 { 337 // void gtk_spin_button_set_adjustment (GtkSpinButton *spin_button, GtkAdjustment *adjustment); 338 gtk_spin_button_set_adjustment(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 339 } 340 341 /** 342 * Get the adjustment associated with a GtkSpinButton 343 * Returns: the GtkAdjustment of spin_button. [transfer none] 344 */ 345 public Adjustment getAdjustment() 346 { 347 // GtkAdjustment * gtk_spin_button_get_adjustment (GtkSpinButton *spin_button); 348 auto p = gtk_spin_button_get_adjustment(gtkSpinButton); 349 350 if(p is null) 351 { 352 return null; 353 } 354 355 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p); 356 } 357 358 /** 359 * Set the precision to be displayed by spin_button. Up to 20 digit precision 360 * is allowed. 361 * Params: 362 * digits = the number of digits after the decimal point to be displayed for the spin button's value 363 */ 364 public void setDigits(uint digits) 365 { 366 // void gtk_spin_button_set_digits (GtkSpinButton *spin_button, guint digits); 367 gtk_spin_button_set_digits(gtkSpinButton, digits); 368 } 369 370 /** 371 * Sets the step and page increments for spin_button. This affects how 372 * quickly the value changes when the spin button's arrows are activated. 373 * Params: 374 * step = increment applied for a button 1 press. 375 * page = increment applied for a button 2 press. 376 */ 377 public void setIncrements(double step, double page) 378 { 379 // void gtk_spin_button_set_increments (GtkSpinButton *spin_button, gdouble step, gdouble page); 380 gtk_spin_button_set_increments(gtkSpinButton, step, page); 381 } 382 383 /** 384 * Sets the minimum and maximum allowable values for spin_button 385 * Params: 386 * min = minimum allowable value 387 * max = maximum allowable value 388 */ 389 public void setRange(double min, double max) 390 { 391 // void gtk_spin_button_set_range (GtkSpinButton *spin_button, gdouble min, gdouble max); 392 gtk_spin_button_set_range(gtkSpinButton, min, max); 393 } 394 395 /** 396 * Get the value spin_button represented as an integer. 397 * Returns: the value of spin_button 398 */ 399 public int getValueAsInt() 400 { 401 // gint gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button); 402 return gtk_spin_button_get_value_as_int(gtkSpinButton); 403 } 404 405 /** 406 * Set the value of spin_button. 407 * Params: 408 * value = the new value 409 */ 410 public void setValue(double value) 411 { 412 // void gtk_spin_button_set_value (GtkSpinButton *spin_button, gdouble value); 413 gtk_spin_button_set_value(gtkSpinButton, value); 414 } 415 416 /** 417 * Sets the update behavior of a spin button. This determines whether the 418 * spin button is always updated or only when a valid value is set. 419 * Params: 420 * policy = a GtkSpinButtonUpdatePolicy value 421 */ 422 public void setUpdatePolicy(GtkSpinButtonUpdatePolicy policy) 423 { 424 // void gtk_spin_button_set_update_policy (GtkSpinButton *spin_button, GtkSpinButtonUpdatePolicy policy); 425 gtk_spin_button_set_update_policy(gtkSpinButton, policy); 426 } 427 428 /** 429 * Sets the flag that determines if non-numeric text can be typed into 430 * the spin button. 431 * Params: 432 * numeric = flag indicating if only numeric entry is allowed. 433 */ 434 public void setNumeric(int numeric) 435 { 436 // void gtk_spin_button_set_numeric (GtkSpinButton *spin_button, gboolean numeric); 437 gtk_spin_button_set_numeric(gtkSpinButton, numeric); 438 } 439 440 /** 441 * Increment or decrement a spin button's value in a specified direction 442 * by a specified amount. 443 * Params: 444 * direction = a GtkSpinType indicating the direction to spin. 445 * increment = step increment to apply in the specified direction. 446 */ 447 public void spin(GtkSpinType direction, double increment) 448 { 449 // void gtk_spin_button_spin (GtkSpinButton *spin_button, GtkSpinType direction, gdouble increment); 450 gtk_spin_button_spin(gtkSpinButton, direction, increment); 451 } 452 453 /** 454 * Sets the flag that determines if a spin button value wraps around to the 455 * opposite limit when the upper or lower limit of the range is exceeded. 456 * Params: 457 * wrap = a flag indicating if wrapping behavior is performed. 458 */ 459 public void setWrap(int wrap) 460 { 461 // void gtk_spin_button_set_wrap (GtkSpinButton *spin_button, gboolean wrap); 462 gtk_spin_button_set_wrap(gtkSpinButton, wrap); 463 } 464 465 /** 466 * Sets the policy as to whether values are corrected to the nearest step 467 * increment when a spin button is activated after providing an invalid value. 468 * Params: 469 * snapToTicks = a flag indicating if invalid values should be corrected. 470 */ 471 public void setSnapToTicks(int snapToTicks) 472 { 473 // void gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button, gboolean snap_to_ticks); 474 gtk_spin_button_set_snap_to_ticks(gtkSpinButton, snapToTicks); 475 } 476 477 /** 478 * Manually force an update of the spin button. 479 */ 480 public void update() 481 { 482 // void gtk_spin_button_update (GtkSpinButton *spin_button); 483 gtk_spin_button_update(gtkSpinButton); 484 } 485 486 /** 487 * Fetches the precision of spin_button. See gtk_spin_button_set_digits(). 488 * Returns: the current precision 489 */ 490 public uint getDigits() 491 { 492 // guint gtk_spin_button_get_digits (GtkSpinButton *spin_button); 493 return gtk_spin_button_get_digits(gtkSpinButton); 494 } 495 496 /** 497 * Gets the current step and page the increments used by spin_button. See 498 * gtk_spin_button_set_increments(). 499 * Params: 500 * step = location to store step increment, or NULL. [out][allow-none] 501 * page = location to store page increment, or NULL. [out][allow-none] 502 */ 503 public void getIncrements(out double step, out double page) 504 { 505 // void gtk_spin_button_get_increments (GtkSpinButton *spin_button, gdouble *step, gdouble *page); 506 gtk_spin_button_get_increments(gtkSpinButton, &step, &page); 507 } 508 509 /** 510 * Returns whether non-numeric text can be typed into the spin button. 511 * See gtk_spin_button_set_numeric(). 512 * Returns: TRUE if only numeric text can be entered 513 */ 514 public int getNumeric() 515 { 516 // gboolean gtk_spin_button_get_numeric (GtkSpinButton *spin_button); 517 return gtk_spin_button_get_numeric(gtkSpinButton); 518 } 519 520 /** 521 * Gets the range allowed for spin_button. See 522 * gtk_spin_button_set_range(). 523 * Params: 524 * min = location to store minimum allowed value, or NULL. [out][allow-none] 525 * max = location to store maximum allowed value, or NULL. [out][allow-none] 526 */ 527 public void getRange(out double min, out double max) 528 { 529 // void gtk_spin_button_get_range (GtkSpinButton *spin_button, gdouble *min, gdouble *max); 530 gtk_spin_button_get_range(gtkSpinButton, &min, &max); 531 } 532 533 /** 534 * Returns whether the values are corrected to the nearest step. See 535 * gtk_spin_button_set_snap_to_ticks(). 536 * Returns: TRUE if values are snapped to the nearest step. 537 */ 538 public int getSnapToTicks() 539 { 540 // gboolean gtk_spin_button_get_snap_to_ticks (GtkSpinButton *spin_button); 541 return gtk_spin_button_get_snap_to_ticks(gtkSpinButton); 542 } 543 544 /** 545 * Gets the update behavior of a spin button. See 546 * gtk_spin_button_set_update_policy(). 547 * Returns: the current update policy 548 */ 549 public GtkSpinButtonUpdatePolicy getUpdatePolicy() 550 { 551 // GtkSpinButtonUpdatePolicy gtk_spin_button_get_update_policy (GtkSpinButton *spin_button); 552 return gtk_spin_button_get_update_policy(gtkSpinButton); 553 } 554 555 /** 556 * Get the value in the spin_button. 557 * Returns: the value of spin_button 558 */ 559 public double getValue() 560 { 561 // gdouble gtk_spin_button_get_value (GtkSpinButton *spin_button); 562 return gtk_spin_button_get_value(gtkSpinButton); 563 } 564 565 /** 566 * Returns whether the spin button's value wraps around to the 567 * opposite limit when the upper or lower limit of the range is 568 * exceeded. See gtk_spin_button_set_wrap(). 569 * Returns: TRUE if the spin button wraps around 570 */ 571 public int getWrap() 572 { 573 // gboolean gtk_spin_button_get_wrap (GtkSpinButton *spin_button); 574 return gtk_spin_button_get_wrap(gtkSpinButton); 575 } 576 }