[gnumeric] GnmStyle: order styles so we consistently use the same ordering in files.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] GnmStyle: order styles so we consistently use the same ordering in files.
- Date: Thu, 21 Feb 2013 20:12:05 +0000 (UTC)
commit c99058808a72e8dc23f178d8f5a0578f672c526e
Author: Morten Welinder <terra gnome org>
Date: Thu Feb 21 15:10:44 2013 -0500
GnmStyle: order styles so we consistently use the same ordering in files.
ChangeLog | 6 ++++++
plugins/excel/ms-excel-write.c | 5 ++---
plugins/sylk/sylk-write.c | 8 +++-----
src/sheet-style.c | 33 ++++++++++++++++-----------------
src/sheet-style.h | 4 ++--
src/ssindex.c | 4 ++--
6 files changed, 31 insertions(+), 29 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2ae424b..1c08b37 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-02-21 Morten Welinder <terra gnome org>
+
+ * src/sheet-style.c (sheet_style_foreach): Take a GFunc, not a
+ GHFunc. All callers changed. Impose a robust ordering.
+ (sh_all_styles): New function replacing sh_foreach.
+
2013-02-20 Morten Welinder <terra gnome org>
* src/sheet-object-graph.c (dim_start): Survive malformed xml.
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 881436c..9df7e68 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -2582,7 +2582,7 @@ cb_cell_pre_pass (gpointer ignored, GnmCell const *cell, ExcelWriteState *ewb)
}
static void
-cb_accum_styles (GnmStyle const *st, gconstpointer dummy, XLExportBase *xle)
+cb_accum_styles (GnmStyle const *st, XLExportBase *xle)
{
ExcelStyleVariant *esv = g_new (ExcelStyleVariant, 1);
esv->style = st;
@@ -2602,8 +2602,7 @@ gather_styles (ExcelWriteState *ewb)
int col, cols = MIN (XLS_MaxCol, gnm_sheet_get_max_cols(sheet));
sheet_cell_foreach (sheet,
(GHFunc) cb_cell_pre_pass, &ewb->base);
- sheet_style_foreach (sheet,
- (GHFunc) cb_accum_styles, &ewb->base);
+ sheet_style_foreach (sheet, (GFunc)cb_accum_styles, &ewb->base);
for (col = 0; col < cols; col++) {
ExcelStyleVariant esv;
esv.style = esheet->col_style[col];
diff --git a/plugins/sylk/sylk-write.c b/plugins/sylk/sylk-write.c
index 8219254..0544a72 100644
--- a/plugins/sylk/sylk-write.c
+++ b/plugins/sylk/sylk-write.c
@@ -140,9 +140,7 @@ cb_sylk_write_cell (GnmCellIter const *iter, SylkWriter *state)
}
static void
-cb_sylk_collect_styles (GnmStyle const *st,
- G_GNUC_UNUSED gconstpointer dummy,
- SylkWriter *state)
+cb_sylk_collect_styles (GnmStyle const *st, SylkWriter *state)
{
}
@@ -160,9 +158,9 @@ sylk_write_sheet (SylkWriter *state)
/* collect style and font info */
extent = sheet_get_extent (state->sheet, FALSE);
sheet_style_foreach (state->sheet,
- (GHFunc) cb_sylk_collect_styles, state);
+ (GFunc)cb_sylk_collect_styles, state);
sheet_cell_foreach (state->sheet,
- (GHFunc) cb_sylk_collect_cell_styles, state);
+ (GHFunc)cb_sylk_collect_cell_styles, state);
/*
* 1) formats P;P.....
diff --git a/src/sheet-style.c b/src/sheet-style.c
index 49a7ad7..e82f82d 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -107,21 +107,21 @@ sh_insert (GnmStyleHash *h, GnmStyle *st)
}
}
-static void
-sh_foreach (GnmStyleHash *h, GHFunc func, gpointer user)
+static GSList *
+sh_all_styles (GnmStyleHash *h)
{
GHashTableIter iter;
gpointer value;
+ GSList *res = NULL;
g_hash_table_iter_init (&iter, h);
while (g_hash_table_iter_next (&iter, NULL, &value)) {
GSList *l = value;
- while (l) {
- GnmStyle *st = l->data;
- func (st, st, user);
- l = l->next;
- }
+ for (; l; l = l->next)
+ res = g_slist_prepend (res, l->data);
}
+
+ return res;
}
static GnmStyleHash *
@@ -737,13 +737,6 @@ sheet_style_resize (Sheet *sheet, int cols, int rows)
style_list_free (styles);
}
-static void
-cb_unlink (void *key, G_GNUC_UNUSED void *value, G_GNUC_UNUSED void *user)
-{
- GnmStyle *style = key;
- gnm_style_unlink (style);
-}
-
#if USE_TILE_POOLS
static void
cb_tile_pool_leak (gpointer data, gpointer user)
@@ -781,7 +774,8 @@ sheet_style_shutdown (Sheet *sheet)
*/
table = sheet->style_data->style_hash;
sheet->style_data->style_hash = NULL;
- sh_foreach (table, cb_unlink, NULL);
+ g_slist_free_full (sh_all_styles (table),
+ (GDestroyNotify)gnm_style_unlink);
sh_destroy (table);
style_color_unref (sheet->style_data->auto_pattern_color);
@@ -3089,12 +3083,17 @@ sheet_style_region_contains_link (Sheet const *sheet, GnmRange const *r)
* Executes @func for each style in the sheet.
**/
void
-sheet_style_foreach (Sheet const *sheet, GHFunc func, gpointer user_data)
+sheet_style_foreach (Sheet const *sheet, GFunc func, gpointer user_data)
{
+ GSList *styles;
+
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (sheet->style_data != NULL);
- sh_foreach (sheet->style_data->style_hash, func, user_data);
+ styles = sh_all_styles (sheet->style_data->style_hash);
+ styles = g_slist_sort (styles, (GCompareFunc)gnm_style_cmp);
+ g_slist_foreach (styles, func, user_data);
+ g_slist_free (styles);
}
/**
diff --git a/src/sheet-style.h b/src/sheet-style.h
index ebe10f2..03de1e7 100644
--- a/src/sheet-style.h
+++ b/src/sheet-style.h
@@ -58,8 +58,8 @@ void style_row_init (GnmBorder const * * *prev_vert,
gpointer mem, gboolean hide_grid);
GnmHLink *sheet_style_region_contains_link (Sheet const *sheet, GnmRange const *r);
void sheet_style_foreach (Sheet const *sheet,
- GHFunc func,
- gpointer user_data);
+ GFunc func,
+ gpointer user_data);
void sheet_style_range_foreach (Sheet const *sheet, GnmRange const *r,
GHFunc func,
gpointer user_data);
diff --git a/src/ssindex.c b/src/ssindex.c
index 44fa843..d255734 100644
--- a/src/ssindex.c
+++ b/src/ssindex.c
@@ -122,7 +122,7 @@ cb_index_cell (G_GNUC_UNUSED gpointer ignore,
}
static void
-cb_index_styles (GnmStyle *style, gconstpointer dummy, IndexerState *state)
+cb_index_styles (GnmStyle *style, IndexerState *state)
{
if (gnm_style_is_element_set (style, MSTYLE_HLINK)) {
GnmHLink const *lnk = gnm_style_get_hlink (style);
@@ -217,7 +217,7 @@ ssindex (char const *file, GOIOContext *ioc)
/* Various stuff in styles. */
sheet_style_foreach (state.sheet,
- (GHFunc)&cb_index_styles, &state);
+ (GFunc)cb_index_styles, &state);
/* Local names. */
gnm_sheet_foreach_name (state.sheet,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]