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-2011, 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. --  A Gtk_Toggle_Button is like a regular button, but can be in one of two 
  27. --  states, "active" or "inactive". Its visual aspect is modified when the 
  28. --  state is changed. 
  29. -- 
  30. --  You should consider using a Gtk_Check_Button instead, since it looks nicer 
  31. --  and provides more visual clues that the button can be toggled. 
  32. -- 
  33. --  </description> 
  34. --  <screenshot>gtk-toggle_button</screenshot> 
  35. --  <group>Buttons and Toggles</group> 
  36. --  <testgtk>create_toggle_buttons.adb</testgtk> 
  37.  
  38. pragma Warnings (Off, "*is already use-visible*"); 
  39. with Glib;            use Glib; 
  40. with Glib.Properties; use Glib.Properties; 
  41. with Glib.Types;      use Glib.Types; 
  42. with Gtk.Action;      use Gtk.Action; 
  43. with Gtk.Activatable; use Gtk.Activatable; 
  44. with Gtk.Buildable;   use Gtk.Buildable; 
  45. with Gtk.Button;      use Gtk.Button; 
  46. with Gtk.Widget;      use Gtk.Widget; 
  47.  
  48. package Gtk.Toggle_Button is 
  49.  
  50.    type Gtk_Toggle_Button_Record is new Gtk_Button_Record with null record; 
  51.    type Gtk_Toggle_Button is access all Gtk_Toggle_Button_Record'Class; 
  52.  
  53.    ------------------ 
  54.    -- Constructors -- 
  55.    ------------------ 
  56.  
  57.    procedure Gtk_New 
  58.       (Toggle_Button : out Gtk_Toggle_Button; 
  59.        Label         : UTF8_String := ""); 
  60.    procedure Initialize 
  61.       (Toggle_Button : access Gtk_Toggle_Button_Record'Class; 
  62.        Label         : UTF8_String := ""); 
  63.    --  Initialize a button. If Label is "", then no label is created inside 
  64.    --  the button and you will have to provide your own child through a call to 
  65.    --  Gtk.Container.Add. This is the recommended way to put a pixmap inside a 
  66.    --  toggle button. 
  67.  
  68.    procedure Gtk_New_With_Mnemonic 
  69.       (Toggle_Button : out Gtk_Toggle_Button; 
  70.        Label         : UTF8_String); 
  71.    procedure Initialize_With_Mnemonic 
  72.       (Toggle_Button : access Gtk_Toggle_Button_Record'Class; 
  73.        Label         : UTF8_String); 
  74.    --  Creates a new Gtk.Toggle_Button.Gtk_Toggle_Button containing a label. 
  75.    --  The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so 
  76.    --  underscores in Label indicate the mnemonic for the button. 
  77.    --  "label": the text of the button, with an underscore in front of the 
  78.    --  mnemonic character 
  79.  
  80.    function Get_Type return Glib.GType; 
  81.    pragma Import (C, Get_Type, "gtk_toggle_button_get_type"); 
  82.  
  83.    ------------- 
  84.    -- Methods -- 
  85.    ------------- 
  86.  
  87.    function Get_Active 
  88.       (Toggle_Button : access Gtk_Toggle_Button_Record) return Boolean; 
  89.    procedure Set_Active 
  90.       (Toggle_Button : access Gtk_Toggle_Button_Record; 
  91.        Is_Active     : Boolean); 
  92.    --  Change the state of the button. When Is_Active is True, the button is 
  93.    --  drawn as a pressed button 
  94.  
  95.    function Get_Inconsistent 
  96.       (Toggle_Button : access Gtk_Toggle_Button_Record) return Boolean; 
  97.    procedure Set_Inconsistent 
  98.       (Toggle_Button : access Gtk_Toggle_Button_Record; 
  99.        Setting       : Boolean := True); 
  100.    --  If the user has selected a range of elements (such as some text or 
  101.    --  spreadsheet cells) that are affected by a toggle button, and the current 
  102.    --  values in that range are inconsistent, you may want to display the 
  103.    --  toggle in an "in between" state. This function turns on "in between" 
  104.    --  display. Normally you would turn off the inconsistent state again if the 
  105.    --  user toggles the toggle button. This has to be done manually, 
  106.    --  Gtk.Toggle_Button.Set_Inconsistent only affects visual appearance, it 
  107.    --  doesn't affect the semantics of the button. 
  108.    --  "setting": True if state is inconsistent 
  109.  
  110.    function Get_Mode 
  111.       (Toggle_Button : access Gtk_Toggle_Button_Record) return Boolean; 
  112.    procedure Set_Mode 
  113.       (Toggle_Button  : access Gtk_Toggle_Button_Record; 
  114.        Draw_Indicator : Boolean); 
  115.    --  Sets whether the button is displayed as a separate indicator and label. 
  116.    --  You can call this function on a checkbutton or a radiobutton with This 
  117.    --  function only affects instances of classes like 
  118.    --  Gtk.Check_Button.Gtk_Check_Button and Gtk.Radio_Button.Gtk_Radio_Button 
  119.    --  that derive from Gtk.Toggle_Button.Gtk_Toggle_Button, not instances of 
  120.    --  Gtk.Toggle_Button.Gtk_Toggle_Button itself. 
  121.    --  "draw_indicator": if True, draw the button as a separate indicator and 
  122.    --  label; if False, draw the button like a normal button 
  123.  
  124.    procedure Toggled (Toggle_Button : access Gtk_Toggle_Button_Record); 
  125.  
  126.    --------------------- 
  127.    -- Interfaces_Impl -- 
  128.    --------------------- 
  129.  
  130.    procedure Do_Set_Related_Action 
  131.       (Self   : access Gtk_Toggle_Button_Record; 
  132.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  133.  
  134.    function Get_Related_Action 
  135.       (Self : access Gtk_Toggle_Button_Record) return Gtk.Action.Gtk_Action; 
  136.    procedure Set_Related_Action 
  137.       (Self   : access Gtk_Toggle_Button_Record; 
  138.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  139.  
  140.    function Get_Use_Action_Appearance 
  141.       (Self : access Gtk_Toggle_Button_Record) return Boolean; 
  142.    procedure Set_Use_Action_Appearance 
  143.       (Self           : access Gtk_Toggle_Button_Record; 
  144.        Use_Appearance : Boolean); 
  145.  
  146.    procedure Sync_Action_Properties 
  147.       (Self   : access Gtk_Toggle_Button_Record; 
  148.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  149.  
  150.    ---------------- 
  151.    -- Interfaces -- 
  152.    ---------------- 
  153.    --  This class implements several interfaces. See Glib.Types 
  154.    -- 
  155.    --  - "Activatable" 
  156.    -- 
  157.    --  - "Buildable" 
  158.  
  159.    package Implements_Activatable is new Glib.Types.Implements 
  160.      (Gtk.Activatable.Gtk_Activatable, Gtk_Toggle_Button_Record, Gtk_Toggle_Button); 
  161.    function "+" 
  162.      (Widget : access Gtk_Toggle_Button_Record'Class) 
  163.    return Gtk.Activatable.Gtk_Activatable 
  164.    renames Implements_Activatable.To_Interface; 
  165.    function "-" 
  166.      (Interf : Gtk.Activatable.Gtk_Activatable) 
  167.    return Gtk_Toggle_Button 
  168.    renames Implements_Activatable.To_Object; 
  169.  
  170.    package Implements_Buildable is new Glib.Types.Implements 
  171.      (Gtk.Buildable.Gtk_Buildable, Gtk_Toggle_Button_Record, Gtk_Toggle_Button); 
  172.    function "+" 
  173.      (Widget : access Gtk_Toggle_Button_Record'Class) 
  174.    return Gtk.Buildable.Gtk_Buildable 
  175.    renames Implements_Buildable.To_Interface; 
  176.    function "-" 
  177.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  178.    return Gtk_Toggle_Button 
  179.    renames Implements_Buildable.To_Object; 
  180.  
  181.    ---------------- 
  182.    -- Properties -- 
  183.    ---------------- 
  184.    --  The following properties are defined for this widget. See 
  185.    --  Glib.Properties for more information on properties) 
  186.    -- 
  187.    --  Name: Active_Property 
  188.    --  Type: Boolean 
  189.    --  Flags: read-write 
  190.    -- 
  191.    --  Name: Draw_Indicator_Property 
  192.    --  Type: Boolean 
  193.    --  Flags: read-write 
  194.    -- 
  195.    --  Name: Inconsistent_Property 
  196.    --  Type: Boolean 
  197.    --  Flags: read-write 
  198.  
  199.    Active_Property : constant Glib.Properties.Property_Boolean; 
  200.    Draw_Indicator_Property : constant Glib.Properties.Property_Boolean; 
  201.    Inconsistent_Property : constant Glib.Properties.Property_Boolean; 
  202.  
  203.    ------------- 
  204.    -- Signals -- 
  205.    ------------- 
  206.    --  The following new signals are defined for this widget: 
  207.    -- 
  208.    --  "toggled" 
  209.    --     procedure Handler (Self : access Gtk_Toggle_Button_Record'Class); 
  210.  
  211.    Signal_Toggled : constant Glib.Signal_Name := "toggled"; 
  212.  
  213. private 
  214.    Active_Property : constant Glib.Properties.Property_Boolean := 
  215.      Glib.Properties.Build ("active"); 
  216.    Draw_Indicator_Property : constant Glib.Properties.Property_Boolean := 
  217.      Glib.Properties.Build ("draw-indicator"); 
  218.    Inconsistent_Property : constant Glib.Properties.Property_Boolean := 
  219.      Glib.Properties.Build ("inconsistent"); 
  220. end Gtk.Toggle_Button;