[gnumeric] xls: name object types instead of using magic numbers.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] xls: name object types instead of using magic numbers.
- Date: Wed, 14 Oct 2009 00:37:00 +0000 (UTC)
commit f34336f997942be6fc1f0aa1d39fd064902b4e5d
Author: Morten Welinder <terra gnome org>
Date: Tue Oct 13 20:36:32 2009 -0400
xls: name object types instead of using magic numbers.
plugins/excel/ms-excel-read.c | 36 ++++++++--------
plugins/excel/ms-excel-write.c | 48 +++++++++++-----------
plugins/excel/ms-obj.c | 84 ++++++++++++++++++++--------------------
plugins/excel/ms-obj.h | 27 +++++++++++++
4 files changed, 111 insertions(+), 84 deletions(-)
---
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index afc7ec3..6208e8c 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -522,8 +522,8 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
case 0x00:
break;
- case 0x01: /* Line */
- case 0x04: /* Arc */
+ case MSOT_LINE: /* Line */
+ case MSOT_ARC: /* Arc */
style = go_style_new ();
style->line.color = ms_sheet_map_color
(esheet, obj, MS_OBJ_ATTR_OUTLINE_COLOR,
@@ -537,16 +537,16 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
g_object_unref (style);
break;
- case 0x09:
+ case MSOT_POLYGON:
g_object_set (G_OBJECT (so), "points",
ms_obj_attr_get_array (obj->attrs, MS_OBJ_ATTR_POLYGON_COORDS, NULL, TRUE),
NULL);
/* fallthrough */
- case 0x02: /* rectangle */
- case 0x03: /* oval */
- case 0x06: /* TextBox */
- case 0x0E: /* Label */
+ case MSOT_RECTANGLE:
+ case MSOT_OVAL:
+ case MSOT_TEXTBOX:
+ case MSOT_LABEL:
style = go_style_new ();
style->line.color = ms_sheet_map_color
(esheet, obj, MS_OBJ_ATTR_OUTLINE_COLOR,
@@ -568,14 +568,14 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
g_object_unref (style);
break;
- case 0x05: /* Chart */
+ case MSOT_CHART:
/* NOTE : We should not need to do anything for charts */
break;
- case 0x07: /* Button */
+ case MSOT_BUTTON:
break;
- case 0x08: { /* Picture */
+ case MSOT_PICTURE: {
double crop_left = 0.0;
double crop_top = 0.0;
double crop_right = 0.0;
@@ -627,19 +627,19 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
break;
}
- case 0x0B:
- case 0x70:
+ case MSOT_CHECKBOX:
+ case MSOT_TOGGLE:
sheet_widget_checkbox_set_link (obj->gnum_obj,
ms_obj_attr_get_expr (obj->attrs, MS_OBJ_ATTR_LINKED_TO_CELL, NULL, FALSE));
break;
- case 0x0C:
+ case MSOT_OPTION:
sheet_widget_radio_button_set_link (obj->gnum_obj,
ms_obj_attr_get_expr (obj->attrs, MS_OBJ_ATTR_LINKED_TO_CELL, NULL, FALSE));
break;
- case 0x10:
- case 0x11:
+ case MSOT_SPINNER:
+ case MSOT_SCROLLBAR:
sheet_widget_adjustment_set_details (obj->gnum_obj,
ms_obj_attr_get_expr (obj->attrs, MS_OBJ_ATTR_LINKED_TO_CELL, NULL, FALSE),
ms_obj_attr_get_int (obj->attrs, MS_OBJ_ATTR_SCROLLBAR_VALUE, 0),
@@ -649,14 +649,14 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
ms_obj_attr_get_int (obj->attrs, MS_OBJ_ATTR_SCROLLBAR_PAGE, 10));
break;
- case 0x12: /* List */
- case 0x14: /* Combo */
+ case MSOT_LIST: /* List */
+ case MSOT_COMBO: /* Combo */
sheet_widget_list_base_set_links (obj->gnum_obj,
ms_obj_attr_get_expr (obj->attrs, MS_OBJ_ATTR_LINKED_TO_CELL, NULL, FALSE),
ms_obj_attr_get_expr (obj->attrs, MS_OBJ_ATTR_INPUT_FROM, NULL, FALSE));
break;
- case 0x19: /* cell comment text box */
+ case MSOT_COMMENT: /* cell comment text box */
break;
default:
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index c2421bb..77d7d73 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -3968,7 +3968,7 @@ excel_write_autofilter_objs (ExcelWriteSheet *esheet)
* I am guessing is tied to the fact that XL created
* this. not the user*/
ms_objv8_write_common (bp,
- esheet->cur_obj, 0x14, 0x2101);
+ esheet->cur_obj, MSOT_COMBO, 0x2101);
ms_objv8_write_scrollbar_old (bp);
ms_objv8_write_listbox (bp, cond != NULL); /* acts as an end */
} else {
@@ -4027,7 +4027,7 @@ excel_write_chart_v8 (ExcelWriteSheet *esheet, SheetObject *so)
ms_biff_put_commit (bp);
ms_biff_put_var_next (bp, BIFF_OBJ);
- ms_objv8_write_common (bp, esheet->cur_obj, 5, 0x6011);
+ ms_objv8_write_common (bp, esheet->cur_obj, MSOT_CHART, 0x6011);
GSF_LE_SET_GUINT32 (buf, 0); /* end */
ms_biff_put_var_write (bp, buf, 4);
@@ -4168,7 +4168,7 @@ excel_write_image_v8 (ExcelWriteSheet *esheet, BlipInf *bi)
ms_biff_put_commit (bp);
ms_biff_put_var_next (bp, BIFF_OBJ);
- ms_objv8_write_common (bp, esheet->cur_obj, 8, 0x6011);
+ ms_objv8_write_common (bp, esheet->cur_obj, MSOT_PICTURE, 0x6011);
GSF_LE_SET_GUINT32 (buf, 0); /* end */
ms_biff_put_var_write (bp, buf, 4);
@@ -4289,7 +4289,7 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
: NULL;
if (IS_CELL_COMMENT (so)) {
- static float const offset [4] = { .5, .5, .5, .5 };
+ static float const offset[4] = { .5, .5, .5, .5 };
GnmRange r;
r.start = real_anchor->cell_bound.start;
@@ -4299,7 +4299,7 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
r.end.row = r.start.row + 4;
sheet_object_anchor_init (&anchor, &r, offset,
GOD_ANCHOR_DIR_DOWN_RIGHT);
- type = 0x19;
+ type = MSOT_COMMENT;
flags = 0x4011; /* not autofilled */
do_textbox = TRUE;
g_hash_table_insert (esheet->commentshash,
@@ -4308,7 +4308,7 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
} else if (IS_GNM_SO_FILLED (so)) {
gboolean is_oval;
- type = 6;
+ type = MSOT_TEXTBOX;
flags = 0x6011; /* autofilled */
g_object_get (so,
@@ -4317,40 +4317,40 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
NULL);
if (is_oval) {
shape = 3;
- type = 3;
+ type = MSOT_OVAL;
} else if (!do_textbox) {
shape = 1;
- type = 2;
+ type = MSOT_RECTANGLE;
}
} else if (GNM_IS_SOW_CHECKBOX (so)) {
shape = 0xc9;
- type = 0x0b;
+ type = MSOT_CHECKBOX;
flags = 0x0011;
g_object_get (so, "active", &checkbox_active, NULL);
} else if (GNM_IS_SOW_RADIO_BUTTON (so)) {
shape = 0xc9;
- type = 0x0c;
+ type = MSOT_OPTION;
flags = 0x0011;
g_object_get (so, "active", &checkbox_active, NULL);
} else if (GNM_IS_SOW_SPINBUTTON (so)) {
shape = 0xc9;
- type = 0x10;
+ type = MSOT_SPINNER;
flags = 0x0011;
} else if (GNM_IS_SOW_SCROLLBAR (so)) {
shape = 0xc9;
- type = 0x11;
+ type = MSOT_SCROLLBAR;
flags = 0x6011;
} else if (GNM_IS_SOW_LIST (so)) {
shape = 0xc9;
- type = 0x12;
+ type = MSOT_LIST;
flags = 0x2011;
} else if (GNM_IS_SOW_BUTTON (so)) {
shape = 0xc9;
- type = 0x07;
+ type = MSOT_BUTTON;
flags = 0x0011;
} else if (GNM_IS_SOW_COMBO (so)) {
shape = 0xc9;
- type = 0x14;
+ type = MSOT_COMBO;
flags = 0x2011;
} else {
g_assert_not_reached ();
@@ -4428,11 +4428,11 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
ms_objv8_write_common (bp, esheet->cur_obj, type, flags);
switch (type) {
- case 0x07: {
+ case MSOT_BUTTON: {
ms_objv8_write_button (bp, esheet, macro_nexpr);
break;
}
- case 0x0b: {
+ case MSOT_CHECKBOX: {
GnmExprTop const *link = sheet_widget_checkbox_get_link (so);
ms_objv8_write_checkbox (bp,
checkbox_active,
@@ -4442,7 +4442,7 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
if (link) gnm_expr_top_unref (link);
break;
}
- case 0x0c: {
+ case MSOT_OPTION: {
GnmExprTop const *link = sheet_widget_radio_button_get_link (so);
ms_objv8_write_radiobutton (bp,
checkbox_active,
@@ -4452,7 +4452,7 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
if (link) gnm_expr_top_unref (link);
break;
}
- case 0x10: {
+ case MSOT_SPINNER: {
GnmExprTop const *link = sheet_widget_adjustment_get_link (so);
GtkAdjustment *adj =
sheet_widget_adjustment_get_adjustment (so);
@@ -4465,7 +4465,7 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
if (link) gnm_expr_top_unref (link);
break;
}
- case 0x11: {
+ case MSOT_SCROLLBAR: {
GnmExprTop const *link = sheet_widget_adjustment_get_link (so);
GtkAdjustment *adj =
sheet_widget_adjustment_get_adjustment (so);
@@ -4478,8 +4478,8 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
if (link) gnm_expr_top_unref (link);
break;
}
- case 0x12:
- case 0x14: {
+ case MSOT_LIST:
+ case MSOT_COMBO: {
GnmExprTop const *res_link =
sheet_widget_list_base_get_result_link (so);
GnmExprTop const *data_link =
@@ -4496,7 +4496,7 @@ excel_write_textbox_or_widget_v8 (ExcelWriteSheet *esheet,
terminate_obj = FALSE; /* GR_LISTBOX_DATA is strange */
break;
}
- case 0x19:
+ case MSOT_COMMENT:
/* Cell comment. */
ms_objv8_write_note (bp);
break;
@@ -4552,7 +4552,7 @@ excel_write_line_v8 (ExcelWriteSheet *esheet, SheetObject *so)
BiffPut *bp = ewb->bp;
guint32 id = excel_write_start_drawing (esheet);
gsize draw_len = 0;
- int type = 1;
+ int type = MSOT_LINE;
int shape = 0x14;
int flags = 0x6011; /* autofilled */
gsize spmark, optmark;
diff --git a/plugins/excel/ms-obj.c b/plugins/excel/ms-obj.c
index 5a1746a..a48b33b 100644
--- a/plugins/excel/ms-obj.c
+++ b/plugins/excel/ms-obj.c
@@ -466,11 +466,11 @@ ms_read_TXO (BiffQuery *q, MSContainer *c, PangoAttrList **markup)
char const *h_msg = (1 <= halign && halign <= 4) ? haligns[halign-1] : "unknown h-align";
char const *v_msg = (1 <= valign && valign <= 4) ? valigns[valign-1] : "unknown v-align";
- printf ("{ TextObject\n");
- printf ("Text '%s'\n", text);
- printf ("is %s(%d), %s(%d) & %s(%d);\n",
+ g_printerr ("{ TextObject\n");
+ g_printerr ("Text '%s'\n", text);
+ g_printerr ("is %s(%d), %s(%d) & %s(%d);\n",
o_msg, orient, h_msg, halign, v_msg, valign);
- printf ("}; /* TextObject */\n");
+ g_printerr ("}; /* TextObject */\n");
}
#endif
return text;
@@ -483,15 +483,15 @@ ms_obj_dump (guint8 const *data, int len, int data_left, char const *name)
if (ms_excel_object_debug < 2)
return;
- printf ("{ %s \n", name);
+ g_printerr ("{ %s \n", name);
if (len+4 > data_left) {
- printf ("/* invalid length %d (0x%x) > %d(0x%x)*/\n",
+ g_printerr ("/* invalid length %d (0x%x) > %d(0x%x)*/\n",
len+4, len+4, data_left, data_left);
len = data_left - 4;
}
if (ms_excel_object_debug > 2)
gsf_mem_dump (data, len+4);
- printf ("}; /* %s */\n", name);
+ g_printerr ("}; /* %s */\n", name);
}
#else
#define ms_obj_dump (data, len, data_left, name) do { } while (0)
@@ -889,22 +889,22 @@ ms_obj_map_forms_obj (MSObj *obj, MSContainer *c,
guint8 const *data, guint8 const *last)
{
static struct {
- char const *key;
- unsigned excel_type;
- gboolean has_result_link;
- gboolean has_source_link; /* requires has_result_link */
+ char const *key;
+ unsigned excel_type;
+ gboolean has_result_link;
+ gboolean has_source_link; /* requires has_result_link */
} const map_forms [] = {
- { "ScrollBar.1", 0x11, TRUE, FALSE },
- { "CheckBox.1", 0x0B, TRUE, FALSE },
- { "TextBox.1", 0x06, FALSE, FALSE },
- { "CommandButton.1", 0x07, FALSE, FALSE },
- { "OptionButton.1", 0x0C, TRUE, FALSE },
- { "ListBox.1", 0x12, TRUE, TRUE },
- { "ComboBox.1", 0x14, TRUE, TRUE },
- { "ToggleButton.1", 0x70, TRUE, FALSE },
- { "SpinButton.1", 0x10, TRUE, FALSE },
- { "Label.1", 0x0E, FALSE, FALSE },
- { "Image.1", 0x08, FALSE, FALSE }
+ { "ScrollBar.1", MSOT_SCROLLBAR, TRUE, FALSE },
+ { "CheckBox.1", MSOT_CHECKBOX, TRUE, FALSE },
+ { "TextBox.1", MSOT_TEXTBOX, FALSE, FALSE },
+ { "CommandButton.1", MSOT_BUTTON, FALSE, FALSE },
+ { "OptionButton.1", MSOT_OPTION, TRUE, FALSE },
+ { "ListBox.1", MSOT_LIST, TRUE, TRUE },
+ { "ComboBox.1", MSOT_COMBO, TRUE, TRUE },
+ { "ToggleButton.1", MSOT_TOGGLE, TRUE, FALSE },
+ { "SpinButton.1", MSOT_SPINNER, TRUE, FALSE },
+ { "Label.1", MSOT_LABEL, FALSE, FALSE },
+ { "Image.1", MSOT_PICTURE, FALSE, FALSE }
};
int i;
char *type;
@@ -937,7 +937,7 @@ ms_obj_map_forms_obj (MSObj *obj, MSContainer *c,
obj->excel_type = map_forms [i].excel_type;
#ifndef NO_DEBUG_EXCEL
if (ms_excel_object_debug > 0)
- printf ("found = %s\n", map_forms[i].key);
+ g_printerr ("found = %s\n", map_forms[i].key);
#endif
if (map_forms [i].has_result_link) {
@@ -1016,9 +1016,9 @@ ms_obj_read_biff8_obj (BiffQuery *q, MSContainer *c, MSObj *obj)
obj->is_linked = (opt & 0x2) ? TRUE : FALSE;
#ifndef NO_DEBUG_EXCEL
if (ms_excel_object_debug >= 1) {
- printf ("{ /* PictOpt */\n");
- printf ("value = %x;\n", opt);
- printf ("}; /* PictOpt */\n");
+ g_printerr ("{ /* PictOpt */\n");
+ g_printerr ("value = %x;\n", opt);
+ g_printerr ("}; /* PictOpt */\n");
}
#endif
} else {
@@ -1131,15 +1131,15 @@ ms_obj_read_biff8_obj (BiffQuery *q, MSContainer *c, MSObj *obj)
if (ms_excel_object_debug == 0)
break;
- printf ("OBJECT TYPE = %d, id = %d;\n", obj->excel_type, obj->id);
+ g_printerr ("OBJECT TYPE = %d, id = %d;\n", obj->excel_type, obj->id);
if (options&0x0001)
- printf ("Locked;\n");
+ g_printerr ("Locked;\n");
if (options&0x0010)
- printf ("Printable;\n");
+ g_printerr ("Printable;\n");
if (options&0x2000)
- printf ("AutoFilled;\n");
+ g_printerr ("AutoFilled;\n");
if (options&0x4000)
- printf ("AutoLines;\n");
+ g_printerr ("AutoLines;\n");
if (ms_excel_object_debug > 4) {
/* According to the docs this should not fail
@@ -1147,7 +1147,7 @@ ms_obj_read_biff8_obj (BiffQuery *q, MSContainer *c, MSObj *obj)
* scrollbars and 0x100 for combos associated
* with filters. */
if ((options & 0x9eee) != 0)
- printf ("Unknown option flag : %x;\n",
+ g_printerr ("Unknown option flag : %x;\n",
options & 0x9eee);
}
#endif
@@ -1155,18 +1155,18 @@ ms_obj_read_biff8_obj (BiffQuery *q, MSContainer *c, MSObj *obj)
break;
default:
- printf ("ERROR : Unknown Obj record 0x%x len 0x%x dll %d;\n",
+ g_printerr ("ERROR : Unknown Obj record 0x%x len 0x%x dll %d;\n",
record_type, len, data_len_left);
}
if (data_len_left < len+4)
- printf ("record len %d (0x%x) > %d\n", len+4, len+4, data_len_left);
+ g_printerr ("record len %d (0x%x) > %d\n", len+4, len+4, data_len_left);
/* FIXME : We need a structure akin to the escher code to do this properly */
for (data_len_left -= len+4; data_len_left < 0; ) {
guint16 peek_op;
- printf ("deficit of %d\n", data_len_left);
+ g_printerr ("deficit of %d\n", data_len_left);
/* FIXME : what do we expect here ??
* I've seen what seem to be embedded drawings
@@ -1177,20 +1177,20 @@ ms_obj_read_biff8_obj (BiffQuery *q, MSContainer *c, MSObj *obj)
peek_op != BIFF_MS_O_DRAWING &&
peek_op != BIFF_TXO &&
peek_op != BIFF_OBJ)) {
- printf ("0x%x vs 0x%x\n", q->opcode, peek_op);
+ g_printerr ("0x%x vs 0x%x\n", q->opcode, peek_op);
return TRUE;
}
ms_biff_query_next (q);
data_len_left += q->length;
- printf ("merged in 0x%x with len %d\n", q->opcode, q->length);
+ g_printerr ("merged in 0x%x with len %d\n", q->opcode, q->length);
}
data = q->data + q->length - data_len_left;
}
/* The ftEnd record should have been the last */
if (data_len_left > 0) {
- printf("OBJ : unexpected extra data after Object End record;\n");
+ g_printerr("OBJ : unexpected extra data after Object End record;\n");
gsf_mem_dump (data, data_len_left);
return TRUE;
}
@@ -1267,7 +1267,7 @@ ms_read_OBJ (BiffQuery *q, MSContainer *c, MSObjAttrBag *attrs)
#ifndef NO_DEBUG_EXCEL
if (ms_excel_object_debug > 0)
- printf ("{ /* OBJ start */\n");
+ g_printerr ("{ /* OBJ start */\n");
#endif
obj = ms_obj_new (attrs);
/* When called from escher (@attrs != NULL) use the biff8 variant.
@@ -1280,7 +1280,7 @@ ms_read_OBJ (BiffQuery *q, MSContainer *c, MSObjAttrBag *attrs)
if (errors) {
#ifndef NO_DEBUG_EXCEL
if (ms_excel_object_debug > 0)
- printf ("}; /* OBJ error 1 */\n");
+ g_printerr ("}; /* OBJ error 1 */\n");
#endif
ms_obj_delete (obj);
return TRUE;
@@ -1294,8 +1294,8 @@ ms_read_OBJ (BiffQuery *q, MSContainer *c, MSObjAttrBag *attrs)
#ifndef NO_DEBUG_EXCEL
if (ms_excel_object_debug > 0) {
- printf ("Object (%d) is a '%s'\n", obj->id, obj->excel_type_name);
- printf ("}; /* OBJ end */\n");
+ g_printerr ("Object (%d) is a '%s'\n", obj->id, obj->excel_type_name);
+ g_printerr ("}; /* OBJ end */\n");
}
#endif
diff --git a/plugins/excel/ms-obj.h b/plugins/excel/ms-obj.h
index 579170e..cf4d307 100644
--- a/plugins/excel/ms-obj.h
+++ b/plugins/excel/ms-obj.h
@@ -17,6 +17,33 @@
#define MS_ANCHOR_SIZE 18
+enum {
+ MSOT_GROUP00 = 0x00, /* ??? */
+ MSOT_LINE = 0x01,
+ MSOT_RECTANGLE = 0x02,
+ MSOT_OVAL = 0x03,
+ MSOT_ARC = 0x04,
+ MSOT_CHART = 0x05,
+ MSOT_TEXTBOX = 0x06,
+ MSOT_BUTTON = 0x07,
+ MSOT_PICTURE = 0x08,
+ MSOT_POLYGON = 0x09,
+ MSOT_CHECKBOX = 0x0b,
+ MSOT_OPTION = 0x0c,
+ MSOT_EDIT = 0x0d,
+ MSOT_LABEL = 0x0e,
+ MSOT_DIALOG = 0x0f,
+ MSOT_SPINNER = 0x10,
+ MSOT_SCROLLBAR = 0x11,
+ MSOT_LIST = 0x12,
+ MSOT_GROUP = 0x13,
+ MSOT_COMBO = 0x14,
+ MSOT_COMMENT = 0x19,
+ MSOT_DRAWING = 0x1e,
+ MSOT_TOGGLE = 0x70
+};
+
+
typedef enum {
MS_OBJ_ATTR_NONE = 0,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]