/* $Id: treemodelfilter.hg,v 1.16 2006/04/12 11:11:25 murrayc Exp $ */

/* 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 Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

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

_DEFS(gtkmm,gtk)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gtk
{

/** 
 * @ingroup TreeView
 * 
 */
class TreeModelFilter :
  public Glib::Object,
  public TreeModel
{
  _CLASS_GOBJECT(TreeModelFilter, GtkTreeModelFilter, GTK_TREE_MODEL_FILTER, Glib::Object, GObject)
  _IMPLEMENTS_INTERFACE(TreeModel)

protected:

  explicit TreeModelFilter(const Glib::RefPtr<TreeModel>& child_model);
  explicit TreeModelFilter(const Glib::RefPtr<TreeModel>& child_model, const TreeModel::Path& virtual_root);
  _IGNORE(gtk_tree_model_filter_new)

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 sorted 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 sorted model.
   */
  iterator convert_child_iter_to_iter(const iterator& child_iter) const;

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

  //TODO: Remove these deprecated non-const versions when we can break ABI:
  _WRAP_METHOD(Path convert_child_path_to_path(const Path& child_path), gtk_tree_model_filter_convert_child_path_to_path, deprecated "Use convert_child_path_to_path(const Path& child_path) const")

  _WRAP_METHOD(Path convert_path_to_child_path(const Path& filter_path), gtk_tree_model_filter_convert_path_to_child_path, deprecated "convert_path_to_child_path(const Path& filter_path) const")

  _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)

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

} // namespace Gtk

