1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006-2009, AdaCore                   -- 
  5. --                                                                   -- 
  6. -- This library is free software; you can redistribute it and/or     -- 
  7. -- modify it under the terms of the GNU General Public               -- 
  8. -- License as published by the Free Software Foundation; either      -- 
  9. -- version 2 of the License, or (at your option) any later version.  -- 
  10. --                                                                   -- 
  11. -- This library is distributed in the hope that it will be useful,   -- 
  12. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  13. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  14. -- General Public License for more details.                          -- 
  15. --                                                                   -- 
  16. -- You should have received a copy of the GNU General Public         -- 
  17. -- License along with this library; if not, write to the             -- 
  18. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  19. -- Boston, MA 02111-1307, USA.                                       -- 
  20. --                                                                   -- 
  21. -- -- -- -- -- -- -- -- -- -- -- --
  22. ----------------------------------------------------------------------- 
  23.  
  24. --  <description> 
  25. --  A Gtk_File_Filter can be used to restrict the files being shown in a 
  26. --  Gtk_File_Chooser. Files can be filtered based on their name (with 
  27. --  Add_Pattern), on their mime type (with Add_Mime_Type), or by a custom 
  28. --  filter function (with Add_Custom). 
  29. -- 
  30. --  Filtering by mime types handles aliasing and subclassing of mime types; 
  31. --  e.g. a filter for text/plain also matches a file with mime type 
  32. --  application/rtf, since application/rtf is a subclass of text/plain. Note 
  33. --  that Gtk_File_Filter allows wildcards for the subtype of a mime type, so 
  34. --  you can e.g. filter for image/*. 
  35. -- 
  36. --  Normally, filters are used by adding them to a Gtk_File_Chooser, see 
  37. --  Add_Filter, but it is also possible to manually use a filter on a file with 
  38. --  Filter. 
  39. --  </description> 
  40. --  <c_version>2.8.17</c_version> 
  41. --  <group>Selectors</group> 
  42.  
  43. with Glib; 
  44. with Gtk.Object; 
  45. with System; 
  46.  
  47. package Gtk.File_Filter is 
  48.  
  49.    type Gtk_File_Filter_Record is 
  50.      new Gtk.Object.Gtk_Object_Record with private; 
  51.    type Gtk_File_Filter is access all Gtk_File_Filter_Record'Class; 
  52.  
  53.    type File_Filter_Info is new Glib.C_Proxy; 
  54.    --  An opaque structure that contains information about a file 
  55.  
  56.    function Get_Filename     (Info : File_Filter_Info) return String; 
  57.    function Get_Uri          (Info : File_Filter_Info) return String; 
  58.    function Get_Display_Name (Info : File_Filter_Info) return String; 
  59.    function Get_Mime_Type    (Info : File_Filter_Info) return String; 
  60.    --  Return the various information known about the file. The empty string is 
  61.    --  returned when the associated information is unknown. Display_Name is the 
  62.    --  string used to display the file in a file_chooser. 
  63.  
  64.    type File_Filter_Flags is mod 2 ** 8; 
  65.    Filter_Filename     : constant File_Filter_Flags := 2 ** 0; 
  66.    Filter_Uri          : constant File_Filter_Flags := 2 ** 1; 
  67.    Filter_Display_Name : constant File_Filter_Flags := 2 ** 2; 
  68.    Filter_Mime_Type    : constant File_Filter_Flags := 2 ** 3; 
  69.    --  These flags indicate what parts of a Gtk_File_Filter_Info struct are 
  70.    --  filled or need to be filled. 
  71.  
  72.    type File_Filter_Func is access function 
  73.      (Info : File_Filter_Info) return Gboolean; 
  74.    pragma Convention (C, File_Filter_Func); 
  75.    --  Function used by custom filters 
  76.  
  77.    function Get_Type return GType; 
  78.    --  Return the internal value associated with a Gtk_File_Filter 
  79.  
  80.    procedure Gtk_New    (Filter : out Gtk_File_Filter); 
  81.    procedure Initialize (Filter : access Gtk_File_Filter_Record'Class); 
  82.    --  Creates a new Gtk_File_Filter with no rules added to it. Such a filter 
  83.    --  doesn't accept any files, so is not particularly useful until you add 
  84.    --  rules with Add_Mime_Type, Add_Pattern, or Add_Custom. To create a filter 
  85.    --  that accepts any file, use: 
  86.    --      Gtk_New (Filter); 
  87.    --      Add_Pattern (Filter, "*"); 
  88.  
  89.    procedure Set_Name 
  90.      (Filter : access Gtk_File_Filter_Record; Name : String); 
  91.    function Get_Name (Filter : access Gtk_File_Filter_Record) return String; 
  92.    --  Sets the human-readable name of the filter; this is the string 
  93.    --  that will be displayed in the file selector user interface if 
  94.    --  there is a selectable list of filters. 
  95.  
  96.    procedure Add_Mime_Type 
  97.      (Filter    : access Gtk_File_Filter_Record; 
  98.       Mime_Type : String); 
  99.    --  Adds a rule allowing a given mime type to Filter. 
  100.    --  In particular, if you want to show directories only and not files, you 
  101.    --  could use "x-directory/normal" as the Mime type 
  102.  
  103.    procedure Add_Pattern 
  104.      (Filter  : access Gtk_File_Filter_Record; 
  105.       Pattern : String); 
  106.    --  Adds a rule allowing a shell style glob to a filter. 
  107.  
  108.    procedure Add_Pixbuf_Formats 
  109.      (Filter : access Gtk_File_Filter_Record); 
  110.    --  Adds a rule allowing image files in the formats supported 
  111.    --  by Gdk_Pixbuf. 
  112.  
  113.    procedure Add_Custom 
  114.      (Filter : access Gtk_File_Filter_Record; 
  115.       Needed : File_Filter_Flags; 
  116.       Func   : File_Filter_Func; 
  117.       Data   : System.Address := System.Null_Address; 
  118.       Notify : G_Destroy_Notify_Address := null); 
  119.    --  Adds rule to a filter that allows files based on a custom callback 
  120.    --  function. The bitfield Needed which is passed in provides information 
  121.    --  about what sorts of information that the filter function needs; 
  122.    --  this allows GTK+ to avoid retrieving expensive information when 
  123.    --  it isn't needed by the filter. 
  124.    --  Notify is called when Data is no longer needed and should be freed. 
  125.  
  126. private 
  127.    type Gtk_File_Filter_Record is 
  128.      new Gtk.Object.Gtk_Object_Record with null record; 
  129.  
  130.    pragma Import (C, Get_Type, "gtk_file_filter_get_type"); 
  131. end Gtk.File_Filter; 
  132.  
  133. --  No binding: gtk_file_filter_filter 
  134. --  No binding: gtk_file_filter_get_needed