goffice r2333 - in trunk: . goffice/gtk goffice/utils



Author: mortenw
Date: Wed Mar 18 19:37:40 2009
New Revision: 2333
URL: http://svn.gnome.org/viewvc/goffice?rev=2333&view=rev

Log:
2009-03-18  Morten Welinder  <terra gnome org>

	* goffice/gtk/go-format-sel.c (fmt_dialog_init_fmt_list): Select a
	magic format if just the magic agrees.

	* goffice/utils/go-format.c (go_format_get_magic): New function.



Modified:
   trunk/ChangeLog
   trunk/goffice/gtk/go-format-sel.c
   trunk/goffice/utils/go-format.c
   trunk/goffice/utils/go-format.h

Modified: trunk/goffice/gtk/go-format-sel.c
==============================================================================
--- trunk/goffice/gtk/go-format-sel.c	(original)
+++ trunk/goffice/gtk/go-format-sel.c	Wed Mar 18 19:37:40 2009
@@ -520,18 +520,28 @@
 fmt_dialog_init_fmt_list (GOFormatSel *gfs, char const *const *formats,
 			  GtkTreeIter *select)
 {
-	GtkTreeIter iter;
-	char *fmt;
-	const char *cur_fmt = go_format_as_XL (gfs->format.spec);
+	GOFormatMagic cur_magic = go_format_get_magic (gfs->format.spec);
 
 	for (; *formats; formats++) {
+		GtkTreeIter iter;
+		char *fmt = go_format_str_localize (*formats);
+		GOFormat *f = go_format_new_from_XL (*formats);
+		GOFormatMagic magic = go_format_get_magic (f);
+		gboolean found;
+
 		gtk_list_store_append (gfs->format.formats.model, &iter);
-		fmt = go_format_str_localize (*formats);
 		gtk_list_store_set (gfs->format.formats.model, &iter,
 				    0, fmt, -1);
 		g_free (fmt);
 
-		if (!strcmp (*formats, cur_fmt))
+		/* Magic formats are fully defined by their magic.  */
+		found = cur_magic
+			? (cur_magic == magic)
+			: go_format_eq (f, gfs->format.spec);
+
+		go_format_unref (f);
+
+		if (found)
 			*select = iter;
 	}
 }

Modified: trunk/goffice/utils/go-format.c
==============================================================================
--- trunk/goffice/utils/go-format.c	(original)
+++ trunk/goffice/utils/go-format.c	Wed Mar 18 19:37:40 2009
@@ -273,7 +273,8 @@
 	unsigned int typ : 8;
 	unsigned int ref_count : 24;
 	GOColor color;
-	unsigned int has_fill;
+	unsigned char has_fill;
+	GOFormatMagic magic;
 	char *format;
 	union {
 		struct {
@@ -1902,7 +1903,8 @@
 		GOFormatCondition *condition;
 		const char *tail;
 		GOFormatParseState state;
-		GOFormat *fmt = NULL;;
+		GOFormat *fmt = NULL;
+		gboolean is_magic = FALSE;
 
 		memset (&state, 0, sizeof (state));
 		tail = go_format_preparse (str, &state, FALSE, FALSE);
@@ -1918,16 +1920,18 @@
 		if (!state.have_cond)
 			condition->implicit = TRUE;
 
-		if (state.locale.locale == 0xf800) {
+		if (state.locale.locale == GO_FORMAT_MAGIC_SYSDATE) {
 			const GString *dfmt = go_locale_get_date_format ();
 			fmt = go_format_parse_sequential (dfmt->str, NULL, &state);
 			/* Make the upcoming switch do nothing.  */
 			state.typ = GO_FMT_INVALID;
-		} else if (state.locale.locale == 0xf400) {
+			is_magic = TRUE;
+		} else if (state.locale.locale == GO_FORMAT_MAGIC_SYSTIME) {
 			const GString *tfmt = go_locale_get_time_format ();
 			fmt = go_format_parse_sequential (tfmt->str, NULL, &state);
 			/* Make the upcoming switch do nothing.  */
 			state.typ = GO_FMT_INVALID;
+			is_magic = TRUE;
 		}
 
 		switch (state.typ) {
@@ -1967,6 +1971,7 @@
 		fmt->format = g_strndup (str, tail - str);
 		fmt->has_fill = state.fill_char != 0;
 		fmt->color = state.color;
+		if (is_magic) fmt->magic = state.locale.locale;
 
 		if (go_format_is_text (fmt)) {
 			/* Only one text format.  */
@@ -4330,6 +4335,23 @@
 #endif
 
 
+#ifdef DEFINE_COMMON
+/**
+ * go_format_get_magic:
+ * @fmt: Format to query
+ *
+ * Returns: a non-zero magic code for certain formats, such as system date.
+ **/
+GOFormatMagic
+go_format_get_magic (GOFormat const *fmt)
+{
+	g_return_val_if_fail (fmt != NULL, GO_FORMAT_MAGIC_NONE);
+
+	return fmt->magic;
+}
+#endif
+
+
 const GOFormat *
 SUFFIX(go_format_specialize) (GOFormat const *fmt, DOUBLE val, char type,
 			      gboolean *inhibit_minus)

Modified: trunk/goffice/utils/go-format.h
==============================================================================
--- trunk/goffice/utils/go-format.h	(original)
+++ trunk/goffice/utils/go-format.h	Wed Mar 18 19:37:40 2009
@@ -52,6 +52,12 @@
 } GOFormatFamily;
 
 typedef enum {
+	GO_FORMAT_MAGIC_NONE    = 0,
+	GO_FORMAT_MAGIC_SYSDATE = 0xf800,
+	GO_FORMAT_MAGIC_SYSTIME = 0xf400
+} GOFormatMagic;
+
+typedef enum {
 	GO_FORMAT_NUMBER_OK = 0,
 	GO_FORMAT_NUMBER_INVALID_FORMAT,
 	GO_FORMAT_NUMBER_DATE_ERROR
@@ -110,6 +116,7 @@
 
 int       go_format_month_before_day    (GOFormat const *fmt);
 gboolean  go_format_has_hour            (GOFormat const *fmt);
+GOFormatMagic go_format_get_magic       (GOFormat const *fmt);
 
 const GOFormat *go_format_specialize          (GOFormat const *fmt,
 					       double val, char type,



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