[gcalctool] Convert display.c into math-equation.c and a GObject
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Convert display.c into math-equation.c and a GObject
- Date: Mon, 5 Apr 2010 23:53:28 +0000 (UTC)
commit 9573ff6bbcea366fe67f4afe48c6ed134682aceb
Author: Robert Ancell <robert ancell gmail com>
Date: Tue Apr 6 08:40:51 2010 +1000
Convert display.c into math-equation.c and a GObject
src/Makefile.am | 4 +-
src/calctool.c | 3 +-
src/calctool.h | 4 +-
src/display.h | 121 ----------------------
src/financial.c | 4 +-
src/math-buttons.c | 8 +-
src/math-display.c | 35 ++-----
src/{display.c => math-equation.c} | 192 ++++++++++++++++++++----------------
src/math-equation.h | 136 +++++++++++++++++++++++++
src/ui-preferences.c | 12 +-
10 files changed, 271 insertions(+), 248 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0f11c88..6b490ca 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,14 +11,14 @@ gcalctool_SOURCES = \
calctool.h \
currency.c \
currency.h \
- display.c \
- display.h \
get.c \
get.h \
math-buttons.c \
math-buttons.h \
math-display.c \
math-display.h \
+ math-equation.c \
+ math-equation.h \
mp.c \
mp.h \
mp-binary.c \
diff --git a/src/calctool.c b/src/calctool.c
index f55c138..80a02e0 100644
--- a/src/calctool.c
+++ b/src/calctool.c
@@ -27,7 +27,6 @@
#include "currency.h"
#include "unittest.h"
#include "get.h"
-#include "display.h"
#include "ui.h"
#include "register.h"
#include "mp-equation.h"
@@ -218,7 +217,7 @@ main(int argc, char **argv)
init_state();
register_init();
- display_init(&v->display);
+ v->display = math_equation_new();
ui_gtk_init(&argc, &argv);
get_options(argc, argv);
diff --git a/src/calctool.h b/src/calctool.h
index 0f1f7bf..100ef14 100644
--- a/src/calctool.h
+++ b/src/calctool.h
@@ -24,7 +24,7 @@
#include "config.h"
#include "mp.h"
-#include "display.h"
+#include "math-equation.h"
#include "ui.h"
/* To make lint happy. */
@@ -51,7 +51,7 @@
typedef struct {
char *progname; /* Name of this program. */
- GCDisplay display; /* Display stack */
+ MathEquation *display; /* Display stack */
const char *digits[16]; /* Localized digit values */
const char *radix; /* Locale specific radix string. */
diff --git a/src/financial.c b/src/financial.c
index 29850b0..532c580 100644
--- a/src/financial.c
+++ b/src/financial.c
@@ -76,7 +76,7 @@ calc_ddb(MPNumber *t, MPNumber *cost, MPNumber *life, MPNumber *period)
}
if (len >= 0) {
- display_set_error (&v->display,
+ display_set_error (v->display,
("Error: the number of periods must be positive"));
mp_set_from_integer(0, t);
}
@@ -291,5 +291,5 @@ do_finc_expression(int function, MPNumber *arg1, MPNumber *arg2, MPNumber *arg3,
calc_term(&result, arg1, arg2, arg3);
break;
}
- display_set_number(&v->display, &result);
+ display_set_number(v->display, &result);
}
diff --git a/src/math-buttons.c b/src/math-buttons.c
index 968854e..de31039 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -600,7 +600,7 @@ update_store_menu(MathButtons *buttons)
t = register_get_value(registers[i]);
if (t)
- display_make_number(&v->display, value, MAXLINE, t);
+ display_make_number(v->display, value, MAXLINE, t);
snprintf(mstr, MAXLINE, "<span weight=\"bold\">%s</span> = %s", registers[i], value);
gtk_label_set_markup_with_mnemonic(GTK_LABEL(buttons->priv->store_menu_labels[i]), mstr);
}
@@ -675,7 +675,7 @@ update_recall_menu(MathButtons *buttons)
t = register_get_value(registers[i]);
if (t)
- display_make_number(&v->display, value, MAXLINE, t);
+ display_make_number(v->display, value, MAXLINE, t);
snprintf(mstr, MAXLINE, "<span weight=\"bold\">%s</span> = %s", registers[i], value);
gtk_label_set_markup_with_mnemonic(GTK_LABEL(buttons->priv->recall_menu_labels[i]), mstr);
}
@@ -996,7 +996,7 @@ currency_cb(GtkWidget *widget, MathButtons *buttons)
win = GTK_DIALOG(gtk_builder_get_object(buttons->priv->financial_ui, "currency_dialog"));
c_amount_upper = GTK_SPIN_BUTTON(gtk_builder_get_object(buttons->priv->financial_ui, "currency_amount_upper"));
c_amount_lower = GTK_SPIN_BUTTON(gtk_builder_get_object(buttons->priv->financial_ui, "currency_amount_lower"));
- if (display_is_usable_number(&v->display, &display_val)) {
+ if (display_is_usable_number(v->display, &display_val)) {
double start_val = mp_cast_to_double(&display_val);
gtk_spin_button_set_value(c_amount_upper, start_val);
}
@@ -1009,7 +1009,7 @@ currency_cb(GtkWidget *widget, MathButtons *buttons)
mp_set_from_string(result, &display_val);
g_free(result);
- display_set_number(&v->display, &display_val);
+ display_set_number(v->display, &display_val);
}
gtk_widget_hide(GTK_WIDGET(win));
diff --git a/src/math-display.c b/src/math-display.c
index f1484d3..1686715 100644
--- a/src/math-display.c
+++ b/src/math-display.c
@@ -20,8 +20,8 @@
#include <gdk/gdkkeysyms.h>
#include "math-display.h"
-#include "display.h"
-#include "calctool.h"
+#include "math-equation.h" // FIXME: Move into math-display.h
+#include "calctool.h" // FIXME: TEMP
enum {
NUMBER_MODE_CHANGED,
@@ -134,7 +134,7 @@ do_button(MathDisplay *display, int function, gpointer arg)
do_button(display, FN_TEXT, "^");
}
else {
- display_do_function(&v->display, function, arg, cursor_start, cursor_end);
+ display_do_function(v->display, function, arg, cursor_start, cursor_end);
if (function == FN_TEXT)
display->priv->last_text = (char *)arg;
else
@@ -602,18 +602,18 @@ void
math_display_set_base(MathDisplay *display, gint base)
{
/* If has a number already in a base, then solve and convert it */
- if (!display_is_result(&v->display) && display_is_number_with_base(&v->display))
+ if (!display_is_result(v->display) && display_is_number_with_base(v->display))
math_display_solve(display);
- if (display_is_result(&v->display)) {
+ if (display_is_result(v->display)) {
if (base == 2)
- display_convert (&v->display, BIN);
+ display_convert (v->display, BIN);
else if (base == 8)
- display_convert (&v->display, OCT);
+ display_convert (v->display, OCT);
else if (base == 16)
- display_convert (&v->display, HEX);
+ display_convert (v->display, HEX);
else
- display_convert (&v->display, DEC);
+ display_convert (v->display, DEC);
}
else {
if (base == 2)
@@ -643,20 +643,7 @@ math_display_class_init (MathDisplayClass *klass)
G_TYPE_NONE, 0);
}
-
-/*
- <child>
- <object class="GtkEventBox" id="display_eventbox">
- <property name="visible">True</property>
- <child>
- <object class="GtkScrolledWindow" id="display_scroll">
- <property name="can_focus">True</property>
- <child>
- <object class="GtkViewport" id="viewport1">
- <property name="resize_mode">queue</property>
- <child>
- <object class="GtkVBox" id="vbox1">
- <child>
+/* FIXME
<object class="GtkTextView" id="displayitem">
<property name="wrap_mode">word</property>
<child internal-child="accessible">
@@ -665,8 +652,6 @@ math_display_class_init (MathDisplayClass *klass)
</object>
</child>
</object>
- </child>
- <child>
<object class="GtkTextView" id="info_textview">
<property name="wrap_mode">word</property>
</object>
diff --git a/src/display.c b/src/math-equation.c
similarity index 86%
rename from src/display.c
rename to src/math-equation.c
index 26410aa..9cea6c4 100644
--- a/src/display.c
+++ b/src/math-equation.c
@@ -25,7 +25,7 @@
#include <errno.h>
#include <glib.h>
-#include "display.h"
+#include "math-equation.h"
#include "mp.h"
#include "ui.h"
@@ -34,8 +34,23 @@
#include "currency.h"
#include "calctool.h"
-static GCDisplayState *
-get_state(GCDisplay *display)
+
+struct MathEquationPrivate
+{
+ gint fixme;
+};
+
+G_DEFINE_TYPE (MathEquation, math_equation, G_TYPE_OBJECT);
+
+MathEquation *
+math_equation_new()
+{
+ return g_object_new (math_equation_get_type(), NULL);
+}
+
+
+static MathEquationState *
+get_state(MathEquation *display)
{
return &(display->h.e[display->h.current]);
}
@@ -47,7 +62,7 @@ get_state(GCDisplay *display)
/* Add in the thousand separators characters if required */
static void
-localize_expression(GCDisplay *display, char *dest, const char *src, int dest_length, int *cursor)
+localize_expression(MathEquation *display, char *dest, const char *src, int dest_length, int *cursor)
{
GString *output;
const char *c, *d;
@@ -111,9 +126,9 @@ localize_expression(GCDisplay *display, char *dest, const char *src, int dest_le
void
-display_clear(GCDisplay *display)
+display_clear(MathEquation *display)
{
- GCDisplayState *state;
+ MathEquationState *state;
state = get_state(display);
display_set_string(display, "", -1);
@@ -123,16 +138,16 @@ display_clear(GCDisplay *display)
static const char *
-get_text(GCDisplay *display)
+get_text(MathEquation *display)
{
return get_state(display)->expression;
}
static char *
-get_expression(GCDisplay *display)
+get_expression(MathEquation *display)
{
- GCDisplayState *state;
+ MathEquationState *state;
state = get_state(display);
if(state->ans_start >= 0)
@@ -143,7 +158,7 @@ get_expression(GCDisplay *display)
gboolean
-display_get_integer(GCDisplay *display, gint64 *value)
+display_get_integer(MathEquation *display, gint64 *value)
{
MPNumber t, min, max;
@@ -161,7 +176,7 @@ display_get_integer(GCDisplay *display, gint64 *value)
gboolean
-display_get_unsigned_integer(GCDisplay *display, guint64 *value)
+display_get_unsigned_integer(MathEquation *display, guint64 *value)
{
MPNumber t, max;
@@ -179,14 +194,14 @@ display_get_unsigned_integer(GCDisplay *display, guint64 *value)
MPNumber *
-display_get_answer(GCDisplay *display)
+display_get_answer(MathEquation *display)
{
return &get_state(display)->ans;
}
int
-display_get_cursor(GCDisplay *display)
+display_get_cursor(MathEquation *display)
{
return get_state(display)->cursor;
}
@@ -194,7 +209,7 @@ display_get_cursor(GCDisplay *display)
// FIXME: Looses accuracy
void
-display_set_number(GCDisplay *display, const MPNumber *x)
+display_set_number(MathEquation *display, const MPNumber *x)
{
char text[MAX_DISPLAY];
int enabled;
@@ -209,9 +224,9 @@ display_set_number(GCDisplay *display, const MPNumber *x)
void
-display_set_answer(GCDisplay *display)
+display_set_answer(MathEquation *display)
{
- GCDisplayState *state;
+ MathEquationState *state;
char text[MAX_DISPLAY];
state = get_state(display);
@@ -223,10 +238,10 @@ display_set_answer(GCDisplay *display)
static void
-display_make_text(GCDisplay *display, char *localized, int length, int *cursor)
+display_make_text(MathEquation *display, char *localized, int length, int *cursor)
{
char *str;
- GCDisplayState *e;
+ MathEquationState *e;
e = get_state(display);
@@ -245,7 +260,7 @@ display_make_text(GCDisplay *display, char *localized, int length, int *cursor)
static void
-display_refresh(GCDisplay *display)
+display_refresh(MathEquation *display)
{
char localized[MAX_LOCALIZED];
int cursor;
@@ -257,9 +272,9 @@ display_refresh(GCDisplay *display)
void
-display_set_string(GCDisplay *display, const char *value, int cursor)
+display_set_string(MathEquation *display, const char *value, int cursor)
{
- GCDisplayState *e;
+ MathEquationState *e;
if (value[0] == '\0')
cursor = -1;
@@ -274,9 +289,9 @@ display_set_string(GCDisplay *display, const char *value, int cursor)
void
-display_set_cursor(GCDisplay *display, int cursor)
+display_set_cursor(MathEquation *display, int cursor)
{
- GCDisplayState *e;
+ MathEquationState *e;
e = get_state(display);
e->cursor = cursor;
@@ -285,14 +300,14 @@ display_set_cursor(GCDisplay *display, int cursor)
void
-display_set_error(GCDisplay *display, const char *message)
+display_set_error(MathEquation *display, const char *message)
{
math_display_set_status(ui_get_display(X), message);
}
void
-display_convert(GCDisplay *display, DisplayFormat format)
+display_convert(MathEquation *display, DisplayFormat format)
{
DisplayFormat old_format;
@@ -308,15 +323,15 @@ display_convert(GCDisplay *display, DisplayFormat format)
static void
-copy_state(GCDisplayState *dst, GCDisplayState *src)
+copy_state(MathEquationState *dst, MathEquationState *src)
{
- memcpy(dst, src, sizeof(GCDisplayState));
+ memcpy(dst, src, sizeof(MathEquationState));
dst->expression = strdup(src->expression);
}
void
-display_clear_stack(GCDisplay *display)
+display_clear_stack(MathEquation *display)
{
int i = display->h.begin;
while (i != display->h.end) {
@@ -331,7 +346,7 @@ display_clear_stack(GCDisplay *display)
void
-display_push(GCDisplay *display)
+display_push(MathEquation *display)
{
int c;
@@ -362,7 +377,7 @@ display_push(GCDisplay *display)
void
-display_pop(GCDisplay *display)
+display_pop(MathEquation *display)
{
if (display->h.current != display->h.begin) {
display->h.current = ((display->h.current - 1) % UNDO_HISTORY_LENGTH);
@@ -376,7 +391,7 @@ display_pop(GCDisplay *display)
void
-display_unpop(GCDisplay *display)
+display_unpop(MathEquation *display)
{
if (display->h.current != display->h.end) {
display->h.current = ((display->h.current + 1) % UNDO_HISTORY_LENGTH);
@@ -390,16 +405,16 @@ display_unpop(GCDisplay *display)
gboolean
-display_is_undo_step(GCDisplay *display)
+display_is_undo_step(MathEquation *display)
{
return(display->h.current != display->h.begin);
}
void
-display_insert(GCDisplay *display, int cursor_start, int cursor_end, const char *text)
+display_insert(MathEquation *display, int cursor_start, int cursor_end, const char *text)
{
- GCDisplayState *state;
+ MathEquationState *state;
char buf[MAX_DISPLAY];
state = get_state(display);
@@ -459,7 +474,7 @@ display_insert(GCDisplay *display, int cursor_start, int cursor_end, const char
void
-display_insert_number(GCDisplay *display, int cursor_start, int cursor_end, const MPNumber *value)
+display_insert_number(MathEquation *display, int cursor_start, int cursor_end, const MPNumber *value)
{
char text[MAX_DISPLAY];
display_make_number(display, text, MAX_DISPLAY, value);
@@ -468,7 +483,7 @@ display_insert_number(GCDisplay *display, int cursor_start, int cursor_end, cons
void
-display_backspace(GCDisplay *display, int cursor_start, int cursor_end)
+display_backspace(MathEquation *display, int cursor_start, int cursor_end)
{
int cursor;
@@ -492,7 +507,7 @@ display_backspace(GCDisplay *display, int cursor_start, int cursor_end)
}
void
-display_delete(GCDisplay *display, int cursor_start, int cursor_end)
+display_delete(MathEquation *display, int cursor_start, int cursor_end)
{
/* Delete selected block */
if (cursor_start != cursor_end)
@@ -503,16 +518,16 @@ display_delete(GCDisplay *display, int cursor_start, int cursor_end)
gboolean
-display_is_empty(GCDisplay *display)
+display_is_empty(MathEquation *display)
{
return strcmp(get_text(display), "") == 0;
}
gboolean
-display_is_result(GCDisplay *display)
+display_is_result(MathEquation *display)
{
- GCDisplayState *state;
+ MathEquationState *state;
state = get_state(display);
if (state->ans_start == 0 && state->ans_end == g_utf8_strlen(state->expression, -1))
@@ -523,7 +538,7 @@ display_is_result(GCDisplay *display)
gboolean
-display_is_usable_number(GCDisplay *display, MPNumber *z)
+display_is_usable_number(MathEquation *display, MPNumber *z)
{
if (display_is_empty(display)) {
mp_set_from_integer(0, z);
@@ -538,7 +553,7 @@ display_is_usable_number(GCDisplay *display, MPNumber *z)
gboolean
-display_is_number_with_base(GCDisplay *display)
+display_is_number_with_base(MathEquation *display)
{
MPNumber t;
const char *text;
@@ -564,29 +579,7 @@ display_is_number_with_base(GCDisplay *display)
void
-display_init(GCDisplay *display)
-{
- int i;
-
- memset(display, 0, sizeof(GCDisplay));
-
- display->show_zeroes = FALSE;
- display->show_tsep = FALSE;
- display->format = DEC;
- display->accuracy = 9;
- display->word_size = 32;
- display->angle_unit = MP_DEGREES;
-
- for (i = 0; i < UNDO_HISTORY_LENGTH; i++) {
- display->h.e[i].expression = strdup("");
- display->h.e[i].ans_start = -1;
- display->h.e[i].ans_end = -1;
- }
-}
-
-
-void
-display_set_accuracy(GCDisplay *display, int accuracy)
+display_set_accuracy(MathEquation *display, int accuracy)
{
display->accuracy = accuracy;
get_state(display)->cursor = -1;
@@ -595,7 +588,7 @@ display_set_accuracy(GCDisplay *display, int accuracy)
void
-display_set_show_thousands_separator(GCDisplay *display, gboolean visible)
+display_set_show_thousands_separator(MathEquation *display, gboolean visible)
{
display->show_tsep = visible;
display_set_cursor(display, -1);
@@ -604,7 +597,7 @@ display_set_show_thousands_separator(GCDisplay *display, gboolean visible)
void
-display_set_show_trailing_zeroes(GCDisplay *display, gboolean visible)
+display_set_show_trailing_zeroes(MathEquation *display, gboolean visible)
{
display->show_zeroes = visible;
get_state(display)->cursor = -1;
@@ -613,7 +606,7 @@ display_set_show_trailing_zeroes(GCDisplay *display, gboolean visible)
void
-display_set_format(GCDisplay *display, DisplayFormat format)
+display_set_format(MathEquation *display, DisplayFormat format)
{
display->format = format;
get_state(display)->cursor = -1;
@@ -622,14 +615,14 @@ display_set_format(GCDisplay *display, DisplayFormat format)
void
-display_set_word_size(GCDisplay *display, int word_size)
+display_set_word_size(MathEquation *display, int word_size)
{
display->word_size = word_size;
}
void
-display_set_angle_unit(GCDisplay *display, MPAngleUnit angle_unit)
+display_set_angle_unit(MathEquation *display, MPAngleUnit angle_unit)
{
display->angle_unit = angle_unit;
}
@@ -637,7 +630,7 @@ display_set_angle_unit(GCDisplay *display, MPAngleUnit angle_unit)
/* 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_)
+make_eng_sci(MathEquation *display, char *target, int target_len, const MPNumber *x, int base_)
{
char fixed[MAX_DIGITS], *c;
MPNumber t, z, base, base3, base10, base10inv, mantissa;
@@ -702,7 +695,7 @@ make_eng_sci(GCDisplay *display, char *target, int target_len, const MPNumber *x
/* Convert MP number to character string. */
void
-display_make_number(GCDisplay *display, char *target, int target_len, const MPNumber *x)
+display_make_number(MathEquation *display, char *target, int target_len, const MPNumber *x)
{
switch(display->format) {
case DEC:
@@ -752,7 +745,7 @@ get_variable(const char *name, MPNumber *z, void *data)
{
char *c, *lower_name;
int result = 1;
- GCDisplay *display = data;
+ MathEquation *display = data;
MPNumber *t;
lower_name = strdup(name);
@@ -803,7 +796,7 @@ convert(const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z
static int
-parse(GCDisplay *display, const char *text, MPNumber *z, char **error_token)
+parse(MathEquation *display, const char *text, MPNumber *z, char **error_token)
{
MPEquationOptions options;
@@ -821,7 +814,7 @@ parse(GCDisplay *display, const char *text, MPNumber *z, char **error_token)
static void
-do_paste(GCDisplay *display, int cursor_start, int cursor_end, const char *text)
+do_paste(MathEquation *display, int cursor_start, int cursor_end, const char *text)
{
const char *input;
char c, *output, *clean_text;
@@ -885,7 +878,7 @@ do_paste(GCDisplay *display, int cursor_start, int cursor_end, const char *text)
static void
-do_insert_character(GCDisplay *display, const unsigned char *text)
+do_insert_character(MathEquation *display, const unsigned char *text)
{
MPNumber value;
int i = 0;
@@ -905,7 +898,7 @@ do_insert_character(GCDisplay *display, const unsigned char *text)
/* Perform bitwise shift on display value. */
static void
-do_shift(GCDisplay *display, int count)
+do_shift(MathEquation *display, int count)
{
MPNumber z;
@@ -926,22 +919,22 @@ do_factorize()
{
MPNumber value;
- if (!display_is_usable_number(&v->display, &value)) {
+ if (!display_is_usable_number(v->display, &value)) {
/* Translators: Error displayed when trying to factorize a non-integer value */
math_display_set_status(ui_get_display(X), _("Need an integer to factorize"));
return;
}
- display_clear(&v->display);
+ display_clear(v->display);
GList *factors = mp_factorize(&value);
- display_insert_number(&v->display, -1, -1, factors->data);
+ display_insert_number(v->display, -1, -1, factors->data);
g_slice_free(MPNumber, factors->data);
GList *list = factors->next;
for (; list != NULL; list = list->next) {
- display_insert(&v->display, -1, -1, "Ã?");
- display_insert_number(&v->display, -1, -1, list->data);
+ display_insert(v->display, -1, -1, "Ã?");
+ display_insert_number(v->display, -1, -1, list->data);
g_slice_free(MPNumber, list->data);
}
g_list_free(factors);
@@ -949,7 +942,7 @@ do_factorize()
static void
-do_sto(GCDisplay *display, const char *name)
+do_sto(MathEquation *display, const char *name)
{
MPNumber t;
@@ -961,7 +954,7 @@ do_sto(GCDisplay *display, const char *name)
void
-display_do_function(GCDisplay *display, int function, gpointer arg, int cursor_start, int cursor_end)
+display_do_function(MathEquation *display, int function, gpointer arg, int cursor_start, int cursor_end)
{
MPNumber *ans;
int enabled;
@@ -1121,3 +1114,34 @@ display_do_function(GCDisplay *display, int function, gpointer arg, int cursor_s
enabled = display_get_unsigned_integer(display, &bit_value);
math_buttons_set_bitfield(ui_get_buttons(X), enabled, bit_value);
}
+
+
+static void
+math_equation_class_init (MathEquationClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (MathEquationPrivate));
+}
+
+
+static void
+math_equation_init(MathEquation *equation)
+{
+ int i;
+
+ equation->priv = G_TYPE_INSTANCE_GET_PRIVATE (equation, math_equation_get_type(), MathEquationPrivate);
+
+ equation->show_zeroes = FALSE;
+ equation->show_tsep = FALSE;
+ equation->format = DEC;
+ equation->accuracy = 9;
+ equation->word_size = 32;
+ equation->angle_unit = MP_DEGREES;
+
+ for (i = 0; i < UNDO_HISTORY_LENGTH; i++) {
+ equation->h.e[i].expression = strdup("");
+ equation->h.e[i].ans_start = -1;
+ equation->h.e[i].ans_end = -1;
+ }
+}
diff --git a/src/math-equation.h b/src/math-equation.h
new file mode 100644
index 0000000..9eb9a44
--- /dev/null
+++ b/src/math-equation.h
@@ -0,0 +1,136 @@
+/* Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2008-2009 Robert Ancell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef DISPLAY_H
+#define DISPLAY_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MATH_EQUATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), math_equation_get_type(), MathEquation))
+
+typedef struct MathEquationPrivate MathEquationPrivate;
+
+#include "mp.h"
+
+#define UNDO_HISTORY_LENGTH 16 /* Arithmetic mode undo history length */
+#define MAX_DISPLAY 512
+
+/* Expression mode state */
+typedef struct {
+ MPNumber ans; /* Previously calculated answer */
+ char *expression; /* Expression entered by user */
+ int ans_start, ans_end; /* Start and end characters for ans variable in expression */
+ int cursor;
+} MathEquationState;
+
+/* Circular list of Arithmetic Precedence Mode states*/
+typedef struct {
+ unsigned int begin;
+ unsigned int end;
+ unsigned int current;
+ MathEquationState e[UNDO_HISTORY_LENGTH]; /* Expression mode state */
+} MathEquationHistory;
+
+/* Number display mode. */
+typedef enum { DEC, BIN, OCT, HEX, SCI, ENG } DisplayFormat;
+
+typedef struct
+{
+ GObject parent_instance;
+ MathEquationPrivate *priv;
+ MathEquationHistory h; /* History of expression mode states */
+ int show_tsep; /* Set if the thousands separator should be shown. */
+ int show_zeroes; /* Set if trailing zeroes should be shown. */
+ DisplayFormat format; /* Number display mode. */
+ int accuracy; /* Number of digits to show */
+ int word_size;
+ MPAngleUnit angle_unit;
+} MathEquation;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} MathEquationClass;
+
+/* Available functions */
+enum
+{
+ FN_TEXT,
+ FN_CALCULATE,
+ FN_CLEAR,
+ FN_BACKSPACE,
+ FN_DELETE,
+ FN_TOGGLE_BIT,
+ FN_SHIFT,
+ FN_FACTORIZE,
+ FN_STORE,
+ FN_RECALL,
+ FN_UNDO,
+ FN_REDO,
+ FN_PASTE,
+ FN_INSERT_CHARACTER
+};
+
+GType math_equation_get_type();
+MathEquation *math_equation_new();
+
+void display_set_accuracy(MathEquation *display, int accuracy);
+void display_set_show_thousands_separator(MathEquation *display, gboolean visible);
+void display_set_show_trailing_zeroes(MathEquation *display, gboolean visible);
+void display_set_format(MathEquation *display, DisplayFormat format);
+void display_set_word_size(MathEquation *display, int word_size);
+void display_set_angle_unit(MathEquation *display, MPAngleUnit angle_unit);
+void display_clear(MathEquation *);
+
+gboolean display_get_integer(MathEquation *display, gint64 *value);
+gboolean display_get_unsigned_integer(MathEquation *display, guint64 *value);
+MPNumber *display_get_answer(MathEquation *);
+int display_get_cursor(MathEquation *);
+
+void display_set_number(MathEquation *display, const MPNumber *);
+void display_set_answer(MathEquation *display);
+void display_set_string(MathEquation *display, const char *, int);
+void display_set_cursor(MathEquation *display, int);
+void display_set_error(MathEquation *display, const char *);
+
+void display_convert(MathEquation *display, DisplayFormat format);
+
+void display_clear_stack(MathEquation *);
+void display_push(MathEquation *);
+void display_pop(MathEquation *);
+void display_unpop(MathEquation *);
+gboolean display_is_undo_step(MathEquation *display);
+
+void display_insert(MathEquation *display, int, int, const char *);
+void display_insert_number(MathEquation *display, int, int, const MPNumber *);
+void display_backspace(MathEquation *, int, int);
+void display_delete(MathEquation *, int, int);
+
+gboolean display_is_empty(MathEquation *);
+gboolean display_is_result(MathEquation *);
+gboolean display_is_usable_number(MathEquation *display, MPNumber *);
+gboolean display_is_number_with_base(MathEquation *display);
+
+void display_make_number(MathEquation *display, char *target, int target_len, const MPNumber *x);
+
+void display_do_function(MathEquation *display, int function, gpointer arg, int cursor_start, int cursor_end);
+
+#endif /* DISPLAY_H */
diff --git a/src/ui-preferences.c b/src/ui-preferences.c
index 6d59e59..f3a8d80 100644
--- a/src/ui-preferences.c
+++ b/src/ui-preferences.c
@@ -77,7 +77,7 @@ angle_unit_combobox_changed_cb(GtkWidget *combo)
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter);
gtk_tree_model_get(model, &iter, 1, &value, -1);
for (i = 0; unit_map[i].value != NULL && strcmp(unit_map[i].value, value) != 0; i++);
- display_set_angle_unit(&v->display, unit_map[i].units);
+ display_set_angle_unit(v->display, unit_map[i].units);
set_resource(R_TRIG, value);
}
@@ -110,7 +110,7 @@ display_format_combobox_changed_cb(GtkWidget *combo)
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter);
gtk_tree_model_get(model, &iter, 1, &value, -1);
for (i = 0; mode_map[i].value != NULL && strcmp(mode_map[i].value, value) != 0; i++);
- display_set_format(&v->display, mode_map[i].format);
+ display_set_format(v->display, mode_map[i].format);
set_resource(R_DISPLAY, value);
}
@@ -127,7 +127,7 @@ word_size_combobox_changed_cb(GtkWidget *combo)
model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter);
gtk_tree_model_get(model, &iter, 1, &value, -1);
- display_set_word_size(&v->display, value);
+ display_set_word_size(v->display, value);
set_int_resource(R_WORDLEN, value);
}
@@ -140,7 +140,7 @@ decimal_places_spin_change_value_cb(GtkWidget *spin)
gint value = 0;
value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
- display_set_accuracy(&v->display, value);
+ display_set_accuracy(v->display, value);
set_int_resource(R_ACCURACY, value);
}
@@ -153,7 +153,7 @@ thousands_separator_check_toggled_cb(GtkWidget *check)
gboolean value;
value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
- display_set_show_thousands_separator(&v->display, value);
+ display_set_show_thousands_separator(v->display, value);
set_boolean_resource(R_TSEP, value);
}
@@ -165,7 +165,7 @@ trailing_zeroes_check_toggled_cb(GtkWidget *check)
gboolean value;
value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
- display_set_show_trailing_zeroes(&v->display, value);
+ display_set_show_trailing_zeroes(v->display, value);
set_boolean_resource(R_ZEROES, value);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]