You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

314 lines
12 KiB

  1. /* ATK - Accessibility Toolkit
  2. * Copyright 2001 Sun Microsystems Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. #if defined(ATK_DISABLE_SINGLE_INCLUDES) && !defined (__ATK_H_INSIDE__) && !defined (ATK_COMPILATION)
  20. #error "Only <atk/atk.h> can be included directly."
  21. #endif
  22. #ifndef __ATK_UTIL_H__
  23. #define __ATK_UTIL_H__
  24. #include <atk/atkobject.h>
  25. G_BEGIN_DECLS
  26. #define ATK_TYPE_UTIL (atk_util_get_type ())
  27. #define ATK_IS_UTIL(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_UTIL)
  28. #define ATK_UTIL(obj) G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_UTIL, AtkUtil)
  29. #define ATK_UTIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ATK_TYPE_UTIL, AtkUtilClass))
  30. #define ATK_IS_UTIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ATK_TYPE_UTIL))
  31. #define ATK_UTIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ATK_TYPE_UTIL, AtkUtilClass))
  32. #ifndef _TYPEDEF_ATK_UTIL_
  33. #define _TYPEDEF_ATK_UTIL_
  34. typedef struct _AtkUtil AtkUtil;
  35. typedef struct _AtkUtilClass AtkUtilClass;
  36. typedef struct _AtkKeyEventStruct AtkKeyEventStruct;
  37. #endif
  38. /**
  39. * AtkEventListener:
  40. * @obj: An #AtkObject instance for whom the callback will be called when
  41. * the specified event (e.g. 'focus:') takes place.
  42. *
  43. * A function which is called when an object emits a matching event,
  44. * as used in #atk_add_focus_tracker.
  45. * Currently the only events for which object-specific handlers are
  46. * supported are events of type "focus:". Most clients of ATK will prefer to
  47. * attach signal handlers for the various ATK signals instead.
  48. *
  49. * @see: atk_add_focus_tracker.
  50. **/
  51. typedef void (*AtkEventListener) (AtkObject* obj);
  52. /**
  53. * AtkEventListenerInit:
  54. *
  55. * An #AtkEventListenerInit function is a special function that is
  56. * called in order to initialize the per-object event registration system
  57. * used by #AtkEventListener, if any preparation is required.
  58. *
  59. * @see: atk_focus_tracker_init.
  60. **/
  61. typedef void (*AtkEventListenerInit) (void);
  62. /**
  63. * AtkKeySnoopFunc:
  64. * @event: an AtkKeyEventStruct containing information about the key event for which
  65. * notification is being given.
  66. * @func_data: a block of data which will be passed to the event listener, on notification.
  67. *
  68. * An #AtkKeySnoopFunc is a type of callback which is called whenever a key event occurs,
  69. * if registered via atk_add_key_event_listener. It allows for pre-emptive
  70. * interception of key events via the return code as described below.
  71. *
  72. * Returns: TRUE (nonzero) if the event emission should be stopped and the event
  73. * discarded without being passed to the normal GUI recipient; FALSE (zero) if the
  74. * event dispatch to the client application should proceed as normal.
  75. *
  76. * @see: atk_add_key_event_listener.
  77. **/
  78. typedef gint (*AtkKeySnoopFunc) (AtkKeyEventStruct *event,
  79. gpointer func_data);
  80. /**
  81. * AtkKeyEventStruct:
  82. * @type: An AtkKeyEventType, generally one of ATK_KEY_EVENT_PRESS or ATK_KEY_EVENT_RELEASE
  83. * @state: A bitmask representing the state of the modifier keys immediately after the event takes place.
  84. * The meaning of the bits is currently defined to match the bitmask used by GDK in
  85. * GdkEventType.state, see
  86. * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey
  87. * @keyval: A guint representing a keysym value corresponding to those used by GDK and X11: see
  88. * /usr/X11/include/keysymdef.h.
  89. * @length: The length of member #string.
  90. * @string: A string containing one of the following: either a string approximating the text that would
  91. * result from this keypress, if the key is a control or graphic character, or a symbolic name for this keypress.
  92. * Alphanumeric and printable keys will have the symbolic key name in this string member, for instance "A". "0",
  93. * "semicolon", "aacute". Keypad keys have the prefix "KP".
  94. * @keycode: The raw hardware code that generated the key event. This field is raraly useful.
  95. * @timestamp: A timestamp in milliseconds indicating when the event occurred.
  96. * These timestamps are relative to a starting point which should be considered arbitrary,
  97. * and only used to compare the dispatch times of events to one another.
  98. *
  99. * Encapsulates information about a key event.
  100. **/
  101. struct _AtkKeyEventStruct {
  102. gint type;
  103. guint state;
  104. guint keyval;
  105. gint length;
  106. gchar *string;
  107. guint16 keycode;
  108. guint32 timestamp;
  109. };
  110. /**
  111. *AtkKeyEventType:
  112. *@ATK_KEY_EVENT_PRESS: specifies a key press event
  113. *@ATK_KEY_EVENT_RELEASE: specifies a key release event
  114. *@ATK_KEY_EVENT_LAST_DEFINED: Not a valid value; specifies end of enumeration
  115. *
  116. *Specifies the type of a keyboard evemt.
  117. **/
  118. typedef enum
  119. {
  120. ATK_KEY_EVENT_PRESS,
  121. ATK_KEY_EVENT_RELEASE,
  122. ATK_KEY_EVENT_LAST_DEFINED
  123. } AtkKeyEventType;
  124. struct _AtkUtil
  125. {
  126. GObject parent;
  127. };
  128. struct _AtkUtilClass
  129. {
  130. GObjectClass parent;
  131. guint (* add_global_event_listener) (GSignalEmissionHook listener,
  132. const gchar *event_type);
  133. void (* remove_global_event_listener) (guint listener_id);
  134. guint (* add_key_event_listener) (AtkKeySnoopFunc listener,
  135. gpointer data);
  136. void (* remove_key_event_listener) (guint listener_id);
  137. AtkObject* (* get_root) (void);
  138. G_CONST_RETURN gchar* (* get_toolkit_name) (void);
  139. G_CONST_RETURN gchar* (* get_toolkit_version) (void);
  140. };
  141. GType atk_util_get_type (void);
  142. /**
  143. *AtkCoordType:
  144. *@ATK_XY_SCREEN: specifies xy coordinates relative to the screen
  145. *@ATK_XY_WINDOW: specifies xy coordinates relative to the widget's
  146. * top-level window
  147. *
  148. *Specifies how xy coordinates are to be interpreted. Used by functions such
  149. *as atk_component_get_position() and atk_text_get_character_extents()
  150. **/
  151. typedef enum {
  152. ATK_XY_SCREEN,
  153. ATK_XY_WINDOW
  154. }AtkCoordType;
  155. /*
  156. * Adds the specified function to the list of functions to be called
  157. * when an object receives focus.
  158. */
  159. guint atk_add_focus_tracker (AtkEventListener focus_tracker);
  160. /*
  161. * Removes the specified focus tracker from the list of function
  162. * to be called when any object receives focus
  163. */
  164. void atk_remove_focus_tracker (guint tracker_id);
  165. /*
  166. * atk_focus_tracker_init:
  167. * @init: An #AtkEventListenerInit function to be called
  168. * prior to any focus-tracking requests.
  169. *
  170. * Specifies the function to be called for focus tracker initialization.
  171. * removal. This function should be called by an implementation of the
  172. * ATK interface if any specific work needs to be done to enable
  173. * focus tracking.
  174. */
  175. void atk_focus_tracker_init (AtkEventListenerInit init);
  176. /*
  177. * Cause the focus tracker functions which have been specified to be
  178. * executed for the object.
  179. */
  180. void atk_focus_tracker_notify (AtkObject *object);
  181. /*
  182. * Adds the specified function to the list of functions to be called
  183. * when an event of type event_type occurs.
  184. */
  185. guint atk_add_global_event_listener (GSignalEmissionHook listener,
  186. const gchar *event_type);
  187. /*
  188. * Removes the specified event listener
  189. */
  190. void atk_remove_global_event_listener (guint listener_id);
  191. /*
  192. * Adds the specified function to the list of functions to be called
  193. * when an keyboard event occurs.
  194. */
  195. guint atk_add_key_event_listener (AtkKeySnoopFunc listener, gpointer data);
  196. /*
  197. * Removes the specified event listener
  198. */
  199. void atk_remove_key_event_listener (guint listener_id);
  200. /*
  201. * Returns the root accessible container for the current application.
  202. */
  203. AtkObject* atk_get_root(void);
  204. AtkObject* atk_get_focus_object (void);
  205. /*
  206. * Returns name string for the GUI toolkit.
  207. */
  208. G_CONST_RETURN gchar *atk_get_toolkit_name (void);
  209. /*
  210. * Returns version string for the GUI toolkit.
  211. */
  212. G_CONST_RETURN gchar *atk_get_toolkit_version (void);
  213. /*
  214. * Gets the current version of ATK
  215. */
  216. G_CONST_RETURN gchar *atk_get_version (void);
  217. /* --- GType boilerplate --- */
  218. /* convenience macros for atk type implementations, which for a type GtkGadgetAccessible will:
  219. * - prototype: static void gtk_gadget_accessible_class_init (GtkGadgetClass *klass);
  220. * - prototype: static void gtk_gadget_accessible_init (GtkGadget *self);
  221. * - define: static gpointer gtk_gadget_accessible_parent_class = NULL;
  222. * gtk_gadget_accessible_parent_class is initialized prior to calling gtk_gadget_class_init()
  223. * - implement: GType gtk_gadget_accessible_get_type (void) { ... }
  224. * - support custom code in gtk_gadget_accessible_get_type() after the type is registered.
  225. *
  226. * macro arguments: TypeName, type_name, TYPE_PARENT, CODE
  227. * example: ATK_DEFINE_TYPE_WITH_CODE (GtkGadgetAccessible, gtk_gadget_accessible, GTK_TYPE_GADGET,
  228. * G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, gtk_gadget_accessible_table_iface_init))
  229. */
  230. #define ATK_DEFINE_TYPE(TN, t_n, T_P) ATK_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
  231. #define ATK_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _ATK_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _ATK_DEFINE_TYPE_EXTENDED_END()
  232. #define ATK_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) ATK_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
  233. #define ATK_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _ATK_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT) {_C_;} _ATK_DEFINE_TYPE_EXTENDED_END()
  234. #define ATK_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_) _ATK_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;} _ATK_DEFINE_TYPE_EXTENDED_END()
  235. #define _ATK_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE, flags) \
  236. \
  237. static void type_name##_init (TypeName *self); \
  238. static void type_name##_class_init (TypeName##Class *klass); \
  239. static gpointer type_name##_parent_class = NULL; \
  240. static void type_name##_class_intern_init (gpointer klass) \
  241. { \
  242. type_name##_parent_class = g_type_class_peek_parent (klass); \
  243. type_name##_class_init ((TypeName##Class*) klass); \
  244. } \
  245. \
  246. GType \
  247. type_name##_get_type (void) \
  248. { \
  249. static volatile gsize g_define_type_id__volatile = 0; \
  250. if (g_once_init_enter (&g_define_type_id__volatile)) \
  251. { \
  252. AtkObjectFactory *factory; \
  253. GType derived_type; \
  254. GTypeQuery query; \
  255. GType derived_atk_type; \
  256. GType g_define_type_id; \
  257. \
  258. /* Figure out the size of the class and instance we are deriving from */ \
  259. derived_type = g_type_parent (TYPE); \
  260. factory = atk_registry_get_factory (atk_get_default_registry (), \
  261. derived_type); \
  262. derived_atk_type = atk_object_factory_get_accessible_type (factory); \
  263. g_type_query (derived_atk_type, &query); \
  264. \
  265. g_define_type_id = \
  266. g_type_register_static_simple (derived_atk_type, \
  267. g_intern_static_string (#TypeName), \
  268. query.class_size, \
  269. (GClassInitFunc) type_name##_class_intern_init, \
  270. query.instance_size, \
  271. (GInstanceInitFunc) type_name##_init, \
  272. (GTypeFlags) flags); \
  273. { /* custom code follows */
  274. #define _ATK_DEFINE_TYPE_EXTENDED_END() \
  275. /* following custom code */ \
  276. } \
  277. g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
  278. } \
  279. return g_define_type_id__volatile; \
  280. } /* closes type_name##_get_type() */
  281. G_END_DECLS
  282. #endif /* __ATK_UTIL_H__ */