Commit 815c2d9f authored by Morten Welinder's avatar Morten Welinder

.gnumeric: use enum for new anchor mode attribute.

parent 687ccf8b
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.
......
......@@ -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>
......
......@@ -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))
......
......@@ -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 *
......
......@@ -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",
......
......@@ -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]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment