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