[gnumeric] Fix handling of repeating top/left cells.



commit 2dfcccce27d3039f9009e0611315d844b3f19ccd
Author: Morten Welinder <terra gnome org>
Date:   Tue Apr 21 09:20:14 2009 -0400

    Fix handling of repeating top/left cells.
    
    * src/print-info.c (print_info_free): Free here.
    (print_info_load_defaults): Simply copy as text here.
    (print_info_dup): Copy here.
    (print_info_new, print_info_dup): Don't take sheet argument
    anymore.  All callers changed.
    
    * src/print-info.h (struct _PrintInformation): Keep repeat_top and
    repeat_left as strings so they become sheet independent.
    
    * src/print.c (compute_sheet_pages): Parse repeat_top and
    repeat_left here.
---
 ChangeLog                          |   14 ++++++++++++
 src/commands.c                     |   11 ++++-----
 src/dialogs/dialog-printer-setup.c |   28 ++++++++++--------------
 src/print-info.c                   |   40 ++++++++++++++---------------------
 src/print-info.h                   |    7 ++---
 src/print.c                        |   31 +++++++++++++++++++--------
 src/sheet.c                        |    4 +-
 src/xml-sax-read.c                 |   20 +++++++++---------
 8 files changed, 84 insertions(+), 71 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ae748c3..d6ef4a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-04-21  Morten Welinder  <terra gnome org>
+
+	* src/print-info.c (print_info_free): Free here.
+	(print_info_load_defaults): Simply copy as text here.
+	(print_info_dup): Copy here.
+	(print_info_new, print_info_dup): Don't take sheet argument
+	anymore.  All callers changed.
+
+	* src/print-info.h (struct _PrintInformation): Keep repeat_top and
+	repeat_left as strings so they become sheet independent.
+
+	* src/print.c (compute_sheet_pages): Parse repeat_top and
+	repeat_left here.
+
 2009-04-20  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/commands.h (cmd_object_format): add argument
diff --git a/src/commands.c b/src/commands.c
index 8c14317..3822bb5 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -5536,8 +5536,7 @@ cmd_print_setup_undo (GnmCommand *cmd, WorkbookControl *wbc)
 	if (me->cmd.sheet) {
 		PrintInformation *pi = me->old_pi->data;
 		print_info_free (me->cmd.sheet->print_info);
-		me->cmd.sheet->print_info =
-			print_info_dup (pi, me->cmd.sheet);
+		me->cmd.sheet->print_info = print_info_dup (pi);
 	} else {
 		book = wb_control_get_workbook(wbc);
 		n = workbook_sheet_count (book);
@@ -5551,7 +5550,7 @@ cmd_print_setup_undo (GnmCommand *cmd, WorkbookControl *wbc)
 			g_return_val_if_fail (infos != NULL, TRUE);
 
 			print_info_free (sheet->print_info);
-			sheet->print_info = print_info_dup (pi, sheet);
+			sheet->print_info = print_info_dup (pi);
 			infos = infos->next;
 		}
 	}
@@ -5571,7 +5570,7 @@ cmd_print_setup_redo (GnmCommand *cmd, WorkbookControl *wbc)
 			me->old_pi = g_slist_append (me->old_pi, me->cmd.sheet->print_info);
 		else
 			print_info_free (me->cmd.sheet->print_info);
-		me->cmd.sheet->print_info = print_info_dup (me->new_pi, me->cmd.sheet);
+		me->cmd.sheet->print_info = print_info_dup (me->new_pi);
 	} else {
 		book = wb_control_get_workbook(wbc);
 		n = workbook_sheet_count (book);
@@ -5582,7 +5581,7 @@ cmd_print_setup_redo (GnmCommand *cmd, WorkbookControl *wbc)
 				me->old_pi = g_slist_prepend (me->old_pi, sheet->print_info);
 			else
 				print_info_free (sheet->print_info);
-			sheet->print_info = print_info_dup (me->new_pi, sheet);
+			sheet->print_info = print_info_dup (me->new_pi);
 		}
 		me->old_pi = g_slist_reverse (me->old_pi);
 	}
@@ -5618,7 +5617,7 @@ cmd_print_setup (WorkbookControl *wbc, Sheet *sheet, PrintInformation const *pi)
 	else
 		me->cmd.cmd_descriptor = g_strdup (_("Page Setup For All Sheets"));
 	me->old_pi = NULL;
-	me->new_pi = print_info_dup (pi, sheet);
+	me->new_pi = print_info_dup (pi);
 
 	return command_push_undo (wbc, G_OBJECT (me));
 }
diff --git a/src/dialogs/dialog-printer-setup.c b/src/dialogs/dialog-printer-setup.c
index 902ad66..5895983 100644
--- a/src/dialogs/dialog-printer-setup.c
+++ b/src/dialogs/dialog-printer-setup.c
@@ -2135,17 +2135,11 @@ do_setup_page_info (PrinterSetupState *state)
 /*	gnumeric_editable_enters (GTK_WINDOW (state->dialog), */
 /*		gtk_bin_get_child (GTK_BIN (glade_xml_get_widget (state->gui, "comments-combo")))); */
 
-	if (state->pi->repeat_top.use)
-		gnm_expr_entry_load_from_range (
-			state->top_entry,
-			wb_control_cur_sheet (WORKBOOK_CONTROL (state->wbcg)),
-			&state->pi->repeat_top.range);
-
-	if (state->pi->repeat_left.use)
-		gnm_expr_entry_load_from_range (
-			state->left_entry,
-			wb_control_cur_sheet (WORKBOOK_CONTROL (state->wbcg)),
-			&state->pi->repeat_left.range);
+	gnm_expr_entry_load_from_text (state->top_entry,
+				       state->pi->repeat_top);
+	gnm_expr_entry_load_from_text (state->left_entry,
+				       state->pi->repeat_left);
+
 	load_print_area (state);
 }
 
@@ -2609,7 +2603,7 @@ printer_setup_state_new (WBCGtk *wbcg, Sheet *sheet)
 	state->wbcg  = wbcg;
 	state->sheet = sheet;
 	state->gui   = gui;
-	state->pi    = print_info_dup (sheet->print_info, sheet);
+	state->pi    = print_info_dup (sheet->print_info);
 	state->display_unit = state->pi->desired_display.top;
 	state->customize_header = NULL; 
 	state->customize_footer = NULL; 
@@ -2743,10 +2737,12 @@ do_fetch_page_info (PrinterSetupState *state)
 		(GTK_TOGGLE_BUTTON (glade_xml_get_widget (state->gui, "radio-order-right")));
 	pi->do_not_print = gtk_toggle_button_get_active
 		(GTK_TOGGLE_BUTTON (glade_xml_get_widget (state->gui, "check-do-not-print")));
-	pi->repeat_top.use = gnm_expr_entry_get_rangesel (state->top_entry,
-		&pi->repeat_top.range, NULL);
-	pi->repeat_left.use = gnm_expr_entry_get_rangesel (state->left_entry,
-		&pi->repeat_left.range, NULL);
+
+	g_free (pi->repeat_top);
+	pi->repeat_top = g_strdup (gnm_expr_entry_get_text (state->top_entry));
+
+	g_free (pi->repeat_left);
+	pi->repeat_left = g_strdup (gnm_expr_entry_get_text (state->left_entry));
 }
 
 static void
diff --git a/src/print-info.c b/src/print-info.c
index 940b0ab..d6a7e88 100644
--- a/src/print-info.c
+++ b/src/print-info.c
@@ -138,6 +138,8 @@ print_info_free (PrintInformation *pi)
 	if (NULL != pi->page_breaks.h)
 		gnm_page_breaks_free (pi->page_breaks.h);
 
+	g_free (pi->repeat_top);
+	g_free (pi->repeat_left);
 	print_hf_free (pi->header);
 	print_hf_free (pi->footer);
 
@@ -147,12 +149,6 @@ print_info_free (PrintInformation *pi)
 	g_free (pi);
 }
 
-static gboolean
-load_range (char const *str, GnmRange *r, Sheet *sheet)
-{
-	return str && range_parse (r, str, sheet);
-}
-
 static void
 load_formats (void)
 {
@@ -255,14 +251,8 @@ print_info_load_defaults (PrintInformation *res)
 	res->desired_display.right = gnm_app_prefs->desired_display;
 	res->desired_display.footer = gnm_app_prefs->desired_display;
 	res->desired_display.header = gnm_app_prefs->desired_display;
-
-	res->repeat_top.use   = load_range (gnm_app_prefs->print_repeat_top,
-					    &res->repeat_top.range,
-					    res->sheet);
-	res->repeat_left.use  = load_range (gnm_app_prefs->print_repeat_left,
-					    &res->repeat_left.range,
-					    res->sheet);
-
+	res->repeat_top            = g_strdup (gnm_app_prefs->print_repeat_top);
+	res->repeat_left           = g_strdup (gnm_app_prefs->print_repeat_left);
 	res->center_vertically     = gnm_app_prefs->print_center_vertically;
 	res->center_horizontally   = gnm_app_prefs->print_center_horizontally;
 	res->print_grid_lines      = gnm_app_prefs->print_grid_lines;
@@ -296,11 +286,10 @@ print_info_load_defaults (PrintInformation *res)
  *
  */
 PrintInformation *
-print_info_new (Sheet *sheet, gboolean load_defaults)
+print_info_new (gboolean load_defaults)
 {
 	PrintInformation *res = g_new0 (PrintInformation, 1);
 
-	res->sheet = sheet;
 	res->print_as_draft	   = FALSE;
 	res->comment_placement = PRINT_COMMENTS_IN_PLACE;
 	res->error_display     = PRINT_ERRORS_AS_DISPLAYED;
@@ -387,10 +376,8 @@ print_info_save (PrintInformation *pi)
 	gnm_gconf_set_print_black_and_white (pi->print_black_and_white);
 	gnm_gconf_set_print_order_across_then_down (pi->print_across_then_down);
 
-	go_conf_set_string (node, PRINTSETUP_GCONF_REPEAT_TOP,
-		pi->repeat_top.use ? range_as_string (&pi->repeat_top.range) : "");
-	go_conf_set_string (node, PRINTSETUP_GCONF_REPEAT_LEFT,
-		pi->repeat_left.use ? range_as_string (&pi->repeat_left.range) : "");
+	go_conf_set_string (node, PRINTSETUP_GCONF_REPEAT_TOP, pi->repeat_top);
+	go_conf_set_string (node, PRINTSETUP_GCONF_REPEAT_LEFT, pi->repeat_left);
 
 	save_formats ();
 
@@ -822,18 +809,23 @@ print_shutdown (void)
 #define COPY(field) dst->field = src->field
 
 PrintInformation *
-print_info_dup (PrintInformation const *src, Sheet *new_sheet)
+print_info_dup (PrintInformation const *src)
 {
-	PrintInformation *dst = print_info_new (new_sheet, TRUE);
+	PrintInformation *dst = print_info_new (TRUE);
 
 	print_info_load_defaults ((PrintInformation *)src);
 
-	/* Don't copy sheet */
 	COPY(scaling);
 	COPY(edge_to_below_header);
 	COPY(edge_to_above_footer);
         COPY(desired_display);
-	COPY(repeat_left);
+
+	g_free (dst->repeat_top);
+	dst->repeat_top = g_strdup (src->repeat_top);
+
+	g_free (dst->repeat_left);
+	dst->repeat_left = g_strdup (src->repeat_left);
+
 	COPY(print_across_then_down);
 	COPY(center_vertically);
 	COPY(center_horizontally);
diff --git a/src/print-info.h b/src/print-info.h
index a72ba16..3feea15 100644
--- a/src/print-info.h
+++ b/src/print-info.h
@@ -41,7 +41,6 @@ typedef struct {
 } GnmPageBreaks;
 
 struct _PrintInformation {
-	Sheet *sheet;
 	struct {
 		enum {
 			PRINT_SCALE_PERCENTAGE,
@@ -66,7 +65,7 @@ struct _PrintInformation {
 	double           edge_to_below_header;
 	double           edge_to_above_footer;
         DesiredDisplay   desired_display;
-	PrintRepeatRange repeat_top, repeat_left;
+	char            *repeat_top, *repeat_left;
 	unsigned int	 print_across_then_down;
 	unsigned int     center_vertically:1;
 	unsigned int     center_horizontally:1;
@@ -117,9 +116,9 @@ typedef struct {
 	GnmCellPos top_repeating;
 } HFRenderInfo;
 
-PrintInformation *print_info_new         (Sheet *sheet, gboolean load_defaults);
+PrintInformation *print_info_new         (gboolean load_defaults);
 PrintInformation *print_info_load_defaults (PrintInformation *pi);
-PrintInformation *print_info_dup	 (PrintInformation const *pi, Sheet *new_sheet);
+PrintInformation *print_info_dup	 (PrintInformation const *pi);
 void              print_info_free        (PrintInformation *pi);
 void              print_info_save        (PrintInformation *pi);
 
diff --git a/src/print.c b/src/print.c
index 7bf8557..5eb55e2 100644
--- a/src/print.c
+++ b/src/print.c
@@ -871,6 +871,12 @@ compute_sheet_pages_across_then_down (PrintingInstance * pi,
 }
 
 
+static gboolean
+load_repeat_range (char const *str, GnmRange *r, Sheet *sheet)
+{
+       return str && range_parse (r, str, sheet);
+}
+
 /*
   return TRUE in case of trouble
 */
@@ -891,9 +897,10 @@ compute_sheet_pages (GtkPrintContext   *context,
 	gdouble top_margin, bottom_margin, edge_to_below_header, edge_to_above_footer;
 	gdouble px, py;
 	gdouble usable_x, usable_y;
-
 	GSList *column_pagination = NULL;
 	GSList *row_pagination = NULL;
+	gboolean repeat_top_use, repeat_left_use;
+	int repeat_top_start, repeat_top_end, repeat_left_start, repeat_left_end;
 
 	if (pinfo->print_titles) {
 		col_header_height = sheet->rows.default_style.size_pts;
@@ -925,6 +932,14 @@ compute_sheet_pages (GtkPrintContext   *context,
 	page_height -= ((edge_to_below_header - top_margin)
 			+ (edge_to_above_footer - bottom_margin));
 
+	repeat_top_use = load_repeat_range (pinfo->repeat_top, &r, sheet);
+	repeat_top_start = repeat_top_use ? r.start.row : 0;
+	repeat_top_end = repeat_top_use ? r.end.row : 0;
+
+	repeat_left_use = load_repeat_range (pinfo->repeat_left, &r, sheet);
+	repeat_left_start = repeat_left_use ? r.start.col : 0;
+	repeat_left_end = repeat_left_use ? r.end.col : 0;
+
 	if (pinfo->scaling.type == PRINT_SCALE_FIT_PAGES) {
 		/* Note that the resulting scale is independent from */
 		/* whether we print first down or across!            */
@@ -935,15 +950,15 @@ compute_sheet_pages (GtkPrintContext   *context,
 					    sheet_row_get_distance_pts,
 					    pinfo->scaling.dim.rows, 1.,
 					    col_header_height,
-					    pinfo->repeat_top.use, pinfo->repeat_top.range.start.row, 
-					    pinfo->repeat_top.range.end.row);
+					    repeat_top_use,
+					    repeat_top_start, repeat_top_end);
 		pxy = compute_scale_fit_to (sheet, r.start.col, r.end.col,
 					    page_width, sheet_col_get_info,
 					    sheet_col_get_distance_pts,
 					    pinfo->scaling.dim.cols, pxy,
 					    row_header_width,
-					    pinfo->repeat_left.use, pinfo->repeat_left.range.start.col, 
-					    pinfo->repeat_left.range.end.col);
+					    repeat_left_use,
+					    repeat_left_start, repeat_left_end);
 
 		pinfo->scaling.percentage.x = pxy * 100.;
 		pinfo->scaling.percentage.y = pxy * 100.;
@@ -962,13 +977,11 @@ compute_sheet_pages (GtkPrintContext   *context,
 
 	paginate (&column_pagination, sheet, r.start.col, r.end.col, 
 		  usable_x - row_header_width,
-		  pinfo->repeat_left.use, pinfo->repeat_left.range.start.col, 
-		  pinfo->repeat_left.range.end.col, 
+		  repeat_left_use, repeat_left_start, repeat_left_end,
 		  sheet_col_get_distance_pts, sheet_col_get_info);
 	paginate (&row_pagination, sheet, r.start.row, r.end.row, 
 		  usable_y - col_header_height,
-		  pinfo->repeat_top.use, pinfo->repeat_top.range.start.row, 
-		  pinfo->repeat_top.range.end.row,
+		  repeat_top_use, repeat_top_start, repeat_top_end,
 		  sheet_row_get_distance_pts, sheet_row_get_info);
 
 	if (sheet->print_info->print_across_then_down)
diff --git a/src/sheet.c b/src/sheet.c
index cfd73dd..b11c94c 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -748,7 +748,7 @@ gnm_sheet_init (Sheet *sheet)
 	sheet->rows.info = g_ptr_array_new ();
 	sheet_row_set_default_size_pts (sheet, 12.75);
 
-	sheet->print_info = print_info_new (sheet, FALSE);
+	sheet->print_info = print_info_new (FALSE);
 
 	sheet->filters = NULL;
 	sheet->scenarios = NULL;
@@ -5248,7 +5248,7 @@ sheet_dup (Sheet const *src)
 		NULL);
 
 	print_info_free (dst->print_info);
-	dst->print_info = print_info_dup (src->print_info, dst);
+	dst->print_info = print_info_dup (src->print_info);
 
 	sheet_dup_styles         (src, dst);
 	sheet_dup_merged_regions (src, dst);
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index 76ee36e..a768c05 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -1009,11 +1009,11 @@ xml_sax_repeat_top (GsfXMLIn *xin, xmlChar const **attrs)
 	pi = state->sheet->print_info;
 
 	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
-		if (!strcmp (CXML2C (attrs[0]), "value"))
-			pi->repeat_top.use =
-				range_parse (&pi->repeat_top.range,
-					     CXML2C (attrs[1]),
-					     state->sheet);
+		if (!strcmp (CXML2C (attrs[0]), "value")) {
+			g_free (pi->repeat_top);
+			pi->repeat_top = g_strdup (CXML2C (attrs[1]));
+			break;
+		}
 }
 
 static void
@@ -1028,11 +1028,11 @@ xml_sax_repeat_left (GsfXMLIn *xin, xmlChar const **attrs)
 	pi = state->sheet->print_info;
 
 	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
-		if (!strcmp (CXML2C (attrs[0]), "value"))
-			pi->repeat_left.use =
-				range_parse (&pi->repeat_left.range,
-					     CXML2C (attrs[1]),
-					     state->sheet);
+		if (!strcmp (CXML2C (attrs[0]), "value")) {
+			g_free (pi->repeat_left);
+			pi->repeat_left = g_strdup (CXML2C (attrs[1]));
+			break;
+		}
 }
 
 static void



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