1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006-2013, 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. -- As a special exception, if other files instantiate generics from  -- 
  22. -- this unit, or you link this unit with other files to produce an   -- 
  23. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  24. -- executable to be covered by the GNU General Public License. This  -- 
  25. -- exception does not however invalidate any other reasons why the   -- 
  26. -- executable file  might be covered by the  GNU Public License.     -- 
  27. ----------------------------------------------------------------------- 
  28.  
  29. --  <description> 
  30. --  A Gtk_File_Filter can be used to restrict the files being shown in a 
  31. --  Gtk_File_Chooser. Files can be filtered based on their name (with 
  32. --  Add_Pattern), on their mime type (with Add_Mime_Type), or by a custom 
  33. --  filter function (with Add_Custom). 
  34. -- 
  35. --  Filtering by mime types handles aliasing and subclassing of mime types; 
  36. --  e.g. a filter for text/plain also matches a file with mime type 
  37. --  application/rtf, since application/rtf is a subclass of text/plain. Note 
  38. --  that Gtk_File_Filter allows wildcards for the subtype of a mime type, so 
  39. --  you can e.g. filter for image/*. 
  40. -- 
  41. --  Normally, filters are used by adding them to a Gtk_File_Chooser, see 
  42. --  Add_Filter, but it is also possible to manually use a filter on a file with 
  43. --  Filter. 
  44. --  </description> 
  45. --  <c_version>2.8.17</c_version> 
  46. --  <group>Selectors</group> 
  47.  
  48. with Glib; 
  49. with Glib.Object; 
  50. with System; 
  51.  
  52. package Gtk.File_Filter is 
  53.  
  54.    type Gtk_File_Filter_Record is 
  55.      new Glib.Object.GObject_Record with private; 
  56.    type Gtk_File_Filter is access all Gtk_File_Filter_Record'Class; 
  57.  
  58.    type File_Filter_Info is new Glib.C_Proxy; 
  59.    --  An opaque structure that contains information about a file 
  60.  
  61.    function Get_Filename     (Info : File_Filter_Info) return String; 
  62.    function Get_Uri          (Info : File_Filter_Info) return String; 
  63.    function Get_Display_Name (Info : File_Filter_Info) return String; 
  64.    function Get_Mime_Type    (Info : File_Filter_Info) return String; 
  65.    --  Return the various information known about the file. The empty string is 
  66.    --  returned when the associated information is unknown. Display_Name is the 
  67.    --  string used to display the file in a file_chooser. 
  68.  
  69.    type File_Filter_Flags is mod 2 ** 8; 
  70.    Filter_Filename     : constant File_Filter_Flags := 2 ** 0; 
  71.    Filter_Uri          : constant File_Filter_Flags := 2 ** 1; 
  72.    Filter_Display_Name : constant File_Filter_Flags := 2 ** 2; 
  73.    Filter_Mime_Type    : constant File_Filter_Flags := 2 ** 3; 
  74.    --  These flags indicate what parts of a Gtk_File_Filter_Info struct are 
  75.    --  filled or need to be filled. 
  76.  
  77.    type File_Filter_Func is access function 
  78.      (Info : File_Filter_Info) return Gboolean; 
  79.    pragma Convention (C, File_Filter_Func); 
  80.    --  Function used by custom filters 
  81.  
  82.    function Get_Type return GType; 
  83.    --  Return the internal value associated with a Gtk_File_Filter 
  84.  
  85.    procedure Gtk_New    (Filter : out Gtk_File_Filter); 
  86.    procedure Initialize (Filter : access Gtk_File_Filter_Record'Class); 
  87.    --  Creates a new Gtk_File_Filter with no rules added to it. Such a filter 
  88.    --  doesn't accept any files, so is not particularly useful until you add 
  89.    --  rules with Add_Mime_Type, Add_Pattern, or Add_Custom. To create a filter 
  90.    --  that accepts any file, use: 
  91.    --      Gtk_New (Filter); 
  92.    --      Add_Pattern (Filter, "*"); 
  93.  
  94.    procedure Set_Name 
  95.      (Filter : access Gtk_File_Filter_Record; Name : String); 
  96.    function Get_Name (Filter : access Gtk_File_Filter_Record) return String; 
  97.    --  Sets the human-readable name of the filter; this is the string 
  98.    --  that will be displayed in the file selector user interface if 
  99.    --  there is a selectable list of filters. 
  100.  
  101.    procedure Add_Mime_Type 
  102.      (Filter    : access Gtk_File_Filter_Record; 
  103.       Mime_Type : String); 
  104.    --  Adds a rule allowing a given mime type to Filter. 
  105.    --  In particular, if you want to show directories only and not files, you 
  106.    --  could use "x-directory/normal" as the Mime type 
  107.  
  108.    procedure Add_Pattern 
  109.      (Filter  : access Gtk_File_Filter_Record; 
  110.       Pattern : String); 
  111.    --  Adds a rule allowing a shell style glob to a filter. 
  112.  
  113.    procedure Add_Pixbuf_Formats 
  114.      (Filter : access Gtk_File_Filter_Record); 
  115.    --  Adds a rule allowing image files in the formats supported 
  116.    --  by Gdk_Pixbuf. 
  117.  
  118.    procedure Add_Custom 
  119.      (Filter : access Gtk_File_Filter_Record; 
  120.       Needed : File_Filter_Flags; 
  121.       Func   : File_Filter_Func; 
  122.       Data   : System.Address := System.Null_Address; 
  123.       Notify : G_Destroy_Notify_Address := null); 
  124.    --  Adds rule to a filter that allows files based on a custom callback 
  125.    --  function. The bitfield Needed which is passed in provides information 
  126.    --  about what sorts of information that the filter function needs; 
  127.    --  this allows GTK+ to avoid retrieving expensive information when 
  128.    --  it isn't needed by the filter. 
  129.    --  Notify is called when Data is no longer needed and should be freed. 
  130.  
  131. private 
  132.    type Gtk_File_Filter_Record is 
  133.      new Glib.Object.GObject_Record with null record; 
  134.  
  135.    pragma Import (C, Get_Type, "gtk_file_filter_get_type"); 
  136. end Gtk.File_Filter; 
  137.  
  138. --  No binding: gtk_file_filter_filter 
  139. --  No binding: gtk_file_filter_get_needed