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