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-2007 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_Color_Selection widget is a complex dialog that allows the user 
  32. --  to select a color based either on its (Red, Green, Blue) or its 
  33. --  (Hue, Saturation, Value). 
  34. --  An additional field is provided to select the opacity of the color (this 
  35. --  is usually called the alpha channel). 
  36. -- 
  37. --  See Gtk.Color_Selection_Dialog for a version of this widget that comes with 
  38. --  its own dialog. 
  39. -- 
  40. --  See Gtk.Extra.Color_Combo for a different way to select colors. 
  41. --  </description> 
  42. --  <c_version>2.8.17</c_version> 
  43. --  <group>Drawing</group> 
  44. --  <testgtk>create_color_selection.adb</testgtk> 
  45. --  <screenshot>gtk-colorsel</screenshot> 
  46.  
  47. with Glib.Properties; 
  48. with Gdk.Color; 
  49. with Gtk.Enums; 
  50. with Gtk.Box; 
  51.  
  52. package Gtk.Color_Selection is 
  53.  
  54.    type Gtk_Color_Selection_Record is new Gtk.Box.Gtk_Box_Record with private; 
  55.    type Gtk_Color_Selection is access all Gtk_Color_Selection_Record'Class; 
  56.  
  57.    type Color_Index is (Red, Green, Blue, Opacity); 
  58.    --  Used as an index to the table used to set and get the currently 
  59.    --  selected color. 
  60.  
  61.    type Color_Array is array (Color_Index) of Gdouble; 
  62.    --  Array that indicates the currently selected color. 
  63.    --  All the values are between 0.0 and 1.0 (a percentage value). 
  64.    --  They should be converted to absolute values before using them to create 
  65.    --  a new color, with the following piece of code: 
  66.    --    Absolute := To_Absolute (Color_Array (Index)) 
  67.  
  68.    procedure Gtk_New (Widget : out Gtk_Color_Selection); 
  69.    procedure Initialize (Widget : access Gtk_Color_Selection_Record'Class); 
  70.    --  Creates or initiailizes a new color selection widget. 
  71.  
  72.    function Get_Type return Glib.GType; 
  73.    --  Return the internal value associated with a Gtk_Color_Selection. 
  74.  
  75.    procedure Set_Current_Color 
  76.      (Colorsel : access Gtk_Color_Selection_Record; 
  77.       Color    : Gdk.Color.Gdk_Color); 
  78.    procedure Get_Current_Color 
  79.      (Colorsel : access Gtk_Color_Selection_Record; 
  80.       Color    : out Gdk.Color.Gdk_Color); 
  81.    --  Set the current color of the Colorsel. When called for the first time, 
  82.    --  the original color will the set to Color as well. 
  83.  
  84.    procedure Set_Previous_Color 
  85.      (Colorsel : access Gtk_Color_Selection_Record; 
  86.       Color    : Gdk.Color.Gdk_Color); 
  87.    procedure Get_Previous_Color 
  88.      (Colorsel : access Gtk_Color_Selection_Record; 
  89.       Color    : out Gdk.Color.Gdk_Color); 
  90.    --  Set the previous color. This procedure should not be called without 
  91.    --  analysis, as it might seem confusing to see that color change. 
  92.    --  Calling Set_Current_Color for the first time will also set this 
  93.    --  color. 
  94.  
  95.    function Is_Adjusting 
  96.       (Colorsel : access Gtk_Color_Selection_Record) return Boolean; 
  97.    --  Get the current state of the Colorsel. 
  98.    --  Return TRue if the user is currently dragging a color around, False if 
  99.    --  the selection has stopped. 
  100.  
  101.    function To_Absolute (Color : Gdouble) return Gushort; 
  102.    --  Convert from a percentage value as returned by Get_Color to an 
  103.    --  absolute value as can be used with Gdk_Color. 
  104.  
  105.    function To_Percent (Color : Gushort) return Gdouble; 
  106.    --  Convert from an absolute value as used in Gdk_Color to a percentage 
  107.    --  value as used in Set_Color. 
  108.  
  109.    ------------- 
  110.    -- Opacity -- 
  111.    ------------- 
  112.    --  The color selection widget allows you optionally to select the opacity 
  113.    --  of the color 
  114.  
  115.    procedure Set_Has_Opacity_Control 
  116.      (Colorsel    : access Gtk_Color_Selection_Record; 
  117.       Has_Opacity : Boolean); 
  118.    function Get_Has_Opacity_Control 
  119.      (Colorsel : access Gtk_Color_Selection_Record) return Boolean; 
  120.    --  Set the Colorsel to use or not use opacity. An additional field is 
  121.    --  displayed to select the opacity if needed. 
  122.  
  123.    procedure Set_Previous_Alpha 
  124.      (Colorsel : access Gtk_Color_Selection_Record; 
  125.       Alpha    : Guint16); 
  126.    function Get_Previous_Alpha 
  127.      (Colorsel : access Gtk_Color_Selection_Record) return Guint16; 
  128.    --  Set the previous opacity to Alpha. This procedure should not be called 
  129.    --  without analysis, as it might seem confusing to see that value change. 
  130.  
  131.    procedure Set_Current_Alpha 
  132.      (Colorsel : access Gtk_Color_Selection_Record; 
  133.       Alpha    : Guint16); 
  134.    function Get_Current_Alpha 
  135.      (Colorsel : access Gtk_Color_Selection_Record) return Guint16; 
  136.    --  Set the current opacity to be Alpha. When called for the first time, 
  137.    --  the original opacity will be set too. 
  138.  
  139.    ------------- 
  140.    -- Palette -- 
  141.    ------------- 
  142.    --  The color selection widget can optionally display a palette, which the 
  143.    --  user can change dynamically. This palette helps selecting colors for the 
  144.    --  user, who can chose faster among a limited set of colors. 
  145.  
  146.    procedure Set_Has_Palette 
  147.      (Colorsel    : access Gtk_Color_Selection_Record; 
  148.       Has_Palette : Boolean); 
  149.    function Get_Has_Palette 
  150.      (Colorsel : access Gtk_Color_Selection_Record) return Boolean; 
  151.    --  If Has_Palette is True, then set the Colorsel to show the palette. 
  152.    --  Hide the palette otherwise. 
  153.  
  154.    function Palette_From_String 
  155.      (Str : String) return Gdk.Color.Gdk_Color_Array; 
  156.    --  Parses a color palette string; this string is a colon-separated list of 
  157.    --  color names readable by Gdk.Color.Parse. 
  158.    --  An empty array is returned if Str couldn't be parsed 
  159.  
  160.    function Palette_To_String 
  161.      (Colors   : Gdk.Color.Gdk_Color_Array) return String; 
  162.    --  Encodes a palette as a string, useful for persistent storage. 
  163.  
  164.    type Gtk_Color_Selection_Change_Palette_With_Screen_Func is access 
  165.      procedure (Screen : Gdk.Gdk_Screen; 
  166.                 Colors : Gdk.Color.Gdk_Color_Array); 
  167.    --  This function should save the new palette contents, and update the 
  168.    --  Gtk_Settings property "gtk-color-palette" so all Gtk_Color_Selection 
  169.    --  widgets will be modified, including the current one. For instance, you 
  170.    --  would do: 
  171.    --    Set_String_Property 
  172.    --      (Get_Default, Gtk_Color_Palette, Palette_To_String (Colors), "Foo"); 
  173.  
  174.    function Set_Change_Palette_With_Screen_Hook 
  175.      (Func : Gtk_Color_Selection_Change_Palette_With_Screen_Func) 
  176.       return Gtk_Color_Selection_Change_Palette_With_Screen_Func; 
  177.    --  Installs a global function to be called whenever the user tries to 
  178.    --  modify the palette in a color selection. 
  179.    --  Return value: the previous change palette hook (that was replaced). 
  180.  
  181.    ----------------- 
  182.    -- Obsolescent -- 
  183.    ----------------- 
  184.    --  All subprograms below are now obsolescent in gtk+. They might be removed 
  185.    --  from future versions of gtk+ (and therefore GtkAda). 
  186.    --  To find out whether your code uses any of these, we recommend compiling 
  187.    --  with the -gnatwj switch 
  188.    --  <doc_ignore> 
  189.  
  190.    procedure Set_Update_Policy 
  191.      (Colorsel : access Gtk_Color_Selection_Record; 
  192.       Policy   : Enums.Gtk_Update_Type); 
  193.    pragma Obsolescent;  --  Set_Update_Policy 
  194.    --  Set the behavior of the scales used to select a value (red, green,...) 
  195.    --  Set Policy to Update_Continuous if you want to update the color 
  196.    --  continuously as the slider is mode, Update_Discontinuous to update the 
  197.    --  color only when the mouse is released and Update_Delayed to update when 
  198.    --  the mouse is released or has been motionless for a while. 
  199.  
  200.    procedure Set_Color 
  201.      (Colorsel : access Gtk_Color_Selection_Record; 
  202.       Color    : Color_Array); 
  203.    pragma Obsolescent ("Use Set_Current_Color");  --  Set_Color 
  204.    --  Modify the current color. 
  205.    --  Note that Color is an array of percentages, between 0.0 and 1.0, not 
  206.    --  absolute values. 
  207.  
  208.    procedure Get_Color 
  209.      (Colorsel : access Gtk_Color_Selection_Record; 
  210.       Color    : out Color_Array); 
  211.    pragma Obsolescent ("Use Get_Current_Color");  --  Get_Color 
  212.    --  Get the current color. 
  213.    --  Note that Color is an array of percentages, between 0.0 and 1.0, not 
  214.    --  absolute values. 
  215.  
  216.    --  </doc_ignore> 
  217.  
  218.    ---------------- 
  219.    -- Properties -- 
  220.    ---------------- 
  221.  
  222.    --  <properties> 
  223.    --  The following properties are defined for this widget. See 
  224.    --  Glib.Properties for more information on properties. 
  225.    -- 
  226.    --  Name:  Current_Alpha_Property 
  227.    --  Type:  Uint 
  228.    --  Descr: The current opacity value (0 fully transparent, 65535 fully 
  229.    --         opaque) 
  230.    -- 
  231.    --  Name:  Current_Color_Property 
  232.    --  Type:  Boxed 
  233.    --  Descr: The current color 
  234.    -- 
  235.    --  Name:  Has_Opacity_Control_Property 
  236.    --  Type:  Boolean 
  237.    --  Descr: Whether the color selector should allow setting opacity 
  238.    -- 
  239.    --  Name:  Has_Palette_Property 
  240.    --  Type:  Boolean 
  241.    --  Descr: Whether a palette should be used 
  242.    -- 
  243.    --  </properties> 
  244.  
  245.    Current_Alpha_Property       : constant Glib.Properties.Property_Uint; 
  246.    --  Current_Color_Property       : constant Glib.Properties.Property_Boxed; 
  247.    Has_Opacity_Control_Property : constant Glib.Properties.Property_Boolean; 
  248.    Has_Palette_Property         : constant Glib.Properties.Property_Boolean; 
  249.  
  250.    ------------- 
  251.    -- Signals -- 
  252.    ------------- 
  253.  
  254.    --  <signals> 
  255.    --  The following new signals are defined for this widget: 
  256.    -- 
  257.    --  - "color_changed" 
  258.    --    procedure Handler 
  259.    --       (Selection : access Gtk_Color_Selection_Record'Class); 
  260.    --    Called every time a new color is selected in the dialog 
  261.    --  </signals> 
  262.  
  263.    Signal_Color_Changed : constant Glib.Signal_Name := "color_changed"; 
  264.  
  265. private 
  266.    type Gtk_Color_Selection_Record is new Gtk.Box.Gtk_Box_Record 
  267.      with null record; 
  268.  
  269.    Current_Alpha_Property : constant Glib.Properties.Property_Uint := 
  270.      Glib.Properties.Build ("current-alpha"); 
  271.    --  Current_Color_Property : constant Glib.Properties.Property_Boxed := 
  272.    --    Glib.Properties.Build ("current-color"); 
  273.    Has_Opacity_Control_Property : constant Glib.Properties.Property_Boolean := 
  274.      Glib.Properties.Build ("has-opacity-control"); 
  275.    Has_Palette_Property : constant Glib.Properties.Property_Boolean := 
  276.      Glib.Properties.Build ("has-palette"); 
  277.  
  278.    pragma Import (C, Get_Type, "gtk_color_selection_get_type"); 
  279. end Gtk.Color_Selection; 
  280.  
  281. --  These subprograms never had a binding and are now obsolescent: 
  282. --  No binding: gtk_color_selection_set_change_palette_hook