/* Copyright (C) 1998-2002 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or(at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

_DEFS(gtkmm,gtk)
_CONFIGINCLUDE(gtkmmconfig.h)
_IS_DEPRECATED // The entire file is deprecated.

#include <gtkmm/treeiter.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treedragsource.h>
// We couldn't include it in treemodel.h, but doing it here makes it easier for people.
#include <gtkmm/treepath.h>

_PINCLUDE(glibmm/private/object_p.h)

#m4 _PUSH(SECTION_CC_PRE_INCLUDES)
#undef GTK_DISABLE_DEPRECATED
#define GDK_DISABLE_DEPRECATION_WARNINGS 1
#m4 _POP()

namespace Gtk
{

/** A Gtk::TreeModel which hides parts of an underlying tree model.
 *
 * A %Gtk::TreeModelFilter is a tree model which wraps another tree model.
 *
 * @ingroup TreeView
 * @deprecated 4.10: Use Gtk::FilterListModel instead.
 */
class GTKMM_API TreeModelFilter :
  public Glib::Object,
  public TreeModel,
  public TreeDragSource
{
  _CLASS_GOBJECT(TreeModelFilter, GtkTreeModelFilter, GTK_TREE_MODEL_FILTER, Glib::Object, GObject, , , GTKMM_API)
  _IMPLEMENTS_INTERFACE(TreeModel)
  _IMPLEMENTS_INTERFACE(TreeDragSource)

protected:

  explicit TreeModelFilter(const Glib::RefPtr<TreeModel>& child_model);
  explicit TreeModelFilter(const Glib::RefPtr<TreeModel>& child_model, const TreeModel::Path& virtual_root);
  dnl // Don't _IGNORE(gtk_tree_model_filter_new). It's listed in gtk_methods.defs as
  dnl // a method of GtkTreeModel. Ignoring it would make gmmproc think that this
  dnl // file wraps GtkTreeModel, and it would list all GtkTreeModel methods as unwrapped.

public:

  /** This creates a TreeModelFilter with @a child_model as the child model.
   * You can use set_visible_func(), set_visible_column() and/or set_modify_func() to change the mapping of child
   * model to parent model.
   */
  _WRAP_CREATE(const Glib::RefPtr<TreeModel>& child_model)

  /** This creates a TreeModelFilter with @a child_model as the child model, and @a root as the virtual root.
   * You can use set_visible_func(), set_visible_column() and/or set_modify_func() to change the mapping of child
   * model to parent model.
   */
  _WRAP_CREATE(const Glib::RefPtr<TreeModel>& child_model, const TreeModel::Path& virtual_root)


  /** For instance,
   * bool on_visible(const TreeModel::const_iterator& iter);
   * This should return true if the given row should be visible and false otherwise.
   */
  typedef sigc::slot<bool(const TreeModel::const_iterator&)> SlotVisible;

  /** Sets the "visible" callback used when filtering the filter.
   * The callback function should return true if the given row should be visible and false otherwise.
   *
   * @param slot A callback slot which determines whether the row should be visible.
   */
  void set_visible_func(const SlotVisible& slot);
  _IGNORE(gtk_tree_model_filter_set_visible_func)

  //TODO: It would be nicer to use "const TreeModelColumnBase& column" instead of "int column",
  //but how can we get the TreeModelColumnBase from the int in the SignalProxy?
  //Maybe we could pass the ColumnsRecord to set_modify_func() and store it in the proxy? murrayc.
  /** For instance,
   *   void on_modify(const Gtk::TreeModel::iterator& iter, Glib::ValueBase& value, int column);
   *
   * where iter is an iterator to a row in the child model,
   * value is an output parameter in which you must store the value to be used in the parent model's row,
   * column is the column in the parent row whose row value you must provide in the value output paramater.
   */
  typedef sigc::slot<void(const Gtk::TreeModel::iterator& /* iter */, Glib::ValueBase& /* value */, int /* column */)> SlotModify;

  /** Specify columns that will be provided by this model, and a callback that will provide data for these
   * columns based on data in the columns of the child model.
   * The modify function will get called for each data access.
   *
   * @param columns Column types for this model (which will be exposed to the parent model/view).
   * @param slot A callback which will be called for each data access.
   */
  void set_modify_func(const TreeModelColumnRecord& columns, const SlotModify& slot);
  _IGNORE(gtk_tree_model_filter_set_modify_func)

  _WRAP_METHOD(void set_visible_column(const TreeModelColumnBase& column), gtk_tree_model_filter_set_visible_column)
  _WRAP_METHOD(void set_visible_column(int column), gtk_tree_model_filter_set_visible_column)

  _WRAP_METHOD(Glib::RefPtr<TreeModel> get_model(), gtk_tree_model_filter_get_model, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const TreeModel> get_model() const, gtk_tree_model_filter_get_model, refreturn, constversion)

  /** Gets an iterator that points to the filtered row that corresponds to the child row pointed at by child_iter.
   *
   * @param child_iter A valid iterator pointing to a row on the child model.
   * @result A valid iterator that points to the row in this filtered model.
   */
  iterator convert_child_iter_to_iter(const iterator& child_iter);

  /** Gets an iterator that points to the filtered row that corresponds to the child row pointed at by child_iter.
   *
   * @param child_iter A valid iterator pointing to a row on the child model.
   * @result A valid iterator that points to the row in this filtered model.
   */
  const_iterator convert_child_iter_to_iter(const const_iterator& child_iter) const;
  _IGNORE(gtk_tree_model_filter_convert_child_iter_to_iter)

  /** Gets an iterator that points to the child row that corresponds to the filtered row pointed at by sorted_iter.
   *
   * @param filter_iter A valid iterator pointing to a row on the filtered model.
   * @result A valid iterator that points to the row in the child model.
   */
  iterator convert_iter_to_child_iter(const iterator& filter_iter);

  /** Gets an iterator that points to the child row that corresponds to the filtered row pointed at by sorted_iter.
   *
   * @param filter_iter A valid iterator pointing to a row on the filtered model.
   * @result A valid iterator that points to the row in the child model.
   */
  const_iterator convert_iter_to_child_iter(const const_iterator& filter_iter) const;
  _IGNORE(gtk_tree_model_filter_convert_iter_to_child_iter)

  _WRAP_METHOD(Path convert_child_path_to_path(const Path& child_path) const, gtk_tree_model_filter_convert_child_path_to_path)
  _WRAP_METHOD(Path convert_path_to_child_path(const Path& filter_path) const, gtk_tree_model_filter_convert_path_to_child_path)

  _WRAP_METHOD(void refilter(), gtk_tree_model_filter_refilter)
  _WRAP_METHOD(void clear_cache(), gtk_tree_model_filter_clear_cache)

  _WRAP_PROPERTY("child-model", Glib::RefPtr<TreeModel>)
  _WRAP_PROPERTY("virtual-root", TreeModel::Path)

protected:
  void set_value_impl(const iterator& row, int column, const Glib::ValueBase& value) override;
};

} // namespace Gtk
