Debian Codegraph @

gtk/src/filefilter.ccg

raw
1 /* Copyright (C) 2003 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <gtk/gtk.h> //For gtk_file_filter_flags_get_type().
18
19 static gboolean SignalProxy_Custom_gtk_callback(const GtkFileFilterInfo* filter_info, gpointer data)
20 {
21 auto the_slot = static_cast<Gtk::FileFilter::SlotCustom*>(data);
22
23 try
24 {
25 //Create a suitable C++ instance to pass to the C++ method:
26 Gtk::FileFilter::Info cppInfo;
27 cppInfo.contains = (Gtk::FileFilterFlags)filter_info->contains;
28 cppInfo.filename = Glib::convert_const_gchar_ptr_to_ustring(filter_info->filename);
29 cppInfo.uri = Glib::convert_const_gchar_ptr_to_ustring(filter_info->uri);
30 cppInfo.display_name = Glib::convert_const_gchar_ptr_to_ustring(filter_info->display_name);
31 cppInfo.mime_type = Glib::convert_const_gchar_ptr_to_ustring(filter_info->mime_type);
32
33 return (*the_slot)(cppInfo);
34 }
35 catch(...)
36 {
37 Glib::exception_handlers_invoke();
38 return false; //arbitrary default;
39 }
40 }
41
42 static void SignalProxy_Custom_gtk_callback_destroy(void* data)
43 {
44 delete static_cast<Gtk::FileFilter::SlotCustom*>(data);
45 }
46
47
48 namespace Gtk
49 {
50
51 void FileFilter::add_custom(FileFilterFlags needed, const SlotCustom& slot)
52 {
53 //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
54 //It will be deleted when SignalProxy_Custom::gtk_callback_destroy() is called.
55 auto slot_copy = new SlotCustom(slot);
56
57 gtk_file_filter_add_custom(gobj(), (GtkFileFilterFlags)needed,
58 &SignalProxy_Custom_gtk_callback,
59 slot_copy,
60 &SignalProxy_Custom_gtk_callback_destroy);
61 }
62
63 } // namespace Gtk