[gcalctool/gcalctool-newui2] Head fixes
- From: Robert Ancell <rancell src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gcalctool/gcalctool-newui2] Head fixes
- Date: Sun, 30 Aug 2009 23:57:00 +0000 (UTC)
commit 7cda3a885920e2e151a5464b91a293b3abaf66a8
Author: Robert Ancell <robert ancell gmail com>
Date: Mon Aug 31 09:56:39 2009 +1000
Head fixes
data/financial.ui | 22 ++++++++++++----
src/display.c | 71 +++++++++++++++++++---------------------------------
src/display.h | 1 -
src/functions.c | 4 +-
src/mp-convert.c | 6 +++-
src/mp.h | 6 +++-
6 files changed, 52 insertions(+), 58 deletions(-)
---
diff --git a/data/financial.ui b/data/financial.ui
index 78cba64..8b60ed6 100644
--- a/data/financial.ui
+++ b/data/financial.ui
@@ -12,6 +12,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
@@ -188,6 +189,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox2">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
@@ -364,6 +366,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox3">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table3">
<property name="visible">True</property>
@@ -538,10 +541,11 @@
<property name="has_separator">False</property>
<signal name="response" handler="finc_response_cb"/>
<child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox3">
+ <object class="GtkVBox" id="dialog-vbox10">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
- <object class="GtkTable" id="table3">
+ <object class="GtkTable" id="table10">
<property name="visible">True</property>
<property name="border_width">6</property>
<property name="n_rows">3</property>
@@ -549,7 +553,7 @@
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
- <object class="GtkLabel" id="label12">
+ <object class="GtkLabel" id="label47">
<property name="visible">True</property>
<property name="label" translatable="yes" comments="Gross Profit Margin Dialog: Description of calculation">Calculates the resale price of a product, based on the product cost and the wanted gross profit margin.</property>
<property name="wrap">True</property>
@@ -561,7 +565,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="label13">
+ <object class="GtkLabel" id="label48">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" comments="Gross Profit Margin Dialog: Label before cost input">C_ost:</property>
@@ -576,7 +580,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="label14">
+ <object class="GtkLabel" id="label49">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" comments="Gross Profit Margin Dialog: Label before margin input">_Margin:</property>
@@ -627,7 +631,7 @@
</packing>
</child>
<child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area3">
+ <object class="GtkHButtonBox" id="dialog-action_area10">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
@@ -684,6 +688,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox4">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table4">
<property name="visible">True</property>
@@ -861,6 +866,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox5">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table5">
<property name="visible">True</property>
@@ -1038,6 +1044,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox6">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table6">
<property name="visible">True</property>
@@ -1215,6 +1222,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox7">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table7">
<property name="visible">True</property>
@@ -1392,6 +1400,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox8">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table8">
<property name="visible">True</property>
@@ -1600,6 +1609,7 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox9">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkTable" id="table9">
<property name="visible">True</property>
diff --git a/src/display.c b/src/display.c
index e030b71..2ab56ac 100644
--- a/src/display.c
+++ b/src/display.c
@@ -163,7 +163,6 @@ gboolean display_get_integer(GCDisplay *display, gint64 *value)
const char *text;
char buf[MAX_DISPLAY];
gchar *endptr;
- guint bases[] = {2, 8, 10, 16};
text = display_get_text(display);
if (display_is_result(display)) {
@@ -171,7 +170,7 @@ gboolean display_get_integer(GCDisplay *display, gint64 *value)
text = buf;
}
- *value = g_ascii_strtoll(text, &endptr, bases[v->base]);
+ *value = g_ascii_strtoll(text, &endptr, v->base);
if(*endptr != '\0' || ((*value == G_MAXINT64 || *value == G_MININT64) && errno == ERANGE))
return FALSE;
return TRUE;
@@ -545,8 +544,11 @@ display_is_usable_number(GCDisplay *display, MPNumber *z)
if (display_is_empty(display)) {
mp_set_from_integer(0, z);
return TRUE;
+ } else if (display_is_result(display)) {
+ mp_set_from_mp(display_get_answer(display), z);
+ return TRUE;
} else {
- return display_solve(display, z) == 0; // FIXME: Change to MP
+ return mp_set_from_string(display_get_text(display), z) == 0;
}
}
@@ -623,25 +625,6 @@ void display_set_format(GCDisplay *display, DisplayFormat type)
}
-// FIXME: Obsolete
-int
-display_solve(GCDisplay *display, MPNumber *result)
-{
- MPEquationOptions options;
- const char *text;
- int errorCode;
-
- memset(&options, 0, sizeof(options));
- options.wordlen = v->wordlen;
- options.angle_units = v->ttype;
-
- text = display_get_text(display);
- errorCode = mp_equation_parse(text, &options, result);
-
- return errorCode;
-}
-
-
/* Convert engineering or scientific number in the given base. */
static void
make_eng_sci(GCDisplay *display, char *target, int target_len, const MPNumber *x, int base_)
@@ -727,27 +710,7 @@ make_eng_sci(GCDisplay *display, char *target, int target_len, const MPNumber *x
void
display_make_number(GCDisplay *display, char *target, int target_len, const MPNumber *x, int base, int ignoreError)
{
- static double max_fix[17] = {
- 0,
- 0,
- 1.298074214e+33, /* Binary. */
- 0,
- 0,
- 0,
- 0,
- 0,
- 2.037035976e+90, /* Octal. */
- 0,
- 1.000000000e+100, /* Decimal */
- 0,
- 0,
- 0,
- 0,
- 0,
- 2.582249878e+120 /* Hexadecimal. */
- };
-
- double val;
+ double val, max_fix;
/* NOTE: display_make_number can currently set v->error when converting to a double.
* This is to provide the same look&feel as V3 even though gcalctool
@@ -758,16 +721,34 @@ display_make_number(GCDisplay *display, char *target, int target_len, const MPNu
*/
double number = mp_cast_to_double(x);
-
+
val = fabs(number);
if (v->error && !ignoreError) {
target[0] = '\0';
return;
}
+
+ switch (base)
+ {
+ case 2:
+ max_fix = 1.298074214e+33;
+ break;
+ case 8:
+ max_fix = 2.037035976e+90;
+ break;
+ case 10:
+ max_fix = 1.000000000e+100;
+ break;
+ default:
+ case 16:
+ max_fix = 2.582249878e+120;
+ break;
+ }
+
// FIXME: Do this based on the number of digits, not actual values
if ((display->format == ENG) ||
(display->format == SCI) ||
- (display->format == FIX && val != 0.0 && (val > max_fix[base]))) {
+ (display->format == FIX && val != 0.0 && (val > max_fix))) {
make_eng_sci(display, target, target_len, x, base);
} else {
mp_cast_to_string(x, base, v->accuracy, !v->display.show_zeroes, target, target_len);
diff --git a/src/display.h b/src/display.h
index 3e2ff2f..c0a5c8e 100644
--- a/src/display.h
+++ b/src/display.h
@@ -92,7 +92,6 @@ gboolean display_is_result(GCDisplay *);
gboolean display_is_usable_number(GCDisplay *display, MPNumber *);
const char *display_get_text(GCDisplay *display);
-int display_solve(GCDisplay *display, MPNumber *);
void display_make_number(GCDisplay *display, char *target, int target_len, const MPNumber *MPnumber, int base, int ignoreError);
diff --git a/src/functions.c b/src/functions.c
index 0435683..c18200a 100644
--- a/src/functions.c
+++ b/src/functions.c
@@ -192,7 +192,7 @@ do_shift(int count)
{
MPNumber z;
- if (display_is_usable_number(&v->display, &z) || !mp_is_integer(&z)) {
+ if (!display_is_usable_number(&v->display, &z) || !mp_is_integer(&z)) {
/* Translators: This message is displayed in the status bar when a bit
shift operation is performed and the display does not contain a number */
ui_set_statusbar(_("No sane value to do bitwise shift"),
@@ -210,7 +210,7 @@ do_sto(int index)
{
MPNumber temp;
- if (display_is_usable_number(&v->display, &temp))
+ if (!display_is_usable_number(&v->display, &temp))
ui_set_statusbar(_("No sane value to store"),
"gtk-dialog-error");
else
diff --git a/src/mp-convert.c b/src/mp-convert.c
index d03577e..a79af5f 100644
--- a/src/mp-convert.c
+++ b/src/mp-convert.c
@@ -595,7 +595,7 @@ char_val(char **c, int base)
}
-void
+int
mp_set_from_string(const char *str, MPNumber *z)
{
int i, base, negate = 0, multiplier = 0;
@@ -685,7 +685,7 @@ mp_set_from_string(const char *str, MPNumber *z)
}
if (c != end) {
- // FIXME: Error decoding
+ return 1;
}
if (multiplier != 0) {
@@ -697,4 +697,6 @@ mp_set_from_string(const char *str, MPNumber *z)
if (negate == 1)
mp_invert_sign(z, z);
+
+ return 0;
}
diff --git a/src/mp.h b/src/mp.h
index 4cef038..729f7ae 100644
--- a/src/mp.h
+++ b/src/mp.h
@@ -204,8 +204,10 @@ void mp_set_from_fraction(int numerator, int denominator, MPNumber *z);
/* Sets z to be a uniform random number in the range [0, 1] */
void mp_set_from_random(MPNumber *z);
-/* Sets z from a string representation in 'text' */
-void mp_set_from_string(const char *text, MPNumber *z);
+/* Sets z from a string representation in 'text'.
+ * Returns 0 on success.
+ */
+int mp_set_from_string(const char *text, MPNumber *z);
/* Returns x as a native single-precision floating point number */
float mp_cast_to_float(const MPNumber *x);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]