[gnumeric] .gnumeric: use enum for new anchor mode attribute.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] .gnumeric: use enum for new anchor mode attribute.
- Date: Mon, 30 Mar 2015 17:14:49 +0000 (UTC)
commit 815c2d9f8e83ae64f8832382bfdafafe7c398b2b
Author: Morten Welinder <terra gnome org>
Date: Mon Mar 30 13:14:16 2015 -0400
.gnumeric: use enum for new anchor mode attribute.
ChangeLog | 6 ++++++
gnumeric.xsd | 6 +++---
src/sheet-object.c | 17 +++++++++++++++++
src/sheet-object.h | 10 ++++++----
src/xml-sax-read.c | 17 +++--------------
src/xml-sax-write.c | 7 ++++---
6 files changed, 39 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 538d688..ea91780 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2015-03-30 Morten Welinder <terra gnome org>
+ * src/sheet-object.c (gnm_sheet_object_anchor_mode_get_type): New
+ function.
+
+ * src/xml-sax-read.c (xml_sax_read_obj): Use an enum for anchor
+ mode.
+
* src/sstest.c (test_random_randhyperg): Take var=0 case into
account when checking mean.
diff --git a/gnumeric.xsd b/gnumeric.xsd
index 18be247..4ee7173 100644
--- a/gnumeric.xsd
+++ b/gnumeric.xsd
@@ -1082,9 +1082,9 @@
<xs:simpleType name="anchor_mode">
<xs:restriction base="xs:string">
- <xs:enumeration value="absolute"/>
- <xs:enumeration value="one cell"/>
- <xs:enumeration value="two cells"/>
+ <xs:enumeration value="GNM_SO_ANCHOR_ABSOLUTE"/>
+ <xs:enumeration value="GNM_SO_ANCHOR_ONE_CELL"/>
+ <xs:enumeration value="GNM_SO_ANCHOR_TWO_CELLS"/>
</xs:restriction>
</xs:simpleType>
diff --git a/src/sheet-object.c b/src/sheet-object.c
index a857813..9642ed8 100644
--- a/src/sheet-object.c
+++ b/src/sheet-object.c
@@ -67,6 +67,23 @@ sheet_object_anchor_get_type (void)
return t;
}
+GType
+gnm_sheet_object_anchor_mode_get_type (void)
+{
+ static GType etype = 0;
+ if (etype == 0) {
+ static GEnumValue const values[] = {
+ { GNM_SO_ANCHOR_TWO_CELLS, "GNM_SO_ANCHOR_TWO_CELLS", "two-cells" },
+ { GNM_SO_ANCHOR_ONE_CELL, "GNM_SO_ANCHOR_ONE_CELL", "one-cell" },
+ { GNM_SO_ANCHOR_ABSOLUTE, "GNM_SO_ANCHOR_ABSOLUTE", "absolute" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static ("GnmSOAnchorMode", values);
+ }
+ return etype;
+}
+
+
/* Returns the class for a SheetObject */
#define SO_CLASS(so) GNM_SO_CLASS(G_OBJECT_GET_CLASS(so))
diff --git a/src/sheet-object.h b/src/sheet-object.h
index 4d035bf..9c65d5d 100644
--- a/src/sheet-object.h
+++ b/src/sheet-object.h
@@ -18,10 +18,12 @@ typedef enum {
} GnmSOResizeMode;
typedef enum {
- GNM_SO_ANCHOR_TWO_CELLS, /* move and size (if sizeable) with cells) */
- GNM_SO_ANCHOR_ONE_CELL, /* move with cells */
- GNM_SO_ANCHOR_ABSOLUTE /* anchored to the sheet */
+ GNM_SO_ANCHOR_TWO_CELLS, /* move and size (if sizeable) with cells) */
+ GNM_SO_ANCHOR_ONE_CELL, /* move with cells */
+ GNM_SO_ANCHOR_ABSOLUTE /* anchored to the sheet */
} GnmSOAnchorMode;
+GType gnm_sheet_object_anchor_mode_get_type (void);
+#define GNM_SHEET_OBJECT_ANCHOR_MODE_TYPE (gnm_sheet_object_anchor_mode_get_type ())
struct _SheetObjectAnchor {
GODrawingAnchor base;
@@ -117,7 +119,7 @@ void sheet_object_anchor_init (SheetObjectAnchor *anchor,
GnmRange const *cell_bound,
const double *offsets,
GODrawingAnchorDir direction,
- GnmSOAnchorMode mode);
+ GnmSOAnchorMode mode);
void sheet_object_pts_to_anchor (SheetObjectAnchor *anchor,
Sheet const *sheet, double const *res_pts);
SheetObjectAnchor *
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index bc79d94..4525969 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -2398,20 +2398,9 @@ xml_sax_read_obj (GsfXMLIn *xin, gboolean needs_cleanup,
for (i = 0; attrs != NULL && attrs[i] && attrs[i + 1] ; i += 2) {
if (attr_eq (attrs[i], "Name"))
sheet_object_set_name (so, CXML2C (attrs[i + 1]));
- else if (!strcmp (attrs[i], "AnchorMode")) {
- if (!strcmp (attrs[i+1], "one cell"))
- anchor_mode = GNM_SO_ANCHOR_ONE_CELL;
- else if (!strcmp (attrs[i+1], "two cells"))
- anchor_mode = GNM_SO_ANCHOR_TWO_CELLS;
- else if (!strcmp (attrs[i+1], "absolute") )
- anchor_mode = GNM_SO_ANCHOR_ABSOLUTE;
- else {
- char *str = g_strdup_printf (_("Unknown object anchor mode '%s'"),
- attrs[i+1]);
- go_io_warning_unsupported_feature (state->context, str);
- g_free (str);
- }
- } else if (attr_eq (attrs[i], "ObjectBound"))
+ else if (xml_sax_attr_enum (attrs, "AnchorMode", GNM_SHEET_OBJECT_ANCHOR_MODE_TYPE, &tmp_int))
+ anchor_mode = tmp_int;
+ else if (attr_eq (attrs[i], "ObjectBound"))
range_parse (&anchor_r, CXML2C (attrs[i + 1]), gnm_sheet_get_size (state->sheet));
else if (attr_eq (attrs[i], "ObjectOffset") &&
4 == sscanf (CXML2C (attrs[i + 1]), "%lg %lg %lg %lg",
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index 1a5ead0..6e85b1a 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -1266,9 +1266,10 @@ xml_write_objects (GnmOutputXML *state, GSList *objects)
if (so->anchor.mode != GNM_SO_ANCHOR_ABSOLUTE)
gsf_xml_out_add_cstr (state->output, "ObjectBound", range_as_string
(&so->anchor.cell_bound));
if (so->anchor.mode != GNM_SO_ANCHOR_TWO_CELLS)
- gsf_xml_out_add_cstr_unchecked (state->output, "AnchorMode",
- (so->anchor.mode == GNM_SO_ANCHOR_ONE_CELL)?
- "one cell": "absolute");
+ gsf_xml_out_add_enum (state->output,
+ "AnchorMode",
+ GNM_SHEET_OBJECT_ANCHOR_MODE_TYPE,
+ so->anchor.mode);
snprintf (buffer, sizeof (buffer), "%.3g %.3g %.3g %.3g",
so->anchor.offset [0], so->anchor.offset [1],
so->anchor.offset [2], so->anchor.offset [3]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]