From 121d923d296957e57e3a3673f4d0f001e3886403 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Wed, 27 Oct 2010 18:15:31 +0200
Subject: Added an "area" property to LdSymbol.
To accomplish this, LdSymbolArea had to be converted
to a regular boxed type.
---
src/ld-symbol.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/ld-symbol.h | 45 ++++++++++++++++++++++---------------
2 files changed, 95 insertions(+), 19 deletions(-)
diff --git a/src/ld-symbol.c b/src/ld-symbol.c
index 92e0baa..42c01cd 100644
--- a/src/ld-symbol.c
+++ b/src/ld-symbol.c
@@ -17,6 +17,55 @@
#include "ld-library.h"
+/**
+ * ld_symbol_area_copy:
+ * @self: An #LdSymbolArea structure.
+ *
+ * Makes a copy of the structure.
+ * The result must be freed by ld_symbol_area_free().
+ *
+ * Return value: A copy of @self.
+ **/
+LdSymbolArea *
+ld_symbol_area_copy (const LdSymbolArea *self)
+{
+ LdSymbolArea *new_area;
+
+ g_return_val_if_fail (self != NULL, NULL);
+
+ new_area = g_slice_new (LdSymbolArea);
+ *new_area = *self;
+ return new_area;
+}
+
+/**
+ * ld_symbol_area_free:
+ * @self: An #LdSymbolArea structure.
+ *
+ * Frees the structure created with ld_symbol_area_copy().
+ **/
+void
+ld_symbol_area_free (LdSymbolArea *self)
+{
+ g_return_if_fail (self != NULL);
+
+ g_slice_free (LdSymbolArea, self);
+}
+
+GType
+ld_symbol_area_get_type (void)
+{
+ static GType our_type = 0;
+
+ if (our_type == 0)
+ our_type = g_boxed_type_register_static
+ (g_intern_static_string ("LdSymbolArea"),
+ (GBoxedCopyFunc) ld_symbol_area_copy,
+ (GBoxedFreeFunc) ld_symbol_area_free);
+ return our_type;
+}
+
+
/**
* SECTION:ld-symbol
* @short_description: A symbol.
@@ -33,7 +82,7 @@ enum
PROP_0,
PROP_NAME,
PROP_HUMAN_NAME,
- /* TODO: Property for the area. */
+ PROP_AREA
};
static void
@@ -76,6 +125,16 @@ ld_symbol_class_init (LdSymbolClass *klass)
"The localized human name of this symbol.",
"", G_PARAM_READABLE);
g_object_class_install_property (object_class, PROP_HUMAN_NAME, pspec);
+
+/**
+ * LdSymbol:area:
+ *
+ * The area of this symbol.
+ */
+ pspec = g_param_spec_boxed ("area", "Area",
+ "The area of this symbol.",
+ LD_TYPE_SYMBOL_AREA, G_PARAM_READABLE);
+ g_object_class_install_property (object_class, PROP_AREA, pspec);
}
static void
@@ -98,6 +157,14 @@ ld_symbol_get_property (GObject *object, guint property_id,
case PROP_HUMAN_NAME:
g_value_set_string (value, ld_symbol_get_human_name (self));
break;
+ case PROP_AREA:
+ {
+ LdSymbolArea area;
+
+ ld_symbol_get_area (self, &area);
+ g_value_set_boxed (value, &area);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
diff --git a/src/ld-symbol.h b/src/ld-symbol.h
index 92d7d82..b0ef883 100644
--- a/src/ld-symbol.h
+++ b/src/ld-symbol.h
@@ -14,6 +14,33 @@
G_BEGIN_DECLS
+#define LD_TYPE_SYMBOL_AREA (ld_symbol_area_get_type ())
+
+typedef struct _LdSymbolArea LdSymbolArea;
+
+/**
+ * LdSymbolArea:
+ * @x1: Left-top X coordinate.
+ * @y1: Left-top Y coordinate.
+ * @x2: Right-bottom X coordinate.
+ * @y2: Right-bottom Y coordinate.
+ *
+ * Defines the area of the symbol relative to the center of the symbol,
+ * which is at the (0, 0) coordinates.
+ */
+struct _LdSymbolArea
+{
+ gdouble x1, y1;
+ gdouble x2, y2;
+};
+
+
+GType ld_symbol_area_get_type (void) G_GNUC_CONST;
+
+LdSymbolArea *ld_symbol_area_copy (const LdSymbolArea *self);
+void ld_symbol_area_free (LdSymbolArea *self);
+
+
#define LD_TYPE_SYMBOL (ld_symbol_get_type ())
#define LD_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST \
((obj), LD_TYPE_SYMBOL, LdSymbol))
@@ -30,8 +57,6 @@ typedef struct _LdSymbol LdSymbol;
typedef struct _LdSymbolPrivate LdSymbolPrivate;
typedef struct _LdSymbolClass LdSymbolClass;
-typedef struct _LdSymbolArea LdSymbolArea;
-
/**
* LdSymbol:
@@ -44,22 +69,6 @@ struct _LdSymbol
LdSymbolPrivate *priv;
};
-/**
- * LdSymbolArea:
- * @x1: Left-top X coordinate.
- * @y1: Left-top Y coordinate.
- * @x2: Right-bottom X coordinate.
- * @y2: Right-bottom Y coordinate.
- *
- * Defines the area of the symbol relative to the center of the symbol,
- * which is at the (0, 0) coordinates.
- */
-struct _LdSymbolArea
-{
- gdouble x1, y1;
- gdouble x2, y2;
-};
-
/**
* LdSymbolClass:
* @parent_class: The parent class.
--
cgit v1.2.3-70-g09d2