[gnumeric] Code cleanup
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Code cleanup
- Date: Fri, 13 Apr 2018 15:14:22 +0000 (UTC)
commit b28021932cc6380980d25e81a608060e69ce5f90
Author: Morten Welinder <terra gnome org>
Date: Fri Apr 13 11:13:56 2018 -0400
Code cleanup
ChangeLog | 3 +
plugins/sc/sc.c | 2 +-
src/Makefile.am | 1 -
src/dialogs/dialog-cell-format-cond.c | 11 ++-
src/gnm-style-impl.h | 85 -------------------------
src/item-grid.c | 9 ++-
src/mstyle.c | 110 ++++++++++++++++++++++++++++++++-
src/mstyle.h | 2 +
src/print-cell.c | 9 ++-
src/rendered-value.c | 9 ++-
src/sheet-merge.c | 2 +-
src/sheet-style.c | 25 ++++---
src/sheet.c | 6 +-
src/ssdiff.c | 3 +-
src/style-conditions.c | 9 +--
src/style.c | 1 -
src/tools/dao.c | 2 +-
17 files changed, 159 insertions(+), 130 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 22b57e9..738c36f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2018-04-13 Morten Welinder <terra gnome org>
+ * src/mstyle.c: Hide internals.
+ src/gnm-style-impl.h: Remove.
+
* src/cell.c (gnm_cell_set_format): Remove. Unused and badly
named.
diff --git a/plugins/sc/sc.c b/plugins/sc/sc.c
index fb6c81a..edfa874 100644
--- a/plugins/sc/sc.c
+++ b/plugins/sc/sc.c
@@ -42,7 +42,7 @@
#include "sheet-view.h"
#include "selection.h"
#include "rendered-value.h"
-#include "gnm-style-impl.h"
+#include "style-font.h"
#include <gsf/gsf-input.h>
#include <gsf/gsf-input-textline.h>
diff --git a/src/Makefile.am b/src/Makefile.am
index ce654bc..a77f501 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -263,7 +263,6 @@ libspreadsheet_include_HEADERS = \
gnm-so-line.h \
gnm-so-path.h \
gnm-so-polygon.h \
- gnm-style-impl.h \
gnumeric-conf.h \
gnumeric-fwd.h \
gnumeric-simple-canvas.h \
diff --git a/src/dialogs/dialog-cell-format-cond.c b/src/dialogs/dialog-cell-format-cond.c
index 0366b17..b3682dd 100644
--- a/src/dialogs/dialog-cell-format-cond.c
+++ b/src/dialogs/dialog-cell-format-cond.c
@@ -43,7 +43,6 @@
#include <commands.h>
#include <mathfunc.h>
#include <style-conditions.h>
-#include <gnm-style-impl.h>
#include <gtk/gtk.h>
@@ -463,6 +462,8 @@ cb_c_fmt_dialog_copy_button (G_GNUC_UNUSED GtkWidget *btn, CFormatState *state)
GtkTreeIter iter;
GnmParsePos pp;
GnmStyle *style;
+ GnmStyleConditions *conds;
+
/* Set the condition op */
if (gtk_tree_model_get_iter_first
(GTK_TREE_MODEL (state->editor.typestore), &iter)) {
@@ -497,10 +498,12 @@ cb_c_fmt_dialog_copy_button (G_GNUC_UNUSED GtkWidget *btn, CFormatState *state)
gnm_expr_entry_load_from_text (GNM_EXPR_ENTRY (state->editor.expr_y),
"");
/* Set the style */
- if (state->style && state->style->cond_styles)
+ conds = state->style
+ ? gnm_style_get_conditions (state->style)
+ : NULL;
+ if (conds)
style = gnm_style_dup
- (g_ptr_array_index (state->style->cond_styles,
- ind));
+ (gnm_style_get_cond_style (state->style, ind));
else {
style = gnm_style_new_default ();
gnm_style_merge (style, gsc->overlay);
diff --git a/src/item-grid.c b/src/item-grid.c
index 7e554a7..28292e6 100644
--- a/src/item-grid.c
+++ b/src/item-grid.c
@@ -31,7 +31,6 @@
#include "parse-util.h"
#include "mstyle.h"
#include "style-conditions.h"
-#include "gnm-style-impl.h" /* cheesy */
#include "position.h" /* to eval conditions */
#include "style-border.h"
#include "style-color.h"
@@ -283,6 +282,7 @@ item_grid_draw_merged_range (cairo_t *cr, GnmItemGrid *ig,
Sheet const *sheet = sv->sheet;
GnmCell const *cell = sheet_cell_get (sheet, range->start.col, range->start.row);
int const dir = sheet->text_is_rtl ? -1 : 1;
+ GnmStyleConditions *conds;
/* load style from corner which may not be visible */
GnmStyle const *style = sheet_style_get (sheet, range->start.col, range->start.row);
@@ -311,12 +311,13 @@ item_grid_draw_merged_range (cairo_t *cr, GnmItemGrid *ig,
if (l == r || t == b)
return;
- if (style->conditions) {
+ conds = gnm_style_get_conditions (style);
+ if (conds) {
GnmEvalPos ep;
int res;
eval_pos_init (&ep, (Sheet *)sheet, range->start.col, range->start.row);
- if ((res = gnm_style_conditions_eval (style->conditions, &ep)) >= 0)
- style = g_ptr_array_index (style->cond_styles, res);
+ if ((res = gnm_style_conditions_eval (conds, &ep)) >= 0)
+ style = gnm_style_get_cond_style (style, res);
}
/* Check for background THEN selection */
diff --git a/src/mstyle.c b/src/mstyle.c
index 5f21445..2eb4bbe 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -1,6 +1,5 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * gnm-style.c: Storing a style
+ * mstyle.c: Storing a style
*
* Authors:
* Michael Meeks <mmeeks gnu org>
@@ -12,9 +11,13 @@
#include "gnumeric.h"
#include "style.h"
-#include "gnm-style-impl.h"
#include "sheet-style.h"
+#include "style-border.h"
+#include "style-font.h"
+#include "style-color.h"
#include "style-conditions.h"
+#include "validation.h"
+#include "pattern.h"
#include "hlink.h"
#include "input-msg.h"
#include "application.h"
@@ -44,6 +47,77 @@ static GOMemChunk *gnm_style_pool;
#define CHUNK_FREE(p,v) g_free ((v))
#endif
+
+struct _GnmStyle {
+ unsigned int changed;
+ unsigned int set;
+
+ unsigned int hash_key;
+ unsigned int hash_key_xl;
+ unsigned int ref_count;
+ unsigned int link_count;
+ Sheet *linked_sheet;
+
+ PangoAttrList *pango_attrs;
+ double pango_attrs_zoom;
+ int pango_attrs_height;
+
+ GnmFont *font;
+ PangoContext *font_context;
+
+/* public */
+ struct _GnmStyleColor {
+ GnmColor *font;
+ GnmColor *back;
+ GnmColor *pattern;
+ } color;
+ GnmBorder *borders[MSTYLE_BORDER_DIAGONAL - MSTYLE_BORDER_TOP + 1];
+ guint32 pattern;
+
+ /* FIXME: TODO use GOFont */
+ struct _GnmStyleFontDetails {
+ GOString *name;
+ gboolean bold;
+ gboolean italic;
+ GnmUnderline underline;
+ gboolean strikethrough;
+ GOFontScript script;
+ double size;
+ } font_detail;
+
+ GOFormat const *format;
+ GnmHAlign h_align;
+ GnmVAlign v_align;
+ int indent;
+ int rotation;
+ int text_dir;
+ gboolean wrap_text;
+ gboolean shrink_to_fit;
+ gboolean contents_locked;
+ gboolean contents_hidden;
+
+ GnmValidation *validation;
+ GnmHLink *hlink;
+ GnmInputMsg *input_msg;
+ GnmStyleConditions *conditions;
+ GPtrArray *cond_styles;
+
+ GPtrArray *deps;
+};
+
+#define elem_changed(style, elem) do { (style)->changed |= (1u << (elem)); } while(0)
+#define elem_set(style, elem) do { (style)->set |= (1u << (elem)); } while(0)
+#define elem_unset(style, elem) do { (style)->set &= ~(1u << (elem)); } while(0)
+#define elem_is_set(style, elem) (((style)->set & (1u << (elem))) != 0)
+
+#define MSTYLE_ANY_BORDER MSTYLE_BORDER_TOP: \
+ case MSTYLE_BORDER_BOTTOM: \
+ case MSTYLE_BORDER_LEFT: \
+ case MSTYLE_BORDER_RIGHT: \
+ case MSTYLE_BORDER_DIAGONAL: \
+ case MSTYLE_BORDER_REV_DIAGONAL
+
+
#define UNROLLED_FOR(init_,cond_,step_,code_) \
do { \
init_; \
@@ -1005,6 +1079,14 @@ gnm_style_unlink (GnmStyle *style)
}
}
+// Internal function for sheet-style.c use only
+void
+gnm_style_abandon_link (GnmStyle *style)
+{
+ style->link_count = 0;
+ style->linked_sheet = NULL;
+}
+
gboolean
gnm_style_eq (GnmStyle const *a, GnmStyle const *b)
{
@@ -1986,6 +2068,28 @@ gnm_style_get_conditions (GnmStyle const *style)
return style->conditions;
}
+/**
+ * gnm_style_get_cond_style:
+ * @style: #GnmStyle
+ * @ix: The index of the condition for which style is desired
+ *
+ * Returns: (transfer none): the resulting style from applying the condition's
+ * style overlay onto @style.
+ **/
+GnmStyle const *
+gnm_style_get_cond_style (GnmStyle const *style, int ix)
+{
+ g_return_val_if_fail (style != NULL, NULL);
+ g_return_val_if_fail (elem_is_set (style, MSTYLE_CONDITIONS), NULL);
+ g_return_val_if_fail (style->cond_styles != NULL, NULL);
+
+ g_return_val_if_fail (ix < 0 || (unsigned)ix > style->cond_styles->len, NULL);
+
+ return g_ptr_array_index (style->cond_styles, ix);
+}
+
+
+
static gboolean
debug_style_deps (void)
{
diff --git a/src/mstyle.h b/src/mstyle.h
index dd87026..874ac1d 100644
--- a/src/mstyle.h
+++ b/src/mstyle.h
@@ -75,6 +75,7 @@ GnmStyle *gnm_style_link_sheet (GnmStyle *style, Sheet *sheet);
void gnm_style_link (GnmStyle *style);
void gnm_style_link_multiple (GnmStyle *style, int count);
void gnm_style_unlink (GnmStyle *style);
+void gnm_style_abandon_link (GnmStyle *style);
gboolean gnm_style_eq (GnmStyle const *a, GnmStyle const *b);
gboolean gnm_style_equal (GnmStyle const *a, GnmStyle const *b);
@@ -163,6 +164,7 @@ GnmInputMsg *gnm_style_get_input_msg (GnmStyle const *style);
void gnm_style_set_conditions (GnmStyle *style, GnmStyleConditions *sc);
GnmStyleConditions *gnm_style_get_conditions (GnmStyle const *style);
+GnmStyle const * gnm_style_get_cond_style (GnmStyle const *style, int ix);
void gnm_style_link_dependents (GnmStyle *style,
GnmRange const *r);
diff --git a/src/print-cell.c b/src/print-cell.c
index cbe7d37..02775b4 100644
--- a/src/print-cell.c
+++ b/src/print-cell.c
@@ -22,7 +22,6 @@
#include "value.h"
#include "style-border.h"
#include "style-conditions.h"
-#include "gnm-style-impl.h"
#include "pattern.h"
#include "cellspan.h"
#include "ranges.h"
@@ -217,6 +216,7 @@ print_merged_range_gtk (cairo_t *context,
int last;
GnmCell const *cell = sheet_cell_get (sheet, range->start.col, range->start.row);
int const dir = sheet->text_is_rtl ? -1 : 1;
+ GnmStyleConditions *conds;
/* load style from corner which may not be visible */
GnmStyle const *style = sheet_style_get (sheet, range->start.col, range->start.row);
@@ -240,12 +240,13 @@ print_merged_range_gtk (cairo_t *context,
if (l == r || t == b)
return;
- if (style->conditions) {
+ conds = gnm_style_get_conditions (style);
+ if (style) {
GnmEvalPos ep;
int res;
eval_pos_init (&ep, (Sheet *)sheet, range->start.col, range->start.row);
- if ((res = gnm_style_conditions_eval (style->conditions, &ep)) >= 0)
- style = g_ptr_array_index (style->cond_styles, res);
+ if ((res = gnm_style_conditions_eval (conds, &ep)) >= 0)
+ style = gnm_style_get_cond_style (style, res);
}
if (gnm_pattern_background_set (style, context, FALSE, NULL))
diff --git a/src/rendered-value.c b/src/rendered-value.c
index 541858b..adb4cad 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -33,7 +33,6 @@
#include "style-font.h"
#include "style-border.h"
#include "style-conditions.h"
-#include "gnm-style-impl.h"
#include "sheet.h"
#include "sheet-merge.h"
#include "gnm-format.h"
@@ -245,6 +244,7 @@ gnm_rendered_value_new (GnmCell const *cell,
PangoDirection dir;
char const *text;
gboolean debug = debug_rv ();
+ GnmStyleConditions *conds;
g_return_val_if_fail (cell != NULL, NULL);
@@ -271,14 +271,15 @@ gnm_rendered_value_new (GnmCell const *cell,
mstyle = gnm_cell_get_style (cell);
- if (mstyle->conditions) {
+ conds = gnm_style_get_conditions (mstyle);
+ if (conds) {
GnmEvalPos ep;
int res;
eval_pos_init_cell (&ep, cell);
- res = gnm_style_conditions_eval (mstyle->conditions, &ep);
+ res = gnm_style_conditions_eval (conds, &ep);
if (res >= 0)
- mstyle = g_ptr_array_index (mstyle->cond_styles, res);
+ mstyle = gnm_style_get_cond_style (mstyle, res);
}
rotation = gnm_style_get_rotation (mstyle);
diff --git a/src/sheet-merge.c b/src/sheet-merge.c
index f983672..930306a 100644
--- a/src/sheet-merge.c
+++ b/src/sheet-merge.c
@@ -65,7 +65,6 @@ gnm_sheet_merge_add (Sheet *sheet, GnmRange const *r, gboolean clear,
GSList *test;
GnmRange *r_copy;
GnmCell *cell;
- GnmStyle *style;
GnmComment *comment;
GnmRange r2;
@@ -92,6 +91,7 @@ gnm_sheet_merge_add (Sheet *sheet, GnmRange const *r, gboolean clear,
if (clear) {
int i;
+ GnmStyle *style;
sheet_redraw_range (sheet, &r2);
diff --git a/src/sheet-style.c b/src/sheet-style.c
index 8cca134..101f687 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -23,7 +23,6 @@
#include <gnumeric-config.h>
#include "sheet-style.h"
-#include "gnm-style-impl.h"
#include "ranges.h"
#include "sheet.h"
#include "expr.h"
@@ -213,8 +212,7 @@ sheet_style_find (Sheet const *sheet, GnmStyle *s)
* gnm_style_unlink as that would call sheet_style_unlink
* and thus remove "res" from the hash.
*/
- s->link_count = 0;
- s->linked_sheet = NULL;
+ gnm_style_abandon_link (s);
gnm_style_unref (s);
return res;
@@ -737,10 +735,8 @@ sheet_style_resize (Sheet *sheet, int cols, int rows)
GnmRange const *r = &sr->range;
GnmStyle *style = sr->style;
GnmRange newr;
- if (range_intersection (&newr, r, &new_full)) {
- gnm_style_ref (style);
- sheet_style_apply_range (sheet, &newr, style);
- }
+ if (range_intersection (&newr, r, &new_full))
+ sheet_style_apply_range2 (sheet, &newr, style);
}
style_list_free (styles);
@@ -1542,20 +1538,27 @@ sheet_style_get (Sheet const *sheet, int col, int row)
#define border_null(b) ((b) == none || (b) == NULL)
static void
-style_row (GnmStyle *style, int start_col, int end_col, GnmStyleRow *sr, gboolean accept_conditions)
+style_row (GnmStyle const *style, int start_col, int end_col,
+ GnmStyleRow *sr, gboolean accept_conditions)
{
GnmBorder const *top, *bottom, *none = gnm_style_border_none ();
GnmBorder const *left, *right, *v;
int const end = MIN (end_col, sr->end_col);
int i = MAX (start_col, sr->start_col);
+ GnmStyleConditions *conds;
- if (accept_conditions && style->conditions) {
+ conds = accept_conditions
+ ? gnm_style_get_conditions (style)
+ : NULL;
+ if (conds) {
GnmEvalPos ep;
int res;
for (eval_pos_init (&ep, (Sheet *)sr->sheet, i, sr->row); ep.eval.col <= end ; ep.eval.col++)
{
- res = gnm_style_conditions_eval (style->conditions, &ep);
- style_row (res >= 0 ? g_ptr_array_index (style->cond_styles, res) : style,
+ res = gnm_style_conditions_eval (conds, &ep);
+ style_row (res >= 0
+ ? gnm_style_get_cond_style (style, res)
+ : style,
ep.eval.col, ep.eval.col, sr, FALSE);
}
return;
diff --git a/src/sheet.c b/src/sheet.c
index 3f0bfbd..06b699c 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -1709,12 +1709,10 @@ sheet_cell_calc_span (GnmCell *cell, GnmSpanCalcFlags flags)
* sheet_apply_style:
* @sheet: the sheet in which can be found
* @range: the range to which should be applied
- * @mstyle: the style
+ * @mstyle: (transfer full): A #GnmStyle partial style
*
* A mid level routine that applies the supplied partial style @style to the
* target @range and performs the necessary respanning and redrawing.
- *
- * It absorbs the style reference.
**/
void
sheet_apply_style (Sheet *sheet,
@@ -3072,6 +3070,8 @@ sheet_cell_set_value (GnmCell *cell, GnmValue *v)
void
sheet_cell_set_value_gi (Sheet *sheet, int col, int row, GnmValue *v)
{
+ // This version exists because not all versions of pygobject
+ // understand transfer-full parameters
sheet_cell_set_value (sheet_cell_fetch (sheet, col, row),
value_dup (v));
}
diff --git a/src/ssdiff.c b/src/ssdiff.c
index 41c8a65..6a248c0 100644
--- a/src/ssdiff.c
+++ b/src/ssdiff.c
@@ -833,8 +833,7 @@ highlight_apply (DiffState *state, const GnmRange *r)
g_return_if_fail (IS_SHEET (sheet));
- gnm_style_ref (state->highlight_style);
- sheet_style_apply_range (sheet, r, state->highlight_style);
+ sheet_style_apply_range2 (sheet, r, state->highlight_style);
}
static void
diff --git a/src/style-conditions.c b/src/style-conditions.c
index cb93d99..fb40618 100644
--- a/src/style-conditions.c
+++ b/src/style-conditions.c
@@ -23,7 +23,6 @@
#include "gnumeric.h"
#include "style-conditions.h"
#include "mstyle.h"
-#include "gnm-style-impl.h"
#include "expr.h"
#include "expr-impl.h"
#include "cell.h"
@@ -950,10 +949,10 @@ gnm_style_conditions_overlay (GnmStyleConditions const *sc,
GnmStyle const *overlay = cond->overlay;
GnmStyle *merge = gnm_style_new_merged (base, overlay);
/* We only draw a background colour if the pattern != 0 */
- if (merge->pattern == 0 &&
- elem_is_set (overlay, MSTYLE_COLOR_BACK) &&
- !elem_is_set (overlay, MSTYLE_PATTERN))
- merge->pattern = 1;
+ if (gnm_style_get_pattern (merge) == 0 &&
+ gnm_style_is_element_set (overlay, MSTYLE_COLOR_BACK) &&
+ !gnm_style_is_element_set (overlay, MSTYLE_PATTERN))
+ gnm_style_set_pattern (merge, 1);
g_ptr_array_add (res, merge);
}
return res;
diff --git a/src/style.c b/src/style.c
index d768af0..255cbb8 100644
--- a/src/style.c
+++ b/src/style.c
@@ -11,7 +11,6 @@
#include "gnumeric.h"
#include "style.h"
#include "style-font.h"
-#include "gnm-style-impl.h"
#include "gnm-format.h"
#include "style-color.h"
diff --git a/src/tools/dao.c b/src/tools/dao.c
index 69be7dc..d7ccf33 100644
--- a/src/tools/dao.c
+++ b/src/tools/dao.c
@@ -689,7 +689,7 @@ dao_autofit_rows (data_analysis_output_t *dao)
* @row1:
* @col2:
* @row2:
- * @style:
+ * @style: (transfer full):
*
* Applies a partial style to the given region.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]