Implement the LdSymbol "name" property.
This commit is contained in:
parent
ba3b348dfd
commit
2b9b543402
|
@ -103,7 +103,7 @@ ld_lua_symbol_new (const gchar *name, LdLua *lua, const gchar *ident)
|
||||||
|
|
||||||
self = g_object_new (LD_TYPE_LUA_SYMBOL, NULL);
|
self = g_object_new (LD_TYPE_LUA_SYMBOL, NULL);
|
||||||
|
|
||||||
/* TODO: Set the symbol name. */
|
ld_symbol_set_name (LD_SYMBOL (self), name);
|
||||||
|
|
||||||
self->priv->lua = lua;
|
self->priv->lua = lua;
|
||||||
g_object_ref (lua);
|
g_object_ref (lua);
|
||||||
|
|
|
@ -37,6 +37,20 @@ struct _LdSymbolPrivate
|
||||||
|
|
||||||
G_DEFINE_ABSTRACT_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT);
|
G_DEFINE_ABSTRACT_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT);
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_NAME
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_get_property (GObject *object, guint property_id,
|
||||||
|
GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_set_property (GObject *object, guint property_id,
|
||||||
|
const GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
static void ld_symbol_finalize (GObject *gobject);
|
static void ld_symbol_finalize (GObject *gobject);
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,10 +58,23 @@ static void
|
||||||
ld_symbol_class_init (LdSymbolClass *klass)
|
ld_symbol_class_init (LdSymbolClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class;
|
GObjectClass *object_class;
|
||||||
|
GParamSpec *pspec;
|
||||||
|
|
||||||
object_class = G_OBJECT_CLASS (klass);
|
object_class = G_OBJECT_CLASS (klass);
|
||||||
|
object_class->get_property = ld_symbol_get_property;
|
||||||
|
object_class->set_property = ld_symbol_set_property;
|
||||||
object_class->finalize = ld_symbol_finalize;
|
object_class->finalize = ld_symbol_finalize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LdSymbol:name:
|
||||||
|
*
|
||||||
|
* The name of this symbol.
|
||||||
|
*/
|
||||||
|
pspec = g_param_spec_string ("name", "Name",
|
||||||
|
"The name of this symbol.",
|
||||||
|
"", G_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (object_class, PROP_NAME, pspec);
|
||||||
|
|
||||||
g_type_class_add_private (klass, sizeof (LdSymbolPrivate));
|
g_type_class_add_private (klass, sizeof (LdSymbolPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +85,40 @@ ld_symbol_init (LdSymbol *self)
|
||||||
(self, LD_TYPE_SYMBOL, LdSymbolPrivate);
|
(self, LD_TYPE_SYMBOL, LdSymbolPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_get_property (GObject *object, guint property_id,
|
||||||
|
GValue *value, GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
LdSymbol *self;
|
||||||
|
|
||||||
|
self = LD_SYMBOL (object);
|
||||||
|
switch (property_id)
|
||||||
|
{
|
||||||
|
case PROP_NAME:
|
||||||
|
g_value_set_string (value, ld_symbol_get_name (self));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_set_property (GObject *object, guint property_id,
|
||||||
|
const GValue *value, GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
LdSymbol *self;
|
||||||
|
|
||||||
|
self = LD_SYMBOL (object);
|
||||||
|
switch (property_id)
|
||||||
|
{
|
||||||
|
case PROP_NAME:
|
||||||
|
ld_symbol_set_name (self, g_value_get_string (value));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ld_symbol_finalize (GObject *gobject)
|
ld_symbol_finalize (GObject *gobject)
|
||||||
{
|
{
|
||||||
|
@ -65,10 +126,44 @@ ld_symbol_finalize (GObject *gobject)
|
||||||
|
|
||||||
self = LD_SYMBOL (gobject);
|
self = LD_SYMBOL (gobject);
|
||||||
|
|
||||||
|
if (self->priv->name)
|
||||||
|
g_free (self->priv->name);
|
||||||
|
|
||||||
/* Chain up to the parent class. */
|
/* Chain up to the parent class. */
|
||||||
G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject);
|
G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ld_symbol_set_name:
|
||||||
|
* @self: An #LdSymbol object.
|
||||||
|
* @name: A new name for the symbol.
|
||||||
|
*
|
||||||
|
* Set the name of a symbol.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ld_symbol_set_name (LdSymbol *self, const gchar *name)
|
||||||
|
{
|
||||||
|
g_return_if_fail (LD_IS_SYMBOL (self));
|
||||||
|
g_return_if_fail (name != NULL);
|
||||||
|
|
||||||
|
if (self->priv->name)
|
||||||
|
g_free (self->priv->name);
|
||||||
|
self->priv->name = g_strdup (name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ld_symbol_get_name:
|
||||||
|
* @self: An #LdSymbol object.
|
||||||
|
*
|
||||||
|
* Return value: The name of the symbol.
|
||||||
|
*/
|
||||||
|
const gchar *
|
||||||
|
ld_symbol_get_name (LdSymbol *self)
|
||||||
|
{
|
||||||
|
g_return_if_fail (LD_IS_SYMBOL (self));
|
||||||
|
return self->priv->name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ld_symbol_draw:
|
* ld_symbol_draw:
|
||||||
* @self: A symbol object.
|
* @self: A symbol object.
|
||||||
|
|
|
@ -57,11 +57,12 @@ struct _LdSymbolClass
|
||||||
|
|
||||||
GType ld_symbol_get_type (void) G_GNUC_CONST;
|
GType ld_symbol_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
void ld_symbol_set_name (LdSymbol *self, const gchar *name);
|
||||||
|
const gchar *ld_symbol_get_name (LdSymbol *self);
|
||||||
|
|
||||||
void ld_symbol_draw (LdSymbol *self, cairo_t *cr);
|
void ld_symbol_draw (LdSymbol *self, cairo_t *cr);
|
||||||
|
|
||||||
/* TODO: Interface for symbol terminals
|
/* TODO: Interface for symbol terminals. */
|
||||||
* Interface + property for symbol name (will be used by _new)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
Loading…
Reference in New Issue