1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   -- 
  5. --                Copyright (C) 2000-2011, AdaCore                   -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- -- -- -- -- -- -- -- -- -- -- --
  23. ----------------------------------------------------------------------- 
  24.  
  25. --  <description> 
  26. --  This package implements a general button widget. This button can be 
  27. --  clicked on by the user to start any action. This button does not have 
  28. --  multiple states, it can just be temporarily pressed while the mouse is on 
  29. --  it, but does not keep its pressed state. 
  30. -- 
  31. --  The gtk+ sources provide the following drawing that explains the role of 
  32. --  the various spacings that can be set for a button: 
  33. -- 
  34. --  </description> 
  35. --  <screenshot>gtk-button</screenshot> 
  36. --  <group>Buttons and Toggles</group> 
  37. --  <testgtk>create_buttons.adb</testgtk> 
  38.  
  39. pragma Warnings (Off, "*is already use-visible*"); 
  40. with Gdk.Window;      use Gdk.Window; 
  41. with Glib;            use Glib; 
  42. with Glib.Properties; use Glib.Properties; 
  43. with Glib.Types;      use Glib.Types; 
  44. with Gtk.Action;      use Gtk.Action; 
  45. with Gtk.Activatable; use Gtk.Activatable; 
  46. with Gtk.Bin;         use Gtk.Bin; 
  47. with Gtk.Buildable;   use Gtk.Buildable; 
  48. with Gtk.Enums;       use Gtk.Enums; 
  49. with Gtk.Widget;      use Gtk.Widget; 
  50.  
  51. package Gtk.Button is 
  52.  
  53.    type Gtk_Button_Record is new Gtk_Bin_Record with null record; 
  54.    type Gtk_Button is access all Gtk_Button_Record'Class; 
  55.  
  56.    ------------------ 
  57.    -- Constructors -- 
  58.    ------------------ 
  59.  
  60.    procedure Gtk_New_From_Stock 
  61.       (Button   : out Gtk_Button; 
  62.        Stock_Id : UTF8_String); 
  63.    procedure Initialize_From_Stock 
  64.       (Button   : access Gtk_Button_Record'Class; 
  65.        Stock_Id : UTF8_String); 
  66.    --  Creates a new Gtk.Button.Gtk_Button containing the image and text from 
  67.    --  a stock item. Some stock ids have preprocessor macros like GTK_STOCK_OK 
  68.    --  and GTK_STOCK_APPLY. If Stock_Id is unknown, then it will be treated as 
  69.    --  a mnemonic label (as for Gtk.Button.Gtk_New_With_Mnemonic). 
  70.    --  "stock_id": the name of the stock item 
  71.  
  72.    procedure Gtk_New (Button : out Gtk_Button; Label : UTF8_String := ""); 
  73.    procedure Initialize 
  74.       (Button : access Gtk_Button_Record'Class; 
  75.        Label  : UTF8_String := ""); 
  76.  
  77.    procedure Gtk_New_With_Mnemonic 
  78.       (Button : out Gtk_Button; 
  79.        Label  : UTF8_String); 
  80.    procedure Initialize_With_Mnemonic 
  81.       (Button : access Gtk_Button_Record'Class; 
  82.        Label  : UTF8_String); 
  83.    --  Creates a new Gtk.Button.Gtk_Button containing a label. If characters 
  84.    --  in Label are preceded by an underscore, they are underlined. If you need 
  85.    --  a literal underscore character in a label, use '__' (two underscores). 
  86.    --  The first underlined character represents a keyboard accelerator called 
  87.    --  a mnemonic. Pressing Alt and that key activates the button. 
  88.    --  "label": The text of the button, with an underscore in front of the 
  89.    --  mnemonic character 
  90.  
  91.    function Get_Type return Glib.GType; 
  92.    pragma Import (C, Get_Type, "gtk_button_get_type"); 
  93.  
  94.    ------------- 
  95.    -- Methods -- 
  96.    ------------- 
  97.  
  98.    procedure Clicked (Button : access Gtk_Button_Record); 
  99.  
  100.    procedure Enter (Button : access Gtk_Button_Record); 
  101.  
  102.    procedure Get_Alignment 
  103.       (Button : access Gtk_Button_Record; 
  104.        Xalign : out Gfloat; 
  105.        Yalign : out Gfloat); 
  106.    procedure Set_Alignment 
  107.       (Button : access Gtk_Button_Record; 
  108.        Xalign : Gfloat; 
  109.        Yalign : Gfloat); 
  110.    --  Sets the alignment of the child. This property has no effect unless the 
  111.    --  child is a Gtk.Misc.Gtk_Misc or a GtkAligment. 
  112.    --  Since: gtk+ 2.4 
  113.    --  "xalign": the horizontal position of the child, 0.0 is left aligned, 
  114.    --  1.0 is right aligned 
  115.    --  "yalign": the vertical position of the child, 0.0 is top aligned, 1.0 
  116.    --  is bottom aligned 
  117.  
  118.    function Get_Event_Window 
  119.       (Button : access Gtk_Button_Record) return Gdk.Window.Gdk_Window; 
  120.    --  Returns the button's event window if it is realized, null otherwise. 
  121.    --  This function should be rarely needed. 
  122.    --  Since: gtk+ 2.22 
  123.    --  Returns Button's event window. 
  124.  
  125.    function Get_Focus_On_Click 
  126.       (Button : access Gtk_Button_Record) return Boolean; 
  127.    procedure Set_Focus_On_Click 
  128.       (Button         : access Gtk_Button_Record; 
  129.        Focus_On_Click : Boolean); 
  130.    --  Sets whether the button will grab focus when it is clicked with the 
  131.    --  mouse. Making mouse clicks not grab focus is useful in places like 
  132.    --  toolbars where you don't want the keyboard focus removed from the main 
  133.    --  area of the application. 
  134.    --  Since: gtk+ 2.4 
  135.    --  "focus_on_click": whether the button grabs focus when clicked with the 
  136.    --  mouse 
  137.  
  138.    function Get_Image 
  139.       (Button : access Gtk_Button_Record) return Gtk.Widget.Gtk_Widget; 
  140.    procedure Set_Image 
  141.       (Button : access Gtk_Button_Record; 
  142.        Image  : access Gtk.Widget.Gtk_Widget_Record'Class); 
  143.    --  Set the image of Button to the given widget. Note that it depends on 
  144.    --  the Gtk.Settings.Gtk_Settings:gtk-button-images setting whether the 
  145.    --  image will be displayed or not, you don't have to call Gtk.Widget.Show 
  146.    --  on Image yourself. 
  147.    --  Since: gtk+ 2.6 
  148.    --  "image": a widget to set as the image for the button 
  149.  
  150.    function Get_Image_Position 
  151.       (Button : access Gtk_Button_Record) return Gtk.Enums.Gtk_Position_Type; 
  152.    procedure Set_Image_Position 
  153.       (Button   : access Gtk_Button_Record; 
  154.        Position : Gtk.Enums.Gtk_Position_Type); 
  155.    --  Sets the position of the image relative to the text inside the button. 
  156.    --  Since: gtk+ 2.10 
  157.    --  "position": the position 
  158.  
  159.    function Get_Label (Button : access Gtk_Button_Record) return UTF8_String; 
  160.    procedure Set_Label 
  161.       (Button : access Gtk_Button_Record; 
  162.        Label  : UTF8_String); 
  163.    --  Sets the text of the label of the button to Str. This text is also used 
  164.    --  to select the stock item if Gtk.Button.Set_Use_Stock is used. This will 
  165.    --  also clear any previously set labels. 
  166.    --  "label": a string 
  167.  
  168.    function Get_Relief 
  169.       (Button : access Gtk_Button_Record) return Gtk.Enums.Gtk_Relief_Style; 
  170.    procedure Set_Relief 
  171.       (Button   : access Gtk_Button_Record; 
  172.        Newstyle : Gtk.Enums.Gtk_Relief_Style); 
  173.  
  174.    function Get_Use_Stock (Button : access Gtk_Button_Record) return Boolean; 
  175.    procedure Set_Use_Stock 
  176.       (Button    : access Gtk_Button_Record; 
  177.        Use_Stock : Boolean); 
  178.    --  If True, the label set on the button is used as a stock id to select 
  179.    --  the stock item for the button. 
  180.    --  "use_stock": True if the button should use a stock item 
  181.  
  182.    function Get_Use_Underline 
  183.       (Button : access Gtk_Button_Record) return Boolean; 
  184.    procedure Set_Use_Underline 
  185.       (Button        : access Gtk_Button_Record; 
  186.        Use_Underline : Boolean); 
  187.    --  If true, an underline in the text of the button label indicates the 
  188.    --  next character should be used for the mnemonic accelerator key. 
  189.    --  "use_underline": True if underlines in the text indicate mnemonics 
  190.  
  191.    procedure Leave (Button : access Gtk_Button_Record); 
  192.  
  193.    procedure Pressed (Button : access Gtk_Button_Record); 
  194.  
  195.    procedure Released (Button : access Gtk_Button_Record); 
  196.  
  197.    --------------------- 
  198.    -- Interfaces_Impl -- 
  199.    --------------------- 
  200.  
  201.    procedure Do_Set_Related_Action 
  202.       (Self   : access Gtk_Button_Record; 
  203.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  204.  
  205.    function Get_Related_Action 
  206.       (Self : access Gtk_Button_Record) return Gtk.Action.Gtk_Action; 
  207.    procedure Set_Related_Action 
  208.       (Self   : access Gtk_Button_Record; 
  209.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  210.  
  211.    function Get_Use_Action_Appearance 
  212.       (Self : access Gtk_Button_Record) return Boolean; 
  213.    procedure Set_Use_Action_Appearance 
  214.       (Self           : access Gtk_Button_Record; 
  215.        Use_Appearance : Boolean); 
  216.  
  217.    procedure Sync_Action_Properties 
  218.       (Self   : access Gtk_Button_Record; 
  219.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  220.  
  221.    ---------------- 
  222.    -- Interfaces -- 
  223.    ---------------- 
  224.    --  This class implements several interfaces. See Glib.Types 
  225.    -- 
  226.    --  - "Activatable" 
  227.    -- 
  228.    --  - "Buildable" 
  229.  
  230.    package Implements_Activatable is new Glib.Types.Implements 
  231.      (Gtk.Activatable.Gtk_Activatable, Gtk_Button_Record, Gtk_Button); 
  232.    function "+" 
  233.      (Widget : access Gtk_Button_Record'Class) 
  234.    return Gtk.Activatable.Gtk_Activatable 
  235.    renames Implements_Activatable.To_Interface; 
  236.    function "-" 
  237.      (Interf : Gtk.Activatable.Gtk_Activatable) 
  238.    return Gtk_Button 
  239.    renames Implements_Activatable.To_Object; 
  240.  
  241.    package Implements_Buildable is new Glib.Types.Implements 
  242.      (Gtk.Buildable.Gtk_Buildable, Gtk_Button_Record, Gtk_Button); 
  243.    function "+" 
  244.      (Widget : access Gtk_Button_Record'Class) 
  245.    return Gtk.Buildable.Gtk_Buildable 
  246.    renames Implements_Buildable.To_Interface; 
  247.    function "-" 
  248.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  249.    return Gtk_Button 
  250.    renames Implements_Buildable.To_Object; 
  251.  
  252.    ---------------- 
  253.    -- Properties -- 
  254.    ---------------- 
  255.    --  The following properties are defined for this widget. See 
  256.    --  Glib.Properties for more information on properties) 
  257.    -- 
  258.    --  Name: Focus_On_Click_Property 
  259.    --  Type: Boolean 
  260.    --  Flags: read-write 
  261.    -- 
  262.    --  Name: Image_Property 
  263.    --  Type: Gtk.Widget.Gtk_Widget 
  264.    --  Flags: read-write 
  265.    -- 
  266.    --  Name: Image_Position_Property 
  267.    --  Type: Gtk.Enums.Gtk_Position_Type 
  268.    --  Flags: read-write 
  269.    --  The position of the image relative to the text inside the button. 
  270.    -- 
  271.    --  Name: Label_Property 
  272.    --  Type: UTF8_String 
  273.    --  Flags: read-write 
  274.    -- 
  275.    --  Name: Relief_Property 
  276.    --  Type: Gtk.Enums.Gtk_Relief_Style 
  277.    --  Flags: read-write 
  278.    -- 
  279.    --  Name: Use_Stock_Property 
  280.    --  Type: Boolean 
  281.    --  Flags: read-write 
  282.    -- 
  283.    --  Name: Use_Underline_Property 
  284.    --  Type: Boolean 
  285.    --  Flags: read-write 
  286.    -- 
  287.    --  Name: Xalign_Property 
  288.    --  Type: Gfloat 
  289.    --  Flags: read-write 
  290.    --  If the child of the button is a Gtk.Misc.Gtk_Misc or 
  291.    --  Gtk.Alignment.Gtk_Alignment, this property can be used to control it's 
  292.    --  horizontal alignment. 0.0 is left aligned, 1.0 is right aligned. 
  293.    -- 
  294.    --  Name: Yalign_Property 
  295.    --  Type: Gfloat 
  296.    --  Flags: read-write 
  297.    --  If the child of the button is a Gtk.Misc.Gtk_Misc or 
  298.    --  Gtk.Alignment.Gtk_Alignment, this property can be used to control it's 
  299.    --  vertical alignment. 0.0 is top aligned, 1.0 is bottom aligned. 
  300.  
  301.    Focus_On_Click_Property : constant Glib.Properties.Property_Boolean; 
  302.    Image_Property : constant Glib.Properties.Property_Object; 
  303.    Image_Position_Property : constant Gtk.Enums.Property_Gtk_Position_Type; 
  304.    Label_Property : constant Glib.Properties.Property_String; 
  305.    Relief_Property : constant Gtk.Enums.Property_Gtk_Relief_Style; 
  306.    Use_Stock_Property : constant Glib.Properties.Property_Boolean; 
  307.    Use_Underline_Property : constant Glib.Properties.Property_Boolean; 
  308.    Xalign_Property : constant Glib.Properties.Property_Float; 
  309.    Yalign_Property : constant Glib.Properties.Property_Float; 
  310.  
  311.    ------------- 
  312.    -- Signals -- 
  313.    ------------- 
  314.    --  The following new signals are defined for this widget: 
  315.    -- 
  316.    --  "activate" 
  317.    --     procedure Handler (Self : access Gtk_Button_Record'Class); 
  318.    --  The ::activate signal on GtkButton is an action signal and emitting it 
  319.    --  causes the button to animate press then release. Applications should 
  320.    --  never connect to this signal, but use the Gtk.Button.Gtk_Button::clicked 
  321.    --  signal. 
  322.    -- 
  323.    --  "clicked" 
  324.    --     procedure Handler (Self : access Gtk_Button_Record'Class); 
  325.    --  Emitted when the button has been activated (pressed and released). 
  326.    -- 
  327.    --  "enter" 
  328.    --     procedure Handler (Self : access Gtk_Button_Record'Class); 
  329.    --  Emitted when the pointer enters the button. 
  330.    -- 
  331.    --  "leave" 
  332.    --     procedure Handler (Self : access Gtk_Button_Record'Class); 
  333.    --  Emitted when the pointer leaves the button. 
  334.    -- 
  335.    --  "pressed" 
  336.    --     procedure Handler (Self : access Gtk_Button_Record'Class); 
  337.    --  Emitted when the button is pressed. 
  338.    -- 
  339.    --  "released" 
  340.    --     procedure Handler (Self : access Gtk_Button_Record'Class); 
  341.    --  Emitted when the button is released. 
  342.  
  343.    Signal_Activate : constant Glib.Signal_Name := "activate"; 
  344.    Signal_Clicked : constant Glib.Signal_Name := "clicked"; 
  345.    Signal_Enter : constant Glib.Signal_Name := "enter"; 
  346.    Signal_Leave : constant Glib.Signal_Name := "leave"; 
  347.    Signal_Pressed : constant Glib.Signal_Name := "pressed"; 
  348.    Signal_Released : constant Glib.Signal_Name := "released"; 
  349.  
  350. private 
  351.    Focus_On_Click_Property : constant Glib.Properties.Property_Boolean := 
  352.      Glib.Properties.Build ("focus-on-click"); 
  353.    Image_Property : constant Glib.Properties.Property_Object := 
  354.      Glib.Properties.Build ("image"); 
  355.    Image_Position_Property : constant Gtk.Enums.Property_Gtk_Position_Type := 
  356.      Gtk.Enums.Build ("image-position"); 
  357.    Label_Property : constant Glib.Properties.Property_String := 
  358.      Glib.Properties.Build ("label"); 
  359.    Relief_Property : constant Gtk.Enums.Property_Gtk_Relief_Style := 
  360.      Gtk.Enums.Build ("relief"); 
  361.    Use_Stock_Property : constant Glib.Properties.Property_Boolean := 
  362.      Glib.Properties.Build ("use-stock"); 
  363.    Use_Underline_Property : constant Glib.Properties.Property_Boolean := 
  364.      Glib.Properties.Build ("use-underline"); 
  365.    Xalign_Property : constant Glib.Properties.Property_Float := 
  366.      Glib.Properties.Build ("xalign"); 
  367.    Yalign_Property : constant Glib.Properties.Property_Float := 
  368.      Glib.Properties.Build ("yalign"); 
  369. end Gtk.Button;