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.ScrolledWindow; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gtk.Adjustment; 31 private import gtk.Widget; 32 private import gtk.c.functions; 33 public import gtk.c.types; 34 private import std.algorithm; 35 36 37 /** 38 * `GtkScrolledWindow` is a container that makes its child scrollable. 39 * 40 * It does so using either internally added scrollbars or externally 41 * associated adjustments, and optionally draws a frame around the child. 42 * 43 * Widgets with native scrolling support, i.e. those whose classes implement 44 * the [iface@Gtk.Scrollable] interface, are added directly. For other types 45 * of widget, the class [class@Gtk.Viewport] acts as an adaptor, giving 46 * scrollability to other widgets. [method@Gtk.ScrolledWindow.set_child] 47 * intelligently accounts for whether or not the added child is a `GtkScrollable`. 48 * If it isn’t, then it wraps the child in a `GtkViewport`. Therefore, you can 49 * just add any child widget and not worry about the details. 50 * 51 * If [method@Gtk.ScrolledWindow.set_child] has added a `GtkViewport` for you, 52 * you can remove both your added child widget from the `GtkViewport`, and the 53 * `GtkViewport` from the `GtkScrolledWindow`, like this: 54 * 55 * ```c 56 * GtkWidget *scrolled_window = gtk_scrolled_window_new (); 57 * GtkWidget *child_widget = gtk_button_new (); 58 * 59 * // GtkButton is not a GtkScrollable, so GtkScrolledWindow will automatically 60 * // add a GtkViewport. 61 * gtk_box_append (GTK_BOX (scrolled_window), child_widget); 62 * 63 * // Either of these will result in child_widget being unparented: 64 * gtk_box_remove (GTK_BOX (scrolled_window), child_widget); 65 * // or 66 * gtk_box_remove (GTK_BOX (scrolled_window), 67 * gtk_bin_get_child (GTK_BIN (scrolled_window))); 68 * ``` 69 * 70 * Unless [property@Gtk.ScrolledWindow:hscrollbar-policy] and 71 * [property@Gtk.ScrolledWindow:vscrollbar-policy] are %GTK_POLICY_NEVER or 72 * %GTK_POLICY_EXTERNAL, `GtkScrolledWindow` adds internal `GtkScrollbar` widgets 73 * around its child. The scroll position of the child, and if applicable the 74 * scrollbars, is controlled by the [property@Gtk.ScrolledWindow:hadjustment] 75 * and [property@Gtk.ScrolledWindow:vadjustment] that are associated with the 76 * `GtkScrolledWindow`. See the docs on [class@Gtk.Scrollbar] for the details, 77 * but note that the “step_increment” and “page_increment” fields are only 78 * effective if the policy causes scrollbars to be present. 79 * 80 * If a `GtkScrolledWindow` doesn’t behave quite as you would like, or 81 * doesn’t have exactly the right layout, it’s very possible to set up 82 * your own scrolling with `GtkScrollbar` and for example a `GtkGrid`. 83 * 84 * # Touch support 85 * 86 * `GtkScrolledWindow` has built-in support for touch devices. When a 87 * touchscreen is used, swiping will move the scrolled window, and will 88 * expose 'kinetic' behavior. This can be turned off with the 89 * [property@Gtk.ScrolledWindow:kinetic-scrolling] property if it is undesired. 90 * 91 * `GtkScrolledWindow` also displays visual 'overshoot' indication when 92 * the content is pulled beyond the end, and this situation can be 93 * captured with the [signal@Gtk.ScrolledWindow::edge-overshot] signal. 94 * 95 * If no mouse device is present, the scrollbars will overlaid as 96 * narrow, auto-hiding indicators over the content. If traditional 97 * scrollbars are desired although no mouse is present, this behaviour 98 * can be turned off with the [property@Gtk.ScrolledWindow:overlay-scrolling] 99 * property. 100 * 101 * # CSS nodes 102 * 103 * `GtkScrolledWindow` has a main CSS node with name scrolledwindow. 104 * It gets a .frame style class added when [property@Gtk.ScrolledWindow:has-frame] 105 * is %TRUE. 106 * 107 * It uses subnodes with names overshoot and undershoot to draw the overflow 108 * and underflow indications. These nodes get the .left, .right, .top or .bottom 109 * style class added depending on where the indication is drawn. 110 * 111 * `GtkScrolledWindow` also sets the positional style classes (.left, .right, 112 * .top, .bottom) and style classes related to overlay scrolling 113 * (.overlay-indicator, .dragging, .hovering) on its scrollbars. 114 * 115 * If both scrollbars are visible, the area where they meet is drawn 116 * with a subnode named junction. 117 * 118 * # Accessibility 119 * 120 * `GtkScrolledWindow` uses the %GTK_ACCESSIBLE_ROLE_GROUP role. 121 */ 122 public class ScrolledWindow : Widget 123 { 124 /** the main Gtk struct */ 125 protected GtkScrolledWindow* gtkScrolledWindow; 126 127 /** Get the main Gtk struct */ 128 public GtkScrolledWindow* getScrolledWindowStruct(bool transferOwnership = false) 129 { 130 if (transferOwnership) 131 ownedRef = false; 132 return gtkScrolledWindow; 133 } 134 135 /** the main Gtk struct as a void* */ 136 protected override void* getStruct() 137 { 138 return cast(void*)gtkScrolledWindow; 139 } 140 141 /** 142 * Sets our main struct and passes it to the parent class. 143 */ 144 public this (GtkScrolledWindow* gtkScrolledWindow, bool ownedRef = false) 145 { 146 this.gtkScrolledWindow = gtkScrolledWindow; 147 super(cast(GtkWidget*)gtkScrolledWindow, ownedRef); 148 } 149 150 /** */ 151 public this(Widget widget) 152 { 153 this(); 154 setChild(widget); 155 } 156 157 /** 158 */ 159 160 /** */ 161 public static GType getType() 162 { 163 return gtk_scrolled_window_get_type(); 164 } 165 166 /** 167 * Creates a new scrolled window. 168 * 169 * Returns: a new scrolled window 170 * 171 * Throws: ConstructionException GTK+ fails to create the object. 172 */ 173 public this() 174 { 175 auto __p = gtk_scrolled_window_new(); 176 177 if(__p is null) 178 { 179 throw new ConstructionException("null returned by new"); 180 } 181 182 this(cast(GtkScrolledWindow*) __p); 183 } 184 185 /** 186 * Gets the child widget of @scrolled_window. 187 * 188 * Returns: the child widget of @scrolled_window 189 */ 190 public Widget getChild() 191 { 192 auto __p = gtk_scrolled_window_get_child(gtkScrolledWindow); 193 194 if(__p is null) 195 { 196 return null; 197 } 198 199 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 200 } 201 202 /** 203 * Returns the horizontal scrollbar’s adjustment. 204 * 205 * This is the adjustment used to connect the horizontal scrollbar 206 * to the child widget’s horizontal scroll functionality. 207 * 208 * Returns: the horizontal `GtkAdjustment` 209 */ 210 public Adjustment getHadjustment() 211 { 212 auto __p = gtk_scrolled_window_get_hadjustment(gtkScrolledWindow); 213 214 if(__p is null) 215 { 216 return null; 217 } 218 219 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) __p); 220 } 221 222 /** 223 * Gets whether the scrolled window draws a frame. 224 * 225 * Returns: %TRUE if the @scrolled_window has a frame 226 */ 227 public bool getHasFrame() 228 { 229 return gtk_scrolled_window_get_has_frame(gtkScrolledWindow) != 0; 230 } 231 232 /** 233 * Returns the horizontal scrollbar of @scrolled_window. 234 * 235 * Returns: the horizontal scrollbar of the scrolled window. 236 */ 237 public Widget getHscrollbar() 238 { 239 auto __p = gtk_scrolled_window_get_hscrollbar(gtkScrolledWindow); 240 241 if(__p is null) 242 { 243 return null; 244 } 245 246 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 247 } 248 249 /** 250 * Returns the specified kinetic scrolling behavior. 251 * 252 * Returns: the scrolling behavior flags. 253 */ 254 public bool getKineticScrolling() 255 { 256 return gtk_scrolled_window_get_kinetic_scrolling(gtkScrolledWindow) != 0; 257 } 258 259 /** 260 * Returns the maximum content height set. 261 * 262 * Returns: the maximum content height, or -1 263 */ 264 public int getMaxContentHeight() 265 { 266 return gtk_scrolled_window_get_max_content_height(gtkScrolledWindow); 267 } 268 269 /** 270 * Returns the maximum content width set. 271 * 272 * Returns: the maximum content width, or -1 273 */ 274 public int getMaxContentWidth() 275 { 276 return gtk_scrolled_window_get_max_content_width(gtkScrolledWindow); 277 } 278 279 /** 280 * Gets the minimal content height of @scrolled_window. 281 * 282 * Returns: the minimal content height 283 */ 284 public int getMinContentHeight() 285 { 286 return gtk_scrolled_window_get_min_content_height(gtkScrolledWindow); 287 } 288 289 /** 290 * Gets the minimum content width of @scrolled_window. 291 * 292 * Returns: the minimum content width 293 */ 294 public int getMinContentWidth() 295 { 296 return gtk_scrolled_window_get_min_content_width(gtkScrolledWindow); 297 } 298 299 /** 300 * Returns whether overlay scrolling is enabled for this scrolled window. 301 * 302 * Returns: %TRUE if overlay scrolling is enabled 303 */ 304 public bool getOverlayScrolling() 305 { 306 return gtk_scrolled_window_get_overlay_scrolling(gtkScrolledWindow) != 0; 307 } 308 309 /** 310 * Gets the placement of the contents with respect to the scrollbars. 311 * 312 * Returns: the current placement value. 313 */ 314 public GtkCornerType getPlacement() 315 { 316 return gtk_scrolled_window_get_placement(gtkScrolledWindow); 317 } 318 319 /** 320 * Retrieves the current policy values for the horizontal and vertical 321 * scrollbars. 322 * 323 * See [method@Gtk.ScrolledWindow.set_policy]. 324 * 325 * Params: 326 * hscrollbarPolicy = location to store the policy 327 * for the horizontal scrollbar, or %NULL 328 * vscrollbarPolicy = location to store the policy 329 * for the vertical scrollbar, or %NULL 330 */ 331 public void getPolicy(out GtkPolicyType hscrollbarPolicy, out GtkPolicyType vscrollbarPolicy) 332 { 333 gtk_scrolled_window_get_policy(gtkScrolledWindow, &hscrollbarPolicy, &vscrollbarPolicy); 334 } 335 336 /** 337 * Reports whether the natural height of the child will be calculated 338 * and propagated through the scrolled window’s requested natural height. 339 * 340 * Returns: whether natural height propagation is enabled. 341 */ 342 public bool getPropagateNaturalHeight() 343 { 344 return gtk_scrolled_window_get_propagate_natural_height(gtkScrolledWindow) != 0; 345 } 346 347 /** 348 * Reports whether the natural width of the child will be calculated 349 * and propagated through the scrolled window’s requested natural width. 350 * 351 * Returns: whether natural width propagation is enabled. 352 */ 353 public bool getPropagateNaturalWidth() 354 { 355 return gtk_scrolled_window_get_propagate_natural_width(gtkScrolledWindow) != 0; 356 } 357 358 /** 359 * Returns the vertical scrollbar’s adjustment. 360 * 361 * This is the adjustment used to connect the vertical 362 * scrollbar to the child widget’s vertical scroll functionality. 363 * 364 * Returns: the vertical `GtkAdjustment` 365 */ 366 public Adjustment getVadjustment() 367 { 368 auto __p = gtk_scrolled_window_get_vadjustment(gtkScrolledWindow); 369 370 if(__p is null) 371 { 372 return null; 373 } 374 375 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) __p); 376 } 377 378 /** 379 * Returns the vertical scrollbar of @scrolled_window. 380 * 381 * Returns: the vertical scrollbar of the scrolled window. 382 */ 383 public Widget getVscrollbar() 384 { 385 auto __p = gtk_scrolled_window_get_vscrollbar(gtkScrolledWindow); 386 387 if(__p is null) 388 { 389 return null; 390 } 391 392 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 393 } 394 395 /** 396 * Sets the child widget of @scrolled_window. 397 * 398 * Params: 399 * child = the child widget 400 */ 401 public void setChild(Widget child) 402 { 403 gtk_scrolled_window_set_child(gtkScrolledWindow, (child is null) ? null : child.getWidgetStruct()); 404 } 405 406 /** 407 * Sets the `GtkAdjustment` for the horizontal scrollbar. 408 * 409 * Params: 410 * hadjustment = the `GtkAdjustment` to use, or %NULL to create a new one 411 */ 412 public void setHadjustment(Adjustment hadjustment) 413 { 414 gtk_scrolled_window_set_hadjustment(gtkScrolledWindow, (hadjustment is null) ? null : hadjustment.getAdjustmentStruct()); 415 } 416 417 /** 418 * Changes the frame drawn around the contents of @scrolled_window. 419 * 420 * Params: 421 * hasFrame = whether to draw a frame around scrolled window contents 422 */ 423 public void setHasFrame(bool hasFrame) 424 { 425 gtk_scrolled_window_set_has_frame(gtkScrolledWindow, hasFrame); 426 } 427 428 /** 429 * Turns kinetic scrolling on or off. 430 * 431 * Kinetic scrolling only applies to devices with source 432 * %GDK_SOURCE_TOUCHSCREEN. 433 * 434 * Params: 435 * kineticScrolling = %TRUE to enable kinetic scrolling 436 */ 437 public void setKineticScrolling(bool kineticScrolling) 438 { 439 gtk_scrolled_window_set_kinetic_scrolling(gtkScrolledWindow, kineticScrolling); 440 } 441 442 /** 443 * Sets the maximum height that @scrolled_window should keep visible. 444 * 445 * The @scrolled_window will grow up to this height before it starts 446 * scrolling the content. 447 * 448 * It is a programming error to set the maximum content height to a value 449 * smaller than [property@Gtk.ScrolledWindow:min-content-height]. 450 * 451 * Params: 452 * height = the maximum content height 453 */ 454 public void setMaxContentHeight(int height) 455 { 456 gtk_scrolled_window_set_max_content_height(gtkScrolledWindow, height); 457 } 458 459 /** 460 * Sets the maximum width that @scrolled_window should keep visible. 461 * 462 * The @scrolled_window will grow up to this width before it starts 463 * scrolling the content. 464 * 465 * It is a programming error to set the maximum content width to a 466 * value smaller than [property@Gtk.ScrolledWindow:min-content-width]. 467 * 468 * Params: 469 * width = the maximum content width 470 */ 471 public void setMaxContentWidth(int width) 472 { 473 gtk_scrolled_window_set_max_content_width(gtkScrolledWindow, width); 474 } 475 476 /** 477 * Sets the minimum height that @scrolled_window should keep visible. 478 * 479 * Note that this can and (usually will) be smaller than the minimum 480 * size of the content. 481 * 482 * It is a programming error to set the minimum content height to a 483 * value greater than [property@Gtk.ScrolledWindow:max-content-height]. 484 * 485 * Params: 486 * height = the minimal content height 487 */ 488 public void setMinContentHeight(int height) 489 { 490 gtk_scrolled_window_set_min_content_height(gtkScrolledWindow, height); 491 } 492 493 /** 494 * Sets the minimum width that @scrolled_window should keep visible. 495 * 496 * Note that this can and (usually will) be smaller than the minimum 497 * size of the content. 498 * 499 * It is a programming error to set the minimum content width to a 500 * value greater than [property@Gtk.ScrolledWindow:max-content-width]. 501 * 502 * Params: 503 * width = the minimal content width 504 */ 505 public void setMinContentWidth(int width) 506 { 507 gtk_scrolled_window_set_min_content_width(gtkScrolledWindow, width); 508 } 509 510 /** 511 * Enables or disables overlay scrolling for this scrolled window. 512 * 513 * Params: 514 * overlayScrolling = whether to enable overlay scrolling 515 */ 516 public void setOverlayScrolling(bool overlayScrolling) 517 { 518 gtk_scrolled_window_set_overlay_scrolling(gtkScrolledWindow, overlayScrolling); 519 } 520 521 /** 522 * Sets the placement of the contents with respect to the scrollbars 523 * for the scrolled window. 524 * 525 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is 526 * in the top left, with the scrollbars underneath and to the right. 527 * Other values in [enum@Gtk.CornerType] are %GTK_CORNER_TOP_RIGHT, 528 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT. 529 * 530 * See also [method@Gtk.ScrolledWindow.get_placement] and 531 * [method@Gtk.ScrolledWindow.unset_placement]. 532 * 533 * Params: 534 * windowPlacement = position of the child window 535 */ 536 public void setPlacement(GtkCornerType windowPlacement) 537 { 538 gtk_scrolled_window_set_placement(gtkScrolledWindow, windowPlacement); 539 } 540 541 /** 542 * Sets the scrollbar policy for the horizontal and vertical scrollbars. 543 * 544 * The policy determines when the scrollbar should appear; it is a value 545 * from the [enum@Gtk.PolicyType] enumeration. If %GTK_POLICY_ALWAYS, the 546 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is 547 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only 548 * if needed (that is, if the slider part of the bar would be smaller 549 * than the trough — the display is larger than the page size). 550 * 551 * Params: 552 * hscrollbarPolicy = policy for horizontal bar 553 * vscrollbarPolicy = policy for vertical bar 554 */ 555 public void setPolicy(GtkPolicyType hscrollbarPolicy, GtkPolicyType vscrollbarPolicy) 556 { 557 gtk_scrolled_window_set_policy(gtkScrolledWindow, hscrollbarPolicy, vscrollbarPolicy); 558 } 559 560 /** 561 * Sets whether the natural height of the child should be calculated 562 * and propagated through the scrolled window’s requested natural height. 563 * 564 * Params: 565 * propagate = whether to propagate natural height 566 */ 567 public void setPropagateNaturalHeight(bool propagate) 568 { 569 gtk_scrolled_window_set_propagate_natural_height(gtkScrolledWindow, propagate); 570 } 571 572 /** 573 * Sets whether the natural width of the child should be calculated 574 * and propagated through the scrolled window’s requested natural width. 575 * 576 * Params: 577 * propagate = whether to propagate natural width 578 */ 579 public void setPropagateNaturalWidth(bool propagate) 580 { 581 gtk_scrolled_window_set_propagate_natural_width(gtkScrolledWindow, propagate); 582 } 583 584 /** 585 * Sets the `GtkAdjustment` for the vertical scrollbar. 586 * 587 * Params: 588 * vadjustment = the `GtkAdjustment` to use, or %NULL to create a new one 589 */ 590 public void setVadjustment(Adjustment vadjustment) 591 { 592 gtk_scrolled_window_set_vadjustment(gtkScrolledWindow, (vadjustment is null) ? null : vadjustment.getAdjustmentStruct()); 593 } 594 595 /** 596 * Unsets the placement of the contents with respect to the scrollbars. 597 * 598 * If no window placement is set for a scrolled window, 599 * it defaults to %GTK_CORNER_TOP_LEFT. 600 */ 601 public void unsetPlacement() 602 { 603 gtk_scrolled_window_unset_placement(gtkScrolledWindow); 604 } 605 606 /** 607 * Emitted whenever user initiated scrolling makes the scrolled 608 * window firmly surpass the limits defined by the adjustment 609 * in that orientation. 610 * 611 * A similar behavior without edge resistance is provided by the 612 * [signal@Gtk.ScrolledWindow::edge-reached] signal. 613 * 614 * Note: The @pos argument is LTR/RTL aware, so callers should be 615 * aware too if intending to provide behavior on horizontal edges. 616 * 617 * Params: 618 * pos = edge side that was hit 619 */ 620 gulong addOnEdgeOvershot(void delegate(GtkPositionType, ScrolledWindow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 621 { 622 return Signals.connect(this, "edge-overshot", dlg, connectFlags ^ ConnectFlags.SWAPPED); 623 } 624 625 /** 626 * Emitted whenever user-initiated scrolling makes the scrolled 627 * window exactly reach the lower or upper limits defined by the 628 * adjustment in that orientation. 629 * 630 * A similar behavior with edge resistance is provided by the 631 * [signal@Gtk.ScrolledWindow::edge-overshot] signal. 632 * 633 * Note: The @pos argument is LTR/RTL aware, so callers should be 634 * aware too if intending to provide behavior on horizontal edges. 635 * 636 * Params: 637 * pos = edge side that was reached 638 */ 639 gulong addOnEdgeReached(void delegate(GtkPositionType, ScrolledWindow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 640 { 641 return Signals.connect(this, "edge-reached", dlg, connectFlags ^ ConnectFlags.SWAPPED); 642 } 643 644 /** 645 * Emitted when focus is moved away from the scrolled window by a 646 * keybinding. 647 * 648 * This is a [keybinding signal](class.SignalAction.html). 649 * 650 * The default bindings for this signal are 651 * `Ctrl + Tab` to move forward and `Ctrl + Shift + Tab` to 652 * move backward. 653 * 654 * Params: 655 * directionType = either %GTK_DIR_TAB_FORWARD or 656 * %GTK_DIR_TAB_BACKWARD 657 */ 658 gulong addOnMoveFocusOut(void delegate(GtkDirectionType, ScrolledWindow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 659 { 660 return Signals.connect(this, "move-focus-out", dlg, connectFlags ^ ConnectFlags.SWAPPED); 661 } 662 663 /** 664 * Emitted when a keybinding that scrolls is pressed. 665 * 666 * This is a [keybinding signal](class.SignalAction.html). 667 * 668 * The horizontal or vertical adjustment is updated which triggers a 669 * signal that the scrolled window’s child may listen to and scroll itself. 670 * 671 * Params: 672 * scroll = a `GtkScrollType` describing how much to scroll 673 * horizontal = whether the keybinding scrolls the child 674 * horizontally or not 675 */ 676 gulong addOnScrollChild(bool delegate(GtkScrollType, bool, ScrolledWindow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 677 { 678 return Signals.connect(this, "scroll-child", dlg, connectFlags ^ ConnectFlags.SWAPPED); 679 } 680 }