Debian Codegraph @

gtk/src/recentchooser.ccg

raw
1 /* Copyright (C) 2006 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 <glibmm/vectorutils.h>
18
19 #include <gtk/gtk.h>
20
21 // This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.
22
23 static int SignalProxy_Compare_gtk_callback(GtkRecentInfo* a, GtkRecentInfo* b, gpointer data)
24 {
25 const auto the_slot = static_cast<Gtk::RecentChooser::SlotCompare*>(data);
26
27 try
28 {
29 return (*the_slot)(Glib::wrap(a, true /* take reference */), Glib::wrap(b, true /* take reference */));
30 }
31 catch(...)
32 {
33 Glib::exception_handlers_invoke();
34 }
35
36 return 0;
37 }
38
39 static void SignalProxy_Compare_gtk_callback_destroy(gpointer data)
40 {
41 delete static_cast<Gtk::RecentChooser::SlotCompare*>(data);
42 }
43
44
45 namespace Gtk
46 {
47
48 void RecentChooser::set_sort_func(const SlotCompare& slot)
49 {
50 auto slot_copy = new SlotCompare(slot);
51
52 gtk_recent_chooser_set_sort_func(
53 gobj(),
54 &SignalProxy_Compare_gtk_callback, slot_copy,
55 &SignalProxy_Compare_gtk_callback_destroy);
56 }
57
58 std::vector<Glib::ustring> RecentChooser::get_uris() const
59 {
60 return Glib::ArrayHandler<Glib::ustring>::array_to_vector(gtk_recent_chooser_get_uris(const_cast<GtkRecentChooser*>(gobj()), nullptr), Glib::OWNERSHIP_DEEP);
61 }
62
63 void RecentChooser::unset_limit()
64 {
65 gtk_recent_chooser_set_limit(gobj(), -1 /* See C docs */);
66 }
67
68 } // namespace Gtk