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