text-buffer: Use macros for subclassing boilerplate
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3387>
This commit is contained in:
parent
a944889f49
commit
1df56ca77a
@ -51,7 +51,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterShaderEffect, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterStage, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterSwipeAction, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTextBuffer, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterText, g_object_unref)
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActorBox, clutter_actor_box_free)
|
||||
|
@ -66,16 +66,16 @@ enum
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
struct _ClutterTextBufferPrivate
|
||||
typedef struct _ClutterTextBufferPrivate
|
||||
{
|
||||
gint max_length;
|
||||
gint max_length;
|
||||
|
||||
/* Only valid if this class is not derived */
|
||||
gchar *normal_text;
|
||||
gsize normal_text_size;
|
||||
gsize normal_text_bytes;
|
||||
guint normal_text_chars;
|
||||
};
|
||||
gsize normal_text_size;
|
||||
gsize normal_text_bytes;
|
||||
guint normal_text_chars;
|
||||
} ClutterTextBufferPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (ClutterTextBuffer, clutter_text_buffer, G_TYPE_OBJECT)
|
||||
|
||||
@ -99,28 +99,33 @@ trash_area (gchar *area,
|
||||
|
||||
static const gchar*
|
||||
clutter_text_buffer_normal_get_text (ClutterTextBuffer *buffer,
|
||||
gsize *n_bytes)
|
||||
gsize *n_bytes)
|
||||
{
|
||||
ClutterTextBufferPrivate *priv =
|
||||
clutter_text_buffer_get_instance_private (buffer);
|
||||
if (n_bytes)
|
||||
*n_bytes = buffer->priv->normal_text_bytes;
|
||||
if (!buffer->priv->normal_text)
|
||||
return "";
|
||||
return buffer->priv->normal_text;
|
||||
*n_bytes = priv->normal_text_bytes;
|
||||
if (!priv->normal_text)
|
||||
return "";
|
||||
return priv->normal_text;
|
||||
}
|
||||
|
||||
static guint
|
||||
clutter_text_buffer_normal_get_length (ClutterTextBuffer *buffer)
|
||||
{
|
||||
return buffer->priv->normal_text_chars;
|
||||
ClutterTextBufferPrivate *priv =
|
||||
clutter_text_buffer_get_instance_private (buffer);
|
||||
return priv->normal_text_chars;
|
||||
}
|
||||
|
||||
static guint
|
||||
clutter_text_buffer_normal_insert_text (ClutterTextBuffer *buffer,
|
||||
guint position,
|
||||
const gchar *chars,
|
||||
guint n_chars)
|
||||
guint position,
|
||||
const gchar *chars,
|
||||
guint n_chars)
|
||||
{
|
||||
ClutterTextBufferPrivate *pv = buffer->priv;
|
||||
ClutterTextBufferPrivate *pv =
|
||||
clutter_text_buffer_get_instance_private (buffer);;
|
||||
gsize prev_size;
|
||||
gsize n_bytes;
|
||||
gsize at;
|
||||
@ -181,10 +186,11 @@ clutter_text_buffer_normal_insert_text (ClutterTextBuffer *buffer,
|
||||
|
||||
static guint
|
||||
clutter_text_buffer_normal_delete_text (ClutterTextBuffer *buffer,
|
||||
guint position,
|
||||
guint n_chars)
|
||||
guint position,
|
||||
guint n_chars)
|
||||
{
|
||||
ClutterTextBufferPrivate *pv = buffer->priv;
|
||||
ClutterTextBufferPrivate *pv =
|
||||
clutter_text_buffer_get_instance_private (buffer);;
|
||||
gsize start, end;
|
||||
|
||||
if (position > pv->normal_text_chars)
|
||||
@ -244,19 +250,21 @@ clutter_text_buffer_real_deleted_text (ClutterTextBuffer *buffer,
|
||||
static void
|
||||
clutter_text_buffer_init (ClutterTextBuffer *self)
|
||||
{
|
||||
self->priv = clutter_text_buffer_get_instance_private (self);
|
||||
ClutterTextBufferPrivate *priv =
|
||||
clutter_text_buffer_get_instance_private (self);
|
||||
|
||||
self->priv->normal_text = NULL;
|
||||
self->priv->normal_text_chars = 0;
|
||||
self->priv->normal_text_bytes = 0;
|
||||
self->priv->normal_text_size = 0;
|
||||
priv->normal_text = NULL;
|
||||
priv->normal_text_chars = 0;
|
||||
priv->normal_text_bytes = 0;
|
||||
priv->normal_text_size = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_text_buffer_finalize (GObject *obj)
|
||||
{
|
||||
ClutterTextBuffer *buffer = CLUTTER_TEXT_BUFFER (obj);
|
||||
ClutterTextBufferPrivate *pv = buffer->priv;
|
||||
ClutterTextBufferPrivate *pv =
|
||||
clutter_text_buffer_get_instance_private (buffer);
|
||||
|
||||
if (pv->normal_text)
|
||||
{
|
||||
@ -557,14 +565,17 @@ void
|
||||
clutter_text_buffer_set_max_length (ClutterTextBuffer *buffer,
|
||||
gint max_length)
|
||||
{
|
||||
ClutterTextBufferPrivate *priv;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_TEXT_BUFFER (buffer));
|
||||
|
||||
priv = clutter_text_buffer_get_instance_private (buffer);
|
||||
max_length = CLAMP (max_length, 0, CLUTTER_TEXT_BUFFER_MAX_SIZE);
|
||||
|
||||
if (max_length > 0 && clutter_text_buffer_get_length (buffer) > max_length)
|
||||
clutter_text_buffer_delete_text (buffer, max_length, -1);
|
||||
|
||||
buffer->priv->max_length = max_length;
|
||||
priv->max_length = max_length;
|
||||
g_object_notify_by_pspec (G_OBJECT (buffer), obj_props[PROP_MAX_LENGTH]);
|
||||
}
|
||||
|
||||
@ -581,8 +592,12 @@ clutter_text_buffer_set_max_length (ClutterTextBuffer *buffer,
|
||||
gint
|
||||
clutter_text_buffer_get_max_length (ClutterTextBuffer *buffer)
|
||||
{
|
||||
ClutterTextBufferPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_TEXT_BUFFER (buffer), 0);
|
||||
return buffer->priv->max_length;
|
||||
|
||||
priv = clutter_text_buffer_get_instance_private (buffer);
|
||||
return priv->max_length;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -617,7 +632,7 @@ clutter_text_buffer_insert_text (ClutterTextBuffer *buffer,
|
||||
g_return_val_if_fail (CLUTTER_IS_TEXT_BUFFER (buffer), 0);
|
||||
|
||||
length = clutter_text_buffer_get_length (buffer);
|
||||
pv = buffer->priv;
|
||||
pv = clutter_text_buffer_get_instance_private (buffer);;
|
||||
|
||||
if (n_chars < 0)
|
||||
n_chars = g_utf8_strlen (chars, -1);
|
||||
|
@ -28,11 +28,13 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_TEXT_BUFFER (clutter_text_buffer_get_type ())
|
||||
#define CLUTTER_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_TEXT_BUFFER, ClutterTextBuffer))
|
||||
#define CLUTTER_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_TEXT_BUFFER, ClutterTextBufferClass))
|
||||
#define CLUTTER_IS_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_TEXT_BUFFER))
|
||||
#define CLUTTER_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_TEXT_BUFFER))
|
||||
#define CLUTTER_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_TEXT_BUFFER, ClutterTextBufferClass))
|
||||
|
||||
CLUTTER_EXPORT
|
||||
G_DECLARE_DERIVABLE_TYPE (ClutterTextBuffer,
|
||||
clutter_text_buffer,
|
||||
CLUTTER,
|
||||
TEXT_BUFFER,
|
||||
GObject)
|
||||
|
||||
/**
|
||||
* CLUTTER_TEXT_BUFFER_MAX_SIZE:
|
||||
@ -41,18 +43,6 @@ G_BEGIN_DECLS
|
||||
*/
|
||||
#define CLUTTER_TEXT_BUFFER_MAX_SIZE G_MAXUSHORT
|
||||
|
||||
typedef struct _ClutterTextBuffer ClutterTextBuffer;
|
||||
typedef struct _ClutterTextBufferClass ClutterTextBufferClass;
|
||||
typedef struct _ClutterTextBufferPrivate ClutterTextBufferPrivate;
|
||||
|
||||
struct _ClutterTextBuffer
|
||||
{
|
||||
/*< private >*/
|
||||
GObject parent_instance;
|
||||
|
||||
ClutterTextBufferPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* ClutterTextBufferClass:
|
||||
* @inserted_text: default handler for the #ClutterTextBuffer::inserted-text signal
|
||||
@ -97,9 +87,6 @@ struct _ClutterTextBufferClass
|
||||
guint n_chars);
|
||||
};
|
||||
|
||||
CLUTTER_EXPORT
|
||||
GType clutter_text_buffer_get_type (void) G_GNUC_CONST;
|
||||
|
||||
CLUTTER_EXPORT
|
||||
ClutterTextBuffer* clutter_text_buffer_new (void);
|
||||
CLUTTER_EXPORT
|
||||
|
Loading…
Reference in New Issue
Block a user