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. --  Browse the available stock icons in the list of stock IDs found <link 
  26. --  linkend="gtk-Stock-Items">here</link>. You can also use the 
  27. --  <application>gtk-demo</application> application for this purpose. 
  28. -- 
  29. --  An icon factory manages a collection of Gtk.Icon_Set.Gtk_Icon_Set; a 
  30. --  Gtk.Icon_Set.Gtk_Icon_Set manages a set of variants of a particular icon 
  31. --  (i.e. a Gtk.Icon_Set.Gtk_Icon_Set contains variants for different sizes and 
  32. --  widget states). Icons in an icon factory are named by a stock ID, which is 
  33. --  a simple string identifying the icon. Each Gtk.Style.Gtk_Style has a list 
  34. --  of Gtk.Icon_Factory.Gtk_Icon_Factory derived from the current theme; those 
  35. --  icon factories are consulted first when searching for an icon. If the theme 
  36. --  doesn't set a particular icon, GTK+ looks for the icon in a list of default 
  37. --  icon factories, maintained by Gtk.Icon_Factory.Add_Default and 
  38. --  Gtk.Icon_Factory.Remove_Default. Applications with icons should add a 
  39. --  default icon factory with their icons, which will allow themes to override 
  40. --  the icons for the application. 
  41. -- 
  42. --  To display an icon, always use gtk_style_lookup_icon_set on the widget 
  43. --  that will display the icon, or the convenience function 
  44. --  Gtk.Widget.Render_Icon. These functions take the theme into account when 
  45. --  looking up the icon to use for a given stock ID. 
  46. -- 
  47. --  == GtkIconFactory as GtkBuildable == 
  48. -- 
  49. --  GtkIconFactory supports a custom <sources> element, which can contain 
  50. --  multiple <source> elements. The following attributes are allowed: 
  51. -- 
  52. --  'stock-id' 
  53. -- 
  54. --     * The stock id of the source, a string. This attribute is mandatory 
  55. -- 
  56. --  'filename' 
  57. -- 
  58. --     * The filename of the source, a string. This attribute is optional 
  59. -- 
  60. --  'icon-name' 
  61. -- 
  62. --     * The icon name for the source, a string. This attribute is optional. 
  63. -- 
  64. --  'size' 
  65. -- 
  66. --     * Size of the icon, a Gtk.Enums.Gtk_Icon_Size enum value. This 
  67. --  attribute is optional. 
  68. -- 
  69. --  'direction' 
  70. -- 
  71. --     * Direction of the source, a Gtk.Enums.Gtk_Text_Direction enum value. 
  72. --  This attribute is optional. 
  73. -- 
  74. --  'state' 
  75. -- 
  76. --     * State of the source, a Gtk.Enums.Gtk_State_Type enum value. This 
  77. --  attribute is optional. 
  78. -- 
  79. --  == A Gtk.Icon_Factory.Gtk_Icon_Factory UI definition fragment. == 
  80. -- 
  81. --    <object class="GtkIconFactory" id="iconfactory1"> 
  82. --    <sources> 
  83. --    <source stock-id="apple-red" filename="apple-red.png"/> 
  84. --    </sources> 
  85. --    </object> 
  86. --    <object class="GtkWindow" id="window1"> 
  87. --    <child> 
  88. --    <object class="GtkButton" id="apple_button"> 
  89. --    <property name="label">apple-red</property> 
  90. --    <property name="use-stock">True</property> 
  91. --    </object> 
  92. --    </child> 
  93. --    </object> 
  94. --  </description> 
  95. pragma Ada_2005; 
  96.  
  97. pragma Warnings (Off, "*is already use-visible*"); 
  98. with Glib;               use Glib; 
  99. with Glib.Object;        use Glib.Object; 
  100. with Glib.Types;         use Glib.Types; 
  101. with Gtk.Buildable;      use Gtk.Buildable; 
  102. with Gtk.Enums;          use Gtk.Enums; 
  103. with Gtk.Icon_Set;       use Gtk.Icon_Set; 
  104. with Gtk.Settings;       use Gtk.Settings; 
  105. with Gtk.Style_Provider; use Gtk.Style_Provider; 
  106. with Gtk.Widget;         use Gtk.Widget; 
  107.  
  108. package Gtk.Icon_Factory is 
  109.  
  110.    type Gtk_Icon_Factory_Record is new GObject_Record with null record; 
  111.    type Gtk_Icon_Factory is access all Gtk_Icon_Factory_Record'Class; 
  112.  
  113.    ------------------ 
  114.    -- Constructors -- 
  115.    ------------------ 
  116.  
  117.    procedure Gtk_New (Self : out Gtk_Icon_Factory); 
  118.    procedure Initialize 
  119.       (Self : not null access Gtk_Icon_Factory_Record'Class); 
  120.    --  Creates a new Gtk.Icon_Factory.Gtk_Icon_Factory. An icon factory 
  121.    --  manages a collection of Gtk.Icon_Set.Gtk_Icon_Set<!-- -->s; a 
  122.    --  Gtk.Icon_Set.Gtk_Icon_Set manages a set of variants of a particular icon 
  123.    --  (i.e. a Gtk.Icon_Set.Gtk_Icon_Set contains variants for different sizes 
  124.    --  and widget states). Icons in an icon factory are named by a stock ID, 
  125.    --  which is a simple string identifying the icon. Each Gtk.Style.Gtk_Style 
  126.    --  has a list of Gtk.Icon_Factory.Gtk_Icon_Factory<!-- -->s derived from 
  127.    --  the current theme; those icon factories are consulted first when 
  128.    --  searching for an icon. If the theme doesn't set a particular icon, GTK+ 
  129.    --  looks for the icon in a list of default icon factories, maintained by 
  130.    --  Gtk.Icon_Factory.Add_Default and Gtk.Icon_Factory.Remove_Default. 
  131.    --  Applications with icons should add a default icon factory with their 
  132.    --  icons, which will allow themes to override the icons for the 
  133.    --  application. 
  134.  
  135.    function Gtk_Icon_Factory_New return Gtk_Icon_Factory; 
  136.    --  Creates a new Gtk.Icon_Factory.Gtk_Icon_Factory. An icon factory 
  137.    --  manages a collection of Gtk.Icon_Set.Gtk_Icon_Set<!-- -->s; a 
  138.    --  Gtk.Icon_Set.Gtk_Icon_Set manages a set of variants of a particular icon 
  139.    --  (i.e. a Gtk.Icon_Set.Gtk_Icon_Set contains variants for different sizes 
  140.    --  and widget states). Icons in an icon factory are named by a stock ID, 
  141.    --  which is a simple string identifying the icon. Each Gtk.Style.Gtk_Style 
  142.    --  has a list of Gtk.Icon_Factory.Gtk_Icon_Factory<!-- -->s derived from 
  143.    --  the current theme; those icon factories are consulted first when 
  144.    --  searching for an icon. If the theme doesn't set a particular icon, GTK+ 
  145.    --  looks for the icon in a list of default icon factories, maintained by 
  146.    --  Gtk.Icon_Factory.Add_Default and Gtk.Icon_Factory.Remove_Default. 
  147.    --  Applications with icons should add a default icon factory with their 
  148.    --  icons, which will allow themes to override the icons for the 
  149.    --  application. 
  150.  
  151.    function Get_Type return Glib.GType; 
  152.    pragma Import (C, Get_Type, "gtk_icon_factory_get_type"); 
  153.  
  154.    ------------- 
  155.    -- Methods -- 
  156.    ------------- 
  157.  
  158.    procedure Add 
  159.       (Self     : not null access Gtk_Icon_Factory_Record; 
  160.        Stock_Id : UTF8_String; 
  161.        Icon_Set : Gtk.Icon_Set.Gtk_Icon_Set); 
  162.    --  Adds the given Icon_Set to the icon factory, under the name Stock_Id. 
  163.    --  Stock_Id should be namespaced for your application, e.g. 
  164.    --  "myapp-whatever-icon". Normally applications create a 
  165.    --  Gtk.Icon_Factory.Gtk_Icon_Factory, then add it to the list of default 
  166.    --  factories with Gtk.Icon_Factory.Add_Default. Then they pass the Stock_Id 
  167.    --  to widgets such as Gtk.Image.Gtk_Image to display the icon. Themes can 
  168.    --  provide an icon with the same name (such as "myapp-whatever-icon") to 
  169.    --  override your application's default icons. If an icon already existed in 
  170.    --  Factory for Stock_Id, it is unreferenced and replaced with the new 
  171.    --  Icon_Set. 
  172.    --  "stock_id": icon name 
  173.    --  "icon_set": icon set 
  174.  
  175.    procedure Add_Default (Self : not null access Gtk_Icon_Factory_Record); 
  176.    --  Adds an icon factory to the list of icon factories searched by 
  177.    --  gtk_style_lookup_icon_set. This means that, for example, 
  178.    --  Gtk.Image.Gtk_New will be able to find icons in Factory. There will 
  179.    --  normally be an icon factory added for each library or application that 
  180.    --  comes with icons. The default icon factories can be overridden by 
  181.    --  themes. 
  182.  
  183.    function Lookup 
  184.       (Self     : not null access Gtk_Icon_Factory_Record; 
  185.        Stock_Id : UTF8_String) return Gtk.Icon_Set.Gtk_Icon_Set; 
  186.    --  Looks up Stock_Id in the icon factory, returning an icon set if found, 
  187.    --  otherwise null. For display to the user, you should use 
  188.    --  gtk_style_lookup_icon_set on the Gtk.Style.Gtk_Style for the widget that 
  189.    --  will display the icon, instead of using this function directly, so that 
  190.    --  themes are taken into account. 
  191.    --  "stock_id": an icon name 
  192.  
  193.    procedure Remove_Default (Self : not null access Gtk_Icon_Factory_Record); 
  194.    --  Removes an icon factory from the list of default icon factories. Not 
  195.    --  normally used; you might use it for a library that can be unloaded or 
  196.    --  shut down. 
  197.  
  198.    ---------------------- 
  199.    -- GtkAda additions -- 
  200.    ---------------------- 
  201.  
  202.    function Get_Icon_Factory 
  203.      (Self : Gtk.Style_Provider.Gtk_Style_Provider; 
  204.       Path : Gtk.Widget.Gtk_Widget_Path) 
  205.    return Gtk_Icon_Factory; 
  206.    --  Returns the Gtk.Icon_Factory.Gtk_Icon_Factory defined to be in use for 
  207.    --  Path, or null if none is defined. 
  208.    --  Since: gtk+ 3.0 
  209.  
  210.    --------------- 
  211.    -- Functions -- 
  212.    --------------- 
  213.  
  214.    function Lookup_Default 
  215.       (Stock_Id : UTF8_String) return Gtk.Icon_Set.Gtk_Icon_Set; 
  216.    --  Looks for an icon in the list of default icon factories. For display to 
  217.    --  the user, you should use gtk_style_lookup_icon_set on the 
  218.    --  Gtk.Style.Gtk_Style for the widget that will display the icon, instead 
  219.    --  of using this function directly, so that themes are taken into account. 
  220.    --  "stock_id": an icon name 
  221.  
  222.    procedure Icon_Size_Lookup 
  223.       (Size   : Gtk.Enums.Gtk_Icon_Size; 
  224.        Width  : out Gint; 
  225.        Height : out Gint; 
  226.        Result : out Boolean); 
  227.    --  Obtains the pixel size of a semantic icon size, possibly modified by 
  228.    --  user preferences for the default Gtk.Settings.Gtk_Settings. (See 
  229.    --  Gtk.Icon_Factory.Icon_Size_Lookup_For_Settings.) Normally Size would be 
  230.    --  GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_BUTTON, etc. This function isn't 
  231.    --  normally needed, Gtk.Widget.Render_Icon_Pixbuf is the usual way to get 
  232.    --  an icon for rendering, then just look at the size of the rendered 
  233.    --  pixbuf. The rendered pixbuf may not even correspond to the width/height 
  234.    --  returned by Gtk.Icon_Factory.Icon_Size_Lookup, because themes are free 
  235.    --  to render the pixbuf however they like, including changing the usual 
  236.    --  size. 
  237.    --  "size": an icon size 
  238.    --  "width": location to store icon width 
  239.    --  "height": location to store icon height 
  240.  
  241.    procedure Icon_Size_Lookup_For_Settings 
  242.       (Settings : not null access Gtk.Settings.Gtk_Settings_Record'Class; 
  243.        Size     : Gtk.Enums.Gtk_Icon_Size; 
  244.        Width    : out Gint; 
  245.        Height   : out Gint; 
  246.        Result   : out Boolean); 
  247.    --  Obtains the pixel size of a semantic icon size, possibly modified by 
  248.    --  user preferences for a particular Gtk.Settings.Gtk_Settings. Normally 
  249.    --  Size would be GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_BUTTON, etc. This 
  250.    --  function isn't normally needed, Gtk.Widget.Render_Icon_Pixbuf is the 
  251.    --  usual way to get an icon for rendering, then just look at the size of 
  252.    --  the rendered pixbuf. The rendered pixbuf may not even correspond to the 
  253.    --  width/height returned by Gtk.Icon_Factory.Icon_Size_Lookup, because 
  254.    --  themes are free to render the pixbuf however they like, including 
  255.    --  changing the usual size. 
  256.    --  Since: gtk+ 2.2 
  257.    --  "settings": a Gtk.Settings.Gtk_Settings object, used to determine which 
  258.    --  set of user preferences to used. 
  259.    --  "size": an icon size 
  260.    --  "width": location to store icon width 
  261.    --  "height": location to store icon height 
  262.  
  263.    function Icon_Size_Register 
  264.       (Name   : UTF8_String; 
  265.        Width  : Gint; 
  266.        Height : Gint) return Gtk.Enums.Gtk_Icon_Size; 
  267.    --  Registers a new icon size, along the same lines as GTK_ICON_SIZE_MENU, 
  268.    --  etc. Returns the integer value for the size. 
  269.    --  "name": name of the icon size 
  270.    --  "width": the icon width 
  271.    --  "height": the icon height 
  272.  
  273.    procedure Icon_Size_Register_Alias 
  274.       (Alias  : UTF8_String; 
  275.        Target : Gtk.Enums.Gtk_Icon_Size); 
  276.    --  Registers Alias as another name for Target. So calling 
  277.    --  gtk_icon_size_from_name with Alias as argument will return Target. 
  278.    --  "alias": an alias for Target 
  279.    --  "target": an existing icon size 
  280.  
  281.    ---------------- 
  282.    -- Interfaces -- 
  283.    ---------------- 
  284.    --  This class implements several interfaces. See Glib.Types 
  285.    -- 
  286.    --  - "Buildable" 
  287.  
  288.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  289.      (Gtk.Buildable.Gtk_Buildable, Gtk_Icon_Factory_Record, Gtk_Icon_Factory); 
  290.    function "+" 
  291.      (Widget : access Gtk_Icon_Factory_Record'Class) 
  292.    return Gtk.Buildable.Gtk_Buildable 
  293.    renames Implements_Gtk_Buildable.To_Interface; 
  294.    function "-" 
  295.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  296.    return Gtk_Icon_Factory 
  297.    renames Implements_Gtk_Buildable.To_Object; 
  298.  
  299. end Gtk.Icon_Factory;