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