Commit 478f2579 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

new. (ms_object_attr_get_expr) : ditto. (ms_object_attr_destroy) : support

2002-08-12  Jody Goldberg <jody@gnome.org>

	* ms-obj.c (ms_object_attr_new_array) : new.
	(ms_object_attr_get_expr) : ditto.
	(ms_object_attr_destroy) : support arrays.
	(ms_obj_read_pre_biff8_obj) : Parse the coord list for polygons.

	* ms-excel-read.c (ms_excel_read_SUPBOOK) : do a touch more.
	Still need to write the encoded path parser.

2002-08-12  Jody Goldberg <jody@gnome.org>

	* src/sheet-object-graphic.c : Add a quicky line based polygon object.
parent 7fcd6e52
2002-08-12 Jody Goldberg <jody@gnome.org>
* src/sheet-object-graphic.c : Add a quicky line based polygon object.
2002-08-11 Jody Goldberg <jody@gnome.org>
* src/workbook-view.c (wb_view_save_as) : Doh! order these correctly.
* src/sheet-object-cell-comment.c (cell_set_comment) : fix ref leak
when adding a comment.
......
......@@ -25,6 +25,7 @@ Jody:
* Fix ref-count problem importing builtin names in XLS.
* Enable and patch the plan perfect importer.
* Fix ref-count problem with cell comments.
* Ultra basic support for Excel 95 Polygon objects.
Jukka:
* New random distribution functions (mostly integrated from the
......
2002-08-12 Jody Goldberg <jody@gnome.org>
* src/sheet-object-graphic.c : Add a quicky line based polygon object.
2002-08-11 Jody Goldberg <jody@gnome.org>
* src/workbook-view.c (wb_view_save_as) : Doh! order these correctly.
* src/sheet-object-cell-comment.c (cell_set_comment) : fix ref leak
when adding a comment.
......
2002-08-12 Jody Goldberg <jody@gnome.org>
* src/sheet-object-graphic.c : Add a quicky line based polygon object.
2002-08-11 Jody Goldberg <jody@gnome.org>
* src/workbook-view.c (wb_view_save_as) : Doh! order these correctly.
* src/sheet-object-cell-comment.c (cell_set_comment) : fix ref leak
when adding a comment.
......
2002-08-12 Jody Goldberg <jody@gnome.org>
* ms-obj.c (ms_object_attr_new_array) : new.
(ms_object_attr_get_expr) : ditto.
(ms_object_attr_destroy) : support arrays.
(ms_obj_read_pre_biff8_obj) : Parse the coord list for polygons.
* ms-excel-read.c (ms_excel_read_SUPBOOK) : do a touch more.
Still need to write the encoded path parser.
2002-08-11 Jody Goldberg <jody@gnome.org>
* ms-excel-read.c (ms_excel_read_cf) : don't leak.
2002-08-11 Jody Goldberg <jody@gnome.org>
......
......@@ -344,7 +344,10 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
esheet->gnum_sheet);
/* can not be done until we have set the sheet */
if (obj->excel_type == 0x0B) {
if (obj->excel_type == 0x09) {
sheet_object_polygon_set_points (SHEET_OBJECT (obj->gnum_obj),
ms_object_attr_get_array (obj, MS_OBJ_ATTR_POLYGON_COORDS, NULL));
} else if (obj->excel_type == 0x0B) {
sheet_widget_checkbox_set_link (SHEET_OBJECT (obj->gnum_obj),
ms_object_attr_get_expr (obj, MS_OBJ_ATTR_CHECKBOX_LINK, NULL));
} else if (obj->excel_type == 0x11) {
......@@ -432,6 +435,8 @@ ms_sheet_create_obj (MSContainer *container, MSObj *obj)
so = sheet_object_box_new (FALSE); /* placeholder */
break;
}
case 0x09: so = g_object_new (sheet_object_polygon_get_type (), NULL);
break;
case 0x0B: so = g_object_new (sheet_widget_checkbox_get_type (), NULL);
break;
case 0x0C: so = g_object_new (sheet_widget_radio_button_get_type (), NULL);
......
......@@ -94,6 +94,19 @@ ms_object_attr_new_ptr (MSObjAttrID id, gpointer val)
return res;
}
MSObjAttr *
ms_object_attr_new_array (MSObjAttrID id, GArray *array)
{
MSObjAttr *res = g_new (MSObjAttr, 1);
g_return_val_if_fail ((id & MS_OBJ_ATTR_MASK) == MS_OBJ_ATTR_IS_GARRAY_MASK, NULL);
/* be anal about constness */
*((MSObjAttrID *)&(res->id)) = id;
res->v.v_array = array;
return res;
}
MSObjAttr *
ms_object_attr_new_expr (MSObjAttrID id, GnmExpr const *expr)
{
......@@ -149,6 +162,20 @@ ms_object_attr_get_ptr (MSObj *obj, MSObjAttrID id, gpointer default_value)
return attr->v.v_ptr;
}
GArray *
ms_object_attr_get_array (MSObj *obj, MSObjAttrID id, GArray *default_value)
{
MSObjAttr *attr;
g_return_val_if_fail (obj != NULL, default_value);
g_return_val_if_fail (id & MS_OBJ_ATTR_IS_GARRAY_MASK, default_value);
attr = ms_object_attr_bag_lookup (obj->attrs, id);
if (attr == NULL)
return default_value;
return attr->v.v_array;
}
GnmExpr const *
ms_object_attr_get_expr (MSObj *obj, MSObjAttrID id, GnmExpr const *default_value)
{
......@@ -170,9 +197,15 @@ ms_object_attr_destroy (MSObjAttr *attr)
if ((attr->id & MS_OBJ_ATTR_IS_PTR_MASK) &&
attr->v.v_ptr != NULL) {
g_free (attr->v.v_ptr);
attr->v.v_ptr = NULL;
} else if ((attr->id & MS_OBJ_ATTR_IS_GARRAY_MASK) &&
attr->v.v_array != NULL) {
g_array_free (attr->v.v_array, TRUE);
attr->v.v_array = NULL;
} else if ((attr->id & MS_OBJ_ATTR_IS_EXPR_MASK) &&
attr->v.v_expr != NULL) {
attr->v.v_expr != NULL) {
gnm_expr_unref (attr->v.v_expr);
attr->v.v_expr = NULL;
}
g_free (attr);
}
......@@ -351,6 +384,7 @@ ms_obj_dump_impl (guint8 const *data, int len, int data_left, char const *name)
static gboolean
ms_obj_read_pre_biff8_obj (BiffQuery *q, MSContainer *container, MSObj *obj)
{
guint16 peek_op;
/* TODO : Lots of docs for these things. Write the parser. */
#if 0
......@@ -365,6 +399,28 @@ ms_obj_read_pre_biff8_obj (BiffQuery *q, MSContainer *container, MSObj *obj)
obj->excel_type = GSF_LE_GET_GUINT16(q->data + 4);
obj->id = GSF_LE_GET_GUINT32(q->data + 6);
if (obj->excel_type == 9 && /* polygon */
ms_biff_query_peek_next (q, &peek_op) &&
peek_op == BIFF_COORDLIST) {
unsigned i, n;
guint tmp;
GArray *array;
ms_biff_query_next (q);
n = q->length / 2;
array = g_array_set_size (
g_array_new (FALSE, FALSE, sizeof (double)), n + 2);
for (i = 0; i < n ; i++) {
tmp = GSF_LE_GET_GUINT16 (q->data + 2*i);
g_array_index (array, double, i) = (double)tmp/ 16384.;
}
g_array_index (array, double, i) = g_array_index (array, double, 0);
g_array_index (array, double, i+1) = g_array_index (array, double, 1);
ms_object_attr_bag_insert (obj->attrs,
ms_object_attr_new_array (MS_OBJ_ATTR_POLYGON_COORDS, array));
}
return FALSE;
}
......
......@@ -45,12 +45,16 @@ typedef enum {
MS_OBJ_ATTR_IS_PTR_MASK = 0x2000,
MS_OBJ_ATTR_ANCHOR,
/* GArrays */
MS_OBJ_ATTR_IS_GARRAY_MASK = 0x4000,
MS_OBJ_ATTR_POLYGON_COORDS,
/* Expressions */
MS_OBJ_ATTR_IS_EXPR_MASK = 0x4000,
MS_OBJ_ATTR_IS_EXPR_MASK = 0x10000,
MS_OBJ_ATTR_CHECKBOX_LINK,
MS_OBJ_ATTR_SCROLLBAR_LINK,
MS_OBJ_ATTR_MASK = 0x7000
MS_OBJ_ATTR_MASK = 0x17000
} MSObjAttrID;
typedef struct {
......@@ -60,6 +64,7 @@ typedef struct {
guint32 v_uint;
guint32 v_int;
gpointer v_ptr;
GArray *v_array;
GnmExpr const *v_expr;
} v;
} MSObjAttr;
......@@ -68,12 +73,14 @@ MSObjAttr *ms_object_attr_new_flag (MSObjAttrID id);
MSObjAttr *ms_object_attr_new_uint (MSObjAttrID id, guint32 val);
MSObjAttr *ms_object_attr_new_int (MSObjAttrID id, gint32 val);
MSObjAttr *ms_object_attr_new_ptr (MSObjAttrID id, gpointer val);
MSObjAttr *ms_object_attr_new_array (MSObjAttrID id, GArray *array);
MSObjAttr *ms_object_attr_new_expr (MSObjAttrID id, GnmExpr const *expr);
guint32 ms_object_attr_get_uint (MSObj *obj, MSObjAttrID id, guint32 default_value);
gint32 ms_object_attr_get_int (MSObj *obj, MSObjAttrID id, gint32 default_value);
gpointer ms_object_attr_get_ptr (MSObj *obj, MSObjAttrID id, gpointer default_value);
GnmExpr const *ms_object_attr_get_expr (MSObj *obj, MSObjAttrID id, GnmExpr const *default_value);
guint32 ms_object_attr_get_uint (MSObj *obj, MSObjAttrID id, guint32 default_value);
gint32 ms_object_attr_get_int (MSObj *obj, MSObjAttrID id, gint32 default_value);
gpointer ms_object_attr_get_ptr (MSObj *obj, MSObjAttrID id, gpointer default_value);
GArray *ms_object_attr_get_array (MSObj *obj, MSObjAttrID id, GArray *default_value);
GnmExpr const *ms_object_attr_get_expr (MSObj *obj, MSObjAttrID id, GnmExpr const *default_value);
typedef GHashTable MSObjAttrBag;
MSObjAttrBag *ms_object_attr_bag_new (void);
......
......@@ -1140,3 +1140,207 @@ sheet_object_filled_init (GObject *obj)
GSF_CLASS (SheetObjectFilled, sheet_object_filled,
sheet_object_filled_class_init, sheet_object_filled_init,
SHEET_OBJECT_GRAPHIC_TYPE);
/************************************************************************/
#define SHEET_OBJECT_POLYGON(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SHEET_OBJECT_POLYGON_TYPE, SheetObjectPolygon))
#define SHEET_OBJECT_POLYGON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), SHEET_OBJECT_POLYGON_TYPE, SheetObjectPolygonClass))
typedef struct {
SheetObject sheet_object;
StyleColor *fill_color;
StyleColor *outline_color;
double outline_width;
GnomeCanvasPoints *points;
} SheetObjectPolygon;
typedef struct {
SheetObjectClass parent_class;
} SheetObjectPolygonClass;
static SheetObjectClass *sheet_object_polygon_parent_class;
SheetObject *
sheet_object_polygon_new (void)
{
return g_object_new (SHEET_OBJECT_POLYGON_TYPE, NULL);
}
static void
sheet_object_polygon_finalize (GObject *object)
{
SheetObjectPolygon *sop = SHEET_OBJECT_POLYGON (object);
style_color_unref (sop->fill_color);
style_color_unref (sop->outline_color);
G_OBJECT_CLASS (sheet_object_polygon_parent_class)->finalize (object);
}
static GObject *
sheet_object_polygon_new_view (SheetObject *so, SheetControl *sc, gpointer key)
{
GnumericCanvas *gcanvas = ((GnumericPane *)key)->gcanvas;
SheetObjectPolygon *sop = SHEET_OBJECT_POLYGON (so);
GnomeCanvasItem *item = NULL;
GdkColor *fill_color, *outline_color;
g_return_val_if_fail (IS_SHEET_OBJECT (so), NULL);
g_return_val_if_fail (IS_SHEET_CONTROL (sc), NULL);
g_return_val_if_fail (gcanvas != NULL, NULL);
fill_color = (sop->fill_color != NULL) ? &sop->fill_color->color : NULL;
outline_color = (sop->outline_color != NULL) ? &sop->outline_color->color : NULL;
gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM (gcanvas->sheet_object_group));
item = gnome_canvas_item_new (
gcanvas->sheet_object_group,
gnome_canvas_line_get_type (),
"fill_color_gdk", fill_color,
"width_units", sop->outline_width,
"points", sop->points,
NULL);
gnm_pane_object_register (so, item);
return G_OBJECT (item);
}
static void
sheet_object_polygon_update_bounds (SheetObject *so, GObject *view_obj)
{
double scale[6], translate[6], result[6];
GnomeCanvasPoints *points = gnome_canvas_points_new (2);
GnomeCanvasItem *view = GNOME_CANVAS_ITEM (view_obj);
SheetControlGUI *scg =
SHEET_CONTROL_GUI (sheet_object_view_control (view_obj));
scg_object_view_position (scg, so, points->coords);
art_affine_scale (scale,
fabs (points->coords[2] - points->coords[0]),
fabs (points->coords[3] - points->coords[1]));
art_affine_translate (translate,
MIN (points->coords[0], points->coords[2]),
MIN (points->coords[1], points->coords[3]));
art_affine_multiply (result, scale, translate);
gnome_canvas_item_affine_absolute (view, result);
gnome_canvas_points_free (points);
if (so->is_visible)
gnome_canvas_item_show (view);
else
gnome_canvas_item_hide (view);
}
static gboolean
sheet_object_polygon_read_xml (SheetObject *so,
XmlParseContext const *ctxt, xmlNodePtr tree)
{
SheetObjectPolygon *sop;
g_return_val_if_fail (IS_SHEET_OBJECT_POLYGON (so), TRUE);
sop = SHEET_OBJECT_POLYGON (so);
return FALSE;
}
static gboolean
sheet_object_polygon_write_xml (SheetObject const *so,
XmlParseContext const *ctxt, xmlNodePtr tree)
{
SheetObjectPolygon *sop;
g_return_val_if_fail (IS_SHEET_OBJECT_POLYGON (so), TRUE);
sop = SHEET_OBJECT_POLYGON (so);
return FALSE;
}
static SheetObject *
sheet_object_polygon_clone (SheetObject const *so, Sheet *sheet)
{
SheetObjectPolygon *sop;
SheetObjectPolygon *new_sop;
g_return_val_if_fail (IS_SHEET_OBJECT_POLYGON (so), NULL);
sop = SHEET_OBJECT_POLYGON (so);
new_sop = g_object_new (G_OBJECT_TYPE (so), NULL);
new_sop->fill_color = style_color_ref (sop->fill_color);
new_sop->outline_color = style_color_ref (sop->outline_color);
return SHEET_OBJECT (new_sop);
}
static void
sheet_object_polygon_print (SheetObject const *so, GnomePrintContext *ctx,
double base_x, double base_y)
{
}
static void
sheet_object_polygon_class_init (GObjectClass *object_class)
{
SheetObjectClass *sheet_object_class;
sheet_object_polygon_parent_class = gtk_type_class (SHEET_OBJECT_TYPE);
/* Object class method overrides */
object_class->finalize = sheet_object_polygon_finalize;
/* SheetObject class method overrides */
sheet_object_class = SHEET_OBJECT_CLASS (object_class);
sheet_object_class->new_view = sheet_object_polygon_new_view;
sheet_object_class->update_bounds = sheet_object_polygon_update_bounds;
sheet_object_class->read_xml = sheet_object_polygon_read_xml;
sheet_object_class->write_xml = sheet_object_polygon_write_xml;
sheet_object_class->clone = sheet_object_polygon_clone;
sheet_object_class->user_config = NULL;
sheet_object_class->print = sheet_object_polygon_print;
sheet_object_class->rubber_band_directly = FALSE;
}
static void
sheet_object_polygon_init (GObject *obj)
{
SheetObjectPolygon *sop;
SheetObject *so;
sop = SHEET_OBJECT_POLYGON (obj);
sop->fill_color = style_color_new_name ("black");
sop->outline_color = style_color_new_name ("white");
sop->outline_width = 1.;
sop->points = gnome_canvas_points_new (4);
sop->points->coords[0] = 0.; sop->points->coords[1] = 0.;
sop->points->coords[2] = 1.; sop->points->coords[3] = 0.;
sop->points->coords[4] = 1.; sop->points->coords[5] = 1.;
sop->points->coords[6] = 0.; sop->points->coords[7] = 1.;
so = SHEET_OBJECT (obj);
so->anchor.direction = SO_DIR_NONE_MASK;
}
GSF_CLASS (SheetObjectPolygon, sheet_object_polygon,
sheet_object_polygon_class_init, sheet_object_polygon_init,
SHEET_OBJECT_TYPE);
void
sheet_object_polygon_set_points (SheetObject *so, GArray *pairs)
{
GnomeCanvasPoints *points;
unsigned i;
GList *l;
SheetObjectPolygon *sop;
g_return_if_fail (IS_SHEET_OBJECT_POLYGON (so));
g_return_if_fail (pairs != NULL);
sop = SHEET_OBJECT_POLYGON (so);
points = gnome_canvas_points_new (pairs->len / 2);
for (i = 0 ; i < pairs->len ; i++)
points->coords [i] = g_array_index (pairs, double, i);
for (l = so->realized_list; l; l = l->next)
gnome_canvas_item_set (l->data, "points", points, NULL);
gnome_canvas_points_free (sop->points);
sop->points = points;
}
......@@ -19,4 +19,11 @@ SheetObject *sheet_object_box_new (gboolean is_oval);
void sheet_object_filled_outline_color_set (SheetObject *so,
StyleColor *color);
#define SHEET_OBJECT_POLYGON_TYPE (sheet_object_polygon_get_type ())
#define IS_SHEET_OBJECT_POLYGON(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SHEET_OBJECT_POLYGON_TYPE))
GType sheet_object_polygon_get_type (void);
SheetObject *sheet_object_polygon_new (void);
void sheet_object_polygon_set_points (SheetObject *so, GArray *pairs);
#endif /* GNUMERIC_SHEET_OBJECT_GRAPHIC_H */
......@@ -548,9 +548,9 @@ wb_view_save_as (WorkbookView *wbv, GnumFileSaver *fs, gchar const *file_name,
wb = wb_view_workbook (wbv);
io_context = gnumeric_io_context_new (context);
cmd_context_set_sensitive (context, TRUE);
gnum_file_saver_save (fs, io_context, wbv, file_name);
cmd_context_set_sensitive (context, FALSE);
gnum_file_saver_save (fs, io_context, wbv, file_name);
cmd_context_set_sensitive (context, TRUE);
error = gnumeric_io_error_occurred (io_context);
if (!error) {
......
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