gmenumodel.h 14 KB

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