[gcalctool/gcalctool-newui2] ...
- From: Robert Ancell <rancell src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gcalctool/gcalctool-newui2] ...
- Date: Sun, 30 Aug 2009 23:56:50 +0000 (UTC)
commit d69627c72b686424d2569f59e28ffddb2aec4cc0
Author: Robert Ancell <robert ancell gmail com>
Date: Sat Aug 22 10:54:52 2009 -0700
...
data/gcalctool.ui | 343 +++++++++++++++++------------------------------------
src/calctool.c | 3 +-
src/display.c | 112 ++++++++----------
src/functions.c | 1 -
src/gtk.c | 178 ++--------------------------
src/mp-equation.h | 3 -
src/unittest.c | 15 ++-
7 files changed, 177 insertions(+), 478 deletions(-)
---
diff --git a/data/gcalctool.ui b/data/gcalctool.ui
index 7f67575..02e2dd1 100644
--- a/data/gcalctool.ui
+++ b/data/gcalctool.ui
@@ -110,23 +110,6 @@
</object>
</child>
<child>
- <object class="GtkMenuItem" id="insert_ascii_menu">
- <property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">Insert ASCII value</property>
- <property name="label" translatable="yes" comments="Edit|Insert ASCII value menu item">_Insert ASCII value...</property>
- <property name="use_underline">True</property>
- <accelerator key="I" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- <signal name="select" handler="menu_item_select_cb"/>
- <signal name="deselect" handler="menu_item_deselect_cb"/>
- <signal name="activate" handler="insert_ascii_cb"/>
- </object>
- </child>
- <child>
- <object class="GtkSeparatorMenuItem" id="menuitem2">
- <property name="visible">True</property>
- </object>
- </child>
- <child>
<object class="GtkImageMenuItem" id="menuitem6">
<property name="label">gtk-preferences</property>
<property name="visible">True</property>
@@ -211,23 +194,6 @@
<signal name="activate" handler="mode_radio_cb"/>
</object>
</child>
- <child>
- <object class="GtkSeparatorMenuItem" id="separator1">
- <property name="visible">True</property>
- </object>
- </child>
- <child>
- <object class="GtkCheckMenuItem" id="show_registers_menu">
- <property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">Show memory registers</property>
- <property name="label" translatable="yes" comments="View|Memory Registers menu item">_Memory Registers</property>
- <property name="use_underline">True</property>
- <accelerator key="M" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- <signal name="select" handler="menu_item_select_cb"/>
- <signal name="deselect" handler="menu_item_deselect_cb"/>
- <signal name="activate" handler="edit_register_names_cb"/>
- </object>
- </child>
</object>
</child>
</object>
@@ -3594,7 +3560,20 @@
</packing>
</child>
<child>
- <placeholder/>
+ <object class="GtkButton" id="calc_character_button">
+ <property name="label" translatable="yes" comments="Boolean NOT button">á</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="border_width">3</property>
+ <property name="focus_on_click">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">9</property>
+ <property name="right_attach">10</property>
+ <property name="x_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
+ <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
+ </packing>
</child>
</object>
<packing>
@@ -4494,111 +4473,6 @@
</row>
</data>
</object>
- <object class="GtkDialog" id="edit_register_names_dialog">
- <property name="width_request">380</property>
- <property name="height_request">300</property>
- <property name="border_width">5</property>
- <property name="title" translatable="yes" comments="Title of edit register names dialog">Edit Register Names</property>
- <property name="destroy_with_parent">True</property>
- <property name="type_hint">dialog</property>
- <property name="has_separator">False</property>
- <signal name="response" handler="edit_register_names_response_cb"/>
- <signal name="delete_event" handler="edit_register_names_delete_cb"/>
- <child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox2">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkVBox" id="vbox2">
- <property name="visible">True</property>
- <property name="border_width">5</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkLabel" id="label51">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes" comments="Edit Register Names Dialog: Instructions in dialog">Click a description to edit it:</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">never</property>
- <child>
- <object class="GtkTreeView" id="edit_register_names_treeview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="rules_hint">True</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area2">
- <property name="visible">True</property>
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="helpbutton1">
- <property name="label">gtk-help</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">False</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="okbutton1">
- <property name="label">gtk-close</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="has_default">True</property>
- <property name="receives_default">False</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="-11">helpbutton1</action-widget>
- <action-widget response="-3">okbutton1</action-widget>
- </action-widgets>
- </object>
<object class="GtkMenu" id="memory_store_popup">
<child>
<object class="GtkMenuItem" id="store_menu_item0">
@@ -4670,14 +4544,6 @@
<signal name="activate" handler="store_menu_cb"/>
</object>
</child>
- <child>
- <object class="GtkMenuItem" id="edit_register_names_menu_item">
- <property name="visible">True</property>
- <property name="label" translatable="yes" comments="Menu item in the register menu to show the Edit Register Names dialog">Edit Names...</property>
- <property name="use_underline">True</property>
- <signal name="activate" handler="edit_register_names_cb"/>
- </object>
- </child>
</object>
<object class="GtkMenu" id="memory_recall_popup">
<child>
@@ -4750,14 +4616,6 @@
<signal name="activate" handler="recall_menu_cb"/>
</object>
</child>
- <child>
- <object class="GtkMenuItem" id="edit_register_names_menu_item2">
- <property name="visible">True</property>
- <property name="label" translatable="yes" comments="Menu item in the register menu to show the Edit Register Names dialog">Edit Names...</property>
- <property name="use_underline">True</property>
- <signal name="activate" handler="edit_register_names_cb"/>
- </object>
- </child>
</object>
<object class="GtkDialog" id="ascii_dialog">
<property name="border_width">6</property>
@@ -4873,14 +4731,14 @@
<object class="GtkVBox" id="dialog-vbox4">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="spacing">2</property>
+ <property name="spacing">18</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
- <property name="n_rows">6</property>
- <property name="n_columns">3</property>
+ <property name="n_rows">4</property>
+ <property name="n_columns">2</property>
<property name="column_spacing">6</property>
- <property name="row_spacing">6</property>
+ <property name="row_spacing">12</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
@@ -4890,7 +4748,6 @@
<property name="mnemonic_widget">angle_unit_combobox</property>
</object>
<packing>
- <property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
@@ -4903,7 +4760,6 @@
<property name="mnemonic_widget">display_format_combobox</property>
</object>
<packing>
- <property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
@@ -4915,8 +4771,8 @@
<property name="model">angle_unit_model</property>
</object>
<packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
</packing>
</child>
<child>
@@ -4925,50 +4781,10 @@
<property name="model">display_format_model</property>
</object>
<packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label4">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Significant _places:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">spinbutton1</property>
- </object>
- <packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label5">
- <property name="visible">True</property>
- <property name="label" translatable="yes"> </property>
- </object>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">4</property>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkSpinButton" id="spinbutton1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">•</property>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
</packing>
</child>
<child>
@@ -4980,9 +4796,8 @@
<property name="mnemonic_widget">word_size_combobox</property>
</object>
<packing>
- <property name="right_attach">2</property>
- <property name="top_attach">5</property>
- <property name="bottom_attach">6</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
@@ -4992,41 +4807,99 @@
<property name="model">word_size_model</property>
</object>
<packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">5</property>
- <property name="bottom_attach">6</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="checkbutton1">
- <property name="label" translatable="yes">Show trailing _zeroes</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
<property name="left_attach">1</property>
- <property name="right_attach">3</property>
+ <property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="checkbutton2">
- <property name="label" translatable="yes">Show _thousands separators</property>
+ <object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
+ <property name="bottom_padding">6</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkTable" id="table2">
+ <property name="visible">True</property>
+ <property name="n_rows">3</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkCheckButton" id="checkbutton1">
+ <property name="label" translatable="yes">Show trailing _zeroes</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="checkbutton2">
+ <property name="label" translatable="yes">Show _thousands separators</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Show</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">spinbutton1</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="spinbutton1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">decimal _places</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">spinbutton1</property>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
<packing>
- <property name="right_attach">3</property>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
</packing>
</child>
</object>
diff --git a/src/calctool.c b/src/calctool.c
index 5e6388e..cbecf1d 100644
--- a/src/calctool.c
+++ b/src/calctool.c
@@ -60,7 +60,6 @@ solve(const char *equation)
char result_str[MAXLINE];
memset(&options, 0, sizeof(options));
- options.base = 10;
options.wordlen = 32;
options.angle_units = MP_DEGREES;
@@ -184,6 +183,8 @@ init_state(void)
acc = MAX_DIGITS + 12; /* MP internal accuracy. */
v->error = FALSE; /* No calculator error initially. */
+
+ v->base = 10;
digits = g_strsplit(digit_values, ",", -1);
for (i = 0; i < 16; i++) {
diff --git a/src/display.c b/src/display.c
index 8eab055..e030b71 100644
--- a/src/display.c
+++ b/src/display.c
@@ -632,7 +632,6 @@ display_solve(GCDisplay *display, MPNumber *result)
int errorCode;
memset(&options, 0, sizeof(options));
- options.base = v->base;
options.wordlen = v->wordlen;
options.angle_units = v->ttype;
@@ -644,92 +643,81 @@ display_solve(GCDisplay *display, MPNumber *result)
/* Convert engineering or scientific number in the given base. */
-void
-make_eng_sci(GCDisplay *display, char *target, int target_len, const MPNumber *MPnumber, int base)
+static void
+make_eng_sci(GCDisplay *display, char *target, int target_len, const MPNumber *x, int base_)
{
static char digits[] = "0123456789ABCDEF";
char fixed[MAX_DIGITS];
- MPNumber MP1, MPatmp, MPval;
- MPNumber MP1base, MP3base, MP10base;
- int i, dval, len;
- MPNumber MPmant; /* Mantissa. */
- int ddig; /* Number of digits in exponent. */
- int eng = 0; /* Set if this is an engineering number. */
- int exp = 0; /* Exponent */
+ MPNumber t, z, base, base3, base10, base10inv, mantissa;
+ int ddig, eng, exponent = 0;
GString *string;
string = g_string_sized_new(target_len);
+
+ eng = display->format == ENG;
- if (display->format == ENG) {
- eng = 1;
- }
- mp_abs(MPnumber, &MPval);
- mp_set_from_integer(0, &MP1);
- if (mp_is_less_than(MPnumber, &MP1))
+ mp_abs(x, &z);
+ if (mp_is_negative(x))
g_string_append(string, "â??");
- mp_set_from_mp(&MPval, &MPmant);
-
- mp_set_from_integer(base, &MP1base);
- mp_xpowy_integer(&MP1base, 3, &MP3base);
- mp_xpowy_integer(&MP1base, 10, &MP10base);
-
- mp_set_from_integer(1, &MP1);
- mp_divide(&MP1, &MP10base, &MPatmp);
-
- mp_set_from_integer(0, &MP1);
- if (!mp_is_equal(&MPmant, &MP1)) {
- while (!eng && mp_is_greater_equal(&MPmant, &MP10base)) {
- exp += 10;
- mp_multiply(&MPmant, &MPatmp, &MPmant);
+ mp_set_from_mp(&z, &mantissa);
+
+ mp_set_from_integer(base_, &base);
+ mp_xpowy_integer(&base, 3, &base3);
+ mp_xpowy_integer(&base, 10, &base10);
+ mp_set_from_integer(1, &t);
+ mp_divide(&t, &base10, &base10inv);
+
+ if (!mp_is_zero(&mantissa)) {
+ while (!eng && mp_is_greater_equal(&mantissa, &base10)) {
+ exponent += 10;
+ mp_multiply(&mantissa, &base10inv, &mantissa);
}
- while ((!eng && mp_is_greater_equal(&MPmant, &MP1base)) ||
- (eng && (mp_is_greater_equal(&MPmant, &MP3base) || exp % 3 != 0))) {
- exp += 1;
- mp_divide(&MPmant, &MP1base, &MPmant);
+ while ((!eng && mp_is_greater_equal(&mantissa, &base)) ||
+ (eng && (mp_is_greater_equal(&mantissa, &base3) || exponent % 3 != 0))) {
+ exponent += 1;
+ mp_divide(&mantissa, &base, &mantissa);
}
- while (!eng && mp_is_less_than(&MPmant, &MPatmp)) {
- exp -= 10;
- mp_multiply(&MPmant, &MP10base, &MPmant);
+ while (!eng && mp_is_less_than(&mantissa, &base10inv)) {
+ exponent -= 10;
+ mp_multiply(&mantissa, &base10, &mantissa);
}
- mp_set_from_integer(1, &MP1);
- while (mp_is_less_than(&MPmant, &MP1) || (eng && exp % 3 != 0)) {
- exp -= 1;
- mp_multiply(&MPmant, &MP1base, &MPmant);
+ mp_set_from_integer(1, &t);
+ while (mp_is_less_than(&mantissa, &t) || (eng && exponent % 3 != 0)) {
+ exponent -= 1;
+ mp_multiply(&mantissa, &base, &mantissa);
}
}
- mp_cast_to_string(&MPmant, base, v->accuracy, !v->display.show_zeroes, fixed, MAX_DIGITS);
- len = strlen(fixed);
- for (i = 0; i < len; i++)
- g_string_append_c(string, fixed[i]);
-
+ mp_cast_to_string(&mantissa, base_, v->accuracy, !v->display.show_zeroes, fixed, MAX_DIGITS);
+ g_string_append(string, fixed);
g_string_append(string, "Ã?10^");
- if (exp < 0) {
- exp = -exp;
+ if (exponent < 0) {
+ exponent = -exponent;
g_string_append(string, "â??");
} else {
g_string_append(string, "+");
}
- mp_set_from_string("0.5", &MP1);
- mp_add_integer(&MP1, exp, &MPval);
- mp_set_from_integer(1, &MP1);
- for (ddig = 0; mp_is_greater_equal(&MPval, &MP1); ddig++) {
- mp_divide(&MPval, &MP1base, &MPval);
+ mp_set_from_string("0.5", &t);
+ mp_add_integer(&t, exponent, &z);
+ mp_set_from_integer(1, &t);
+ for (ddig = 0; mp_is_greater_equal(&z, &t); ddig++) {
+ mp_divide(&z, &base, &z);
}
while (ddig-- > 0) {
- mp_multiply(&MPval, &MP1base, &MPval);
- dval = mp_cast_to_int(&MPval);
+ int dval;
+
+ mp_multiply(&z, &base, &z);
+ dval = mp_cast_to_int(&z);
g_string_append_c(string, digits[dval]);
- dval = -dval;
- mp_add_integer(&MPval, dval, &MPval);
+ mp_add_integer(&z, -dval, &z);
}
-
+
strncpy(target, string->str, target_len);
g_string_free(string, TRUE);
}
@@ -737,7 +725,7 @@ make_eng_sci(GCDisplay *display, char *target, int target_len, const MPNumber *M
/* Convert MP number to character string in the given base. */
void
-display_make_number(GCDisplay *display, char *target, int target_len, const MPNumber *MPnumber, int base, int ignoreError)
+display_make_number(GCDisplay *display, char *target, int target_len, const MPNumber *x, int base, int ignoreError)
{
static double max_fix[17] = {
0,
@@ -769,7 +757,7 @@ display_make_number(GCDisplay *display, char *target, int target_len, const MPNu
* order to do these tests.
*/
- double number = mp_cast_to_double(MPnumber);
+ double number = mp_cast_to_double(x);
val = fabs(number);
if (v->error && !ignoreError) {
@@ -780,8 +768,8 @@ display_make_number(GCDisplay *display, char *target, int target_len, const MPNu
if ((display->format == ENG) ||
(display->format == SCI) ||
(display->format == FIX && val != 0.0 && (val > max_fix[base]))) {
- make_eng_sci(display, target, target_len, MPnumber, base);
+ make_eng_sci(display, target, target_len, x, base);
} else {
- mp_cast_to_string(MPnumber, base, v->accuracy, !v->display.show_zeroes, target, target_len);
+ mp_cast_to_string(x, base, v->accuracy, !v->display.show_zeroes, target, target_len);
}
}
diff --git a/src/functions.c b/src/functions.c
index 8ed93b6..0435683 100644
--- a/src/functions.c
+++ b/src/functions.c
@@ -104,7 +104,6 @@ parse(const char *text, MPNumber *z)
MPEquationOptions options;
memset(&options, 0, sizeof(options));
- options.base = v->base;
options.wordlen = v->wordlen;
options.angle_units = v->ttype;
options.get_variable = get_variable;
diff --git a/src/gtk.c b/src/gtk.c
index b518cbc..1b1ad23 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -160,9 +160,6 @@ typedef struct {
GtkWidget *main_window;
- GtkTreeModel *register_model;
- GtkWidget *register_dialog;
-
GtkWidget *menubar; // FIXME: Why is this needed?
GtkWidget *bit_panel;
@@ -457,7 +454,6 @@ ui_set_mode(ModeType mode)
g_object_set(G_OBJECT(X.sci_panel), "visible", mode == SCIENTIFIC, NULL);
g_object_set(G_OBJECT(X.prog_panel), "visible", mode == PROGRAMMING, NULL);
g_object_set(G_OBJECT(X.bit_panel), "visible", mode == PROGRAMMING, NULL);
- gtk_widget_set_sensitive(GET_WIDGET("show_registers_menu"), mode != BASIC);
/* Set the title */
if((hostname = make_hostname())) {
@@ -591,14 +587,10 @@ ui_set_error_state(gboolean error)
gtk_widget_set_sensitive(GET_WIDGET("paste_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("undo_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("redo_menu"), !v->error);
- gtk_widget_set_sensitive(GET_WIDGET("insert_ascii_menu"), !v->error);
-
gtk_widget_set_sensitive(GET_WIDGET("view_basic_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("view_advanced_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("view_financial_menu"), !v->error);
- gtk_widget_set_sensitive(GET_WIDGET("view_scientific_menu"), !v->error);
- gtk_widget_set_sensitive(GET_WIDGET("show_registers_menu"), !v->error);
-
+ gtk_widget_set_sensitive(GET_WIDGET("view_scientific_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("about_menu"), !v->error);
}
@@ -610,31 +602,6 @@ ui_beep()
}
-static void
-set_registers_visible(gboolean visible)
-{
- GtkWidget *menu;
-
- menu = GET_WIDGET("show_registers_menu");
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), visible);
-
- gtk_widget_realize(X.register_dialog);
-
- if (visible) {
- if (gdk_window_is_visible(gtk_widget_get_window(X.register_dialog))) {
- gdk_window_raise(gtk_widget_get_window(X.register_dialog));
- return;
- }
- position_popup(X.main_window, X.register_dialog, POPUP_ABOVE);
- gtk_widget_show(X.register_dialog);
- } else {
- gtk_widget_hide(X.register_dialog);
- }
-
- set_boolean_resource(R_REGS, visible);
-}
-
-
G_MODULE_EXPORT
void
about_cb(GtkWidget *widget)
@@ -686,60 +653,6 @@ about_cb(GtkWidget *widget)
NULL);
}
-static void
-cell_edited_cb(GtkCellRendererText *cell, const gchar *path_string,
- const gchar *new_text, gpointer data)
-{
- GtkTreeModel *model = (GtkTreeModel *) data;
- GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
- GtkTreeIter iter;
- gint *column;
-
- column = g_object_get_data(G_OBJECT(cell), "column");
-
- gtk_tree_model_get_iter(model, &iter, path);
-
- switch (GPOINTER_TO_INT(column)) {
- case COLUMN_VALUE:
- gtk_list_store_set(GTK_LIST_STORE(model), &iter, column,
- g_strdup(new_text), -1);
- break;
-
- case COLUMN_DESCRIPTION:
- gtk_list_store_set(GTK_LIST_STORE(model), &iter, column,
- g_strdup(new_text), -1);
- break;
- }
-
- gtk_tree_path_free(path);
-}
-
-
-static void
-add_cf_column(GtkTreeView *treeview, gchar *name, gint colno, gboolean editable)
-{
- GtkCellRenderer *renderer;
- GtkTreeModel *model = gtk_tree_view_get_model(treeview);
-
- renderer = gtk_cell_renderer_text_new();
- if (editable)
- g_signal_connect(G_OBJECT(renderer), "edited",
- G_CALLBACK(cell_edited_cb), model);
- g_object_set_data(G_OBJECT(renderer), "column", GINT_TO_POINTER(colno));
-
- if (editable)
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview),
- -1, name, renderer,
- "text", colno,
- "editable", COLUMN_EDITABLE,
- NULL);
- else
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview),
- -1, name, renderer,
- "text", colno,
- NULL);
-}
-
G_MODULE_EXPORT
void
@@ -904,54 +817,6 @@ setup_finc_dialogs(void)
G_MODULE_EXPORT
-void
-edit_register_names_response_cb(GtkDialog *dialog, gint id)
-{
- if (id == GTK_RESPONSE_HELP)
- help_display();
- else {
- gtk_widget_hide(GTK_WIDGET(dialog));
- set_registers_visible(FALSE);
- }
-}
-
-
-G_MODULE_EXPORT
-gboolean
-edit_register_names_delete_cb(GtkDialog *dialog)
-{
- set_registers_visible(FALSE);
- return TRUE;
-}
-
-
-static GtkTreeModel *
-create_register_model()
-{
- gint i = 0;
- GtkListStore *model;
- GtkTreeIter iter;
- char value[MAXLINE];
-
- model = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_BOOLEAN);
- for (i = 0; i < MAX_REGISTERS; i++) {
- gtk_list_store_append(model, &iter);
-
- display_make_number(&v->display, value, MAXLINE, register_get_value(i), 10, TRUE);
- gtk_list_store_set(model, &iter,
- COLUMN_NUMBER, i,
- COLUMN_EDITABLE, TRUE,
- COLUMN_VALUE, value,
- COLUMN_DESCRIPTION, register_get_name(i),
- -1);
- }
-
- return GTK_TREE_MODEL(model);
-}
-
-
-G_MODULE_EXPORT
gboolean
bit_toggle_cb(GtkWidget *event_box, GdkEventButton *event)
{
@@ -1503,14 +1368,6 @@ quit_cb(GtkWidget *widget)
G_MODULE_EXPORT
void
-edit_register_names_cb(GtkMenuItem *item)
-{
- set_registers_visible(TRUE);
-}
-
-
-G_MODULE_EXPORT
-void
show_preferences_cb(GtkMenuItem *menu)
{
gtk_window_present(GTK_WINDOW(X.preferences_dialog));
@@ -1552,7 +1409,6 @@ create_main_window()
X.main_window = GET_WIDGET("calc_window");
X.ascii_dialog = GET_WIDGET("ascii_dialog");
X.ascii_entry = GET_WIDGET("ascii_entry");
- X.register_dialog = GET_WIDGET("edit_register_names_dialog");
X.menubar = GET_WIDGET("menubar");
X.scrolledwindow = GET_WIDGET("display_scroll"),
X.display_item = GET_WIDGET("displayitem"),
@@ -1622,33 +1478,17 @@ create_main_window()
set_menubar_tooltip("quit_menu");
set_menubar_tooltip("copy_menu");
set_menubar_tooltip("paste_menu");
- set_menubar_tooltip("insert_ascii_menu");
set_menubar_tooltip("undo_menu");
set_menubar_tooltip("redo_menu");
set_menubar_tooltip("view_basic_menu");
set_menubar_tooltip("view_advanced_menu");
set_menubar_tooltip("view_financial_menu");
set_menubar_tooltip("view_scientific_menu");
- set_menubar_tooltip("show_registers_menu");
set_menubar_tooltip("help_menu");
set_menubar_tooltip("about_menu");
/* Make dialogs transient of the main window */
gtk_window_set_transient_for(GTK_WINDOW(X.ascii_dialog), GTK_WINDOW(X.main_window));
- gtk_window_set_transient_for(GTK_WINDOW(X.register_dialog), GTK_WINDOW(X.main_window));
-
- /* Make register tree model */
- X.register_model = create_register_model();
- widget = GET_WIDGET("edit_register_names_treeview");
- gtk_tree_view_set_model(GTK_TREE_VIEW(widget), X.register_model);
- gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)),
- GTK_SELECTION_SINGLE);
- /* Translators: Edit Register Names Dialog: Register number column title */
- add_cf_column(GTK_TREE_VIEW(widget), _("No."), COLUMN_NUMBER, FALSE);
- /* Translators: Edit Register Names Dialog: Register value column title */
- add_cf_column(GTK_TREE_VIEW(widget), _("Value"), COLUMN_VALUE, TRUE);
- /* Translators: Edit Register Names Dialog: Register description column title */
- add_cf_column(GTK_TREE_VIEW(widget), _("Description"), COLUMN_DESCRIPTION, TRUE);
X.display_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(X.display_item));
gtk_widget_ensure_style(X.display_item);
@@ -1746,7 +1586,8 @@ set_combo_box_from_config(const gchar *name, const gchar *key_name)
model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
key_value = get_resource(key_name);
- valid = gtk_tree_model_get_iter_first(model, &iter);
+ printf("'%s' '%s'\n", key_name, key_value);
+ valid = key_value && gtk_tree_model_get_iter_first(model, &iter);
while (valid) {
GValue value = {0};
@@ -1772,17 +1613,13 @@ set_combo_box_from_config(const gchar *name, const gchar *key_name)
void
ui_load(void)
{
- int boolval;
-
/* Create main gcalctool window. */
create_main_window();
ui_set_undo_enabled(FALSE, FALSE);
+ set_combo_box_from_config("angle_unit_combobox", R_TRIG);
set_combo_box_from_config("display_format_combobox", R_DISPLAY);
-
- /* Show the memory register window? */
- if (get_boolean_resource(R_REGS, &boolval))
- set_registers_visible(boolval);
+ //set_combo_box_from_config("word_size_combobox", R_WORDLEN);
}
@@ -1876,6 +1713,7 @@ add_buttons_to_size_group()
"calc_hyperbolic_cosine_button",
"calc_hyperbolic_sine_button",
"calc_hyperbolic_tangent_button",
+ "calc_character_button",
NULL};
size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
@@ -1886,7 +1724,9 @@ add_buttons_to_size_group()
void
ui_start(void)
-{
+{
+ ui_set_mode(X.mode);
+
gtk_widget_show(X.main_window);
/* Add buttons to size group so they are all the same size.
diff --git a/src/mp-equation.h b/src/mp-equation.h
index 969f489..1a6b585 100644
--- a/src/mp-equation.h
+++ b/src/mp-equation.h
@@ -35,9 +35,6 @@
/* Options for parser */
typedef struct {
- /* The numeric base (e.g 2, 8, 10, 16) */
- int base;
-
/* The wordlength for binary operations in bits (e.g. 8, 16, 32) */
int wordlen;
diff --git a/src/unittest.c b/src/unittest.c
index bcfd9a7..c9bb66e 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -28,6 +28,7 @@
#include "mp-equation.h"
static MPEquationOptions options;
+static int base;
static int fails = 0;
@@ -72,7 +73,7 @@ test(char *expression, char *expected, int expected_error)
error = mp_equation_parse(expression, &options, &result);
if(error == 0) {
- mp_cast_to_string(&result, options.base, 9, 1, result_str, 1024);
+ mp_cast_to_string(&result, base, 9, 1, result_str, 1024);
if(expected_error != 0)
fail("'%s' -> %s, expected error %d", expression, result_str, expected_error);
else if(strcmp(result_str, expected) != 0)
@@ -93,20 +94,20 @@ void
test_parser()
{
memset(&options, 0, sizeof(options));
- options.base = 10;
+ base = 10;
options.wordlen = 32;
options.angle_units = MP_DEGREES;
- options.base = 2;
+ base = 2;
test("2", "10â??", 0);
- options.base = 8;
+ base = 8;
test("16434824", "76543210â??", 0);
- options.base = 16;
+ base = 16;
test("18364758544493064720", "FEDCBA9876543210â??â??", 0);
- options.base = 10;
+ base = 10;
test("0â??", "0", 0); test("0â??", "0", 0); test("0", "0", 0); test("0â??â??", "0", 0);
test("1â??", "1", 0); test("1â??", "1", 0); test("1", "1", 0); test("1â??â??", "1", 0);
test("2â??", "", -1); test("2â??", "2", 0); test("2", "2", 0); test("2â??â??", "2", 0);
@@ -376,7 +377,7 @@ test_parser()
test("3 or 5", "7", 0);
test("3 xor 5", "6", 0);
- options.base = 16;
+ base = 16;
test("ones 1", "FFFFFFFEâ??â??", 0);
test("ones 7FFFFFFFâ??â??", "80000000â??â??", 0);
test("twos 1", "FFFFFFFFâ??â??", 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]