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 * Conversion parameters: 26 * inFile = GtkButton.html 27 * outPack = gtk 28 * outFile = Button 29 * strct = GtkButton 30 * realStrct= 31 * ctorStrct= 32 * clss = Button 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - ActivatableIF 40 * prefixes: 41 * - gtk_button_ 42 * - gtk_ 43 * omit structs: 44 * omit prefixes: 45 * omit code: 46 * - gtk_button_new_with_mnemonic 47 * - gtk_button_new_with_label 48 * - gtk_button_new_from_stock 49 * omit signals: 50 * imports: 51 * - glib.Str 52 * - gdk.Window 53 * - gtk.Widget 54 * - gtk.Image 55 * - gtk.ActivatableT 56 * - gtk.ActivatableIF 57 * structWrap: 58 * - GdkWindow* -> Window 59 * - GtkWidget* -> Widget 60 * module aliases: 61 * local aliases: 62 * overrides: 63 */ 64 65 module gtk.Button; 66 67 public import gtkc.gtktypes; 68 69 private import gtkc.gtk; 70 private import glib.ConstructionException; 71 private import gobject.ObjectG; 72 73 private import gobject.Signals; 74 public import gtkc.gdktypes; 75 76 private import glib.Str; 77 private import gdk.Window; 78 private import gtk.Widget; 79 private import gtk.Image; 80 private import gtk.ActivatableT; 81 private import gtk.ActivatableIF; 82 83 84 85 private import gtk.Bin; 86 87 /** 88 * Description 89 * The GtkButton widget is generally used to attach a function to that 90 * is called when the button is pressed. The various signals and how to use 91 * them are outlined below. 92 * The GtkButton widget can hold any valid child widget. That is it can 93 * hold most any other standard GtkWidget. The most commonly used child is 94 * the GtkLabel. 95 */ 96 public class Button : Bin, ActivatableIF 97 { 98 99 /** the main Gtk struct */ 100 protected GtkButton* gtkButton; 101 102 103 public GtkButton* getButtonStruct() 104 { 105 return gtkButton; 106 } 107 108 109 /** the main Gtk struct as a void* */ 110 protected override void* getStruct() 111 { 112 return cast(void*)gtkButton; 113 } 114 115 /** 116 * Sets our main struct and passes it to the parent class 117 */ 118 public this (GtkButton* gtkButton) 119 { 120 super(cast(GtkBin*)gtkButton); 121 this.gtkButton = gtkButton; 122 } 123 124 protected override void setStruct(GObject* obj) 125 { 126 super.setStruct(obj); 127 gtkButton = cast(GtkButton*)obj; 128 } 129 130 private static IconSize currentIconSize = IconSize.BUTTON; 131 132 /** An arbitrary string to be used by the application */ 133 private string action; 134 135 // add the Activatable capabilities 136 mixin ActivatableT!(GtkButton); 137 138 /** */ 139 public static void setIconSize(IconSize iconSize) 140 { 141 currentIconSize = iconSize; 142 } 143 144 /** */ 145 public static IconSize getIconSize() 146 { 147 return currentIconSize; 148 } 149 150 /** */ 151 public void setActionName(string action) 152 { 153 this.action = action; 154 } 155 156 /** */ 157 public string getActionName() 158 { 159 return action; 160 } 161 162 /** 163 * Creates a new GtkButton containing a label. 164 * If characters in label are preceded by an underscore, they are underlined. 165 * If you need a literal underscore character in a label, use '__' (two 166 * underscores). The first underlined character represents a keyboard 167 * accelerator called a mnemonic. 168 * Pressing Alt and that key activates the button. 169 * Params: 170 * label = The text of the button, with an underscore in front of the 171 * mnemonic character 172 * mnemonic = true if the button has an mnemnonic 173 * Returns: 174 * a new GtkButton 175 * Throws: ConstructionException GTK+ fails to create the object. 176 */ 177 public this (string label, bool mnemonic=true) 178 { 179 GtkButton* p; 180 181 if ( mnemonic ) 182 { 183 // GtkWidget* gtk_button_new_with_mnemonic (const gchar *label); 184 p = cast(GtkButton*)gtk_button_new_with_mnemonic(Str.toStringz(label)); 185 } 186 else 187 { 188 // GtkWidget* gtk_button_new_with_label (const gchar *label); 189 p = cast(GtkButton*)gtk_button_new_with_label(Str.toStringz(label)); 190 } 191 192 if(p is null) 193 { 194 throw new ConstructionException("null returned by gtk_button_new_with_label"); 195 } 196 197 this(p); 198 } 199 200 /** 201 * Creates a new GtkButton containing the image and text from a stock item. 202 * Some stock ids have preprocessor macros like GTK_STOCK_OK and 203 * GTK_STOCK_APPLY. 204 * If stock_id is unknown, then it will be treated as a mnemonic 205 * label (as for gtk_button_new_with_mnemonic()). 206 * Params: 207 * StockID = the name of the stock item 208 * Throws: ConstructionException GTK+ fails to create the object. 209 */ 210 public this (StockID stockID, bool hideLabel=false) 211 { 212 // GtkWidget* gtk_button_new_from_stock (const gchar *stock_id); 213 if ( hideLabel ) 214 { 215 this(); 216 Image image = new Image(stockID,currentIconSize); 217 add(image); 218 } 219 else 220 { 221 auto p = gtk_button_new_from_stock(Str.toStringz(StockDesc[stockID])); 222 223 if(p is null) 224 { 225 throw new ConstructionException("null returned by gtk_button_new_from_stock"); 226 } 227 228 this(cast(GtkButton*) p); 229 } 230 231 } 232 233 /** */ 234 public this(StockID stockID, void delegate(Button) dlg, bool hideLabel=false) 235 { 236 this(stockID, hideLabel); 237 addOnClicked(dlg); 238 } 239 240 /** */ 241 public this(string label, void delegate(Button) dlg, bool mnemonic=true) 242 { 243 this(label, mnemonic); 244 addOnClicked(dlg); 245 } 246 247 /** */ 248 public this(string label, void delegate(Button) dlg, string action) 249 { 250 this(label); 251 setActionName(action); 252 addOnClicked(dlg); 253 } 254 255 256 /** 257 */ 258 int[string] connectedSignals; 259 260 void delegate(Button)[] onActivateListeners; 261 /** 262 * The ::activate signal on GtkButton is an action signal and 263 * emitting it causes the button to animate press then release. 264 * Applications should never connect to this signal, but use the 265 * "clicked" signal. 266 */ 267 void addOnActivate(void delegate(Button) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 268 { 269 if ( !("activate" in connectedSignals) ) 270 { 271 Signals.connectData( 272 getStruct(), 273 "activate", 274 cast(GCallback)&callBackActivate, 275 cast(void*)this, 276 null, 277 connectFlags); 278 connectedSignals["activate"] = 1; 279 } 280 onActivateListeners ~= dlg; 281 } 282 extern(C) static void callBackActivate(GtkButton* widgetStruct, Button _button) 283 { 284 foreach ( void delegate(Button) dlg ; _button.onActivateListeners ) 285 { 286 dlg(_button); 287 } 288 } 289 290 void delegate(Button)[] onClickedListeners; 291 /** 292 * Emitted when the button has been activated (pressed and released). 293 */ 294 void addOnClicked(void delegate(Button) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 295 { 296 if ( !("clicked" in connectedSignals) ) 297 { 298 Signals.connectData( 299 getStruct(), 300 "clicked", 301 cast(GCallback)&callBackClicked, 302 cast(void*)this, 303 null, 304 connectFlags); 305 connectedSignals["clicked"] = 1; 306 } 307 onClickedListeners ~= dlg; 308 } 309 extern(C) static void callBackClicked(GtkButton* buttonStruct, Button _button) 310 { 311 foreach ( void delegate(Button) dlg ; _button.onClickedListeners ) 312 { 313 dlg(_button); 314 } 315 } 316 317 void delegate(Button)[] onEnterListeners; 318 /** 319 * Warning 320 * GtkButton::enter has been deprecated since version 2.8 and should not be used in newly-written code. Use the "enter-notify-event" signal. 321 * Emitted when the pointer enters the button. 322 */ 323 void addOnEnter(void delegate(Button) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 324 { 325 if ( !("enter" in connectedSignals) ) 326 { 327 Signals.connectData( 328 getStruct(), 329 "enter", 330 cast(GCallback)&callBackEnter, 331 cast(void*)this, 332 null, 333 connectFlags); 334 connectedSignals["enter"] = 1; 335 } 336 onEnterListeners ~= dlg; 337 } 338 extern(C) static void callBackEnter(GtkButton* buttonStruct, Button _button) 339 { 340 foreach ( void delegate(Button) dlg ; _button.onEnterListeners ) 341 { 342 dlg(_button); 343 } 344 } 345 346 void delegate(Button)[] onLeaveListeners; 347 /** 348 * Warning 349 * GtkButton::leave has been deprecated since version 2.8 and should not be used in newly-written code. Use the "leave-notify-event" signal. 350 * Emitted when the pointer leaves the button. 351 */ 352 void addOnLeave(void delegate(Button) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 353 { 354 if ( !("leave" in connectedSignals) ) 355 { 356 Signals.connectData( 357 getStruct(), 358 "leave", 359 cast(GCallback)&callBackLeave, 360 cast(void*)this, 361 null, 362 connectFlags); 363 connectedSignals["leave"] = 1; 364 } 365 onLeaveListeners ~= dlg; 366 } 367 extern(C) static void callBackLeave(GtkButton* buttonStruct, Button _button) 368 { 369 foreach ( void delegate(Button) dlg ; _button.onLeaveListeners ) 370 { 371 dlg(_button); 372 } 373 } 374 375 void delegate(Button)[] onPressedListeners; 376 /** 377 * Warning 378 * GtkButton::pressed has been deprecated since version 2.8 and should not be used in newly-written code. Use the "button-press-event" signal. 379 * Emitted when the button is pressed. 380 */ 381 void addOnPressed(void delegate(Button) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 382 { 383 if ( !("pressed" in connectedSignals) ) 384 { 385 Signals.connectData( 386 getStruct(), 387 "pressed", 388 cast(GCallback)&callBackPressed, 389 cast(void*)this, 390 null, 391 connectFlags); 392 connectedSignals["pressed"] = 1; 393 } 394 onPressedListeners ~= dlg; 395 } 396 extern(C) static void callBackPressed(GtkButton* buttonStruct, Button _button) 397 { 398 foreach ( void delegate(Button) dlg ; _button.onPressedListeners ) 399 { 400 dlg(_button); 401 } 402 } 403 404 void delegate(Button)[] onReleasedListeners; 405 /** 406 * Warning 407 * GtkButton::released has been deprecated since version 2.8 and should not be used in newly-written code. Use the "button-release-event" signal. 408 * Emitted when the button is released. 409 */ 410 void addOnReleased(void delegate(Button) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 411 { 412 if ( !("released" in connectedSignals) ) 413 { 414 Signals.connectData( 415 getStruct(), 416 "released", 417 cast(GCallback)&callBackReleased, 418 cast(void*)this, 419 null, 420 connectFlags); 421 connectedSignals["released"] = 1; 422 } 423 onReleasedListeners ~= dlg; 424 } 425 extern(C) static void callBackReleased(GtkButton* buttonStruct, Button _button) 426 { 427 foreach ( void delegate(Button) dlg ; _button.onReleasedListeners ) 428 { 429 dlg(_button); 430 } 431 } 432 433 434 /** 435 * Creates a new GtkButton widget. To add a child widget to the button, 436 * use gtk_container_add(). 437 * Throws: ConstructionException GTK+ fails to create the object. 438 */ 439 public this () 440 { 441 // GtkWidget * gtk_button_new (void); 442 auto p = gtk_button_new(); 443 if(p is null) 444 { 445 throw new ConstructionException("null returned by gtk_button_new()"); 446 } 447 this(cast(GtkButton*) p); 448 } 449 450 /** 451 * Warning 452 * gtk_button_pressed has been deprecated since version 2.20 and should not be used in newly-written code. Use the "button-press-event" signal. 453 * Emits a "pressed" signal to the given GtkButton. 454 */ 455 public void pressed() 456 { 457 // void gtk_button_pressed (GtkButton *button); 458 gtk_button_pressed(gtkButton); 459 } 460 461 /** 462 * Warning 463 * gtk_button_released has been deprecated since version 2.20 and should not be used in newly-written code. Use the "button-release-event" signal. 464 * Emits a "released" signal to the given GtkButton. 465 */ 466 public void released() 467 { 468 // void gtk_button_released (GtkButton *button); 469 gtk_button_released(gtkButton); 470 } 471 472 /** 473 * Emits a "clicked" signal to the given GtkButton. 474 */ 475 public void clicked() 476 { 477 // void gtk_button_clicked (GtkButton *button); 478 gtk_button_clicked(gtkButton); 479 } 480 481 /** 482 * Warning 483 * gtk_button_enter has been deprecated since version 2.20 and should not be used in newly-written code. Use the "enter-notify-event" signal. 484 * Emits a "enter" signal to the given GtkButton. 485 */ 486 public void enter() 487 { 488 // void gtk_button_enter (GtkButton *button); 489 gtk_button_enter(gtkButton); 490 } 491 492 /** 493 * Warning 494 * gtk_button_leave has been deprecated since version 2.20 and should not be used in newly-written code. Use the "leave-notify-event" signal. 495 * Emits a "leave" signal to the given GtkButton. 496 */ 497 public void leave() 498 { 499 // void gtk_button_leave (GtkButton *button); 500 gtk_button_leave(gtkButton); 501 } 502 503 /** 504 * Sets the relief style of the edges of the given GtkButton widget. 505 * Three styles exist, GTK_RELIEF_NORMAL, GTK_RELIEF_HALF, GTK_RELIEF_NONE. 506 * The default style is, as one can guess, GTK_RELIEF_NORMAL. 507 * Params: 508 * newstyle = The GtkReliefStyle as described above. 509 */ 510 public void setRelief(GtkReliefStyle newstyle) 511 { 512 // void gtk_button_set_relief (GtkButton *button, GtkReliefStyle newstyle); 513 gtk_button_set_relief(gtkButton, newstyle); 514 } 515 516 /** 517 * Returns the current relief style of the given GtkButton. 518 * Returns: The current GtkReliefStyle 519 */ 520 public GtkReliefStyle getRelief() 521 { 522 // GtkReliefStyle gtk_button_get_relief (GtkButton *button); 523 return gtk_button_get_relief(gtkButton); 524 } 525 526 /** 527 * Fetches the text from the label of the button, as set by 528 * gtk_button_set_label(). If the label text has not 529 * been set the return value will be NULL. This will be the 530 * case if you create an empty button with gtk_button_new() to 531 * use as a container. 532 * Returns: The text of the label widget. This string is owned by the widget and must not be modified or freed. 533 */ 534 public string getLabel() 535 { 536 // const gchar * gtk_button_get_label (GtkButton *button); 537 return Str.toString(gtk_button_get_label(gtkButton)); 538 } 539 540 /** 541 * Sets the text of the label of the button to str. This text is 542 * also used to select the stock item if gtk_button_set_use_stock() 543 * is used. 544 * This will also clear any previously set labels. 545 * Params: 546 * label = a string 547 */ 548 public void setLabel(string label) 549 { 550 // void gtk_button_set_label (GtkButton *button, const gchar *label); 551 gtk_button_set_label(gtkButton, Str.toStringz(label)); 552 } 553 554 /** 555 * Returns whether the button label is a stock item. 556 * Returns: TRUE if the button label is used to select a stock item instead of being used directly as the label text. 557 */ 558 public int getUseStock() 559 { 560 // gboolean gtk_button_get_use_stock (GtkButton *button); 561 return gtk_button_get_use_stock(gtkButton); 562 } 563 564 /** 565 * If TRUE, the label set on the button is used as a 566 * stock id to select the stock item for the button. 567 * Params: 568 * useStock = TRUE if the button should use a stock item 569 */ 570 public void setUseStock(int useStock) 571 { 572 // void gtk_button_set_use_stock (GtkButton *button, gboolean use_stock); 573 gtk_button_set_use_stock(gtkButton, useStock); 574 } 575 576 /** 577 * Returns whether an embedded underline in the button label indicates a 578 * mnemonic. See gtk_button_set_use_underline(). 579 * Returns: TRUE if an embedded underline in the button label indicates the mnemonic accelerator keys. 580 */ 581 public int getUseUnderline() 582 { 583 // gboolean gtk_button_get_use_underline (GtkButton *button); 584 return gtk_button_get_use_underline(gtkButton); 585 } 586 587 /** 588 * If true, an underline in the text of the button label indicates 589 * the next character should be used for the mnemonic accelerator key. 590 * Params: 591 * useUnderline = TRUE if underlines in the text indicate mnemonics 592 */ 593 public void setUseUnderline(int useUnderline) 594 { 595 // void gtk_button_set_use_underline (GtkButton *button, gboolean use_underline); 596 gtk_button_set_use_underline(gtkButton, useUnderline); 597 } 598 599 /** 600 * Sets whether the button will grab focus when it is clicked with the mouse. 601 * Making mouse clicks not grab focus is useful in places like toolbars where 602 * you don't want the keyboard focus removed from the main area of the 603 * application. 604 * Since 2.4 605 * Params: 606 * focusOnClick = whether the button grabs focus when clicked with the mouse 607 */ 608 public void setFocusOnClick(int focusOnClick) 609 { 610 // void gtk_button_set_focus_on_click (GtkButton *button, gboolean focus_on_click); 611 gtk_button_set_focus_on_click(gtkButton, focusOnClick); 612 } 613 614 /** 615 * Returns whether the button grabs focus when it is clicked with the mouse. 616 * See gtk_button_set_focus_on_click(). 617 * Since 2.4 618 * Returns: TRUE if the button grabs focus when it is clicked with the mouse. 619 */ 620 public int getFocusOnClick() 621 { 622 // gboolean gtk_button_get_focus_on_click (GtkButton *button); 623 return gtk_button_get_focus_on_click(gtkButton); 624 } 625 626 /** 627 * Sets the alignment of the child. This property has no effect unless 628 * the child is a GtkMisc or a GtkAligment. 629 * Since 2.4 630 * Params: 631 * xalign = the horizontal position of the child, 0.0 is left aligned, 632 * 1.0 is right aligned 633 * yalign = the vertical position of the child, 0.0 is top aligned, 634 * 1.0 is bottom aligned 635 */ 636 public void setAlignment(float xalign, float yalign) 637 { 638 // void gtk_button_set_alignment (GtkButton *button, gfloat xalign, gfloat yalign); 639 gtk_button_set_alignment(gtkButton, xalign, yalign); 640 } 641 642 /** 643 * Gets the alignment of the child in the button. 644 * Since 2.4 645 * Params: 646 * xalign = return location for horizontal alignment. [out] 647 * yalign = return location for vertical alignment. [out] 648 */ 649 public void getAlignment(out float xalign, out float yalign) 650 { 651 // void gtk_button_get_alignment (GtkButton *button, gfloat *xalign, gfloat *yalign); 652 gtk_button_get_alignment(gtkButton, &xalign, &yalign); 653 } 654 655 /** 656 * Set the image of button to the given widget. Note that 657 * it depends on the "gtk-button-images" setting whether the 658 * image will be displayed or not, you don't have to call 659 * gtk_widget_show() on image yourself. 660 * Since 2.6 661 * Params: 662 * image = a widget to set as the image for the button 663 */ 664 public void setImage(Widget image) 665 { 666 // void gtk_button_set_image (GtkButton *button, GtkWidget *image); 667 gtk_button_set_image(gtkButton, (image is null) ? null : image.getWidgetStruct()); 668 } 669 670 /** 671 * Gets the widget that is currenty set as the image of button. 672 * This may have been explicitly set by gtk_button_set_image() 673 * or constructed by gtk_button_new_from_stock(). 674 * Since 2.6 675 * Returns: a GtkWidget or NULL in case there is no image. [transfer none] 676 */ 677 public Widget getImage() 678 { 679 // GtkWidget * gtk_button_get_image (GtkButton *button); 680 auto p = gtk_button_get_image(gtkButton); 681 682 if(p is null) 683 { 684 return null; 685 } 686 687 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 688 } 689 690 /** 691 * Sets the position of the image relative to the text 692 * inside the button. 693 * Since 2.10 694 * Params: 695 * position = the position 696 */ 697 public void setImagePosition(GtkPositionType position) 698 { 699 // void gtk_button_set_image_position (GtkButton *button, GtkPositionType position); 700 gtk_button_set_image_position(gtkButton, position); 701 } 702 703 /** 704 * Gets the position of the image relative to the text 705 * inside the button. 706 * Since 2.10 707 * Returns: the position 708 */ 709 public GtkPositionType getImagePosition() 710 { 711 // GtkPositionType gtk_button_get_image_position (GtkButton *button); 712 return gtk_button_get_image_position(gtkButton); 713 } 714 715 /** 716 * Returns the button's event window if it is realized, NULL otherwise. 717 * This function should be rarely needed. 718 * Since 2.22 719 * Returns: button's event window. [transfer none] 720 */ 721 public Window getEventWindow() 722 { 723 // GdkWindow * gtk_button_get_event_window (GtkButton *button); 724 auto p = gtk_button_get_event_window(gtkButton); 725 726 if(p is null) 727 { 728 return null; 729 } 730 731 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 732 } 733 }