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.Container; 26 27 private import cairo.Context; 28 private import glib.ListG; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.ParamSpec; 32 private import gobject.Signals; 33 private import gobject.Value; 34 private import gtk.Adjustment; 35 private import gtk.Widget; 36 private import gtk.WidgetPath; 37 private import gtkc.gtk; 38 public import gtkc.gtktypes; 39 private import std.algorithm; 40 41 42 /** 43 * A GTK+ user interface is constructed by nesting widgets inside widgets. 44 * Container widgets are the inner nodes in the resulting tree of widgets: 45 * they contain other widgets. So, for example, you might have a #GtkWindow 46 * containing a #GtkFrame containing a #GtkLabel. If you wanted an image instead 47 * of a textual label inside the frame, you might replace the #GtkLabel widget 48 * with a #GtkImage widget. 49 * 50 * There are two major kinds of container widgets in GTK+. Both are subclasses 51 * of the abstract GtkContainer base class. 52 * 53 * The first type of container widget has a single child widget and derives 54 * from #GtkBin. These containers are decorators, which 55 * add some kind of functionality to the child. For example, a #GtkButton makes 56 * its child into a clickable button; a #GtkFrame draws a frame around its child 57 * and a #GtkWindow places its child widget inside a top-level window. 58 * 59 * The second type of container can have more than one child; its purpose is to 60 * manage layout. This means that these containers assign 61 * sizes and positions to their children. For example, a #GtkHBox arranges its 62 * children in a horizontal row, and a #GtkGrid arranges the widgets it contains 63 * in a two-dimensional grid. 64 * 65 * For implementations of #GtkContainer the virtual method #GtkContainerClass.forall() 66 * is always required, since it's used for drawing and other internal operations 67 * on the children. 68 * If the #GtkContainer implementation expect to have non internal children 69 * it's needed to implement both #GtkContainerClass.add() and #GtkContainerClass.remove(). 70 * If the GtkContainer implementation has internal children, they should be added 71 * with gtk_widget_set_parent() on init() and removed with gtk_widget_unparent() 72 * in the #GtkWidgetClass.destroy() implementation. 73 * See more about implementing custom widgets at https://wiki.gnome.org/HowDoI/CustomWidgets 74 * 75 * # Height for width geometry management 76 * 77 * GTK+ uses a height-for-width (and width-for-height) geometry management system. 78 * Height-for-width means that a widget can change how much vertical space it needs, 79 * depending on the amount of horizontal space that it is given (and similar for 80 * width-for-height). 81 * 82 * There are some things to keep in mind when implementing container widgets 83 * that make use of GTK+’s height for width geometry management system. First, 84 * it’s important to note that a container must prioritize one of its 85 * dimensions, that is to say that a widget or container can only have a 86 * #GtkSizeRequestMode that is %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH or 87 * %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT. However, every widget and container 88 * must be able to respond to the APIs for both dimensions, i.e. even if a 89 * widget has a request mode that is height-for-width, it is possible that 90 * its parent will request its sizes using the width-for-height APIs. 91 * 92 * To ensure that everything works properly, here are some guidelines to follow 93 * when implementing height-for-width (or width-for-height) containers. 94 * 95 * Each request mode involves 2 virtual methods. Height-for-width apis run 96 * through gtk_widget_get_preferred_width() and then through gtk_widget_get_preferred_height_for_width(). 97 * When handling requests in the opposite #GtkSizeRequestMode it is important that 98 * every widget request at least enough space to display all of its content at all times. 99 * 100 * When gtk_widget_get_preferred_height() is called on a container that is height-for-width, 101 * the container must return the height for its minimum width. This is easily achieved by 102 * simply calling the reverse apis implemented for itself as follows: 103 * 104 * |[<!-- language="C" --> 105 * static void 106 * foo_container_get_preferred_height (GtkWidget *widget, 107 * gint *min_height, 108 * gint *nat_height) 109 * { 110 * if (i_am_in_height_for_width_mode) 111 * { 112 * gint min_width; 113 * 114 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, 115 * &min_width, 116 * NULL); 117 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width 118 * (widget, 119 * min_width, 120 * min_height, 121 * nat_height); 122 * } 123 * else 124 * { 125 * ... many containers support both request modes, execute the 126 * real width-for-height request here by returning the 127 * collective heights of all widgets that are stacked 128 * vertically (or whatever is appropriate for this container) 129 * ... 130 * } 131 * } 132 * ]| 133 * 134 * Similarly, when gtk_widget_get_preferred_width_for_height() is called for a container or widget 135 * that is height-for-width, it then only needs to return the base minimum width like so: 136 * 137 * |[<!-- language="C" --> 138 * static void 139 * foo_container_get_preferred_width_for_height (GtkWidget *widget, 140 * gint for_height, 141 * gint *min_width, 142 * gint *nat_width) 143 * { 144 * if (i_am_in_height_for_width_mode) 145 * { 146 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, 147 * min_width, 148 * nat_width); 149 * } 150 * else 151 * { 152 * ... execute the real width-for-height request here based on 153 * the required width of the children collectively if the 154 * container were to be allocated the said height ... 155 * } 156 * } 157 * ]| 158 * 159 * Height for width requests are generally implemented in terms of a virtual allocation 160 * of widgets in the input orientation. Assuming an height-for-width request mode, a container 161 * would implement the get_preferred_height_for_width() virtual function by first calling 162 * gtk_widget_get_preferred_width() for each of its children. 163 * 164 * For each potential group of children that are lined up horizontally, the values returned by 165 * gtk_widget_get_preferred_width() should be collected in an array of #GtkRequestedSize structures. 166 * Any child spacing should be removed from the input @for_width and then the collective size should be 167 * allocated using the gtk_distribute_natural_allocation() convenience function. 168 * 169 * The container will then move on to request the preferred height for each child by using 170 * gtk_widget_get_preferred_height_for_width() and using the sizes stored in the #GtkRequestedSize array. 171 * 172 * To allocate a height-for-width container, it’s again important 173 * to consider that a container must prioritize one dimension over the other. So if 174 * a container is a height-for-width container it must first allocate all widgets horizontally 175 * using a #GtkRequestedSize array and gtk_distribute_natural_allocation() and then add any 176 * extra space (if and where appropriate) for the widget to expand. 177 * 178 * After adding all the expand space, the container assumes it was allocated sufficient 179 * height to fit all of its content. At this time, the container must use the total horizontal sizes 180 * of each widget to request the height-for-width of each of its children and store the requests in a 181 * #GtkRequestedSize array for any widgets that stack vertically (for tabular containers this can 182 * be generalized into the heights and widths of rows and columns). 183 * The vertical space must then again be distributed using gtk_distribute_natural_allocation() 184 * while this time considering the allocated height of the widget minus any vertical spacing 185 * that the container adds. Then vertical expand space should be added where appropriate and available 186 * and the container should go on to actually allocating the child widgets. 187 * 188 * See [GtkWidget’s geometry management section][geometry-management] 189 * to learn more about implementing height-for-width geometry management for widgets. 190 * 191 * # Child properties 192 * 193 * GtkContainer introduces child properties. 194 * These are object properties that are not specific 195 * to either the container or the contained widget, but rather to their relation. 196 * Typical examples of child properties are the position or pack-type of a widget 197 * which is contained in a #GtkBox. 198 * 199 * Use gtk_container_class_install_child_property() to install child properties 200 * for a container class and gtk_container_class_find_child_property() or 201 * gtk_container_class_list_child_properties() to get information about existing 202 * child properties. 203 * 204 * To set the value of a child property, use gtk_container_child_set_property(), 205 * gtk_container_child_set() or gtk_container_child_set_valist(). 206 * To obtain the value of a child property, use 207 * gtk_container_child_get_property(), gtk_container_child_get() or 208 * gtk_container_child_get_valist(). To emit notification about child property 209 * changes, use gtk_widget_child_notify(). 210 * 211 * # GtkContainer as GtkBuildable 212 * 213 * The GtkContainer implementation of the GtkBuildable interface supports 214 * a <packing> element for children, which can contain multiple <property> 215 * elements that specify child properties for the child. 216 * 217 * Since 2.16, child properties can also be marked as translatable using 218 * the same “translatable”, “comments” and “context” attributes that are used 219 * for regular properties. 220 * 221 * Since 3.16, containers can have a <focus-chain> element containing multiple 222 * <widget> elements, one for each child that should be added to the focus 223 * chain. The ”name” attribute gives the id of the widget. 224 * 225 * An example of these properties in UI definitions: 226 * |[ 227 * <object class="GtkBox"> 228 * <child> 229 * <object class="GtkEntry" id="entry1"/> 230 * <packing> 231 * <property name="pack-type">start</property> 232 * </packing> 233 * </child> 234 * <child> 235 * <object class="GtkEntry" id="entry2"/> 236 * </child> 237 * <focus-chain> 238 * <widget name="entry1"/> 239 * <widget name="entry2"/> 240 * </focus-chain> 241 * </object> 242 * ]| 243 */ 244 public class Container : Widget 245 { 246 /** the main Gtk struct */ 247 protected GtkContainer* gtkContainer; 248 249 /** Get the main Gtk struct */ 250 public GtkContainer* getContainerStruct(bool transferOwnership = false) 251 { 252 if (transferOwnership) 253 ownedRef = false; 254 return gtkContainer; 255 } 256 257 /** the main Gtk struct as a void* */ 258 protected override void* getStruct() 259 { 260 return cast(void*)gtkContainer; 261 } 262 263 protected override void setStruct(GObject* obj) 264 { 265 gtkContainer = cast(GtkContainer*)obj; 266 super.setStruct(obj); 267 } 268 269 /** 270 * Sets our main struct and passes it to the parent class. 271 */ 272 public this (GtkContainer* gtkContainer, bool ownedRef = false) 273 { 274 this.gtkContainer = gtkContainer; 275 super(cast(GtkWidget*)gtkContainer, ownedRef); 276 } 277 278 /** 279 * Removes all widgets from the container 280 */ 281 void removeAll() 282 { 283 GList* gList = gtk_container_get_children(getContainerStruct()); 284 if ( gList !is null ) 285 { 286 ListG children = new ListG(gList); 287 for ( int i=children.length()-1 ; i>=0 ; i-- ) 288 { 289 gtk_container_remove(getContainerStruct(), cast(GtkWidget*)children.nthData(i)); 290 } 291 } 292 } 293 294 /** 295 */ 296 297 /** */ 298 public static GType getType() 299 { 300 return gtk_container_get_type(); 301 } 302 303 /** 304 * Adds @widget to @container. Typically used for simple containers 305 * such as #GtkWindow, #GtkFrame, or #GtkButton; for more complicated 306 * layout containers such as #GtkBox or #GtkGrid, this function will 307 * pick default packing parameters that may not be correct. So 308 * consider functions such as gtk_box_pack_start() and 309 * gtk_grid_attach() as an alternative to gtk_container_add() in 310 * those cases. A widget may be added to only one container at a time; 311 * you can’t place the same widget inside two different containers. 312 * 313 * Note that some containers, such as #GtkScrolledWindow or #GtkListBox, 314 * may add intermediate children between the added widget and the 315 * container. 316 * 317 * Params: 318 * widget = a widget to be placed inside @container 319 */ 320 public void add(Widget widget) 321 { 322 gtk_container_add(gtkContainer, (widget is null) ? null : widget.getWidgetStruct()); 323 } 324 325 /** */ 326 public void checkResize() 327 { 328 gtk_container_check_resize(gtkContainer); 329 } 330 331 /** 332 * Gets the value of a child property for @child and @container. 333 * 334 * Params: 335 * child = a widget which is a child of @container 336 * propertyName = the name of the property to get 337 * value = a location to return the value 338 */ 339 public void childGetProperty(Widget child, string propertyName, Value value) 340 { 341 gtk_container_child_get_property(gtkContainer, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct()); 342 } 343 344 /** 345 * Gets the values of one or more child properties for @child and @container. 346 * 347 * Params: 348 * child = a widget which is a child of @container 349 * firstPropertyName = the name of the first property to get 350 * varArgs = return location for the first property, followed 351 * optionally by more name/return location pairs, followed by %NULL 352 */ 353 public void childGetValist(Widget child, string firstPropertyName, void* varArgs) 354 { 355 gtk_container_child_get_valist(gtkContainer, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(firstPropertyName), varArgs); 356 } 357 358 /** 359 * Emits a #GtkWidget::child-notify signal for the 360 * [child property][child-properties] 361 * @child_property on the child. 362 * 363 * This is an analogue of g_object_notify() for child properties. 364 * 365 * Also see gtk_widget_child_notify(). 366 * 367 * Params: 368 * child = the child widget 369 * childProperty = the name of a child property installed on 370 * the class of @container 371 * 372 * Since: 3.2 373 */ 374 public void childNotify(Widget child, string childProperty) 375 { 376 gtk_container_child_notify(gtkContainer, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(childProperty)); 377 } 378 379 /** 380 * Emits a #GtkWidget::child-notify signal for the 381 * [child property][child-properties] specified by 382 * @pspec on the child. 383 * 384 * This is an analogue of g_object_notify_by_pspec() for child properties. 385 * 386 * Params: 387 * child = the child widget 388 * pspec = the #GParamSpec of a child property instealled on 389 * the class of @container 390 * 391 * Since: 3.18 392 */ 393 public void childNotifyByPspec(Widget child, ParamSpec pspec) 394 { 395 gtk_container_child_notify_by_pspec(gtkContainer, (child is null) ? null : child.getWidgetStruct(), (pspec is null) ? null : pspec.getParamSpecStruct()); 396 } 397 398 /** 399 * Sets a child property for @child and @container. 400 * 401 * Params: 402 * child = a widget which is a child of @container 403 * propertyName = the name of the property to set 404 * value = the value to set the property to 405 */ 406 public void childSetProperty(Widget child, string propertyName, Value value) 407 { 408 gtk_container_child_set_property(gtkContainer, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct()); 409 } 410 411 /** 412 * Sets one or more child properties for @child and @container. 413 * 414 * Params: 415 * child = a widget which is a child of @container 416 * firstPropertyName = the name of the first property to set 417 * varArgs = a %NULL-terminated list of property names and values, starting 418 * with @first_prop_name 419 */ 420 public void childSetValist(Widget child, string firstPropertyName, void* varArgs) 421 { 422 gtk_container_child_set_valist(gtkContainer, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(firstPropertyName), varArgs); 423 } 424 425 /** 426 * Returns the type of the children supported by the container. 427 * 428 * Note that this may return %G_TYPE_NONE to indicate that no more 429 * children can be added, e.g. for a #GtkPaned which already has two 430 * children. 431 * 432 * Returns: a #GType. 433 */ 434 public GType childType() 435 { 436 return gtk_container_child_type(gtkContainer); 437 } 438 439 /** 440 * Invokes @callback on each direct child of @container, including 441 * children that are considered “internal” (implementation details 442 * of the container). “Internal” children generally weren’t added 443 * by the user of the container, but were added by the container 444 * implementation itself. 445 * 446 * Most applications should use gtk_container_foreach(), rather 447 * than gtk_container_forall(). 448 * 449 * Params: 450 * callback = a callback 451 * callbackData = callback user data 452 */ 453 public void forall(GtkCallback callback, void* callbackData) 454 { 455 gtk_container_forall(gtkContainer, callback, callbackData); 456 } 457 458 /** 459 * Invokes @callback on each non-internal child of @container. 460 * See gtk_container_forall() for details on what constitutes 461 * an “internal” child. For all practical purposes, this function 462 * should iterate over precisely those child widgets that were 463 * added to the container by the application with explicit add() 464 * calls. 465 * 466 * Most applications should use gtk_container_foreach(), 467 * rather than gtk_container_forall(). 468 * 469 * Params: 470 * callback = a callback 471 * callbackData = callback user data 472 */ 473 public void foreac(GtkCallback callback, void* callbackData) 474 { 475 gtk_container_foreach(gtkContainer, callback, callbackData); 476 } 477 478 /** 479 * Retrieves the border width of the container. See 480 * gtk_container_set_border_width(). 481 * 482 * Returns: the current border width 483 */ 484 public uint getBorderWidth() 485 { 486 return gtk_container_get_border_width(gtkContainer); 487 } 488 489 /** 490 * Returns the container’s non-internal children. See 491 * gtk_container_forall() for details on what constitutes an "internal" child. 492 * 493 * Returns: a newly-allocated list of the container’s non-internal children. 494 */ 495 public ListG getChildren() 496 { 497 auto p = gtk_container_get_children(gtkContainer); 498 499 if(p is null) 500 { 501 return null; 502 } 503 504 return new ListG(cast(GList*) p); 505 } 506 507 /** 508 * Retrieves the focus chain of the container, if one has been 509 * set explicitly. If no focus chain has been explicitly 510 * set, GTK+ computes the focus chain based on the positions 511 * of the children. In that case, GTK+ stores %NULL in 512 * @focusable_widgets and returns %FALSE. 513 * 514 * Params: 515 * focusableWidgets = location 516 * to store the focus chain of the 517 * container, or %NULL. You should free this list 518 * using g_list_free() when you are done with it, however 519 * no additional reference count is added to the 520 * individual widgets in the focus chain. 521 * 522 * Returns: %TRUE if the focus chain of the container 523 * has been set explicitly. 524 */ 525 public bool getFocusChain(out ListG focusableWidgets) 526 { 527 GList* outfocusableWidgets = null; 528 529 auto p = gtk_container_get_focus_chain(gtkContainer, &outfocusableWidgets) != 0; 530 531 focusableWidgets = new ListG(outfocusableWidgets); 532 533 return p; 534 } 535 536 /** 537 * Returns the current focus child widget inside @container. This is not the 538 * currently focused widget. That can be obtained by calling 539 * gtk_window_get_focus(). 540 * 541 * Returns: The child widget which will receive the 542 * focus inside @container when the @container is focused, 543 * or %NULL if none is set. 544 * 545 * Since: 2.14 546 */ 547 public Widget getFocusChild() 548 { 549 auto p = gtk_container_get_focus_child(gtkContainer); 550 551 if(p is null) 552 { 553 return null; 554 } 555 556 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 557 } 558 559 /** 560 * Retrieves the horizontal focus adjustment for the container. See 561 * gtk_container_set_focus_hadjustment (). 562 * 563 * Returns: the horizontal focus adjustment, or %NULL if 564 * none has been set. 565 */ 566 public Adjustment getFocusHadjustment() 567 { 568 auto p = gtk_container_get_focus_hadjustment(gtkContainer); 569 570 if(p is null) 571 { 572 return null; 573 } 574 575 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p); 576 } 577 578 /** 579 * Retrieves the vertical focus adjustment for the container. See 580 * gtk_container_set_focus_vadjustment(). 581 * 582 * Returns: the vertical focus adjustment, or 583 * %NULL if none has been set. 584 */ 585 public Adjustment getFocusVadjustment() 586 { 587 auto p = gtk_container_get_focus_vadjustment(gtkContainer); 588 589 if(p is null) 590 { 591 return null; 592 } 593 594 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p); 595 } 596 597 /** 598 * Returns a newly created widget path representing all the widget hierarchy 599 * from the toplevel down to and including @child. 600 * 601 * Params: 602 * child = a child of @container 603 * 604 * Returns: A newly created #GtkWidgetPath 605 */ 606 public WidgetPath getPathForChild(Widget child) 607 { 608 auto p = gtk_container_get_path_for_child(gtkContainer, (child is null) ? null : child.getWidgetStruct()); 609 610 if(p is null) 611 { 612 return null; 613 } 614 615 return ObjectG.getDObject!(WidgetPath)(cast(GtkWidgetPath*) p, true); 616 } 617 618 /** 619 * Returns the resize mode for the container. See 620 * gtk_container_set_resize_mode (). 621 * 622 * Deprecated: Resize modes are deprecated. They aren’t necessary 623 * anymore since frame clocks and might introduce obscure bugs if 624 * used. 625 * 626 * Returns: the current resize mode 627 */ 628 public GtkResizeMode getResizeMode() 629 { 630 return gtk_container_get_resize_mode(gtkContainer); 631 } 632 633 /** 634 * When a container receives a call to the draw function, it must send 635 * synthetic #GtkWidget::draw calls to all children that don’t have their 636 * own #GdkWindows. This function provides a convenient way of doing this. 637 * A container, when it receives a call to its #GtkWidget::draw function, 638 * calls gtk_container_propagate_draw() once for each child, passing in 639 * the @cr the container received. 640 * 641 * gtk_container_propagate_draw() takes care of translating the origin of @cr, 642 * and deciding whether the draw needs to be sent to the child. It is a 643 * convenient and optimized way of getting the same effect as calling 644 * gtk_widget_draw() on the child directly. 645 * 646 * In most cases, a container can simply either inherit the 647 * #GtkWidget::draw implementation from #GtkContainer, or do some drawing 648 * and then chain to the ::draw implementation from #GtkContainer. 649 * 650 * Params: 651 * child = a child of @container 652 * cr = Cairo context as passed to the container. If you want to use @cr 653 * in container’s draw function, consider using cairo_save() and 654 * cairo_restore() before calling this function. 655 */ 656 public void propagateDraw(Widget child, Context cr) 657 { 658 gtk_container_propagate_draw(gtkContainer, (child is null) ? null : child.getWidgetStruct(), (cr is null) ? null : cr.getContextStruct()); 659 } 660 661 /** 662 * Removes @widget from @container. @widget must be inside @container. 663 * Note that @container will own a reference to @widget, and that this 664 * may be the last reference held; so removing a widget from its 665 * container can destroy that widget. If you want to use @widget 666 * again, you need to add a reference to it before removing it from 667 * a container, using g_object_ref(). If you don’t want to use @widget 668 * again it’s usually more efficient to simply destroy it directly 669 * using gtk_widget_destroy() since this will remove it from the 670 * container and help break any circular reference count cycles. 671 * 672 * Params: 673 * widget = a current child of @container 674 */ 675 public void remove(Widget widget) 676 { 677 gtk_container_remove(gtkContainer, (widget is null) ? null : widget.getWidgetStruct()); 678 } 679 680 /** */ 681 public void resizeChildren() 682 { 683 gtk_container_resize_children(gtkContainer); 684 } 685 686 /** 687 * Sets the border width of the container. 688 * 689 * The border width of a container is the amount of space to leave 690 * around the outside of the container. The only exception to this is 691 * #GtkWindow; because toplevel windows can’t leave space outside, 692 * they leave the space inside. The border is added on all sides of 693 * the container. To add space to only one side, use a specific 694 * #GtkWidget:margin property on the child widget, for example 695 * #GtkWidget:margin-top. 696 * 697 * Params: 698 * borderWidth = amount of blank space to leave outside 699 * the container. Valid values are in the range 0-65535 pixels. 700 */ 701 public void setBorderWidth(uint borderWidth) 702 { 703 gtk_container_set_border_width(gtkContainer, borderWidth); 704 } 705 706 /** 707 * Sets a focus chain, overriding the one computed automatically by GTK+. 708 * 709 * In principle each widget in the chain should be a descendant of the 710 * container, but this is not enforced by this method, since it’s allowed 711 * to set the focus chain before you pack the widgets, or have a widget 712 * in the chain that isn’t always packed. The necessary checks are done 713 * when the focus chain is actually traversed. 714 * 715 * Params: 716 * focusableWidgets = the new focus chain 717 */ 718 public void setFocusChain(ListG focusableWidgets) 719 { 720 gtk_container_set_focus_chain(gtkContainer, (focusableWidgets is null) ? null : focusableWidgets.getListGStruct()); 721 } 722 723 /** 724 * Sets, or unsets if @child is %NULL, the focused child of @container. 725 * 726 * This function emits the GtkContainer::set_focus_child signal of 727 * @container. Implementations of #GtkContainer can override the 728 * default behaviour by overriding the class closure of this signal. 729 * 730 * This is function is mostly meant to be used by widgets. Applications can use 731 * gtk_widget_grab_focus() to manually set the focus to a specific widget. 732 * 733 * Params: 734 * child = a #GtkWidget, or %NULL 735 */ 736 public void setFocusChild(Widget child) 737 { 738 gtk_container_set_focus_child(gtkContainer, (child is null) ? null : child.getWidgetStruct()); 739 } 740 741 /** 742 * Hooks up an adjustment to focus handling in a container, so when a child 743 * of the container is focused, the adjustment is scrolled to show that 744 * widget. This function sets the horizontal alignment. 745 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining 746 * the adjustment and gtk_container_set_focus_vadjustment() for setting 747 * the vertical adjustment. 748 * 749 * The adjustments have to be in pixel units and in the same coordinate 750 * system as the allocation for immediate children of the container. 751 * 752 * Params: 753 * adjustment = an adjustment which should be adjusted when the focus is 754 * moved among the descendents of @container 755 */ 756 public void setFocusHadjustment(Adjustment adjustment) 757 { 758 gtk_container_set_focus_hadjustment(gtkContainer, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 759 } 760 761 /** 762 * Hooks up an adjustment to focus handling in a container, so when a 763 * child of the container is focused, the adjustment is scrolled to 764 * show that widget. This function sets the vertical alignment. See 765 * gtk_scrolled_window_get_vadjustment() for a typical way of obtaining 766 * the adjustment and gtk_container_set_focus_hadjustment() for setting 767 * the horizontal adjustment. 768 * 769 * The adjustments have to be in pixel units and in the same coordinate 770 * system as the allocation for immediate children of the container. 771 * 772 * Params: 773 * adjustment = an adjustment which should be adjusted when the focus 774 * is moved among the descendents of @container 775 */ 776 public void setFocusVadjustment(Adjustment adjustment) 777 { 778 gtk_container_set_focus_vadjustment(gtkContainer, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 779 } 780 781 /** 782 * Sets the @reallocate_redraws flag of the container to the given value. 783 * 784 * Containers requesting reallocation redraws get automatically 785 * redrawn if any of their children changed allocation. 786 * 787 * Deprecated: Call gtk_widget_queue_draw() in your size_allocate handler. 788 * 789 * Params: 790 * needsRedraws = the new value for the container’s @reallocate_redraws flag 791 */ 792 public void setReallocateRedraws(bool needsRedraws) 793 { 794 gtk_container_set_reallocate_redraws(gtkContainer, needsRedraws); 795 } 796 797 /** 798 * Sets the resize mode for the container. 799 * 800 * The resize mode of a container determines whether a resize request 801 * will be passed to the container’s parent, queued for later execution 802 * or executed immediately. 803 * 804 * Deprecated: Resize modes are deprecated. They aren’t necessary 805 * anymore since frame clocks and might introduce obscure bugs if 806 * used. 807 * 808 * Params: 809 * resizeMode = the new resize mode 810 */ 811 public void setResizeMode(GtkResizeMode resizeMode) 812 { 813 gtk_container_set_resize_mode(gtkContainer, resizeMode); 814 } 815 816 /** 817 * Removes a focus chain explicitly set with gtk_container_set_focus_chain(). 818 */ 819 public void unsetFocusChain() 820 { 821 gtk_container_unset_focus_chain(gtkContainer); 822 } 823 824 protected class OnAddDelegateWrapper 825 { 826 void delegate(Widget, Container) dlg; 827 gulong handlerId; 828 829 this(void delegate(Widget, Container) dlg) 830 { 831 this.dlg = dlg; 832 onAddListeners ~= this; 833 } 834 835 void remove(OnAddDelegateWrapper source) 836 { 837 foreach(index, wrapper; onAddListeners) 838 { 839 if (wrapper.handlerId == source.handlerId) 840 { 841 onAddListeners[index] = null; 842 onAddListeners = std.algorithm.remove(onAddListeners, index); 843 break; 844 } 845 } 846 } 847 } 848 OnAddDelegateWrapper[] onAddListeners; 849 850 /** */ 851 gulong addOnAdd(void delegate(Widget, Container) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 852 { 853 auto wrapper = new OnAddDelegateWrapper(dlg); 854 wrapper.handlerId = Signals.connectData( 855 this, 856 "add", 857 cast(GCallback)&callBackAdd, 858 cast(void*)wrapper, 859 cast(GClosureNotify)&callBackAddDestroy, 860 connectFlags); 861 return wrapper.handlerId; 862 } 863 864 extern(C) static void callBackAdd(GtkContainer* containerStruct, GtkWidget* object, OnAddDelegateWrapper wrapper) 865 { 866 wrapper.dlg(ObjectG.getDObject!(Widget)(object), wrapper.outer); 867 } 868 869 extern(C) static void callBackAddDestroy(OnAddDelegateWrapper wrapper, GClosure* closure) 870 { 871 wrapper.remove(wrapper); 872 } 873 874 protected class OnCheckResizeDelegateWrapper 875 { 876 void delegate(Container) dlg; 877 gulong handlerId; 878 879 this(void delegate(Container) dlg) 880 { 881 this.dlg = dlg; 882 onCheckResizeListeners ~= this; 883 } 884 885 void remove(OnCheckResizeDelegateWrapper source) 886 { 887 foreach(index, wrapper; onCheckResizeListeners) 888 { 889 if (wrapper.handlerId == source.handlerId) 890 { 891 onCheckResizeListeners[index] = null; 892 onCheckResizeListeners = std.algorithm.remove(onCheckResizeListeners, index); 893 break; 894 } 895 } 896 } 897 } 898 OnCheckResizeDelegateWrapper[] onCheckResizeListeners; 899 900 /** */ 901 gulong addOnCheckResize(void delegate(Container) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 902 { 903 auto wrapper = new OnCheckResizeDelegateWrapper(dlg); 904 wrapper.handlerId = Signals.connectData( 905 this, 906 "check-resize", 907 cast(GCallback)&callBackCheckResize, 908 cast(void*)wrapper, 909 cast(GClosureNotify)&callBackCheckResizeDestroy, 910 connectFlags); 911 return wrapper.handlerId; 912 } 913 914 extern(C) static void callBackCheckResize(GtkContainer* containerStruct, OnCheckResizeDelegateWrapper wrapper) 915 { 916 wrapper.dlg(wrapper.outer); 917 } 918 919 extern(C) static void callBackCheckResizeDestroy(OnCheckResizeDelegateWrapper wrapper, GClosure* closure) 920 { 921 wrapper.remove(wrapper); 922 } 923 924 protected class OnRemoveDelegateWrapper 925 { 926 void delegate(Widget, Container) dlg; 927 gulong handlerId; 928 929 this(void delegate(Widget, Container) dlg) 930 { 931 this.dlg = dlg; 932 onRemoveListeners ~= this; 933 } 934 935 void remove(OnRemoveDelegateWrapper source) 936 { 937 foreach(index, wrapper; onRemoveListeners) 938 { 939 if (wrapper.handlerId == source.handlerId) 940 { 941 onRemoveListeners[index] = null; 942 onRemoveListeners = std.algorithm.remove(onRemoveListeners, index); 943 break; 944 } 945 } 946 } 947 } 948 OnRemoveDelegateWrapper[] onRemoveListeners; 949 950 /** */ 951 gulong addOnRemove(void delegate(Widget, Container) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 952 { 953 auto wrapper = new OnRemoveDelegateWrapper(dlg); 954 wrapper.handlerId = Signals.connectData( 955 this, 956 "remove", 957 cast(GCallback)&callBackRemove, 958 cast(void*)wrapper, 959 cast(GClosureNotify)&callBackRemoveDestroy, 960 connectFlags); 961 return wrapper.handlerId; 962 } 963 964 extern(C) static void callBackRemove(GtkContainer* containerStruct, GtkWidget* object, OnRemoveDelegateWrapper wrapper) 965 { 966 wrapper.dlg(ObjectG.getDObject!(Widget)(object), wrapper.outer); 967 } 968 969 extern(C) static void callBackRemoveDestroy(OnRemoveDelegateWrapper wrapper, GClosure* closure) 970 { 971 wrapper.remove(wrapper); 972 } 973 974 protected class OnSetFocusChildDelegateWrapper 975 { 976 void delegate(Widget, Container) dlg; 977 gulong handlerId; 978 979 this(void delegate(Widget, Container) dlg) 980 { 981 this.dlg = dlg; 982 onSetFocusChildListeners ~= this; 983 } 984 985 void remove(OnSetFocusChildDelegateWrapper source) 986 { 987 foreach(index, wrapper; onSetFocusChildListeners) 988 { 989 if (wrapper.handlerId == source.handlerId) 990 { 991 onSetFocusChildListeners[index] = null; 992 onSetFocusChildListeners = std.algorithm.remove(onSetFocusChildListeners, index); 993 break; 994 } 995 } 996 } 997 } 998 OnSetFocusChildDelegateWrapper[] onSetFocusChildListeners; 999 1000 /** */ 1001 gulong addOnSetFocusChild(void delegate(Widget, Container) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1002 { 1003 auto wrapper = new OnSetFocusChildDelegateWrapper(dlg); 1004 wrapper.handlerId = Signals.connectData( 1005 this, 1006 "set-focus-child", 1007 cast(GCallback)&callBackSetFocusChild, 1008 cast(void*)wrapper, 1009 cast(GClosureNotify)&callBackSetFocusChildDestroy, 1010 connectFlags); 1011 return wrapper.handlerId; 1012 } 1013 1014 extern(C) static void callBackSetFocusChild(GtkContainer* containerStruct, GtkWidget* object, OnSetFocusChildDelegateWrapper wrapper) 1015 { 1016 wrapper.dlg(ObjectG.getDObject!(Widget)(object), wrapper.outer); 1017 } 1018 1019 extern(C) static void callBackSetFocusChildDestroy(OnSetFocusChildDelegateWrapper wrapper, GClosure* closure) 1020 { 1021 wrapper.remove(wrapper); 1022 } 1023 }