[Gnucash-changes] r13312 - gnucash/trunk - Take the selection into account when handling the keypad decimal point

David Hampton hampton at cvs.gnucash.org
Sun Feb 19 21:16:50 EST 2006


Author: hampton
Date: 2006-02-19 21:16:50 -0500 (Sun, 19 Feb 2006)
New Revision: 13312
Trac: http://svn.gnucash.org/trac/changeset/13312

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/register/register-gnome/pricecell-gnome.c
Log:
Take the selection into account when handling the keypad decimal point
key.  Fixes 314775.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-02-20 00:02:01 UTC (rev 13311)
+++ gnucash/trunk/ChangeLog	2006-02-20 02:16:50 UTC (rev 13312)
@@ -1,5 +1,9 @@
 2006-02-19  David Hampton  <hampton at employees.org>
 
+	* src/register/register-gnome/pricecell-gnome.c: Take the
+	selection into account when handling the keypad decimal point key.
+	Fixes 314775.
+
 	* src/register/register-gnome/combocell-gnome.c: When looking for
 	an matching account name, start at the beginning of the selected
 	region, not the end.  Problem created when the code stopped adding

Modified: gnucash/trunk/src/register/register-gnome/pricecell-gnome.c
===================================================================
--- gnucash/trunk/src/register/register-gnome/pricecell-gnome.c	2006-02-20 00:02:01 UTC (rev 13311)
+++ gnucash/trunk/src/register/register-gnome/pricecell-gnome.c	2006-02-20 02:16:50 UTC (rev 13312)
@@ -50,9 +50,8 @@
     struct lconv *lc;
     GString *newval_gs;
     gboolean is_return;
-    int i;
-    const char *c;
-    gunichar uc;
+    gint start, end;
+    gchar *buf;
 
     if (event->type != GDK_KEY_PRESS)
 	return FALSE;
@@ -67,6 +66,7 @@
             if (!(event->state &
                   (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SHIFT_MASK)))
                 is_return = TRUE;
+	    /* fall through */
 
         case GDK_KP_Enter:
             {
@@ -113,6 +113,7 @@
             return FALSE;
     }
 
+    /* This  point is only reached when the KP_Decimal key is pressed. */
     if (cell->print_info.monetary)
 	decimal_point = lc->mon_decimal_point[0];
     else
@@ -121,32 +122,23 @@
     /* allocate space for newval_ptr : oldval + one letter ( the
        decimal_point ) */
     newval_gs = g_string_new("");
-    /* copy oldval up to the cursor position */
-    i = 0;
-    c = bcell->value;
-    while (*c && (i < *cursor_position))
-    {
-        uc = g_utf8_get_char (c);
-        g_string_append_unichar (newval_gs, uc);
-        c = g_utf8_next_char (c);
-        i++;
-    }
 
-    /* insert the decimal_point at cursor position */
-    g_string_append_c (newval_gs, decimal_point);
-    i++;
-    c = g_utf8_next_char (c);
-    
-    /* copy oldval after cursor position */
-    while (*c) 
-    {
-        uc = g_utf8_get_char (c);
-        g_string_append_unichar (newval_gs, uc);
-        c = g_utf8_next_char (c);
-    }
+    start = MIN(*start_selection, *end_selection);
+    end = MAX(*start_selection, *end_selection);
 
+    /* length in bytes, not chars. do not use g_utf8_strlen. */
+    buf = malloc(strlen(bcell->value));
+    g_utf8_strncpy(buf, bcell->value, start);
+    g_string_append(newval_gs, buf);
+    g_free(buf);
+
+    g_string_append_unichar(newval_gs, decimal_point);
+
+    buf = g_utf8_offset_to_pointer(bcell->value, end);
+    g_string_append(newval_gs, buf);
+
     /* update the cursor position */
-    (*cursor_position)++;
+    *cursor_position = start + 1;
 
     gnc_basic_cell_set_value_internal (bcell, newval_gs->str);
 



More information about the gnucash-changes mailing list