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.Stack; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 private import gobject.ObjectG; 31 private import gtk.SelectionModelIF; 32 private import gtk.StackPage; 33 private import gtk.Widget; 34 private import gtk.c.functions; 35 public import gtk.c.types; 36 37 38 /** 39 * `GtkStack` is a container which only shows one of its children 40 * at a time. 41 * 42 * In contrast to `GtkNotebook`, `GtkStack` does not provide a means 43 * for users to change the visible child. Instead, a separate widget 44 * such as [class@Gtk.StackSwitcher] or [class@Gtk.StackSidebar] can 45 * be used with `GtkStack` to provide this functionality. 46 * 47 * Transitions between pages can be animated as slides or fades. This 48 * can be controlled with [method@Gtk.Stack.set_transition_type]. 49 * These animations respect the [property@Gtk.Settings:gtk-enable-animations] 50 * setting. 51 * 52 * `GtkStack` maintains a [class@Gtk.StackPage] object for each added 53 * child, which holds additional per-child properties. You 54 * obtain the `GtkStackPage` for a child with [method@Gtk.Stack.get_page] 55 * and you can obtain a `GtkSelectionModel` containing all the pages 56 * with [method@Gtk.Stack.get_pages]. 57 * 58 * # GtkStack as GtkBuildable 59 * 60 * To set child-specific properties in a .ui file, create `GtkStackPage` 61 * objects explicitly, and set the child widget as a property on it: 62 * 63 * ```xml 64 * <object class="GtkStack" id="stack"> 65 * <child> 66 * <object class="GtkStackPage"> 67 * <property name="name">page1</property> 68 * <property name="title">In the beginning…</property> 69 * <property name="child"> 70 * <object class="GtkLabel"> 71 * <property name="label">It was dark</property> 72 * </object> 73 * </property> 74 * </object> 75 * </child> 76 * ``` 77 * 78 * # CSS nodes 79 * 80 * `GtkStack` has a single CSS node named stack. 81 * 82 * # Accessibility 83 * 84 * `GtkStack` uses the %GTK_ACCESSIBLE_ROLE_TAB_PANEL for the stack 85 * pages, which are the accessible parent objects of the child widgets. 86 */ 87 public class Stack : Widget 88 { 89 /** the main Gtk struct */ 90 protected GtkStack* gtkStack; 91 92 /** Get the main Gtk struct */ 93 public GtkStack* getStackStruct(bool transferOwnership = false) 94 { 95 if (transferOwnership) 96 ownedRef = false; 97 return gtkStack; 98 } 99 100 /** the main Gtk struct as a void* */ 101 protected override void* getStruct() 102 { 103 return cast(void*)gtkStack; 104 } 105 106 /** 107 * Sets our main struct and passes it to the parent class. 108 */ 109 public this (GtkStack* gtkStack, bool ownedRef = false) 110 { 111 this.gtkStack = gtkStack; 112 super(cast(GtkWidget*)gtkStack, ownedRef); 113 } 114 115 116 /** */ 117 public static GType getType() 118 { 119 return gtk_stack_get_type(); 120 } 121 122 /** 123 * Creates a new `GtkStack`. 124 * 125 * Returns: a new `GtkStack` 126 * 127 * Throws: ConstructionException GTK+ fails to create the object. 128 */ 129 public this() 130 { 131 auto __p = gtk_stack_new(); 132 133 if(__p is null) 134 { 135 throw new ConstructionException("null returned by new"); 136 } 137 138 this(cast(GtkStack*) __p); 139 } 140 141 /** 142 * Adds a child to @stack. 143 * 144 * Params: 145 * child = the widget to add 146 * 147 * Returns: the `GtkStackPage` for @child 148 */ 149 public StackPage addChild(Widget child) 150 { 151 auto __p = gtk_stack_add_child(gtkStack, (child is null) ? null : child.getWidgetStruct()); 152 153 if(__p is null) 154 { 155 return null; 156 } 157 158 return ObjectG.getDObject!(StackPage)(cast(GtkStackPage*) __p); 159 } 160 161 /** 162 * Adds a child to @stack. 163 * 164 * The child is identified by the @name. 165 * 166 * Params: 167 * child = the widget to add 168 * name = the name for @child or %NULL 169 * 170 * Returns: the `GtkStackPage` for @child 171 */ 172 public StackPage addNamed(Widget child, string name) 173 { 174 auto __p = gtk_stack_add_named(gtkStack, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(name)); 175 176 if(__p is null) 177 { 178 return null; 179 } 180 181 return ObjectG.getDObject!(StackPage)(cast(GtkStackPage*) __p); 182 } 183 184 /** 185 * Adds a child to @stack. 186 * 187 * The child is identified by the @name. The @title 188 * will be used by `GtkStackSwitcher` to represent 189 * @child in a tab bar, so it should be short. 190 * 191 * Params: 192 * child = the widget to add 193 * name = the name for @child 194 * title = a human-readable title for @child 195 * 196 * Returns: the `GtkStackPage` for @child 197 */ 198 public StackPage addTitled(Widget child, string name, string title) 199 { 200 auto __p = gtk_stack_add_titled(gtkStack, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(name), Str.toStringz(title)); 201 202 if(__p is null) 203 { 204 return null; 205 } 206 207 return ObjectG.getDObject!(StackPage)(cast(GtkStackPage*) __p); 208 } 209 210 /** 211 * Finds the child with the name given as the argument. 212 * 213 * Returns %NULL if there is no child with this name. 214 * 215 * Params: 216 * name = the name of the child to find 217 * 218 * Returns: the requested child 219 * of the `GtkStack` 220 */ 221 public Widget getChildByName(string name) 222 { 223 auto __p = gtk_stack_get_child_by_name(gtkStack, Str.toStringz(name)); 224 225 if(__p is null) 226 { 227 return null; 228 } 229 230 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 231 } 232 233 /** 234 * Gets whether @stack is horizontally homogeneous. 235 * 236 * Returns: whether @stack is horizontally homogeneous. 237 */ 238 public bool getHhomogeneous() 239 { 240 return gtk_stack_get_hhomogeneous(gtkStack) != 0; 241 } 242 243 /** 244 * Returns whether the #GtkStack is set up to interpolate between 245 * the sizes of children on page switch. 246 * 247 * Returns: %TRUE if child sizes are interpolated 248 */ 249 public bool getInterpolateSize() 250 { 251 return gtk_stack_get_interpolate_size(gtkStack) != 0; 252 } 253 254 /** 255 * Returns the `GtkStackPage` object for @child. 256 * 257 * Params: 258 * child = a child of @stack 259 * 260 * Returns: the `GtkStackPage` for @child 261 */ 262 public StackPage getPage(Widget child) 263 { 264 auto __p = gtk_stack_get_page(gtkStack, (child is null) ? null : child.getWidgetStruct()); 265 266 if(__p is null) 267 { 268 return null; 269 } 270 271 return ObjectG.getDObject!(StackPage)(cast(GtkStackPage*) __p); 272 } 273 274 /** 275 * Returns a `GListModel` that contains the pages of the stack. 276 * 277 * This can be used to keep an up-to-date view. The model also 278 * implements [iface@Gtk.SelectionModel] and can be used to track 279 * and modify the visible page. 280 * 281 * Returns: a `GtkSelectionModel` for the stack's children 282 */ 283 public SelectionModelIF getPages() 284 { 285 auto __p = gtk_stack_get_pages(gtkStack); 286 287 if(__p is null) 288 { 289 return null; 290 } 291 292 return ObjectG.getDObject!(SelectionModelIF)(cast(GtkSelectionModel*) __p, true); 293 } 294 295 /** 296 * Returns the amount of time (in milliseconds) that 297 * transitions between pages in @stack will take. 298 * 299 * Returns: the transition duration 300 */ 301 public uint getTransitionDuration() 302 { 303 return gtk_stack_get_transition_duration(gtkStack); 304 } 305 306 /** 307 * Returns whether the @stack is currently in a transition from one page to 308 * another. 309 * 310 * Returns: %TRUE if the transition is currently running, %FALSE otherwise. 311 */ 312 public bool getTransitionRunning() 313 { 314 return gtk_stack_get_transition_running(gtkStack) != 0; 315 } 316 317 /** 318 * Gets the type of animation that will be used 319 * for transitions between pages in @stack. 320 * 321 * Returns: the current transition type of @stack 322 */ 323 public GtkStackTransitionType getTransitionType() 324 { 325 return gtk_stack_get_transition_type(gtkStack); 326 } 327 328 /** 329 * Gets whether @stack is vertically homogeneous. 330 * 331 * Returns: whether @stack is vertically homogeneous. 332 */ 333 public bool getVhomogeneous() 334 { 335 return gtk_stack_get_vhomogeneous(gtkStack) != 0; 336 } 337 338 /** 339 * Gets the currently visible child of @stack. 340 * 341 * Returns %NULL if there are no visible children. 342 * 343 * Returns: the visible child of the `GtkStack` 344 */ 345 public Widget getVisibleChild() 346 { 347 auto __p = gtk_stack_get_visible_child(gtkStack); 348 349 if(__p is null) 350 { 351 return null; 352 } 353 354 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 355 } 356 357 /** 358 * Returns the name of the currently visible child of @stack. 359 * 360 * Returns %NULL if there is no visible child. 361 * 362 * Returns: the name of the visible child 363 * of the `GtkStack` 364 */ 365 public string getVisibleChildName() 366 { 367 return Str.toString(gtk_stack_get_visible_child_name(gtkStack)); 368 } 369 370 /** 371 * Removes a child widget from @stack. 372 * 373 * Params: 374 * child = the child to remove 375 */ 376 public void remove(Widget child) 377 { 378 gtk_stack_remove(gtkStack, (child is null) ? null : child.getWidgetStruct()); 379 } 380 381 /** 382 * Sets the `GtkStack` to be horizontally homogeneous or not. 383 * 384 * If it is homogeneous, the `GtkStack` will request the same 385 * width for all its children. If it isn't, the stack 386 * may change width when a different child becomes visible. 387 * 388 * Params: 389 * hhomogeneous = %TRUE to make @stack horizontally homogeneous 390 */ 391 public void setHhomogeneous(bool hhomogeneous) 392 { 393 gtk_stack_set_hhomogeneous(gtkStack, hhomogeneous); 394 } 395 396 /** 397 * Sets whether or not @stack will interpolate its size when 398 * changing the visible child. 399 * 400 * If the [property@Gtk.Stack:interpolate-size] property is set 401 * to %TRUE, @stack will interpolate its size between the current 402 * one and the one it'll take after changing the visible child, 403 * according to the set transition duration. 404 * 405 * Params: 406 * interpolateSize = the new value 407 */ 408 public void setInterpolateSize(bool interpolateSize) 409 { 410 gtk_stack_set_interpolate_size(gtkStack, interpolateSize); 411 } 412 413 /** 414 * Sets the duration that transitions between pages in @stack 415 * will take. 416 * 417 * Params: 418 * duration = the new duration, in milliseconds 419 */ 420 public void setTransitionDuration(uint duration) 421 { 422 gtk_stack_set_transition_duration(gtkStack, duration); 423 } 424 425 /** 426 * Sets the type of animation that will be used for 427 * transitions between pages in @stack. 428 * 429 * Available types include various kinds of fades and slides. 430 * 431 * The transition type can be changed without problems 432 * at runtime, so it is possible to change the animation 433 * based on the page that is about to become current. 434 * 435 * Params: 436 * transition = the new transition type 437 */ 438 public void setTransitionType(GtkStackTransitionType transition) 439 { 440 gtk_stack_set_transition_type(gtkStack, transition); 441 } 442 443 /** 444 * Sets the #GtkStack to be vertically homogeneous or not. 445 * 446 * If it is homogeneous, the `GtkStack` will request the same 447 * height for all its children. If it isn't, the stack 448 * may change height when a different child becomes visible. 449 * 450 * Params: 451 * vhomogeneous = %TRUE to make @stack vertically homogeneous 452 */ 453 public void setVhomogeneous(bool vhomogeneous) 454 { 455 gtk_stack_set_vhomogeneous(gtkStack, vhomogeneous); 456 } 457 458 /** 459 * Makes @child the visible child of @stack. 460 * 461 * If @child is different from the currently visible child, 462 * the transition between the two will be animated with the 463 * current transition type of @stack. 464 * 465 * Note that the @child widget has to be visible itself 466 * (see [method@Gtk.Widget.show]) in order to become the visible 467 * child of @stack. 468 * 469 * Params: 470 * child = a child of @stack 471 */ 472 public void setVisibleChild(Widget child) 473 { 474 gtk_stack_set_visible_child(gtkStack, (child is null) ? null : child.getWidgetStruct()); 475 } 476 477 /** 478 * Makes the child with the given name visible. 479 * 480 * Note that the child widget has to be visible itself 481 * (see [method@Gtk.Widget.show]) in order to become the visible 482 * child of @stack. 483 * 484 * Params: 485 * name = the name of the child to make visible 486 * transition = the transition type to use 487 */ 488 public void setVisibleChildFull(string name, GtkStackTransitionType transition) 489 { 490 gtk_stack_set_visible_child_full(gtkStack, Str.toStringz(name), transition); 491 } 492 493 /** 494 * Makes the child with the given name visible. 495 * 496 * If @child is different from the currently visible child, 497 * the transition between the two will be animated with the 498 * current transition type of @stack. 499 * 500 * Note that the child widget has to be visible itself 501 * (see [method@Gtk.Widget.show]) in order to become the visible 502 * child of @stack. 503 * 504 * Params: 505 * name = the name of the child to make visible 506 */ 507 public void setVisibleChildName(string name) 508 { 509 gtk_stack_set_visible_child_name(gtkStack, Str.toStringz(name)); 510 } 511 }