/* 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <vector>

#include <gtkmm/widget.h>

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

/** @defgroup Containers Container Widgets
 * These widgets can be used to group other widgets together.
 */

namespace Gtk
{

class Adjustment;
class Label;

/** Abstract container class
 *
 * This is the abstract container from which all gtk+ widgets which hold
 * other items derive from.  It mainly houses virtual functions
 * used for inserting and removing children.  Containers in gtk+
 * may hold one item or many items depending on the implementation.
 *
 * This interface is used for all single item holding containers.
 * Multi-item containers provide their own unique interface as their
 * items are generally more complex.  The methods of the derived
 * classes should be prefered over these.
 *
 * @ingroup Widgets
 */
class Container : public Widget
{
  _CLASS_GTKOBJECT(Container,GtkContainer,GTK_CONTAINER,Gtk::Widget,GtkWidget)
public:

/* Application-level methods */

  _WRAP_METHOD_DOCS_ONLY(gtk_container_add)
  void add(Widget& widget);
  _IGNORE(gtk_container_add)

  /** Removes @a widget from the container.
   * @a widget must be inside this container.
   * If @a widget is managed with Gtk::manage(), and you don't want to use @a widget
   * again, then you should delete it, because there will no longer be any parent
   * container to delete it automatically.
   *
   * What's said about ScrolledWindow in the documentation of Bin::remove()
   * applies also to Container::remove().
   *
   * @param widget A current child of the container.
   */
  void remove(Widget& widget);
  _IGNORE(gtk_container_remove)

  /** A slot to invoke with each child iterated over by foreach() or forall().
   * For instance,<br>
   * void on_foreach(Gtk::Widget& widget);
   */
  using ForeachSlot = sigc::slot<void(Widget&)>;

  /** Operate on contained items.
   *
   * Invokes the @a slot on each non-internal child of the container. See
   * forall() for details on what constitutes an
   * "internal" child.  Most applications should use foreach()
   * rather than forall().
   */
  void foreach(const ForeachSlot& slot);
  _IGNORE(gtk_container_foreach)


  /** Operate on contained items, including internal children.
   *
   * Invokes the @a slot on each child of the container, including children
   * that are considered "internal" (implementation details of the
   * container). "Internal" children generally weren't added by the user
   * of the container, but were added by the container implementation
   * itself.  Most applications should use foreach(),
   * rather than forall().
   *
   * @newin{3,6}
   */
  void forall(const ForeachSlot& slot);
  _IGNORE(gtk_container_forall)

#m4 _CONVERSION(`GList*',`std::vector<Widget*>',`Glib::ListHandler<Widget*>::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
  _WRAP_METHOD(std::vector<Widget*> get_children(), gtk_container_get_children)
#m4 _CONVERSION(`GList*',`std::vector<const Widget*>',`Glib::ListHandler<const Widget*>::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
  _WRAP_METHOD(std::vector<const Widget*> get_children() const, gtk_container_get_children)

/* Widget-level methods */

  _WRAP_METHOD(void set_focus_vadjustment(const Glib::RefPtr<Adjustment>& adjustment),
               gtk_container_set_focus_vadjustment)

  _WRAP_METHOD(Glib::RefPtr<Adjustment> get_focus_vadjustment(),
               gtk_container_get_focus_vadjustment, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Adjustment> get_focus_vadjustment() const,
               gtk_container_get_focus_vadjustment, refreturn, constversion)

  _WRAP_METHOD(void set_focus_hadjustment(const Glib::RefPtr<Adjustment>& adjustment),
               gtk_container_set_focus_hadjustment)

  _WRAP_METHOD(Glib::RefPtr<Adjustment> get_focus_hadjustment(),
               gtk_container_get_focus_hadjustment, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Adjustment> get_focus_hadjustment() const,
               gtk_container_get_focus_hadjustment, refreturn, constversion)

  _WRAP_METHOD(GType child_type() const, gtk_container_child_type)

  _WRAP_SIGNAL(void add(Widget* widget), "add")

  //We use the optional custom_c_callback parameter with _WRAP_SIGNAL() here,
  //so that we can write special code to check for deleted child widget parameters:
  _WRAP_SIGNAL(void remove(Widget* widget), "remove", custom_c_callback)

protected:
  _CTOR_DEFAULT()

  /** Implements child_type().
   *
   * The default implementation returns G_TYPE_NONE
   */
  _WRAP_VFUNC(GType child_type() const, child_type)

  /** Invokes a callback on all non-internal children of the container.
   *
   * "Internal" children generally weren't added by the user of the container,
   * but were added by the container implementation itself.
   *
   * %forall_vfunc() resembles foreach(): They don't invoke the callback for
   * internal children. forall() invokes it for all kinds of children.
   * Most applications should use foreach(), rather than forall().
   *
   * @param slot A slot to call for each non-internal child.
   */
  _WRAP_VFUNC(void forall(const ForeachSlot& slot{callback}), forall,
    custom_vfunc_callback, slot_name slot, slot_callback container_foreach_callback, no_slot_copy)

  /** Sets the focused child of container.
   *
   * @param child The child widget.
   */
  _WRAP_VFUNC(void set_focus_child(Widget* child), set_focus_child)

#m4begin
dnl// Hook in special code to catch explicit uses of gtk_object_destroy() by
dnl// GTK+ code, e.g. when receiving the GDK_DELETE event.  For details, look
dnl// at Gtk::Widget_Class::dispose_vfunc_callback() in widget.ccg.
dnl
  _PUSH(SECTION_PCC_CLASS_INIT_DEFAULT_SIGNAL_HANDLERS)
  _SECTION(SECTION_PH_DEFAULT_SIGNAL_HANDLERS)
    static void remove_callback_normal(GtkContainer* self, GtkWidget* p0);
  _POP()
#m4end
};

} // namespace Gtk
