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 Gtk.Toggle_Button.Gtk_Toggle_Button is a Gtk.Button.Gtk_Button which 
  26. --  will remain 'pressed-in' when clicked. Clicking again will cause the toggle 
  27. --  button to return to its normal state. 
  28. -- 
  29. --  A toggle button is created by calling either gtk_toggle_button_new or 
  30. --  Gtk.Toggle_Button.Gtk_New. If using the former, it is advisable to pack a 
  31. --  widget, (such as a Gtk.Label.Gtk_Label and/or a Gtk.Image.Gtk_Image), into 
  32. --  the toggle button's container. (See Gtk.Button.Gtk_Button for more 
  33. --  information). 
  34. -- 
  35. --  The state of a Gtk.Toggle_Button.Gtk_Toggle_Button can be set specifically 
  36. --  using Gtk.Toggle_Button.Set_Active, and retrieved using 
  37. --  Gtk.Toggle_Button.Get_Active. 
  38. -- 
  39. --  To simply switch the state of a toggle button, use 
  40. --  Gtk.Toggle_Button.Toggled. 
  41. -- 
  42. --  == Creating two Gtk.Toggle_Button.Gtk_Toggle_Button widgets. == 
  43. -- 
  44. --    void make_toggles (void) { 
  45. --       GtkWidget *dialog, *toggle1, *toggle2; 
  46. --       dialog = gtk_dialog_new (<!-- -->); 
  47. --          toggle1 = gtk_toggle_button_new_with_label ("Hi, i'm a toggle button."); 
  48. --          // Makes this toggle button invisible 
  49. --          gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1), TRUE); 
  50. --             g_signal_connect (toggle1, "toggled", 
  51. --             G_CALLBACK (output_state), NULL); 
  52. --             gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), 
  53. --             toggle1, FALSE, FALSE, 2); 
  54. --          toggle2 = gtk_toggle_button_new_with_label ("Hi, i'm another toggle button."); 
  55. --          gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2), FALSE); 
  56. --             g_signal_connect (toggle2, "toggled", 
  57. --             G_CALLBACK (output_state), NULL); 
  58. --             gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), 
  59. --             toggle2, FALSE, FALSE, 2); 
  60. --          gtk_widget_show_all (dialog); 
  61. --       } 
  62. -- 
  63. -- 
  64. --  </description> 
  65. --  <description> 
  66. --  You should consider using a Gtk_Check_Button instead, since it looks nicer 
  67. --  and provides more visual clues that the button can be toggled. 
  68. -- 
  69. --  </description> 
  70. --  <screenshot>gtk-toggle_button</screenshot> 
  71. --  <group>Buttons and Toggles</group> 
  72. --  <testgtk>create_toggle_buttons.adb</testgtk> 
  73. pragma Ada_2005; 
  74.  
  75. pragma Warnings (Off, "*is already use-visible*"); 
  76. with Glib;            use Glib; 
  77. with Glib.Object;     use Glib.Object; 
  78. with Glib.Properties; use Glib.Properties; 
  79. with Glib.Types;      use Glib.Types; 
  80. with Glib.Variant;    use Glib.Variant; 
  81. with Gtk.Action;      use Gtk.Action; 
  82. with Gtk.Actionable;  use Gtk.Actionable; 
  83. with Gtk.Activatable; use Gtk.Activatable; 
  84. with Gtk.Buildable;   use Gtk.Buildable; 
  85. with Gtk.Button;      use Gtk.Button; 
  86.  
  87. package Gtk.Toggle_Button is 
  88.  
  89.    type Gtk_Toggle_Button_Record is new Gtk_Button_Record with null record; 
  90.    type Gtk_Toggle_Button is access all Gtk_Toggle_Button_Record'Class; 
  91.  
  92.    ------------------ 
  93.    -- Constructors -- 
  94.    ------------------ 
  95.  
  96.    procedure Gtk_New 
  97.       (Toggle_Button : out Gtk_Toggle_Button; 
  98.        Label         : UTF8_String := ""); 
  99.    procedure Initialize 
  100.       (Toggle_Button : not null access Gtk_Toggle_Button_Record'Class; 
  101.        Label         : UTF8_String := ""); 
  102.    --  Initialize a button. If Label is "", then no label is created inside 
  103.    --  the button and you will have to provide your own child through a call to 
  104.    --  Gtk.Container.Add. This is the recommended way to put a pixmap inside a 
  105.    --  toggle button. 
  106.    --  "label": a string containing the message to be placed in the toggle 
  107.    --  button. 
  108.  
  109.    function Gtk_Toggle_Button_New_With_Label 
  110.       (Label : UTF8_String := "") return Gtk_Toggle_Button; 
  111.    --  Initialize a button. If Label is "", then no label is created inside 
  112.    --  the button and you will have to provide your own child through a call to 
  113.    --  Gtk.Container.Add. This is the recommended way to put a pixmap inside a 
  114.    --  toggle button. 
  115.    --  "label": a string containing the message to be placed in the toggle 
  116.    --  button. 
  117.  
  118.    procedure Gtk_New_With_Mnemonic 
  119.       (Toggle_Button : out Gtk_Toggle_Button; 
  120.        Label         : UTF8_String); 
  121.    procedure Initialize_With_Mnemonic 
  122.       (Toggle_Button : not null access Gtk_Toggle_Button_Record'Class; 
  123.        Label         : UTF8_String); 
  124.    --  Creates a new Gtk.Toggle_Button.Gtk_Toggle_Button containing a label. 
  125.    --  The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so 
  126.    --  underscores in Label indicate the mnemonic for the button. 
  127.    --  "label": the text of the button, with an underscore in front of the 
  128.    --  mnemonic character 
  129.  
  130.    function Gtk_Toggle_Button_New_With_Mnemonic 
  131.       (Label : UTF8_String) return Gtk_Toggle_Button; 
  132.    --  Creates a new Gtk.Toggle_Button.Gtk_Toggle_Button containing a label. 
  133.    --  The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so 
  134.    --  underscores in Label indicate the mnemonic for the button. 
  135.    --  "label": the text of the button, with an underscore in front of the 
  136.    --  mnemonic character 
  137.  
  138.    function Get_Type return Glib.GType; 
  139.    pragma Import (C, Get_Type, "gtk_toggle_button_get_type"); 
  140.  
  141.    ------------- 
  142.    -- Methods -- 
  143.    ------------- 
  144.  
  145.    function Get_Active 
  146.       (Toggle_Button : not null access Gtk_Toggle_Button_Record) 
  147.        return Boolean; 
  148.    --  Queries a Gtk.Toggle_Button.Gtk_Toggle_Button and returns its current 
  149.    --  state. Returns True if the toggle button is pressed in and False if it 
  150.    --  is raised. 
  151.  
  152.    procedure Set_Active 
  153.       (Toggle_Button : not null access Gtk_Toggle_Button_Record; 
  154.        Is_Active     : Boolean); 
  155.    --  Change the state of the button. When Is_Active is True, the button is 
  156.    --  drawn as a pressed button 
  157.    --  "is_active": True or False. 
  158.  
  159.    function Get_Inconsistent 
  160.       (Toggle_Button : not null access Gtk_Toggle_Button_Record) 
  161.        return Boolean; 
  162.    --  Gets the value set by Gtk.Toggle_Button.Set_Inconsistent. 
  163.  
  164.    procedure Set_Inconsistent 
  165.       (Toggle_Button : not null access Gtk_Toggle_Button_Record; 
  166.        Setting       : Boolean := True); 
  167.    --  If the user has selected a range of elements (such as some text or 
  168.    --  spreadsheet cells) that are affected by a toggle button, and the current 
  169.    --  values in that range are inconsistent, you may want to display the 
  170.    --  toggle in an "in between" state. This function turns on "in between" 
  171.    --  display. Normally you would turn off the inconsistent state again if the 
  172.    --  user toggles the toggle button. This has to be done manually, 
  173.    --  Gtk.Toggle_Button.Set_Inconsistent only affects visual appearance, it 
  174.    --  doesn't affect the semantics of the button. 
  175.    --  "setting": True if state is inconsistent 
  176.  
  177.    function Get_Mode 
  178.       (Toggle_Button : not null access Gtk_Toggle_Button_Record) 
  179.        return Boolean; 
  180.    --  Retrieves whether the button is displayed as a separate indicator and 
  181.    --  label. See Gtk.Toggle_Button.Set_Mode. 
  182.  
  183.    procedure Set_Mode 
  184.       (Toggle_Button  : not null access Gtk_Toggle_Button_Record; 
  185.        Draw_Indicator : Boolean); 
  186.    --  Sets whether the button is displayed as a separate indicator and label. 
  187.    --  You can call this function on a checkbutton or a radiobutton with 
  188.    --  Draw_Indicator = False to make the button look like a normal button 
  189.    --  This function only affects instances of classes like 
  190.    --  Gtk.Check_Button.Gtk_Check_Button and Gtk.Radio_Button.Gtk_Radio_Button 
  191.    --  that derive from Gtk.Toggle_Button.Gtk_Toggle_Button, not instances of 
  192.    --  Gtk.Toggle_Button.Gtk_Toggle_Button itself. 
  193.    --  "draw_indicator": if True, draw the button as a separate indicator and 
  194.    --  label; if False, draw the button like a normal button 
  195.  
  196.    procedure Toggled 
  197.       (Toggle_Button : not null access Gtk_Toggle_Button_Record); 
  198.    --  Emits the Gtk.Toggle_Button.Gtk_Toggle_Button::toggled signal on the 
  199.    --  Gtk.Toggle_Button.Gtk_Toggle_Button. There is no good reason for an 
  200.    --  application ever to call this function. 
  201.  
  202.    --------------------------------------------- 
  203.    -- Inherited subprograms (from interfaces) -- 
  204.    --------------------------------------------- 
  205.    --  Methods inherited from the Buildable interface are not duplicated here 
  206.    --  since they are meant to be used by tools, mostly. If you need to call 
  207.    --  them, use an explicit cast through the "-" operator below. 
  208.  
  209.    function Get_Action_Name 
  210.       (Self : not null access Gtk_Toggle_Button_Record) return UTF8_String; 
  211.  
  212.    procedure Set_Action_Name 
  213.       (Self        : not null access Gtk_Toggle_Button_Record; 
  214.        Action_Name : UTF8_String); 
  215.  
  216.    function Get_Action_Target_Value 
  217.       (Self : not null access Gtk_Toggle_Button_Record) 
  218.        return Glib.Variant.Gvariant; 
  219.  
  220.    procedure Set_Action_Target_Value 
  221.       (Self         : not null access Gtk_Toggle_Button_Record; 
  222.        Target_Value : Glib.Variant.Gvariant); 
  223.  
  224.    procedure Set_Detailed_Action_Name 
  225.       (Self                 : not null access Gtk_Toggle_Button_Record; 
  226.        Detailed_Action_Name : UTF8_String); 
  227.  
  228.    procedure Do_Set_Related_Action 
  229.       (Self   : not null access Gtk_Toggle_Button_Record; 
  230.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  231.  
  232.    function Get_Related_Action 
  233.       (Self : not null access Gtk_Toggle_Button_Record) 
  234.        return Gtk.Action.Gtk_Action; 
  235.  
  236.    procedure Set_Related_Action 
  237.       (Self   : not null access Gtk_Toggle_Button_Record; 
  238.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  239.  
  240.    function Get_Use_Action_Appearance 
  241.       (Self : not null access Gtk_Toggle_Button_Record) return Boolean; 
  242.  
  243.    procedure Set_Use_Action_Appearance 
  244.       (Self           : not null access Gtk_Toggle_Button_Record; 
  245.        Use_Appearance : Boolean); 
  246.  
  247.    procedure Sync_Action_Properties 
  248.       (Self   : not null access Gtk_Toggle_Button_Record; 
  249.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  250.  
  251.    ---------------- 
  252.    -- Properties -- 
  253.    ---------------- 
  254.    --  The following properties are defined for this widget. See 
  255.    --  Glib.Properties for more information on properties) 
  256.  
  257.    Active_Property : constant Glib.Properties.Property_Boolean; 
  258.  
  259.    Draw_Indicator_Property : constant Glib.Properties.Property_Boolean; 
  260.  
  261.    Inconsistent_Property : constant Glib.Properties.Property_Boolean; 
  262.  
  263.    ------------- 
  264.    -- Signals -- 
  265.    ------------- 
  266.  
  267.    type Cb_Gtk_Toggle_Button_Void is not null access procedure 
  268.      (Self : access Gtk_Toggle_Button_Record'Class); 
  269.  
  270.    type Cb_GObject_Void is not null access procedure 
  271.      (Self : access Glib.Object.GObject_Record'Class); 
  272.  
  273.    Signal_Toggled : constant Glib.Signal_Name := "toggled"; 
  274.    procedure On_Toggled 
  275.       (Self  : not null access Gtk_Toggle_Button_Record; 
  276.        Call  : Cb_Gtk_Toggle_Button_Void; 
  277.        After : Boolean := False); 
  278.    procedure On_Toggled 
  279.       (Self  : not null access Gtk_Toggle_Button_Record; 
  280.        Call  : Cb_GObject_Void; 
  281.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  282.        After : Boolean := False); 
  283.    --  Should be connected if you wish to perform an action whenever the 
  284.    --  Gtk.Toggle_Button.Gtk_Toggle_Button's state is changed. 
  285.  
  286.    ---------------- 
  287.    -- Interfaces -- 
  288.    ---------------- 
  289.    --  This class implements several interfaces. See Glib.Types 
  290.    -- 
  291.    --  - "Actionable" 
  292.    -- 
  293.    --  - "Activatable" 
  294.    -- 
  295.    --  - "Buildable" 
  296.  
  297.    package Implements_Gtk_Actionable is new Glib.Types.Implements 
  298.      (Gtk.Actionable.Gtk_Actionable, Gtk_Toggle_Button_Record, Gtk_Toggle_Button); 
  299.    function "+" 
  300.      (Widget : access Gtk_Toggle_Button_Record'Class) 
  301.    return Gtk.Actionable.Gtk_Actionable 
  302.    renames Implements_Gtk_Actionable.To_Interface; 
  303.    function "-" 
  304.      (Interf : Gtk.Actionable.Gtk_Actionable) 
  305.    return Gtk_Toggle_Button 
  306.    renames Implements_Gtk_Actionable.To_Object; 
  307.  
  308.    package Implements_Gtk_Activatable is new Glib.Types.Implements 
  309.      (Gtk.Activatable.Gtk_Activatable, Gtk_Toggle_Button_Record, Gtk_Toggle_Button); 
  310.    function "+" 
  311.      (Widget : access Gtk_Toggle_Button_Record'Class) 
  312.    return Gtk.Activatable.Gtk_Activatable 
  313.    renames Implements_Gtk_Activatable.To_Interface; 
  314.    function "-" 
  315.      (Interf : Gtk.Activatable.Gtk_Activatable) 
  316.    return Gtk_Toggle_Button 
  317.    renames Implements_Gtk_Activatable.To_Object; 
  318.  
  319.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  320.      (Gtk.Buildable.Gtk_Buildable, Gtk_Toggle_Button_Record, Gtk_Toggle_Button); 
  321.    function "+" 
  322.      (Widget : access Gtk_Toggle_Button_Record'Class) 
  323.    return Gtk.Buildable.Gtk_Buildable 
  324.    renames Implements_Gtk_Buildable.To_Interface; 
  325.    function "-" 
  326.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  327.    return Gtk_Toggle_Button 
  328.    renames Implements_Gtk_Buildable.To_Object; 
  329.  
  330. private 
  331.    Inconsistent_Property : constant Glib.Properties.Property_Boolean := 
  332.      Glib.Properties.Build ("inconsistent"); 
  333.    Draw_Indicator_Property : constant Glib.Properties.Property_Boolean := 
  334.      Glib.Properties.Build ("draw-indicator"); 
  335.    Active_Property : constant Glib.Properties.Property_Boolean := 
  336.      Glib.Properties.Build ("active"); 
  337. end Gtk.Toggle_Button;