Debian Codegraph @

gtk/src/treesortable.hg

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 // This is for including the config header before any code (such as
18 // the #ifndef GTKMM_DISABLE_DEPRECATED in deprecated classes) is generated:
19 _CONFIGINCLUDE(gtkmmconfig.h)
20
21 #include <glibmm/interface.h>
22 #include <gtkmm/enums.h>
23 #include <gtkmm/treemodelcolumn.h>
24 #include <gtkmm/treemodel.h>
25 #include <gtkmm/treeiter.h>
26
27 _DEFS(gtkmm,gtk)
28 _PINCLUDE(glibmm/private/interface_p.h)
29
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 extern "C"
32 {
33 typedef struct _GtkTreeSortableIface GtkTreeSortableIface;
34 }
35 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
36
37 namespace Gtk
38 {
39
40 //TODO: This should maybe derive from TreeModel, because it is a prerequisite. murrayc
41
42 /**
43 * @ingroup TreeView
44 */
45 class GTKMM_API TreeSortable : public Glib::Interface
46 {
47 _CLASS_INTERFACE(TreeSortable, GtkTreeSortable, GTK_TREE_SORTABLE, GtkTreeSortableIface, , , GTKMM_API)
48
49 public:
50
51 enum
52 {
53 /// See set_default_sort_func() and set_sort_column().
54 DEFAULT_SORT_COLUMN_ID = -1,
55 DEFAULT_UNSORTED_COLUMN_ID = -2
56 }; //See GTK+ implementation.
57
58 _WRAP_METHOD(bool get_sort_column_id(int& sort_column_id, SortType& order) const,
59 gtk_tree_sortable_get_sort_column_id)
60
61 _WRAP_METHOD(void set_sort_column(const TreeModelColumnBase& sort_column_id, SortType order),
62 gtk_tree_sortable_set_sort_column_id)
63 _WRAP_METHOD(void set_sort_column(int sort_column_id, SortType order),
64 gtk_tree_sortable_set_sort_column_id)
65
66 /** This callback should return -1 if a compares before b, 0 if they compare equal, 1 if a compares after b.
67 * For instance, int on_sort_compare(const Gtk::TreeModel::iterator& a, const Gtk::TreeModel::iterator& b);
68 */
69 typedef sigc::slot<int, const Gtk::TreeModel::iterator&, const Gtk::TreeModel::iterator&> SlotCompare;
70
71 _IGNORE(gtk_tree_sortable_set_sort_func, gtk_tree_sortable_set_default_sort_func)
72
73 /** Sets the comparison function used when sorting a certain column.
74 * If the current sort column is the same as @a sort_column, then the model will sort using this function.
75 * @param sort_column the sort column to set the function for
76 * @param slot The sorting slot callback.
77 */
78 void set_sort_func(const TreeModelColumnBase& sort_column, const SlotCompare& slot);
79
80 /** Sets the comparison function used when sorting a certain column.
81 * If the current sort column id is the same as @a sort_column_id, then the model will sort using this function.
82 * @param sort_column_id the sort column id to set the function for
83 * @param slot The sorting slot callback.
84 */
85 void set_sort_func(int sort_column_id, const SlotCompare& slot);
86
87 /** Sets the default comparison function used when sorting.
88 * If the current sort column id of sortable is DEFAULT_SORT_COLUMN_ID, then the model will
89 * sort using this function. See also unset_default_sort_func().
90 *
91 * @param slot The sorting function
92 */
93 void set_default_sort_func(const SlotCompare& slot);
94
95 /** Sets the default comparison function used when sorting. See set_default_sort_func().
96 *
97 * After calling this method there will be no default comparison function. This means that once the model has been sorted,
98 * it can't go back to the default state. In this case, when the current sort column id of sortable is
99 * DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
100 */
101 void unset_default_sort_func();
102
103 _WRAP_METHOD(bool has_default_sort_func() const, gtk_tree_sortable_has_default_sort_func)
104
105 _WRAP_METHOD(void sort_column_changed(), gtk_tree_sortable_sort_column_changed)
106 _WRAP_SIGNAL(void sort_column_changed(), "sort_column_changed")
107
108 protected:
109 _WRAP_VFUNC(bool get_sort_column_id(int* sort_column_id, SortType* order) const, get_sort_column_id)
110 _WRAP_VFUNC(void set_sort_column_id(int sort_column_id, SortType order), set_sort_column_id)
111 _WRAP_VFUNC(void set_sort_func(int sort_column_id, GtkTreeIterCompareFunc func, void* data, GDestroyNotify destroy), set_sort_func)
112 _WRAP_VFUNC(void set_default_sort_func(GtkTreeIterCompareFunc func, void* data, GDestroyNotify destroy), set_default_sort_func)
113 _WRAP_VFUNC(bool has_default_sort_func() const, has_default_sort_func)
114 _WRAP_VFUNC(void sort_column_changed() const, sort_column_changed)
115 };
116
117 } // namespace Gtk