Commit adf4f10c authored by Jon K Hellan's avatar Jon K Hellan Committed by Jon Kåre Hellan

Create with refcount 1. (style_color_new): Only increment refcount if

2002-02-08  Jon K Hellan  <hellan@acm.org>

	* src/style-color.c (style_color_new_uninterned): Create with
	refcount 1.
	(style_color_new): Only increment refcount if using cached color.

	* src/sheet.c (sheet_duplicate): Clone auto pattern color

	* src/sheet-style.c (sheet_style_init): Move auto_pattern_color
	initialization forward. sheet_style_get_auto_pattern_color is
	called from sheet_style_find below.
	(sheet_style_set_auto_pattern_color): Tag it as an auto
	color. Unref the input color.

	* src/sheet-style.[ch]: (sheet_style_get_auto_pattern_color): constify.

	* src/mstyle.c (link_pattern_color): New function.  Replace auto
	pattern color in style with sheet's auto pattern color.
	(link_border_colors): New function. Replace auto border colors in
	style with sheet's auto pattern color.
	(mstyle_link_sheet): Use target sheet's auto pattern color by
	calling link_xxxx_color functions.
	(mstyle_set_border): Fix typo.

	* plugins/excel/ms-excel-read.c (ms_excel_read_window2): No
	need to unref pattern_color,
	sheet_style_set_auto_pattern_color now does that.
parent 7bc1c924
2002-02-08 Jon K Hellan <hellan@acm.org>
* src/style-color.c (style_color_new_uninterned): Create with
refcount 1.
(style_color_new): Only increment refcount if using cached color.
* src/sheet.c (sheet_duplicate): Clone auto pattern color
* src/sheet-style.c (sheet_style_init): Move auto_pattern_color
initialization forward. sheet_style_get_auto_pattern_color is
called from sheet_style_find below.
(sheet_style_set_auto_pattern_color): Tag it as an auto
color. Unref the input color.
* src/sheet-style.[ch]: (sheet_style_get_auto_pattern_color): constify.
* src/mstyle.c (link_pattern_color): New function. Replace auto
pattern color in style with sheet's auto pattern color.
(link_border_colors): New function. Replace auto border colors in
style with sheet's auto pattern color.
(mstyle_link_sheet): Use target sheet's auto pattern color by
calling link_xxxx_color functions.
(mstyle_set_border): Fix typo.
2002-02-07 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/analysis-tools.c (anova_single_factor_tool) : be more
......
2002-02-08 Jon K Hellan <hellan@acm.org>
* src/style-color.c (style_color_new_uninterned): Create with
refcount 1.
(style_color_new): Only increment refcount if using cached color.
* src/sheet.c (sheet_duplicate): Clone auto pattern color
* src/sheet-style.c (sheet_style_init): Move auto_pattern_color
initialization forward. sheet_style_get_auto_pattern_color is
called from sheet_style_find below.
(sheet_style_set_auto_pattern_color): Tag it as an auto
color. Unref the input color.
* src/sheet-style.[ch]: (sheet_style_get_auto_pattern_color): constify.
* src/mstyle.c (link_pattern_color): New function. Replace auto
pattern color in style with sheet's auto pattern color.
(link_border_colors): New function. Replace auto border colors in
style with sheet's auto pattern color.
(mstyle_link_sheet): Use target sheet's auto pattern color by
calling link_xxxx_color functions.
(mstyle_set_border): Fix typo.
2002-02-07 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/analysis-tools.c (anova_single_factor_tool) : be more
......
2002-02-08 Jon K Hellan <hellan@acm.org>
* src/style-color.c (style_color_new_uninterned): Create with
refcount 1.
(style_color_new): Only increment refcount if using cached color.
* src/sheet.c (sheet_duplicate): Clone auto pattern color
* src/sheet-style.c (sheet_style_init): Move auto_pattern_color
initialization forward. sheet_style_get_auto_pattern_color is
called from sheet_style_find below.
(sheet_style_set_auto_pattern_color): Tag it as an auto
color. Unref the input color.
* src/sheet-style.[ch]: (sheet_style_get_auto_pattern_color): constify.
* src/mstyle.c (link_pattern_color): New function. Replace auto
pattern color in style with sheet's auto pattern color.
(link_border_colors): New function. Replace auto border colors in
style with sheet's auto pattern color.
(mstyle_link_sheet): Use target sheet's auto pattern color by
calling link_xxxx_color functions.
(mstyle_set_border): Fix typo.
2002-02-07 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/analysis-tools.c (anova_single_factor_tool) : be more
......
2002-02-08 Jon K Hellan <hellan@acm.org>
* ms-excel-read.c (ms_excel_read_window2): No need to unref
pattern_color, sheet_style_set_auto_pattern_color now does that.
2002-02-05 Jon K Hellan <hellan@acm.org>
* ms-excel-read.c (black_or_white_contrast): Burn.
......
......@@ -3395,9 +3395,6 @@ ms_excel_read_window2 (BiffQuery *q, ExcelSheet *esheet, WorkbookView *wb_view)
pattern_color->color.blue););
sheet_style_set_auto_pattern_color (
esheet->gnum_sheet, pattern_color);
/* sheet_style_set_auto_pattern_color made a copy,
and is responsible for the copy's life cycle. */
style_color_unref (pattern_color);
}
d (0, if (options & 0x0200) printf ("Sheet flag selected\n"););
......
......@@ -676,18 +676,109 @@ mstyle_unref (MStyle *style)
}
}
/**
* Replace auto pattern color in style with sheet's auto pattern color.
* make_copy tells if we are allowed to modify the style in place or we must
* make a copy first.
*/
static MStyle *
link_pattern_color (MStyle *style, StyleColor *auto_color, gboolean make_copy)
{
MStyleElementType etype = MSTYLE_COLOR_PATTERN;
StyleColor *pattern_color = style->elements[etype].u.color.any;
if (pattern_color->is_auto && auto_color != pattern_color) {
style_color_ref (auto_color);
if (make_copy) {
MStyle *orig = style;
style = mstyle_copy (style);
mstyle_unref (orig);
}
mstyle_set_color (style, etype, auto_color);
}
return style;
}
/**
* Replace auto border colors in style with sheet's auto pattern
* color. (pattern is *not* a typo.)
* make_copy tells if we are allowed to modify the style in place or we must
* make a copy first.
*
* FIXME: We conjecture that XL color 64 in border should change with the
* pattern, but not color 127. That distinction is not yet represented in
* our data structures.
*/
static MStyle *
link_border_colors (MStyle *style, StyleColor *auto_color, gboolean make_copy)
{
MStyleElementType etype;
StyleBorder *border;
StyleColor *color;
int i;
for (i = MSTYLE_BORDER_TOP ; i <= MSTYLE_BORDER_DIAGONAL ; ++i) {
if (mstyle_is_element_set (style, i)) {
border = style->elements[i].u.border.any;
color = border->color;
if (color->is_auto && auto_color != color) {
StyleBorder *new_border;
StyleBorderOrientation orientation;
switch (i) {
case MSTYLE_BORDER_LEFT:
case MSTYLE_BORDER_RIGHT:
orientation = STYLE_BORDER_VERTICAL;
break;
case MSTYLE_BORDER_REV_DIAGONAL:
case MSTYLE_BORDER_DIAGONAL:
orientation = STYLE_BORDER_DIAGONAL;
break;
case MSTYLE_BORDER_TOP:
case MSTYLE_BORDER_BOTTOM:
default:
orientation = STYLE_BORDER_HORIZONTAL;
break;
}
style_color_ref (auto_color);
new_border = style_border_fetch (
border->line_type, auto_color,
orientation);
if (make_copy) {
MStyle *orig = style;
style = mstyle_copy (style);
mstyle_unref (orig);
make_copy = FALSE;
}
mstyle_set_border (style, i, new_border);
}
return style;
}
}
}
/**
* mstyle_link_sheet :
* @style :
* @sheet :
*
* ABSORBS a reference to the style and sets the link count to 1.
*
* Where auto pattern color occurs in the style (it may for pattern and
* borders), it is replaced with the sheet's auto pattern color. We make
* sure that we do not modify the style which was passed in to us, but also
* that we don't copy more than once. The final argument to the
* link_xxxxx_color functions tell whether or not to copy.
*/
MStyle *
mstyle_link_sheet (MStyle *style, Sheet *sheet)
{
StyleColor *auto_color;
MStyle *orig = style;
int i;
if (style->linked_sheet != NULL) {
MStyle *orig = style;
style = mstyle_copy (style);
mstyle_unref (orig);
......@@ -698,6 +789,12 @@ mstyle_link_sheet (MStyle *style, Sheet *sheet)
g_return_val_if_fail (style->link_count == 0, style);
g_return_val_if_fail (style->linked_sheet == NULL, style);
auto_color = sheet_style_get_auto_pattern_color (sheet);
if (mstyle_is_element_set (style, MSTYLE_COLOR_PATTERN))
style = link_pattern_color (style, auto_color, style == orig);
style = link_border_colors (style, auto_color, style == orig);
style_color_unref (auto_color);
style->linked_sheet = sheet;
style->link_count = 1;
......@@ -925,7 +1022,7 @@ mstyle_set_border (MStyle *st, MStyleElementType t,
st->elements[t].u.border.any = border;
break;
default:
g_warning ("Not a color element");
g_warning ("Not a border element");
break;
}
......
......@@ -422,15 +422,15 @@ sheet_style_init (Sheet *sheet)
sheet->style_data = g_new (SheetStyleData, 1);
sheet->style_data->style_hash =
g_hash_table_new (mstyle_hash, (GCompareFunc) mstyle_equal);
sheet->style_data->auto_pattern_color = g_new (StyleColor, 1);
memcpy (sheet->style_data->auto_pattern_color,
style_color_auto_pattern(), sizeof (StyleColor));
sheet->style_data->auto_pattern_color->ref_count = 1;
sheet->style_data->default_style =
sheet_style_find (sheet, mstyle_new_default ());
sheet->style_data->styles =
cell_tile_style_new (sheet->style_data->default_style,
TILE_SIMPLE);
sheet->style_data->auto_pattern_color = g_new (StyleColor, 1);
memcpy (sheet->style_data->auto_pattern_color,
style_color_auto_pattern(), sizeof (StyleColor));
sheet->style_data->auto_pattern_color->ref_count = 1;
}
static gboolean
......@@ -479,15 +479,18 @@ sheet_style_shutdown (Sheet *sheet)
void
sheet_style_set_auto_pattern_color (Sheet *sheet, StyleColor *pattern_color)
{
StyleColor *apc;
int ref_count;
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (sheet->style_data != NULL);
ref_count = sheet->style_data->auto_pattern_color->ref_count;
memcpy(sheet->style_data->auto_pattern_color, pattern_color,
sizeof (StyleColor));
sheet->style_data->auto_pattern_color->ref_count = ref_count;
apc = sheet->style_data->auto_pattern_color;
ref_count = apc->ref_count;
memcpy(apc, pattern_color, sizeof (StyleColor));
apc->is_auto = TRUE;
apc->ref_count = ref_count;
style_color_unref (pattern_color);
}
/**
......@@ -498,7 +501,7 @@ sheet_style_set_auto_pattern_color (Sheet *sheet, StyleColor *pattern_color)
* Returns the color for rendering auto colored patterns in this sheet.
*/
StyleColor *
sheet_style_get_auto_pattern_color (Sheet *sheet)
sheet_style_get_auto_pattern_color (Sheet const *sheet)
{
StyleColor *sc;
g_return_val_if_fail (IS_SHEET (sheet), style_color_black ());
......
......@@ -46,7 +46,7 @@ void sheet_style_shutdown (Sheet *sheet);
void sheet_style_set_auto_pattern_color (Sheet *sheet,
StyleColor *grid_color);
StyleColor *sheet_style_get_auto_pattern_color (Sheet *sheet);
StyleColor *sheet_style_get_auto_pattern_color (Sheet const *sheet);
MStyle const *style_list_get_style (StyleList const *l, CellPos const *pos);
void style_list_free (StyleList *l);
......
......@@ -4388,6 +4388,9 @@ sheet_duplicate (Sheet const *src)
print_info_free (dst->print_info);
dst->print_info = print_info_copy (src->print_info);
sheet_style_set_auto_pattern_color (
dst, sheet_style_get_auto_pattern_color (src));
sheet_clone_styles (src, dst);
sheet_clone_merged_regions (src, dst);
sheet_clone_colrow_info (src, dst);
......
......@@ -54,7 +54,7 @@ style_color_new_uninterned (gushort red, gushort green, gushort blue,
sc->selected_color.blue = blue;
sc->selected_color.pixel = e_color_alloc (red, green, blue);
sc->ref_count = 0;
sc->ref_count = 1;
return sc;
}
......@@ -74,8 +74,8 @@ style_color_new (gushort red, gushort green, gushort blue)
if (!sc) {
sc = style_color_new_uninterned (red, green, blue, FALSE);
g_hash_table_insert (style_color_hash, sc, sc);
}
sc->ref_count++;
} else
sc->ref_count++;
return sc;
}
......
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