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_Color_Selection widget is a complex dialog that allows the user to 
  26. --  select a color based either on its (Red, Green, Blue) or its (Hue, 
  27. --  Saturation, Value). An additional field is provided to select the opacity 
  28. --  of the color (this is usually called the alpha channel). 
  29. -- 
  30. --  See Gtk.Color_Selection_Dialog for a version of this widget that comes 
  31. --  with its own dialog. 
  32. -- 
  33. --  See Gtk.Extra.Color_Combo for a different way to select colors. 
  34. -- 
  35. --  </description> 
  36. --  <screenshot>gtk-colorsel</screenshot> 
  37. --  <group>Drawing</group> 
  38. --  <testgtk>create_color_selection.adb</testgtk> 
  39. pragma Ada_2005; 
  40.  
  41. pragma Warnings (Off, "*is already use-visible*"); 
  42. with Gdk.Color;       use Gdk.Color; 
  43. with Gdk.RGBA;        use Gdk.RGBA; 
  44. with Glib;            use Glib; 
  45. with Glib.Object;     use Glib.Object; 
  46. with Glib.Properties; use Glib.Properties; 
  47. with Glib.Types;      use Glib.Types; 
  48. with Gtk.Box;         use Gtk.Box; 
  49. with Gtk.Buildable;   use Gtk.Buildable; 
  50. with Gtk.Enums;       use Gtk.Enums; 
  51. with Gtk.Orientable;  use Gtk.Orientable; 
  52.  
  53. package Gtk.Color_Selection is 
  54.  
  55.    type Gtk_Color_Selection_Record is new Gtk_Box_Record with null record; 
  56.    type Gtk_Color_Selection is access all Gtk_Color_Selection_Record'Class; 
  57.  
  58.    ------------------ 
  59.    -- Constructors -- 
  60.    ------------------ 
  61.  
  62.    procedure Gtk_New (Colorsel : out Gtk_Color_Selection); 
  63.    procedure Initialize 
  64.       (Colorsel : not null access Gtk_Color_Selection_Record'Class); 
  65.    --  Creates a new GtkColorSelection. 
  66.  
  67.    function Gtk_Color_Selection_New return Gtk_Color_Selection; 
  68.    --  Creates a new GtkColorSelection. 
  69.  
  70.    function Get_Type return Glib.GType; 
  71.    pragma Import (C, Get_Type, "gtk_color_selection_get_type"); 
  72.  
  73.    ------------- 
  74.    -- Methods -- 
  75.    ------------- 
  76.  
  77.    function Get_Current_Alpha 
  78.       (Colorsel : not null access Gtk_Color_Selection_Record) return Guint16; 
  79.    --  Returns the current alpha value. 
  80.  
  81.    procedure Set_Current_Alpha 
  82.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  83.        Alpha    : Guint16); 
  84.    --  Sets the current opacity to be Alpha. 
  85.    --  The first time this is called, it will also set the original opacity to 
  86.    --  be Alpha too. 
  87.    --  "alpha": an integer between 0 and 65535 
  88.  
  89.    procedure Get_Current_Color 
  90.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  91.        Color    : out Gdk.Color.Gdk_Color); 
  92.    pragma Obsolescent (Get_Current_Color); 
  93.    --  Sets Color to be the current color in the GtkColorSelection widget. 
  94.    --  Deprecated since 3.4, Use Gtk.Color_Selection.Get_Current_Rgba instead. 
  95.    --  "color": a Gdk.Color.Gdk_Color to fill in with the current color 
  96.  
  97.    procedure Set_Current_Color 
  98.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  99.        Color    : Gdk.Color.Gdk_Color); 
  100.    pragma Obsolescent (Set_Current_Color); 
  101.    --  Sets the current color to be Color. 
  102.    --  The first time this is called, it will also set the original color to 
  103.    --  be Color too. 
  104.    --  Deprecated since 3.4, Use Gtk.Color_Selection.Set_Current_Rgba instead. 
  105.    --  "color": a Gdk.Color.Gdk_Color to set the current color with 
  106.  
  107.    procedure Get_Current_Rgba 
  108.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  109.        Rgba     : out Gdk.RGBA.Gdk_RGBA); 
  110.    --  Sets Rgba to be the current color in the GtkColorSelection widget. 
  111.    --  Since: gtk+ 3.0 
  112.    --  "rgba": a Gdk.RGBA.Gdk_RGBA to fill in with the current color 
  113.  
  114.    procedure Set_Current_Rgba 
  115.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  116.        Rgba     : Gdk.RGBA.Gdk_RGBA); 
  117.    --  Sets the current color to be Rgba. 
  118.    --  The first time this is called, it will also set the original color to 
  119.    --  be Rgba too. 
  120.    --  Since: gtk+ 3.0 
  121.    --  "rgba": A Gdk.RGBA.Gdk_RGBA to set the current color with 
  122.  
  123.    function Get_Has_Opacity_Control 
  124.       (Colorsel : not null access Gtk_Color_Selection_Record) return Boolean; 
  125.    --  Determines whether the colorsel has an opacity control. 
  126.  
  127.    procedure Set_Has_Opacity_Control 
  128.       (Colorsel    : not null access Gtk_Color_Selection_Record; 
  129.        Has_Opacity : Boolean); 
  130.    --  Sets the Colorsel to use or not use opacity. 
  131.    --  "has_opacity": True if Colorsel can set the opacity, False otherwise 
  132.  
  133.    function Get_Has_Palette 
  134.       (Colorsel : not null access Gtk_Color_Selection_Record) return Boolean; 
  135.    --  Determines whether the color selector has a color palette. 
  136.  
  137.    procedure Set_Has_Palette 
  138.       (Colorsel    : not null access Gtk_Color_Selection_Record; 
  139.        Has_Palette : Boolean); 
  140.    --  Shows and hides the palette based upon the value of Has_Palette. 
  141.    --  "has_palette": True if palette is to be visible, False otherwise 
  142.  
  143.    function Get_Previous_Alpha 
  144.       (Colorsel : not null access Gtk_Color_Selection_Record) return Guint16; 
  145.    --  Returns the previous alpha value. 
  146.  
  147.    procedure Set_Previous_Alpha 
  148.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  149.        Alpha    : Guint16); 
  150.    --  Sets the 'previous' alpha to be Alpha. 
  151.    --  This function should be called with some hesitations, as it might seem 
  152.    --  confusing to have that alpha change. 
  153.    --  "alpha": an integer between 0 and 65535 
  154.  
  155.    procedure Get_Previous_Color 
  156.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  157.        Color    : out Gdk.Color.Gdk_Color); 
  158.    pragma Obsolescent (Get_Previous_Color); 
  159.    --  Fills Color in with the original color value. 
  160.    --  Deprecated since 3.4, Use Gtk.Color_Selection.Get_Previous_Rgba 
  161.    --  instead. 
  162.    --  "color": a Gdk.Color.Gdk_Color to fill in with the original color value 
  163.  
  164.    procedure Set_Previous_Color 
  165.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  166.        Color    : Gdk.Color.Gdk_Color); 
  167.    pragma Obsolescent (Set_Previous_Color); 
  168.    --  Sets the 'previous' color to be Color. 
  169.    --  This function should be called with some hesitations, as it might seem 
  170.    --  confusing to have that color change. Calling 
  171.    --  Gtk.Color_Selection.Set_Current_Color will also set this color the first 
  172.    --  time it is called. 
  173.    --  Deprecated since 3.4, Use Gtk.Color_Selection.Set_Previous_Rgba 
  174.    --  instead. 
  175.    --  "color": a Gdk.Color.Gdk_Color to set the previous color with 
  176.  
  177.    procedure Get_Previous_Rgba 
  178.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  179.        Rgba     : out Gdk.RGBA.Gdk_RGBA); 
  180.    --  Fills Rgba in with the original color value. 
  181.    --  Since: gtk+ 3.0 
  182.    --  "rgba": a Gdk.RGBA.Gdk_RGBA to fill in with the original color value 
  183.  
  184.    procedure Set_Previous_Rgba 
  185.       (Colorsel : not null access Gtk_Color_Selection_Record; 
  186.        Rgba     : Gdk.RGBA.Gdk_RGBA); 
  187.    --  Sets the 'previous' color to be Rgba. 
  188.    --  This function should be called with some hesitations, as it might seem 
  189.    --  confusing to have that color change. Calling 
  190.    --  Gtk.Color_Selection.Set_Current_Rgba will also set this color the first 
  191.    --  time it is called. 
  192.    --  Since: gtk+ 3.0 
  193.    --  "rgba": a Gdk.RGBA.Gdk_RGBA to set the previous color with 
  194.  
  195.    function Is_Adjusting 
  196.       (Colorsel : not null access Gtk_Color_Selection_Record) return Boolean; 
  197.    --  Gets the current state of the Colorsel. 
  198.  
  199.    ---------------------- 
  200.    -- GtkAda additions -- 
  201.    ---------------------- 
  202.  
  203.    type Gtk_Color_Selection_Change_Palette_With_Screen_Func is access procedure 
  204.      (Screen   : System.Address;--  Convert to Gdk_Screen with Get_User_Data 
  205.       Colors   : Gdk.Color.Gdk_Color_Unconstrained_Array; 
  206.       N_Colors : Gint); 
  207.    pragma Convention (C, Gtk_Color_Selection_Change_Palette_With_Screen_Func); 
  208.    --  This function should save the new palette contents, and update the 
  209.    --  Gtk_Settings property "gtk-color-palette" so all Gtk_Color_Selection 
  210.    --  widgets will be modified, including the current one. For instance, you 
  211.    --  would do: 
  212.    --    Set_String_Property 
  213.    --      (Get_Default, Gtk_Color_Palette, Palette_To_String (Colors), "Foo"); 
  214.  
  215.    function Palette_From_String 
  216.      (Str : String) return Gdk.Color.Gdk_Color_Array; 
  217.    --  Parses a color palette string. This string is a colon-separated list of 
  218.    --  color names readable by Gdk.Color.Parse. 
  219.    --  An empty array is returned if Str couldn't be parsed 
  220.  
  221.    function Palette_To_String 
  222.      (Colors   : Gdk.Color.Gdk_Color_Array) return String; 
  223.    --  Encodes a palette as a string, useful for persistent storage. 
  224.  
  225.    --------------------------------------------- 
  226.    -- Inherited subprograms (from interfaces) -- 
  227.    --------------------------------------------- 
  228.    --  Methods inherited from the Buildable interface are not duplicated here 
  229.    --  since they are meant to be used by tools, mostly. If you need to call 
  230.    --  them, use an explicit cast through the "-" operator below. 
  231.  
  232.    function Get_Orientation 
  233.       (Self : not null access Gtk_Color_Selection_Record) 
  234.        return Gtk.Enums.Gtk_Orientation; 
  235.  
  236.    procedure Set_Orientation 
  237.       (Self        : not null access Gtk_Color_Selection_Record; 
  238.        Orientation : Gtk.Enums.Gtk_Orientation); 
  239.  
  240.    --------------- 
  241.    -- Functions -- 
  242.    --------------- 
  243.  
  244.    procedure Set_Change_Palette_With_Screen_Hook 
  245.       (Func : Gtk_Color_Selection_Change_Palette_With_Screen_Func); 
  246.    --  Installs a global function to be called whenever the user tries to 
  247.    --  modify the palette in a color selection. 
  248.    --  This function should save the new palette contents, and update the 
  249.    --  Gtk.Settings.Gtk_Settings:gtk-color-palette GtkSettings property so all 
  250.    --  GtkColorSelection widgets will be modified. 
  251.    --  Since: gtk+ 2.2 
  252.    --  "func": a function to call when the custom palette needs saving 
  253.  
  254.    ---------------- 
  255.    -- Properties -- 
  256.    ---------------- 
  257.    --  The following properties are defined for this widget. See 
  258.    --  Glib.Properties for more information on properties) 
  259.  
  260.    Current_Alpha_Property : constant Glib.Properties.Property_Uint; 
  261.  
  262.    Current_Color_Property : constant Gdk.Color.Property_Gdk_Color; 
  263.    --  Type: Gdk.Color.Gdk_Color 
  264.    --  The current GdkColor color. 
  265.  
  266.    Current_Rgba_Property : constant Gdk.RGBA.Property_RGBA; 
  267.    --  Type: Gdk.RGBA.Gdk_RGBA 
  268.    --  The current RGBA color. 
  269.  
  270.    Has_Opacity_Control_Property : constant Glib.Properties.Property_Boolean; 
  271.  
  272.    Has_Palette_Property : constant Glib.Properties.Property_Boolean; 
  273.  
  274.    ------------- 
  275.    -- Signals -- 
  276.    ------------- 
  277.  
  278.    type Cb_Gtk_Color_Selection_Void is not null access procedure 
  279.      (Self : access Gtk_Color_Selection_Record'Class); 
  280.  
  281.    type Cb_GObject_Void is not null access procedure 
  282.      (Self : access Glib.Object.GObject_Record'Class); 
  283.  
  284.    Signal_Color_Changed : constant Glib.Signal_Name := "color-changed"; 
  285.    procedure On_Color_Changed 
  286.       (Self  : not null access Gtk_Color_Selection_Record; 
  287.        Call  : Cb_Gtk_Color_Selection_Void; 
  288.        After : Boolean := False); 
  289.    procedure On_Color_Changed 
  290.       (Self  : not null access Gtk_Color_Selection_Record; 
  291.        Call  : Cb_GObject_Void; 
  292.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  293.        After : Boolean := False); 
  294.    --  This signal is emitted when the color changes in the 
  295.    --  Gtk.Color_Selection.Gtk_Color_Selection according to its update policy. 
  296.  
  297.    ---------------- 
  298.    -- Interfaces -- 
  299.    ---------------- 
  300.    --  This class implements several interfaces. See Glib.Types 
  301.    -- 
  302.    --  - "Buildable" 
  303.    -- 
  304.    --  - "Orientable" 
  305.  
  306.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  307.      (Gtk.Buildable.Gtk_Buildable, Gtk_Color_Selection_Record, Gtk_Color_Selection); 
  308.    function "+" 
  309.      (Widget : access Gtk_Color_Selection_Record'Class) 
  310.    return Gtk.Buildable.Gtk_Buildable 
  311.    renames Implements_Gtk_Buildable.To_Interface; 
  312.    function "-" 
  313.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  314.    return Gtk_Color_Selection 
  315.    renames Implements_Gtk_Buildable.To_Object; 
  316.  
  317.    package Implements_Gtk_Orientable is new Glib.Types.Implements 
  318.      (Gtk.Orientable.Gtk_Orientable, Gtk_Color_Selection_Record, Gtk_Color_Selection); 
  319.    function "+" 
  320.      (Widget : access Gtk_Color_Selection_Record'Class) 
  321.    return Gtk.Orientable.Gtk_Orientable 
  322.    renames Implements_Gtk_Orientable.To_Interface; 
  323.    function "-" 
  324.      (Interf : Gtk.Orientable.Gtk_Orientable) 
  325.    return Gtk_Color_Selection 
  326.    renames Implements_Gtk_Orientable.To_Object; 
  327.  
  328. private 
  329.    Has_Palette_Property : constant Glib.Properties.Property_Boolean := 
  330.      Glib.Properties.Build ("has-palette"); 
  331.    Has_Opacity_Control_Property : constant Glib.Properties.Property_Boolean := 
  332.      Glib.Properties.Build ("has-opacity-control"); 
  333.    Current_Rgba_Property : constant Gdk.RGBA.Property_RGBA := 
  334.      Gdk.RGBA.Build ("current-rgba"); 
  335.    Current_Color_Property : constant Gdk.Color.Property_Gdk_Color := 
  336.      Gdk.Color.Build ("current-color"); 
  337.    Current_Alpha_Property : constant Glib.Properties.Property_Uint := 
  338.      Glib.Properties.Build ("current-alpha"); 
  339. end Gtk.Color_Selection;