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.Button; 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.ActionableIF; 33 private import gtk.ActionableT; 34 private import gtk.Widget; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 private import std.algorithm; 38 39 40 /** 41 * The `GtkButton` widget is generally used to trigger a callback function that is 42 * called when the button is pressed. 43 * 44 * ![An example GtkButton](button.png) 45 * 46 * The `GtkButton` widget can hold any valid child widget. That is, it can hold 47 * almost any other standard `GtkWidget`. The most commonly used child is the 48 * `GtkLabel`. 49 * 50 * # CSS nodes 51 * 52 * `GtkButton` has a single CSS node with name button. The node will get the 53 * style classes .image-button or .text-button, if the content is just an 54 * image or label, respectively. It may also receive the .flat style class. 55 * When activating a button via the keyboard, the button will temporarily 56 * gain the .keyboard-activating style class. 57 * 58 * Other style classes that are commonly used with `GtkButton` include 59 * .suggested-action and .destructive-action. In special cases, buttons 60 * can be made round by adding the .circular style class. 61 * 62 * Button-like widgets like [class@Gtk.ToggleButton], [class@Gtk.MenuButton], 63 * [class@Gtk.VolumeButton], [class@Gtk.LockButton], [class@Gtk.ColorButton] 64 * or [class@Gtk.FontButton] use style classes such as .toggle, .popup, .scale, 65 * .lock, .color on the button node to differentiate themselves from a plain 66 * `GtkButton`. 67 * 68 * # Accessibility 69 * 70 * `GtkButton` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role. 71 */ 72 public class Button : Widget, ActionableIF 73 { 74 /** the main Gtk struct */ 75 protected GtkButton* gtkButton; 76 77 /** Get the main Gtk struct */ 78 public GtkButton* getButtonStruct(bool transferOwnership = false) 79 { 80 if (transferOwnership) 81 ownedRef = false; 82 return gtkButton; 83 } 84 85 /** the main Gtk struct as a void* */ 86 protected override void* getStruct() 87 { 88 return cast(void*)gtkButton; 89 } 90 91 /** 92 * Sets our main struct and passes it to the parent class. 93 */ 94 public this (GtkButton* gtkButton, bool ownedRef = false) 95 { 96 this.gtkButton = gtkButton; 97 super(cast(GtkWidget*)gtkButton, ownedRef); 98 } 99 100 // add the Actionable capabilities 101 mixin ActionableT!(GtkButton); 102 103 104 /** */ 105 public static GType getType() 106 { 107 return gtk_button_get_type(); 108 } 109 110 /** 111 * Creates a new `GtkButton` widget. 112 * 113 * To add a child widget to the button, use [method@Gtk.Button.set_child]. 114 * 115 * Returns: The newly created `GtkButton` widget. 116 * 117 * Throws: ConstructionException GTK+ fails to create the object. 118 */ 119 public this() 120 { 121 auto __p = gtk_button_new(); 122 123 if(__p is null) 124 { 125 throw new ConstructionException("null returned by new"); 126 } 127 128 this(cast(GtkButton*) __p); 129 } 130 131 /** 132 * Creates a new `GtkButton` containing a label. 133 * 134 * If characters in @label are preceded by an underscore, they are underlined. 135 * If you need a literal underscore character in a label, use “__” (two 136 * underscores). The first underlined character represents a keyboard 137 * accelerator called a mnemonic. Pressing Alt and that key activates the button. 138 * 139 * Params: 140 * label = The text of the button, with an underscore in front of the 141 * mnemonic character 142 * 143 * Returns: a new `GtkButton` 144 * 145 * Throws: ConstructionException GTK+ fails to create the object. 146 */ 147 public this(string label) 148 { 149 auto __p = gtk_button_new_with_mnemonic(Str.toStringz(label)); 150 151 if(__p is null) 152 { 153 throw new ConstructionException("null returned by new_with_mnemonic"); 154 } 155 156 this(cast(GtkButton*) __p); 157 } 158 159 /** 160 * Gets the child widget of @button. 161 * 162 * Returns: the child widget of @button 163 */ 164 public Widget getChild() 165 { 166 auto __p = gtk_button_get_child(gtkButton); 167 168 if(__p is null) 169 { 170 return null; 171 } 172 173 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 174 } 175 176 /** 177 * Returns whether the button has a frame. 178 * 179 * Returns: %TRUE if the button has a frame 180 */ 181 public bool getHasFrame() 182 { 183 return gtk_button_get_has_frame(gtkButton) != 0; 184 } 185 186 /** 187 * Returns the icon name of the button. 188 * 189 * If the icon name has not been set with [method@Gtk.Button.set_icon_name] 190 * the return value will be %NULL. This will be the case if you create 191 * an empty button with [ctor@Gtk.Button.new] to use as a container. 192 * 193 * Returns: The icon name set via [method@Gtk.Button.set_icon_name] 194 */ 195 public string getIconName() 196 { 197 return Str.toString(gtk_button_get_icon_name(gtkButton)); 198 } 199 200 /** 201 * Fetches the text from the label of the button. 202 * 203 * If the label text has not been set with [method@Gtk.Button.set_label] 204 * the return value will be %NULL. This will be the case if you create 205 * an empty button with [ctor@Gtk.Button.new] to use as a container. 206 * 207 * Returns: The text of the label widget. This string is owned 208 * by the widget and must not be modified or freed. 209 */ 210 public string getLabel() 211 { 212 return Str.toString(gtk_button_get_label(gtkButton)); 213 } 214 215 /** 216 * gets whether underlines are interpreted as mnemonics. 217 * 218 * See [method@Gtk.Button.set_use_underline]. 219 * 220 * Returns: %TRUE if an embedded underline in the button label 221 * indicates the mnemonic accelerator keys. 222 */ 223 public bool getUseUnderline() 224 { 225 return gtk_button_get_use_underline(gtkButton) != 0; 226 } 227 228 /** 229 * Sets the child widget of @button. 230 * 231 * Params: 232 * child = the child widget 233 */ 234 public void setChild(Widget child) 235 { 236 gtk_button_set_child(gtkButton, (child is null) ? null : child.getWidgetStruct()); 237 } 238 239 /** 240 * Sets the style of the button. 241 * 242 * Buttons can has a flat appearance or have a frame drawn around them. 243 * 244 * Params: 245 * hasFrame = whether the button should have a visible frame 246 */ 247 public void setHasFrame(bool hasFrame) 248 { 249 gtk_button_set_has_frame(gtkButton, hasFrame); 250 } 251 252 /** 253 * Adds a `GtkImage` with the given icon name as a child. 254 * 255 * If @button already contains a child widget, that child widget will 256 * be removed and replaced with the image. 257 * 258 * Params: 259 * iconName = An icon name 260 */ 261 public void setIconName(string iconName) 262 { 263 gtk_button_set_icon_name(gtkButton, Str.toStringz(iconName)); 264 } 265 266 /** 267 * Sets the text of the label of the button to @label. 268 * 269 * This will also clear any previously set labels. 270 * 271 * Params: 272 * label = a string 273 */ 274 public void setLabel(string label) 275 { 276 gtk_button_set_label(gtkButton, Str.toStringz(label)); 277 } 278 279 /** 280 * Sets whether to use underlines as mnemonics. 281 * 282 * If true, an underline in the text of the button label indicates 283 * the next character should be used for the mnemonic accelerator key. 284 * 285 * Params: 286 * useUnderline = %TRUE if underlines in the text indicate mnemonics 287 */ 288 public void setUseUnderline(bool useUnderline) 289 { 290 gtk_button_set_use_underline(gtkButton, useUnderline); 291 } 292 293 /** 294 * Emitted to animate press then release. 295 * 296 * This is an action signal. Applications should never connect 297 * to this signal, but use the [signal@Gtk.Button::clicked] signal. 298 */ 299 gulong addOnActivate(void delegate(Button) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 300 { 301 return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED); 302 } 303 304 /** 305 * Emitted when the button has been activated (pressed and released). 306 */ 307 gulong addOnClicked(void delegate(Button) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 308 { 309 return Signals.connect(this, "clicked", dlg, connectFlags ^ ConnectFlags.SWAPPED); 310 } 311 }