atkutil.h 14.3 KB
Newer Older
Bill Haneman's avatar
Bill Haneman committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* ATK -  Accessibility Toolkit
 * Copyright 2001 Sun Microsystems Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Piotr Drąg's avatar
Piotr Drąg committed
15
16
17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Bill Haneman's avatar
Bill Haneman committed
18
19
 */

20
21
22
#ifndef __ATK_UTIL_H__
#define __ATK_UTIL_H__

23
24
25
26
#if defined(ATK_DISABLE_SINGLE_INCLUDES) && !defined (__ATK_H_INSIDE__) && !defined (ATK_COMPILATION)
#error "Only <atk/atk.h> can be included directly."
#endif

Bill Haneman's avatar
Bill Haneman committed
27
28
#include <atk/atkobject.h>

29
G_BEGIN_DECLS
Bill Haneman's avatar
Bill Haneman committed
30

31
32
33
34
35
36
37
38
39
40
41
42
#define ATK_TYPE_UTIL                   (atk_util_get_type ())
#define ATK_IS_UTIL(obj)                G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_UTIL)
#define ATK_UTIL(obj)                   G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_UTIL, AtkUtil)
#define ATK_UTIL_CLASS(klass)                   (G_TYPE_CHECK_CLASS_CAST ((klass), ATK_TYPE_UTIL, AtkUtilClass))
#define ATK_IS_UTIL_CLASS(klass)                (G_TYPE_CHECK_CLASS_TYPE ((klass), ATK_TYPE_UTIL))
#define ATK_UTIL_GET_CLASS(obj)                 (G_TYPE_INSTANCE_GET_CLASS ((obj), ATK_TYPE_UTIL, AtkUtilClass))


#ifndef _TYPEDEF_ATK_UTIL_
#define _TYPEDEF_ATK_UTIL_
typedef struct _AtkUtil      AtkUtil;
typedef struct _AtkUtilClass AtkUtilClass;
43
typedef struct _AtkKeyEventStruct AtkKeyEventStruct;
44
45
#endif

46
47
48
49
50
51
52
53
54
55
56
/**
 * AtkEventListener: 
 * @obj: An #AtkObject instance for whom the callback will be called when
 * the specified event (e.g. 'focus:') takes place.
 *
 * A function which is called when an object emits a matching event,
 * as used in #atk_add_focus_tracker.
 * Currently the only events for which object-specific handlers are
 * supported are events of type "focus:".  Most clients of ATK will prefer to 
 * attach signal handlers for the various ATK signals instead.
 *
57
 * see atk_add_focus_tracker.
58
59
60
61
62
63
64
65
66
 **/
typedef void  (*AtkEventListener) (AtkObject* obj);
/**
 * AtkEventListenerInit:
 *
 * An #AtkEventListenerInit function is a special function that is
 * called in order to initialize the per-object event registration system
 * used by #AtkEventListener, if any preparation is required.  
 *
67
 * see atk_focus_tracker_init.
68
 **/
69
typedef void  (*AtkEventListenerInit) (void);
70
71
72
73
/**
 * AtkKeySnoopFunc:
 * @event: an AtkKeyEventStruct containing information about the key event for which
 * notification is being given.
74
 * @user_data: a block of data which will be passed to the event listener, on notification.
75
76
77
78
79
80
81
82
83
 *
 * An #AtkKeySnoopFunc is a type of callback which is called whenever a key event occurs, 
 * if registered via atk_add_key_event_listener.  It allows for pre-emptive 
 * interception of key events via the return code as described below.
 *
 * Returns: TRUE (nonzero) if the event emission should be stopped and the event 
 * discarded without being passed to the normal GUI recipient; FALSE (zero) if the 
 * event dispatch to the client application should proceed as normal.
 *
84
 * see atk_add_key_event_listener.
85
 **/
86
typedef gint  (*AtkKeySnoopFunc)  (AtkKeyEventStruct *event,
87
				   gpointer user_data);
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
 * AtkKeyEventStruct:
 * @type: An AtkKeyEventType, generally one of ATK_KEY_EVENT_PRESS or ATK_KEY_EVENT_RELEASE
 * @state: A bitmask representing the state of the modifier keys immediately after the event takes place.   
 * The meaning of the bits is currently defined to match the bitmask used by GDK in
 * GdkEventType.state, see 
 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey
 * @keyval: A guint representing a keysym value corresponding to those used by GDK and X11: see
 * /usr/X11/include/keysymdef.h.
 * @length: The length of member #string.
 * @string: A string containing one of the following: either a string approximating the text that would 
 * result from this keypress, if the key is a control or graphic character, or a symbolic name for this keypress.
 * Alphanumeric and printable keys will have the symbolic key name in this string member, for instance "A". "0", 
 * "semicolon", "aacute".  Keypad keys have the prefix "KP".
 * @keycode: The raw hardware code that generated the key event.  This field is raraly useful.
 * @timestamp: A timestamp in milliseconds indicating when the event occurred.  
 * These timestamps are relative to a starting point which should be considered arbitrary, 
 * and only used to compare the dispatch times of events to one another.
 *
 * Encapsulates information about a key event.
 **/
110
111
112
113
114
115
116
struct _AtkKeyEventStruct {
  gint type;
  guint state;
  guint keyval;
  gint length;
  gchar *string;
  guint16 keycode;
117
  guint32 timestamp;	
118
};
119

120
121
122
123
124
125
126
127
/**
 *AtkKeyEventType:
 *@ATK_KEY_EVENT_PRESS: specifies a key press event
 *@ATK_KEY_EVENT_RELEASE: specifies a key release event
 *@ATK_KEY_EVENT_LAST_DEFINED: Not a valid value; specifies end of enumeration
 *
 *Specifies the type of a keyboard evemt.
 **/
128
129
130
131
132
133
134
typedef enum
{
  ATK_KEY_EVENT_PRESS,
  ATK_KEY_EVENT_RELEASE,
  ATK_KEY_EVENT_LAST_DEFINED
} AtkKeyEventType;

135
136
137
138
139
struct _AtkUtil
{
  GObject parent;
};

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
 * AtkUtilClass:
 * @add_global_event_listener: adds the specified function to the list
 *  of functions to be called when an ATK event occurs. ATK
 *  implementors are discouraged from reimplementing this method.
 * @remove_global_event_listener: removes the specified function to
 *  the list of functions to be called when an ATK event occurs. ATK
 *  implementors are discouraged from reimplementing this method.
 * @add_key_event_listener: adds the specified function to the list of
 *  functions to be called when a key event occurs.
 * @remove_key_event_listener: remove the specified function to the
 *  list of functions to be called when a key event occurs.
 * @get_root: gets the root accessible container for the current
 *  application.
 * @get_toolkit_name: gets name string for the GUI toolkit
 *  implementing ATK for this application.
 * @get_toolkit_version: gets version string for the GUI toolkit
 *  implementing ATK for this application.
 *
 */
160
161
162
struct _AtkUtilClass
{
   GObjectClass parent;
163
   guint        (* add_global_event_listener)    (GSignalEmissionHook listener,
Michael Meeks's avatar
Michael Meeks committed
164
						  const gchar        *event_type);
165
   void         (* remove_global_event_listener) (guint               listener_id);
166
   guint	(* add_key_event_listener) 	 (AtkKeySnoopFunc     listener,
167
168
						  gpointer data);
   void         (* remove_key_event_listener)    (guint               listener_id);
169
   AtkObject*   (* get_root)                     (void);
170
171
   const gchar* (* get_toolkit_name)             (void);
   const gchar* (* get_toolkit_version)          (void);
172
};
173
ATK_AVAILABLE_IN_ALL
174
175
GType atk_util_get_type (void);

176
177
178
/**
 *AtkCoordType:
 *@ATK_XY_SCREEN: specifies xy coordinates relative to the screen
179
 *@ATK_XY_WINDOW: specifies xy coordinates relative to the widget's
180
 * top-level window
181
 *@ATK_XY_PARENT: specifies xy coordinates relative to the widget's
Michael Catanzaro's avatar
Michael Catanzaro committed
182
 * immediate parent. Since: 2.30
183
 *
184
185
 *Specifies how xy coordinates are to be interpreted. Used by functions such
 *as atk_component_get_position() and atk_text_get_character_extents() 
186
187
188
 **/
typedef enum {
  ATK_XY_SCREEN,
189
190
  ATK_XY_WINDOW,
  ATK_XY_PARENT
191
192
}AtkCoordType;

193
ATK_DEPRECATED_IN_2_10
194
guint    atk_add_focus_tracker     (AtkEventListener      focus_tracker);
195
ATK_DEPRECATED_IN_2_10
Bill Haneman's avatar
Bill Haneman committed
196
void     atk_remove_focus_tracker  (guint                tracker_id);
197
ATK_DEPRECATED_IN_2_10
198
void     atk_focus_tracker_init    (AtkEventListenerInit  init);
199
ATK_DEPRECATED_IN_2_10
Bill Haneman's avatar
Bill Haneman committed
200
void     atk_focus_tracker_notify  (AtkObject            *object);
201
ATK_AVAILABLE_IN_ALL
Michael Meeks's avatar
Michael Meeks committed
202
203
guint	atk_add_global_event_listener (GSignalEmissionHook listener,
				       const gchar        *event_type);
204
ATK_AVAILABLE_IN_ALL
205
void	atk_remove_global_event_listener (guint listener_id);
206
ATK_AVAILABLE_IN_ALL
207
guint	atk_add_key_event_listener (AtkKeySnoopFunc listener, gpointer data);
208
ATK_AVAILABLE_IN_ALL
209
210
void	atk_remove_key_event_listener (guint listener_id);

211
ATK_AVAILABLE_IN_ALL
212
AtkObject* atk_get_root(void);
213
ATK_AVAILABLE_IN_ALL
214
215
AtkObject* atk_get_focus_object (void);

216
ATK_AVAILABLE_IN_ALL
217
const gchar *atk_get_toolkit_name (void);
218
ATK_AVAILABLE_IN_ALL
219
const gchar *atk_get_toolkit_version (void);
220
ATK_AVAILABLE_IN_ALL
221
const gchar *atk_get_version (void);
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* --- GType boilerplate --- */
/* convenience macros for atk type implementations, which for a type GtkGadgetAccessible will:
 * - prototype: static void     gtk_gadget_accessible_class_init (GtkGadgetClass *klass);
 * - prototype: static void     gtk_gadget_accessible_init       (GtkGadget      *self);
 * - define:    static gpointer gtk_gadget_accessible_parent_class = NULL;
 *   gtk_gadget_accessible_parent_class is initialized prior to calling gtk_gadget_class_init()
 * - implement: GType           gtk_gadget_accessible_get_type (void) { ... }
 * - support custom code in gtk_gadget_accessible_get_type() after the type is registered.
 *
 * macro arguments: TypeName, type_name, TYPE_PARENT, CODE
 * example: ATK_DEFINE_TYPE_WITH_CODE (GtkGadgetAccessible, gtk_gadget_accessible, GTK_TYPE_GADGET,
 *                                     G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, gtk_gadget_accessible_table_iface_init))
 */

237
238
239
240
241
242
243
244
245
246
247
248
249
250
/**
 * ATK_DEFINE_TYPE:
 * @TN: The name of the new type, in Camel case.
 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
 * @T_P: The #GType of the parent type.
 *
 * A convenience macro for type ATK implementations, which declares a class
 * initialization function, an instance initialization function (see #GTypeInfo
 * for information about these) and a static variable named
 * @t_n _parent_class pointing to the parent class. Furthermore, it
 * defines a _get_type() function.
 *
 * Since: 1.22
 */
251
#define ATK_DEFINE_TYPE(TN, t_n, T_P)			       ATK_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
252
253
254
255
256
257
258
259
260
261
262
263
264
265

/**
 * ATK_DEFINE_TYPE_WITH_CODE:
 * @TN: The name of the new type, in Camel case.
 * @t_n: The name of the new type in lowercase, with words separated by '_'.
 * @T_P: The #GType of the parent type.
 * @_C_: Custom code that gets inserted in the _get_type() function.
 *
 * A convenience macro for ATK type implementations.
 * Similar to ATK_DEFINE_TYPE(), but allows you to insert custom code into the
 * _get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE().
 *
 * Since: 1.22
 */
266
#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()
267
268
269
270
271
272
273
274
275
276
277
278

/**
 * ATK_DEFINE_ABSTRACT_TYPE:
 * @TN: The name of the new type, in Camel case.
 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
 * @T_P: The #GType of the parent type.
 *
 * A convenience macro for ATK type implementations.
 * Similar to ATK_DEFINE_TYPE(), but defines an abstract type.
 *
 * Since: 1.22
 */
279
#define ATK_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P)		       ATK_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
280
281
282
283
284
285
286
287
288
289
290
291
292

/**
 * ATK_DEFINE_ABSTRACT_TYPE_WITH_CODE:
 * @TN: The name of the new type, in Camel case.
 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
 * @T_P: The #GType of the parent type.
 * @_C_: Custom code that gets inserted in the _get_type() function.
 *
 * A convenience macro for ATK type implementations.
 * Similar to ATK_DEFINE_TYPE_WITH_CODE(), but defines an abstract type.
 *
 * Since: 1.22
 */
293
#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()
294
295
296
297
298
299
300
301
302
303
304
305
306
307

/**
 * ATK_DEFINE_TYPE_EXTENDED:
 * @TN: The name of the new type, in Camel case.
 * @t_n: The name of the new type, in lowercase, with words separated by '_'.
 * @T_P: The #GType of the parent type.
 * @_f_: #GTypeFlags to pass to g_type_register_static()
 * @_C_: Custom code that gets inserted in the _get_type() function.
 *
 * The most general convenience macro for ATK type implementations, on which
 * ATK_DEFINE_TYPE(), etc are based.
 *
 * Since: 1.22
 */
308
309
310
311
312
313
314
315
316
317
318
319
320
#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()

#define _ATK_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE, flags) \
\
static void     type_name##_init              (TypeName        *self); \
static void     type_name##_class_init        (TypeName##Class *klass); \
static gpointer type_name##_parent_class = NULL; \
static void     type_name##_class_intern_init (gpointer klass) \
{ \
  type_name##_parent_class = g_type_class_peek_parent (klass); \
  type_name##_class_init ((TypeName##Class*) klass); \
} \
\
321
ATK_AVAILABLE_IN_ALL \
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
GType \
type_name##_get_type (void) \
{ \
  static volatile gsize g_define_type_id__volatile = 0; \
  if (g_once_init_enter (&g_define_type_id__volatile))  \
    { \
      AtkObjectFactory *factory; \
      GType derived_type; \
      GTypeQuery query; \
      GType derived_atk_type; \
      GType g_define_type_id; \
\
      /* Figure out the size of the class and instance we are deriving from */ \
      derived_type = g_type_parent (TYPE); \
      factory = atk_registry_get_factory (atk_get_default_registry (), \
                                          derived_type); \
      derived_atk_type = atk_object_factory_get_accessible_type (factory); \
      g_type_query (derived_atk_type, &query); \
\
      g_define_type_id = \
        g_type_register_static_simple (derived_atk_type, \
                                       g_intern_static_string (#TypeName), \
                                       query.class_size, \
                                       (GClassInitFunc) type_name##_class_intern_init, \
                                       query.instance_size, \
                                       (GInstanceInitFunc) type_name##_init, \
                                       (GTypeFlags) flags); \
      { /* custom code follows */
#define _ATK_DEFINE_TYPE_EXTENDED_END()	\
        /* following custom code */	\
      }					\
      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
    }					\
  return g_define_type_id__volatile;	\
} /* closes type_name##_get_type() */

358
G_END_DECLS
Bill Haneman's avatar
Bill Haneman committed
359
360

#endif /* __ATK_UTIL_H__ */