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.ToolButton; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.ActionableIF; 32 private import gtk.ActionableT; 33 private import gtk.ToolItem; 34 private import gtk.Widget; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 public import gtkc.gtktypes; 38 private import std.algorithm; 39 40 41 /** 42 * #GtkToolButtons are #GtkToolItems containing buttons. 43 * 44 * Use gtk_tool_button_new() to create a new #GtkToolButton. 45 * 46 * The label of a #GtkToolButton is determined by the properties 47 * #GtkToolButton:label-widget, #GtkToolButton:label, and 48 * #GtkToolButton:stock-id. If #GtkToolButton:label-widget is 49 * non-%NULL, then that widget is used as the label. Otherwise, if 50 * #GtkToolButton:label is non-%NULL, that string is used as the label. 51 * Otherwise, if #GtkToolButton:stock-id is non-%NULL, the label is 52 * determined by the stock item. Otherwise, the button does not have a label. 53 * 54 * The icon of a #GtkToolButton is determined by the properties 55 * #GtkToolButton:icon-widget and #GtkToolButton:stock-id. If 56 * #GtkToolButton:icon-widget is non-%NULL, then 57 * that widget is used as the icon. Otherwise, if #GtkToolButton:stock-id is 58 * non-%NULL, the icon is determined by the stock item. Otherwise, 59 * the button does not have a icon. 60 * 61 * # CSS nodes 62 * 63 * GtkToolButton has a single CSS node with name toolbutton. 64 */ 65 public class ToolButton : ToolItem, ActionableIF 66 { 67 /** the main Gtk struct */ 68 protected GtkToolButton* gtkToolButton; 69 70 /** Get the main Gtk struct */ 71 public GtkToolButton* getToolButtonStruct(bool transferOwnership = false) 72 { 73 if (transferOwnership) 74 ownedRef = false; 75 return gtkToolButton; 76 } 77 78 /** the main Gtk struct as a void* */ 79 protected override void* getStruct() 80 { 81 return cast(void*)gtkToolButton; 82 } 83 84 /** 85 * Sets our main struct and passes it to the parent class. 86 */ 87 public this (GtkToolButton* gtkToolButton, bool ownedRef = false) 88 { 89 this.gtkToolButton = gtkToolButton; 90 super(cast(GtkToolItem*)gtkToolButton, ownedRef); 91 } 92 93 // add the Actionable capabilities 94 mixin ActionableT!(GtkToolButton); 95 96 /** */ 97 public this (StockID stockID) 98 { 99 this(cast(string)stockID); 100 } 101 102 /** 103 */ 104 105 /** */ 106 public static GType getType() 107 { 108 return gtk_tool_button_get_type(); 109 } 110 111 /** 112 * Creates a new #GtkToolButton using @icon_widget as contents and @label as 113 * label. 114 * 115 * Params: 116 * iconWidget = a widget that will be used as the button contents, or %NULL 117 * label = a string that will be used as label, or %NULL 118 * 119 * Returns: A new #GtkToolButton 120 * 121 * Since: 2.4 122 * 123 * Throws: ConstructionException GTK+ fails to create the object. 124 */ 125 public this(Widget iconWidget, string label) 126 { 127 auto p = gtk_tool_button_new((iconWidget is null) ? null : iconWidget.getWidgetStruct(), Str.toStringz(label)); 128 129 if(p is null) 130 { 131 throw new ConstructionException("null returned by new"); 132 } 133 134 this(cast(GtkToolButton*) p); 135 } 136 137 /** 138 * Creates a new #GtkToolButton containing the image and text from a 139 * stock item. Some stock ids have preprocessor macros like #GTK_STOCK_OK 140 * and #GTK_STOCK_APPLY. 141 * 142 * It is an error if @stock_id is not a name of a stock item. 143 * 144 * Deprecated: Use gtk_tool_button_new() together with 145 * gtk_image_new_from_icon_name() instead. 146 * 147 * Params: 148 * stockId = the name of the stock item 149 * 150 * Returns: A new #GtkToolButton 151 * 152 * Since: 2.4 153 * 154 * Throws: ConstructionException GTK+ fails to create the object. 155 */ 156 public this(string stockId) 157 { 158 auto p = gtk_tool_button_new_from_stock(Str.toStringz(stockId)); 159 160 if(p is null) 161 { 162 throw new ConstructionException("null returned by new_from_stock"); 163 } 164 165 this(cast(GtkToolButton*) p); 166 } 167 168 /** 169 * Returns the name of the themed icon for the tool button, 170 * see gtk_tool_button_set_icon_name(). 171 * 172 * Returns: the icon name or %NULL if the tool button has 173 * no themed icon 174 * 175 * Since: 2.8 176 */ 177 public string getIconName() 178 { 179 return Str.toString(gtk_tool_button_get_icon_name(gtkToolButton)); 180 } 181 182 /** 183 * Return the widget used as icon widget on @button. 184 * See gtk_tool_button_set_icon_widget(). 185 * 186 * Returns: The widget used as icon 187 * on @button, or %NULL. 188 * 189 * Since: 2.4 190 */ 191 public Widget getIconWidget() 192 { 193 auto p = gtk_tool_button_get_icon_widget(gtkToolButton); 194 195 if(p is null) 196 { 197 return null; 198 } 199 200 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 201 } 202 203 /** 204 * Returns the label used by the tool button, or %NULL if the tool button 205 * doesn’t have a label. or uses a the label from a stock item. The returned 206 * string is owned by GTK+, and must not be modified or freed. 207 * 208 * Returns: The label, or %NULL 209 * 210 * Since: 2.4 211 */ 212 public string getLabel() 213 { 214 return Str.toString(gtk_tool_button_get_label(gtkToolButton)); 215 } 216 217 /** 218 * Returns the widget used as label on @button. 219 * See gtk_tool_button_set_label_widget(). 220 * 221 * Returns: The widget used as label 222 * on @button, or %NULL. 223 * 224 * Since: 2.4 225 */ 226 public Widget getLabelWidget() 227 { 228 auto p = gtk_tool_button_get_label_widget(gtkToolButton); 229 230 if(p is null) 231 { 232 return null; 233 } 234 235 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 236 } 237 238 /** 239 * Returns the name of the stock item. See gtk_tool_button_set_stock_id(). 240 * The returned string is owned by GTK+ and must not be freed or modifed. 241 * 242 * Deprecated: Use gtk_tool_button_get_icon_name() instead. 243 * 244 * Returns: the name of the stock item for @button. 245 * 246 * Since: 2.4 247 */ 248 public string getStockId() 249 { 250 return Str.toString(gtk_tool_button_get_stock_id(gtkToolButton)); 251 } 252 253 /** 254 * Returns whether underscores in the label property are used as mnemonics 255 * on menu items on the overflow menu. See gtk_tool_button_set_use_underline(). 256 * 257 * Returns: %TRUE if underscores in the label property are used as 258 * mnemonics on menu items on the overflow menu. 259 * 260 * Since: 2.4 261 */ 262 public bool getUseUnderline() 263 { 264 return gtk_tool_button_get_use_underline(gtkToolButton) != 0; 265 } 266 267 /** 268 * Sets the icon for the tool button from a named themed icon. 269 * See the docs for #GtkIconTheme for more details. 270 * The #GtkToolButton:icon-name property only has an effect if not 271 * overridden by non-%NULL #GtkToolButton:label-widget, 272 * #GtkToolButton:icon-widget and #GtkToolButton:stock-id properties. 273 * 274 * Params: 275 * iconName = the name of the themed icon 276 * 277 * Since: 2.8 278 */ 279 public void setIconName(string iconName) 280 { 281 gtk_tool_button_set_icon_name(gtkToolButton, Str.toStringz(iconName)); 282 } 283 284 /** 285 * Sets @icon as the widget used as icon on @button. If @icon_widget is 286 * %NULL the icon is determined by the #GtkToolButton:stock-id property. If the 287 * #GtkToolButton:stock-id property is also %NULL, @button will not have an icon. 288 * 289 * Params: 290 * iconWidget = the widget used as icon, or %NULL 291 * 292 * Since: 2.4 293 */ 294 public void setIconWidget(Widget iconWidget) 295 { 296 gtk_tool_button_set_icon_widget(gtkToolButton, (iconWidget is null) ? null : iconWidget.getWidgetStruct()); 297 } 298 299 /** 300 * Sets @label as the label used for the tool button. The #GtkToolButton:label 301 * property only has an effect if not overridden by a non-%NULL 302 * #GtkToolButton:label-widget property. If both the #GtkToolButton:label-widget 303 * and #GtkToolButton:label properties are %NULL, the label is determined by the 304 * #GtkToolButton:stock-id property. If the #GtkToolButton:stock-id property is 305 * also %NULL, @button will not have a label. 306 * 307 * Params: 308 * label = a string that will be used as label, or %NULL. 309 * 310 * Since: 2.4 311 */ 312 public void setLabel(string label) 313 { 314 gtk_tool_button_set_label(gtkToolButton, Str.toStringz(label)); 315 } 316 317 /** 318 * Sets @label_widget as the widget that will be used as the label 319 * for @button. If @label_widget is %NULL the #GtkToolButton:label property is used 320 * as label. If #GtkToolButton:label is also %NULL, the label in the stock item 321 * determined by the #GtkToolButton:stock-id property is used as label. If 322 * #GtkToolButton:stock-id is also %NULL, @button does not have a label. 323 * 324 * Params: 325 * labelWidget = the widget used as label, or %NULL 326 * 327 * Since: 2.4 328 */ 329 public void setLabelWidget(Widget labelWidget) 330 { 331 gtk_tool_button_set_label_widget(gtkToolButton, (labelWidget is null) ? null : labelWidget.getWidgetStruct()); 332 } 333 334 /** 335 * Sets the name of the stock item. See gtk_tool_button_new_from_stock(). 336 * The stock_id property only has an effect if not overridden by non-%NULL 337 * #GtkToolButton:label-widget and #GtkToolButton:icon-widget properties. 338 * 339 * Deprecated: Use gtk_tool_button_set_icon_name() instead. 340 * 341 * Params: 342 * stockId = a name of a stock item, or %NULL 343 * 344 * Since: 2.4 345 */ 346 public void setStockId(string stockId) 347 { 348 gtk_tool_button_set_stock_id(gtkToolButton, Str.toStringz(stockId)); 349 } 350 351 /** 352 * If set, an underline in the label property indicates that the next character 353 * should be used for the mnemonic accelerator key in the overflow menu. For 354 * example, if the label property is “_Open” and @use_underline is %TRUE, 355 * the label on the tool button will be “Open” and the item on the overflow 356 * menu will have an underlined “O”. 357 * 358 * Labels shown on tool buttons never have mnemonics on them; this property 359 * only affects the menu item on the overflow menu. 360 * 361 * Params: 362 * useUnderline = whether the button label has the form “_Open” 363 * 364 * Since: 2.4 365 */ 366 public void setUseUnderline(bool useUnderline) 367 { 368 gtk_tool_button_set_use_underline(gtkToolButton, useUnderline); 369 } 370 371 /** 372 * This signal is emitted when the tool button is clicked with the mouse 373 * or activated with the keyboard. 374 */ 375 gulong addOnClicked(void delegate(ToolButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 376 { 377 return Signals.connect(this, "clicked", dlg, connectFlags ^ ConnectFlags.SWAPPED); 378 } 379 }