1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  A single radio button performs the same basic function as a 
  26. --  Gtk.Check_Button.Gtk_Check_Button, as its position in the object hierarchy 
  27. --  reflects. It is only when multiple radio buttons are grouped together that 
  28. --  they become a different user interface component in their own right. 
  29. -- 
  30. --  Every radio button is a member of some group of radio buttons. When one is 
  31. --  selected, all other radio buttons in the same group are deselected. A 
  32. --  Gtk.Radio_Button.Gtk_Radio_Button is one way of giving the user a choice 
  33. --  from many options. 
  34. -- 
  35. --  Radio button widgets are created with gtk_radio_button_new, passing null 
  36. --  as the argument if this is the first radio button in a group. In subsequent 
  37. --  calls, the group you wish to add this button to should be passed as an 
  38. --  argument. Optionally, Gtk.Radio_Button.Gtk_New can be used if you want a 
  39. --  text label on the radio button. 
  40. -- 
  41. --  Alternatively, when adding widgets to an existing group of radio buttons, 
  42. --  use gtk_radio_button_new_from_widget with a 
  43. --  Gtk.Radio_Button.Gtk_Radio_Button that already has a group assigned to it. 
  44. --  The convenience function Gtk.Radio_Button.Gtk_New is also provided. 
  45. -- 
  46. --  To retrieve the group a Gtk.Radio_Button.Gtk_Radio_Button is assigned to, 
  47. --  use Gtk.Radio_Button.Get_Group. 
  48. -- 
  49. --  To remove a Gtk.Radio_Button.Gtk_Radio_Button from one group and make it 
  50. --  part of a new one, use Gtk.Radio_Button.Set_Group. 
  51. -- 
  52. --  The group list does not need to be freed, as each 
  53. --  Gtk.Radio_Button.Gtk_Radio_Button will remove itself and its list item when 
  54. --  it is destroyed. 
  55. -- 
  56. --  == How to create a group of two radio buttons. == 
  57. -- 
  58. --    void create_radio_buttons (void) { 
  59. --       GtkWidget *window, *radio1, *radio2, *box, *entry; 
  60. --       window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 
  61. --       box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); 
  62. --       gtk_box_set_homogeneous (GTK_BOX (box), TRUE); 
  63. --       /* Create a radio button with a GtkEntry widget */ 
  64. --       radio1 = gtk_radio_button_new (NULL); 
  65. --       entry = gtk_entry_new (<!-- -->); 
  66. --          gtk_container_add (GTK_CONTAINER (radio1), entry); 
  67. --          /* Create a radio button with a label */ 
  68. --             radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1), 
  69. --             "I'm the second radio button."); 
  70. --          /* Pack them into a box, then show all the widgets */ 
  71. --          gtk_box_pack_start (GTK_BOX (box), radio1, TRUE, TRUE, 2); 
  72. --          gtk_box_pack_start (GTK_BOX (box), radio2, TRUE, TRUE, 2); 
  73. --          gtk_container_add (GTK_CONTAINER (window), box); 
  74. --          gtk_widget_show_all (window); 
  75. --          return; 
  76. --       } 
  77. -- 
  78. --  When an unselected button in the group is clicked the clicked button 
  79. --  receives the Gtk.Toggle_Button.Gtk_Toggle_Button::toggled signal, as does 
  80. --  the previously selected button. Inside the 
  81. --  Gtk.Toggle_Button.Gtk_Toggle_Button::toggled handler, 
  82. --  Gtk.Toggle_Button.Get_Active can be used to determine if the button has 
  83. --  been selected or deselected. 
  84. -- 
  85. --  </description> 
  86. --  <screenshot>gtk-radio_button</screenshot> 
  87. --  <group>Buttons and Toggles</group> 
  88. --  <testgtk>create_radio_button.adb</testgtk> 
  89. pragma Ada_2005; 
  90.  
  91. pragma Warnings (Off, "*is already use-visible*"); 
  92. with Glib;             use Glib; 
  93. with Glib.Object;      use Glib.Object; 
  94. with Glib.Properties;  use Glib.Properties; 
  95. with Glib.Types;       use Glib.Types; 
  96. with Glib.Variant;     use Glib.Variant; 
  97. with Gtk.Action;       use Gtk.Action; 
  98. with Gtk.Actionable;   use Gtk.Actionable; 
  99. with Gtk.Activatable;  use Gtk.Activatable; 
  100. with Gtk.Buildable;    use Gtk.Buildable; 
  101. with Gtk.Check_Button; use Gtk.Check_Button; 
  102. with Gtk.Widget;       use Gtk.Widget; 
  103.  
  104. package Gtk.Radio_Button is 
  105.  
  106.    type Gtk_Radio_Button_Record is new Gtk_Check_Button_Record with null record; 
  107.    type Gtk_Radio_Button is access all Gtk_Radio_Button_Record'Class; 
  108.  
  109.    ------------------ 
  110.    -- Constructors -- 
  111.    ------------------ 
  112.  
  113.    procedure Gtk_New 
  114.       (Radio_Button : out Gtk_Radio_Button; 
  115.        Group        : Gtk.Widget.Widget_SList.GSlist := Widget_SList.Null_List; 
  116.        Label        : UTF8_String := ""); 
  117.    procedure Initialize 
  118.       (Radio_Button : not null access Gtk_Radio_Button_Record'Class; 
  119.        Group        : Gtk.Widget.Widget_SList.GSlist := Widget_SList.Null_List; 
  120.        Label        : UTF8_String := ""); 
  121.    --  Creates or initializes a new radio button, belonging to Group. If Label 
  122.    --  is left as the empty string, then the button will not have any child and 
  123.    --  you are free to put any thing you want in it, including a pixmap. To 
  124.    --  initialize the group (when creating the first button), leave Group to 
  125.    --  the Null_List. You can later get the new group that is created with a 
  126.    --  call to the Get_Group subprogram below. 
  127.    --  "group": an existing radio button group, or null if you are creating a 
  128.    --  new group. 
  129.    --  "label": the text label to display next to the radio button. 
  130.  
  131.    function Gtk_Radio_Button_New_With_Label 
  132.       (Group : Gtk.Widget.Widget_SList.GSlist := Widget_SList.Null_List; 
  133.        Label : UTF8_String := "") return Gtk_Radio_Button; 
  134.    --  Creates or initializes a new radio button, belonging to Group. If Label 
  135.    --  is left as the empty string, then the button will not have any child and 
  136.    --  you are free to put any thing you want in it, including a pixmap. To 
  137.    --  initialize the group (when creating the first button), leave Group to 
  138.    --  the Null_List. You can later get the new group that is created with a 
  139.    --  call to the Get_Group subprogram below. 
  140.    --  "group": an existing radio button group, or null if you are creating a 
  141.    --  new group. 
  142.    --  "label": the text label to display next to the radio button. 
  143.  
  144.    procedure Gtk_New 
  145.       (Radio_Button : out Gtk_Radio_Button; 
  146.        Group        : access Gtk_Radio_Button_Record'Class; 
  147.        Label        : UTF8_String := ""); 
  148.    procedure Initialize 
  149.       (Radio_Button : not null access Gtk_Radio_Button_Record'Class; 
  150.        Group        : access Gtk_Radio_Button_Record'Class; 
  151.        Label        : UTF8_String := ""); 
  152.    --  Creates a new Gtk.Radio_Button.Gtk_Radio_Button with a text label, 
  153.    --  adding it to the same group as Radio_Group_Member. 
  154.    --  "Group": widget to get radio group from or null 
  155.    --  "label": a text string to display next to the radio button. 
  156.  
  157.    function Gtk_Radio_Button_New_With_Label_From_Widget 
  158.       (Group : access Gtk_Radio_Button_Record'Class; 
  159.        Label : UTF8_String := "") return Gtk_Radio_Button; 
  160.    --  Creates a new Gtk.Radio_Button.Gtk_Radio_Button with a text label, 
  161.    --  adding it to the same group as Radio_Group_Member. 
  162.    --  "Group": widget to get radio group from or null 
  163.    --  "label": a text string to display next to the radio button. 
  164.  
  165.    procedure Gtk_New_With_Mnemonic 
  166.       (Radio_Button : out Gtk_Radio_Button; 
  167.        Group        : Gtk.Widget.Widget_SList.GSlist := Widget_SList.Null_List; 
  168.        Label        : UTF8_String); 
  169.    procedure Initialize_With_Mnemonic 
  170.       (Radio_Button : not null access Gtk_Radio_Button_Record'Class; 
  171.        Group        : Gtk.Widget.Widget_SList.GSlist := Widget_SList.Null_List; 
  172.        Label        : UTF8_String); 
  173.    --  Creates a new Gtk.Radio_Button.Gtk_Radio_Button containing a label, 
  174.    --  adding it to the same group as Group. The label will be created using 
  175.    --  Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the 
  176.    --  mnemonic for the button. 
  177.    --  "group": the radio button group 
  178.    --  "label": the text of the button, with an underscore in front of the 
  179.    --  mnemonic character 
  180.  
  181.    procedure Gtk_New_With_Mnemonic 
  182.       (Radio_Button : out Gtk_Radio_Button; 
  183.        Group        : access Gtk_Radio_Button_Record'Class; 
  184.        Label        : UTF8_String); 
  185.    procedure Initialize_With_Mnemonic 
  186.       (Radio_Button : not null access Gtk_Radio_Button_Record'Class; 
  187.        Group        : access Gtk_Radio_Button_Record'Class; 
  188.        Label        : UTF8_String); 
  189.    --  Creates a new Gtk.Radio_Button.Gtk_Radio_Button containing a label. The 
  190.    --  label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so 
  191.    --  underscores in Label indicate the mnemonic for the button. 
  192.    --  To initialize a new group (when creating the first button), you should 
  193.    --  pass it null or a button that has not been created with Gtk_New, as in 
  194.    --  the example below. 
  195.    --  "Group": widget to get radio group from or null 
  196.    --  "label": the text of the button, with an underscore in front of the 
  197.    --  mnemonic character 
  198.  
  199.    function Gtk_Radio_Button_New_With_Mnemonic 
  200.       (Group : Gtk.Widget.Widget_SList.GSlist := Widget_SList.Null_List; 
  201.        Label : UTF8_String) return Gtk_Radio_Button; 
  202.    --  Creates a new Gtk.Radio_Button.Gtk_Radio_Button containing a label, 
  203.    --  adding it to the same group as Group. The label will be created using 
  204.    --  Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the 
  205.    --  mnemonic for the button. 
  206.    --  "group": the radio button group 
  207.    --  "label": the text of the button, with an underscore in front of the 
  208.    --  mnemonic character 
  209.  
  210.    function Gtk_Radio_Button_New_With_Mnemonic_From_Widget 
  211.       (Group : access Gtk_Radio_Button_Record'Class; 
  212.        Label : UTF8_String) return Gtk_Radio_Button; 
  213.    --  Creates a new Gtk.Radio_Button.Gtk_Radio_Button containing a label. The 
  214.    --  label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so 
  215.    --  underscores in Label indicate the mnemonic for the button. 
  216.    --  To initialize a new group (when creating the first button), you should 
  217.    --  pass it null or a button that has not been created with Gtk_New, as in 
  218.    --  the example below. 
  219.    --  "Group": widget to get radio group from or null 
  220.    --  "label": the text of the button, with an underscore in front of the 
  221.    --  mnemonic character 
  222.  
  223.    function Get_Type return Glib.GType; 
  224.    pragma Import (C, Get_Type, "gtk_radio_button_get_type"); 
  225.  
  226.    ------------- 
  227.    -- Methods -- 
  228.    ------------- 
  229.  
  230.    function Get_Group 
  231.       (Radio_Button : not null access Gtk_Radio_Button_Record) 
  232.        return Gtk.Widget.Widget_SList.GSlist; 
  233.    --  Retrieves the group assigned to a radio button. 
  234.  
  235.    procedure Set_Group 
  236.       (Radio_Button : not null access Gtk_Radio_Button_Record; 
  237.        Group        : Gtk.Widget.Widget_SList.GSlist); 
  238.    --  Sets a Gtk.Radio_Button.Gtk_Radio_Button's group. It should be noted 
  239.    --  that this does not change the layout of your interface in any way, so if 
  240.    --  you are changing the group, it is likely you will need to re-arrange the 
  241.    --  user interface to reflect these changes. 
  242.    --  "group": an existing radio button group, such as one returned from 
  243.    --  Gtk.Radio_Button.Get_Group. 
  244.  
  245.    procedure Join_Group 
  246.       (Radio_Button : not null access Gtk_Radio_Button_Record; 
  247.        Group_Source : access Gtk_Radio_Button_Record'Class); 
  248.    --  Joins a Gtk.Radio_Button.Gtk_Radio_Button object to the group of 
  249.    --  another Gtk.Radio_Button.Gtk_Radio_Button object 
  250.    --  Use this in language bindings instead of the Gtk.Radio_Button.Get_Group 
  251.    --  and Gtk.Radio_Button.Set_Group methods 
  252.    --  A common way to set up a group of radio buttons is the following: |[ 
  253.    --  GtkRadioButton *radio_button; GtkRadioButton *last_button; 
  254.    --  while (/* more buttons to add */) { radio_button = gtk_radio_button_new 
  255.    --  (...); 
  256.    --  gtk_radio_button_join_group (radio_button, last_button); last_button = 
  257.    --  radio_button; } ]| 
  258.    --  Since: gtk+ 3.0 
  259.    --  "group_source": a radio button object whos group we are joining, or 
  260.    --  null to remove the radio button from its group 
  261.  
  262.    --------------------------------------------- 
  263.    -- Inherited subprograms (from interfaces) -- 
  264.    --------------------------------------------- 
  265.    --  Methods inherited from the Buildable interface are not duplicated here 
  266.    --  since they are meant to be used by tools, mostly. If you need to call 
  267.    --  them, use an explicit cast through the "-" operator below. 
  268.  
  269.    function Get_Action_Name 
  270.       (Self : not null access Gtk_Radio_Button_Record) return UTF8_String; 
  271.  
  272.    procedure Set_Action_Name 
  273.       (Self        : not null access Gtk_Radio_Button_Record; 
  274.        Action_Name : UTF8_String); 
  275.  
  276.    function Get_Action_Target_Value 
  277.       (Self : not null access Gtk_Radio_Button_Record) 
  278.        return Glib.Variant.Gvariant; 
  279.  
  280.    procedure Set_Action_Target_Value 
  281.       (Self         : not null access Gtk_Radio_Button_Record; 
  282.        Target_Value : Glib.Variant.Gvariant); 
  283.  
  284.    procedure Set_Detailed_Action_Name 
  285.       (Self                 : not null access Gtk_Radio_Button_Record; 
  286.        Detailed_Action_Name : UTF8_String); 
  287.  
  288.    procedure Do_Set_Related_Action 
  289.       (Self   : not null access Gtk_Radio_Button_Record; 
  290.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  291.  
  292.    function Get_Related_Action 
  293.       (Self : not null access Gtk_Radio_Button_Record) 
  294.        return Gtk.Action.Gtk_Action; 
  295.  
  296.    procedure Set_Related_Action 
  297.       (Self   : not null access Gtk_Radio_Button_Record; 
  298.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  299.  
  300.    function Get_Use_Action_Appearance 
  301.       (Self : not null access Gtk_Radio_Button_Record) return Boolean; 
  302.  
  303.    procedure Set_Use_Action_Appearance 
  304.       (Self           : not null access Gtk_Radio_Button_Record; 
  305.        Use_Appearance : Boolean); 
  306.  
  307.    procedure Sync_Action_Properties 
  308.       (Self   : not null access Gtk_Radio_Button_Record; 
  309.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  310.  
  311.    ---------------- 
  312.    -- Properties -- 
  313.    ---------------- 
  314.    --  The following properties are defined for this widget. See 
  315.    --  Glib.Properties for more information on properties) 
  316.  
  317.    Group_Property : constant Glib.Properties.Property_Object; 
  318.    --  Type: Gtk_Radio_Button 
  319.    --  Flags: write 
  320.    --  Sets a new group for a radio button. 
  321.  
  322.    ------------- 
  323.    -- Signals -- 
  324.    ------------- 
  325.  
  326.    type Cb_Gtk_Radio_Button_Void is not null access procedure 
  327.      (Self : access Gtk_Radio_Button_Record'Class); 
  328.  
  329.    type Cb_GObject_Void is not null access procedure 
  330.      (Self : access Glib.Object.GObject_Record'Class); 
  331.  
  332.    Signal_Group_Changed : constant Glib.Signal_Name := "group-changed"; 
  333.    procedure On_Group_Changed 
  334.       (Self  : not null access Gtk_Radio_Button_Record; 
  335.        Call  : Cb_Gtk_Radio_Button_Void; 
  336.        After : Boolean := False); 
  337.    procedure On_Group_Changed 
  338.       (Self  : not null access Gtk_Radio_Button_Record; 
  339.        Call  : Cb_GObject_Void; 
  340.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  341.        After : Boolean := False); 
  342.    --  Emitted when the group of radio buttons that a radio button belongs to 
  343.    --  changes. This is emitted when a radio button switches from being alone 
  344.    --  to being part of a group of 2 or more buttons, or vice-versa, and when a 
  345.    --  button is moved from one group of 2 or more buttons to a different one, 
  346.    --  but not when the composition of the group that a button belongs to 
  347.    --  changes. 
  348.  
  349.    ---------------- 
  350.    -- Interfaces -- 
  351.    ---------------- 
  352.    --  This class implements several interfaces. See Glib.Types 
  353.    -- 
  354.    --  - "Actionable" 
  355.    -- 
  356.    --  - "Activatable" 
  357.    -- 
  358.    --  - "Buildable" 
  359.  
  360.    package Implements_Gtk_Actionable is new Glib.Types.Implements 
  361.      (Gtk.Actionable.Gtk_Actionable, Gtk_Radio_Button_Record, Gtk_Radio_Button); 
  362.    function "+" 
  363.      (Widget : access Gtk_Radio_Button_Record'Class) 
  364.    return Gtk.Actionable.Gtk_Actionable 
  365.    renames Implements_Gtk_Actionable.To_Interface; 
  366.    function "-" 
  367.      (Interf : Gtk.Actionable.Gtk_Actionable) 
  368.    return Gtk_Radio_Button 
  369.    renames Implements_Gtk_Actionable.To_Object; 
  370.  
  371.    package Implements_Gtk_Activatable is new Glib.Types.Implements 
  372.      (Gtk.Activatable.Gtk_Activatable, Gtk_Radio_Button_Record, Gtk_Radio_Button); 
  373.    function "+" 
  374.      (Widget : access Gtk_Radio_Button_Record'Class) 
  375.    return Gtk.Activatable.Gtk_Activatable 
  376.    renames Implements_Gtk_Activatable.To_Interface; 
  377.    function "-" 
  378.      (Interf : Gtk.Activatable.Gtk_Activatable) 
  379.    return Gtk_Radio_Button 
  380.    renames Implements_Gtk_Activatable.To_Object; 
  381.  
  382.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  383.      (Gtk.Buildable.Gtk_Buildable, Gtk_Radio_Button_Record, Gtk_Radio_Button); 
  384.    function "+" 
  385.      (Widget : access Gtk_Radio_Button_Record'Class) 
  386.    return Gtk.Buildable.Gtk_Buildable 
  387.    renames Implements_Gtk_Buildable.To_Interface; 
  388.    function "-" 
  389.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  390.    return Gtk_Radio_Button 
  391.    renames Implements_Gtk_Buildable.To_Object; 
  392.  
  393. private 
  394.    Group_Property : constant Glib.Properties.Property_Object := 
  395.      Glib.Properties.Build ("group"); 
  396. end Gtk.Radio_Button;