| 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 |
#include <gtkmm/treeiter.h> |
| 18 |
#include <gtkmm/treemodel.h> |
| 19 |
// We couldn't include it in treemodel.h, but doing it here makes it easier for people. |
| 20 |
#include <gtkmm/treepath.h> |
| 21 |
|
| 22 |
_DEFS(gtkmm,gtk) |
| 23 |
_PINCLUDE(glibmm/private/object_p.h) |
| 24 |
|
| 25 |
namespace Gtk |
| 26 |
{ |
| 27 |
|
| 28 |
/** |
| 29 |
* @ingroup TreeView |
| 30 |
* |
| 31 |
*/ |
| 32 |
class GTKMM_API TreeModelFilter : |
| 33 |
public Glib::Object, |
| 34 |
public TreeModel |
| 35 |
{ |
| 36 |
_CLASS_GOBJECT(TreeModelFilter, GtkTreeModelFilter, GTK_TREE_MODEL_FILTER, Glib::Object, GObject, , , GTKMM_API) |
| 37 |
_IMPLEMENTS_INTERFACE(TreeModel) |
| 38 |
|
| 39 |
protected: |
| 40 |
|
| 41 |
explicit TreeModelFilter(const Glib::RefPtr<TreeModel>& child_model); |
| 42 |
explicit TreeModelFilter(const Glib::RefPtr<TreeModel>& child_model, const TreeModel::Path& virtual_root); |
| 43 |
dnl // Don't _IGNORE(gtk_tree_model_filter_new). It's listed in gtk_methods.defs as |
| 44 |
dnl // a method of GtkTreeModel. Ignoring it would make gmmproc think that this |
| 45 |
dnl // file wraps GtkTreeModel, and it would list all GtkTreeModel methods as unwrapped. |
| 46 |
|
| 47 |
public: |
| 48 |
|
| 49 |
/** This creates a TreeModelFilter with @a child_model as the child model. |
| 50 |
* You can use set_visible_func(), set_visible_column() and/or set_modify_func() to change the mapping of child |
| 51 |
* model to parent model. |
| 52 |
*/ |
| 53 |
_WRAP_CREATE(const Glib::RefPtr<TreeModel>& child_model) |
| 54 |
|
| 55 |
/** This creates a TreeModelFilter with @a child_model as the child model, and @a root as the virtual root. |
| 56 |
* You can use set_visible_func(), set_visible_column() and/or set_modify_func() to change the mapping of child |
| 57 |
* model to parent model. |
| 58 |
*/ |
| 59 |
_WRAP_CREATE(const Glib::RefPtr<TreeModel>& child_model, const TreeModel::Path& virtual_root) |
| 60 |
|
| 61 |
|
| 62 |
/** For instance, |
| 63 |
* bool on_visible(const TreeModel::const_iterator& iter); |
| 64 |
* This should return true if the given row should be visible and false otherwise. |
| 65 |
*/ |
| 66 |
typedef sigc::slot<bool, const TreeModel::const_iterator&> SlotVisible; |
| 67 |
|
| 68 |
/** Sets the "visible" callback used when filtering the filter. |
| 69 |
* The callback function should return true if the given row should be visible and false otherwise. |
| 70 |
* |
| 71 |
* @param slot A callback slot which determines whether the row should be visible. |
| 72 |
*/ |
| 73 |
void set_visible_func(const SlotVisible& slot); |
| 74 |
_IGNORE(gtk_tree_model_filter_set_visible_func) |
| 75 |
|
| 76 |
//TODO: It would be nicer to use "const TreeModelColumnBase& column" instead of "int column", |
| 77 |
//but how can we get the TreeModelColumnBase from the int in the SignalProxy? |
| 78 |
//Maybe we could pass the ColumnsRecord to set_modify_func() and store it in the proxy? murrayc. |
| 79 |
/** For instance, |
| 80 |
* void on_modify(const Gtk::TreeModel::iterator& iter, Glib::ValueBase& value, int column); |
| 81 |
* |
| 82 |
* where iter is an iterator to a row in the child model, |
| 83 |
* value is an output parameter in which you must store the value to be used in the parent model's row, |
| 84 |
* column is the column in the parent row whose row value you must provide in the value output paramater. |
| 85 |
*/ |
| 86 |
typedef sigc::slot<void, const Gtk::TreeModel::iterator& /* iter */, Glib::ValueBase& /* value */, int /* column */> SlotModify; |
| 87 |
|
| 88 |
/** Specify columns that will be provided by this model, and a callback that will provide data for these |
| 89 |
* columns based on data in the columns of the child model. |
| 90 |
* The modify function will get called for each data access. |
| 91 |
* |
| 92 |
* @param columns Column types for this model (which will be exposed to the parent model/view). |
| 93 |
* @param slot A callback which will be called for each data access. |
| 94 |
*/ |
| 95 |
void set_modify_func(const TreeModelColumnRecord& columns, const SlotModify& slot); |
| 96 |
_IGNORE(gtk_tree_model_filter_set_modify_func) |
| 97 |
|
| 98 |
_WRAP_METHOD(void set_visible_column(const TreeModelColumnBase& column), gtk_tree_model_filter_set_visible_column) |
| 99 |
_WRAP_METHOD(void set_visible_column(int column), gtk_tree_model_filter_set_visible_column) |
| 100 |
|
| 101 |
_WRAP_METHOD(Glib::RefPtr<TreeModel> get_model(), gtk_tree_model_filter_get_model, refreturn) |
| 102 |
_WRAP_METHOD(Glib::RefPtr<const TreeModel> get_model() const, gtk_tree_model_filter_get_model, refreturn, constversion) |
| 103 |
|
| 104 |
/** Gets an iterator that points to the sorted row that corresponds to the child row pointed at by child_iter. |
| 105 |
* |
| 106 |
* @param child_iter A valid iterator pointing to a row on the child model. |
| 107 |
* @result A valid iterator that points to the row in this sorted model. |
| 108 |
*/ |
| 109 |
iterator convert_child_iter_to_iter(const iterator& child_iter) const; |
| 110 |
_IGNORE(gtk_tree_model_filter_convert_child_iter_to_iter) |
| 111 |
|
| 112 |
/** Gets an iterator that points to the child row that corresponds to the sorted row pointed at by sorted_iter. |
| 113 |
* |
| 114 |
* @param filter_iter A valid iterator pointing to a row on the sorted model. |
| 115 |
* @result A valid iterator that points to the row in the child model. |
| 116 |
*/ |
| 117 |
iterator convert_iter_to_child_iter(const iterator& filter_iter) const; |
| 118 |
_IGNORE(gtk_tree_model_filter_convert_iter_to_child_iter) |
| 119 |
|
| 120 |
_WRAP_METHOD(Path convert_child_path_to_path(const Path& child_path) const, gtk_tree_model_filter_convert_child_path_to_path) |
| 121 |
_WRAP_METHOD(Path convert_path_to_child_path(const Path& filter_path) const, gtk_tree_model_filter_convert_path_to_child_path) |
| 122 |
|
| 123 |
_WRAP_METHOD(void refilter(), gtk_tree_model_filter_refilter) |
| 124 |
_WRAP_METHOD(void clear_cache(), gtk_tree_model_filter_clear_cache) |
| 125 |
|
| 126 |
_WRAP_PROPERTY("child-model", Glib::RefPtr<TreeModel>) |
| 127 |
_WRAP_PROPERTY("virtual-root", TreeModel::Path) |
| 128 |
|
| 129 |
protected: |
| 130 |
void set_value_impl(const iterator& row, int column, const Glib::ValueBase& value) override; |
| 131 |
}; |
| 132 |
|
| 133 |
} // namespace Gtk |