gnumeric r16502 - in branches/gnumeric-1-8: . src
- From: mortenw svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r16502 - in branches/gnumeric-1-8: . src
- Date: Fri, 11 Apr 2008 12:00:18 +0100 (BST)
Author: mortenw
Date: Fri Apr 11 12:00:17 2008
New Revision: 16502
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16502&view=rev
Log:
2008-04-11 Morten Welinder <terra gnome org>
* src/wbc-gtk-edit.c (close_to_int): Add missing abs case causing
lots of trouble.
(guess_time_format): Return the format, not a string. Deduce
GOFormat's limit of decimals.
Modified:
branches/gnumeric-1-8/ChangeLog
branches/gnumeric-1-8/NEWS
branches/gnumeric-1-8/src/wbc-gtk-edit.c
Modified: branches/gnumeric-1-8/NEWS
==============================================================================
--- branches/gnumeric-1-8/NEWS (original)
+++ branches/gnumeric-1-8/NEWS Fri Apr 11 12:00:17 2008
@@ -19,6 +19,7 @@
* Fix performance repeated VLOOKUP/HLOOKUP/MATCH with constant
data range. [#525875]
* Fix date pasting problems to/from 1904 workbooks. [#490419]
+ * Fix problems editing times.
--------------------------------------------------------------------------
Gnumeric 1.8.2
Modified: branches/gnumeric-1-8/src/wbc-gtk-edit.c
==============================================================================
--- branches/gnumeric-1-8/src/wbc-gtk-edit.c (original)
+++ branches/gnumeric-1-8/src/wbc-gtk-edit.c Fri Apr 11 12:00:17 2008
@@ -622,33 +622,45 @@
static gboolean
close_to_int (gnm_float x, gnm_float eps)
{
- return (x - gnm_fake_round (x)) < eps;
+ return gnm_abs (x - gnm_fake_round (x)) < eps;
}
-static void
-guess_time_format (GString *res, gnm_float f)
+static GOFormat *
+guess_time_format (const char *prefix, gnm_float f)
{
- int decs;
+ int decs = 0;
gnm_float eps = 1e-6;
+ static int maxdecs = 6;
+ GString *str = g_string_new (prefix);
+ GOFormat *fmt;
- g_string_append (res, "hh:mm");
+ g_string_append (str, "hh:mm");
f *= 24 * 60;
- if (close_to_int (f, eps / 60))
- return;
-
- g_string_append (res, ":ss");
- f *= 60;
- if (close_to_int (f, eps))
- return;
+ if (!close_to_int (f, eps / 60)) {
+ g_string_append (str, ":ss");
+ f *= 60;
+ if (!close_to_int (f, eps)) {
+ g_string_append_c (str, '.');
+ while (decs < maxdecs) {
+ decs++;
+ g_string_append_c (str, '0');
+ f *= 10;
+ if (close_to_int (f, eps))
+ break;
+ }
+ }
+ }
- g_string_append_c (res, '.');
- for (decs = 0; decs < 6; decs++) {
- g_string_append_c (res, '0');
- f *= 10;
- if (close_to_int (f, eps))
- break;
+ while (go_format_is_invalid ((fmt = go_format_new_from_XL (str->str))) && decs > 0) {
+ /* We don't know how many decimals GOFormat allows. */
+ go_format_unref (fmt);
+ maxdecs = --decs;
+ g_string_truncate (str, str->len - 1);
}
+
+ g_string_free (str, TRUE);
+ return fmt;
}
static void
@@ -842,8 +854,9 @@
go_format_unref (new_fmt);
g_string_append_c (fstr, ' ');
- guess_time_format (fstr, f - gnm_floor (f));
- new_fmt = go_format_new_from_XL (fstr->str);
+ new_fmt = guess_time_format
+ (fstr->str,
+ f - gnm_floor (f));
g_string_free (fstr, TRUE);
}
@@ -863,12 +876,8 @@
case GO_FORMAT_TIME:
if (f >= 0 && f <= 1) {
- GString *fstr = g_string_new (NULL);
- GOFormat *new_fmt;
-
- guess_time_format (fstr, f);
- new_fmt = go_format_new_from_XL (fstr->str);
- g_string_free (fstr, TRUE);
+ GOFormat *new_fmt =
+ guess_time_format (NULL, f);
text = format_value (new_fmt, cell->value, NULL, -1,
workbook_date_conv (sv->sheet->workbook));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]