mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-06 01:12:40 +02:00
Compare commits
2 Commits
3a1076598b
...
wip/nielsd
Author | SHA1 | Date | |
---|---|---|---|
|
92c0816632 | ||
|
238a14bc3d |
@@ -47,13 +47,13 @@ enum
|
||||
};
|
||||
|
||||
|
||||
struct _GimpObjectPrivate
|
||||
typedef struct _GimpObjectPrivate
|
||||
{
|
||||
gchar *name;
|
||||
gchar *normalized;
|
||||
guint static_name : 1;
|
||||
guint disconnected : 1;
|
||||
};
|
||||
} GimpObjectPrivate;
|
||||
|
||||
|
||||
static void gimp_object_constructed (GObject *object);
|
||||
@@ -72,8 +72,7 @@ static gint64 gimp_object_real_get_memsize (GimpObject *object,
|
||||
static void gimp_object_name_normalize (GimpObject *object);
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GimpObject, gimp_object, G_TYPE_OBJECT,
|
||||
G_ADD_PRIVATE (GimpObject))
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GimpObject, gimp_object, G_TYPE_OBJECT)
|
||||
|
||||
#define parent_class gimp_object_parent_class
|
||||
|
||||
@@ -126,10 +125,10 @@ gimp_object_class_init (GimpObjectClass *klass)
|
||||
static void
|
||||
gimp_object_init (GimpObject *object)
|
||||
{
|
||||
object->p = gimp_object_get_instance_private (object);
|
||||
GimpObjectPrivate *priv = gimp_object_get_instance_private (object);
|
||||
|
||||
object->p->name = NULL;
|
||||
object->p->normalized = NULL;
|
||||
priv->name = NULL;
|
||||
priv->normalized = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -144,12 +143,13 @@ static void
|
||||
gimp_object_dispose (GObject *object)
|
||||
{
|
||||
GimpObject *gimp_object = GIMP_OBJECT (object);
|
||||
GimpObjectPrivate *priv = gimp_object_get_instance_private (gimp_object);
|
||||
|
||||
if (! gimp_object->p->disconnected)
|
||||
if (! priv->disconnected)
|
||||
{
|
||||
g_signal_emit (object, object_signals[DISCONNECT], 0);
|
||||
|
||||
gimp_object->p->disconnected = TRUE;
|
||||
priv->disconnected = TRUE;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
@@ -191,14 +191,15 @@ gimp_object_get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpObject *gimp_object = GIMP_OBJECT (object);
|
||||
GimpObjectPrivate *priv = gimp_object_get_instance_private (gimp_object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_NAME:
|
||||
if (gimp_object->p->static_name)
|
||||
g_value_set_static_string (value, gimp_object->p->name);
|
||||
if (priv->static_name)
|
||||
g_value_set_static_string (value, priv->name);
|
||||
else
|
||||
g_value_set_string (value, gimp_object->p->name);
|
||||
g_value_set_string (value, priv->name);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
@@ -218,15 +219,19 @@ void
|
||||
gimp_object_set_name (GimpObject *object,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpObjectPrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_OBJECT (object));
|
||||
|
||||
if (! g_strcmp0 (object->p->name, name))
|
||||
priv = gimp_object_get_instance_private (object);
|
||||
|
||||
if (! g_strcmp0 (priv->name, name))
|
||||
return;
|
||||
|
||||
gimp_object_name_free (object);
|
||||
|
||||
object->p->name = g_strdup (name);
|
||||
object->p->static_name = FALSE;
|
||||
priv->name = g_strdup (name);
|
||||
priv->static_name = FALSE;
|
||||
|
||||
gimp_object_name_changed (object);
|
||||
g_object_notify (G_OBJECT (object), "name");
|
||||
@@ -245,15 +250,19 @@ void
|
||||
gimp_object_set_name_safe (GimpObject *object,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpObjectPrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_OBJECT (object));
|
||||
|
||||
if (! g_strcmp0 (object->p->name, name))
|
||||
priv = gimp_object_get_instance_private (object);
|
||||
|
||||
if (! g_strcmp0 (priv->name, name))
|
||||
return;
|
||||
|
||||
gimp_object_name_free (object);
|
||||
|
||||
object->p->name = gimp_utf8_strtrim (name, 30);
|
||||
object->p->static_name = FALSE;
|
||||
priv->name = gimp_utf8_strtrim (name, 30);
|
||||
priv->static_name = FALSE;
|
||||
|
||||
gimp_object_name_changed (object);
|
||||
g_object_notify (G_OBJECT (object), "name");
|
||||
@@ -263,15 +272,19 @@ void
|
||||
gimp_object_set_static_name (GimpObject *object,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpObjectPrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_OBJECT (object));
|
||||
|
||||
if (! g_strcmp0 (object->p->name, name))
|
||||
priv = gimp_object_get_instance_private (object);
|
||||
|
||||
if (! g_strcmp0 (priv->name, name))
|
||||
return;
|
||||
|
||||
gimp_object_name_free (object);
|
||||
|
||||
object->p->name = (gchar *) name;
|
||||
object->p->static_name = TRUE;
|
||||
priv->name = (gchar *) name;
|
||||
priv->static_name = TRUE;
|
||||
|
||||
gimp_object_name_changed (object);
|
||||
g_object_notify (G_OBJECT (object), "name");
|
||||
@@ -281,9 +294,13 @@ void
|
||||
gimp_object_take_name (GimpObject *object,
|
||||
gchar *name)
|
||||
{
|
||||
GimpObjectPrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_OBJECT (object));
|
||||
|
||||
if (! g_strcmp0 (object->p->name, name))
|
||||
priv = gimp_object_get_instance_private (object);
|
||||
|
||||
if (! g_strcmp0 (priv->name, name))
|
||||
{
|
||||
g_free (name);
|
||||
return;
|
||||
@@ -291,8 +308,8 @@ gimp_object_take_name (GimpObject *object,
|
||||
|
||||
gimp_object_name_free (object);
|
||||
|
||||
object->p->name = name;
|
||||
object->p->static_name = FALSE;
|
||||
priv->name = name;
|
||||
priv->static_name = FALSE;
|
||||
|
||||
gimp_object_name_changed (object);
|
||||
g_object_notify (G_OBJECT (object), "name");
|
||||
@@ -310,10 +327,13 @@ gimp_object_take_name (GimpObject *object,
|
||||
const gchar *
|
||||
gimp_object_get_name (gconstpointer object)
|
||||
{
|
||||
const GimpObject *object_typed = object;
|
||||
GimpObject *object_typed = (GimpObject *) object;
|
||||
GimpObjectPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_OBJECT (object_typed), NULL);
|
||||
|
||||
return object_typed->p->name;
|
||||
priv = gimp_object_get_instance_private (GIMP_OBJECT (object_typed));
|
||||
return priv->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,21 +365,27 @@ gimp_object_name_changed (GimpObject *object)
|
||||
void
|
||||
gimp_object_name_free (GimpObject *object)
|
||||
{
|
||||
if (object->p->normalized)
|
||||
{
|
||||
if (object->p->normalized != object->p->name)
|
||||
g_free (object->p->normalized);
|
||||
GimpObjectPrivate *priv;
|
||||
|
||||
object->p->normalized = NULL;
|
||||
g_return_if_fail (GIMP_IS_OBJECT (object));
|
||||
|
||||
priv = gimp_object_get_instance_private (object);
|
||||
|
||||
if (priv->normalized)
|
||||
{
|
||||
if (priv->normalized != priv->name)
|
||||
g_free (priv->normalized);
|
||||
|
||||
priv->normalized = NULL;
|
||||
}
|
||||
|
||||
if (object->p->name)
|
||||
if (priv->name)
|
||||
{
|
||||
if (! object->p->static_name)
|
||||
g_free (object->p->name);
|
||||
if (! priv->static_name)
|
||||
g_free (priv->name);
|
||||
|
||||
object->p->name = NULL;
|
||||
object->p->static_name = FALSE;
|
||||
priv->name = NULL;
|
||||
priv->static_name = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,32 +406,40 @@ gint
|
||||
gimp_object_name_collate (GimpObject *object1,
|
||||
GimpObject *object2)
|
||||
{
|
||||
if (! object1->p->normalized)
|
||||
GimpObjectPrivate *priv1 = gimp_object_get_instance_private (object1);
|
||||
GimpObjectPrivate *priv2 = gimp_object_get_instance_private (object2);
|
||||
|
||||
if (! priv1->normalized)
|
||||
gimp_object_name_normalize (object1);
|
||||
|
||||
if (! object2->p->normalized)
|
||||
if (! priv2->normalized)
|
||||
gimp_object_name_normalize (object2);
|
||||
|
||||
return strcmp (object1->p->normalized, object2->p->normalized);
|
||||
return strcmp (priv1->normalized, priv2->normalized);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_object_name_normalize (GimpObject *object)
|
||||
{
|
||||
g_return_if_fail (object->p->normalized == NULL);
|
||||
GimpObjectPrivate *priv;
|
||||
|
||||
if (object->p->name)
|
||||
g_return_if_fail (GIMP_IS_OBJECT (object));
|
||||
|
||||
priv = gimp_object_get_instance_private (object);
|
||||
g_return_if_fail (priv->normalized == NULL);
|
||||
|
||||
if (priv->name)
|
||||
{
|
||||
gchar *key = g_utf8_collate_key (object->p->name, -1);
|
||||
gchar *key = g_utf8_collate_key (priv->name, -1);
|
||||
|
||||
if (strcmp (key, object->p->name))
|
||||
if (strcmp (key, priv->name))
|
||||
{
|
||||
object->p->normalized = key;
|
||||
priv->normalized = key;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (key);
|
||||
object->p->normalized = object->p->name;
|
||||
priv->normalized = priv->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -421,6 +455,7 @@ gint64
|
||||
gimp_object_get_memsize (GimpObject *object,
|
||||
gint64 *gui_size)
|
||||
{
|
||||
GimpObjectPrivate *priv;
|
||||
gint64 my_size = 0;
|
||||
gint64 my_gui_size = 0;
|
||||
|
||||
@@ -434,6 +469,8 @@ gimp_object_get_memsize (GimpObject *object,
|
||||
return 0;
|
||||
}
|
||||
|
||||
priv = gimp_object_get_instance_private (object);
|
||||
|
||||
#ifdef DEBUG_MEMSIZE
|
||||
if (gimp_debug_memsize)
|
||||
{
|
||||
@@ -466,7 +503,7 @@ gimp_object_get_memsize (GimpObject *object,
|
||||
"(%" G_GINT64_FORMAT ")\n",
|
||||
indent_buf,
|
||||
g_type_name (G_TYPE_FROM_INSTANCE (object)),
|
||||
object->p->name ? object->p->name : "anonymous",
|
||||
priv->name ? priv->name : "anonymous",
|
||||
memsize,
|
||||
gui_memsize);
|
||||
|
||||
@@ -503,10 +540,11 @@ static gint64
|
||||
gimp_object_real_get_memsize (GimpObject *object,
|
||||
gint64 *gui_size)
|
||||
{
|
||||
GimpObjectPrivate *priv = gimp_object_get_instance_private (object);
|
||||
gint64 memsize = 0;
|
||||
|
||||
if (! object->p->static_name)
|
||||
memsize += gimp_string_get_memsize (object->p->name);
|
||||
if (! priv->static_name)
|
||||
memsize += gimp_string_get_memsize (priv->name);
|
||||
|
||||
return memsize + gimp_g_object_get_memsize ((GObject *) object);
|
||||
}
|
||||
|
@@ -19,24 +19,10 @@
|
||||
#define __GIMP_OBJECT_H__
|
||||
|
||||
|
||||
#define GIMP_TYPE_OBJECT (gimp_object_get_type ())
|
||||
#define GIMP_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OBJECT, GimpObject))
|
||||
#define GIMP_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OBJECT, GimpObjectClass))
|
||||
#define GIMP_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OBJECT))
|
||||
#define GIMP_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_OBJECT))
|
||||
#define GIMP_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OBJECT, GimpObjectClass))
|
||||
#define GIMP_TYPE_OBJECT (gimp_object_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (GimpObject, gimp_object, GIMP, OBJECT, GObject)
|
||||
|
||||
|
||||
typedef struct _GimpObjectPrivate GimpObjectPrivate;
|
||||
typedef struct _GimpObjectClass GimpObjectClass;
|
||||
|
||||
struct _GimpObject
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
GimpObjectPrivate *p;
|
||||
};
|
||||
|
||||
struct _GimpObjectClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
@@ -51,8 +37,6 @@ struct _GimpObjectClass
|
||||
};
|
||||
|
||||
|
||||
GType gimp_object_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void gimp_object_set_name (GimpObject *object,
|
||||
const gchar *name);
|
||||
void gimp_object_set_name_safe (GimpObject *object,
|
||||
|
Reference in New Issue
Block a user