Commit 7afb51e5 authored by Mike Gorse's avatar Mike Gorse

Enum clean-ups

Generate enum types where appropriate.
Fix prototypes where a method took a "gint" that was really a bitflag.
Remove tables of state and role names, since these are now redundant with data
from the generated enums and would need to be maintained in parallel.

These changes were originally in master but have been backed out since they
break compatibility with pygobject 2.26.0, which some users are still using.
parent e5198adb
......@@ -27,6 +27,7 @@ libatspiinclude_HEADERS = \
atspi-device-listener-private.h \
atspi-document.h \
atspi-editabletext.h \
atspi-enum-types.h \
atspi-event-listener.h \
atspi-event-listener-private.h \
atspi-gmain.c \
......@@ -48,6 +49,7 @@ atspi-gmain.h \
atspi-value.h
libatspi_la_SOURCES = \
$(BUILT_SOURCES) \
$(libatspiinclude_HEADERS) \
atspi.h \
atspi-accessible.c \
......@@ -102,13 +104,25 @@ libatspi_la_SOURCES = \
atspi-value.c \
atspi-value.h
#BUILT_SOURCES = atspi-constants.h
BUILT_SOURCES = \
atspi-enum-types.c \
atspi-enum-types.h
#CLEANFILES = atspi-constants.h
#atspi-constants.h: $(top_srcdir)/xml/spec.xml $(top_srcdir)/tools/c-constants-gen.py
# python $(top_srcdir)/tools/c-constants-gen.py Atspi $(top_srcdir)/xml/spec.xml atspi-constants
ENUM_TYPES = \
atspi-constants.h \
atspi-types.h
atspi-enum-types.h: atspi-enum-types.h.template $(ENUM_TYPES) $(GLIB_MKENUMS)
$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template atspi-enum-types.h.template $(ENUM_TYPES)) > $@
atspi-enum-types.c: atspi-enum-types.c.template $(ENUM_TYPES) $(GLIB_MKENUMS)
$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template atspi-enum-types.c.template $(ENUM_TYPES)) > $@
if HAVE_INTROSPECTION
INTROSPECTION_FILES = $(libatspi_la_SOURCES)
......
......@@ -178,123 +178,6 @@ atspi_accessible_class_init (AtspiAccessibleClass *klass)
object_class->finalize = atspi_accessible_finalize;
}
/* TODO: Generate following from spec? */
static const char *role_names [] =
{
"invalid",
"accel-label",
"alert",
"animation",
"arrow",
"calendar",
"canvas",
"check-box",
"check-menu-item",
"color-chooser",
"column-header",
"combo-box",
"date-editor",
"desktop-icon",
"desktop-frame",
"dial",
"dialog",
"directory-pane",
"drawing-area",
"file-chooser",
"filler",
"font-chooser",
"frame",
"glass-pane",
"html-container",
"icon",
"image",
"internalframe",
"label",
"layered-pane",
"list",
"list-item",
"menu",
"menu-bar",
"menu-item",
"option-pane",
"page-tab",
"page-tab-list",
"panel",
"password-text",
"popup-menu",
"progress-bar",
"push-button",
"radio-button",
"radio-menu-item",
"root-pane",
"row-header",
"scroll-bar",
"scroll-pane",
"separator",
"slider",
"spin-button",
"split-pane",
"statusbar",
"table",
"table-cell",
"table-column-header",
"table-row-header",
"tear-off-menu-item",
"terminal",
"text",
"toggle-button",
"tool-bar",
"tool-tip",
"tree",
"tree-table",
"unknown",
"viewport",
"window",
NULL,
"header",
"fooler",
"paragraph",
"ruler",
"application",
"autocomplete",
"editbar",
"embedded",
"entry",
"chart",
"caption",
"document_frame",
"heading",
"page",
"section",
"form",
"redundant object",
"link",
"input method window"
};
#define MAX_ROLES (sizeof (role_names) / sizeof (char *))
/**
* atspi_role_get_name
* @role: an #AtspiAccessibleRole object to query.
*
* Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
* <em>DEPRECATED.</em>
*
* Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
**/
gchar *
atspi_role_get_name (AtspiRole role)
{
if (role < MAX_ROLES && role_names [(int) role])
{
return g_strdup (role_names [(int) role]);
}
else
{
return g_strdup ("");
}
}
/**
* atspi_accessible_get_name:
......@@ -578,7 +461,24 @@ atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
gchar *
atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
{
AtspiRole role = atspi_accessible_get_role (obj, error);
char *retval = NULL;
GTypeClass *type_class;
GEnumValue *value;
const gchar *name = NULL;
type_class = g_type_class_ref (ATSPI_TYPE_ROLE);
g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
value = g_enum_get_value (G_ENUM_CLASS (type_class), role);
if (value)
{
retval = value->value_nick;
}
if (retval)
return g_strdup (retval);
g_return_val_if_fail (obj != NULL, NULL);
......@@ -1415,7 +1315,7 @@ atspi_accessible_new (AtspiApplication *app, const gchar *path)
*
* @accessible: The #AtspiAccessible to operate on. Must be the desktop or
* the root of an application.
* @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
* @mask: An #AtspiCache specifying a bit mask of the types of data to cache.
*
* Sets the type of data to cache for accessibles.
* If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
......
......@@ -66,8 +66,6 @@ GType atspi_accessible_get_type (void);
AtspiAccessible *
atspi_accessible_new (AtspiApplication *app, const gchar *path);
gchar * atspi_role_get_name (AtspiRole role);
gchar * atspi_accessible_get_name (AtspiAccessible *obj, GError **error);
gchar * atspi_accessible_get_description (AtspiAccessible *obj, GError **error);
......
......@@ -761,8 +761,8 @@ typedef enum {
typedef enum
{
ATSPI_CACHE_NONE = 0,
ATSPI_CACHE_PARENT = 1 << 0,
ATSPI_CACHE_NONE = 0,
ATSPI_CACHE_PARENT = 1 << 0,
ATSPI_CACHE_CHILDREN = 1 << 1,
ATSPI_CACHE_NAME = 1 << 2,
ATSPI_CACHE_DESCRIPTION = 1 << 3,
......
/*** BEGIN file-header ***/
#include "atspi-enum-types.h"
/*** END file-header ***/
/*** BEGIN file-production ***/
/* enumerations from "@filename@" */
#include "@filename@"
/*** END file-production ***/
/*** BEGIN value-header ***/
GType
@enum_name@_get_type (void)
{
static GType the_type = 0;
if (the_type == 0)
{
static const G@Type@Value values[] = {
/*** END value-header ***/
/*** BEGIN value-production ***/
{ @VALUENAME@,
"@VALUENAME@",
"@valuenick@" },
/*** END value-production ***/
/*** BEGIN value-tail ***/
{ 0, NULL, NULL }
};
the_type = g_@type@_register_static (
g_intern_static_string ("@EnumName@"),
values);
}
return the_type;
}
/*** END value-tail ***/
/*** BEGIN file-header ***/
#ifndef __ATSPI_ENUM_TYPES_H__
#define __ATSPI_ENUM_TYPES_H__
#include <glib-object.h>
G_BEGIN_DECLS
/*** END file-header ***/
/*** BEGIN file-production ***/
/* Enumerations from "@filename@" */
/*** END file-production ***/
/*** BEGIN enumeration-production ***/
#define ATSPI_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
GType @enum_name@_get_type (void) G_GNUC_CONST;
/*** END enumeration-production ***/
/*** BEGIN file-tail ***/
G_END_DECLS
#endif /* __ATSPI_ENUM_TYPES_H__ */
/*** END file-tail ***/
......@@ -119,7 +119,8 @@ atspi_register_keystroke_listener (AtspiDeviceListener *listener,
GArray *key_set,
AtspiKeyMaskType modmask,
AtspiKeyEventMask event_types,
gint sync_type, GError **error)
AtspiKeyListenerSyncType sync_type,
GError **error)
{
GArray *d_key_set;
gchar *path = _atspi_device_listener_get_path (listener);
......
......@@ -42,7 +42,8 @@ atspi_register_keystroke_listener (AtspiDeviceListener *listener,
GArray *key_set,
AtspiKeyMaskType modmask,
AtspiKeyEventMask event_types,
gint sync_type, GError **error);
AtspiKeyListenerSyncType sync_type,
GError **error);
gboolean
atspi_deregister_keystroke_listener (AtspiDeviceListener *listener,
......
......@@ -28,52 +28,6 @@ static void atspi_state_set_class_init (AtspiStateSetClass *klass);
G_DEFINE_TYPE (AtspiStateSet, atspi_state_set, G_TYPE_OBJECT)
static const char *state_names [] =
{
"invalid",
"active",
"armed",
"busy",
"checked",
"collapsed",
"defunct",
"editable",
"enabled",
"expandable",
"expanded",
"focusable",
"focused",
"has-tool-tip",
"horizontal",
"iconified",
"modal",
"multi-line",
"multiselectable",
"opaque",
"pressed",
"resizable",
"selectable",
"selected",
"sensitive",
"showing",
"singleLine",
"stale",
"transient",
"vertical",
"visible",
"manages-descendants",
"indeterminate",
"required",
"truncated",
"animated",
"invalid-entry",
"supports-autocompletion",
"selectable-text",
"is-default",
"visited",
NULL
};
static void
atspi_state_set_init (AtspiStateSet *set)
{
......@@ -123,25 +77,25 @@ _atspi_state_set_new_internal (AtspiAccessible *accessible, gint64 states)
void
atspi_state_set_set_by_name (AtspiStateSet *set, const gchar *name, gboolean enabled)
{
gint i = 0;
GTypeClass *type_class;
GEnumValue *value;
type_class = g_type_class_ref (ATSPI_TYPE_STATE_TYPE);
if (set->accessible &&
!(set->accessible->cached_properties & ATSPI_CACHE_STATES))
return;
/* TODO: This could perhaps be optimized */
for (i = 0; state_names [i]; i++)
value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
if (!value)
{
if (!strcmp (state_names [i], name))
{
if (enabled)
set->states |= ((gint64)1 << i);
else
set->states &= ~((gint64)1 << i);
return;
}
g_warning ("AT-SPI: Attempt to set unknown state '%s'", name);
}
g_warning ("at-spi: Attempt to set unknown state '%s'", name);
if (enabled)
set->states |= ((gint64)1 << value->value);
else
set->states &= ~((gint64)1 << value->value);
}
static void
......
......@@ -143,8 +143,8 @@ typedef struct _AtspiKeySet
**/
typedef enum {
ATSPI_KEYLISTENER_NOSYNC = 0,
ATSPI_KEYLISTENER_SYNCHRONOUS = 1,
ATSPI_KEYLISTENER_CANCONSUME = 2,
ATSPI_KEYLISTENER_ALL_WINDOWS = 4
ATSPI_KEYLISTENER_SYNCHRONOUS = 1 << 0,
ATSPI_KEYLISTENER_CANCONSUME = 1 << 1,
ATSPI_KEYLISTENER_ALL_WINDOWS = 1 << 2
} AtspiKeyListenerSyncType;
#endif /* _ATSPI_TYPES_H_ */
......@@ -50,4 +50,6 @@
#include "atspi-value.h"
#include "atspi-gmain.h"
#include "atspi-enum-types.h"
#endif
......@@ -171,6 +171,8 @@ else
fi
AC_SUBST(DBUS_SERVICES_DIR)
AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
GOBJECT_INTROSPECTION_CHECK([0.9.6])
AC_SUBST(LIBTOOL_EXPORT_OPTIONS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment