[gnumeric] Make the font style buttons override the character attributes. [#163410]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Make the font style buttons override the character attributes. [#163410]
- Date: Mon, 19 Jul 2010 05:07:07 +0000 (UTC)
commit 8cec5cd4a83671baf62519ccaf8d170c0ac14d70
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Sun Jul 18 23:07:42 2010 -0600
Make the font style buttons override the character attributes. [#163410]
2010-07-18 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/commands.h (cmd_selection_format_toggle_font_style): new
* src/commands.c (cmd_selection_format_toggle_font_style): new
(cmd_selection_format_toggle_font_style_cb): new
(cmd_selection_format_toggle_font_style_filter): new
* src/sheet.c (sheet_apply_style_cb): call sheet_flag_style_update_range
* src/wbc-gtk-actions.c (toggle_font_attr): use
cmd_selection_format_toggle_font_style
ChangeLog | 10 ++++
NEWS | 1 +
src/commands.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++
src/commands.h | 2 +
src/sheet.c | 1 +
src/wbc-gtk-actions.c | 2 +-
6 files changed, 125 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9c6df9d..ae428ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,16 @@
2010-07-18 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * src/commands.h (cmd_selection_format_toggle_font_style): new
+ * src/commands.c (cmd_selection_format_toggle_font_style): new
+ (cmd_selection_format_toggle_font_style_cb): new
+ (cmd_selection_format_toggle_font_style_filter): new
+ * src/sheet.c (sheet_apply_style_cb): call sheet_flag_style_update_range
+ * src/wbc-gtk-actions.c (toggle_font_attr): use
+ cmd_selection_format_toggle_font_style
+
+2010-07-18 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* src/clipboard.c (clipboard_paste_region): allow single merge to single
merge pasting
* src/commands.c (CmdPasteCopy): add field
diff --git a/NEWS b/NEWS
index b3624e5..f827c96 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,7 @@ Andreas:
* Add merge and unmerge items to the cell context menu.
* Permit double-clicking of functions in the function selector.
* Allow single merge to single merge copying. [#87296]
+ * Make the font style buttons override the character attributes. [#163410]
Jean:
* Fix strong/weak cursor display. [#623241]
diff --git a/src/commands.c b/src/commands.c
index f7768ff..bb2b2ef 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -1832,6 +1832,116 @@ cmd_selection_format (WorkbookControl *wbc,
/******************************************************************/
+static gboolean
+cmd_selection_format_toggle_font_style_filter (PangoAttribute *attribute, PangoAttrType *pt)
+{
+ return ((attribute->klass->type == *pt) ||
+ ((PANGO_ATTR_RISE == *pt) && (attribute->klass->type == PANGO_ATTR_SCALE)));
+}
+
+typedef struct {
+ GOUndo *undo;
+ PangoAttrType pt;
+} csftfs;
+
+static GnmValue *
+cmd_selection_format_toggle_font_style_cb (GnmCellIter const *iter, csftfs *closure)
+{
+ if (iter->cell && iter->cell->value && VALUE_IS_STRING (iter->cell->value)) {
+ const GOFormat *fmt = VALUE_FMT (iter->cell->value);
+ if (fmt && go_format_is_markup (fmt)) {
+ const PangoAttrList *old_markup =
+ go_format_get_markup (fmt);
+ PangoAttrList *new_markup = pango_attr_list_copy ((PangoAttrList *)old_markup);
+ PangoAttrList *other = pango_attr_list_filter
+ (new_markup,
+ (PangoAttrFilterFunc) cmd_selection_format_toggle_font_style_filter,
+ &closure->pt);
+ if (other != NULL) {
+ GnmSheetRange *sr;
+ GnmRange r;
+ range_init_cellpos (&r, &iter->pp.eval);
+ sr = gnm_sheet_range_new (iter->pp.sheet, &r);
+ closure->undo = go_undo_combine (closure->undo,
+ sheet_range_set_markup_undo (sr, new_markup));
+ }
+ pango_attr_list_unref (new_markup);
+ pango_attr_list_unref (other);
+ }
+ }
+ return NULL;
+}
+
+gboolean
+cmd_selection_format_toggle_font_style (WorkbookControl *wbc,
+ GnmStyle *style, GnmStyleElement t)
+{
+ SheetView *sv = wb_control_cur_sheet_view (wbc);
+ Sheet *sheet = sv->sheet;
+ GSList *selection = selection_get_ranges (sv, FALSE), *l;
+ gboolean result;
+ char *text, *name;
+ GOUndo *undo = NULL;
+ GOUndo *redo = NULL;
+ PangoAttrType pt;
+
+
+ switch (t) {
+ case MSTYLE_FONT_BOLD:
+ pt = PANGO_ATTR_WEIGHT;
+ break;
+ case MSTYLE_FONT_ITALIC:
+ pt = PANGO_ATTR_STYLE;
+ break;
+ case MSTYLE_FONT_UNDERLINE:
+ pt = PANGO_ATTR_UNDERLINE;
+ break;
+ case MSTYLE_FONT_STRIKETHROUGH:
+ pt = PANGO_ATTR_STRIKETHROUGH;
+ break;
+ case MSTYLE_FONT_SCRIPT:
+ pt = PANGO_ATTR_RISE; /* and PANGO_ATTR_SCALE (see ) */
+ break;
+ default:
+ pt = PANGO_ATTR_INVALID;
+ break;
+ }
+
+
+ name = undo_range_list_name (sheet, selection);
+ text = g_strdup_printf (_("Setting Font Style of %s"), name);
+ g_free (name);
+
+ for (l = selection; l != NULL; l = l->next) {
+ GnmSheetRange *sr;
+ undo = go_undo_combine
+ (undo, clipboard_copy_range_undo (sheet, l->data));
+ sr = gnm_sheet_range_new (sheet, l->data);
+ redo = go_undo_combine
+ (redo, sheet_apply_style_undo (sr, style));
+ if (pt != PANGO_ATTR_INVALID) {
+ csftfs closure;
+ closure.undo = NULL;
+ closure.pt = pt;
+ sheet_foreach_cell_in_range (sheet, CELL_ITER_IGNORE_BLANK,
+ sr->range.start.col, sr->range.start.row,
+ sr->range.end.col, sr->range.end.row,
+ (CellIterFunc) cmd_selection_format_toggle_font_style_cb,
+ &closure);
+ redo = go_undo_combine (redo, closure.undo);
+ }
+ }
+ gnm_style_unref (style);
+ result = cmd_generic (wbc, text, undo, redo);
+ g_free (text);
+ range_fragment_free (selection);
+
+ return result;
+}
+
+
+/******************************************************************/
+
gboolean
cmd_resize_colrow (WorkbookControl *wbc, Sheet *sheet,
diff --git a/src/commands.h b/src/commands.h
index d28937a..6802456 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -86,6 +86,8 @@ gboolean cmd_copyrel (WorkbookControl *wbc,
gboolean cmd_selection_format (WorkbookControl *wbc,
GnmStyle *style, GnmBorder **borders,
char const *opt_translated_name);
+gboolean cmd_selection_format_toggle_font_style (WorkbookControl *wbc,
+ GnmStyle *style, GnmStyleElement t);
gboolean cmd_selection_clear (WorkbookControl *wbc, int clear_flags);
gboolean cmd_selection_colrow_hide (WorkbookControl *wbc,
gboolean is_cols, gboolean visible);
diff --git a/src/sheet.c b/src/sheet.c
index 164b8f2..72aea45 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -1536,6 +1536,7 @@ sheet_apply_style_cb (GnmSheetRange *sr,
{
gnm_style_ref (style);
sheet_apply_style (sr->sheet, &sr->range, style);
+ sheet_flag_style_update_range (sr->sheet, &sr->range);
}
GOUndo *
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index e828c97..72bc895 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -1457,7 +1457,7 @@ toggle_font_attr (WBCGtk *wbcg, GtkToggleAction *act,
case MSTYLE_FONT_SCRIPT: gnm_style_set_font_script (new_style, val); break;
}
- cmd_selection_format (wbc, new_style, NULL, _("Set Font Style"));
+ cmd_selection_format_toggle_font_style (wbc, new_style, t);
}
static void cb_font_bold (GtkToggleAction *act, WBCGtk *wbcg)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]