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