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

_CONFIGINCLUDE(gtkmmconfig.h)

#include <gtkmm/widget.h>
#include <gtkmm/treelistrow.h>

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

namespace Gtk
{

/** An indenting expander button for use in a tree list.
 *
 * %Gtk::TreeExpander is a widget that provides an expander for a list.
 *
 * It is typically placed as a bottommost child into a Gtk::ListView to allow
 * users to expand and collapse children in a list with a Gtk::TreeListModel.
 * It will provide the common UI elements, gestures and keybindings for this
 * purpose.
 *
 * On top of this, the "listitem.expand", "listitem.collapse" and
 * "listitem.toggle-expand" actions are provided to allow adding custom UI
 * for managing expanded state.
 *
 * The Gtk::TreeListModel must be set to not be passthrough. Then it will provide
 * Gtk::TreeListRow items which can be set via set_list_row()
 * on the expander. The expander will then watch that row item automatically.  
 * set_child() sets the widget that displays the actual row contents.
 *
 * %Gtk::TreeExpander can be modified with properties such as
 * property_indent_for_icon(), property_indent_for_depth(), and
 * property_hide_expander() to achieve a different appearance.
 * This can even be done to influence individual rows, for example by binding
 * property_hide_expander() to the item count of the model of the treelistrow,
 * to hide the expander for rows without children, even if the row is expandable.
 *
 * @see Gtk::TreeListModel
 * @ingroup ListView
 *
 * @newin{3,98}
 */
class GTKMM_API TreeExpander : public Widget
{
  _CLASS_GTKOBJECT(TreeExpander, GtkTreeExpander, GTK_TREE_EXPANDER, Gtk::Widget, GtkWidget, , , GTKMM_API)
  _DO_NOT_DERIVE_GTYPE dnl// GtkTreeExpander is a final type
  _ABI_AS_WITH_DERIVED_GTYPE dnl// Remove when we can break ABI
  _STRUCT_NOT_HIDDEN

public:
  _CTOR_DEFAULT()

  _WRAP_METHOD(Widget* get_child(), gtk_tree_expander_get_child)
  _WRAP_METHOD(const Widget* get_child() const, gtk_tree_expander_get_child, constversion)
  _WRAP_METHOD(void set_child(Widget& widget), gtk_tree_expander_set_child)
  /** Removes the content widget to display.
   */
  void unset_child();

#m4 _CONVERSION(`gpointer',`Glib::RefPtr<Glib::ObjectBase>',`Glib::make_refptr_for_instance<Glib::ObjectBase>(Glib::wrap_auto(G_OBJECT($3)))')
  _WRAP_METHOD(Glib::RefPtr<Glib::ObjectBase> get_item(), gtk_tree_expander_get_item)
  _WRAP_METHOD(Glib::RefPtr<const Glib::ObjectBase> get_item() const, gtk_tree_expander_get_item, constversion)

  _WRAP_METHOD(Glib::RefPtr<TreeListRow> get_list_row(), gtk_tree_expander_get_list_row, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const TreeListRow> get_list_row() const, gtk_tree_expander_get_list_row, refreturn, constversion)
  _WRAP_METHOD(void set_list_row(const Glib::RefPtr<TreeListRow>& list_row), gtk_tree_expander_set_list_row)
  /** Removes the tree list row that this expander should manage.
   */
  void unset_list_row();

  _WRAP_METHOD(bool get_indent_for_depth() const, gtk_tree_expander_get_indent_for_depth)
  _WRAP_METHOD(void set_indent_for_depth(bool indent_for_depth = true), gtk_tree_expander_set_indent_for_depth)
  _WRAP_METHOD(bool get_indent_for_icon() const, gtk_tree_expander_get_indent_for_icon)
  _WRAP_METHOD(void set_indent_for_icon(bool indent_for_icon = true), gtk_tree_expander_set_indent_for_icon)
  _WRAP_METHOD(bool get_hide_expander() const, gtk_tree_expander_get_hide_expander)
  _WRAP_METHOD(void set_hide_expander(bool hide_expander = true), gtk_tree_expander_set_hide_expander)

  _WRAP_PROPERTY("child", Widget*)
  _WRAP_PROPERTY("hide-expander", bool)
  _WRAP_PROPERTY("indent-for-depth", bool)
  _WRAP_PROPERTY("indent-for-icon", bool)
  _WRAP_PROPERTY("item", Glib::RefPtr<Glib::ObjectBase>)
  _WRAP_PROPERTY("list-row", Glib::RefPtr<TreeListRow>)
};

} // namespace Gtk
