1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --      Copyright (C) 2000 E. Briot, J. Brobecker and A. Charlet     -- 
  5. --                Copyright (C) 2000-2006 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_Color_Combo is a widget that ease the selection of colors 
  27. --  by the user. It is a special form of a Gtk_Combo_Box, that displays 
  28. --  a special popup window, with a list of colors. 
  29. -- 
  30. --  Note that nothing appears in the button, this your responsibility to 
  31. --  update it when the user selects a new color (see the "changed" signal). 
  32. -- 
  33. --  The recommended solution is to put a Gtk_Pixmap as the 
  34. --  child of the button of the combo box ("Add (Get_Button (Combo), Pixmap)"), 
  35. --  and updated it in the handler for this signal. 
  36. --  </description> 
  37. --  <c_version>gtkextra 2.1.1</c_version> 
  38. --  <group>Selectors</group> 
  39.  
  40. with Gdk.Color; 
  41. with Gtk.Extra.Combo_Button; 
  42.  
  43. package Gtk.Extra.Color_Combo is 
  44.  
  45.    type Gtk_Color_Combo_Record is 
  46.      new Gtk.Extra.Combo_Button.Gtk_Combo_Button_Record with private; 
  47.    type Gtk_Color_Combo is access all Gtk_Color_Combo_Record'Class; 
  48.  
  49.    procedure Gtk_New (Widget : out Gtk_Color_Combo); 
  50.    --  Create a new default combo box. 
  51.    --  It shows a list of 40 default colors. 
  52.  
  53.    procedure Initialize (Widget : access Gtk_Color_Combo_Record'Class); 
  54.    --  Internal initialization function. 
  55.    --  See the section "Creating your own widgets" in the documentation. 
  56.  
  57.    procedure Gtk_New 
  58.      (Widget : out Gtk_Color_Combo; 
  59.       Nrows  : Gint; 
  60.       Ncols  : Gint; 
  61.       Values : Gdk.Color.Gdk_Color_Array); 
  62.    --  Create a new combo box with a specific list of colors. 
  63.    --  Note that Color_Names must contain at least Nrows * Ncols elements. 
  64.  
  65.    procedure Initialize 
  66.      (Widget : access Gtk_Color_Combo_Record; 
  67.       Nrows  : Gint; 
  68.       Ncols  : Gint; 
  69.       Values : Gdk.Color.Gdk_Color_Array); 
  70.    --  Internal initialization function. 
  71.    --  See the section "Creating your own widgets" in the documentation. 
  72.  
  73.    function Get_Type return Gtk.Gtk_Type; 
  74.    --  Return the internal value associated with a Gtk_Color_Combo. 
  75.  
  76.    function Get_Color_At 
  77.      (Widget : access Gtk_Color_Combo_Record; 
  78.       Row    : Gint; 
  79.       Col    : Gint) return Gdk.Color.Gdk_Color; 
  80.    --  Return the name of the color at specific coordinates. 
  81.  
  82.    procedure Find_Color 
  83.      (Color_Combo : access Gtk_Color_Combo_Record; 
  84.       Color       : Gdk.Color.Gdk_Color; 
  85.       Row         : out Gint; 
  86.       Col         : out Gint); 
  87.    --  Return the coordinates in which a color appear in the popup window. 
  88.    --  (-1, -1) is returned if the color was not found in the combo box. 
  89.  
  90.    function Get_Selection (Color_Combo : access Gtk_Color_Combo_Record) 
  91.       return Gdk.Color.Gdk_Color; 
  92.    --  Return the current selection in the combo. 
  93.  
  94.    function Set_Color 
  95.      (Color_Combo : access Gtk_Color_Combo_Record; 
  96.       Name        : String) 
  97.      return Boolean; 
  98.    --  Set the new current color. If the color is not found in the list of 
  99.    --  colors provided in the popup window, False is returned. 
  100.  
  101.    function Set_Color 
  102.      (Color_Combo : access Gtk_Color_Combo_Record; 
  103.       Color       : Gdk.Color.Gdk_Color) 
  104.      return Boolean; 
  105.    --  Set the new current color. Color must have been allocated first.  If the 
  106.    --  color is not found in the list of colors provided in the popup window, 
  107.    --  False is returned. 
  108.  
  109.    function Get_Ncols (Color_Combo : access Gtk_Color_Combo_Record) 
  110.       return Gint; 
  111.    --  Return the number of columns in the popup window 
  112.  
  113.    function Get_Nrows (Color_Combo : access Gtk_Color_Combo_Record) 
  114.       return Gint; 
  115.    --  Return the number of rows in the popup window 
  116.  
  117.    procedure Changed 
  118.      (Color_Combo : access Gtk_Color_Combo_Record; 
  119.       Row : Gint; 
  120.       Col : Gint); 
  121.    --  Emit the changed signal for the widget, as if the color at coordinates 
  122.    --  (Row, Col) had been selected. 
  123.    --  Note that this doesn't change the internal state of the widget (use 
  124.    --  Set_Color for that). 
  125.  
  126.    ------------- 
  127.    -- Signals -- 
  128.    ------------- 
  129.  
  130.    --  <signals> 
  131.    --  The following new signals are defined for this widget: 
  132.    -- 
  133.    --  - "changed" 
  134.    --  procedure Handler (Color_Combo : access Gtk_Color_Combo_Record'Class; 
  135.    --                     Selection   : Gint; 
  136.    --                     Color       : access Gdk.Color.Gdk_Color); 
  137.    -- 
  138.    --  Emitted when the color has selected a new color. 
  139.    --  Selection is the number of the selection (this is the total 
  140.    --  row * Ncols + col). Color_Name is the name of the selected color. 
  141.    --  </signals> 
  142.  
  143. private 
  144.    type Gtk_Color_Combo_Record is 
  145.      new Gtk.Extra.Combo_Button.Gtk_Combo_Button_Record with null record; 
  146.    pragma Import (C, Get_Type, "gtk_color_combo_get_type"); 
  147. end Gtk.Extra.Color_Combo;