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. --  An icon set represents a single icon in various sizes and widget states. 
  26. --  It can provide a Gdk_Pixbuf for a given size and state on request, and 
  27. --  automatically caches some of the rendered Gdk_Pixbuf objects. 
  28. -- 
  29. --  Normally you would use Gtk.Widget.Render_Icon instead of using icon sets 
  30. --  directly. The one case where you'd use an icon set is to create 
  31. --  application-specific icon sets to place in an icon factory. 
  32. -- 
  33. --  </description> 
  34. pragma Ada_2005; 
  35.  
  36. pragma Warnings (Off, "*is already use-visible*"); 
  37. with Gdk.Pixbuf;        use Gdk.Pixbuf; 
  38. with Glib;              use Glib; 
  39. with Gtk.Enums;         use Gtk.Enums; 
  40. with Gtk.Icon_Source;   use Gtk.Icon_Source; 
  41. with Gtk.Style;         use Gtk.Style; 
  42. with Gtk.Style_Context; use Gtk.Style_Context; 
  43. with Gtk.Widget;        use Gtk.Widget; 
  44.  
  45. package Gtk.Icon_Set is 
  46.  
  47.    type Gtk_Icon_Set is new Glib.C_Boxed with null record; 
  48.    Null_Gtk_Icon_Set : constant Gtk_Icon_Set; 
  49.  
  50.    function From_Object (Object : System.Address) return Gtk_Icon_Set; 
  51.    function From_Object_Free (B : access Gtk_Icon_Set'Class) return Gtk_Icon_Set; 
  52.    pragma Inline (From_Object_Free, From_Object); 
  53.  
  54.    ------------------ 
  55.    -- Constructors -- 
  56.    ------------------ 
  57.  
  58.    procedure Gtk_New (Self : out Gtk_Icon_Set); 
  59.    --  Creates a new Gtk.Icon_Set.Gtk_Icon_Set. A Gtk.Icon_Set.Gtk_Icon_Set 
  60.    --  represents a single icon in various sizes and widget states. It can 
  61.    --  provide a Gdk.Pixbuf.Gdk_Pixbuf for a given size and state on request, 
  62.    --  and automatically caches some of the rendered Gdk.Pixbuf.Gdk_Pixbuf 
  63.    --  objects. 
  64.    --  Normally you would use Gtk.Widget.Render_Icon_Pixbuf instead of using 
  65.    --  Gtk.Icon_Set.Gtk_Icon_Set directly. The one case where you'd use 
  66.    --  Gtk.Icon_Set.Gtk_Icon_Set is to create application-specific icon sets to 
  67.    --  place in a Gtk.Icon_Factory.Gtk_Icon_Factory. 
  68.  
  69.    function Gtk_Icon_Set_New return Gtk_Icon_Set; 
  70.    --  Creates a new Gtk.Icon_Set.Gtk_Icon_Set. A Gtk.Icon_Set.Gtk_Icon_Set 
  71.    --  represents a single icon in various sizes and widget states. It can 
  72.    --  provide a Gdk.Pixbuf.Gdk_Pixbuf for a given size and state on request, 
  73.    --  and automatically caches some of the rendered Gdk.Pixbuf.Gdk_Pixbuf 
  74.    --  objects. 
  75.    --  Normally you would use Gtk.Widget.Render_Icon_Pixbuf instead of using 
  76.    --  Gtk.Icon_Set.Gtk_Icon_Set directly. The one case where you'd use 
  77.    --  Gtk.Icon_Set.Gtk_Icon_Set is to create application-specific icon sets to 
  78.    --  place in a Gtk.Icon_Factory.Gtk_Icon_Factory. 
  79.  
  80.    procedure Gtk_New_From_Pixbuf 
  81.       (Self   : out Gtk_Icon_Set; 
  82.        Pixbuf : not null access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class); 
  83.    --  Creates a new Gtk.Icon_Set.Gtk_Icon_Set with Pixbuf as the 
  84.    --  default/fallback source image. If you don't add any additional 
  85.    --  Gtk.Icon_Source.Gtk_Icon_Source to the icon set, all variants of the 
  86.    --  icon will be created from Pixbuf, using scaling, pixelation, etc. as 
  87.    --  required to adjust the icon size or make the icon look 
  88.    --  insensitive/prelighted. 
  89.    --  "pixbuf": a Gdk.Pixbuf.Gdk_Pixbuf 
  90.  
  91.    function Gtk_Icon_Set_New_From_Pixbuf 
  92.       (Pixbuf : not null access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class) 
  93.        return Gtk_Icon_Set; 
  94.    --  Creates a new Gtk.Icon_Set.Gtk_Icon_Set with Pixbuf as the 
  95.    --  default/fallback source image. If you don't add any additional 
  96.    --  Gtk.Icon_Source.Gtk_Icon_Source to the icon set, all variants of the 
  97.    --  icon will be created from Pixbuf, using scaling, pixelation, etc. as 
  98.    --  required to adjust the icon size or make the icon look 
  99.    --  insensitive/prelighted. 
  100.    --  "pixbuf": a Gdk.Pixbuf.Gdk_Pixbuf 
  101.  
  102.    function Get_Type return Glib.GType; 
  103.    pragma Import (C, Get_Type, "gtk_icon_set_get_type"); 
  104.  
  105.    ------------- 
  106.    -- Methods -- 
  107.    ------------- 
  108.  
  109.    procedure Add_Source 
  110.       (Self   : Gtk_Icon_Set; 
  111.        Source : Gtk.Icon_Source.Gtk_Icon_Source); 
  112.    --  Icon sets have a list of Gtk.Icon_Source.Gtk_Icon_Source, which they 
  113.    --  use as base icons for rendering icons in different states and sizes. 
  114.    --  Icons are scaled, made to look insensitive, etc. in 
  115.    --  Gtk.Icon_Set.Render_Icon, but Gtk.Icon_Set.Gtk_Icon_Set needs base 
  116.    --  images to work with. The base images and when to use them are described 
  117.    --  by a Gtk.Icon_Source.Gtk_Icon_Source. 
  118.    --  This function copies Source, so you can reuse the same source 
  119.    --  immediately without affecting the icon set. 
  120.    --  An example of when you'd use this function: a web browser's "Back to 
  121.    --  Previous Page" icon might point in a different direction in Hebrew and 
  122.    --  in English; it might look different when insensitive; and it might 
  123.    --  change size depending on toolbar mode (small/large icons). So a single 
  124.    --  icon set would contain all those variants of the icon, and you might add 
  125.    --  a separate source for each one. 
  126.    --  You should nearly always add a "default" icon source with all fields 
  127.    --  wildcarded, which will be used as a fallback if no more specific source 
  128.    --  matches. Gtk.Icon_Set.Gtk_Icon_Set always prefers more specific icon 
  129.    --  sources to more generic icon sources. The order in which you add the 
  130.    --  sources to the icon set does not matter. 
  131.    --  gtk_icon_set_new_from_pixbuf creates a new icon set with a default icon 
  132.    --  source based on the given pixbuf. 
  133.    --  "source": a Gtk.Icon_Source.Gtk_Icon_Source 
  134.  
  135.    function Copy (Self : Gtk_Icon_Set) return Gtk_Icon_Set; 
  136.    --  Copies Icon_Set by value. 
  137.  
  138.    function Get_Sizes (Self : Gtk_Icon_Set) return Gint_Array; 
  139.    --  Obtains a list of icon sizes this icon set can render. The returned 
  140.    --  array must be freed with g_free. 
  141.  
  142.    function Ref (Self : Gtk_Icon_Set) return Gtk_Icon_Set; 
  143.    --  Increments the reference count on Icon_Set. 
  144.  
  145.    function Render_Icon 
  146.       (Self      : Gtk_Icon_Set; 
  147.        Style     : access Gtk.Style.Gtk_Style_Record'Class; 
  148.        Direction : Gtk.Enums.Gtk_Text_Direction; 
  149.        State     : Gtk.Enums.Gtk_State_Type; 
  150.        Size      : Gtk.Enums.Gtk_Icon_Size; 
  151.        Widget    : access Gtk.Widget.Gtk_Widget_Record'Class; 
  152.        Detail    : UTF8_String := "") return Gdk.Pixbuf.Gdk_Pixbuf; 
  153.    pragma Obsolescent (Render_Icon); 
  154.    --  Renders an icon using gtk_style_render_icon. In most cases, 
  155.    --  Gtk.Widget.Render_Icon is better, since it automatically provides most 
  156.    --  of the arguments from the current widget settings. This function never 
  157.    --  returns null; if the icon can't be rendered (perhaps because an image 
  158.    --  file fails to load), a default "missing image" icon will be returned 
  159.    --  instead. 
  160.    --  Deprecated since 3.0, Use Gtk.Icon_Set.Render_Icon_Pixbuf instead 
  161.    --  "style": a Gtk.Style.Gtk_Style associated with Widget, or null 
  162.    --  "direction": text direction 
  163.    --  "state": widget state 
  164.    --  "size": icon size. A size of (GtkIconSize)-1 means render at the size 
  165.    --  of the source and don't scale. 
  166.    --  "widget": widget that will display the icon, or null. The only use that 
  167.    --  is typically made of this is to determine the appropriate 
  168.    --  Gdk.Screen.Gdk_Screen. 
  169.    --  "detail": detail to pass to the theme engine, or null. Note that 
  170.    --  passing a detail of anything but null will disable caching. 
  171.  
  172.    function Render_Icon_Pixbuf 
  173.       (Self    : Gtk_Icon_Set; 
  174.        Context : not null access Gtk.Style_Context.Gtk_Style_Context_Record'Class; 
  175.        Size    : Gtk.Enums.Gtk_Icon_Size) return Gdk.Pixbuf.Gdk_Pixbuf; 
  176.    --  Renders an icon using gtk_render_icon_pixbuf. In most cases, 
  177.    --  Gtk.Widget.Render_Icon_Pixbuf is better, since it automatically provides 
  178.    --  most of the arguments from the current widget settings. This function 
  179.    --  never returns null; if the icon can't be rendered (perhaps because an 
  180.    --  image file fails to load), a default "missing image" icon will be 
  181.    --  returned instead. 
  182.    --  Since: gtk+ 3.0 
  183.    --  "context": a Gtk.Style_Context.Gtk_Style_Context 
  184.    --  "size": icon size. A size of (GtkIconSize)-1 means render at the size 
  185.    --  of the source and don't scale. 
  186.  
  187.    procedure Unref (Self : Gtk_Icon_Set); 
  188.    --  Decrements the reference count on Icon_Set, and frees memory if the 
  189.    --  reference count reaches 0. 
  190.  
  191.    ---------------------- 
  192.    -- GtkAda additions -- 
  193.    ---------------------- 
  194.  
  195.    function Lookup_Icon_Set 
  196.      (Style  : access Gtk.Style.Gtk_Style_Record'Class; Stock_Id : String) 
  197.    return Gtk_Icon_Set; 
  198.    --  Retrieve an icon set by its name. The icon might exist in various sizes, 
  199.    --  that can be manipulated through the result set 
  200.  
  201. private 
  202.  
  203.    Null_Gtk_Icon_Set : constant Gtk_Icon_Set := (Glib.C_Boxed with null record); 
  204.  
  205. end Gtk.Icon_Set;