/* Copyright (C) 2013 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/>.
 */

#include <gtkmm/widget.h>
#include <gtkmm/stackpage.h>
#include <gtkmm/enums.h>
#include <gtkmm/selectionmodel.h>

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

namespace Gtk
{
_CC_INCLUDE(gtk/gtk.h)

/** A container that shows only one child at a time.
 *
 * %Gtk::Stack does not provide a means for users to change the visible
 * child. Instead, the Gtk::StackSwitcher or Gtk::StackSidebar widget can be used with
 * %Gtk::Stack to provide this functionality.
 *
 * %Gtk::Stack maintains a Gtk::StackPage object for each added
 * child, which holds additional per-child properties. You
 * obtain the Gtk::StackPage for a child with get_page().
 *
 * @ingroup Widgets
 * @ingroup Containers
 * @newin{3,10}
 */
class GTKMM_API Stack
  : public Widget
{
  _CLASS_GTKOBJECT(Stack, GtkStack, GTK_STACK, Gtk::Widget, GtkWidget, , , GTKMM_API)
public:
  _CTOR_DEFAULT

  _WRAP_METHOD(Glib::RefPtr<StackPage> add(Widget& child), gtk_stack_add_child, refreturn)
  _WRAP_METHOD(Glib::RefPtr<StackPage> add(Widget& child, const Glib::ustring& name),
    gtk_stack_add_named, refreturn)
  _WRAP_METHOD(Glib::RefPtr<StackPage> add(Widget& child, const Glib::ustring& name,
    const Glib::ustring& title), gtk_stack_add_titled, refreturn)

  _WRAP_METHOD(void remove(Widget& child), gtk_stack_remove)

  _WRAP_METHOD(Glib::RefPtr<StackPage> get_page(Widget& child), gtk_stack_get_page, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const StackPage> get_page(const Widget& child) const, gtk_stack_get_page, refreturn)

  _WRAP_METHOD(void set_visible_child(Widget& child), gtk_stack_set_visible_child)
  _WRAP_METHOD(Widget* get_visible_child(), gtk_stack_get_visible_child)
  _WRAP_METHOD(const Widget* get_visible_child() const, gtk_stack_get_visible_child, constversion)

  _WRAP_METHOD(void set_visible_child(const Glib::ustring& name), gtk_stack_set_visible_child_name)
  _WRAP_METHOD(void set_visible_child(const Glib::ustring& name, StackTransitionType transition), gtk_stack_set_visible_child_full)
  _WRAP_METHOD(Glib::ustring get_visible_child_name() const, gtk_stack_get_visible_child_name)

  _WRAP_METHOD(void set_hhomogeneous(bool hhomogeneous = true), gtk_stack_set_hhomogeneous)
  _WRAP_METHOD(bool get_hhomogeneous() const, gtk_stack_get_hhomogeneous)

  _WRAP_METHOD(void set_vhomogeneous(bool vhomogeneous = true), gtk_stack_set_vhomogeneous)
  _WRAP_METHOD(bool get_vhomogeneous() const, gtk_stack_get_vhomogeneous)

  _WRAP_METHOD(void set_transition_duration(guint duration), gtk_stack_set_transition_duration)
  _WRAP_METHOD(guint get_transition_duration() const, gtk_stack_get_transition_duration)

  _WRAP_METHOD(void set_transition_type(StackTransitionType transition), gtk_stack_set_transition_type)
  _WRAP_METHOD(StackTransitionType get_transition_type() const, gtk_stack_get_transition_type)

  _WRAP_METHOD(bool get_transition_running() const, gtk_stack_get_transition_running)

  _WRAP_METHOD(Widget* get_child_by_name(const Glib::ustring& name), gtk_stack_get_child_by_name)
  _WRAP_METHOD(const Widget* get_child_by_name(const Glib::ustring& name) const, gtk_stack_get_child_by_name, constversion)

  _WRAP_METHOD(void set_interpolate_size(bool interpolate_size), gtk_stack_set_interpolate_size, newin "3,20")
  _WRAP_METHOD(bool get_interpolate_size() const, gtk_stack_get_interpolate_size, newin "3,20")

  /** Returns a Gio::ListModel that contains the pages of the stack.
   *
   * It can be used to keep an up-to-date view. The model also
   * implements Gtk::SelectionModel and can be used to track and
   * modify the visible page.
   *
   * To use Gio::ListModel API, do something like
   * @code
   * auto pages = stack->get_pages();
   * auto list_model = std::dynamic_pointer_cast<Gio::ListModel>(pages);
   * if (list_model)
   *   list_model->do_something();
   * @endcode
   *
   * @return A Gtk::SelectionModel for the stack's children. The caller becomes
   * the owner of the returned instance. When the caller's reference is dropped,
   * the instance is deleted.
   */
  Glib::RefPtr<SelectionModel> get_pages();

  /// See the non-const version.
  _WRAP_METHOD(Glib::RefPtr<const SelectionModel> get_pages() const, gtk_stack_get_pages, constversion)

  _WRAP_PROPERTY("hhomogeneous", bool)
  _WRAP_PROPERTY("transition-duration", unsigned int)
  _WRAP_PROPERTY("transition-running", bool)
  _WRAP_PROPERTY("transition-type", StackTransitionType)
  _WRAP_PROPERTY("vhomogeneous", bool)
  _WRAP_PROPERTY("visible-child", Widget*)
  _WRAP_PROPERTY("visible-child-name", Glib::ustring)
  _WRAP_PROPERTY("interpolate-size", bool, newin "3,20")
  _WRAP_PROPERTY("pages", Glib::RefPtr<SelectionModel>)

  // There are no signals or vfuncs.
};

} //namespace Gtk
