/* Copyright (C) 2012 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 <gtkmm/widget.h>
#include <gtkmm/popover.h>
#include <giomm/menumodel.h>
_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/widget_p.h)

namespace Gtk
{

/** A widget that shows a menu when clicked on.
 *
 * This menu can be provided either as a Gtk::Menu, a Gtk::Popover or an
 * abstract Gio::MenuModel.
 *
 * The %Gtk::MenuButton widget can show either an icon (set with set_icon_name())
 * or a label (set with set_label()). If neither is explicitly set,
 * a Gtk::Image is automatically created, using an arrow image oriented according
 * to set_direction() or the generic “open-menu-symbolic” icon if the direction
 * is not set.
 *
 * @ingroup Widgets
 * @newin{3,6}
 */
class MenuButton : public Widget
{
  _CLASS_GTKOBJECT(MenuButton, GtkMenuButton, GTK_MENU_BUTTON, Gtk::Widget, GtkWidget)
public:

  _CTOR_DEFAULT

  _WRAP_METHOD(void set_popover(Popover& popover), gtk_menu_button_set_popover)

  /** Disables the button.
   */
  void unset_popover();

  _WRAP_METHOD(Popover* get_popover(), gtk_menu_button_get_popover)
  _WRAP_METHOD(const Popover* get_popover() const, gtk_menu_button_get_popover, constversion)

  _WRAP_METHOD(void set_direction(ArrowType direction), gtk_menu_button_set_direction)
  _WRAP_METHOD(ArrowType get_direction() const, gtk_menu_button_get_direction)

  _WRAP_METHOD(void set_menu_model(const Glib::RefPtr<const Gio::MenuModel>& menu_model), gtk_menu_button_set_menu_model)

  /** Disables the button.
   */
  void unset_menu_model();

  _WRAP_METHOD(Glib::RefPtr<Gio::MenuModel> get_menu_model(), gtk_menu_button_get_menu_model, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::MenuModel> get_menu_model() const, gtk_menu_button_get_menu_model, refreturn, constversion)

  _WRAP_METHOD(void set_align_widget(Widget& align_widget), gtk_menu_button_set_align_widget)
  _WRAP_METHOD(Widget* get_align_widget(), gtk_menu_button_get_align_widget)
  _WRAP_METHOD(const Widget* get_align_widget() const, gtk_menu_button_get_align_widget, constversion)

  _WRAP_METHOD(void set_icon_name(const Glib::ustring& icon_name), gtk_menu_button_set_icon_name)
  _WRAP_METHOD(Glib::ustring get_icon_name() const, gtk_menu_button_get_icon_name)

  _WRAP_METHOD(void set_label(const Glib::ustring& label), gtk_menu_button_set_label)
  _WRAP_METHOD(Glib::ustring get_label() const, gtk_menu_button_get_label)

  _WRAP_METHOD(void set_relief(ReliefStyle relief), gtk_menu_button_set_relief)
  _WRAP_METHOD(ReliefStyle get_relief() const, gtk_menu_button_get_relief)

  _WRAP_METHOD(void popup(), gtk_menu_button_popup)
  _WRAP_METHOD(void popdown(), gtk_menu_button_popdown)

  /** Slot to create a popup for the %MenuButton on demand.
   *
   * This slot is called when the popoup of the %MenuButton is shown, but none has
   * been provided via set_popup(), set_popover() or set_menu_model().
   */
  using SlotCreatePopup = sigc::slot<void()>;

  /** Sets @a slot to be called when a popup is about to be shown.
   *
   *  @a slot should use one of
   *
   * - set_popup()
   * - set_popover()
   * - set_menu_model()
   *
   * to set a popup for the %MenuButton.
   * The %MenuButton will always be sensitive.
   *
   * Using this method will NOT reset the menu widget attached to the %MenuButton.
   * Instead, this can be done manually in @a slot.
   *
   * @param slot Slot to call when a popup is about to be shown, but none
   *             has been provided via other means.
   * @newin{3,96}
   */
  void set_create_popup_func(const SlotCreatePopup& slot);
  _IGNORE(gtk_menu_button_set_create_popup_func)

  /** Undoes the effect of a previous call to set_create_popup_func().
   */
  void unset_create_popup_func();

  _WRAP_PROPERTY("menu-model", Glib::RefPtr<Gio::MenuModel>)
  _WRAP_PROPERTY("align-widget", Widget*)
  _WRAP_PROPERTY("direction", ArrowType)
  _WRAP_PROPERTY("popover", Popover*)
  _WRAP_PROPERTY("icon-name", Glib::ustring)
  _WRAP_PROPERTY("label", Glib::ustring)
  _WRAP_PROPERTY("relief", ReliefStyle)
};

} /* namespace Gtk */

