/* 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.

_PINCLUDE(glibmm/private/object_p.h)

#include <gtkmm/treeiter.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treesortable.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>

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

namespace Gtk
{

/** A wrapper which makes an underlying Gtk::TreeModel sortable.
 *
 * The TreeModelSort is a model which implements the TreeSortable interface.
 * It does not hold any data itself, but rather is created with
 * a child model and proxies its data.  It has identical column types to
 * this child model, and the changes in the child are propagated.  The
 * primary purpose of this model is to provide a way to sort a different
 * model without modifying it. Note that the sort function used by
 * TreeModelSort is not guaranteed to be stable.
 *
 * For instance, you might create two TreeView widgets each with a
 * view of the same data.  If the model is wrapped by a
 * TreeModelSort then the two TreeViews can each sort their
 * view of the data without affecting the other.  By contrast, if we
 * simply put the same model in each widget, then sorting the first would
 * sort the second.
 *
 * @ingroup TreeView
 * @deprecated 4.10: Use Gtk::SortListModel instead.
 */
class GTKMM_API TreeModelSort :
  public Glib::Object,
  public TreeModel,
  public TreeSortable,
  public TreeDragSource
{
  _CLASS_GOBJECT(TreeModelSort, GtkTreeModelSort, GTK_TREE_MODEL_SORT, Glib::Object, GObject, , , GTKMM_API)
  _IMPLEMENTS_INTERFACE(TreeModel)
  _IMPLEMENTS_INTERFACE(TreeSortable)
  _IMPLEMENTS_INTERFACE(TreeDragSource)

protected:
  _WRAP_CTOR(TreeModelSort(const Glib::RefPtr<TreeModel>& model), gtk_tree_model_sort_new_with_model)

public:
  _WRAP_CREATE(const Glib::RefPtr<TreeModel>& model)

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

  _WRAP_METHOD(Path convert_child_path_to_path(const Path& child_path) const, gtk_tree_model_sort_convert_child_path_to_path)

  /** 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);

  /** 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.
   */
  const_iterator convert_child_iter_to_iter(const const_iterator& child_iter) const;
  _IGNORE(gtk_tree_model_sort_convert_child_iter_to_iter)

  _WRAP_METHOD(Path convert_path_to_child_path(const Path& sorted_path) const, gtk_tree_model_sort_convert_path_to_child_path)

  /** Gets an iterator that points to the child row that corresponds to the sorted row pointed at by sorted_iter.
   *
   * @param sorted_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& sorted_iter);

  /** Gets an iterator that points to the child row that corresponds to the sorted row pointed at by sorted_iter.
   *
   * @param sorted_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.
   */
  const_iterator convert_iter_to_child_iter(const const_iterator& sorted_iter) const;
  _IGNORE(gtk_tree_model_sort_convert_iter_to_child_iter)

  _WRAP_METHOD(void reset_default_sort_func(), gtk_tree_model_sort_reset_default_sort_func)
  _WRAP_METHOD(void clear_cache(), gtk_tree_model_sort_clear_cache)

  _WRAP_METHOD(bool iter_is_valid(const const_iterator& iter) const, gtk_tree_model_sort_iter_is_valid)

  _WRAP_PROPERTY("model", Glib::RefPtr<TreeModel>)

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

} // namespace Gtk
