Commit 5c840ace authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

implement.


2006-04-30  Jody Goldberg <jody@gnome.org>

	* src/mstyle.c (gnm_style_is_complete) : implement.
parent ff6817f2
2006-04-30 Jody Goldberg <jody@gnome.org> 2006-04-30 Jody Goldberg <jody@gnome.org>
* src/mstyle.c (gnm_style_is_complete) : implement.
* src/sheet-style.c (sheet_style_get) : returns a const to make it * src/sheet-style.c (sheet_style_get) : returns a const to make it
clear not to touch the result. clear not to touch the result.
* src/workbook-view.c (wb_view_format_feedback) : update. * src/workbook-view.c (wb_view_format_feedback) : update.
......
2006-04-30 Jody Goldberg <jody@gnome.org> 2006-04-30 Jody Goldberg <jody@gnome.org>
* src/mstyle.c (gnm_style_is_complete) : implement.
* src/sheet-style.c (sheet_style_get) : returns a const to make it * src/sheet-style.c (sheet_style_get) : returns a const to make it
clear not to touch the result. clear not to touch the result.
* src/workbook-view.c (wb_view_format_feedback) : update. * src/workbook-view.c (wb_view_format_feedback) : update.
......
...@@ -1950,7 +1950,7 @@ xlsx_xf_start (GsfXMLIn *xin, xmlChar const **attrs) ...@@ -1950,7 +1950,7 @@ xlsx_xf_start (GsfXMLIn *xin, xmlChar const **attrs)
else else
style = NULL; style = NULL;
if (NULL != style) { if (NULL != style) {
style = gnm_style_merge (state->style_accum, style); style = gnm_style_new_merged (state->style_accum, style);
gnm_style_unref (state->style_accum); gnm_style_unref (state->style_accum);
state->style_accum = style; state->style_accum = style;
} else } else
......
...@@ -37,7 +37,7 @@ void cell_destroy (GnmCell *cell); ...@@ -37,7 +37,7 @@ void cell_destroy (GnmCell *cell);
void cell_relocate (GnmCell *cell, GnmExprRewriteInfo const *rwinfo); void cell_relocate (GnmCell *cell, GnmExprRewriteInfo const *rwinfo);
/* DEPRECATED */ /* DEPRECATED */
GnmCell *cell_copy (GnmCell const *cell); GnmCell *cell_dup (GnmCell const *cell);
/** /**
* GnmCell state checking * GnmCell state checking
......
...@@ -365,7 +365,7 @@ cell_calc_span (GnmCell const *cell, int *col1, int *col2) ...@@ -365,7 +365,7 @@ cell_calc_span (GnmCell const *cell, int *col1, int *col2)
ColRowInfo const *ci = sheet_col_get_info (sheet, pos_l); ColRowInfo const *ci = sheet_col_get_info (sheet, pos_l);
if (ci->visible) { if (ci->visible) {
if (cellspan_is_empty (pos_l, ri, cell)) { if (cellspan_is_empty (pos_l, ri, cell)) {
GnmStyle * const style = GnmStyle const * const style =
sheet_style_get (cell->base.sheet, pos_l, row); sheet_style_get (cell->base.sheet, pos_l, row);
if (gnm_style_get_align_h (style) != HALIGN_CENTER_ACROSS_SELECTION) if (gnm_style_get_align_h (style) != HALIGN_CENTER_ACROSS_SELECTION)
......
...@@ -2062,7 +2062,7 @@ gnm_gconf_set_hf_font (GnmStyle const *mstyle) ...@@ -2062,7 +2062,7 @@ gnm_gconf_set_hf_font (GnmStyle const *mstyle)
prefs.printer_decoration_font : prefs.printer_decoration_font :
gnm_style_new_default (); gnm_style_new_default ();
prefs.printer_decoration_font = gnm_style_merge (old_style, mstyle); prefs.printer_decoration_font = gnm_style_new_merged (old_style, mstyle);
gnm_style_unref (old_style); gnm_style_unref (old_style);
node = go_conf_get_node (root, PRINTSETUP_GCONF_DIR); node = go_conf_get_node (root, PRINTSETUP_GCONF_DIR);
......
...@@ -489,8 +489,18 @@ gnm_style_dup (GnmStyle const *src) ...@@ -489,8 +489,18 @@ gnm_style_dup (GnmStyle const *src)
return new_style; return new_style;
} }
/**
* gnm_style_new_merged :
* @src : #GnmStyle
* @overlay : #GnmStyle
*
* A new GnmStyle that contains any elements of @overlay that are set, and uses
* @src for anything that is not set in @overlay.
*
* Returns A ref to a new GnmStyle.
**/
GnmStyle * GnmStyle *
gnm_style_merge (GnmStyle const *src, GnmStyle const *overlay) gnm_style_new_merged (GnmStyle const *src, GnmStyle const *overlay)
{ {
GnmStyle *new_style = CHUNK_ALLOC0 (GnmStyle, gnm_style_pool); GnmStyle *new_style = CHUNK_ALLOC0 (GnmStyle, gnm_style_pool);
int i; int i;
...@@ -506,36 +516,46 @@ gnm_style_merge (GnmStyle const *src, GnmStyle const *overlay) ...@@ -506,36 +516,46 @@ gnm_style_merge (GnmStyle const *src, GnmStyle const *overlay)
} }
void void
gnm_style_ref (GnmStyle *style) gnm_style_ref (GnmStyle const *style)
{ {
g_return_if_fail (style != NULL); g_return_if_fail (style != NULL);
g_return_if_fail (style->ref_count > 0); g_return_if_fail (style->ref_count > 0);
style->ref_count++; ((GnmStyle *)style)->ref_count++;
d(("ref %p = %d\n", style, style->ref_count)); d(("ref %p = %d\n", style, style->ref_count));
} }
/**
* gnm_style_unref :
* @style : #GnmStyle const
*
* Unrefs and _potentially frees_ @style.
* Takes a _const_ pointer to facilitate life cycles. The const indicates that
* the content can not be changed, mainly when handling styles that are in the
* style hash.
**/
void void
gnm_style_unref (GnmStyle *style) gnm_style_unref (GnmStyle const *style)
{ {
g_return_if_fail (style != NULL); g_return_if_fail (style != NULL);
g_return_if_fail (style->ref_count > 0); g_return_if_fail (style->ref_count > 0);
d(("unref %p = %d\n", style, style->ref_count-1)); d(("unref %p = %d\n", style, style->ref_count-1));
if (style->ref_count-- <= 1) { if (((GnmStyle *)style)->ref_count-- <= 1) {
GnmStyle *unconst = (GnmStyle *)style;
int i; int i;
g_return_if_fail (style->link_count == 0); g_return_if_fail (style->link_count == 0);
g_return_if_fail (style->linked_sheet == NULL); g_return_if_fail (style->linked_sheet == NULL);
for (i = 0; i < MSTYLE_ELEMENT_MAX; i++) for (i = 0; i < MSTYLE_ELEMENT_MAX; i++)
elem_clear_contents (style, i); elem_clear_contents (unconst, i);
style->set = 0; unconst->set = 0;
clear_conditional_merges (style); clear_conditional_merges (unconst);
gnm_style_pango_clear (style); gnm_style_pango_clear (unconst);
gnm_style_font_clear (style); gnm_style_font_clear (unconst);
CHUNK_FREE (gnm_style_pool, style); CHUNK_FREE (gnm_style_pool, unconst);
} }
} }
...@@ -772,8 +792,7 @@ gnm_style_is_complete (GnmStyle const *style) ...@@ -772,8 +792,7 @@ gnm_style_is_complete (GnmStyle const *style)
{ {
g_return_val_if_fail (style != NULL, FALSE); g_return_val_if_fail (style != NULL, FALSE);
g_assert_not_reached (); return style->set == ((1u << MSTYLE_ELEMENT_MAX) - 1);
return FALSE;
} }
void void
......
...@@ -59,12 +59,12 @@ typedef enum { ...@@ -59,12 +59,12 @@ typedef enum {
GnmStyle *gnm_style_new (void); GnmStyle *gnm_style_new (void);
GnmStyle *gnm_style_new_default (void); GnmStyle *gnm_style_new_default (void);
GnmStyle *gnm_style_new_merged (GnmStyle const *orig, GnmStyle const *overlay);
GnmStyle *gnm_style_dup (GnmStyle const *src); GnmStyle *gnm_style_dup (GnmStyle const *src);
GnmStyle *gnm_style_merge (GnmStyle const *orig, GnmStyle const *overlay);
void gnm_style_merge_element (GnmStyle *dst, GnmStyle const *src, void gnm_style_merge_element (GnmStyle *dst, GnmStyle const *src,
GnmStyleElement elem); GnmStyleElement elem);
void gnm_style_ref (GnmStyle *style); void gnm_style_ref (GnmStyle const *style);
void gnm_style_unref (GnmStyle *style); void gnm_style_unref (GnmStyle const *style);
GnmStyle *gnm_style_link_sheet (GnmStyle *style, Sheet *sheet); GnmStyle *gnm_style_link_sheet (GnmStyle *style, Sheet *sheet);
void gnm_style_link (GnmStyle *style); void gnm_style_link (GnmStyle *style);
......
...@@ -891,7 +891,7 @@ sheet_autofill_dir (Sheet *sheet, gboolean singleton, ...@@ -891,7 +891,7 @@ sheet_autofill_dir (Sheet *sheet, gboolean singleton,
GList *f; GList *f;
int i; int i;
AutoFiller *af = NULL; AutoFiller *af = NULL;
GnmStyle **styles; GnmStyle const **styles;
GODateConventions const *dateconv = GODateConventions const *dateconv =
workbook_date_conv (sheet->workbook); workbook_date_conv (sheet->workbook);
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "sheet-private.h" #include "sheet-private.h"
#include "ranges.h" #include "ranges.h"
#include "cell.h" #include "cell.h"
#include "cellspan.h"
#include "sheet-style.h" #include "sheet-style.h"
#include "mstyle.h" #include "mstyle.h"
#include "expr.h" #include "expr.h"
......
...@@ -162,7 +162,7 @@ rstyle_apply (GnmStyle **old, ReplacementStyle *rs) ...@@ -162,7 +162,7 @@ rstyle_apply (GnmStyle **old, ReplacementStyle *rs)
*/ */
s = (GnmStyle *)g_hash_table_lookup (rs->cache, *old); s = (GnmStyle *)g_hash_table_lookup (rs->cache, *old);
if (s == NULL) { if (s == NULL) {
GnmStyle *tmp = gnm_style_merge (*old, rs->pstyle); GnmStyle *tmp = gnm_style_new_merged (*old, rs->pstyle);
s = sheet_style_find (rs->sheet, tmp); s = sheet_style_find (rs->sheet, tmp);
gnm_style_link (*old); gnm_style_link (*old);
g_hash_table_insert (rs->cache, *old, s); g_hash_table_insert (rs->cache, *old, s);
......
...@@ -163,7 +163,7 @@ gnm_style_conditions_overlay (GnmStyleConditions const *sc, ...@@ -163,7 +163,7 @@ gnm_style_conditions_overlay (GnmStyleConditions const *sc,
res = g_ptr_array_sized_new (sc->conditions->len); res = g_ptr_array_sized_new (sc->conditions->len);
for (i = 0 ; i < sc->conditions->len; i++) { for (i = 0 ; i < sc->conditions->len; i++) {
overlay = g_array_index (sc->conditions, GnmStyleCond, i).overlay; overlay = g_array_index (sc->conditions, GnmStyleCond, i).overlay;
merge = gnm_style_merge (base, overlay); merge = gnm_style_new_merged (base, overlay);
/* We only draw a background colour is the pattern != 0 */ /* We only draw a background colour is the pattern != 0 */
if (merge->pattern == 0 && if (merge->pattern == 0 &&
elem_is_set (overlay, MSTYLE_COLOR_BACK) && elem_is_set (overlay, MSTYLE_COLOR_BACK) &&
......
...@@ -87,7 +87,7 @@ fs_modify_style (FontSelector *fs, GnmStyle *modification) ...@@ -87,7 +87,7 @@ fs_modify_style (FontSelector *fs, GnmStyle *modification)
GnmStyle *original = fs->mstyle; GnmStyle *original = fs->mstyle;
g_return_if_fail (modification != NULL); g_return_if_fail (modification != NULL);
fs->mstyle = gnm_style_merge (original, modification); fs->mstyle = gnm_style_new_merged (original, modification);
g_signal_emit (G_OBJECT (fs), g_signal_emit (G_OBJECT (fs),
fs_signals[FONT_CHANGED], 0, modification); fs_signals[FONT_CHANGED], 0, modification);
foo_canvas_item_set (fs->font_preview_grid, foo_canvas_item_set (fs->font_preview_grid,
......
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