add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / filefilter.ccg
1 // -*- c++ -*-
2 /* $Id: filefilter.ccg,v 1.8 2006/05/11 11:40:24 murrayc Exp $ */
3
4 /* Copyright 2003 The gtkmm Development Team
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library 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  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include <gtk/gtkfilefilter.h>
22 #include <gtk/gtktypebuiltins.h> //For gtk_file_filter_flags_get_type().
23
24 static gboolean SignalProxy_Custom_gtk_callback(const GtkFileFilterInfo* filter_info, gpointer data)
25 {
26   Gtk::FileFilter::SlotCustom* the_slot = static_cast<Gtk::FileFilter::SlotCustom*>(data);
27
28   #ifdef GLIBMM_EXCEPTIONS_ENABLED
29   try
30   {
31   #endif //GLIBMM_EXCEPTIONS_ENABLED
32     //Create a suitable C++ instance to pass to the C++ method:
33     Gtk::FileFilter::Info cppInfo;
34     cppInfo.contains = (Gtk::FileFilterFlags)filter_info->contains;
35     cppInfo.filename = Glib::convert_const_gchar_ptr_to_ustring(filter_info->filename);
36     cppInfo.uri = Glib::convert_const_gchar_ptr_to_ustring(filter_info->uri);
37     cppInfo.display_name = Glib::convert_const_gchar_ptr_to_ustring(filter_info->display_name);
38     cppInfo.mime_type = Glib::convert_const_gchar_ptr_to_ustring(filter_info->mime_type);
39   
40     return (*the_slot)(cppInfo);
41   #ifdef GLIBMM_EXCEPTIONS_ENABLED
42   }
43   catch(...)
44   {
45     Glib::exception_handlers_invoke();
46     return false; //arbitrary default;
47   }
48   #endif //GLIBMM_EXCEPTIONS_ENABLED
49 }
50
51 static void SignalProxy_Custom_gtk_callback_destroy(void* data)
52 {
53   delete static_cast<Gtk::FileFilter::SlotCustom*>(data);
54 }
55
56
57 namespace Gtk
58 {
59
60 void FileFilter::add_custom(FileFilterFlags needed, const SlotCustom& slot)
61 {
62   //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
63   //It will be deleted when SignalProxy_Custom::gtk_callback_destroy() is called.
64   SlotCustom* slot_copy = new SlotCustom(slot);
65       
66   gtk_file_filter_add_custom(gobj(), (GtkFileFilterFlags)needed,
67                              &SignalProxy_Custom_gtk_callback,
68                              slot_copy,
69                              &SignalProxy_Custom_gtk_callback_destroy);     
70 }
71  
72 } // namespace Gtk
73