Toc Gallery Index Tree Gtk.Button

Screenshot

No screeshot

Hierarchy

Description

This package implements a general button widget. This button can be clicked on by the user to start any action. This button does not have multiple states, it can just be temporarily pressed while the mouse is on it, but does not keep its pressed state.

The gtk+ sources provide the following drawing that explains the role of the various spacings that can be set for a button:

Types

  • type Gtk_Button is access all Gtk_Button_Record'Class;
  • type Gtk_Button_Record is new Bin.Gtk_Bin_Record with private;

Subprograms

  • procedure Gtk_New (Button : out Gtk_Button; Label : UTF8_String := "");
    Create a new button. if Label is not the empty string, then the text appears in the button (and the child of the button is a Gtk_Label). On the other hand, if Label is the empty string, then no child is created for the button and it is your responsibility to add one. This is the recommended way to put a pixmap inside the button.
  • procedure Gtk_New_From_Stock (Button : out Gtk_Button; Stock_Id : String);
    Create a new button containing the image and text from a stock item. Some stock ids have predefined contants like Gtk.Stock.Stock_OK or Gtk.Stock.Stock_Apply. See Gtk.Stock for a complete list of predefined stock items. Stock_Id: the name of the stock item.
  • procedure Gtk_New_With_Mnemonic (Button : out Gtk_Button; Label : UTF8_String);
    Create a new button containing a label. Label: The text of the button, with an underscore in front of the mnemonic character If characters in Label are preceded by an underscore, they are underlined indicating that they represent a keyboard accelerator called a mnemonic. Pressing Alt and that key activates the button.
  • procedure Initialize (Button : access Gtk_Button_Record'Class; Label : UTF8_String);
    Internal initialization function. See the section "Creating your own widgets" in the documentation.
  • procedure Initialize_From_Stock (Button : access Gtk_Button_Record'Class; Stock_Id : String);
    Internal initialization function.
  • procedure Initialize_With_Mnemonic (Button : access Gtk_Button_Record'Class; Label : UTF8_String);
    Internal initialization function.
  • function Get_Type return Gtk.Gtk_Type;
    Return the internal value associated with a Gtk_Button.
  • procedure Set_Relief (Button : access Gtk_Button_Record; New_Style : Gtk.Enums.Gtk_Relief_Style);
    function Get_Relief (Button : access Gtk_Button_Record) return Gtk.Enums.Gtk_Relief_Style;
    Modify the relief style for the button. This modifies only its visual aspect, not its behavior.
  • procedure Set_Label (Button : access Gtk_Button_Record; Label : UTF8_String);
    function Get_Label (Button : access Gtk_Button_Record) return UTF8_String;
    Set or gets the label of the button. This text is also used to select an icon if Set_Use_Stock was called with a parameter set to True.
  • procedure Set_Use_Underline (Button : access Gtk_Button_Record; Use_Underline : Boolean);
    function Get_Use_Underline (Button : access Gtk_Button_Record) return Boolean;
    Sets whether an underscore used in the button's label designates an accelerator. If True, then if the user presses alt and the character following the underscore, then the button will act as if it had been pressed.
  • procedure Set_Use_Stock (Button : access Gtk_Button_Record; Use_Stock : Boolean);
    function Get_Use_Stock (Button : access Gtk_Button_Record) return Boolean;
    Sets or Gets whether a stock item is used by the button.
  • procedure Set_Alignment (Button : access Gtk_Button_Record; Xalign : Gfloat := 0.5; Yalign : Gfloat := 0.5);
    procedure Get_Alignment (Button : access Gtk_Button_Record; Xalign : out Gfloat; Yalign : out Gfloat);
    Specify the alignment of the label inside the button. Passing (0.0, 0.0) indicates the label should be at the top-left corner of the button. (0.5, 0.5) indicates that the label should be centered. This property has no effect unless the button's child is a child of Gtk_Alignment or Gtk_Misc
  • procedure Set_Focus_On_Click (Button : access Gtk_Button_Record; Focus_On_Click : Boolean := True);
    function Get_Focus_On_Click (Button : access Gtk_Button_Record) return Boolean;
    Sets whether the button will grab focus when it is clicked with the mouse. Setting Focus_On_Click to False is useful in contexts like toolbars where the focus should not be removed from the main area of the application.
  • procedure Set_Image (Button : access Gtk_Button_Record; Image : access Gtk.Widget.Gtk_Widget_Record'Class);
    function Get_Image (Button : access Gtk_Button_Record) return Gtk.Widget.Gtk_Widget;
    Set the image of the button. You do not need to call Show on the image yourself. This settings might have no effect, depending on the theme configuration that the application's user is using (in particular, the setting "gtk-button-images" indicates whether or not images should be displayed in buttons).
  • Signals emission

  • procedure Pressed (Button : access Gtk_Button_Record);
    Send the "pressed" signal to the button
  • procedure Released (Button : access Gtk_Button_Record);
    Send the "release" signal to the button
  • procedure Clicked (Button : access Gtk_Button_Record);
    Send the "clicked" signal to the button
  • procedure Enter (Button : access Gtk_Button_Record);
    Send the "enter" signal to the button
  • procedure Leave (Button : access Gtk_Button_Record);
    Send the "leave" signal to the button

Signals

  • activate
    procedure Handler (Button : access Gtk_Button_Record'Class);
    You should emit this signal to force the activation of this widget, as if the user has clicked on it. This is generally only useful when bound to a key binding.
  • clicked
    procedure Handler (Button : access Gtk_Button_Record'Class);
    Emitted when the button has been clicked on by the user. This is the signal you should use to start your own actions.
  • enter
    procedure Handler (Button : access Gtk_Button_Record'Class);
    Emitted when the mouse enters the button. The clicked signal can only be emitted when the mouse is inside the button.
  • leave
    procedure Handler (Button : access Gtk_Button_Record'Class);
    Emitted when the mouse leaves the button.
  • pressed
    procedure Handler (Button : access Gtk_Button_Record'Class);
    Emitted when the user presses the mouse button on the widget. The default implementation modifies the widget state and its visual aspect.
  • released
    procedure Handler (Button : access Gtk_Button_Record'Class);
    Emitted when the user releases the mouse button and is inside of the widget. The default implementation modifies the widget state and its visual aspect. If the mouse is still inside the widget, then the "clicked" signal is emitted.

Properties

  • Focus_On_Click_Property
    Boolean

    See: Same as calling Set_Focus_On_Click directly
  • Image_Property
    Object
    Child widget to appear next to the button text
  • Label_Property
    UTF8_String
    Changes the text contained in the button.
    See: Same as calling Set_Label directly.
  • Relief_Property
    Gtk_Relief_Style
    Changes the relief used to draw the border of the button.
    See: Same as calling Set_Relief directly.
  • Use_Stock_Property
    Boolean

    See: Same as calling Set_Use_Stock directly
  • Use_Underline_Property
    Boolean

    See: Same as calling Set_Use_Underline directly
  • Xalign_Property
    Float
    Horizontal position of child in available space. 0.0 is left
  • Yalign_Property
    Float
    Vertical position of child in available space. 0.0 is top

Style Properties

  • Child_Displacement_X_Property
    Int
    How far in the x direction to move the child when the button is
  • Child_Displacement_Y_Property
    Int
    How far in the y direction to move the child when the button is
  • Default_Border_Property
    Boxed
    Extra space to add for CAN_DEFAULT buttons
  • Default_Outside_Border_Property
    Boxed
    Extra space to add for CAN_DEFAULT buttons that is always drawn
  • Displace_Focus_Property
    Boolean
    Whether the child_displacement_x/_y properties should also affect

Example

+------------------------------------------------+ | BORDER | | +------------------------------------------+ | | |\\\\\\\\\\\\\\\\DEFAULT\\\\\\\\\\\\\\\\\ | | | |\\+------------------------------------+ | | | |\\| | SPACING 3 | | | | | |\\| +--------------------------------+ | | | | |\\| |########## FOCUS ###############| | | | | |\\| |#+----------------------------+#| | | | | |\\| |#| RELIEF \|#| | | | | |\\| |#| +-----------------------+\|#| | | | | |\\|1|#| + THE TEXT +\|#|2| | | | |\\| |#| +-----------------------+\|#| | | | | |\\| |#| \\\\\ ythickness \\\\\\\\\\|#| | | | | |\\| |#+----------------------------+#| | | | | |\\| |########### 1 ##################| | | | | |\\| +--------------------------------+ | | | | |\\| | default spacing 4 | | | | | |\\+------------------------------------+ | | | |\ ythickness | | | +------------------------------------------+ | | border_width | +------------------------------------------------+

Testgtk source code

This code is part of testgtk, a demo application packaged with GtkAda. Testgtk demonstrates the various widgets of GtkAda
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for the Gimp Toolkit -- -- -- -- Copyright (C) 1998-1999 -- -- Emmanuel Briot, Joel Brobecker and Arnaud Charlet -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public -- -- License along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- -- -- -- -- -- -- -- ----------------------------------------------------------------------- with Glib; use Glib; with Gtk; use Gtk; with Gtk.Box; use Gtk.Box; with Gtk.Button; use Gtk.Button; with Gtk.Enums; use Gtk.Enums; with Gtk.Frame; use Gtk.Frame; with Gtk.Handlers; use Gtk.Handlers; with Gtk.Table; use Gtk.Table; with Gtk.Widget; use Gtk.Widget; package body Create_Buttons is package Button_Cb is new Handlers.Callback (Gtk_Button_Record); procedure Button_Window (Widget : access Gtk_Button_Record'Class); -- Toggles the visibility of Widget ---------- -- Help -- ---------- function Help return String is begin return "a @bGtk_Button@B is the basic widget to which you can associate" & " a callback. Whenever the user presses the mouse on the button," & " one or more functions specified by the user can be called."; end Help; ------------------- -- Button_Window -- ------------------- procedure Button_Window (Widget : access Gtk_Button_Record'Class) is begin if Visible_Is_Set (Widget) then Hide (Widget); else Show (Widget); end if; end Button_Window; --------- -- Run -- --------- procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is Box1 : Gtk_Box; Table : Gtk_Table; Button : array (0 .. 8) of Gtk_Button; Left_A : constant array (0 .. 8) of Guint := (0, 1, 2, 0, 2, 1, 1, 2, 0); Right_A : constant array (0 .. 8) of Guint := (1, 2, 3, 1, 3, 2, 2, 3, 1); Top_A : constant array (0 .. 8) of Guint := (0, 1, 2, 2, 0, 2, 0, 1, 1); Bott_A : constant array (0 .. 8) of Guint := (1, 2, 3, 3, 1, 3, 1, 2, 2); begin Gtk.Frame.Set_Label (Frame, "Buttons"); Gtk_New_Vbox (Box1, Homogeneous => False, Spacing => 0); Add (Frame, Box1); Gtk_New (Table, Rows => 3, Columns => 3, Homogeneous => False); Set_Row_Spacings (Table, Spacing => 5); Set_Col_Spacings (Table, Spacing => 5); Set_Border_Width (Table, Border_Width => 10); Pack_Start (Box1, Table, Expand => False, Fill => False, Padding => 0); for J in Button'Range loop Gtk_New (Button (J), Label => "Button" & Integer'Image (J)); end loop; for J in Button'Range loop Button_Cb.Object_Connect (Button (J), "clicked", Button_Cb.To_Marshaller (Button_Window'Access), Button ((J + 1) mod Button'Length)); Attach (Table, Button (J), Left_A (J), Right_A (J), Top_A (J), Bott_A (J), Expand + Fill, Expand + Fill, Xpadding => 0, Ypadding => 0); end loop; Show_All (Box1); end Run; end Create_Buttons;

Alphabetical Index