/* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
 */

#include <gtkmm/widget.h>
#include <giomm/listmodel.h>
#include <gtkmm/selectionmodel.h>
#include <gtkmm/columnviewcolumn.h>
#include <gtkmm/scrollable.h>
#include <gtkmm/scrollinfo.h>
#include <gtkmm/listitemfactory.h>

_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/widget_p.h)

namespace Gtk
{

/** A widget for displaying lists in multiple columns.
 *
 * %Gtk::ColumnView is a widget to present a view into a large dynamic list of items
 * using multiple columns with headers.
 *
 * %Gtk::ColumnView uses the factories of its columns to generate a cell widget for
 * each column, for each visible item and displays them together as the row for
 * this item. The property_show_row_separators() and
 * property_show_column_separators() properties offer a simple way to display
 * separators between the rows or columns.
 *
 * %Gtk::ColumnView allows the user to select items according to the selection
 * characteristics of the model. For models that allow multiple selected items,
 * it is possible to turn on *rubberband selection*, using set_enable_rubberband().
 *
 * The column view supports sorting that can be customized by the user by
 * clicking on column headers. To set this up, the Gtk::Sorter returned by
 * get_sorter() must be attached to a sort model for the data
 * that the view is showing, and the columns must have sorters attached to them
 * by calling Gtk::ColumnViewColumn::set_sorter(). The initial sort order can be
 * set with sort_by_column().
 *
 * The column view also supports interactive resizing and reordering of
 * columns, via Drag-and-Drop of the column headers. This can be enabled or
 * disabled with the property_reorderable() and
 * Gtk::ColumnViewColumn::property_resizable() properties.
 *
 * @see Gtk::ColumnViewColumn, Gtk::TreeView
 *
 * @ingroup Widgets
 * @ingroup ListView
 *
 * @newin{3,98}
 */
class GTKMM_API ColumnView : public Widget, public Scrollable
{
  _CLASS_GTKOBJECT(ColumnView, GtkColumnView, GTK_COLUMN_VIEW, Gtk::Widget, GtkWidget, , , GTKMM_API)
  _IMPLEMENTS_INTERFACE(Scrollable)
  _STRUCT_NOT_HIDDEN

public:
  _WRAP_CTOR(ColumnView(const Glib::RefPtr<SelectionModel>& model = {}), gtk_column_view_new)

  _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> get_columns(), gtk_column_view_get_columns, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> get_columns() const, gtk_column_view_get_columns, refreturn, constversion)
#m4 _CONVERSION(`const Glib::RefPtr<ColumnViewColumn>&', `GtkColumnViewColumn*', __CONVERT_REFPTR_TO_P)
  _WRAP_METHOD(void append_column(const Glib::RefPtr<ColumnViewColumn>& column), gtk_column_view_append_column)
  _WRAP_METHOD(void remove_column(const Glib::RefPtr<ColumnViewColumn>& column), gtk_column_view_remove_column)
  _WRAP_METHOD(void insert_column(guint position, const Glib::RefPtr<ColumnViewColumn>& column), gtk_column_view_insert_column)

  _WRAP_METHOD(Glib::RefPtr<SelectionModel> get_model(), gtk_column_view_get_model, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const SelectionModel> get_model() const, gtk_column_view_get_model, refreturn, constversion)
  _WRAP_METHOD(void set_model(const Glib::RefPtr<SelectionModel>& model), gtk_column_view_set_model)

  _WRAP_METHOD(bool get_show_row_separators() const, gtk_column_view_get_show_row_separators)
  _WRAP_METHOD(void set_show_row_separators(bool show_separators = true), gtk_column_view_set_show_row_separators)

  _WRAP_METHOD(bool get_show_column_separators() const, gtk_column_view_get_show_column_separators)
  _WRAP_METHOD(void set_show_column_separators(bool show_separators = true), gtk_column_view_set_show_column_separators)

  _WRAP_METHOD(Glib::RefPtr<Sorter> get_sorter(), gtk_column_view_get_sorter, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Sorter> get_sorter() const, gtk_column_view_get_sorter, refreturn, constversion)
  _WRAP_METHOD(void sort_by_column(const Glib::RefPtr<ColumnViewColumn>& column, SortType direction), gtk_column_view_sort_by_column)

  _WRAP_METHOD(void set_single_click_activate(bool single_click_activate = true), gtk_column_view_set_single_click_activate)
  _WRAP_METHOD(bool get_single_click_activate() const, gtk_column_view_get_single_click_activate)
  _WRAP_METHOD(void set_reorderable(bool reorderable = true), gtk_column_view_set_reorderable)
  _WRAP_METHOD(bool get_reorderable() const, gtk_column_view_get_reorderable)
  _WRAP_METHOD(void set_enable_rubberband(bool enable_rubberband = true), gtk_column_view_set_enable_rubberband)
  _WRAP_METHOD(bool get_enable_rubberband() const, gtk_column_view_get_enable_rubberband)
  _WRAP_METHOD(void set_tab_behavior(ListTabBehavior tab_behavior), gtk_column_view_set_tab_behavior)
  _WRAP_METHOD(ListTabBehavior get_tab_behavior() const, gtk_column_view_get_tab_behavior)
  _WRAP_METHOD(void set_row_factory(const Glib::RefPtr<ListItemFactory>& factory), gtk_column_view_set_row_factory)
  _WRAP_METHOD(Glib::RefPtr<ListItemFactory> get_row_factory(), gtk_column_view_get_row_factory, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const ListItemFactory> get_row_factory() const, gtk_column_view_get_row_factory, refreturn, constversion)
  _WRAP_METHOD(void set_header_factory(const Glib::RefPtr<ListItemFactory>& factory), gtk_column_view_set_header_factory)
  _WRAP_METHOD(Glib::RefPtr<ListItemFactory> get_header_factory(), gtk_column_view_get_header_factory, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const ListItemFactory> get_header_factory() const, gtk_column_view_get_header_factory, refreturn, constversion)

  // gtk_column_view_scroll_to() does not take a ref (transfer full).
#m4 _CONVERSION(`const Glib::RefPtr<const ScrollInfo>&', `GtkScrollInfo*', `const_cast<GtkScrollInfo*>(Glib::unwrap_copy($3))')
  _WRAP_METHOD(void scroll_to(guint pos,
                              const Glib::RefPtr<ColumnViewColumn>& column = {},
                              ListScrollFlags flags = ListScrollFlags::NONE,
                              const Glib::RefPtr<const ScrollInfo>& scroll = {}),
               gtk_column_view_scroll_to)

  _WRAP_PROPERTY("columns", Glib::RefPtr<Gio::ListModel>)
  _WRAP_PROPERTY("model", Glib::RefPtr<SelectionModel>)
  _WRAP_PROPERTY("show-row-separators", bool)
  _WRAP_PROPERTY("show-column-separators", bool)
  _WRAP_PROPERTY("sorter", Glib::RefPtr<Sorter>)
  _WRAP_PROPERTY("single-click-activate", bool)
  _WRAP_PROPERTY("tab-behavior", ListTabBehavior)
  _WRAP_PROPERTY("reorderable", bool)
  _WRAP_PROPERTY("row-factory", Glib::RefPtr<ListItemFactory>)
  _WRAP_PROPERTY("header-factory", Glib::RefPtr<ListItemFactory>)
  _WRAP_PROPERTY("enable-rubberband", bool)

  _WRAP_SIGNAL(void activate(guint pos), "activate", no_default_handler)
};

} // namespace Gtk
