/** * atk_state_type_get_name: * @type: The #AtkStateType whose name is required * * Gets the description string describing the #AtkStateType @type. * * Returns: the string describing the AtkStateType */ const gchar* atk_state_type_get_name (AtkStateType type) { GTypeClass *type_class; GEnumValue *value; const gchar *name = NULL; type_class = g_type_class_ref (ATK_TYPE_STATE_TYPE); g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL); value = g_enum_get_value (G_ENUM_CLASS (type_class), type); if (value) { name = value->value_nick; } else { if (type <= last_type) { if (type >= 0) name = state_names[type]; } } return name; }
static PyObject * pyg_enum_repr(PyGEnum *self) { GEnumClass *enum_class; const char *value; guint index; static char tmp[256]; long l; enum_class = g_type_class_ref(self->gtype); g_assert(G_IS_ENUM_CLASS(enum_class)); l = PYGLIB_PyLong_AS_LONG(self); for (index = 0; index < enum_class->n_values; index++) if (l == enum_class->values[index].value) break; value = enum_class->values[index].value_name; if (value) sprintf(tmp, "<enum %s of type %s>", value, g_type_name(self->gtype)); else sprintf(tmp, "<enum %ld of type %s>", PYGLIB_PyLong_AS_LONG(self), g_type_name(self->gtype)); g_type_class_unref(enum_class); return PYGLIB_PyUnicode_FromString(tmp); }
/** * atk_state_type_for_name: * @name: a character string state name * * Gets the #AtkStateType corresponding to the description string @name. * * Returns: an #AtkStateType corresponding to @name */ AtkStateType atk_state_type_for_name (const gchar *name) { GTypeClass *type_class; GEnumValue *value; AtkStateType type = ATK_STATE_INVALID; g_return_val_if_fail (name, ATK_STATE_INVALID); type_class = g_type_class_ref (ATK_TYPE_STATE_TYPE); g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_STATE_INVALID); value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name); if (value) { type = value->value; } else { gint i; for (i = ATK_STATE_LAST_DEFINED + 1; i <= last_type; i++) { if (state_names[i] == NULL) continue; if (!strcmp(name, state_names[i])) { type = i; break; } } } return type; }
/** * atk_relation_type_get_name: * @type: The #AtkRelationType whose name is required * * Gets the description string describing the #AtkRelationType @type. * * Returns: the string describing the AtkRelationType */ const gchar* atk_relation_type_get_name (AtkRelationType type) { GTypeClass *type_class; GEnumValue *value; const gchar *name = NULL; type_class = g_type_class_ref (ATK_TYPE_RELATION_TYPE); g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL); value = g_enum_get_value (G_ENUM_CLASS (type_class), type); if (value) { name = value->value_nick; } else { if (extra_names) { gint n = type; n -= ATK_RELATION_LAST_DEFINED + 1; if (n < extra_names->len) name = g_ptr_array_index (extra_names, n); } } g_type_class_unref (type_class); return name; }
const static gchar* atspi_state_get_name (gint state) { GTypeClass *type_class; GEnumValue *value; type_class = g_type_class_ref (ATSPI_TYPE_STATE_TYPE); g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ""); value = g_enum_get_value (G_ENUM_CLASS (type_class), state); return value->value_nick; }
static GVariant * int_enum_set_mapping (const GValue *value, const GVariantType *expected_type, GEnumClass *enum_class) { GEnumValue *enum_value; g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), NULL); enum_value = g_enum_get_value (enum_class, g_value_get_int (value)); if (enum_value == NULL) return NULL; return g_variant_new_string (enum_value->value_nick); }
static gboolean int_enum_get_mapping (GValue *value, GVariant *variant, GEnumClass *enum_class) { GEnumValue *enum_value; const gchar *nick; g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), FALSE); nick = g_variant_get_string (variant, NULL); enum_value = g_enum_get_value_by_nick (enum_class, nick); if (enum_value == NULL) return FALSE; g_value_set_int (value, enum_value->value); return TRUE; }
/** * atk_relation_type_for_name: * @name: a string which is the (non-localized) name of an ATK relation type. * * Get the #AtkRelationType type corresponding to a relation name. * * Returns: the #AtkRelationType enumerated type corresponding to the specified name, * or #ATK_RELATION_NULL if no matching relation type is found. **/ AtkRelationType atk_relation_type_for_name (const gchar *name) { GTypeClass *type_class; GEnumValue *value; AtkRelationType type = ATK_RELATION_NULL; g_return_val_if_fail (name, ATK_RELATION_NULL); type_class = g_type_class_ref (ATK_TYPE_RELATION_TYPE); g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_RELATION_NULL); value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name); if (value) { type = value->value; } else { gint i; if (extra_names) { for (i = 0; i < extra_names->len; i++) { gchar *extra_name = (gchar *)g_ptr_array_index (extra_names, i); g_return_val_if_fail (extra_name, ATK_RELATION_NULL); if (strcmp (name, extra_name) == 0) { type = i + 1 + ATK_RELATION_LAST_DEFINED; break; } } } } g_type_class_unref (type_class); return type; }
/** * gimp_enum_get_desc: * @enum_class: a #GEnumClass * @value: a value from @enum_class * * Retrieves #GimpEnumDesc associated with the given value, or %NULL. * * Return value: the value's #GimpEnumDesc. * * Since: GIMP 2.2 **/ GimpEnumDesc * gimp_enum_get_desc (GEnumClass *enum_class, gint value) { const GimpEnumDesc *value_desc; g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), NULL); value_desc = gimp_enum_get_value_descriptions (G_TYPE_FROM_CLASS (enum_class)); if (value_desc) { while (value_desc->value_desc) { if (value_desc->value == value) return (GimpEnumDesc *) value_desc; value_desc++; } } return NULL; }