/*
 * 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
 */

_CONFIGINCLUDE(gtkmmconfig.h)

#include <gtkmm/bin.h>
#include <gtkmm/accelkey.h>
#include <gtkmm/accellabel.h>
#include <gtkmm/activatable.h>
_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/bin_p.h)

namespace Gtk
{

//TODO: Derive from (and implement) Actionable when we can break ABI.

class GTKMM_API Menu;
namespace Menu_Helpers { class GTKMM_API Element; }

/** Child item for menus.
 * Handle highlighting, alignment, events and submenus.
 * As it derives from Gtk::Bin it can hold any valid child widget, although only a few are really useful.
 * @ingroup Widgets
 * @ingroup Menus
 */
class GTKMM_API MenuItem
 : public Bin,
   public Activatable
{
  _CLASS_GTKOBJECT(MenuItem,GtkMenuItem,GTK_MENU_ITEM,Gtk::Bin,GtkBin,,,GTKMM_API)
  _IMPLEMENTS_INTERFACE(Activatable)
public:
  /// Create an empty menu item
  _CTOR_DEFAULT

  /// Create a menu item with widget
  explicit MenuItem(Widget& widget);

  /// Create a menu item with label
  explicit MenuItem(const Glib::ustring& label, bool mnemonic = false);

  _WRAP_METHOD(void set_submenu(Menu& submenu), gtk_menu_item_set_submenu)

  /** Remove the menu item's sub-menu.
   * @newin{2,22}
   */
  void unset_submenu();

  _WRAP_METHOD(Menu* get_submenu(), gtk_menu_item_get_submenu)
  _WRAP_METHOD(const Menu* get_submenu() const, gtk_menu_item_get_submenu, constversion)
  bool has_submenu() const;
  _WRAP_METHOD(void select(), gtk_menu_item_select)
  _WRAP_METHOD(void deselect(), gtk_menu_item_deselect)
  _WRAP_METHOD(void activate(), gtk_menu_item_activate)
  _WRAP_METHOD(void toggle_size_request(int& requisition), gtk_menu_item_toggle_size_request)
  _WRAP_METHOD(void toggle_size_allocate(int allocation), gtk_menu_item_toggle_size_allocate)

  _WRAP_METHOD(void set_right_justified(bool right_justified = true), gtk_menu_item_set_right_justified, deprecated "If you insist on using it, use Widget::set_hexpand() and Widget::set_halign().")
  _WRAP_METHOD(bool get_right_justified() const, gtk_menu_item_get_right_justified, deprecated "See set_right_justified().")

  _WRAP_METHOD(void set_accel_path(const Glib::ustring& accel_path), gtk_menu_item_set_accel_path)
  void unset_accel_path();
  _WRAP_METHOD(Glib::ustring get_accel_path() const, gtk_menu_item_get_accel_path)
  _WRAP_METHOD(void set_label(const Glib::ustring& label), gtk_menu_item_set_label)
  _WRAP_METHOD(Glib::ustring get_label() const, gtk_menu_item_get_label)
  _WRAP_METHOD(void set_use_underline(bool setting = true), gtk_menu_item_set_use_underline)
  _WRAP_METHOD(bool get_use_underline() const, gtk_menu_item_get_use_underline)

  _WRAP_METHOD(void set_reserve_indicator(bool reserve = true), gtk_menu_item_set_reserve_indicator)
  _WRAP_METHOD(bool get_reserve_indicator() const, gtk_menu_item_get_reserve_indicator)

  _WRAP_SIGNAL(void activate(), "activate")
  _WRAP_SIGNAL(void activate_item(), "activate_item")
  _WRAP_SIGNAL(void toggle_size_request(int* requisition), "toggle_size_request")
  _WRAP_SIGNAL(void toggle_size_allocate(int allocation), "toggle_size_allocate")

  //TODO: Remove no_default_handler when we can break ABI
  _WRAP_SIGNAL(void select(), "select", no_default_handler)
  _WRAP_SIGNAL(void deselect(), "deselect", no_default_handler)

  void accelerate(Window& window);

  //TODO: Deprecate the C property once GTK+ 3.5 has begun. It seems to have been forgotten.
  _WRAP_PROPERTY("right-justified", bool, deprecated "See set_right_justified.")

  _WRAP_PROPERTY("submenu", Gtk::Menu*)
  _WRAP_PROPERTY("accel-path", Glib::ustring)
  _WRAP_PROPERTY("label", Glib::ustring)
  _WRAP_PROPERTY("use-underline", bool)

protected:
  void add_accel_label(const Glib::ustring& label, bool mnemonic = true);
  void set_accel_key(const AccelKey& accel_key);

private:
  friend class Menu_Helpers::Element;

  //This data is set by MenuElem, and will be used in on_realize(), in the call to add_accelerator().
  AccelKey accel_key_;
};

} // namespace Gtk
