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.Expander; 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 gobject.Signals; 32 private import gtk.Widget; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 private import std.algorithm; 36 37 38 /** 39 * `GtkExpander` allows the user to reveal its child by clicking 40 * on an expander triangle. 41 * 42 * ![An example GtkExpander](expander.png) 43 * 44 * This is similar to the triangles used in a `GtkTreeView`. 45 * 46 * Normally you use an expander as you would use a frame; you create 47 * the child widget and use [method@Gtk.Expander.set_child] to add it 48 * to the expander. When the expander is toggled, it will take care of 49 * showing and hiding the child automatically. 50 * 51 * # Special Usage 52 * 53 * There are situations in which you may prefer to show and hide the 54 * expanded widget yourself, such as when you want to actually create 55 * the widget at expansion time. In this case, create a `GtkExpander` 56 * but do not add a child to it. The expander widget has an 57 * [property@Gtk.Expander:expanded[ property which can be used to 58 * monitor its expansion state. You should watch this property with 59 * a signal connection as follows: 60 * 61 * ```c 62 * static void 63 * expander_callback (GObject *object, 64 * GParamSpec *param_spec, 65 * gpointer user_data) 66 * { 67 * GtkExpander *expander; 68 * 69 * expander = GTK_EXPANDER (object); 70 * 71 * if (gtk_expander_get_expanded (expander)) 72 * { 73 * // Show or create widgets 74 * } 75 * else 76 * { 77 * // Hide or destroy widgets 78 * } 79 * } 80 * 81 * static void 82 * create_expander (void) 83 * { 84 * GtkWidget *expander = gtk_expander_new_with_mnemonic ("_More Options"); 85 * g_signal_connect (expander, "notify::expanded", 86 * G_CALLBACK (expander_callback), NULL); 87 * 88 * // ... 89 * } 90 * ``` 91 * 92 * # GtkExpander as GtkBuildable 93 * 94 * The `GtkExpander` implementation of the `GtkBuildable` interface supports 95 * placing a child in the label position by specifying “label” as the 96 * “type” attribute of a <child> element. A normal content child can be 97 * specified without specifying a <child> type attribute. 98 * 99 * An example of a UI definition fragment with GtkExpander: 100 * 101 * ```xml 102 * <object class="GtkExpander"> 103 * <child type="label"> 104 * <object class="GtkLabel" id="expander-label"/> 105 * </child> 106 * <child> 107 * <object class="GtkEntry" id="expander-content"/> 108 * </child> 109 * </object> 110 * ``` 111 * 112 * # CSS nodes 113 * 114 * ``` 115 * expander 116 * ╰── box 117 * ├── title 118 * │ ├── arrow 119 * │ ╰── <label widget> 120 * ╰── <child> 121 * ``` 122 * 123 * `GtkExpander` has three CSS nodes, the main node with the name expander, 124 * a subnode with name title and node below it with name arrow. The arrow of an 125 * expander that is showing its child gets the :checked pseudoclass added to it. 126 * 127 * # Accessibility 128 * 129 * `GtkExpander` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role. 130 */ 131 public class Expander : Widget 132 { 133 /** the main Gtk struct */ 134 protected GtkExpander* gtkExpander; 135 136 /** Get the main Gtk struct */ 137 public GtkExpander* getExpanderStruct(bool transferOwnership = false) 138 { 139 if (transferOwnership) 140 ownedRef = false; 141 return gtkExpander; 142 } 143 144 /** the main Gtk struct as a void* */ 145 protected override void* getStruct() 146 { 147 return cast(void*)gtkExpander; 148 } 149 150 /** 151 * Sets our main struct and passes it to the parent class. 152 */ 153 public this (GtkExpander* gtkExpander, bool ownedRef = false) 154 { 155 this.gtkExpander = gtkExpander; 156 super(cast(GtkWidget*)gtkExpander, ownedRef); 157 } 158 159 160 /** */ 161 public static GType getType() 162 { 163 return gtk_expander_get_type(); 164 } 165 166 /** 167 * Creates a new expander using @label as the text of the label. 168 * 169 * If characters in @label are preceded by an underscore, they are 170 * underlined. If you need a literal underscore character in a label, 171 * use “__” (two underscores). The first underlined character represents 172 * a keyboard accelerator called a mnemonic. 173 * 174 * Pressing Alt and that key activates the button. 175 * 176 * Params: 177 * label = the text of the label with an underscore 178 * in front of the mnemonic character 179 * 180 * Returns: a new `GtkExpander` widget. 181 * 182 * Throws: ConstructionException GTK+ fails to create the object. 183 */ 184 public this(string label) 185 { 186 auto __p = gtk_expander_new_with_mnemonic(Str.toStringz(label)); 187 188 if(__p is null) 189 { 190 throw new ConstructionException("null returned by new_with_mnemonic"); 191 } 192 193 this(cast(GtkExpander*) __p); 194 } 195 196 /** 197 * Gets the child widget of @expander. 198 * 199 * Returns: the child widget of @expander 200 */ 201 public Widget getChild() 202 { 203 auto __p = gtk_expander_get_child(gtkExpander); 204 205 if(__p is null) 206 { 207 return null; 208 } 209 210 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 211 } 212 213 /** 214 * Queries a #GtkExpander and returns its current state. 215 * 216 * Returns %TRUE if the child widget is revealed. 217 * 218 * Returns: the current state of the expander 219 */ 220 public bool getExpanded() 221 { 222 return gtk_expander_get_expanded(gtkExpander) != 0; 223 } 224 225 /** 226 * Fetches the text from a label widget. 227 * 228 * This is including any embedded underlines indicating mnemonics and 229 * Pango markup, as set by [method@Gtk.Expander.set_label]. If the label 230 * text has not been set the return value will be %NULL. This will be the 231 * case if you create an empty button with gtk_button_new() to use as a 232 * container. 233 * 234 * Returns: The text of the label widget. This string is owned 235 * by the widget and must not be modified or freed. 236 */ 237 public string getLabel() 238 { 239 return Str.toString(gtk_expander_get_label(gtkExpander)); 240 } 241 242 /** 243 * Retrieves the label widget for the frame. 244 * 245 * Returns: the label widget, 246 * or %NULL if there is none 247 */ 248 public Widget getLabelWidget() 249 { 250 auto __p = gtk_expander_get_label_widget(gtkExpander); 251 252 if(__p is null) 253 { 254 return null; 255 } 256 257 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 258 } 259 260 /** 261 * Returns whether the expander will resize the toplevel widget 262 * containing the expander upon resizing and collpasing. 263 * 264 * Returns: the “resize toplevel” setting. 265 */ 266 public bool getResizeToplevel() 267 { 268 return gtk_expander_get_resize_toplevel(gtkExpander) != 0; 269 } 270 271 /** 272 * Returns whether the label’s text is interpreted as Pango markup. 273 * 274 * Returns: %TRUE if the label’s text will be parsed for markup 275 */ 276 public bool getUseMarkup() 277 { 278 return gtk_expander_get_use_markup(gtkExpander) != 0; 279 } 280 281 /** 282 * Returns whether an underline in the text indicates a mnemonic. 283 * 284 * Returns: %TRUE if an embedded underline in the expander 285 * label indicates the mnemonic accelerator keys 286 */ 287 public bool getUseUnderline() 288 { 289 return gtk_expander_get_use_underline(gtkExpander) != 0; 290 } 291 292 /** 293 * Sets the child widget of @expander. 294 * 295 * Params: 296 * child = the child widget 297 */ 298 public void setChild(Widget child) 299 { 300 gtk_expander_set_child(gtkExpander, (child is null) ? null : child.getWidgetStruct()); 301 } 302 303 /** 304 * Sets the state of the expander. 305 * 306 * Set to %TRUE, if you want the child widget to be revealed, 307 * and %FALSE if you want the child widget to be hidden. 308 * 309 * Params: 310 * expanded = whether the child widget is revealed 311 */ 312 public void setExpanded(bool expanded) 313 { 314 gtk_expander_set_expanded(gtkExpander, expanded); 315 } 316 317 /** 318 * Sets the text of the label of the expander to @label. 319 * 320 * This will also clear any previously set labels. 321 * 322 * Params: 323 * label = a string 324 */ 325 public void setLabel(string label) 326 { 327 gtk_expander_set_label(gtkExpander, Str.toStringz(label)); 328 } 329 330 /** 331 * Set the label widget for the expander. 332 * 333 * This is the widget that will appear embedded alongside 334 * the expander arrow. 335 * 336 * Params: 337 * labelWidget = the new label widget 338 */ 339 public void setLabelWidget(Widget labelWidget) 340 { 341 gtk_expander_set_label_widget(gtkExpander, (labelWidget is null) ? null : labelWidget.getWidgetStruct()); 342 } 343 344 /** 345 * Sets whether the expander will resize the toplevel widget 346 * containing the expander upon resizing and collpasing. 347 * 348 * Params: 349 * resizeToplevel = whether to resize the toplevel 350 */ 351 public void setResizeToplevel(bool resizeToplevel) 352 { 353 gtk_expander_set_resize_toplevel(gtkExpander, resizeToplevel); 354 } 355 356 /** 357 * Sets whether the text of the label contains Pango markup. 358 * 359 * Params: 360 * useMarkup = %TRUE if the label’s text should be parsed for markup 361 */ 362 public void setUseMarkup(bool useMarkup) 363 { 364 gtk_expander_set_use_markup(gtkExpander, useMarkup); 365 } 366 367 /** 368 * If true, an underline in the text indicates a mnemonic. 369 * 370 * Params: 371 * useUnderline = %TRUE if underlines in the text indicate mnemonics 372 */ 373 public void setUseUnderline(bool useUnderline) 374 { 375 gtk_expander_set_use_underline(gtkExpander, useUnderline); 376 } 377 378 /** 379 * Activates the `GtkExpander`. 380 */ 381 gulong addOnActivate(void delegate(Expander) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 382 { 383 return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED); 384 } 385 }