/* 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 <giomm/listmodel.h>
#include <gtkmm/listitemfactory.h>
#include <gtkmm/expression.h>
#include <gtkmm/stringfilter.h>
#include <gtkmm/widget.h>

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

namespace Gtk
{

/** Choose an item from a list.
 *
 * %Gtk::DropDown is a widget that allows the user to choose an item
 * from a list of options. The %Gtk::DropDown displays the selected
 * choice.
 *
 * The options are given to %Gtk::DropDown in the form of Gio::ListModel,
 * and how the individual options are represented is determined by
 * a Gtk::ListItemFactory. The default factory displays simple strings.
 *
 * %Gtk::DropDown knows how to obtain strings from the items in a
 * Gtk::StringList; for other models, you have to provide an expression
 * to find the strings via set_expression().
 *
 * %Gtk::DropDown can optionally allow search in the popup, which is
 * useful if the list of options is long. To enable the search entry,
 * use set_enable_search().
 *
 * @par CSS nodes
 * %Gtk::DropDown has a single CSS node with name dropdown,
 * with the button and popover nodes as children.
 *
 * @see Gtk::ComboBox
 *
 * @ingroup Widgets
 *
 * @newin{3,98}
 */
class GTKMM_API DropDown : public Widget
{
  _CLASS_GTKOBJECT(DropDown, GtkDropDown, GTK_DROP_DOWN, Gtk::Widget, GtkWidget, , , GTKMM_API)
  _DO_NOT_DERIVE_GTYPE dnl// GtkDropDown is a final type
  _ABI_AS_WITH_DERIVED_GTYPE dnl// Remove when we can break ABI
  _STRUCT_NOT_HIDDEN

public:
  _WRAP_CTOR(DropDown(const Glib::RefPtr<Gio::ListModel>& model = {}, const Glib::RefPtr<Expression<Glib::ustring>>& expression = {}), gtk_drop_down_new)

  /** Creates a new %DropDown that is populated with the strings in @a strings.
   *
   * @param strings The strings to put in the dropdown.
   */
  explicit DropDown(const std::vector<Glib::ustring>& strings);

  _WRAP_METHOD(void set_model(const Glib::RefPtr<Gio::ListModel>& model), gtk_drop_down_set_model)
  _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> get_model(), gtk_drop_down_get_model, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> get_model() const, gtk_drop_down_get_model, refreturn, constversion)
  _WRAP_METHOD(void set_selected(guint position), gtk_drop_down_set_selected)
  _WRAP_METHOD(guint get_selected() const, gtk_drop_down_get_selected)

#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_selected_item(),
    gtk_drop_down_get_selected_item, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Glib::ObjectBase> get_selected_item() const,
    gtk_drop_down_get_selected_item, refreturn, constversion)

  _WRAP_METHOD(void set_factory(const Glib::RefPtr<ListItemFactory>& factory), gtk_drop_down_set_factory)
  _WRAP_METHOD(Glib::RefPtr<ListItemFactory> get_factory(), gtk_drop_down_get_factory, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const ListItemFactory> get_factory() const, gtk_drop_down_get_factory, refreturn, constversion)
  _WRAP_METHOD(void set_list_factory(const Glib::RefPtr<ListItemFactory>& factory), gtk_drop_down_set_list_factory)
  _WRAP_METHOD(Glib::RefPtr<ListItemFactory> get_list_factory(), gtk_drop_down_get_list_factory, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const ListItemFactory> get_list_factory() const, gtk_drop_down_get_list_factory, refreturn, constversion)
  _WRAP_METHOD(void set_header_factory(const Glib::RefPtr<ListItemFactory>& factory), gtk_drop_down_set_header_factory)
  _WRAP_METHOD(Glib::RefPtr<ListItemFactory> get_header_factory(), gtk_drop_down_get_header_factory, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const ListItemFactory> get_header_factory() const, gtk_drop_down_get_header_factory, refreturn, constversion)

  _WRAP_METHOD(void set_expression(const Glib::RefPtr<Expression<Glib::ustring>>& expression), gtk_drop_down_set_expression)
  _WRAP_METHOD(Glib::RefPtr<Expression<Glib::ustring>> get_expression(), gtk_drop_down_get_expression, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Expression<Glib::ustring>> get_expression() const, gtk_drop_down_get_expression, refreturn)

  _WRAP_METHOD(void set_enable_search(bool enable_search = true), gtk_drop_down_set_enable_search)
  _WRAP_METHOD(bool get_enable_search() const, gtk_drop_down_get_enable_search)
  _WRAP_METHOD(void set_show_arrow(bool show_arrow = true), gtk_drop_down_set_show_arrow)
  _WRAP_METHOD(bool set_show_arrow() const, gtk_drop_down_get_show_arrow)
  _WRAP_METHOD(void set_search_match_mode(StringFilter::MatchMode search_match_mode), gtk_drop_down_set_search_match_mode)
  _WRAP_METHOD(StringFilter::MatchMode get_search_match_mode() const, gtk_drop_down_get_search_match_mode)

  _WRAP_PROPERTY("factory", Glib::RefPtr<ListItemFactory>)
  _WRAP_PROPERTY("header-factory", Glib::RefPtr<ListItemFactory>)
  _WRAP_PROPERTY("list-factory", Glib::RefPtr<ListItemFactory>)
  _WRAP_PROPERTY("model", Glib::RefPtr<Gio::ListModel>)
  _WRAP_PROPERTY("selected", guint)
  _WRAP_PROPERTY("selected-item", Glib::RefPtr<Glib::ObjectBase>)
  _WRAP_PROPERTY("enable-search", bool)
  _WRAP_PROPERTY("expression", Glib::RefPtr<Expression<Glib::ustring>>)
  _WRAP_PROPERTY("show-arrow", bool)
  _WRAP_PROPERTY("search-match-mode", StringFilter::MatchMode)

  // no_default_handler because GtkDropDownClass is private.
  _WRAP_SIGNAL(void activate(), "activate", no_default_handler, newin "4,18")
};

} // namespace Gtk
