Debian Codegraph @

gtk/src/treesortable.ccg

raw
1 /* Copyright (C) 1998-2002 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 static int SignalProxy_Compare_gtk_callback(GtkTreeModel* model, GtkTreeIter* lhs, GtkTreeIter* rhs, void* data)
18 {
19 auto the_slot = static_cast<Gtk::TreeSortable::SlotCompare*>(data);
20
21 try
22 {
23 // use Slot::operator()
24 return (*the_slot)(Gtk::TreeIter(model, lhs), Gtk::TreeIter(model, rhs));
25 }
26 catch(...)
27 {
28 Glib::exception_handlers_invoke();
29 }
30
31 return 0;
32 }
33
34 static void SignalProxy_Compare_gtk_callback_destroy(void* data)
35 {
36 delete static_cast<Gtk::TreeSortable::SlotCompare*>(data);
37 }
38
39 namespace Gtk
40 {
41
42 void TreeSortable::set_sort_func(int sort_column_id, const SlotCompare& slot)
43 {
44 auto slot_copy = new SlotCompare(slot);
45
46 gtk_tree_sortable_set_sort_func(
47 gobj(), sort_column_id,
48 &SignalProxy_Compare_gtk_callback, slot_copy,
49 &SignalProxy_Compare_gtk_callback_destroy);
50 }
51
52 void TreeSortable::set_sort_func(const Gtk::TreeModelColumnBase& sort_column, const SlotCompare& slot)
53 {
54 set_sort_func(sort_column.index(), slot);
55 }
56
57 void TreeSortable::set_default_sort_func(const SlotCompare& slot)
58 {
59 auto slot_copy = new SlotCompare(slot);
60
61 gtk_tree_sortable_set_default_sort_func(
62 gobj(),
63 &SignalProxy_Compare_gtk_callback, slot_copy,
64 &SignalProxy_Compare_gtk_callback_destroy);
65 }
66
67 void TreeSortable::unset_default_sort_func()
68 {
69 gtk_tree_sortable_set_default_sort_func(
70 gobj(), nullptr, nullptr, nullptr); /* See GTK+ docs about the nullptrs. */
71 }
72
73 } // namespace Gtk