gcalctool r2085 - in branches/gnome-2-22: . gcalctool
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2085 - in branches/gnome-2-22: . gcalctool
- Date: Tue, 29 Apr 2008 11:13:53 +0100 (BST)
Author: rancell
Date: Tue Apr 29 10:13:53 2008
New Revision: 2085
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2085&view=rev
Log:
Modify cursor when adding/removing thousands separators (Bug #527669)
Modified:
branches/gnome-2-22/ChangeLog
branches/gnome-2-22/gcalctool/display.c
branches/gnome-2-22/gcalctool/display.h
branches/gnome-2-22/gcalctool/gtk.c
Modified: branches/gnome-2-22/gcalctool/display.c
==============================================================================
--- branches/gnome-2-22/gcalctool/display.c (original)
+++ branches/gnome-2-22/gcalctool/display.c Tue Apr 29 10:13:53 2008
@@ -41,29 +41,36 @@
static char *make_eng_sci(int *, int);
-/* Add in the thousand separators characters if required and if we are
- * currently in the decimal numeric base, use the "right" radix character.
- */
-
+/* Add in the thousand separators characters if required */
void
-localize_expression(char *dest, const char *src, int dest_length)
+localize_expression(char *dest, const char *src, int dest_length, int *cursor)
{
GString *clean, *output;
const char *c, *d;
- int digit_count = -1;
+ int digit_count = -1, read_cursor, new_cursor;
gboolean after_radix = FALSE;
-
+
/* Only modify if valid */
if (v->error || v->base != DEC) {
STRNCPY(dest, src, dest_length - 1);
return;
}
+
+ if (cursor) {
+ new_cursor = *cursor;
+ } else {
+ new_cursor = -1;
+ }
/* Remove separators if not supported */
clean = g_string_sized_new(strlen(src));
- for (c = src; *c; c++) {
+ for (c = src, read_cursor = 1; *c; c++, read_cursor++) {
if (strncmp(c, v->tsep, strlen(v->tsep)) == 0) {
c += strlen(v->tsep) - 1;
+ if (new_cursor >= read_cursor) {
+ new_cursor--;
+ }
+ read_cursor--;
}
else {
g_string_append_c(clean, *c);
@@ -78,14 +85,15 @@
/* Scan expression looking for numbers and inserting separators */
output = g_string_sized_new(dest_length);
- for (c = clean->str; *c; c++) {
+ for (c = clean->str, read_cursor = 1; *c; c++, read_cursor++) {
/* Insert separators between digits */
if (*c >= '0' && *c <= '9') {
/* Read ahead to find the number of digits */
if (digit_count < 0) {
digit_count = 1;
- for (d = c + 1; *d >= '0' && *d <= '9'; d++)
+ for (d = c + 1; *d >= '0' && *d <= '9'; d++) {
digit_count++;
+ }
}
g_string_append_c(output, *c);
@@ -93,6 +101,10 @@
/* Insert separator after nth digit */
if (!after_radix && digit_count > 1 && digit_count % v->tsep_count == 1) {
g_string_append(output, v->tsep);
+ if (new_cursor > read_cursor) {
+ new_cursor++;
+ }
+ read_cursor++;
}
digit_count--;
}
@@ -113,7 +125,11 @@
STRNCPY(dest, output->str, dest_length - 1);
g_string_free(output, TRUE);
- g_string_free(clean, TRUE);
+ g_string_free(clean, TRUE);
+
+ if (cursor != NULL && *cursor != -1) {
+ *cursor = new_cursor;
+ }
}
@@ -604,7 +620,7 @@
}
ans = make_number(e->ans, v->base, TRUE);
- localize_expression(localized, ans, MAX_LOCALIZED);
+ localize_expression(localized, ans, MAX_LOCALIZED, &cursor);
t = str_replace(str, "Ans", localized);
free(str);
str = t;
@@ -617,7 +633,7 @@
free(str);
str = t;
}
-
+
ui_set_display(str, cursor);
free(str);
break;
Modified: branches/gnome-2-22/gcalctool/display.h
==============================================================================
--- branches/gnome-2-22/gcalctool/display.h (original)
+++ branches/gnome-2-22/gcalctool/display.h Tue Apr 29 10:13:53 2008
@@ -25,7 +25,7 @@
#include "calctool.h"
void initialise();
-void localize_expression(char *, const char *, int);
+void localize_expression(char *, const char *, int, int *);
char *make_fixed(int *, char *, int, int, int);
char *make_number(int *, int, int);
void clear_display(int);
Modified: branches/gnome-2-22/gcalctool/gtk.c
==============================================================================
--- branches/gnome-2-22/gcalctool/gtk.c (original)
+++ branches/gnome-2-22/gcalctool/gtk.c Tue Apr 29 10:13:53 2008
@@ -954,8 +954,8 @@
if (str == NULL || str[0] == '\0') {
str = " ";
} else {
- if (v->noparens == 0) {
- localize_expression(localized, str, MAX_LOCALIZED);
+ if (v->syntax == EXPRS || (v->syntax == NPA && v->noparens == 0)) {
+ localize_expression(localized, str, MAX_LOCALIZED, &cursor);
str = localized;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]