libgimpwidgets: move GimpEnumStore.enum_class to private

This commit is contained in:
Michael Natterer 2018-05-04 10:57:13 +02:00
parent d87eddb1c4
commit 369b273157
4 changed files with 66 additions and 36 deletions

View File

@ -335,6 +335,7 @@ gimp_layer_mode_combo_box_get_group (GimpLayerModeComboBox *combo)
static void static void
gimp_enum_store_add_value (GtkListStore *store, gimp_enum_store_add_value (GtkListStore *store,
GEnumClass *enum_class,
GEnumValue *value) GEnumValue *value)
{ {
GtkTreeIter iter = { 0, }; GtkTreeIter iter = { 0, };
@ -342,8 +343,8 @@ gimp_enum_store_add_value (GtkListStore *store,
const gchar *abbrev; const gchar *abbrev;
gchar *stripped; gchar *stripped;
desc = gimp_enum_value_get_desc (GIMP_ENUM_STORE (store)->enum_class, value); desc = gimp_enum_value_get_desc (enum_class, value);
abbrev = gimp_enum_value_get_abbrev (GIMP_ENUM_STORE (store)->enum_class, value); abbrev = gimp_enum_value_get_abbrev (enum_class, value);
/* no mnemonics in combo boxes */ /* no mnemonics in combo boxes */
stripped = gimp_strip_uline (desc); stripped = gimp_strip_uline (desc);
@ -376,6 +377,7 @@ gimp_enum_store_new_from_array (GType enum_type,
GimpLayerModeContext context) GimpLayerModeContext context)
{ {
GtkListStore *store; GtkListStore *store;
GEnumClass *enum_class;
GEnumValue *value; GEnumValue *value;
gboolean first_item = TRUE; gboolean first_item = TRUE;
gboolean prepend_separator = FALSE; gboolean prepend_separator = FALSE;
@ -389,14 +391,15 @@ gimp_enum_store_new_from_array (GType enum_type,
"enum-type", enum_type, "enum-type", enum_type,
NULL); NULL);
enum_class = g_type_class_ref (enum_type);
for (i = 0; i < n_values; i++) for (i = 0; i < n_values; i++)
{ {
if (values[i] != GIMP_LAYER_MODE_SEPARATOR) if (values[i] != GIMP_LAYER_MODE_SEPARATOR)
{ {
if (gimp_layer_mode_get_context (values[i]) & context) if (gimp_layer_mode_get_context (values[i]) & context)
{ {
value = g_enum_get_value (GIMP_ENUM_STORE (store)->enum_class, value = g_enum_get_value (enum_class, values[i]);
values[i]);
if (value) if (value)
{ {
@ -407,7 +410,7 @@ gimp_enum_store_new_from_array (GType enum_type,
prepend_separator = FALSE; prepend_separator = FALSE;
} }
gimp_enum_store_add_value (store, value); gimp_enum_store_add_value (store, enum_class, value);
first_item = FALSE; first_item = FALSE;
} }
@ -420,6 +423,8 @@ gimp_enum_store_new_from_array (GType enum_type,
} }
} }
g_type_class_unref (enum_class);
return store; return store;
} }

View File

@ -104,6 +104,7 @@ gimp_stroke_editor_constructed (GObject *object)
GimpStrokeEditor *editor = GIMP_STROKE_EDITOR (object); GimpStrokeEditor *editor = GIMP_STROKE_EDITOR (object);
GimpStrokeOptions *options; GimpStrokeOptions *options;
GimpEnumStore *store; GimpEnumStore *store;
GEnumClass *enum_class;
GEnumValue *value; GEnumValue *value;
GtkWidget *box; GtkWidget *box;
GtkWidget *size; GtkWidget *size;
@ -217,12 +218,14 @@ gimp_stroke_editor_constructed (GObject *object)
"user-data-type", GIMP_TYPE_DASH_PATTERN, "user-data-type", GIMP_TYPE_DASH_PATTERN,
NULL); NULL);
for (value = store->enum_class->values; value->value_name; value++) enum_class = g_type_class_ref (GIMP_TYPE_DASH_PRESET);
for (value = enum_class->values; value->value_name; value++)
{ {
GtkTreeIter iter = { 0, }; GtkTreeIter iter = { 0, };
const gchar *desc; const gchar *desc;
desc = gimp_enum_value_get_desc (store->enum_class, value); desc = gimp_enum_value_get_desc (enum_class, value);
gtk_list_store_append (GTK_LIST_STORE (store), &iter); gtk_list_store_append (GTK_LIST_STORE (store), &iter);
gtk_list_store_set (GTK_LIST_STORE (store), &iter, gtk_list_store_set (GTK_LIST_STORE (store), &iter,
@ -231,6 +234,8 @@ gimp_stroke_editor_constructed (GObject *object)
-1); -1);
} }
g_type_class_unref (enum_class);
box = gimp_enum_combo_box_new_with_model (store); box = gimp_enum_combo_box_new_with_model (store);
g_object_unref (store); g_object_unref (store);

View File

@ -46,6 +46,14 @@ enum
}; };
struct _GimpEnumStorePrivate
{
GEnumClass *enum_class;
};
#define GET_PRIVATE(obj) (((GimpEnumStore *) (obj))->priv)
static void gimp_enum_store_finalize (GObject *object); static void gimp_enum_store_finalize (GObject *object);
static void gimp_enum_store_set_property (GObject *object, static void gimp_enum_store_set_property (GObject *object,
guint property_id, guint property_id,
@ -89,20 +97,24 @@ gimp_enum_store_class_init (GimpEnumStoreClass *klass)
G_TYPE_ENUM, G_TYPE_ENUM,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
GIMP_PARAM_READWRITE)); GIMP_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (GimpEnumStorePrivate));
} }
static void static void
gimp_enum_store_init (GimpEnumStore *store) gimp_enum_store_init (GimpEnumStore *store)
{ {
store->priv = G_TYPE_INSTANCE_GET_PRIVATE (store,
GIMP_TYPE_ENUM_STORE,
GimpEnumStorePrivate);
} }
static void static void
gimp_enum_store_finalize (GObject *object) gimp_enum_store_finalize (GObject *object)
{ {
GimpEnumStore *store = GIMP_ENUM_STORE (object); GimpEnumStorePrivate *priv = GET_PRIVATE (object);
if (store->enum_class) g_clear_pointer (&priv->enum_class, g_type_class_unref);
g_type_class_unref (store->enum_class);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -113,14 +125,15 @@ gimp_enum_store_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpEnumStore *store = GIMP_ENUM_STORE (object); GimpEnumStorePrivate *priv = GET_PRIVATE (object);
switch (property_id) switch (property_id)
{ {
case PROP_ENUM_TYPE: case PROP_ENUM_TYPE:
g_return_if_fail (store->enum_class == NULL); g_return_if_fail (priv->enum_class == NULL);
store->enum_class = g_type_class_ref (g_value_get_gtype (value)); priv->enum_class = g_type_class_ref (g_value_get_gtype (value));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -133,15 +146,16 @@ gimp_enum_store_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpEnumStore *store = GIMP_ENUM_STORE (object); GimpEnumStorePrivate *priv = GET_PRIVATE (object);
switch (property_id) switch (property_id)
{ {
case PROP_ENUM_TYPE: case PROP_ENUM_TYPE:
g_value_set_gtype (value, (store->enum_class ? g_value_set_gtype (value, (priv->enum_class ?
G_TYPE_FROM_CLASS (store->enum_class) : G_TYPE_FROM_CLASS (priv->enum_class) :
G_TYPE_NONE)); G_TYPE_NONE));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -152,13 +166,14 @@ static void
gimp_enum_store_add_value (GtkListStore *store, gimp_enum_store_add_value (GtkListStore *store,
GEnumValue *value) GEnumValue *value)
{ {
GtkTreeIter iter = { 0, }; GimpEnumStorePrivate *priv = GET_PRIVATE (store);
const gchar *desc; GtkTreeIter iter = { 0, };
const gchar *abbrev; const gchar *desc;
gchar *stripped; const gchar *abbrev;
gchar *stripped;
desc = gimp_enum_value_get_desc (GIMP_ENUM_STORE (store)->enum_class, value); desc = gimp_enum_value_get_desc (priv->enum_class, value);
abbrev = gimp_enum_value_get_abbrev (GIMP_ENUM_STORE (store)->enum_class, value); abbrev = gimp_enum_value_get_abbrev (priv->enum_class, value);
/* no mnemonics in combo boxes */ /* no mnemonics in combo boxes */
stripped = gimp_strip_uline (desc); stripped = gimp_strip_uline (desc);
@ -224,8 +239,9 @@ gimp_enum_store_new_with_range (GType enum_type,
gint minimum, gint minimum,
gint maximum) gint maximum)
{ {
GtkListStore *store; GimpEnumStorePrivate *priv;
GEnumValue *value; GtkListStore *store;
GEnumValue *value;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL); g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
@ -233,7 +249,9 @@ gimp_enum_store_new_with_range (GType enum_type,
"enum-type", enum_type, "enum-type", enum_type,
NULL); NULL);
for (value = GIMP_ENUM_STORE (store)->enum_class->values; priv = GET_PRIVATE (store);
for (value = priv->enum_class->values;
value->value_name; value->value_name;
value++) value++)
{ {
@ -294,9 +312,10 @@ gimp_enum_store_new_with_values_valist (GType enum_type,
gint n_values, gint n_values,
va_list args) va_list args)
{ {
GtkListStore *store; GimpEnumStorePrivate *priv;
GEnumValue *value; GtkListStore *store;
gint i; GEnumValue *value;
gint i;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL); g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
g_return_val_if_fail (n_values > 1, NULL); g_return_val_if_fail (n_values > 1, NULL);
@ -305,9 +324,11 @@ gimp_enum_store_new_with_values_valist (GType enum_type,
"enum-type", enum_type, "enum-type", enum_type,
NULL); NULL);
priv = GET_PRIVATE (store);
for (i = 0; i < n_values; i++) for (i = 0; i < n_values; i++)
{ {
value = g_enum_get_value (GIMP_ENUM_STORE (store)->enum_class, value = g_enum_get_value (priv->enum_class,
va_arg (args, gint)); va_arg (args, gint));
if (value) if (value)
@ -333,12 +354,14 @@ void
gimp_enum_store_set_icon_prefix (GimpEnumStore *store, gimp_enum_store_set_icon_prefix (GimpEnumStore *store,
const gchar *icon_prefix) const gchar *icon_prefix)
{ {
GtkTreeModel *model; GimpEnumStorePrivate *priv;
GtkTreeIter iter; GtkTreeModel *model;
gboolean iter_valid; GtkTreeIter iter;
gboolean iter_valid;
g_return_if_fail (GIMP_IS_ENUM_STORE (store)); g_return_if_fail (GIMP_IS_ENUM_STORE (store));
priv = GET_PRIVATE (store);
model = GTK_TREE_MODEL (store); model = GTK_TREE_MODEL (store);
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter); for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
@ -356,7 +379,7 @@ gimp_enum_store_set_icon_prefix (GimpEnumStore *store,
GIMP_INT_STORE_VALUE, &value, GIMP_INT_STORE_VALUE, &value,
-1); -1);
enum_value = g_enum_get_value (store->enum_class, value); enum_value = g_enum_get_value (priv->enum_class, value);
if (enum_value) if (enum_value)
{ {

View File

@ -47,9 +47,6 @@ struct _GimpEnumStore
GimpIntStore parent_instance; GimpIntStore parent_instance;
GimpEnumStorePrivate *priv; GimpEnumStorePrivate *priv;
/* FIXME MOVE TO PRIVATE */
GEnumClass *enum_class;
}; };
struct _GimpEnumStoreClass struct _GimpEnumStoreClass