gmenumodel.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright © 2011 Canonical Ltd.
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * Author: Ryan Lortie <desrt@desrt.ca>
  20. */
  21. #ifndef __G_MENU_MODEL_H__
  22. #define __G_MENU_MODEL_H__
  23. #include <glib-object.h>
  24. #include <gio/giotypes.h>
  25. G_BEGIN_DECLS
  26. /**
  27. * G_MENU_ATTRIBUTE_ACTION:
  28. *
  29. * The menu item attribute which holds the action name of the item. Action
  30. * names are namespaced with an identifier for the action group in which the
  31. * action resides. For example, "win." for window-specific actions and "app."
  32. * for application-wide actions.
  33. *
  34. * See also g_menu_model_get_item_attribute() and g_menu_item_set_attribute().
  35. *
  36. * Since: 2.32
  37. **/
  38. #define G_MENU_ATTRIBUTE_ACTION "action"
  39. /**
  40. * G_MENU_ATTRIBUTE_ACTION_NAMESPACE:
  41. *
  42. * The menu item attribute that holds the namespace for all action names in
  43. * menus that are linked from this item.
  44. *
  45. * Since: 2.36
  46. **/
  47. #define G_MENU_ATTRIBUTE_ACTION_NAMESPACE "action-namespace"
  48. /**
  49. * G_MENU_ATTRIBUTE_TARGET:
  50. *
  51. * The menu item attribute which holds the target with which the item's action
  52. * will be activated.
  53. *
  54. * See also g_menu_item_set_action_and_target()
  55. *
  56. * Since: 2.32
  57. **/
  58. #define G_MENU_ATTRIBUTE_TARGET "target"
  59. /**
  60. * G_MENU_ATTRIBUTE_LABEL:
  61. *
  62. * The menu item attribute which holds the label of the item.
  63. *
  64. * Since: 2.32
  65. **/
  66. #define G_MENU_ATTRIBUTE_LABEL "label"
  67. /**
  68. * G_MENU_ATTRIBUTE_ICON:
  69. *
  70. * The menu item attribute which holds the icon of the item.
  71. *
  72. * The icon is stored in the format returned by g_icon_serialize().
  73. *
  74. * This attribute is intended only to represent 'noun' icons such as
  75. * favicons for a webpage, or application icons. It should not be used
  76. * for 'verbs' (ie: stock icons).
  77. *
  78. * Since: 2.38
  79. **/
  80. #define G_MENU_ATTRIBUTE_ICON "icon"
  81. /**
  82. * G_MENU_LINK_SUBMENU:
  83. *
  84. * The name of the link that associates a menu item with a submenu.
  85. *
  86. * See also g_menu_item_set_link().
  87. *
  88. * Since: 2.32
  89. **/
  90. #define G_MENU_LINK_SUBMENU "submenu"
  91. /**
  92. * G_MENU_LINK_SECTION:
  93. *
  94. * The name of the link that associates a menu item with a section. The linked
  95. * menu will usually be shown in place of the menu item, using the item's label
  96. * as a header.
  97. *
  98. * See also g_menu_item_set_link().
  99. *
  100. * Since: 2.32
  101. **/
  102. #define G_MENU_LINK_SECTION "section"
  103. #define G_TYPE_MENU_MODEL (g_menu_model_get_type ())
  104. #define G_MENU_MODEL(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
  105. G_TYPE_MENU_MODEL, GMenuModel))
  106. #define G_MENU_MODEL_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
  107. G_TYPE_MENU_MODEL, GMenuModelClass))
  108. #define G_IS_MENU_MODEL(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
  109. G_TYPE_MENU_MODEL))
  110. #define G_IS_MENU_MODEL_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
  111. G_TYPE_MENU_MODEL))
  112. #define G_MENU_MODEL_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
  113. G_TYPE_MENU_MODEL, GMenuModelClass))
  114. typedef struct _GMenuModelPrivate GMenuModelPrivate;
  115. typedef struct _GMenuModelClass GMenuModelClass;
  116. typedef struct _GMenuAttributeIterPrivate GMenuAttributeIterPrivate;
  117. typedef struct _GMenuAttributeIterClass GMenuAttributeIterClass;
  118. typedef struct _GMenuAttributeIter GMenuAttributeIter;
  119. typedef struct _GMenuLinkIterPrivate GMenuLinkIterPrivate;
  120. typedef struct _GMenuLinkIterClass GMenuLinkIterClass;
  121. typedef struct _GMenuLinkIter GMenuLinkIter;
  122. struct _GMenuModel
  123. {
  124. GObject parent_instance;
  125. GMenuModelPrivate *priv;
  126. };
  127. /**
  128. * GMenuModelClass::get_item_attributes:
  129. * @model: the #GMenuModel to query
  130. * @item_index: The #GMenuItem to query
  131. * @attributes: (out) (element-type utf8 GLib.Variant): Attributes on the item
  132. *
  133. * Gets all the attributes associated with the item in the menu model.
  134. */
  135. /**
  136. * GMenuModelClass::get_item_links:
  137. * @model: the #GMenuModel to query
  138. * @item_index: The #GMenuItem to query
  139. * @links: (out) (element-type utf8 Gio.MenuModel): Links from the item
  140. *
  141. * Gets all the links associated with the item in the menu model.
  142. */
  143. struct _GMenuModelClass
  144. {
  145. GObjectClass parent_class;
  146. gboolean (*is_mutable) (GMenuModel *model);
  147. gint (*get_n_items) (GMenuModel *model);
  148. void (*get_item_attributes) (GMenuModel *model,
  149. gint item_index,
  150. GHashTable **attributes);
  151. GMenuAttributeIter * (*iterate_item_attributes) (GMenuModel *model,
  152. gint item_index);
  153. GVariant * (*get_item_attribute_value) (GMenuModel *model,
  154. gint item_index,
  155. const gchar *attribute,
  156. const GVariantType *expected_type);
  157. void (*get_item_links) (GMenuModel *model,
  158. gint item_index,
  159. GHashTable **links);
  160. GMenuLinkIter * (*iterate_item_links) (GMenuModel *model,
  161. gint item_index);
  162. GMenuModel * (*get_item_link) (GMenuModel *model,
  163. gint item_index,
  164. const gchar *link);
  165. };
  166. GIO_AVAILABLE_IN_2_32
  167. GType g_menu_model_get_type (void) G_GNUC_CONST;
  168. GIO_AVAILABLE_IN_2_32
  169. gboolean g_menu_model_is_mutable (GMenuModel *model);
  170. GIO_AVAILABLE_IN_2_32
  171. gint g_menu_model_get_n_items (GMenuModel *model);
  172. GIO_AVAILABLE_IN_2_32
  173. GMenuAttributeIter * g_menu_model_iterate_item_attributes (GMenuModel *model,
  174. gint item_index);
  175. GIO_AVAILABLE_IN_2_32
  176. GVariant * g_menu_model_get_item_attribute_value (GMenuModel *model,
  177. gint item_index,
  178. const gchar *attribute,
  179. const GVariantType *expected_type);
  180. GIO_AVAILABLE_IN_2_32
  181. gboolean g_menu_model_get_item_attribute (GMenuModel *model,
  182. gint item_index,
  183. const gchar *attribute,
  184. const gchar *format_string,
  185. ...);
  186. GIO_AVAILABLE_IN_2_32
  187. GMenuLinkIter * g_menu_model_iterate_item_links (GMenuModel *model,
  188. gint item_index);
  189. GIO_AVAILABLE_IN_2_32
  190. GMenuModel * g_menu_model_get_item_link (GMenuModel *model,
  191. gint item_index,
  192. const gchar *link);
  193. GIO_AVAILABLE_IN_2_32
  194. void g_menu_model_items_changed (GMenuModel *model,
  195. gint position,
  196. gint removed,
  197. gint added);
  198. #define G_TYPE_MENU_ATTRIBUTE_ITER (g_menu_attribute_iter_get_type ())
  199. #define G_MENU_ATTRIBUTE_ITER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
  200. G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIter))
  201. #define G_MENU_ATTRIBUTE_ITER_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
  202. G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterClass))
  203. #define G_IS_MENU_ATTRIBUTE_ITER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
  204. G_TYPE_MENU_ATTRIBUTE_ITER))
  205. #define G_IS_MENU_ATTRIBUTE_ITER_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
  206. G_TYPE_MENU_ATTRIBUTE_ITER))
  207. #define G_MENU_ATTRIBUTE_ITER_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
  208. G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterClass))
  209. struct _GMenuAttributeIter
  210. {
  211. GObject parent_instance;
  212. GMenuAttributeIterPrivate *priv;
  213. };
  214. struct _GMenuAttributeIterClass
  215. {
  216. GObjectClass parent_class;
  217. gboolean (*get_next) (GMenuAttributeIter *iter,
  218. const gchar **out_name,
  219. GVariant **value);
  220. };
  221. GIO_AVAILABLE_IN_2_32
  222. GType g_menu_attribute_iter_get_type (void) G_GNUC_CONST;
  223. GIO_AVAILABLE_IN_2_32
  224. gboolean g_menu_attribute_iter_get_next (GMenuAttributeIter *iter,
  225. const gchar **out_name,
  226. GVariant **value);
  227. GIO_AVAILABLE_IN_2_32
  228. gboolean g_menu_attribute_iter_next (GMenuAttributeIter *iter);
  229. GIO_AVAILABLE_IN_2_32
  230. const gchar * g_menu_attribute_iter_get_name (GMenuAttributeIter *iter);
  231. GIO_AVAILABLE_IN_2_32
  232. GVariant * g_menu_attribute_iter_get_value (GMenuAttributeIter *iter);
  233. #define G_TYPE_MENU_LINK_ITER (g_menu_link_iter_get_type ())
  234. #define G_MENU_LINK_ITER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
  235. G_TYPE_MENU_LINK_ITER, GMenuLinkIter))
  236. #define G_MENU_LINK_ITER_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
  237. G_TYPE_MENU_LINK_ITER, GMenuLinkIterClass))
  238. #define G_IS_MENU_LINK_ITER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
  239. G_TYPE_MENU_LINK_ITER))
  240. #define G_IS_MENU_LINK_ITER_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
  241. G_TYPE_MENU_LINK_ITER))
  242. #define G_MENU_LINK_ITER_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
  243. G_TYPE_MENU_LINK_ITER, GMenuLinkIterClass))
  244. struct _GMenuLinkIter
  245. {
  246. GObject parent_instance;
  247. GMenuLinkIterPrivate *priv;
  248. };
  249. struct _GMenuLinkIterClass
  250. {
  251. GObjectClass parent_class;
  252. gboolean (*get_next) (GMenuLinkIter *iter,
  253. const gchar **out_link,
  254. GMenuModel **value);
  255. };
  256. GIO_AVAILABLE_IN_2_32
  257. GType g_menu_link_iter_get_type (void) G_GNUC_CONST;
  258. GIO_AVAILABLE_IN_2_32
  259. gboolean g_menu_link_iter_get_next (GMenuLinkIter *iter,
  260. const gchar **out_link,
  261. GMenuModel **value);
  262. GIO_AVAILABLE_IN_2_32
  263. gboolean g_menu_link_iter_next (GMenuLinkIter *iter);
  264. GIO_AVAILABLE_IN_2_32
  265. const gchar * g_menu_link_iter_get_name (GMenuLinkIter *iter);
  266. GIO_AVAILABLE_IN_2_32
  267. GMenuModel * g_menu_link_iter_get_value (GMenuLinkIter *iter);
  268. G_END_DECLS
  269. #endif /* __G_MENU_MODEL_H__ */