1/* Copyright (C) 2012 The giomm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
15 */
16
17_CONFIGINCLUDE(giommconfig.h)
18
19#include <glibmm/object.h>
20#include <giomm/menumodel.h>
21#include <giomm/icon.h>
22
23_DEFS(giomm,gio)
24_PINCLUDE(glibmm/private/object_p.h)
25
26namespace Gio
27{
28
29/** A menu item for use with Gio::Menu.
30 *
31 * @newin{2,32}
32 */
33class GIOMM_API MenuItem : public Glib::Object
34{
35  _CLASS_GOBJECT(MenuItem, GMenuItem, G_MENU_ITEM, Glib::Object, GObject, , , GIOMM_API)
36
37protected:
38  /** Creates a new MenuItem.
39   *
40   * If @a label is not empty it is used to set the "label" attribute of the
41   * new item.
42   *
43   * If @a detailed_action is not empty it is used to set the "action" and
44   * possibly the "target" attribute of the new item.  See
45   * set_detailed_action() for more information.
46   *
47   * @param label The section label.
48   * @param detailed_action: The detailed action string.
49   */
50  explicit MenuItem(const Glib::ustring& label = Glib::ustring(), const Glib::ustring& detailed_action = Glib::ustring());
51  _IGNORE(g_menu_item_new)
52
53  /** Creates a new MenuItem representing a submenu.
54   *
55   * This is a convenience API around the MenuItem(label, detailed_action) constructor and
56   * set_submenu().
57   *
58   * @param label The section label.
59   * @param submenu A MenuModel with the items of the submenu.
60   */
61  explicit MenuItem(const Glib::ustring& label, const Glib::RefPtr<MenuModel>& submenu);
62
63  /** Creates a new MenuItem representing a submenu.
64   *
65   * This is a convenience API around the MenuItem(label, detailed_action) constructor and
66   * set_submenu().
67   *
68   * @param submenu A MenuModel with the items of the submenu.
69   */
70  explicit MenuItem(const Glib::RefPtr<MenuModel>& submenu);
71  _IGNORE(g_menu_item_new_submenu)
72
73public:
74  _WRAP_CREATE(const Glib::ustring& label, const Glib::ustring& detailed_action)
75
76  _WRAP_CREATE(const Glib::ustring& label{?}, const Glib::RefPtr<MenuModel>& submenu)
77
78
79
80/* TODO:
81GMenuItem * g_menu_item_new_from_model              (GMenuModel  *model,
82                                                     gint         item_index);
83
84
85GMenuItem * g_menu_item_new_submenu                 (const Glib::ustring& label,
86                                                     GMenuModel  *submenu);
87
88
89GMenuItem * g_menu_item_new_section                 (const Glib::ustring& label,
90                                                     GMenuModel  *section);
91*/
92
93
94
95//TODO: GMenuItem * g_menu_item_new_section                 (const Glib::ustring& label,
96//                                                     const Glib::RefPtr<MenuModel>& section);
97
98  //TODO: Add a set_attribute() templated method to get values directly instead
99  //of requiring a Glib::VariantBase, when we can break ABI:
100  //template <typename T_Value>
101  //void set_attribute(const Glib::ustring& attribute, const T_Value& value) const;
102
103  _WRAP_METHOD(void set_attribute_value(const Glib::ustring& attribute, const Glib::VariantBase& value), g_menu_item_set_attribute_value)
104  _WRAP_METHOD(void set_attribute(const Glib::ustring& attribute, const Glib::VariantBase& value), g_menu_item_set_attribute_value, deprecated "Use set_attribute() instead.")
105  _IGNORE(g_menu_item_set_attribute)
106
107//These are documented as transfer-full, so we don't need to use refreturn.
108  _WRAP_METHOD(Glib::RefPtr<MenuModel> get_link(const Glib::ustring& link), g_menu_item_get_link)
109  _WRAP_METHOD(Glib::RefPtr<const MenuModel> get_link(const Glib::ustring& link) const, g_menu_item_get_link, constversion)
110
111  _WRAP_METHOD(void set_link(const Glib::ustring& link, const Glib::RefPtr<MenuModel>& model), g_menu_item_set_link)
112  _WRAP_METHOD(void set_label(const Glib::ustring& label), g_menu_item_set_label)
113  _WRAP_METHOD(void set_submenu(const Glib::RefPtr<MenuModel>& submenu), g_menu_item_set_submenu)
114  _WRAP_METHOD(void set_section(const Glib::RefPtr<MenuModel>& section), g_menu_item_set_section)
115
116  //TODO: Add a get_attribute() templated method to get values directly instead
117  //of returning a Glib::VariantBase, when we can break ABI.
118  //template <typename T_Value>
119  //void get_attribute(const Glib::ustring& attribute, T_Value& value) const;
120  //_WRAP_METHOD(Glib::VariantBase get_attribute_value(const Glib::ustring& attribute, const Glib::VariantType& expected_type{?}) const, g_menu_item_get_attribute_value)
121
122  _WRAP_METHOD(Glib::VariantBase get_attribute(const Glib::ustring& attribute, const Glib::VariantType& expected_type{?}) const, g_menu_item_get_attribute_value, deprecated "Use get_attribute_value() instead.")
123  _WRAP_METHOD(Glib::VariantBase get_attribute_value(const Glib::ustring& attribute, const Glib::VariantType& expected_type{?}) const, g_menu_item_get_attribute_value)
124
125  // Ignore varargs function.
126  _IGNORE(g_menu_item_get_attribute)
127
128_DEPRECATE_IFDEF_START
129  /** Unsets the target for the specified @a action.
130   * @deprecated Use set_action() or unset_target() instead.
131   */
132  void set_action_and_target(const Glib::ustring& action);
133_DEPRECATE_IFDEF_END
134
135  /** Sets the action for the menu item.
136   * See set_action_and_target().
137   *
138   * @newin{2,38}
139   */
140  void set_action(const Glib::ustring& action);
141
142  /** Unsets the target for the menu item.
143   * See set_action_and_target().
144   *
145   * @newin{2,38}
146   */
147  void unset_target();
148
149  /** Unsets the action and target for the menu item.
150   * See set_action_and_target().
151   *
152   * @newin{2,38}
153   */
154  void unset_action_and_target();
155
156  _WRAP_METHOD(void set_action_and_target(const Glib::ustring& action, const Glib::VariantBase& target_value), g_menu_item_set_action_and_target_value)
157  _IGNORE(g_menu_item_set_action_and_target)
158  _WRAP_METHOD(void set_detailed_action(const Glib::ustring& detailed_action), g_menu_item_set_detailed_action)
159
160 _WRAP_METHOD(void set_icon(const Glib::RefPtr<Icon>& icon), g_menu_item_set_icon)
161
162  /** Unset the icon on the menu item.
163   *
164   * See set_icon().
165   *
166   * @newin{2,38}
167   */
168  void unset_icon();
169};
170
171} // namespace Gio
172