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 module gtk.Range; 26 27 private import gobject.ObjectG; 28 private import gobject.Signals; 29 private import gtk.Adjustment; 30 private import gtk.OrientableIF; 31 private import gtk.OrientableT; 32 private import gtk.Widget; 33 private import gtkc.gtk; 34 public import gtkc.gtktypes; 35 private import std.algorithm; 36 37 38 /** 39 * #GtkRange is the common base class for widgets which visualize an 40 * adjustment, e.g #GtkScale or #GtkScrollbar. 41 * 42 * Apart from signals for monitoring the parameters of the adjustment, 43 * #GtkRange provides properties and methods for influencing the sensitivity 44 * of the “steppers”. It also provides properties and methods for setting a 45 * “fill level” on range widgets. See gtk_range_set_fill_level(). 46 */ 47 public class Range : Widget, OrientableIF 48 { 49 /** the main Gtk struct */ 50 protected GtkRange* gtkRange; 51 52 /** Get the main Gtk struct */ 53 public GtkRange* getRangeStruct(bool transferOwnership = false) 54 { 55 if (transferOwnership) 56 ownedRef = false; 57 return gtkRange; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected override void* getStruct() 62 { 63 return cast(void*)gtkRange; 64 } 65 66 protected override void setStruct(GObject* obj) 67 { 68 gtkRange = cast(GtkRange*)obj; 69 super.setStruct(obj); 70 } 71 72 /** 73 * Sets our main struct and passes it to the parent class. 74 */ 75 public this (GtkRange* gtkRange, bool ownedRef = false) 76 { 77 this.gtkRange = gtkRange; 78 super(cast(GtkWidget*)gtkRange, ownedRef); 79 } 80 81 // add the Orientable capabilities 82 mixin OrientableT!(GtkRange); 83 84 85 /** */ 86 public static GType getType() 87 { 88 return gtk_range_get_type(); 89 } 90 91 /** 92 * Get the #GtkAdjustment which is the “model” object for #GtkRange. 93 * See gtk_range_set_adjustment() for details. 94 * The return value does not have a reference added, so should not 95 * be unreferenced. 96 * 97 * Returns: a #GtkAdjustment 98 */ 99 public Adjustment getAdjustment() 100 { 101 auto p = gtk_range_get_adjustment(gtkRange); 102 103 if(p is null) 104 { 105 return null; 106 } 107 108 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p); 109 } 110 111 /** 112 * Gets the current position of the fill level indicator. 113 * 114 * Returns: The current fill level 115 * 116 * Since: 2.12 117 */ 118 public double getFillLevel() 119 { 120 return gtk_range_get_fill_level(gtkRange); 121 } 122 123 /** 124 * Gets the value set by gtk_range_set_flippable(). 125 * 126 * Returns: %TRUE if the range is flippable 127 * 128 * Since: 2.18 129 */ 130 public bool getFlippable() 131 { 132 return gtk_range_get_flippable(gtkRange) != 0; 133 } 134 135 /** 136 * Gets the value set by gtk_range_set_inverted(). 137 * 138 * Returns: %TRUE if the range is inverted 139 */ 140 public bool getInverted() 141 { 142 return gtk_range_get_inverted(gtkRange) != 0; 143 } 144 145 /** 146 * Gets the sensitivity policy for the stepper that points to the 147 * 'lower' end of the GtkRange’s adjustment. 148 * 149 * Returns: The lower stepper’s sensitivity policy. 150 * 151 * Since: 2.10 152 */ 153 public GtkSensitivityType getLowerStepperSensitivity() 154 { 155 return gtk_range_get_lower_stepper_sensitivity(gtkRange); 156 } 157 158 /** 159 * This function is useful mainly for #GtkRange subclasses. 160 * 161 * See gtk_range_set_min_slider_size(). 162 * 163 * Deprecated: Use the min-height/min-width CSS properties on the slider 164 * node. 165 * 166 * Returns: The minimum size of the range’s slider. 167 * 168 * Since: 2.20 169 */ 170 public int getMinSliderSize() 171 { 172 return gtk_range_get_min_slider_size(gtkRange); 173 } 174 175 /** 176 * This function returns the area that contains the range’s trough 177 * and its steppers, in widget->window coordinates. 178 * 179 * This function is useful mainly for #GtkRange subclasses. 180 * 181 * Params: 182 * rangeRect = return location for the range rectangle 183 * 184 * Since: 2.20 185 */ 186 public void getRangeRect(out GdkRectangle rangeRect) 187 { 188 gtk_range_get_range_rect(gtkRange, &rangeRect); 189 } 190 191 /** 192 * Gets whether the range is restricted to the fill level. 193 * 194 * Returns: %TRUE if @range is restricted to the fill level. 195 * 196 * Since: 2.12 197 */ 198 public bool getRestrictToFillLevel() 199 { 200 return gtk_range_get_restrict_to_fill_level(gtkRange) != 0; 201 } 202 203 /** 204 * Gets the number of digits to round the value to when 205 * it changes. See #GtkRange::change-value. 206 * 207 * Returns: the number of digits to round to 208 * 209 * Since: 2.24 210 */ 211 public int getRoundDigits() 212 { 213 return gtk_range_get_round_digits(gtkRange); 214 } 215 216 /** 217 * Gets whether the range displays the fill level graphically. 218 * 219 * Returns: %TRUE if @range shows the fill level. 220 * 221 * Since: 2.12 222 */ 223 public bool getShowFillLevel() 224 { 225 return gtk_range_get_show_fill_level(gtkRange) != 0; 226 } 227 228 /** 229 * This function returns sliders range along the long dimension, 230 * in widget->window coordinates. 231 * 232 * This function is useful mainly for #GtkRange subclasses. 233 * 234 * Params: 235 * sliderStart = return location for the slider's 236 * start, or %NULL 237 * sliderEnd = return location for the slider's 238 * end, or %NULL 239 * 240 * Since: 2.20 241 */ 242 public void getSliderRange(out int sliderStart, out int sliderEnd) 243 { 244 gtk_range_get_slider_range(gtkRange, &sliderStart, &sliderEnd); 245 } 246 247 /** 248 * This function is useful mainly for #GtkRange subclasses. 249 * 250 * See gtk_range_set_slider_size_fixed(). 251 * 252 * Returns: whether the range’s slider has a fixed size. 253 * 254 * Since: 2.20 255 */ 256 public bool getSliderSizeFixed() 257 { 258 return gtk_range_get_slider_size_fixed(gtkRange) != 0; 259 } 260 261 /** 262 * Gets the sensitivity policy for the stepper that points to the 263 * 'upper' end of the GtkRange’s adjustment. 264 * 265 * Returns: The upper stepper’s sensitivity policy. 266 * 267 * Since: 2.10 268 */ 269 public GtkSensitivityType getUpperStepperSensitivity() 270 { 271 return gtk_range_get_upper_stepper_sensitivity(gtkRange); 272 } 273 274 /** 275 * Gets the current value of the range. 276 * 277 * Returns: current value of the range. 278 */ 279 public double getValue() 280 { 281 return gtk_range_get_value(gtkRange); 282 } 283 284 /** 285 * Sets the adjustment to be used as the “model” object for this range 286 * widget. The adjustment indicates the current range value, the 287 * minimum and maximum range values, the step/page increments used 288 * for keybindings and scrolling, and the page size. The page size 289 * is normally 0 for #GtkScale and nonzero for #GtkScrollbar, and 290 * indicates the size of the visible area of the widget being scrolled. 291 * The page size affects the size of the scrollbar slider. 292 * 293 * Params: 294 * adjustment = a #GtkAdjustment 295 */ 296 public void setAdjustment(Adjustment adjustment) 297 { 298 gtk_range_set_adjustment(gtkRange, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 299 } 300 301 /** 302 * Set the new position of the fill level indicator. 303 * 304 * The “fill level” is probably best described by its most prominent 305 * use case, which is an indicator for the amount of pre-buffering in 306 * a streaming media player. In that use case, the value of the range 307 * would indicate the current play position, and the fill level would 308 * be the position up to which the file/stream has been downloaded. 309 * 310 * This amount of prebuffering can be displayed on the range’s trough 311 * and is themeable separately from the trough. To enable fill level 312 * display, use gtk_range_set_show_fill_level(). The range defaults 313 * to not showing the fill level. 314 * 315 * Additionally, it’s possible to restrict the range’s slider position 316 * to values which are smaller than the fill level. This is controller 317 * by gtk_range_set_restrict_to_fill_level() and is by default 318 * enabled. 319 * 320 * Params: 321 * fillLevel = the new position of the fill level indicator 322 * 323 * Since: 2.12 324 */ 325 public void setFillLevel(double fillLevel) 326 { 327 gtk_range_set_fill_level(gtkRange, fillLevel); 328 } 329 330 /** 331 * If a range is flippable, it will switch its direction if it is 332 * horizontal and its direction is %GTK_TEXT_DIR_RTL. 333 * 334 * See gtk_widget_get_direction(). 335 * 336 * Params: 337 * flippable = %TRUE to make the range flippable 338 * 339 * Since: 2.18 340 */ 341 public void setFlippable(bool flippable) 342 { 343 gtk_range_set_flippable(gtkRange, flippable); 344 } 345 346 /** 347 * Sets the step and page sizes for the range. 348 * The step size is used when the user clicks the #GtkScrollbar 349 * arrows or moves #GtkScale via arrow keys. The page size 350 * is used for example when moving via Page Up or Page Down keys. 351 * 352 * Params: 353 * step = step size 354 * page = page size 355 */ 356 public void setIncrements(double step, double page) 357 { 358 gtk_range_set_increments(gtkRange, step, page); 359 } 360 361 /** 362 * Ranges normally move from lower to higher values as the 363 * slider moves from top to bottom or left to right. Inverted 364 * ranges have higher values at the top or on the right rather than 365 * on the bottom or left. 366 * 367 * Params: 368 * setting = %TRUE to invert the range 369 */ 370 public void setInverted(bool setting) 371 { 372 gtk_range_set_inverted(gtkRange, setting); 373 } 374 375 /** 376 * Sets the sensitivity policy for the stepper that points to the 377 * 'lower' end of the GtkRange’s adjustment. 378 * 379 * Params: 380 * sensitivity = the lower stepper’s sensitivity policy. 381 * 382 * Since: 2.10 383 */ 384 public void setLowerStepperSensitivity(GtkSensitivityType sensitivity) 385 { 386 gtk_range_set_lower_stepper_sensitivity(gtkRange, sensitivity); 387 } 388 389 /** 390 * Sets the minimum size of the range’s slider. 391 * 392 * This function is useful mainly for #GtkRange subclasses. 393 * 394 * Deprecated: Use the min-height/min-width CSS properties on the slider 395 * node. 396 * 397 * Params: 398 * minSize = The slider’s minimum size 399 * 400 * Since: 2.20 401 */ 402 public void setMinSliderSize(int minSize) 403 { 404 gtk_range_set_min_slider_size(gtkRange, minSize); 405 } 406 407 /** 408 * Sets the allowable values in the #GtkRange, and clamps the range 409 * value to be between @min and @max. (If the range has a non-zero 410 * page size, it is clamped between @min and @max - page-size.) 411 * 412 * Params: 413 * min = minimum range value 414 * max = maximum range value 415 */ 416 public void setRange(double min, double max) 417 { 418 gtk_range_set_range(gtkRange, min, max); 419 } 420 421 /** 422 * Sets whether the slider is restricted to the fill level. See 423 * gtk_range_set_fill_level() for a general description of the fill 424 * level concept. 425 * 426 * Params: 427 * restrictToFillLevel = Whether the fill level restricts slider movement. 428 * 429 * Since: 2.12 430 */ 431 public void setRestrictToFillLevel(bool restrictToFillLevel) 432 { 433 gtk_range_set_restrict_to_fill_level(gtkRange, restrictToFillLevel); 434 } 435 436 /** 437 * Sets the number of digits to round the value to when 438 * it changes. See #GtkRange::change-value. 439 * 440 * Params: 441 * roundDigits = the precision in digits, or -1 442 * 443 * Since: 2.24 444 */ 445 public void setRoundDigits(int roundDigits) 446 { 447 gtk_range_set_round_digits(gtkRange, roundDigits); 448 } 449 450 /** 451 * Sets whether a graphical fill level is show on the trough. See 452 * gtk_range_set_fill_level() for a general description of the fill 453 * level concept. 454 * 455 * Params: 456 * showFillLevel = Whether a fill level indicator graphics is shown. 457 * 458 * Since: 2.12 459 */ 460 public void setShowFillLevel(bool showFillLevel) 461 { 462 gtk_range_set_show_fill_level(gtkRange, showFillLevel); 463 } 464 465 /** 466 * Sets whether the range’s slider has a fixed size, or a size that 467 * depends on its adjustment’s page size. 468 * 469 * This function is useful mainly for #GtkRange subclasses. 470 * 471 * Params: 472 * sizeFixed = %TRUE to make the slider size constant 473 * 474 * Since: 2.20 475 */ 476 public void setSliderSizeFixed(bool sizeFixed) 477 { 478 gtk_range_set_slider_size_fixed(gtkRange, sizeFixed); 479 } 480 481 /** 482 * Sets the sensitivity policy for the stepper that points to the 483 * 'upper' end of the GtkRange’s adjustment. 484 * 485 * Params: 486 * sensitivity = the upper stepper’s sensitivity policy. 487 * 488 * Since: 2.10 489 */ 490 public void setUpperStepperSensitivity(GtkSensitivityType sensitivity) 491 { 492 gtk_range_set_upper_stepper_sensitivity(gtkRange, sensitivity); 493 } 494 495 /** 496 * Sets the current value of the range; if the value is outside the 497 * minimum or maximum range values, it will be clamped to fit inside 498 * them. The range emits the #GtkRange::value-changed signal if the 499 * value changes. 500 * 501 * Params: 502 * value = new value of the range 503 */ 504 public void setValue(double value) 505 { 506 gtk_range_set_value(gtkRange, value); 507 } 508 509 protected class OnAdjustBoundsDelegateWrapper 510 { 511 void delegate(double, Range) dlg; 512 gulong handlerId; 513 514 this(void delegate(double, Range) dlg) 515 { 516 this.dlg = dlg; 517 onAdjustBoundsListeners ~= this; 518 } 519 520 void remove(OnAdjustBoundsDelegateWrapper source) 521 { 522 foreach(index, wrapper; onAdjustBoundsListeners) 523 { 524 if (wrapper.handlerId == source.handlerId) 525 { 526 onAdjustBoundsListeners[index] = null; 527 onAdjustBoundsListeners = std.algorithm.remove(onAdjustBoundsListeners, index); 528 break; 529 } 530 } 531 } 532 } 533 OnAdjustBoundsDelegateWrapper[] onAdjustBoundsListeners; 534 535 /** 536 * Emitted before clamping a value, to give the application a 537 * chance to adjust the bounds. 538 * 539 * Params: 540 * value = the value before we clamp 541 */ 542 gulong addOnAdjustBounds(void delegate(double, Range) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 543 { 544 auto wrapper = new OnAdjustBoundsDelegateWrapper(dlg); 545 wrapper.handlerId = Signals.connectData( 546 this, 547 "adjust-bounds", 548 cast(GCallback)&callBackAdjustBounds, 549 cast(void*)wrapper, 550 cast(GClosureNotify)&callBackAdjustBoundsDestroy, 551 connectFlags); 552 return wrapper.handlerId; 553 } 554 555 extern(C) static void callBackAdjustBounds(GtkRange* rangeStruct, double value, OnAdjustBoundsDelegateWrapper wrapper) 556 { 557 wrapper.dlg(value, wrapper.outer); 558 } 559 560 extern(C) static void callBackAdjustBoundsDestroy(OnAdjustBoundsDelegateWrapper wrapper, GClosure* closure) 561 { 562 wrapper.remove(wrapper); 563 } 564 565 protected class OnChangeValueDelegateWrapper 566 { 567 bool delegate(GtkScrollType, double, Range) dlg; 568 gulong handlerId; 569 570 this(bool delegate(GtkScrollType, double, Range) dlg) 571 { 572 this.dlg = dlg; 573 onChangeValueListeners ~= this; 574 } 575 576 void remove(OnChangeValueDelegateWrapper source) 577 { 578 foreach(index, wrapper; onChangeValueListeners) 579 { 580 if (wrapper.handlerId == source.handlerId) 581 { 582 onChangeValueListeners[index] = null; 583 onChangeValueListeners = std.algorithm.remove(onChangeValueListeners, index); 584 break; 585 } 586 } 587 } 588 } 589 OnChangeValueDelegateWrapper[] onChangeValueListeners; 590 591 /** 592 * The #GtkRange::change-value signal is emitted when a scroll action is 593 * performed on a range. It allows an application to determine the 594 * type of scroll event that occurred and the resultant new value. 595 * The application can handle the event itself and return %TRUE to 596 * prevent further processing. Or, by returning %FALSE, it can pass 597 * the event to other handlers until the default GTK+ handler is 598 * reached. 599 * 600 * The value parameter is unrounded. An application that overrides 601 * the GtkRange::change-value signal is responsible for clamping the 602 * value to the desired number of decimal digits; the default GTK+ 603 * handler clamps the value based on #GtkRange:round-digits. 604 * 605 * Params: 606 * scroll = the type of scroll action that was performed 607 * value = the new value resulting from the scroll action 608 * 609 * Returns: %TRUE to prevent other handlers from being invoked for 610 * the signal, %FALSE to propagate the signal further 611 * 612 * Since: 2.6 613 */ 614 gulong addOnChangeValue(bool delegate(GtkScrollType, double, Range) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 615 { 616 auto wrapper = new OnChangeValueDelegateWrapper(dlg); 617 wrapper.handlerId = Signals.connectData( 618 this, 619 "change-value", 620 cast(GCallback)&callBackChangeValue, 621 cast(void*)wrapper, 622 cast(GClosureNotify)&callBackChangeValueDestroy, 623 connectFlags); 624 return wrapper.handlerId; 625 } 626 627 extern(C) static int callBackChangeValue(GtkRange* rangeStruct, GtkScrollType scroll, double value, OnChangeValueDelegateWrapper wrapper) 628 { 629 return wrapper.dlg(scroll, value, wrapper.outer); 630 } 631 632 extern(C) static void callBackChangeValueDestroy(OnChangeValueDelegateWrapper wrapper, GClosure* closure) 633 { 634 wrapper.remove(wrapper); 635 } 636 637 protected class OnMoveSliderDelegateWrapper 638 { 639 void delegate(GtkScrollType, Range) dlg; 640 gulong handlerId; 641 642 this(void delegate(GtkScrollType, Range) dlg) 643 { 644 this.dlg = dlg; 645 onMoveSliderListeners ~= this; 646 } 647 648 void remove(OnMoveSliderDelegateWrapper source) 649 { 650 foreach(index, wrapper; onMoveSliderListeners) 651 { 652 if (wrapper.handlerId == source.handlerId) 653 { 654 onMoveSliderListeners[index] = null; 655 onMoveSliderListeners = std.algorithm.remove(onMoveSliderListeners, index); 656 break; 657 } 658 } 659 } 660 } 661 OnMoveSliderDelegateWrapper[] onMoveSliderListeners; 662 663 /** 664 * Virtual function that moves the slider. Used for keybindings. 665 * 666 * Params: 667 * step = how to move the slider 668 */ 669 gulong addOnMoveSlider(void delegate(GtkScrollType, Range) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 670 { 671 auto wrapper = new OnMoveSliderDelegateWrapper(dlg); 672 wrapper.handlerId = Signals.connectData( 673 this, 674 "move-slider", 675 cast(GCallback)&callBackMoveSlider, 676 cast(void*)wrapper, 677 cast(GClosureNotify)&callBackMoveSliderDestroy, 678 connectFlags); 679 return wrapper.handlerId; 680 } 681 682 extern(C) static void callBackMoveSlider(GtkRange* rangeStruct, GtkScrollType step, OnMoveSliderDelegateWrapper wrapper) 683 { 684 wrapper.dlg(step, wrapper.outer); 685 } 686 687 extern(C) static void callBackMoveSliderDestroy(OnMoveSliderDelegateWrapper wrapper, GClosure* closure) 688 { 689 wrapper.remove(wrapper); 690 } 691 692 protected class OnValueChangedDelegateWrapper 693 { 694 void delegate(Range) dlg; 695 gulong handlerId; 696 697 this(void delegate(Range) dlg) 698 { 699 this.dlg = dlg; 700 onValueChangedListeners ~= this; 701 } 702 703 void remove(OnValueChangedDelegateWrapper source) 704 { 705 foreach(index, wrapper; onValueChangedListeners) 706 { 707 if (wrapper.handlerId == source.handlerId) 708 { 709 onValueChangedListeners[index] = null; 710 onValueChangedListeners = std.algorithm.remove(onValueChangedListeners, index); 711 break; 712 } 713 } 714 } 715 } 716 OnValueChangedDelegateWrapper[] onValueChangedListeners; 717 718 /** 719 * Emitted when the range value changes. 720 */ 721 gulong addOnValueChanged(void delegate(Range) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 722 { 723 auto wrapper = new OnValueChangedDelegateWrapper(dlg); 724 wrapper.handlerId = Signals.connectData( 725 this, 726 "value-changed", 727 cast(GCallback)&callBackValueChanged, 728 cast(void*)wrapper, 729 cast(GClosureNotify)&callBackValueChangedDestroy, 730 connectFlags); 731 return wrapper.handlerId; 732 } 733 734 extern(C) static void callBackValueChanged(GtkRange* rangeStruct, OnValueChangedDelegateWrapper wrapper) 735 { 736 wrapper.dlg(wrapper.outer); 737 } 738 739 extern(C) static void callBackValueChangedDestroy(OnValueChangedDelegateWrapper wrapper, GClosure* closure) 740 { 741 wrapper.remove(wrapper); 742 } 743 }