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-2009, 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 
  27. --  be clicked on by the user to start any action. 
  28. --  This button does not have multiple states, it can just be temporarily 
  29. --  pressed while the mouse is on 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. --  </description> 
  34. -- 
  35. --  <example> 
  36. --  +------------------------------------------------+ 
  37. --  |                   BORDER                       | 
  38. --  |  +------------------------------------------+  | 
  39. --  |  |\\\\\\\\\\\\\\\\DEFAULT\\\\\\\\\\\\\\\\\  |  | 
  40. --  |  |\\+------------------------------------+  |  | 
  41. --  |  |\\| |           SPACING       3      | |  |  | 
  42. --  |  |\\| +--------------------------------+ |  |  | 
  43. --  |  |\\| |########## FOCUS ###############| |  |  | 
  44. --  |  |\\| |#+----------------------------+#| |  |  | 
  45. --  |  |\\| |#|         RELIEF            \|#| |  |  | 
  46. --  |  |\\| |#|  +-----------------------+\|#| |  |  | 
  47. --  |  |\\|1|#|  +     THE TEXT          +\|#|2|  |  | 
  48. --  |  |\\| |#|  +-----------------------+\|#| |  |  | 
  49. --  |  |\\| |#| \\\\\ ythickness \\\\\\\\\\|#| |  |  | 
  50. --  |  |\\| |#+----------------------------+#| |  |  | 
  51. --  |  |\\| |########### 1 ##################| |  |  | 
  52. --  |  |\\| +--------------------------------+ |  |  | 
  53. --  |  |\\| |        default spacing   4     | |  |  | 
  54. --  |  |\\+------------------------------------+  |  | 
  55. --  |  |\            ythickness                   |  | 
  56. --  |  +------------------------------------------+  | 
  57. --  |                border_width                    | 
  58. --  +------------------------------------------------+ 
  59. --  </example> 
  60. --  <c_version>2.14</c_version> 
  61. --  <screenshot>gtk-button</screenshot> 
  62. --  <group>Buttons and Toggles</group> 
  63. --  <testgtk>create_buttons.adb</testgtk> 
  64.  
  65. with Glib.Properties; 
  66. with Gtk.Bin; 
  67. with Gtk.Enums; 
  68. with Gtk.Widget; 
  69.  
  70. package Gtk.Button is 
  71.  
  72.    type Gtk_Button_Record is new Bin.Gtk_Bin_Record with private; 
  73.    type Gtk_Button is access all Gtk_Button_Record'Class; 
  74.  
  75.    procedure Gtk_New (Button : out Gtk_Button; Label : UTF8_String := ""); 
  76.    --  Create a new button. 
  77.    --  if Label is not the empty string, then the text appears in the 
  78.    --  button (and the child of the button is a Gtk_Label). On the other 
  79.    --  hand, if Label is the empty string, then no child is created for 
  80.    --  the button and it is your responsibility to add one. This is the 
  81.    --  recommended way to put a pixmap inside the button. 
  82.  
  83.    procedure Gtk_New_From_Stock 
  84.      (Button : out Gtk_Button; Stock_Id : String); 
  85.    --  Create a new button containing the image and text from a stock item. 
  86.    --  Some stock ids have predefined contants like Gtk.Stock.Stock_OK or 
  87.    --  Gtk.Stock.Stock_Apply. See Gtk.Stock for a complete list of predefined 
  88.    --  stock items. 
  89.    --  Stock_Id: the name of the stock item. 
  90.  
  91.    procedure Gtk_New_With_Mnemonic 
  92.      (Button : out Gtk_Button; Label : UTF8_String); 
  93.    --  Create a new button containing a label. 
  94.    --  Label: The text of the button, with an underscore in front of the 
  95.    --         mnemonic character 
  96.    --  If characters in Label are preceded by an underscore, they are 
  97.    --  underlined indicating that they represent a keyboard accelerator called 
  98.    --  a mnemonic. Pressing Alt and that key activates the button. 
  99.  
  100.    procedure Initialize 
  101.      (Button : access Gtk_Button_Record'Class; 
  102.       Label  : UTF8_String); 
  103.    --  Internal initialization function. 
  104.    --  See the section "Creating your own widgets" in the documentation. 
  105.  
  106.    procedure Initialize_From_Stock 
  107.      (Button   : access Gtk_Button_Record'Class; 
  108.       Stock_Id : String); 
  109.    --  Internal initialization function. 
  110.  
  111.    procedure Initialize_With_Mnemonic 
  112.      (Button : access Gtk_Button_Record'Class; 
  113.       Label  : UTF8_String); 
  114.    --  Internal initialization function. 
  115.  
  116.    function Get_Type return Gtk.Gtk_Type; 
  117.    --  Return the internal value associated with a Gtk_Button. 
  118.  
  119.    procedure Set_Relief 
  120.      (Button    : access Gtk_Button_Record; 
  121.       New_Style : Gtk.Enums.Gtk_Relief_Style); 
  122.    function Get_Relief 
  123.      (Button    : access Gtk_Button_Record) return Gtk.Enums.Gtk_Relief_Style; 
  124.    --  Modify the relief style for the button. 
  125.    --  This modifies only its visual aspect, not its behavior. 
  126.  
  127.    procedure Set_Label 
  128.      (Button : access Gtk_Button_Record; 
  129.       Label  : UTF8_String); 
  130.    function Get_Label 
  131.      (Button : access Gtk_Button_Record) return UTF8_String; 
  132.    --  Set or gets the label of the button. 
  133.    --  This text is also used to select an icon if Set_Use_Stock was called 
  134.    --  with a parameter set to True. 
  135.  
  136.    procedure Set_Use_Underline 
  137.      (Button        : access Gtk_Button_Record; 
  138.       Use_Underline : Boolean); 
  139.    function Get_Use_Underline 
  140.      (Button : access Gtk_Button_Record) return Boolean; 
  141.    --  Sets whether an underscore used in the button's label designates an 
  142.    --  accelerator. 
  143.    --  If True, then if the user presses alt and the character following the 
  144.    --  underscore, then the button will act as if it had been pressed. 
  145.  
  146.    procedure Set_Use_Stock 
  147.      (Button    : access Gtk_Button_Record; 
  148.       Use_Stock : Boolean); 
  149.    function Get_Use_Stock 
  150.      (Button : access Gtk_Button_Record) return Boolean; 
  151.    --  Sets or Gets whether a stock item is used by the button. 
  152.  
  153.    procedure Set_Alignment 
  154.      (Button : access Gtk_Button_Record; 
  155.       Xalign : Gfloat := 0.5; 
  156.       Yalign : Gfloat := 0.5); 
  157.    procedure Get_Alignment 
  158.      (Button : access Gtk_Button_Record; 
  159.       Xalign : out Gfloat; 
  160.       Yalign : out Gfloat); 
  161.    --  Specify the alignment of the label inside the button. 
  162.    --  Passing (0.0, 0.0) indicates the label should be at the top-left corner 
  163.    --  of the button. (0.5, 0.5) indicates that the label should be centered. 
  164.    --  This property has no effect unless the button's child is a child of 
  165.    --  Gtk_Alignment or Gtk_Misc 
  166.  
  167.    procedure Set_Focus_On_Click 
  168.      (Button         : access Gtk_Button_Record; 
  169.       Focus_On_Click : Boolean := True); 
  170.    function Get_Focus_On_Click 
  171.      (Button : access Gtk_Button_Record) 
  172.       return Boolean; 
  173.    --  Sets whether the button will grab focus when it is clicked with the 
  174.    --  mouse. 
  175.    --  Setting Focus_On_Click to False is useful in contexts like toolbars 
  176.    --  where the focus should not be removed from the main area of the 
  177.    --  application. 
  178.  
  179.    procedure Set_Image 
  180.      (Button : access Gtk_Button_Record; 
  181.       Image  : access Gtk.Widget.Gtk_Widget_Record'Class); 
  182.    function Get_Image 
  183.      (Button : access Gtk_Button_Record) 
  184.       return Gtk.Widget.Gtk_Widget; 
  185.    --  Set the image of the button. 
  186.    --  You do not need to call Show on the image yourself. 
  187.    --  This settings might have no effect, depending on the theme configuration 
  188.    --  that the application's user is using (in particular, the setting 
  189.    --  "gtk-button-images" indicates whether or not images should be displayed 
  190.    --  in buttons). 
  191.  
  192.    function Get_Image_Position 
  193.      (Button : access Gtk_Button_Record) return Gtk.Enums.Gtk_Position_Type; 
  194.    procedure Set_Image_Position 
  195.      (Button   : access Gtk_Button_Record; 
  196.       Position : Gtk.Enums.Gtk_Position_Type); 
  197.    --  Gets the position of the image relative to the text 
  198.    --  inside the button. 
  199.    --  Since: 2.10 
  200.  
  201.    ---------------------- 
  202.    -- Signals emission -- 
  203.    ---------------------- 
  204.  
  205.    procedure Pressed  (Button : access Gtk_Button_Record); 
  206.    --  Send the "pressed" signal to the button 
  207.  
  208.    procedure Released (Button : access Gtk_Button_Record); 
  209.    --  Send the "release" signal to the button 
  210.  
  211.    procedure Clicked  (Button : access Gtk_Button_Record); 
  212.    --  Send the "clicked" signal to the button 
  213.  
  214.    procedure Enter    (Button : access Gtk_Button_Record); 
  215.    --  Send the "enter" signal to the button 
  216.  
  217.    procedure Leave    (Button : access Gtk_Button_Record); 
  218.    --  Send the "leave" signal to the button 
  219.  
  220.    ---------------- 
  221.    -- Properties -- 
  222.    ---------------- 
  223.    --  The following properties are defined for this widget. See 
  224.    --  Glib.Properties for more information on properties. 
  225.  
  226.    --  <properties> 
  227.    --  Name:  Label_Property 
  228.    --  Type:  UTF8_String 
  229.    --  Flags: read-write 
  230.    --  Descr: Changes the text contained in the button. 
  231.    --  See also: Same as calling Set_Label directly. 
  232.    -- 
  233.    --  Name:  Relief_Property 
  234.    --  Type:  Gtk_Relief_Style 
  235.    --  Flags: read-write 
  236.    --  Descr: Changes the relief used to draw the border of the button. 
  237.    --  See also: Same as calling Set_Relief directly. 
  238.    -- 
  239.    --  Name:  Use_Underline_Property 
  240.    --  Type:  Boolean 
  241.    --  Flags: read-write 
  242.    --  See also: Same as calling Set_Use_Underline directly 
  243.    -- 
  244.    --  Name:  Use_Stock_Property 
  245.    --  Type:  Boolean 
  246.    --  Flags: read-write 
  247.    --  See also: Same as calling Set_Use_Stock directly 
  248.    -- 
  249.    --  Name:  Focus_On_Click_Property 
  250.    --  Type:  Boolean 
  251.    --  Flags: read-write 
  252.    --  See also: Same as calling Set_Focus_On_Click directly 
  253.    -- 
  254.    --  Name:  Image_Property 
  255.    --  Type:  Object 
  256.    --  Descr: Child widget to appear next to the button text 
  257.    -- 
  258.    --  Name:  Image_Position_Property 
  259.    --  Type:  Enum 
  260.    --  Descr: The position of the image relative to the text 
  261.    -- 
  262.    --  Name:  Xalign_Property 
  263.    --  Type:  Float 
  264.    --  Descr: Horizontal position of child in available space. 0.0 is left 
  265.    --         aligned, 1.0 is right aligned 
  266.    -- 
  267.    --  Name:  Yalign_Property 
  268.    --  Type:  Float 
  269.    --  Descr: Vertical position of child in available space. 0.0 is top 
  270.    --         aligned, 1.0 is bottom aligned 
  271.    --  </properties> 
  272.  
  273.    Label_Property          : constant Glib.Properties.Property_String; 
  274.    Relief_Property         : constant Gtk.Enums.Property_Gtk_Relief_Style; 
  275.    Use_Underline_Property  : constant Glib.Properties.Property_Boolean; 
  276.    Use_Stock_Property      : constant Glib.Properties.Property_Boolean; 
  277.    Focus_On_Click_Property : constant Glib.Properties.Property_Boolean; 
  278.    Image_Property          : constant Glib.Properties.Property_Object; 
  279.    --  Image_Position_Property : constant Glib.Properties.Property_Enum; 
  280.    Xalign_Property         : constant Glib.Properties.Property_Float; 
  281.    Yalign_Property         : constant Glib.Properties.Property_Float; 
  282.  
  283.    ---------------------- 
  284.    -- Style Properties -- 
  285.    ---------------------- 
  286.    --  The following properties can be changed through the gtk theme and 
  287.    --  configuration files, and retrieved through Gtk.Widget.Style_Get_Property 
  288.  
  289.    --  <style_properties> 
  290.    --  Name:  Child_Displacement_X_Property 
  291.    --  Type:  Int 
  292.    --  Descr: How far in the x direction to move the child when the button is 
  293.    --         depressed 
  294.    -- 
  295.    --  Name:  Child_Displacement_Y_Property 
  296.    --  Type:  Int 
  297.    --  Descr: How far in the y direction to move the child when the button is 
  298.    --         depressed 
  299.    -- 
  300.    --  Name:  Default_Border_Property 
  301.    --  Type:  Boxed 
  302.    --  Descr: Extra space to add for CAN_DEFAULT buttons 
  303.    -- 
  304.    --  Name:  Default_Outside_Border_Property 
  305.    --  Type:  Boxed 
  306.    --  Descr: Extra space to add for CAN_DEFAULT buttons that is always drawn 
  307.    --         outside the border 
  308.    -- 
  309.    --  Name:  Displace_Focus_Property 
  310.    --  Type:  Boolean 
  311.    --  Descr: Whether the child_displacement_x/_y properties should also affect 
  312.    --         the focus rectangle 
  313.    -- 
  314.    --  Name:  Image_Spacing_Property 
  315.    --  Type:  Int 
  316.    --  Descr: Spacing in pixels between the image and label 
  317.    -- 
  318.    --  Name:  Inner_Border_Property 
  319.    --  Type:  Boxed 
  320.    --  Descr: Border between button edges and child 
  321.    --  </style_properties> 
  322.  
  323.    Child_Displacement_X_Property   : constant Glib.Properties.Property_Int; 
  324.    Child_Displacement_Y_Property   : constant Glib.Properties.Property_Int; 
  325.    --  Default_Border_Property      : constant Glib.Properties.Property_Boxed; 
  326.    --  Default_Outside_Border_Property : 
  327.    --     constant Glib.Properties.Property_Boxed; 
  328.    Displace_Focus_Property         : constant Glib.Properties.Property_Boolean; 
  329.    Image_Spacing_Property : constant Glib.Properties.Property_Int; 
  330.    --  Inner_Border_Property : constant Glib.Properties.Property_Boxed; 
  331.  
  332.    ------------- 
  333.    -- Signals -- 
  334.    ------------- 
  335.  
  336.    --  <signals> 
  337.    --  The following new signals are defined for this widget: 
  338.    -- 
  339.    --  - "clicked" 
  340.    --    procedure Handler (Button : access Gtk_Button_Record'Class); 
  341.    --    Emitted when the button has been clicked on by the user. This is the 
  342.    --    signal you should use to start your own actions. 
  343.    -- 
  344.    --  - "pressed" 
  345.    --    procedure Handler (Button : access Gtk_Button_Record'Class); 
  346.    --    Emitted when the user presses the mouse button on 
  347.    --    the widget. The default implementation modifies the widget state 
  348.    --    and its visual aspect. 
  349.    -- 
  350.    --  - "released" 
  351.    --    procedure Handler (Button : access Gtk_Button_Record'Class); 
  352.    --    Emitted when the user releases the mouse button and 
  353.    --    is inside of the widget. The default implementation modifies the 
  354.    --    widget state and its visual aspect. If the mouse is still inside 
  355.    --    the widget, then the "clicked" signal is emitted. 
  356.    -- 
  357.    --  - "enter" 
  358.    --    procedure Handler (Button : access Gtk_Button_Record'Class); 
  359.    --    Emitted when the mouse enters the button. The clicked 
  360.    --    signal can only be emitted when the mouse is inside the button. 
  361.    -- 
  362.    --  - "leave" 
  363.    --    procedure Handler (Button : access Gtk_Button_Record'Class); 
  364.    --    Emitted when the mouse leaves the button. 
  365.    -- 
  366.    --  - "activate" 
  367.    --    procedure Handler (Button : access Gtk_Button_Record'Class); 
  368.    --    You should emit this signal to force the activation of this widget, as 
  369.    --    if the user has clicked on it. This is generally only useful when 
  370.    --    bound to a key binding. 
  371.    -- 
  372.    --  </signals> 
  373.  
  374.    Signal_Clicked  : constant Glib.Signal_Name := "clicked"; 
  375.    Signal_Pressed  : constant Glib.Signal_Name := "pressed"; 
  376.    Signal_Released : constant Glib.Signal_Name := "released"; 
  377.    Signal_Enter    : constant Glib.Signal_Name := "enter"; 
  378.    Signal_Leave    : constant Glib.Signal_Name := "leave"; 
  379.    Signal_Activate : constant Glib.Signal_Name := "activate"; 
  380.  
  381. private 
  382.    type Gtk_Button_Record is new Bin.Gtk_Bin_Record with null record; 
  383.  
  384.    --  Image_Position_Property : constant Glib.Properties.Property_Enum := 
  385.    --    Glib.Properties.Build ("image-position"); 
  386.    Label_Property  : constant Glib.Properties.Property_String := 
  387.      Glib.Properties.Build ("label"); 
  388.    Relief_Property : constant Gtk.Enums.Property_Gtk_Relief_Style := 
  389.      Gtk.Enums.Build ("relief"); 
  390.    Use_Underline_Property  : constant Glib.Properties.Property_Boolean := 
  391.      Glib.Properties.Build ("use-underline"); 
  392.    Use_Stock_Property      : constant Glib.Properties.Property_Boolean := 
  393.      Glib.Properties.Build ("use-stock"); 
  394.    Focus_On_Click_Property : constant Glib.Properties.Property_Boolean := 
  395.      Glib.Properties.Build ("focus-on-click"); 
  396.    Image_Property : constant Glib.Properties.Property_Object := 
  397.      Glib.Properties.Build ("image"); 
  398.    Xalign_Property : constant Glib.Properties.Property_Float := 
  399.      Glib.Properties.Build ("xalign"); 
  400.    Yalign_Property : constant Glib.Properties.Property_Float := 
  401.      Glib.Properties.Build ("yalign"); 
  402.  
  403.    Child_Displacement_X_Property : constant Glib.Properties.Property_Int := 
  404.      Glib.Properties.Build ("child-displacement-x"); 
  405.    Child_Displacement_Y_Property : constant Glib.Properties.Property_Int := 
  406.      Glib.Properties.Build ("child-displacement-y"); 
  407. --     Default_Border_Property : constant Glib.Properties.Property_Boxed := 
  408. --       Glib.Properties.Build ("default-border"); 
  409.    --  Default_Outside_Border_Property : constant 
  410.    --    Glib.Properties.Property_Boxed := 
  411.    --    Glib.Properties.Build ("default-outside-border"); 
  412.    Displace_Focus_Property : constant Glib.Properties.Property_Boolean := 
  413.      Glib.Properties.Build ("displace-focus"); 
  414.    Image_Spacing_Property : constant Glib.Properties.Property_Int := 
  415.      Glib.Properties.Build ("image-spacing"); 
  416.    --  Inner_Border_Property : constant Glib.Properties.Property_Boxed := 
  417.    --    Glib.Properties.Build ("inner-border"); 
  418.  
  419.    pragma Import (C, Get_Type, "gtk_button_get_type"); 
  420. end Gtk.Button;