/* Copyright (C) 2015 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/popover.h>
#include <giomm/menumodel.h>

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

namespace Gtk
{
/** @defgroup Menus Menu classes
 * @see Gio::Menu, Gio::MenuItem, Gio::MenuModel, Gio::SimpleActionGroup
 */

/** A Popover to use as a menu.
 *
 * %PopoverMenu is a subclass of Popover that treats its
 * children like menus and allows switching between them. It
 * can open submenus as traditional, nested submenus, or in a
 * more touch-friendly sliding fashion.
 *
 * %PopoverMenu is meant to be used primarily with menu models,
 * using one of the constructors or set_menu_model(). If you need to put
 * other widgets such as SpinButton or Switch into a popover, use a Popover.
 *
 * In addition to all the regular menu model features, this function
 * supports rendering sections in the model in a more compact form,
 * as a row of image buttons instead of menu items.
 * To use this rendering, set the ”display-hint” attribute of the
 * section to ”horizontal-buttons” and set the icons of your items
 * with the ”verb-icon” attribute.
 *
 * @newin{3,18}
 *
 * @ingroup Widgets
 * @ingroup Containers
 * @ingroup Menus
 */
class GTKMM_API PopoverMenu : public Popover
{
  _CLASS_GTKOBJECT(PopoverMenu, GtkPopoverMenu, GTK_POPOVER_MENU, Gtk::Popover, GtkPopover, , , GTKMM_API)

public:
  _WRAP_ENUM(Flags, GtkPopoverMenuFlags, decl_prefix GTKMM_API)

  //This is custom-implemented because the gtk_popover_menu_new_from_model() does more
  //than just call g_object_new().
  //See https://bugzilla.gnome.org/show_bug.cgi?id=704671
  /** Creates a %PopoverMenu and populates it according to @a model.
   *
   * The created buttons are connected to actions found in the
   * ApplicationWindow to which the popover menu belongs - typically
   * by means of being attached to a widget that is contained within
   * the ApplicationWindow widget hierarchy.
   *
   * Actions can also be added using Widget::insert_action_group()
   * on the menu's attached widget or on any of its parent widgets.
   *
   * The only flag that is supported currently is
   * Gtk::PopoverMenu::Flags::NESTED, which makes GTK create traditional,
   * nested submenus instead of the default sliding submenus.
   *
   * @param model A Gio::MenuModel or an empty Glib::RefPtr
   * @param flags Flags that affect how the menu is created
   */
  explicit PopoverMenu(const Glib::RefPtr<Gio::MenuModel>& model = {},
    Flags flags = static_cast<Flags>(0));
  _IGNORE(gtk_popover_menu_new_from_model, gtk_popover_menu_new_from_model_full)

  _WRAP_METHOD(void set_menu_model(const Glib::RefPtr<Gio::MenuModel>& model), gtk_popover_menu_set_menu_model)
  _WRAP_METHOD(Glib::RefPtr<Gio::MenuModel> get_menu_model(), gtk_popover_menu_get_menu_model, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::MenuModel> get_menu_model() const, gtk_popover_menu_get_menu_model, refreturn, constversion)

  _WRAP_METHOD(void set_flags(Flags flags), gtk_popover_menu_set_flags)
  _WRAP_METHOD(Flags get_flags() const, gtk_popover_menu_get_flags)

  _WRAP_METHOD(bool add_child(Widget& child, const Glib::ustring& id), gtk_popover_menu_add_child)
  _WRAP_METHOD(bool remove_child(Widget& child), gtk_popover_menu_remove_child)

  _WRAP_PROPERTY("visible-submenu", Glib::ustring)
  _WRAP_PROPERTY("menu-model", Glib::RefPtr<Gio::MenuModel>)
  _WRAP_PROPERTY("flags", Flags)

  // PopoverMenu has no signals nor vfuncs.
};

} //namespace Gtk
