[goffice] Add "as multiple of pi" to fraction format selector



commit 7d80f0ef54388b7b3b4fe7ef85853e23f6deb407
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Fri Aug 26 11:54:27 2011 -0600

    Add "as multiple of pi" to fraction format selector
    
    2011-08-26  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* goffice/gtk/go-format-sel.ui: add as-multiple-of-pi checkbox and sep.
    	* goffice/gtk/go-format-sel.c (FormatWidget): add new widgets
    	(cb_pi_scale_toggle): new
    	(fmt_dialog_enable_widgets): handle new widgets
    	(nfs_init): handle new widgets
    	* goffice/utils/go-format.h (GOFormatDetails): add new field
    	* goffice/utils/go-format.c (go_format_generate_fraction_str):
    	handle pi-slash
    	(go_format_details_init): adjust initialisation
    	(go_format_get_details): handle pi-slash

 ChangeLog                    |   13 +++++++++++++
 goffice/gtk/go-format-sel.c  |   27 ++++++++++++++++++++++++++-
 goffice/gtk/go-format-sel.ui |   28 ++++++++++++++++++++++++++++
 goffice/utils/go-format.c    |   27 +++++++++++++++++++--------
 goffice/utils/go-format.h    |    1 +
 5 files changed, 87 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4fa567b..60ab729 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2011-08-26  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* goffice/gtk/go-format-sel.ui: add as-multiple-of-pi checkbox and sep.
+	* goffice/gtk/go-format-sel.c (FormatWidget): add new widgets
+	(cb_pi_scale_toggle): new
+	(fmt_dialog_enable_widgets): handle new widgets
+	(nfs_init): handle new widgets
+	* goffice/utils/go-format.h (GOFormatDetails): add new field
+	* goffice/utils/go-format.c (go_format_generate_fraction_str):
+	handle pi-slash
+	(go_format_details_init): adjust initialisation
+	(go_format_get_details): handle pi-slash
+
+2011-08-26  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* goffice/utils/go-format.c (go_format_parse_number_fraction): write
 	OP_NUM_VAL_SIGN
 	(go_format_execute): keep the sign attached to val
diff --git a/goffice/gtk/go-format-sel.c b/goffice/gtk/go-format-sel.c
index 1d9ca19..40503da 100644
--- a/goffice/gtk/go-format-sel.c
+++ b/goffice/gtk/go-format-sel.c
@@ -108,6 +108,8 @@ typedef enum {
 	F_FRACTION_MIN_DENOM_DIGITS_LABEL,
 	F_FRACTION_MAX_DENOM_DIGITS,
 	F_FRACTION_MIN_DENOM_DIGITS,
+	F_FRACTION_PI_SCALE,
+	F_BASE_SEPARATOR,
 	F_MAX_WIDGET
 } FormatWidget;
 
@@ -415,6 +417,15 @@ cb_split_fraction_toggle (GtkWidget *w, GOFormatSel *gfs)
 }
 
 static void
+cb_pi_scale_toggle (GtkWidget *w, GOFormatSel *gfs)
+{
+	gboolean act = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
+	gfs->format.details.pi_scale = act;
+
+	draw_format_preview (gfs, TRUE);
+}
+
+static void
 cb_fraction_automatic_toggle (GtkWidget *w, GOFormatSel *gfs)
 {
 	gboolean act =gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
@@ -496,7 +507,7 @@ static void
 fmt_dialog_enable_widgets (GOFormatSel *gfs, int page)
 {
 	SETUP_LOCALE_SWITCH;
-	static FormatWidget const contents[][15] = {
+	static FormatWidget const contents[][17] = {
 		/* General */
 		{
 			F_GENERAL_EXPLANATION,
@@ -578,6 +589,8 @@ fmt_dialog_enable_widgets (GOFormatSel *gfs, int page)
 			F_FRACTION_MIN_DENOM_DIGITS_LABEL,
 			F_FRACTION_MAX_DENOM_DIGITS,
 			F_FRACTION_MIN_DENOM_DIGITS,
+			F_FRACTION_PI_SCALE,
+			F_BASE_SEPARATOR,
 			F_MAX_WIDGET
 		},
 		/* Scientific */
@@ -822,6 +835,12 @@ stays:
 				 gfs->format.details.automatic_denominator);
 			break;
 
+		case F_FRACTION_PI_SCALE:
+			gtk_toggle_button_set_active 
+				(GTK_TOGGLE_BUTTON (w),
+				 gfs->format.details.pi_scale);
+			break;
+
 		default:
 			; /* Nothing */
 		}
@@ -1142,6 +1161,9 @@ nfs_init (GOFormatSel *gfs)
 		"format_min_denominator_digits_label",
 		"format_maximum_denominator_digits",
 		"format_minimum_denominator_digits",
+		"format_pi_scale_check",
+
+		"format_base_separator",
 		NULL
 	};
 
@@ -1273,6 +1295,9 @@ nfs_init (GOFormatSel *gfs)
 			  "toggled", G_CALLBACK (cb_fraction_automatic_toggle), gfs);
 	g_signal_connect (G_OBJECT (gfs->format.widget[F_FRACTION_SEPARATE_INTEGER]), 
 			  "toggled", G_CALLBACK (cb_split_fraction_toggle), gfs);
+	g_signal_connect (G_OBJECT (gfs->format.widget[F_FRACTION_PI_SCALE]), 
+			  "toggled",
+			  G_CALLBACK (cb_pi_scale_toggle), gfs);	
 	g_signal_connect (G_OBJECT (gfs->format.widget[F_FRACTION_MIN_INTEGER_DIGITS]), 
 			  "value_changed",
 			  G_CALLBACK (cb_min_integer_digits_changed), gfs);
diff --git a/goffice/gtk/go-format-sel.ui b/goffice/gtk/go-format-sel.ui
index 5f1b35e..2367173 100644
--- a/goffice/gtk/go-format-sel.ui
+++ b/goffice/gtk/go-format-sel.ui
@@ -1081,6 +1081,34 @@
                 <property name="position">22</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkSeparator" id="format_base_separator">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="padding">6</property>
+                <property name="position">23</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="format_pi_scale_check">
+                <property name="label" translatable="yes">As multiple of ð</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">24</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 863c3b4..384a9d3 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -107,7 +107,7 @@
 
 /* ------------------------------------------------------------------------- */
 
-#define DEBUG_PROGRAMS
+#undef DEBUG_PROGRAMS
 #undef DEBUG_REF_COUNT
 
 /***************************************************************************/
@@ -5405,7 +5405,10 @@ go_format_generate_fraction_str (GString *dst, GOFormatDetails const *details)
 	if  (numerator_min_digits > 0)
 		go_string_append_c_n (dst, '0', numerator_min_digits);
 
-	g_string_append_c (dst, '/');
+	if (details->pi_scale)
+		g_string_append (dst, " pi/");
+	else
+		g_string_append_c (dst, '/');
 	
 	if (details->automatic_denominator) {
 		go_string_append_c_n (dst, '?', 
@@ -5664,9 +5667,8 @@ go_format_details_init (GOFormatDetails *details, GOFormatFamily family)
 	details->magic = GO_FORMAT_MAGIC_NONE;
 	details->exponent_step = 1;
 	details->exponent_digits = 2;
-	details->min_digits = 1;
+	details->min_digits = (family == GO_FORMAT_FRACTION) ? 0 : 1;
 	details->split_fraction = TRUE;
-	details->numerator_min_digits = 1;
 	details->denominator_min_digits = 1;
 	details->denominator_max_digits = 1;
 	details->denominator = 8;
@@ -5827,7 +5829,8 @@ go_format_get_details (GOFormat const *fmt,
 	}
 
 	case GO_FORMAT_FRACTION: {
- 		gchar **tokens = g_strsplit_set (str, " /", 3);
+		char *c_str = pango_trim_string (str);
+ 		gchar **tokens = g_strsplit_set (c_str, " /", 3);
 		int numerator_base;
 		char const *integer;
 		int d;
@@ -5835,7 +5838,10 @@ go_format_get_details (GOFormat const *fmt,
 		/* Since it is a fraction we get at least 2 tokens */
 		g_return_if_fail (tokens + 1 != NULL);
 
-		dst->split_fraction = (tokens[2] != NULL && strlen (tokens[0]) > 0);
+		dst->pi_scale = (NULL != strstr (str, "pi/"));
+
+		dst->split_fraction = (tokens[2] != NULL) && (0 != strcmp (tokens[1], "pi"));
+
 		if (dst->split_fraction) {
 			integer = tokens[0];
 			dst->min_digits = 0;
@@ -5862,13 +5868,18 @@ go_format_get_details (GOFormat const *fmt,
 			dst->denominator_min_digits = 0;
 			dst->denominator_max_digits = 0;
 			while (*integer != 0) {
-				dst->denominator_max_digits++;
-				if (*integer++ == '0')
+				if (*integer == '#' || *integer == '?' 
+				    || g_ascii_isdigit (*integer)) 
+					dst->denominator_max_digits++;
+				if (*integer == '0') {
 					dst->denominator_min_digits++;
+				}
+				integer++;
 			}
 		}
 
 		g_strfreev (tokens);	
+		g_free (c_str);
 
 		if (exact != NULL) {
 			newstr = g_string_new (NULL);
diff --git a/goffice/utils/go-format.h b/goffice/utils/go-format.h
index 3e1495c..135ff1d 100644
--- a/goffice/utils/go-format.h
+++ b/goffice/utils/go-format.h
@@ -99,6 +99,7 @@ typedef struct {
 	/* FRACTION: */
 	gboolean automatic_denominator;
 	gboolean split_fraction;
+	gboolean pi_scale;
 	int numerator_min_digits;
 	int denominator_min_digits;
 	int denominator_max_digits;



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