summaryrefslogtreecommitdiff
path: root/gio/src/menuitem.hg
blob: 2ad85daca46ff6de0dc6ccf8ab0be88daa4eb901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* Copyright (C) 2012 The giomm 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/>.
 */

_CONFIGINCLUDE(giommconfig.h)

#include <glibmm/object.h>
#include <giomm/menumodel.h>
#include <giomm/icon.h>

_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gio
{

/** A menu item for use with Gio::Menu.
 *
 * @newin{2,32}
 */
class GIOMM_API MenuItem : public Glib::Object
{
  _CLASS_GOBJECT(MenuItem, GMenuItem, G_MENU_ITEM, Glib::Object, GObject, , , GIOMM_API)

protected:
  /** Creates a new MenuItem.
   *
   * If @a label is not empty it is used to set the "label" attribute of the
   * new item.
   *
   * If @a detailed_action is not empty it is used to set the "action" and
   * possibly the "target" attribute of the new item.  See
   * set_detailed_action() for more information.
   *
   * @param label The section label.
   * @param detailed_action: The detailed action string.
   */
  explicit MenuItem(const Glib::ustring& label = {}, const Glib::ustring& detailed_action = {});
  _IGNORE(g_menu_item_new)

  /** Creates a new MenuItem representing a submenu.
   *
   * This is a convenience API around the MenuItem(label, detailed_action) constructor and
   * set_submenu().
   *
   * @param label The section label.
   * @param submenu A MenuModel with the items of the submenu.
   */
  explicit MenuItem(const Glib::ustring& label, const Glib::RefPtr<MenuModel>& submenu);

  /** Creates a new MenuItem representing a submenu.
   *
   * This is a convenience API around the MenuItem(label, detailed_action) constructor and
   * set_submenu().
   *
   * @param submenu A MenuModel with the items of the submenu.
   */
  explicit MenuItem(const Glib::RefPtr<MenuModel>& submenu);
  _IGNORE(g_menu_item_new_submenu)

public:
  _WRAP_CREATE(const Glib::ustring& label, const Glib::ustring& detailed_action)

  _WRAP_CREATE(const Glib::ustring& label{?}, const Glib::RefPtr<MenuModel>& submenu)



/* TODO:
GMenuItem * g_menu_item_new_from_model              (GMenuModel  *model,
                                                     gint         item_index);


GMenuItem * g_menu_item_new_submenu                 (const Glib::ustring& label,
                                                     GMenuModel  *submenu);


GMenuItem * g_menu_item_new_section                 (const Glib::ustring& label,
                                                     GMenuModel  *section);
*/



//TODO: GMenuItem * g_menu_item_new_section                 (const Glib::ustring& label,
//                                                     const Glib::RefPtr<MenuModel>& section);

  //TODO: Add a set_attribute() templated method to get values directly instead
  //of requiring a Glib::VariantBase, when we can break ABI:
  //template <typename T_Value>
  //void set_attribute(const Glib::ustring& attribute, const T_Value& value) const;

  _WRAP_METHOD(void set_attribute_value(const Glib::ustring& attribute, const Glib::VariantBase& value), g_menu_item_set_attribute_value)
  _IGNORE(g_menu_item_set_attribute)

//These are documented as transfer-full, so we don't need to use refreturn.
  _WRAP_METHOD(Glib::RefPtr<MenuModel> get_link(const Glib::ustring& link), g_menu_item_get_link)
  _WRAP_METHOD(Glib::RefPtr<const MenuModel> get_link(const Glib::ustring& link) const, g_menu_item_get_link, constversion)

  _WRAP_METHOD(void set_link(const Glib::ustring& link, const Glib::RefPtr<MenuModel>& model), g_menu_item_set_link)
  _WRAP_METHOD(void set_label(const Glib::ustring& label), g_menu_item_set_label)
  _WRAP_METHOD(void set_submenu(const Glib::RefPtr<MenuModel>& submenu), g_menu_item_set_submenu)
  _WRAP_METHOD(void set_section(const Glib::RefPtr<MenuModel>& section), g_menu_item_set_section)

  //TODO: Add a get_attribute() templated method to get values directly instead
  //of returning a Glib::VariantBase, when we can break ABI.
  //template <typename T_Value>
  //void get_attribute(const Glib::ustring& attribute, T_Value& value) const;
  //_WRAP_METHOD(Glib::VariantBase get_attribute_value(const Glib::ustring& attribute, const Glib::VariantType& expected_type{?}) const, g_menu_item_get_attribute_value)

  _WRAP_METHOD(Glib::VariantBase get_attribute_value(const Glib::ustring& attribute, const Glib::VariantType& expected_type{?}) const, g_menu_item_get_attribute_value)

  // Ignore varargs function.
  _IGNORE(g_menu_item_get_attribute)

  /** Sets the action for the menu item.
   * See set_action_and_target().
   *
   * @newin{2,38}
   */
  void set_action(const Glib::ustring& action);

  /** Unsets the target for the menu item.
   * See set_action_and_target().
   *
   * @newin{2,38}
   */
  void unset_target();

  /** Unsets the action and target for the menu item.
   * See set_action_and_target().
   *
   * @newin{2,38}
   */
  void unset_action_and_target();

  _WRAP_METHOD(void set_action_and_target(const Glib::ustring& action, const Glib::VariantBase& target_value), g_menu_item_set_action_and_target_value)
  _IGNORE(g_menu_item_set_action_and_target)
  _WRAP_METHOD(void set_detailed_action(const Glib::ustring& detailed_action), g_menu_item_set_detailed_action)

 _WRAP_METHOD(void set_icon(const Glib::RefPtr<Icon>& icon), g_menu_item_set_icon)

  /** Unset the icon on the menu item.
   *
   * See set_icon().
   *
   * @newin{2,38}
   */
  void unset_icon();
};

} // namespace Gio