[gnumeric] Add paste special flip horizontally and vertically [#393367]



commit 4f01cefae9f2e6a1d507d4209fb2667ecf31aaea
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Sun Dec 20 19:51:21 2009 -0700

    Add paste special flip horizontally and vertically [#393367]
    
    2009-12-20  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/sheet-style.h (sheet_style_set_list): change arguments
    	* src/sheet.c: change all calls to sheet_style_set_list
    	* src/commands.c: ditto
    	* src/sheet-style.c: ditto
    	(sheet_style_set_list): change arguments and adjust code
    	* src/clipboard.c (range_flip_h): new
    	(range_flip_v): new
    	(clipboard_paste_region): handle PASTE_FLIP_H and
    	  PASTE_FLIP for styles

 ChangeLog         |   12 +++++++++++
 NEWS              |    2 +-
 src/clipboard.c   |   54 ++++++++++++++++++++++++++++++++++++++++++++++++----
 src/commands.c    |    6 ++--
 src/sheet-style.c |   13 +++++++----
 src/sheet-style.h |   11 ++++++++-
 src/sheet.c       |    2 +-
 7 files changed, 83 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2dfbbcb..21c894a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-12-20  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/sheet-style.h (sheet_style_set_list): change arguments
+	* src/sheet.c: change all calls to sheet_style_set_list
+	* src/commands.c: ditto
+	* src/sheet-style.c: ditto
+	(sheet_style_set_list): change arguments and adjust code
+	* src/clipboard.c (range_flip_h): new
+	(range_flip_v): new
+	(clipboard_paste_region): handle PASTE_FLIP_H and 
+	  PASTE_FLIP for styles
+
 2009-12-19  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/clipboard.h: add PASTE_FLIP_H and PASTE_FLIP_V
diff --git a/NEWS b/NEWS
index a241bbc..b722d50 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,7 @@
 Gnumeric 1.9.18
 
 Andreas:
-	* Add paste special flip horizontally and vertically (for content)
+	* Add paste special flip horizontally and vertically [#393367]
 
 --------------------------------------------------------------------------
 Gnumeric 1.9.17
diff --git a/src/clipboard.c b/src/clipboard.c
index 18a83da..3df1d69 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -328,6 +328,32 @@ cb_paste_cell (GnmCellCopy const *src, gconstpointer ignore,
 	paste_cell (target_col, target_row, src, dat);
 }
 
+static gboolean
+range_flip_h (GnmRange *range, Sheet const *sheet, int const *data)
+{
+	int t;
+
+	g_return_val_if_fail (range != NULL, TRUE);
+
+	t = *data - range->end.col;
+	range->end.col = *data -  range->start.col;
+	range->start.col = t;
+
+	return FALSE;
+}
+static gboolean
+range_flip_v (GnmRange *range, Sheet const *sheet, int const *data)
+{
+	int t;
+
+	g_return_val_if_fail (range != NULL, TRUE);
+
+	t = *data - range->end.row;
+	range->end.row = *data -  range->start.row;
+	range->start.row = t;
+
+	return FALSE;
+}
 
 /**
  * clipboard_paste_region:
@@ -487,11 +513,29 @@ clipboard_paste_region (GnmCellRegion const *cr,
 			}
 
 			/* Move the styles on here so we get correct formats before recalc */
-			if (pt->paste_flags & PASTE_FORMATS)
-				sheet_style_set_list (pt->sheet, &dat.top_left,
-					(pt->paste_flags & PASTE_TRANSPOSE),
-					cr->styles);
-
+			if (pt->paste_flags & PASTE_FORMATS) {
+				if (pt->paste_flags & PASTE_TRANSPOSE) 
+					sheet_style_set_list (pt->sheet, &dat.top_left,
+							      cr->styles, 
+							      (sheet_style_set_list_cb_t)
+							      range_transpose, 
+							      &dat.top_left);
+				else if (pt->paste_flags & PASTE_FLIP_H) {
+					int data = 2 * left + src_cols - 1;
+					sheet_style_set_list (pt->sheet, &dat.top_left,
+							      cr->styles, 
+							      (sheet_style_set_list_cb_t)
+							      range_flip_h, &data);
+				} else if (pt->paste_flags & PASTE_FLIP_V) {
+					int data = 2 * top + src_rows - 1;
+					sheet_style_set_list (pt->sheet, &dat.top_left,
+							      cr->styles,  
+							      (sheet_style_set_list_cb_t)
+							      range_flip_v, &data);
+				} else
+					sheet_style_set_list (pt->sheet, &dat.top_left,
+							      cr->styles, NULL, NULL);
+			}
 			if (has_contents && !(pt->paste_flags & PASTE_DONT_MERGE)) {
 				for (ptr = cr->merged; ptr != NULL ; ptr = ptr->next) {
 					GnmRange tmp = *((GnmRange const *)ptr->data);
diff --git a/src/commands.c b/src/commands.c
index b7be795..59a5bd1 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -1670,7 +1670,7 @@ cmd_format_undo (GnmCommand *cmd,
 			GnmRange const *r = l2->data;
 			GnmSpanCalcFlags flags = sheet_style_set_list
 				(me->cmd.sheet,
-				 &os->pos, FALSE, os->styles);
+				 &os->pos, os->styles, NULL, NULL);
 
 			if (os->old_heights) {
 				colrow_restore_state_group (me->cmd.sheet, FALSE,
@@ -3402,7 +3402,7 @@ cmd_autoformat_undo (GnmCommand *cmd,
 			GnmRange *r;
 			CmdAutoFormatOldStyle *os = l1->data;
 			GnmSpanCalcFlags flags = sheet_style_set_list (me->cmd.sheet,
-					    &os->pos, FALSE, os->styles);
+					    &os->pos, os->styles, NULL, NULL);
 
 			g_return_val_if_fail (l2 && l2->data, TRUE);
 
@@ -6816,7 +6816,7 @@ cmd_hyperlink_undo (GnmCommand *cmd,
 			GnmRange const *r = l2->data;
 			GnmSpanCalcFlags flags = sheet_style_set_list
 				(me->cmd.sheet,
-				 &os->pos, FALSE, os->styles);
+				 &os->pos, os->styles, NULL, NULL);
 
 			sheet_range_calc_spans (me->cmd.sheet, r, flags);
 			sheet_flag_style_update_range (me->cmd.sheet, r);
diff --git a/src/sheet-style.c b/src/sheet-style.c
index 56ee707..d617c06 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -1885,7 +1885,7 @@ sheet_style_relocate (GnmExprRelocateInfo const *rinfo)
 			       sheet_style_default (rinfo->origin_sheet));
 	corner.col = rinfo->origin.start.col + rinfo->col_offset;
 	corner.row = rinfo->origin.start.row + rinfo->row_offset;
-	sheet_style_set_list (rinfo->target_sheet, &corner, FALSE, styles);
+	sheet_style_set_list (rinfo->target_sheet, &corner, styles, NULL, NULL);
 	style_list_free	(styles);
 }
 
@@ -1939,7 +1939,8 @@ sheet_style_insert_colrow (GnmExprRelocateInfo const *rinfo)
 	sheet_style_relocate (rinfo);
 
 	if (styles != NULL) {
-		sheet_style_set_list (rinfo->target_sheet, &corner, FALSE, styles);
+		sheet_style_set_list (rinfo->target_sheet, &corner, styles, 
+				      NULL, NULL);
 		style_list_free	(styles);
 	}
 }
@@ -2390,7 +2391,9 @@ sheet_style_collect_validations (Sheet const *sheet, GnmRange const *r)
  **/
 GnmSpanCalcFlags
 sheet_style_set_list (Sheet *sheet, GnmCellPos const *corner,
-		      gboolean transpose, GnmStyleList const *list)
+		      GnmStyleList const *list,
+		      sheet_style_set_list_cb_t range_modify, 
+		      gpointer data)
 {
 	GnmSpanCalcFlags spanflags = GNM_SPANCALC_SIMPLE;
 	GnmStyleList const *l;
@@ -2403,8 +2406,8 @@ sheet_style_set_list (Sheet *sheet, GnmCellPos const *corner,
 		GnmRange              r  = sr->range;
 
 		range_translate (&r, sheet, +corner->col, +corner->row);
-		if (transpose)
-			range_transpose (&r, sheet, corner);
+		if (range_modify)
+			range_modify (&r, sheet, data);
 
 		gnm_style_ref (sr->style);
 		sheet_style_set_range (sheet, &r, sr->style);
diff --git a/src/sheet-style.h b/src/sheet-style.h
index e340d36..53b6524 100644
--- a/src/sheet-style.h
+++ b/src/sheet-style.h
@@ -73,8 +73,15 @@ void      sheet_style_update_grid_color      (Sheet const *sheet);
 GnmStyle const    *style_list_get_style	 (GnmStyleList const *l, int col, int row);
 void		   style_list_free	 (GnmStyleList *l);
 GnmStyleList	  *sheet_style_get_range (Sheet const *sheet, GnmRange const *r);
-GnmSpanCalcFlags   sheet_style_set_list  (Sheet *sheet, GnmCellPos const *corner,
-					  gboolean transpose, GnmStyleList const *l);
+
+typedef  gboolean (*sheet_style_set_list_cb_t) (GnmRange *range, 
+						Sheet const *sheet, 
+						gpointer data);
+GnmSpanCalcFlags   sheet_style_set_list  (Sheet *sheet, 
+					  GnmCellPos const *corner,
+					  GnmStyleList const *l,
+					  sheet_style_set_list_cb_t range_modify, 
+					  gpointer data);
 
 GnmStyleList *sheet_style_collect_conditions	(Sheet const *s, GnmRange const *r);
 GnmStyleList *sheet_style_collect_hlinks	(Sheet const *s, GnmRange const *r);
diff --git a/src/sheet.c b/src/sheet.c
index b8f8bcf..45eac1e 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -5322,7 +5322,7 @@ sheet_dup_styles (Sheet const *src, Sheet *dst)
 		dst, sheet_style_get_auto_pattern_color (src));
 
 	styles = sheet_style_get_range (src, range_init_full_sheet (&r, src));
-	sheet_style_set_list (dst, &corner, FALSE, styles);
+	sheet_style_set_list (dst, &corner, styles, NULL, NULL);
 	style_list_free	(styles);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]