[gnumeric] Graphs: improve editing of minimum and maximum for date/time axes.



commit 447055c7c25b12943af6348da97518e749bb13a4
Author: Morten Welinder <terra gnome org>
Date:   Thu May 21 11:29:37 2009 -0400

    Graphs: improve editing of minimum and maximum for date/time axes.
---
 ChangeLog                         |    5 +
 NEWS                              |    1 +
 src/wbc-gtk.c                     |   17 ++-
 src/widgets/ChangeLog             |    6 +
 src/widgets/gnumeric-expr-entry.c |  245 +++++++++++++++++++++++++++++--------
 5 files changed, 219 insertions(+), 55 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 71085fa..952e643 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-05-21  Morten Welinder  <terra gnome org>
+
+	* src/wbc-gtk.c (cb_graph_dim_editor_update): Suppress the initial
+	update gui update.
+
 2009-05-18  Morten Welinder  <terra gnome org>
 
 	* src/sheet-object-widget.c: Clean up class accesses.
diff --git a/NEWS b/NEWS
index d997f78..50a5588 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,7 @@ Andreas:
 	* Fix printing of sheet objects whose text intersects with markup.
 	  [#581125]
 	* Load meta data from gnumeric files [#578607]
+	* Improve GUI for date/time axes.  [#574681]
 
 Jean:
 	* Do not crash in render_value for NULL values. [#581120]
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 7492602..9359f11 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -4431,6 +4431,7 @@ typedef struct {
 	GnmExprEntry *entry;
 	GogDataset *dataset;
 	int dim_i;
+	gboolean suppress_update;
 	GogDataType data_type;
 
 	gulong dataset_changed_handler;
@@ -4496,7 +4497,9 @@ cb_graph_dim_editor_update (GnmExprEntry *gee,
 	}
 
 	/* The SheetObjectGraph does the magic to link things in */
+	editor->suppress_update = TRUE;
 	gog_dataset_set_dim (editor->dataset, editor->dim_i, data, NULL);
+	editor->suppress_update = FALSE;
 }
 
 static gboolean
@@ -4514,7 +4517,9 @@ set_entry_contents (GnmExprEntry *entry, GOData *val)
 {
 	SheetControlGUI *scg = gnm_expr_entry_get_scg (entry);
 	Sheet const *sheet = scg_sheet (scg);
-	char *txt = go_data_serialize (val, (gpointer)sheet->convs);
+	char *txt;
+
+	txt = go_data_serialize (val, (gpointer)sheet->convs);
 	gnm_expr_entry_load_from_text (entry, txt);
 	g_free (txt);
 }
@@ -4525,7 +4530,7 @@ cb_dataset_changed (GogDataset *dataset,
 		    GraphDimEditor *editor)
 {
 	GOData *val = gog_dataset_get_dim (dataset, editor->dim_i);
-	if (val != NULL) {
+	if (val != NULL && !editor->suppress_update) {
 		g_signal_handler_block (editor->entry,
 					editor->entry_update_handler);
 		set_entry_contents (editor->entry, val);
@@ -4552,7 +4557,7 @@ graph_dim_editor_free (GraphDimEditor *editor)
 	g_free (editor);
 }
 
-static gpointer
+static GogDataEditor *
 wbcg_data_allocator_editor (GogDataAllocator *dalloc,
 			    GogDataset *dataset, int dim_i, GogDataType data_type)
 {
@@ -4563,6 +4568,7 @@ wbcg_data_allocator_editor (GogDataAllocator *dalloc,
 	editor = g_new (GraphDimEditor, 1);
 	editor->dataset		= dataset;
 	editor->dim_i		= dim_i;
+	editor->suppress_update = FALSE;
 	editor->data_type	= data_type;
 	editor->entry		= gnm_expr_entry_new (wbcg, TRUE);
 	g_object_weak_ref (G_OBJECT (editor->dataset),
@@ -4572,8 +4578,9 @@ wbcg_data_allocator_editor (GogDataAllocator *dalloc,
 		GTK_UPDATE_DISCONTINUOUS);
 
 	val = gog_dataset_get_dim (dataset, dim_i);
-	if (val != NULL)
+	if (val != NULL) {
 		set_entry_contents (editor->entry, val);
+	}
 
 	gnm_expr_entry_set_flags (editor->entry, GNM_EE_FORCE_ABS_REF, GNM_EE_MASK);
 
@@ -4588,7 +4595,7 @@ wbcg_data_allocator_editor (GogDataAllocator *dalloc,
 	g_object_set_data_full (G_OBJECT (editor->entry),
 		"editor", editor, (GDestroyNotify) graph_dim_editor_free);
 
-	return editor->entry;
+	return GOG_DATA_EDITOR (editor->entry);
 }
 
 static void
diff --git a/src/widgets/ChangeLog b/src/widgets/ChangeLog
index def5189..4fde141 100644
--- a/src/widgets/ChangeLog
+++ b/src/widgets/ChangeLog
@@ -1,3 +1,9 @@
+2009-05-21  Morten Welinder  <terra gnome org>
+
+	* gnumeric-expr-entry.c: Add GogDataEditor interface.
+	(gnm_expr_entry_parse): Try parsing as a constant against current
+	format.
+
 2009-05-13  Morten Welinder  <terra gnome org>
 
 	* widget-editable-label.c (el_size_request): Simplify.
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index 0215e75..28eb975 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -24,11 +24,15 @@
 #include <expr.h>
 #include <dependent.h>
 #include <sheet.h>
+#include <workbook.h>
 #include <sheet-view.h>
 #include <selection.h>
 #include <commands.h>
 #include <gnm-format.h>
+#include <number-match.h>
 #include <goffice/utils/go-locale.h>
+#include <goffice/utils/go-font.h>
+#include <goffice/graph/gog-data-allocator.h>
 
 #include <gsf/gsf-impl-utils.h>
 #include <gtk/gtk.h>
@@ -64,6 +68,8 @@ struct _GnmExprEntry {
 	gboolean                 ignore_changes; /* internal mutex */
 
 	gboolean       feedback_disabled;
+
+	GOFormat const *constant_format;
 };
 
 typedef struct _GnmExprEntryClass {
@@ -90,7 +96,8 @@ enum {
 	PROP_TEXT,
 	PROP_FLAGS,
 	PROP_SCG,
-	PROP_WBCG
+	PROP_WBCG,
+	PROP_CONSTANT_FORMAT
 };
 
 static guint signals [LAST_SIGNAL] = { 0 };
@@ -105,6 +112,12 @@ static void     cb_gee_notify_cursor_position (GnmExprEntry *gee);
 
 static GtkObjectClass *parent_class = NULL;
 
+static GnmConventions const *
+gee_convs (const GnmExprEntry *gee)
+{
+	return sheet_get_conventions (gee->sheet);
+}
+
 static gboolean
 split_char_p (unsigned char const *c)
 {
@@ -278,6 +291,23 @@ cb_icon_clicked (GtkButton *icon,
 }
 
 static void
+gee_set_format (GnmExprEntry *gee, GOFormat const *fmt)
+{
+	if (fmt == gee->constant_format)
+		return;
+
+	if (fmt) go_format_ref (fmt);
+	go_format_unref (gee->constant_format);
+	gee->constant_format = fmt;
+
+#if 0
+	g_printerr ("Setting format %s\n", fmt ? go_format_as_XL (fmt) : "-");
+#endif
+
+	g_object_notify (G_OBJECT (gee), "constant-format");
+}
+
+static void
 gee_set_property (GObject      *object,
 		  guint         prop_id,
 		  GValue const *value,
@@ -322,6 +352,9 @@ gee_set_property (GObject      *object,
 		g_return_if_fail (gee->wbcg == NULL);
 		gee->wbcg = WBC_GTK (g_value_get_object (value));
 		break;
+	case PROP_CONSTANT_FORMAT:
+		gee_set_format (gee, g_value_get_pointer (value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 	}
@@ -353,6 +386,9 @@ gee_get_property (GObject      *object,
 	case PROP_WBCG:
 		g_value_set_object (value, G_OBJECT (gee->wbcg));
 		break;
+	case PROP_CONSTANT_FORMAT:
+		g_value_set_pointer (value, (gpointer)gee->constant_format);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 	}
@@ -568,7 +604,7 @@ cb_gee_key_press_event (GtkEntry	*entry,
 			/* Turn the value into an expression so we get the right syntax.  */
 			expr = gnm_expr_new_constant (v);
 			cst = gnm_expr_as_string  (expr, &gee->pp,
-						   sheet_get_conventions (sheet));
+						   gee_convs (gee));
 			gnm_expr_free (expr);
 
 			gtk_editable_delete_text (editable, start, end);
@@ -656,6 +692,74 @@ gee_init (GnmExprEntry *gee)
 }
 
 static void
+gee_finalize (GObject *obj)
+{
+	GnmExprEntry *gee = (GnmExprEntry *)obj;
+
+	go_format_unref (gee->constant_format);
+
+	((GObjectClass *)parent_class)->finalize (obj);
+}
+
+static void
+gee_set_value_double (GogDataEditor *editor, double val,
+		      GODateConventions const *date_conv)
+{
+	GnmExprEntry *gee = GNM_EXPR_ENTRY (editor);
+	GnmValue *v = value_new_float (val);
+	char *txt = format_value (gee->constant_format, v, NULL, -1, date_conv);
+
+	value_release (v);
+
+	if (*txt == 0) {
+		g_free (txt);
+		txt = g_strdup_printf ("%g", val);
+	}
+
+#if 0
+	g_printerr ("Setting text %s\n", txt);
+#endif
+
+	g_object_set (G_OBJECT (editor), "text", txt, NULL);
+
+	g_free (txt);
+}
+
+static void
+gee_data_editor_set_format (GogDataEditor *deditor, GOFormat const *fmt)
+{
+	GnmExprEntry *gee = (GnmExprEntry *)deditor;
+	GnmValue *v;
+	GODateConventions const *date_conv =
+		workbook_date_conv (gee->sheet->workbook);
+
+	if (fmt == gee->constant_format)
+		return;
+
+	v = format_match_number (gnm_expr_entry_get_text (gee),
+				 gee->constant_format, date_conv);
+
+	gee_set_format (gee, fmt);
+
+	if (v && VALUE_IS_FLOAT (v)) {
+		char *txt = format_value (gee->constant_format, v,
+					  NULL, -1, date_conv);
+		gtk_entry_set_text (gee->entry, txt);
+		g_free (txt);
+	}
+
+	if (v) value_release (v);
+}
+
+static void
+gee_go_plot_data_editor_init (GogDataEditorClass *iface)
+{
+	iface->set_format = gee_data_editor_set_format;
+	iface->set_value_double = gee_set_value_double;
+}
+
+
+static void
 gee_class_init (GObjectClass *gobject_class)
 {
 	GtkObjectClass *gtk_object_class = (GtkObjectClass *)gobject_class;
@@ -665,6 +769,7 @@ gee_class_init (GObjectClass *gobject_class)
 
 	gobject_class->set_property	= gee_set_property;
 	gobject_class->get_property	= gee_get_property;
+	gobject_class->finalize		= gee_finalize;
 	gtk_object_class->destroy	= gee_destroy;
 	widget_class->mnemonic_activate = gee_mnemonic_activate;
 
@@ -692,41 +797,58 @@ gee_class_init (GObjectClass *gobject_class)
 		g_cclosure_marshal_VOID__VOID,
 		G_TYPE_NONE, 0);
 
-	g_object_class_install_property (gobject_class,
-		PROP_UPDATE_POLICY,
-		g_param_spec_enum ("update-policy", "Update policy",
-			"How frequently changes to the entry should be applied",
-			GTK_TYPE_UPDATE_TYPE, GTK_UPDATE_CONTINUOUS,
-			GSF_PARAM_STATIC | G_PARAM_READWRITE));
-	g_object_class_install_property (gobject_class,
-		PROP_WITH_ICON,
-		g_param_spec_boolean ("with-icon", "With icon",
-			"Should there be an icon to the right of the entry",
-			TRUE,
-			GSF_PARAM_STATIC | G_PARAM_READWRITE));
-	g_object_class_install_property (gobject_class,
-		PROP_TEXT,
-		g_param_spec_string ("text", "Text",
-			"The contents of the entry",
-			"",
-			GSF_PARAM_STATIC | G_PARAM_READWRITE));
-	g_object_class_install_property (gobject_class,
-		PROP_FLAGS,
-		g_param_spec_uint ("flags", NULL, NULL,
-			0, GNM_EE_MASK, 0,
-			GSF_PARAM_STATIC | G_PARAM_READWRITE));
-	g_object_class_install_property (gobject_class,
-		PROP_SCG,
-		g_param_spec_object ("scg", "SheetControlGUI",
-			"The GUI container associated with the entry.",
-			SHEET_CONTROL_GUI_TYPE,
-			GSF_PARAM_STATIC | G_PARAM_READWRITE));
-	g_object_class_install_property (gobject_class,
-		PROP_WBCG,
-		g_param_spec_object ("wbcg", "WBCGtk",
-			"The toplevel GUI container associated with the entry.",
-			WBC_GTK_TYPE,
-			GSF_PARAM_STATIC | G_PARAM_READWRITE));
+	g_object_class_install_property
+		(gobject_class, PROP_UPDATE_POLICY,
+		 g_param_spec_enum ("update-policy",
+				    _("Update policy"),
+				    _("How frequently changes to the entry should be applied"),
+				    GTK_TYPE_UPDATE_TYPE, GTK_UPDATE_CONTINUOUS,
+				    GSF_PARAM_STATIC | G_PARAM_READWRITE));
+
+	g_object_class_install_property
+		(gobject_class, PROP_WITH_ICON,
+		 g_param_spec_boolean ("with-icon",
+				       _("With icon"),
+				       _("Should there be an icon to the right of the entry?"),
+				       TRUE,
+				       GSF_PARAM_STATIC | G_PARAM_READWRITE));
+
+	g_object_class_install_property
+		(gobject_class, PROP_TEXT,
+		 g_param_spec_string ("text",
+				      _("Text"),
+				      _("The contents of the entry"),
+				      "",
+				      GSF_PARAM_STATIC | G_PARAM_READWRITE));
+
+	g_object_class_install_property
+		(gobject_class, PROP_FLAGS,
+		 g_param_spec_uint ("flags", NULL, NULL,
+				    0, GNM_EE_MASK, 0,
+				    GSF_PARAM_STATIC | G_PARAM_READWRITE));
+
+	g_object_class_install_property
+		(gobject_class, PROP_SCG,
+		 g_param_spec_object ("scg",
+				      _("SheetControlGUI"),
+				      _("The GUI container associated with the entry."),
+				      SHEET_CONTROL_GUI_TYPE,
+				      GSF_PARAM_STATIC | G_PARAM_READWRITE));
+
+	g_object_class_install_property
+		(gobject_class, PROP_WBCG,
+		 g_param_spec_object ("wbcg",
+				      _("WBCGtk"),
+				      _("The toplevel GUI container associated with the entry."),
+				      WBC_GTK_TYPE,
+				      GSF_PARAM_STATIC | G_PARAM_READWRITE));
+
+	g_object_class_install_property
+		(gobject_class, PROP_CONSTANT_FORMAT,
+		 g_param_spec_pointer ("constant-format",
+				       _("Constant Format"),
+				       _("Format for constants"),
+				       GSF_PARAM_STATIC | G_PARAM_READWRITE));
 }
 
 /***************************************************************************/
@@ -752,7 +874,8 @@ gee_cell_editable_init (GtkCellEditableIface *iface)
 GSF_CLASS_FULL (GnmExprEntry, gnm_expr_entry,
 		NULL, NULL, gee_class_init, NULL,
 		gee_init, GTK_TYPE_HBOX, 0,
-		GSF_INTERFACE (gee_cell_editable_init, GTK_TYPE_CELL_EDITABLE))
+		GSF_INTERFACE (gee_cell_editable_init, GTK_TYPE_CELL_EDITABLE);
+		GSF_INTERFACE (gee_go_plot_data_editor_init, GOG_TYPE_DATA_EDITOR))
 
 /**
  * gee_prepare_range :
@@ -806,7 +929,7 @@ gee_rangesel_make_text (GnmExprEntry const *gee)
 
 	out.accum = g_string_new (NULL);
 	out.pp    = &gee->pp;
-	out.convs = gee->sheet->convs;
+	out.convs = gee_convs (gee);
 	rangeref_as_string (&out, &ref);
 	return g_string_free (out.accum, FALSE);
 }
@@ -892,7 +1015,7 @@ gnm_expr_entry_find_range (GnmExprEntry *gee)
 		ptr = text;
 
 	while (ptr != NULL && *ptr && ptr <= cursor) {
-		tmp = rangeref_parse (&range, ptr, &gee->pp, gee->sheet->convs);
+		tmp = rangeref_parse (&range, ptr, &gee->pp, gee_convs (gee));
 		if (tmp != ptr) {
 			if (tmp >= cursor) {
 				rs->is_valid = TRUE;
@@ -1039,8 +1162,8 @@ gee_reset_update_timer (GnmExprEntry *gee, gboolean user_requested)
  * @user_requested : is the update requested by the user (eg activation)
  *
  * Higher level operations know when they are logically complete and can notify
- * ExperEntry clients.  eg button up after a drag selection indicates a logical
- * end to the change and offers a good time to update.
+ * GnmExprEntry clients.  For example, button-up after a drag selection
+ * indicates a logical end to the change and offers a good time to update.
  **/
 void
 gnm_expr_entry_signal_update (GnmExprEntry *gee, gboolean user_requested)
@@ -1236,20 +1359,23 @@ gnm_expr_entry_load_from_text (GnmExprEntry *gee, char const *txt)
 void
 gnm_expr_entry_load_from_dep (GnmExprEntry *gee, GnmDependent const *dep)
 {
-	GnmParsePos pp;
-
 	g_return_if_fail (IS_GNM_EXPR_ENTRY (gee));
 	g_return_if_fail (dep != NULL);
 	/* We have nowhere to store the text while frozen. */
 	g_return_if_fail (gee->freeze_count == 0);
 
 	if (dep->texpr != NULL) {
-		char *text = gnm_expr_top_as_string (dep->texpr,
-			parse_pos_init_dep (&pp, dep), gnm_conventions_default);
+		char *text;
+		GnmParsePos pp;
+
+		parse_pos_init_dep (&pp, dep);
+		text = gnm_expr_top_as_string (dep->texpr, &pp,
+					       gee_convs (gee));
 
 		gee_rangesel_reset (gee);
 		gtk_entry_set_text (gee->entry, text);
 		gee->rangesel.text_end = strlen (text);
+
 		g_free (text);
 	} else
 		gnm_expr_entry_load_from_text (gee, "");
@@ -1274,8 +1400,8 @@ gnm_expr_entry_load_from_expr (GnmExprEntry *gee,
 	g_return_if_fail (gee->freeze_count == 0);
 
 	if (texpr != NULL) {
-		char *text = gnm_expr_top_as_string (texpr, pp,
-				gnm_conventions_default);
+		char *text = gnm_expr_top_as_string
+			(texpr, pp, gee_convs (gee));
 		gee_rangesel_reset (gee);
 		gtk_entry_set_text (gee->entry, text);
 		gee->rangesel.text_end = strlen (text);
@@ -1461,6 +1587,10 @@ gnm_expr_entry_parse (GnmExprEntry *gee, GnmParsePos const *pp,
 	if (text == NULL || text[0] == '\0')
 		return NULL;
 
+#if 0
+	g_printerr ("Parsing %s\n", text);
+#endif
+
 	if ((gee->flags & GNM_EE_FORCE_ABS_REF))
 		flags |= GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES;
 	else if ((gee->flags & GNM_EE_FORCE_REL_REF))
@@ -1468,7 +1598,22 @@ gnm_expr_entry_parse (GnmExprEntry *gee, GnmParsePos const *pp,
 	if (!(gee->flags & GNM_EE_SHEET_OPTIONAL))
 		flags |= GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
 
-	texpr = gnm_expr_parse_str (text, pp, flags, NULL, perr);
+	texpr = NULL;
+
+	if (gee->constant_format) {
+		GnmValue *v = format_match_number
+			(text, gee->constant_format,
+			 workbook_date_conv (gee->sheet->workbook));
+		if (v) {
+			texpr = gnm_expr_top_new_constant (v);
+			gtk_entry_set_text (gee->entry, text);
+			return texpr;
+		}
+	}
+
+	if (!texpr)
+		texpr = gnm_expr_parse_str (text, pp, flags, NULL, perr);
+
 	if (texpr == NULL)
 		return NULL;
 
@@ -1487,7 +1632,7 @@ gnm_expr_entry_parse (GnmExprEntry *gee, GnmParsePos const *pp,
 	}
 
 	/* Reset the entry in case something changed */
-	str = gnm_expr_top_as_string (texpr, pp, gnm_conventions_default);
+	str = gnm_expr_top_as_string (texpr, pp, gee_convs (gee));
 	if (strcmp (str, text)) {
 		SheetControlGUI *scg = wbcg_cur_scg (gee->wbcg);
 		Rangesel const *rs = &gee->rangesel;



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