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. --  The Gtk.Color_Button.Gtk_Color_Button is a button which displays the 
  26. --  currently selected color an allows to open a color selection dialog to 
  27. --  change the color. It is suitable widget for selecting a color in a 
  28. --  preference dialog. 
  29. -- 
  30. --  </description> 
  31. --  <group>Buttons and Toggles</group> 
  32. pragma Ada_2005; 
  33.  
  34. pragma Warnings (Off, "*is already use-visible*"); 
  35. with Gdk.Color;         use Gdk.Color; 
  36. with Gdk.RGBA;          use Gdk.RGBA; 
  37. with Glib;              use Glib; 
  38. with Glib.Object;       use Glib.Object; 
  39. with Glib.Properties;   use Glib.Properties; 
  40. with Glib.Types;        use Glib.Types; 
  41. with Glib.Variant;      use Glib.Variant; 
  42. with Gtk.Action;        use Gtk.Action; 
  43. with Gtk.Actionable;    use Gtk.Actionable; 
  44. with Gtk.Activatable;   use Gtk.Activatable; 
  45. with Gtk.Buildable;     use Gtk.Buildable; 
  46. with Gtk.Button;        use Gtk.Button; 
  47. with Gtk.Color_Chooser; use Gtk.Color_Chooser; 
  48. with Gtk.Enums;         use Gtk.Enums; 
  49.  
  50. package Gtk.Color_Button is 
  51.  
  52.    type Gtk_Color_Button_Record is new Gtk_Button_Record with null record; 
  53.    type Gtk_Color_Button is access all Gtk_Color_Button_Record'Class; 
  54.  
  55.    ------------------ 
  56.    -- Constructors -- 
  57.    ------------------ 
  58.  
  59.    procedure Gtk_New (Button : out Gtk_Color_Button); 
  60.    procedure Initialize 
  61.       (Button : not null access Gtk_Color_Button_Record'Class); 
  62.    --  Creates a new color button. 
  63.    --  This returns a widget in the form of a small button containing a swatch 
  64.    --  representing the current selected color. When the button is clicked, a 
  65.    --  color-selection dialog will open, allowing the user to select a color. 
  66.    --  The swatch will be updated to reflect the new color when the user 
  67.    --  finishes. 
  68.    --  Since: gtk+ 2.4 
  69.  
  70.    function Gtk_Color_Button_New return Gtk_Color_Button; 
  71.    --  Creates a new color button. 
  72.    --  This returns a widget in the form of a small button containing a swatch 
  73.    --  representing the current selected color. When the button is clicked, a 
  74.    --  color-selection dialog will open, allowing the user to select a color. 
  75.    --  The swatch will be updated to reflect the new color when the user 
  76.    --  finishes. 
  77.    --  Since: gtk+ 2.4 
  78.  
  79.    procedure Gtk_New_With_Color 
  80.       (Button : out Gtk_Color_Button; 
  81.        Color  : Gdk.Color.Gdk_Color); 
  82.    procedure Initialize_With_Color 
  83.       (Button : not null access Gtk_Color_Button_Record'Class; 
  84.        Color  : Gdk.Color.Gdk_Color); 
  85.    --  Creates a new color button. 
  86.    --  Since: gtk+ 2.4 
  87.    --  "color": A Gdk.Color.Gdk_Color to set the current color with 
  88.  
  89.    function Gtk_Color_Button_New_With_Color 
  90.       (Color : Gdk.Color.Gdk_Color) return Gtk_Color_Button; 
  91.    --  Creates a new color button. 
  92.    --  Since: gtk+ 2.4 
  93.    --  "color": A Gdk.Color.Gdk_Color to set the current color with 
  94.  
  95.    procedure Gtk_New_With_Rgba 
  96.       (Button : out Gtk_Color_Button; 
  97.        Rgba   : Gdk.RGBA.Gdk_RGBA); 
  98.    procedure Initialize_With_Rgba 
  99.       (Button : not null access Gtk_Color_Button_Record'Class; 
  100.        Rgba   : Gdk.RGBA.Gdk_RGBA); 
  101.    --  Creates a new color button. 
  102.    --  Since: gtk+ 3.0 
  103.    --  "rgba": A Gdk.RGBA.Gdk_RGBA to set the current color with 
  104.  
  105.    function Gtk_Color_Button_New_With_Rgba 
  106.       (Rgba : Gdk.RGBA.Gdk_RGBA) return Gtk_Color_Button; 
  107.    --  Creates a new color button. 
  108.    --  Since: gtk+ 3.0 
  109.    --  "rgba": A Gdk.RGBA.Gdk_RGBA to set the current color with 
  110.  
  111.    function Get_Type return Glib.GType; 
  112.    pragma Import (C, Get_Type, "gtk_color_button_get_type"); 
  113.  
  114.    ------------- 
  115.    -- Methods -- 
  116.    ------------- 
  117.  
  118.    function Get_Alpha 
  119.       (Button : not null access Gtk_Color_Button_Record) return Guint16; 
  120.    pragma Obsolescent (Get_Alpha); 
  121.    --  Returns the current alpha value. 
  122.    --  Since: gtk+ 2.4 
  123.    --  Deprecated since 3.4, Use Gtk.Color_Chooser.Get_Rgba instead. 
  124.  
  125.    procedure Set_Alpha 
  126.       (Button : not null access Gtk_Color_Button_Record; 
  127.        Alpha  : Guint16); 
  128.    pragma Obsolescent (Set_Alpha); 
  129.    --  Sets the current opacity to be Alpha. 
  130.    --  Since: gtk+ 2.4 
  131.    --  Deprecated since 3.4, Use Gtk.Color_Chooser.Set_Rgba instead. 
  132.    --  "alpha": an integer between 0 and 65535 
  133.  
  134.    procedure Get_Color 
  135.       (Button : not null access Gtk_Color_Button_Record; 
  136.        Color  : out Gdk.Color.Gdk_Color); 
  137.    pragma Obsolescent (Get_Color); 
  138.    --  Sets Color to be the current color in the 
  139.    --  Gtk.Color_Button.Gtk_Color_Button widget. 
  140.    --  Since: gtk+ 2.4 
  141.    --  Deprecated since 3.4, Use Gtk.Color_Chooser.Get_Rgba instead. 
  142.    --  "color": a Gdk.Color.Gdk_Color to fill in with the current color 
  143.  
  144.    procedure Set_Color 
  145.       (Button : not null access Gtk_Color_Button_Record; 
  146.        Color  : Gdk.Color.Gdk_Color); 
  147.    pragma Obsolescent (Set_Color); 
  148.    --  Sets the current color to be Color. 
  149.    --  Since: gtk+ 2.4 
  150.    --  Deprecated since None, Use Gtk.Color_Chooser.Set_Rgba instead. 
  151.    --  "color": A Gdk.Color.Gdk_Color to set the current color with 
  152.  
  153.    function Get_Title 
  154.       (Button : not null access Gtk_Color_Button_Record) return UTF8_String; 
  155.    --  Gets the title of the color selection dialog. 
  156.    --  Since: gtk+ 2.4 
  157.  
  158.    procedure Set_Title 
  159.       (Button : not null access Gtk_Color_Button_Record; 
  160.        Title  : UTF8_String); 
  161.    --  Sets the title for the color selection dialog. 
  162.    --  Since: gtk+ 2.4 
  163.    --  "title": String containing new window title 
  164.  
  165.    --------------------------------------------- 
  166.    -- Inherited subprograms (from interfaces) -- 
  167.    --------------------------------------------- 
  168.    --  Methods inherited from the Buildable interface are not duplicated here 
  169.    --  since they are meant to be used by tools, mostly. If you need to call 
  170.    --  them, use an explicit cast through the "-" operator below. 
  171.  
  172.    function Get_Action_Name 
  173.       (Self : not null access Gtk_Color_Button_Record) return UTF8_String; 
  174.  
  175.    procedure Set_Action_Name 
  176.       (Self        : not null access Gtk_Color_Button_Record; 
  177.        Action_Name : UTF8_String); 
  178.  
  179.    function Get_Action_Target_Value 
  180.       (Self : not null access Gtk_Color_Button_Record) 
  181.        return Glib.Variant.Gvariant; 
  182.  
  183.    procedure Set_Action_Target_Value 
  184.       (Self         : not null access Gtk_Color_Button_Record; 
  185.        Target_Value : Glib.Variant.Gvariant); 
  186.  
  187.    procedure Set_Detailed_Action_Name 
  188.       (Self                 : not null access Gtk_Color_Button_Record; 
  189.        Detailed_Action_Name : UTF8_String); 
  190.  
  191.    procedure Do_Set_Related_Action 
  192.       (Self   : not null access Gtk_Color_Button_Record; 
  193.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  194.  
  195.    function Get_Related_Action 
  196.       (Self : not null access Gtk_Color_Button_Record) 
  197.        return Gtk.Action.Gtk_Action; 
  198.  
  199.    procedure Set_Related_Action 
  200.       (Self   : not null access Gtk_Color_Button_Record; 
  201.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  202.  
  203.    function Get_Use_Action_Appearance 
  204.       (Self : not null access Gtk_Color_Button_Record) return Boolean; 
  205.  
  206.    procedure Set_Use_Action_Appearance 
  207.       (Self           : not null access Gtk_Color_Button_Record; 
  208.        Use_Appearance : Boolean); 
  209.  
  210.    procedure Sync_Action_Properties 
  211.       (Self   : not null access Gtk_Color_Button_Record; 
  212.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  213.  
  214.    procedure Add_Palette 
  215.       (Self            : not null access Gtk_Color_Button_Record; 
  216.        Orientation     : Gtk.Enums.Gtk_Orientation; 
  217.        Colors_Per_Line : Gint; 
  218.        N_Colors        : Gint; 
  219.        Colors          : array_of_Gdk_RGBA); 
  220.  
  221.    procedure Get_Rgba 
  222.       (Self  : not null access Gtk_Color_Button_Record; 
  223.        Color : out Gdk.RGBA.Gdk_RGBA); 
  224.  
  225.    procedure Set_Rgba 
  226.       (Self  : not null access Gtk_Color_Button_Record; 
  227.        Color : Gdk.RGBA.Gdk_RGBA); 
  228.  
  229.    function Get_Use_Alpha 
  230.       (Self : not null access Gtk_Color_Button_Record) return Boolean; 
  231.  
  232.    procedure Set_Use_Alpha 
  233.       (Self      : not null access Gtk_Color_Button_Record; 
  234.        Use_Alpha : Boolean); 
  235.  
  236.    ---------------- 
  237.    -- Properties -- 
  238.    ---------------- 
  239.    --  The following properties are defined for this widget. See 
  240.    --  Glib.Properties for more information on properties) 
  241.  
  242.    Alpha_Property : constant Glib.Properties.Property_Uint; 
  243.    --  The selected opacity value (0 fully transparent, 65535 fully opaque). 
  244.  
  245.    Color_Property : constant Gdk.Color.Property_Gdk_Color; 
  246.    --  Type: Gdk.Color.Gdk_Color 
  247.    --  The selected color. 
  248.  
  249.    Rgba_Property : constant Gdk.RGBA.Property_RGBA; 
  250.    --  Type: Gdk.RGBA.Gdk_RGBA 
  251.    --  The RGBA color. 
  252.  
  253.    Title_Property : constant Glib.Properties.Property_String; 
  254.    --  The title of the color selection dialog 
  255.  
  256.    Use_Alpha_Property : constant Glib.Properties.Property_Boolean; 
  257.    --  If this property is set to True, the color swatch on the button is 
  258.    --  rendered against a checkerboard background to show its opacity and the 
  259.    --  opacity slider is displayed in the color selection dialog. 
  260.  
  261.    ------------- 
  262.    -- Signals -- 
  263.    ------------- 
  264.  
  265.    type Cb_Gtk_Color_Button_Void is not null access procedure 
  266.      (Self : access Gtk_Color_Button_Record'Class); 
  267.  
  268.    type Cb_GObject_Void is not null access procedure 
  269.      (Self : access Glib.Object.GObject_Record'Class); 
  270.  
  271.    Signal_Color_Set : constant Glib.Signal_Name := "color-set"; 
  272.    procedure On_Color_Set 
  273.       (Self  : not null access Gtk_Color_Button_Record; 
  274.        Call  : Cb_Gtk_Color_Button_Void; 
  275.        After : Boolean := False); 
  276.    procedure On_Color_Set 
  277.       (Self  : not null access Gtk_Color_Button_Record; 
  278.        Call  : Cb_GObject_Void; 
  279.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  280.        After : Boolean := False); 
  281.    --  The ::color-set signal is emitted when the user selects a color. When 
  282.    --  handling this signal, use gtk_color_button_get_rgba to find out which 
  283.    --  color was just selected. 
  284.    -- 
  285.    --  Note that this signal is only emitted when the *user* changes the 
  286.    --  color. If you need to react to programmatic color changes as well, use 
  287.    --  the notify::color signal. 
  288.  
  289.    ---------------- 
  290.    -- Interfaces -- 
  291.    ---------------- 
  292.    --  This class implements several interfaces. See Glib.Types 
  293.    -- 
  294.    --  - "Actionable" 
  295.    -- 
  296.    --  - "Activatable" 
  297.    -- 
  298.    --  - "Buildable" 
  299.    -- 
  300.    --  - "ColorChooser" 
  301.  
  302.    package Implements_Gtk_Actionable is new Glib.Types.Implements 
  303.      (Gtk.Actionable.Gtk_Actionable, Gtk_Color_Button_Record, Gtk_Color_Button); 
  304.    function "+" 
  305.      (Widget : access Gtk_Color_Button_Record'Class) 
  306.    return Gtk.Actionable.Gtk_Actionable 
  307.    renames Implements_Gtk_Actionable.To_Interface; 
  308.    function "-" 
  309.      (Interf : Gtk.Actionable.Gtk_Actionable) 
  310.    return Gtk_Color_Button 
  311.    renames Implements_Gtk_Actionable.To_Object; 
  312.  
  313.    package Implements_Gtk_Activatable is new Glib.Types.Implements 
  314.      (Gtk.Activatable.Gtk_Activatable, Gtk_Color_Button_Record, Gtk_Color_Button); 
  315.    function "+" 
  316.      (Widget : access Gtk_Color_Button_Record'Class) 
  317.    return Gtk.Activatable.Gtk_Activatable 
  318.    renames Implements_Gtk_Activatable.To_Interface; 
  319.    function "-" 
  320.      (Interf : Gtk.Activatable.Gtk_Activatable) 
  321.    return Gtk_Color_Button 
  322.    renames Implements_Gtk_Activatable.To_Object; 
  323.  
  324.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  325.      (Gtk.Buildable.Gtk_Buildable, Gtk_Color_Button_Record, Gtk_Color_Button); 
  326.    function "+" 
  327.      (Widget : access Gtk_Color_Button_Record'Class) 
  328.    return Gtk.Buildable.Gtk_Buildable 
  329.    renames Implements_Gtk_Buildable.To_Interface; 
  330.    function "-" 
  331.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  332.    return Gtk_Color_Button 
  333.    renames Implements_Gtk_Buildable.To_Object; 
  334.  
  335.    package Implements_Gtk_Color_Chooser is new Glib.Types.Implements 
  336.      (Gtk.Color_Chooser.Gtk_Color_Chooser, Gtk_Color_Button_Record, Gtk_Color_Button); 
  337.    function "+" 
  338.      (Widget : access Gtk_Color_Button_Record'Class) 
  339.    return Gtk.Color_Chooser.Gtk_Color_Chooser 
  340.    renames Implements_Gtk_Color_Chooser.To_Interface; 
  341.    function "-" 
  342.      (Interf : Gtk.Color_Chooser.Gtk_Color_Chooser) 
  343.    return Gtk_Color_Button 
  344.    renames Implements_Gtk_Color_Chooser.To_Object; 
  345.  
  346. private 
  347.    Use_Alpha_Property : constant Glib.Properties.Property_Boolean := 
  348.      Glib.Properties.Build ("use-alpha"); 
  349.    Title_Property : constant Glib.Properties.Property_String := 
  350.      Glib.Properties.Build ("title"); 
  351.    Rgba_Property : constant Gdk.RGBA.Property_RGBA := 
  352.      Gdk.RGBA.Build ("rgba"); 
  353.    Color_Property : constant Gdk.Color.Property_Gdk_Color := 
  354.      Gdk.Color.Build ("color"); 
  355.    Alpha_Property : constant Glib.Properties.Property_Uint := 
  356.      Glib.Properties.Build ("alpha"); 
  357. end Gtk.Color_Button;