[gnumeric] Store some print range information in gnumeric files. [#649714]



commit 88a585b47433c9bc0a632eba655f6d0db79fae5f
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Mon May 23 01:57:30 2011 -0600

    Store some print range information in gnumeric files. [#649714]
    
    2011-05-23  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/print-info.h (_PrintInformation): new field
    	(print_info_set_from_settings): new
    	(print_info_get_printrange): new
    	(print_info_set_printrange): new
    	* src/print-info.c (print_info_set_from_settings): new
    	(print_info_get_printrange): new
    	(print_info_set_printrange): new
    	(print_info_load_defaults): use settings
    	(print_info_get_printtofile_uri): load defaults
    	* src/print.c (gnm_print_sheet): use printrange from printinfo
    	* src/xml-sax-read.c (xml_sax_print_print_range): new
    	* src/xml-sax-write.c (xml_write_print_info): write printrange

 ChangeLog           |   15 +++++++++++++++
 NEWS                |    3 +++
 src/print-info.c    |   35 +++++++++++++++++++++++++++++++++++
 src/print-info.h    |    7 +++++++
 src/print.c         |    8 +++-----
 src/print.h         |    2 +-
 src/xml-sax-read.c  |   17 +++++++++++++++++
 src/xml-sax-write.c |    3 +++
 8 files changed, 84 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 74f1755..bcb87e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2011-05-23  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/print-info.h (_PrintInformation): new field
+	(print_info_set_from_settings): new
+	(print_info_get_printrange): new
+	(print_info_set_printrange): new
+	* src/print-info.c (print_info_set_from_settings): new
+	(print_info_get_printrange): new
+	(print_info_set_printrange): new
+	(print_info_load_defaults): use settings
+	(print_info_get_printtofile_uri): load defaults
+	* src/print.c (gnm_print_sheet): use printrange from printinfo
+	* src/xml-sax-read.c (xml_sax_print_print_range): new
+	* src/xml-sax-write.c (xml_write_print_info): write printrange
+
+2011-05-23  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* src/print.c (gnm_print_uri_change_extension): if the setting has no
 	extension, specify one
 
diff --git a/NEWS b/NEWS
index 3a2423d..5d82341 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 Gnumeric 1.10.16
 
+Andreas
+	* Store some print range information in gnumeric files. [#649714]
+
 Morten:
 	* Fix leaks in SHEET.  [#650761]
 	* Fix leaks in SHEETS.  [#650764]
diff --git a/src/print-info.c b/src/print-info.c
index 7ebcbdc..04a7185 100644
--- a/src/print-info.c
+++ b/src/print-info.c
@@ -228,6 +228,7 @@ PrintInformation *
 print_info_load_defaults (PrintInformation *res)
 {
 	GSList *list;
+	GtkPrintSettings* settings = gnm_conf_get_print_settings ();
 
 	if (res->page_setup != NULL)
 		return res;
@@ -273,6 +274,10 @@ print_info_load_defaults (PrintInformation *res)
 			      g_slist_nth_data (list, 2)) :
 		print_hf_new ("", _("Page &[PAGE]"), "");
 
+	print_info_set_from_settings (res, settings);
+
+	g_object_unref (settings);
+
 	return res;
 }
 
@@ -300,6 +305,7 @@ print_info_new (gboolean load_defaults)
 	res->page_breaks.h = NULL;
 
 	res->printtofile_uri = NULL;
+	res->print_range = PRINT_ACTIVE_SHEET;
 
 	if (load_defaults)
 		return print_info_load_defaults (res);
@@ -1528,8 +1534,37 @@ print_info_set_printtofile_from_settings (PrintInformation *pi,
 		print_info_set_printtofile_uri (pi, uri);
 }
 
+void
+print_info_set_from_settings (PrintInformation *pi, 
+					  GtkPrintSettings* settings)
+{
+	pi->print_range = gtk_print_settings_get_int_with_default
+		(settings,
+		 GNUMERIC_PRINT_SETTING_PRINTRANGE_KEY,
+		 PRINT_ACTIVE_SHEET);
+}
+
+PrintRange  
+print_info_get_printrange (PrintInformation *pi)
+{
+	print_info_load_defaults (pi);
+	return pi->print_range;
+}
+
+void        
+print_info_set_printrange (PrintInformation *pi, PrintRange pr)
+{
+	if (pr >= PRINT_ACTIVE_SHEET 
+	    && pr <= PRINT_SHEET_SELECTION_IGNORE_PRINTAREA)
+		pi->print_range = pr;
+	else
+		pi->print_range = PRINT_ACTIVE_SHEET;
+}
+
+
 char const *
 print_info_get_printtofile_uri (PrintInformation *pi)
 {
+	print_info_load_defaults (pi);
 	return pi->printtofile_uri;
 }
diff --git a/src/print-info.h b/src/print-info.h
index c4c6c56..f51fa59 100644
--- a/src/print-info.h
+++ b/src/print-info.h
@@ -4,6 +4,7 @@
 
 #include "gnumeric.h"
 #include <gtk/gtk.h>
+#include "print.h"
 
 G_BEGIN_DECLS
 
@@ -96,6 +97,7 @@ struct _PrintInformation {
         int              n_copies;
 
 	gchar           *printtofile_uri;
+	PrintRange       print_range;
 
   /* page_setup doubles as a flag whether the defaults are loaded */
         GtkPageSetup     *page_setup;
@@ -178,7 +180,12 @@ void        print_info_set_printtofile_from_settings
                                (PrintInformation *pi, 
 				GtkPrintSettings *settings,
 				gchar const *default_uri);
+void        print_info_set_from_settings 
+                               (PrintInformation *pi, 
+				GtkPrintSettings *settings);
 char const *print_info_get_printtofile_uri (PrintInformation *pi);
+PrintRange  print_info_get_printrange (PrintInformation *pi);
+void        print_info_set_printrange (PrintInformation *pi, PrintRange pr);
 
 void        print_info_set_breaks (PrintInformation *pi, GnmPageBreaks *breaks);
 
diff --git a/src/print.c b/src/print.c
index e6fe66c..19e5cab 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1648,10 +1648,7 @@ gnm_print_sheet (WorkbookControl *wbc, Sheet *sheet,
 
 	settings = gnm_conf_get_print_settings ();
 	if (default_range == PRINT_SAVED_INFO) {
-		gint dr = gtk_print_settings_get_int_with_default
-			(settings,
-			 GNUMERIC_PRINT_SETTING_PRINTRANGE_KEY,
-			 PRINT_ACTIVE_SHEET);
+		gint dr = print_info_get_printrange (sheet->print_info);
 		if (dr < 0 || dr >= (gint)G_N_ELEMENTS (pr_translator))
 			default_range = PRINT_ACTIVE_SHEET;
 		else 
@@ -1663,7 +1660,6 @@ gnm_print_sheet (WorkbookControl *wbc, Sheet *sheet,
 	pi->pr = default_range;
 	gtk_print_settings_set_use_color (settings,
 					  !sheet->print_info->print_black_and_white);
-
 	if (!export_dst && !preview_via_pdf && !preview) {
 		/* We should be setting the output file name to somethig */
 		/* reasonable */
@@ -1761,6 +1757,8 @@ gnm_print_sheet (WorkbookControl *wbc, Sheet *sheet,
 				g_free (wb_output_uri);
 			}
 		}
+		print_info_set_from_settings 
+			(sheet->print_info, settings);
 		break;
 	case GTK_PRINT_OPERATION_RESULT_CANCEL:
 		printing_instance_delete (pi);
diff --git a/src/print.h b/src/print.h
index 87b06ae..a3ba61e 100644
--- a/src/print.h
+++ b/src/print.h
@@ -13,7 +13,7 @@ G_BEGIN_DECLS
 #define GNUMERIC_PRINT_SETTING_PRINT_TO_SHEET_KEY	"GnumericPrintToSheet"
 #define GNUMERIC_PRINT_SETTING_IGNORE_PAGE_BREAKS_KEY   "GnumericPrintIgnorePageBreaks"
 
-typedef enum {
+typedef enum { /* These numbers are saved in .gnuemric files */
 	PRINT_SAVED_INFO = -1,
 	PRINT_ACTIVE_SHEET = 0,
 	PRINT_ALL_SHEETS = 1,
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index 765fcea..c1668eb 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -1042,6 +1042,22 @@ xml_sax_print_do_not_print (GsfXMLIn *xin, xmlChar const **attrs)
                         pi->do_not_print = val;
 }
 
+static void
+xml_sax_print_print_range (GsfXMLIn *xin, xmlChar const **attrs)
+{
+        XMLSaxParseState *state = (XMLSaxParseState *)xin->user_state;
+        PrintInformation *pi;
+        int val;
+
+	xml_sax_must_have_sheet (state);
+
+	pi = state->sheet->print_info;
+
+        for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
+                if (gnm_xml_attr_int (attrs, "value", &val))
+                        print_info_set_printrange (pi, val);
+}
+
 
 
 static void
@@ -2876,6 +2892,7 @@ GSF_XML_IN_NODE_FULL (START, WB, GNM, "Workbook", GSF_XML_NO_CONTENT, TRUE, TRUE
 	GSF_XML_IN_NODE (SHEET_PRINTINFO, PRINT_HCENTER,    GNM, "hcenter",	GSF_XML_CONTENT, &xml_sax_print_hcenter, NULL),
 	GSF_XML_IN_NODE (SHEET_PRINTINFO, PRINT_GRID,	    GNM, "grid",	GSF_XML_NO_CONTENT, &xml_sax_print_grid, NULL),
 	GSF_XML_IN_NODE (SHEET_PRINTINFO, PRINT_DO_NOT_PRINT, GNM, "do_not_print",GSF_XML_NO_CONTENT, &xml_sax_print_do_not_print, NULL),
+	GSF_XML_IN_NODE (SHEET_PRINTINFO, PRINT_PRINT_RANGE, GNM, "print_range",GSF_XML_NO_CONTENT, &xml_sax_print_print_range, NULL),
 	GSF_XML_IN_NODE (SHEET_PRINTINFO, PRINT_MONO,	    GNM, "monochrome",	GSF_XML_NO_CONTENT, &xml_sax_monochrome, NULL),
 	GSF_XML_IN_NODE (SHEET_PRINTINFO, PRINT_AS_DRAFT,   GNM, "draft",	GSF_XML_NO_CONTENT, NULL, NULL),
 	GSF_XML_IN_NODE (SHEET_PRINTINFO, PRINT_COMMENTS,   GNM, "comments",	GSF_XML_NO_CONTENT, NULL, NULL),
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index 7a336a5..b16a9fb 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -380,6 +380,9 @@ xml_write_print_info (GnmOutputXML *state, PrintInformation *pi)
 	gsf_xml_out_add_int  (state->output, "value",    pi->do_not_print);
 	gsf_xml_out_end_element (state->output);
 
+	gsf_xml_out_start_element (state->output, GNM "print_range");
+	gsf_xml_out_add_int  (state->output, "value", print_info_get_printrange (pi));
+	gsf_xml_out_end_element (state->output);
 
 	xml_write_print_repeat_range (state, GNM "repeat_top", pi->repeat_top);
 	xml_write_print_repeat_range (state, GNM "repeat_left", pi->repeat_left);



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