gcalctool r2333 - trunk/gcalctool
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2333 - trunk/gcalctool
- Date: Sun, 21 Dec 2008 09:25:01 +0000 (UTC)
Author: rancell
Date: Sun Dec 21 09:25:01 2008
New Revision: 2333
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2333&view=rev
Log:
Refactoring...
Modified:
trunk/gcalctool/calctool.c
trunk/gcalctool/calctool.h
trunk/gcalctool/ce_parser.c
trunk/gcalctool/ce_parser.y
trunk/gcalctool/display.c
trunk/gcalctool/display.h
trunk/gcalctool/functions.c
trunk/gcalctool/get.c
trunk/gcalctool/get.h
trunk/gcalctool/gtk.c
trunk/gcalctool/mp-convert.c
trunk/gcalctool/mp.c
trunk/gcalctool/register.c
trunk/gcalctool/ui.h
trunk/gcalctool/unittest.c
Modified: trunk/gcalctool/calctool.c
==============================================================================
--- trunk/gcalctool/calctool.c (original)
+++ trunk/gcalctool/calctool.c Sun Dec 21 09:25:01 2008
@@ -39,6 +39,7 @@
int basevals[4] = { 2, 8, 10, 16 };
/* Calctool variables and options. */
+static CalculatorVariables calc_state;
CalculatorVariables *v;
/* Change type to radian */
@@ -63,7 +64,7 @@
}
void
-do_trig_typeconv(enum trig_type ttype, int s1[MP_SIZE], int t1[MP_SIZE])
+do_trig_typeconv(TrigType ttype, int s1[MP_SIZE], int t1[MP_SIZE])
{
int MP1[MP_SIZE], MP2[MP_SIZE];
@@ -104,8 +105,7 @@
/*ARGSUSED*/
int
-matherr(exc)
-struct exception *exc;
+matherr(struct exception *exc)
{
// FIXME: Useless string
doerr(_("Error"));
@@ -115,80 +115,40 @@
static void
-getparam(char *s, char *argv[], char *errmes)
-{
- if (*argv != NULL && argv[0][0] != '-') {
- STRNCPY(s, *argv, MAXLINE - 1);
- } else {
- // FIXME: Useless string
- /* Translators: the following string contains two strings that
- * are passed to it: the first is the gcalctool program name and
- * the second is an error message (see the last parameter in the
- * getparam() call in the get_options() routine below.
- */
- FPRINTF(stderr, _("%s: %s as next argument.\n"), v->progname, errmes);
- exit(1);
- }
-}
-
-
-static void
usage(const char *progname)
{
/* Translators: This message is displayed on the command line when
help is requested. %1$s and $3$s are replaced with the name
of the program and %2$s with the version string */
- FPRINTF(stderr, _("%1$s version %2$s\n"
+ fprintf(stderr, _("%1$s version %2$s\n"
"\n"
- "Usage: %3$s: [-E] [-u] [-a accuracy] [-?] [-v] [-h]\n"),
+ "Usage: %3$s: [-u] [-?] [-v] [-h]\n"),
progname, VERSION, progname);
exit(1);
}
-#define INC { argc--; argv++; }
-
void
-get_options(int argc, char *argv[]) /* Extract command line options. */
+get_options(int argc, char *argv[])
{
- char next[MAXLINE]; /* The next command line parameter. */
-
- INC;
- while (argc > 0) {
- if (argv[0][0] == '-') {
- switch (argv[0][1]) {
- case 'E' : /* MP errors to stderr. */
- mp_set_show_errors(TRUE);
- break;
-
- case 'a' :
- INC;
- // FIXME: Useless string
- getparam(next, argv, _("-a needs accuracy value"));
- v->accuracy = atoi(next);
- if (v->accuracy < 0 || v->accuracy > MAXACC) {
- /* Translators: This message is displayed when an invalid accuracy value is passed
- as a command line argument. %1$s is replaced with the name of the program and %2$d
- is replaced with the maximum supported accuracy value */
- FPRINTF(stderr, _("%1$s: accuracy should be in the range 0-%2$d\n"),
- v->progname, MAXACC);
- v->accuracy = DEFAULT_ACCURACY;
- }
- break;
-
- case 'u':
- unittest();
- break;
-
- case '?' :
- case 'v' :
- case 'h' :
- usage(v->progname);
- break;
- }
- INC;
- } else {
- INC;
- }
+ int i;
+ char *arg;
+
+ for (i = 1; i < argc; i++) {
+ arg = argv[i];
+ if (arg[0] == '-' && arg[2] == '\0')
+ {
+ switch (arg[1]) {
+ case 'u':
+ unittest();
+ break;
+
+ case '?' :
+ case 'v' :
+ case 'h' :
+ usage(v->progname);
+ break;
+ }
+ }
}
}
@@ -196,51 +156,67 @@
static void
init_state(void)
{
- int acc, size;
+ int acc, size, i;
- v->accuracy = DEFAULT_ACCURACY;
- v->show_zeroes = FALSE; /* Don't show trailing zeroes. */
- v->base = DEC; /* Initial base. */
- v->dtype = FIX; /* Initial number display mode. */
- v->ttype = DEG; /* Initial trigonometric type. */
- v->modetype = BASIC; /* Initial calculator mode. */
acc = MAX_DIGITS + 12; /* MP internal accuracy. */
size = MP_SIZE;
mpset(acc, size, size);
- v->error = 0; /* No calculator error initially. */
+
+ v->error = FALSE; /* No calculator error initially. */
+ v->radix = get_radix(); /* Locale specific radix string. */
+ v->tsep = get_tsep(); /* Locale specific thousands separator. */
+ v->tsep_count = get_tsep_count();
+
+ if (get_int_resource(R_ACCURACY, &i))
+ v->accuracy = i;
+ else
+ v->accuracy = DEFAULT_ACCURACY;
+ if (v->accuracy < 0 || v->accuracy > MAXACC) {
+ /* Translators: A log message displayed when an invalid accuracy
+ is read from the configuration */
+ fprintf(stderr, _("%s: accuracy should be in the range 0-%d\n"),
+ v->progname, MAXACC);
+ v->accuracy = DEFAULT_ACCURACY;
+ }
+
+ if (get_enumerated_resource(R_BASE, Rbstr, &i))
+ v->base = (BaseType) i;
+ else
+ v->base = DEC;
+
+ if (get_enumerated_resource(R_TRIG, Rtstr, &i))
+ v->ttype = (TrigType) i;
+ else
+ v->ttype = DEG;
}
int
main(int argc, char **argv)
{
- v = (CalculatorVariables *)LINT_CAST(calloc(1, sizeof(CalculatorVariables)));
+ memset(&calc_state, 0, sizeof(calc_state));
+ v = &calc_state;
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
- v->progname = argv[0]; /* Save programs name. */
-
- srand48((long) time((time_t *) 0)); /* Seed random number generator. */
+ v->progname = argv[0];
- v->radix = get_radix(); /* Locale specific radix string. */
- v->tsep = get_tsep(); /* Locale specific thousands separator. */
- v->tsep_count = get_tsep_count();
+ /* Seed random number generator. */
+ srand48((long) time((time_t *) 0));
+
+ resources_init();
init_state();
-
- get_options(argc, argv); /* Get command line arguments. */
- resources_init(); /* Initialise configuration */
register_init();
- read_resources(); /* Read resources from merged database. */
-
- ui_init(&argc, &argv); /* Initialise UI */
display_init(&v->display);
+ ui_init(&argc, &argv);
+
+ get_options(argc, argv);
ui_load();
-
- ui_start(); /* Display the calculator. */
+ ui_start();
return(0);
}
Modified: trunk/gcalctool/calctool.h
==============================================================================
--- trunk/gcalctool/calctool.h (original)
+++ trunk/gcalctool/calctool.h Sun Dec 21 09:25:01 2008
@@ -22,53 +22,21 @@
#ifndef CALCTOOL_H
#define CALCTOOL_H
-#include <string.h>
-#include <stdlib.h>
#include <glib/gi18n.h>
#include "config.h"
#include "mp.h"
#include "display.h"
-#define FCLOSE (void) fclose /* To make lint happy. */
-#define FPRINTF (void) fprintf
-#define FPUTS (void) fputs
-#define GETHOSTNAME (void) gethostname
-#define MEMCPY (void) memcpy
-#define MEMSET (void) memset
-#define MKSTEMP (void) mkstemp
-#define REWIND (void) rewind
+/* To make lint happy. */
#define SNPRINTF (void) snprintf
-#define SSCANF (void) sscanf
-#define STRCAT (void) strcat
#define STRNCPY (void) strncpy
-#define STRNCAT (void) strncat
-#define UNLINK (void) unlink
/* Base definitions. */
-enum base_type { BIN, OCT, DEC, HEX, MAXBASES };
-
-/* Calculator modes. */
-enum mode_type { BASIC,
- ADVANCED,
- FINANCIAL,
- SCIENTIFIC,
- PROGRAMMING,
- MAXMODES };
-
-/* Number display mode. */
-enum num_type { ENG, FIX, SCI, MAXDISPMODES };
+typedef enum { BIN, OCT, DEC, HEX, MAXBASES } BaseType;
/* Trigonometric types. */
-enum trig_type { DEG, GRAD, RAD, MAXTRIGMODES };
-
-#ifndef LINT_CAST
-#ifdef lint
-#define LINT_CAST(arg) (arg ? 0 : 0)
-#else
-#define LINT_CAST(arg) (arg)
-#endif /*lint*/
-#endif /*LINT_CAST*/
+typedef enum { DEG, GRAD, RAD, MAXTRIGMODES } TrigType;
#define MAX_DIGITS 200 /* Maximum displayable number of digits. */
#define MAX_LOCALIZED (MAX_DIGITS * (1 + MB_LEN_MAX) + MB_LEN_MAX)
@@ -77,7 +45,7 @@
#ifndef MAXLINE
#define MAXLINE 512 /* Length of character strings. */
-#endif /*MAXLINE*/
+#endif
#define MAXACC 99 /* Max. number of digits after numeric point. */
@@ -87,9 +55,8 @@
#ifndef RCNAME
#define RCNAME ".gcalctoolrc"
-#endif /*RCNAME*/
+#endif
-/* Boolean definitions. */
#undef TRUE
#define TRUE 1
#undef FALSE
@@ -99,36 +66,29 @@
/* Calctool variables and options. */
typedef struct {
- char *progname; /* Name of this program. */
-
- GCDisplay display;
-
- const char *radix; /* Locale specific radix string. */
- const char *tsep; /* Locale specific thousands separator. */
- int tsep_count; /* Number of digits between separator. */
-
- int MPdisp_val[MP_SIZE]; /* Value of the current display. */
-
- enum base_type base; /* Current base: BIN, OCT, DEC or HEX. */
- enum mode_type modetype; /* Current calculator mode. */
- enum num_type dtype; /* Number display mode. */
- enum trig_type ttype; /* Trig. type (deg, grad or rad). */
-
- int accuracy; /* Number of digits precision (Max 9). */
-
- int error; /* Indicates some kind of display error. */
- int math_error; /* Math error (used in expression mode) */
- int show_tsep; /* Set if the thousands separator should be shown. */
- int show_zeroes; /* Set if trailing zeroes should be shown. */
+ char *progname; /* Name of this program. */
+
+ GCDisplay display; /* Display stack */
+
+ const char *radix; /* Locale specific radix string. */
+ const char *tsep; /* Locale specific thousands separator. */
+ int tsep_count; /* Number of digits between separator. */
+
+ BaseType base; /* Numeric base (BIN, OCT, DEC or HEX). */
+ TrigType ttype; /* Trigonometric type (DEG, GRAD or RAD). */
+ int accuracy; /* Number of digits precision. */
+
+ int error; /* true if there is a display error */
+ int math_error; /* Math error */
} CalculatorVariables;
extern CalculatorVariables *v; /* Calctool variables and options. */
-extern int basevals[]; /* Supported arithmetic bases. */
+extern int basevals[]; /* Supported arithmetic bases. */
/* Change type to radian */
void to_rad(int s1[MP_SIZE], int t1[MP_SIZE]);
-void do_trig_typeconv(enum trig_type ttype, int s1[MP_SIZE], int t1[MP_SIZE]);
+void do_trig_typeconv(TrigType ttype, int s1[MP_SIZE], int t1[MP_SIZE]);
void doerr(char *);
Modified: trunk/gcalctool/ce_parser.c
==============================================================================
--- trunk/gcalctool/ce_parser.c (original)
+++ trunk/gcalctool/ce_parser.c Sun Dec 21 09:25:01 2008
@@ -39,7 +39,7 @@
if (strlen(expression)) {
parser_state.i = 0;
parser_state.buff = strdup(expression);
- v->math_error = 0;
+ v->math_error = 0;
ret = ceparse();
free(parser_state.buff);
}
@@ -53,9 +53,9 @@
return -EINVAL;
}
- if (v->math_error) {
- return v->math_error;
- }
+ if (v->math_error) {
+ return v->math_error;
+ }
if (flags & ANS) {
memcpy(result, parser_state.ret, sizeof(int)*MP_SIZE);
Modified: trunk/gcalctool/ce_parser.y
==============================================================================
--- trunk/gcalctool/ce_parser.y (original)
+++ trunk/gcalctool/ce_parser.y Sun Dec 21 09:25:01 2008
@@ -114,8 +114,7 @@
udf:
value '=' {
- cp($1, v->MPdisp_val);
- display_set_number(&v->display, v->MPdisp_val);
+ display_set_number(&v->display, $1);
}
| value '=' tSTO '(' tNUMBER ')' {
int val = mp_cast_to_int($5);
@@ -126,8 +125,7 @@
register_set(val, $1);
}
| tCLR {
- display_reset(&v->display);
- display_set_number(&v->display, v->MPdisp_val);
+ display_clear(&v->display);
}
;
Modified: trunk/gcalctool/display.c
==============================================================================
--- trunk/gcalctool/display.c (original)
+++ trunk/gcalctool/display.c Sun Dec 21 09:25:01 2008
@@ -26,12 +26,15 @@
#include "display.h"
+#include "get.h"
#include "mp.h"
#include "functions.h"
#include "ui.h"
#include "ce_parser.h" // For ce_parse()
#include "register.h"
+static const char *display_types[] = { "ENG", "FIX", "SCI", NULL };
+
static GCDisplayState *
get_state(GCDisplay *display)
{
@@ -125,7 +128,7 @@
}
}
- if (!v->show_tsep) {
+ if (!v->display.show_tsep) {
STRNCPY(dest, clean->str, dest_length - 1);
g_string_free(clean, TRUE);
return;
@@ -184,25 +187,18 @@
void
display_clear(GCDisplay *display)
{
+ v->error = 0;
display_set_string(display, "", -1);
}
-void
-display_reset(GCDisplay *display)
-{
- v->error = 0; /* Currently no display error. */
- mp_set_from_integer(0, v->MPdisp_val);
-
- display_clear(display);
-}
-
static const char *
display_get_text(GCDisplay *display)
{
return get_state(display)->expression;
}
+
gboolean display_get_integer(GCDisplay *display, gint64 *value)
{
const char *text;
@@ -215,7 +211,7 @@
text = "0";
}
else if (display_is_result(display)) {
- display_make_number(buf, MAX_DISPLAY, display_get_answer(display), v->base, FALSE);
+ display_make_number(display, buf, MAX_DISPLAY, display_get_answer(display), v->base, FALSE);
text = buf;
}
@@ -225,6 +221,7 @@
return TRUE;
}
+
gboolean display_get_unsigned_integer(GCDisplay *display, guint64 *value)
{
const char *text;
@@ -237,7 +234,7 @@
text = "0";
}
else if (display_is_result(display)) {
- display_make_number(buf, MAX_DISPLAY, display_get_answer(display), v->base, FALSE);
+ display_make_number(display, buf, MAX_DISPLAY, display_get_answer(display), v->base, FALSE);
text = buf;
}
@@ -251,25 +248,67 @@
return TRUE;
}
+
int *display_get_answer(GCDisplay *display)
{
return get_state(display)->ans;
}
+
int
display_get_cursor(GCDisplay *display)
{
return get_state(display)->cursor;
}
+
void
display_set_number(GCDisplay *display, const int *MPval)
{
char text[MAX_DISPLAY];
- display_make_number(text, MAX_DISPLAY, MPval, v->base, FALSE);
+ display_make_number(display, text, MAX_DISPLAY, MPval, v->base, FALSE);
display_set_string(display, text, -1);
}
+
+static void
+display_refresh(GCDisplay *display)
+{
+ int i, MP_reg[MP_SIZE];
+ char localized[MAX_LOCALIZED], *str, reg[3], *t;
+ GCDisplayState *e;
+ char x[MAX_LOCALIZED], xx[MAX_LOCALIZED], ans[MAX_LOCALIZED];
+ int cursor = display_get_cursor(display);
+
+ e = get_state(display);
+ if (display_is_empty(display)) {
+ mp_set_from_integer(0, MP_reg);
+ display_make_number(display, x, MAX_LOCALIZED, MP_reg, v->base, FALSE);
+ str = x;
+ } else {
+ str = strdup(e->expression);
+ }
+
+ /* Substitute answer register */
+ display_make_number(display, ans, MAX_LOCALIZED, e->ans, v->base, TRUE);
+ localize_expression(localized, ans, MAX_LOCALIZED, &cursor);
+ str = str_replace(str, "Ans", localized);
+
+ /* Replace registers with values. */
+ for (i = 0; i < 10; i++) {
+ SNPRINTF(reg, 3, "R%d", i);
+ register_get(i, MP_reg);
+ display_make_number(display, xx, MAX_LOCALIZED, MP_reg, v->base, FALSE);
+ t = str_replace(str, reg, xx);
+ free(str);
+ str = t;
+ }
+
+ ui_set_display(str, cursor);
+ free(str);
+}
+
+
void
display_set_string(GCDisplay *display, const char *value, int cursor)
{
@@ -279,6 +318,8 @@
free(e->expression);
e->expression = strdup(value);
e->cursor = cursor;
+
+ display_refresh(display);
}
void
@@ -288,6 +329,7 @@
e = get_state(display);
e->cursor = cursor;
+ display_refresh(display);
}
void
@@ -296,13 +338,15 @@
ui_set_statusbar(message, "gtk-dialog-error");
}
+
static void
copy_state(GCDisplayState *dst, GCDisplayState *src)
{
- MEMCPY(dst, src, sizeof(GCDisplayState));
+ memcpy(dst, src, sizeof(GCDisplayState));
dst->expression = strdup(src->expression);
}
+
static void
update_undo_redo_button_sensitivity(GCDisplay *display)
{
@@ -320,6 +364,7 @@
ui_set_undo_enabled(undo, redo);
}
+
void display_clear_stack(GCDisplay *display)
{
int i = display->h.begin;
@@ -334,6 +379,7 @@
update_undo_redo_button_sensitivity(display);
}
+
void display_push(GCDisplay *display)
{
int c;
@@ -362,6 +408,7 @@
update_undo_redo_button_sensitivity(display);
}
+
void display_pop(GCDisplay *display)
{
if (display->h.current != display->h.begin) {
@@ -375,6 +422,7 @@
display_refresh(display);
}
+
void
display_unpop(GCDisplay *display)
{
@@ -385,8 +433,11 @@
ui_set_statusbar(_("No redo steps"), "gtk-dialog-warning");
}
update_undo_redo_button_sensitivity(display);
+ get_state(display)->cursor = -1;
+ display_refresh(display);
}
+
gboolean
display_is_undo_step(GCDisplay *display)
{
@@ -394,10 +445,9 @@
}
void
-display_insert(GCDisplay *display, const char *text)
+display_insert(GCDisplay *display, int cursor, const char *text)
{
char buf[MAX_DISPLAY], *currentText;
- int cursor = display_get_cursor(display);
if (cursor < 0) {
SNPRINTF(buf, MAX_DISPLAY, "%s%s", display_get_text(display), text);
@@ -410,11 +460,11 @@
}
void
-display_insert_number(GCDisplay *display, const int value[MP_SIZE])
+display_insert_number(GCDisplay *display, int cursor, const int value[MP_SIZE])
{
char text[MAX_DISPLAY];
- display_make_number(text, MAX_DISPLAY, value, v->base, FALSE);
- display_insert(display, text);
+ display_make_number(display, text, MAX_DISPLAY, value, v->base, FALSE);
+ display_insert(display, cursor, text);
}
@@ -430,7 +480,7 @@
/* If cursor is at end of the line then delete the last character preserving accuracy */
if (cursor < 0) {
if (exp_has_postfix(e->expression, "Ans")) {
- display_make_number(buf, MAX_DISPLAY, e->ans, v->base, FALSE);
+ display_make_number(display, buf, MAX_DISPLAY, e->ans, v->base, FALSE);
t = str_replace(e->expression, "Ans", buf);
free(e->expression);
e->expression = t;
@@ -439,7 +489,7 @@
SNPRINTF(buf, MAX_DISPLAY, "R%d", i);
if (exp_has_postfix(e->expression, buf)) {
register_get(i, MP_reg);
- display_make_number(buf2, MAX_DISPLAY, MP_reg, v->base, FALSE);
+ display_make_number(display, buf2, MAX_DISPLAY, MP_reg, v->base, FALSE);
/* Remove "Rx" postfix and replace with backspaced number */
SNPRINTF(buf, MAX_DISPLAY, "%.*s%s", strlen(e->expression) - 2, e->expression - 3, buf2);
display_set_string(display, buf, cursor - 1);
@@ -481,45 +531,6 @@
display_set_string(display, buffer, -1);
}
-/* In arithmetic precedence mode this routine should be called to redraw
- * the display.
- */
-void
-display_refresh(GCDisplay *display)
-{
- int i, MP_reg[MP_SIZE];
- char localized[MAX_LOCALIZED], *str, reg[3], *t;
- GCDisplayState *e;
- char x[MAX_LOCALIZED], xx[MAX_LOCALIZED], ans[MAX_LOCALIZED];
- int cursor = display_get_cursor(display);
-
- e = get_state(display);
- if (display_is_empty(display)) {
- mp_set_from_integer(0, MP_reg);
- display_make_number(x, MAX_LOCALIZED, MP_reg, v->base, FALSE);
- str = x;
- } else {
- str = strdup(e->expression);
- }
-
- /* Substitute answer register */
- display_make_number(ans, MAX_LOCALIZED, e->ans, v->base, TRUE);
- localize_expression(localized, ans, MAX_LOCALIZED, &cursor);
- str = str_replace(str, "Ans", localized);
-
- /* Replace registers with values. */
- for (i = 0; i < 10; i++) {
- SNPRINTF(reg, 3, "R%d", i);
- register_get(i, MP_reg);
- display_make_number(xx, MAX_LOCALIZED, MP_reg, v->base, FALSE);
- t = str_replace(str, reg, xx);
- free(str);
- str = t;
- }
-
- ui_set_display(str, cursor);
- free(str);
-}
gboolean
display_is_empty(GCDisplay *display)
@@ -546,16 +557,79 @@
}
}
+
void
display_init(GCDisplay *display)
{
int i;
+
+ memset(display, 0, sizeof(GCDisplay));
+
+ display->base = 10;
+
+ if (get_boolean_resource(R_ZEROES, &i))
+ display->show_zeroes = i;
+ else
+ display->show_zeroes = FALSE;
+
+ if (get_boolean_resource(R_TSEP, &i))
+ display->show_tsep = i;
+ else
+ display->show_tsep = FALSE;
+
+ if (get_enumerated_resource(R_DISPLAY, display_types, &i))
+ display->format = (DisplayFormat) i;
+ else
+ display->format = FIX;
- memset(&(display->h), 0, sizeof(GCDisplayHistory)); /* clear expression mode state history */
for (i = 0; i < UNDO_HISTORY_LENGTH; i++)
display->h.e[i].expression = strdup("");
}
+
+void display_set_accuracy(GCDisplay *display, int accuracy)
+{
+ set_int_resource(R_ACCURACY, accuracy);
+ get_state(display)->cursor = -1;
+ display_refresh(display);
+}
+
+
+void display_set_show_thousands_separator(GCDisplay *display, gboolean visible)
+{
+ display->show_tsep = visible;
+ set_boolean_resource(R_TSEP, visible);
+ display_set_cursor(display, -1);
+ display_refresh(display);
+}
+
+
+void display_set_show_trailing_zeroes(GCDisplay *display, gboolean visible)
+{
+ display->show_zeroes = visible;
+ set_boolean_resource(R_ZEROES, visible);
+ get_state(display)->cursor = -1;
+ display_refresh(display);
+}
+
+
+void display_set_base(GCDisplay *display, int base)
+{
+ display->base = base;
+ get_state(display)->cursor = -1;
+ display_refresh(display);
+}
+
+
+void display_set_format(GCDisplay *display, DisplayFormat type)
+{
+ v->display.format = type;
+ set_enumerated_resource(R_DISPLAY, display_types, (int) type);
+ get_state(display)->cursor = -1;
+ display_refresh(display);
+}
+
+
int
display_solve(GCDisplay *display, int *result)
{
@@ -586,7 +660,7 @@
/* Convert engineering or scientific number in the given base. */
void
-make_eng_sci(char *target, int target_len, const int *MPnumber, int base)
+make_eng_sci(GCDisplay *display, char *target, int target_len, const int *MPnumber, int base)
{
static char digits[] = "0123456789ABCDEF";
char fixed[MAX_DIGITS], *optr;
@@ -598,7 +672,7 @@
int eng = 0; /* Set if this is an engineering number. */
int exp = 0; /* Exponent */
- if (v->dtype == ENG) {
+ if (display->format == ENG) {
eng = 1;
}
optr = target;
@@ -681,7 +755,7 @@
/* Convert MP number to character string in the given base. */
void
-display_make_number(char *target, int target_len, const int *MPnumber, int base, int ignoreError)
+display_make_number(GCDisplay *display, char *target, int target_len, const int *MPnumber, int base, int ignoreError)
{
static double max_fix[MAXBASES] = {
1.298074214e+33, /* Binary. */
@@ -708,10 +782,10 @@
return;
}
// FIXME: Do this based on the number of digits, not actual values
- if ((v->dtype == ENG) ||
- (v->dtype == SCI) ||
- (v->dtype == FIX && val != 0.0 && (val > max_fix[base]))) {
- make_eng_sci(target, target_len, MPnumber, base);
+ 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);
} else {
mp_cast_to_string(target, target_len, MPnumber, basevals[base], v->accuracy);
}
Modified: trunk/gcalctool/display.h
==============================================================================
--- trunk/gcalctool/display.h (original)
+++ trunk/gcalctool/display.h Sun Dec 21 09:25:01 2008
@@ -44,27 +44,37 @@
GCDisplayState e[UNDO_HISTORY_LENGTH]; /* Expression mode state */
} GCDisplayHistory;
+/* Number display mode. */
+typedef enum { ENG, FIX, SCI, MAXDISPMODES } DisplayFormat;
+
typedef struct
{
- GCDisplayHistory h; /* History of expression mode states */
+ GCDisplayHistory 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 base;
} GCDisplay;
void display_init(GCDisplay *);
+void display_set_accuracy(GCDisplay *display, int accuracy);
+void display_set_show_thousands_separator(GCDisplay *display, gboolean visible);
+void display_set_show_trailing_zeroes(GCDisplay *display, gboolean visible);
+void display_set_base(GCDisplay *display, int base);
+void display_set_format(GCDisplay *display, DisplayFormat format);
-void display_reset(GCDisplay *);
void localize_expression(char *, const char *, int, int *);
void display_clear(GCDisplay *);
-void display_refresh(GCDisplay *);
gboolean display_get_integer(GCDisplay *display, gint64 *value);
gboolean display_get_unsigned_integer(GCDisplay *display, guint64 *value);
int *display_get_answer(GCDisplay *);
int display_get_cursor(GCDisplay *);
-void display_set_number(GCDisplay *, const int *);
-void display_set_string(GCDisplay *, const char *, int);
-void display_set_cursor(GCDisplay *, int);
-void display_set_error(GCDisplay *, const char *);
+void display_set_number(GCDisplay *display, const int *);
+void display_set_string(GCDisplay *display, const char *, int);
+void display_set_cursor(GCDisplay *display, int);
+void display_set_error(GCDisplay *display, const char *);
void display_clear_stack(GCDisplay *);
void display_push(GCDisplay *);
@@ -72,18 +82,18 @@
void display_unpop(GCDisplay *);
gboolean display_is_undo_step(GCDisplay *display);
-void display_insert(GCDisplay *, const char *);
-void display_insert_number(GCDisplay *display, const int *);
+void display_insert(GCDisplay *display, int, const char *);
+void display_insert_number(GCDisplay *display, int, const int *);
void display_backspace(GCDisplay *);
void display_delete(GCDisplay *);
-void display_surround(GCDisplay *, const char *, const char *);
+void display_surround(GCDisplay *display, const char *, const char *);
gboolean display_is_empty(GCDisplay *);
gboolean display_is_result(GCDisplay *);
-gboolean display_is_usable_number(GCDisplay *, int *);
+gboolean display_is_usable_number(GCDisplay *display, int *);
-int display_solve(GCDisplay *, int *);
+int display_solve(GCDisplay *display, int *);
-void display_make_number(char *target, int target_len, const int *MPnumber, int base, int ignoreError);
+void display_make_number(GCDisplay *display, char *target, int target_len, const int *MPnumber, int base, int ignoreError);
#endif /* DISPLAY_H */
Modified: trunk/gcalctool/functions.c
==============================================================================
--- trunk/gcalctool/functions.c (original)
+++ trunk/gcalctool/functions.c Sun Dec 21 09:25:01 2008
@@ -36,16 +36,16 @@
#include "ce_parser.h"
#include "ui.h"
-enum button_flags {
+typedef enum {
NUMBER = (1 << 3), /* Number button */
FUNC = (1 << 6), /* Function */
PREFIXOP = (1 << 15), /* Unary prefix operation */
-};
+} ButtonFlags;
typedef struct {
int id;
char *symname; /* Expression function name */
- enum button_flags flags; /* Misc flags */
+ ButtonFlags flags; /* Misc flags */
} Function;
// FIXME: Sort this list
@@ -156,12 +156,10 @@
{
v->accuracy = value;
set_int_resource(R_ACCURACY, v->accuracy);
+ display_set_accuracy(&v->display, value);
ui_set_accuracy(v->accuracy);
ui_make_registers();
clear_undo_history();
-
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
}
@@ -198,15 +196,12 @@
mp_shift(MPval, display_get_answer(&v->display), count);
display_set_string(&v->display, "Ans", -1);
}
-
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
}
/* Change the current base setting. */
static void
-do_base(enum base_type b)
+do_base(BaseType b)
{
int ret, MP[MP_SIZE];
@@ -220,13 +215,11 @@
display_set_string(&v->display, "Ans", -1);
}
v->base = b;
- set_resource(R_BASE, Rbstr[(int) v->base]);
+ set_enumerated_resource(R_BASE, Rbstr, (int) v->base);
+ display_set_base(&v->display, basevals[v->base]);
ui_set_base(v->base);
ui_make_registers();
clear_undo_history();
-
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
}
@@ -245,17 +238,13 @@
register_set(index, MPexpr);
mp_set_from_mp(MPtemp, display_get_answer(&v->display));
display_set_string(&v->display, "Ans", -1);
- display_refresh(&v->display);
ui_make_registers();
}
-
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
}
static void
-do_numtype(enum num_type n) /* Set number display type. */
+do_numtype(DisplayFormat n) /* Set number display type. */
{
int ret, MP[MP_SIZE];
@@ -269,12 +258,8 @@
}
clear_undo_history();
- v->dtype = n;
- set_resource(R_DISPLAY, Rdstr[(int) v->dtype]);
+ display_set_format(&v->display, n);
ui_make_registers();
-
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
}
@@ -283,10 +268,9 @@
{
int temp[MP_SIZE];
- 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
register_set(index, temp);
@@ -351,7 +335,7 @@
case FN_SET_TRIG_TYPE:
v->ttype = arg;
- set_resource(R_TRIG, Rtstr[arg]);
+ set_enumerated_resource(R_TRIG, Rtstr, arg);
return;
case FN_SET_NUMBERTYPE:
@@ -372,11 +356,11 @@
case FN_RECALL:
SNPRINTF(buf, MAXLINE, "R%d", arg);
- display_insert(&v->display, buf);
+ display_insert(&v->display, display_get_cursor(&v->display), buf);
break;
case FN_CONSTANT:
- display_insert_number(&v->display, constant_get_value(arg));
+ display_insert_number(&v->display, display_get_cursor(&v->display), constant_get_value(arg));
break;
case FN_BACKSPACE:
@@ -468,7 +452,7 @@
break;
case FN_NUMERIC_POINT:
- display_insert(&v->display, v->radix);
+ display_insert(&v->display, display_get_cursor(&v->display), v->radix);
break;
default:
@@ -479,16 +463,14 @@
} else {
if (functions[function].flags & FUNC) {
SNPRINTF(buf, MAXLINE, "%s(", functions[function].symname);
- display_insert(&v->display, buf);
+ display_insert(&v->display, display_get_cursor(&v->display), buf);
} else {
- display_insert(&v->display, functions[function].symname);
+ display_insert(&v->display, display_get_cursor(&v->display), functions[function].symname);
}
}
break;
}
- display_refresh(&v->display);
-
enabled = display_get_unsigned_integer(&v->display, &bit_value);
ui_set_bitfield(enabled, bit_value);
}
Modified: trunk/gcalctool/get.c
==============================================================================
--- trunk/gcalctool/get.c (original)
+++ trunk/gcalctool/get.c Sun Dec 21 09:25:01 2008
@@ -40,11 +40,8 @@
/* Various string values read/written as X resources. */
-const char *Rbstr[MAXBASES] = { "BIN", "OCT", "DEC", "HEX" };
-const char *Rdstr[MAXDISPMODES] = { "ENG", "FIX", "SCI" };
-const char *Rmstr[MAXMODES] = { "BASIC", "ADVANCED", "FINANCIAL",
- "SCIENTIFIC", "PROGRAMMING" };
-const char *Rtstr[MAXTRIGMODES] = { "DEG", "GRAD", "RAD" };
+const char *Rbstr[] = { "BIN", "OCT", "DEC", "HEX", NULL };
+const char *Rtstr[] = { "DEG", "GRAD", "RAD", NULL };
static GConfClient *client = NULL;
@@ -87,25 +84,24 @@
}
-char *
-convert(const char *line) /* Convert .gcalctoolcf line to ascii values. */
+void set_enumerated_resource(const char *key, const char *values[], int value)
{
- static char output[MAXLINE]; /* Converted output record. */
- int i; /* Position within input line. */
- int len;
- int n = 0; /* Position within output line. */
-
- len = strlen(line);
- for (i = 0; i < len; i++) {
- if (line[i] == ' ') {
- continue;
- } else {
- output[n++] = line[i];
- }
- }
- output[n] = '\0';
+ set_resource(key, values[value]);
+}
+
- return(output);
+int
+get_int_resource(const char *key, int *intval)
+{
+ char *val;
+
+ val = get_resource(key);
+ if (!val)
+ return(FALSE);
+ *intval = atoi(val);
+
+ g_free(val);
+ return(TRUE);
}
@@ -115,10 +111,9 @@
char *val, tempstr[MAXLINE];
int len, n;
- if ((val = get_resource(key)) == NULL) {
- g_free(val);
- return(0);
- }
+ val = get_resource(key);
+ if (!val)
+ return(FALSE);
STRNCPY(tempstr, val, MAXLINE - 1);
g_free(val);
len = strlen(tempstr);
@@ -133,25 +128,27 @@
*boolval = FALSE;
}
- return(1);
+ return(TRUE);
}
-/* Get integer resource from database. */
-
int
-get_int_resource(const char *key, int *intval)
+get_enumerated_resource(const char *key, const char *values[], int *value)
{
char *val;
-
- if ((val = get_resource(key)) == NULL) {
- g_free(val);
- return(0);
- }
- *intval = atoi(val);
+ int i;
- g_free(val);
- return(1);
+ val = get_resource(key);
+ if (!val)
+ return(FALSE);
+
+ for (i = 0; values[i]; i++)
+ if (strcmp(values[i], val) == 0) {
+ *value = i;
+ return(TRUE);
+ }
+
+ return(FALSE);
}
@@ -177,31 +174,6 @@
}
-/* Get a string resource from database. */
-
-static int
-get_str_resource(const char *key, char *strval)
-{
- char *val;
- int i, len;
-
- if ((val = get_resource(key)) == NULL) {
- g_free(val);
- return(0);
- }
- STRNCPY(strval, val, MAXLINE - 1);
- g_free(val);
- len = strlen(strval);
- for (i = 0; i < len; i++) {
- if (islower((int) strval[i])) {
- strval[i] = toupper((int) strval[i]);
- }
- }
-
- return(1);
-}
-
-
/* Return the thousands separator string. For most locales, this is a
* comma.
*/
@@ -232,109 +204,7 @@
void
-read_resources() /* Read all possible resources from the database. */
-{
- int boolval, i, intval;
- char key[MAXLINE], str[MAXLINE];
-
- if (get_int_resource(R_ACCURACY, &intval)) {
- v->accuracy = intval;
- if (v->accuracy < 0 || v->accuracy > MAXACC) {
- /* Translators: A log message displayed when an invalid accuracy
- is read from the configuration */
- FPRINTF(stderr, _("%s: accuracy should be in the range 0-%d\n"),
- v->progname, MAXACC);
- v->accuracy = 9;
- }
- }
-
- for (i = 0; i < MAX_REGISTERS; i++) {
- SNPRINTF(key, MAXLINE, "register%d", i);
- if (get_str_resource(key, str)) {
- int temp[MP_SIZE];
- mp_set_from_string(str, 10, temp);
- register_set(i, temp);
- }
- }
-
- if (get_str_resource(R_BASE, str)) {
- for (i = 0; i < MAXBASES; i++) {
- if (EQUAL(str, Rbstr[i])) {
- break;
- }
- }
-
- if (i == MAXBASES) {
- /* Translators: A log message displayed when an invalid
- base is read from the configuration */
- FPRINTF(stderr, _("%s: base should be 2, 8, 10 or 16\n"),
- v->progname);
- } else {
- v->base = (enum base_type) i;
- }
- }
-
- if (get_str_resource(R_DISPLAY, str)) {
- for (i = 0; i < MAXDISPMODES; i++) {
- if (EQUAL(str, Rdstr[i])) {
- break;
- }
- }
-
- if (i == MAXDISPMODES) {
- /* Translators: A log message displayed when an invalid
- display mode is read from the configuration */
- FPRINTF(stderr, _("%s: invalid display mode [%s]\n"),
- v->progname, str);
- } else {
- v->dtype = (enum num_type) i;
- }
- }
-
- if (get_str_resource(R_MODE, str)) {
- for (i = 0; i < MAXMODES; i++) {
- if (EQUAL(str, Rmstr[i])) {
- break;
- }
- }
-
- if (i == MAXMODES) {
- /* Translators: This message is a log message displayed when
- an invalid mode is read from the configuration */
- FPRINTF(stderr, _("%s: invalid mode [%s]\n"), v->progname, str);
- } else {
- v->modetype = (enum mode_type) i;
- }
- }
-
- if (get_str_resource(R_TRIG, str)) {
- for (i = 0; i < MAXTRIGMODES; i++) {
- if (EQUAL(str, Rtstr[i])) {
- break;
- }
- }
-
- if (i == MAXTRIGMODES) {
- /* Translators: This message is a log message displayed when
- an invalid trigonometric mode is read from the configuration */
- FPRINTF(stderr, _("%s: invalid trigonometric mode [%s]\n"),
- v->progname, str);
- } else {
- v->ttype = (enum trig_type) i;
- }
- }
-
- if (get_boolean_resource(R_ZEROES, &boolval)) {
- v->show_zeroes = boolval;
- }
-
- if (get_boolean_resource(R_TSEP, &boolval)) {
- v->show_tsep = boolval;
- }
-}
-
-void
-resources_init() /* Load gconf configuration database for gcalctool. */
+resources_init()
{
assert(client == NULL);
client = gconf_client_get_default();
Modified: trunk/gcalctool/get.h
==============================================================================
--- trunk/gcalctool/get.h (original)
+++ trunk/gcalctool/get.h Sun Dec 21 09:25:01 2008
@@ -35,23 +35,20 @@
#define R_XPOS "xposition"
#define R_YPOS "yposition"
-extern const char *Rbstr[]; /* Base mode X resource strings. */
-extern const char *Rdstr[]; /* Display mode X resource strings. */
-extern const char *Rmstr[]; /* Mode mode X resource strings. */
-extern const char *Rtstr[]; /* Trig mode X resource strings. */
-extern const char *Rsstr[]; /* Syntax resource strings. */
+extern const char *Rbstr[];
+extern const char *Rtstr[];
void resources_init();
-void read_resources();
-char *convert(const char *);
void set_resource(const char *key, const char *value);
void set_int_resource(const char *key, int value);
void set_boolean_resource(const char *key, int value);
+void set_enumerated_resource(const char *key, const char *values[], int value);
char *get_resource(const char *key);
int get_int_resource(const char *key, int *value);
int get_boolean_resource(const char *key, int *value);
+int get_enumerated_resource(const char *key, const char *values[], int *value);
const char *get_radix();
const char *get_tsep();
Modified: trunk/gcalctool/gtk.c
==============================================================================
--- trunk/gcalctool/gtk.c (original)
+++ trunk/gcalctool/gtk.c Sun Dec 21 09:25:01 2008
@@ -44,6 +44,9 @@
#include "get.h"
#include "register.h"
+static const char *mode_names[] = { "BASIC", "ADVANCED", "FINANCIAL",
+ "SCIENTIFIC", "PROGRAMMING", NULL };
+
#define MAX_ACCELERATORS 8
struct button_widget {
int function;
@@ -444,14 +447,17 @@
#define MAXBITS 64 /* Bit panel: number of bit fields. */
#define GET_WIDGET(name) \
- glade_xml_get_widget(X->ui, (name))
+ glade_xml_get_widget(X.ui, (name))
-#define CONNECT_SIGNAL(name) glade_xml_signal_connect(X->ui, #name, \
+#define CONNECT_SIGNAL(name) glade_xml_signal_connect(X.ui, #name, \
G_CALLBACK(name))
-struct Xobject { /* Gtk+/Xlib graphics object. */
+/* Gtk+/Xlib graphics object. */
+typedef struct {
GdkAtom clipboard_atom;
GdkAtom primary_atom;
+
+ ModeType mode; /* Current calculator mode. */
GladeXML *ui;
GladeXML *financial;
@@ -504,16 +510,15 @@
GtkWidget *memory_exchange_labels[MAX_REGISTERS];
/* Scientific mode widgets */
- GtkWidget *hyperbolic_toggle; /* Hyperbolic mode. */
- GtkWidget *inverse_toggle; /* Inverse mode. */
+ GtkWidget *hyperbolic_toggle; /* Hyperbolic mode. */
+ GtkWidget *inverse_toggle; /* Inverse mode. */
GtkWidget *base[MAXBASES]; /* Numeric base radio buttons. */
GtkWidget *disp[MAXDISPMODES]; /* Numeric display mode. */
GtkWidget *trig[MAXTRIGMODES]; /* Trigonometric mode. */
char *shelf; /* PUT selection shelf contents. */
-};
-
-typedef struct Xobject *XVars;
+} GtkUI;
+static GtkUI X;
enum {
COLUMN_NUMBER,
@@ -523,22 +528,8 @@
NUM_COLUMNS
};
-static XVars X;
-
static void setup_finc_dialogs ();
-/* FIXME: Move this into display.c (reset_display) */
-static void
-reset_display(void)
-{
- int *ans;
-
- ans = display_get_answer(&v->display);
- mp_set_from_integer(0, ans);
- display_clear(&v->display);
-}
-
-
void
ui_set_accuracy(int accuracy)
{
@@ -562,17 +553,13 @@
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE);
}
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(X->precision_spin),
- (double)accuracy);
-
- set_int_resource(R_ACCURACY, accuracy);
-
- ui_make_registers();
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(X.precision_spin), (double)accuracy);
/* Hide the manual dialog */
- gtk_widget_hide(X->spframe);
+ gtk_widget_hide(X.spframe);
+
+ /* Rebuild registers with new format */
+ ui_make_registers();
}
@@ -687,7 +674,7 @@
int index = 0;
- if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(X->inverse_toggle))) {
+ if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(X.inverse_toggle))) {
index |= 0x1;
}
@@ -720,7 +707,7 @@
"calc_function",
GINT_TO_POINTER(x_pow_y_functions[index]));
- if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(X->hyperbolic_toggle))) {
+ if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(X.hyperbolic_toggle))) {
index |= 0x2;
}
@@ -748,16 +735,16 @@
void
-ui_set_trigonometric_mode(enum trig_type mode)
+ui_set_trigonometric_mode(TrigType mode)
{
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X->trig[mode]), 1);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X.trig[mode]), 1);
}
void
-ui_set_numeric_mode(enum base_type mode)
+ui_set_numeric_mode(BaseType mode)
{
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X->disp[mode]), 1);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X.disp[mode]), 1);
}
@@ -765,16 +752,13 @@
ui_set_show_thousands_separator(gboolean visible)
{
GtkWidget *menu;
-
- v->show_tsep = visible;
- set_boolean_resource(R_TSEP, v->show_tsep);
+
+ display_set_show_thousands_separator(&v->display, visible);
menu = GET_WIDGET("show_thousands_separator_menu");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), visible);
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
-
+ /* Rebuild registers */
ui_make_registers();
}
@@ -783,13 +767,10 @@
ui_set_show_trailing_zeroes(gboolean visible)
{
GtkWidget *menu;
+
+ display_set_show_trailing_zeroes(&v->display, visible);
- v->show_zeroes = visible;
- set_boolean_resource(R_ZEROES, visible);
-
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
-
+ /* Rebuild registers */
ui_make_registers();
menu = GET_WIDGET("show_trailing_zeroes_menu");
@@ -816,7 +797,7 @@
char *display = DisplayString(dpy);
char *scanner = display;
- GETHOSTNAME(hostname, MAXHOSTNAMELEN);
+ gethostname(hostname, MAXHOSTNAMELEN);
while (*scanner) {
scanner++;
@@ -848,8 +829,8 @@
ui_get_display(void)
{
GtkTextIter start, end;
- gtk_text_buffer_get_bounds(X->display_buffer, &start, &end);
- return (gtk_text_buffer_get_text(X->display_buffer,
+ gtk_text_buffer_get_bounds(X.display_buffer, &start, &end);
+ return (gtk_text_buffer_get_text(X.display_buffer,
&start,
&end,
FALSE));
@@ -860,10 +841,10 @@
get_cursor(void)
{
gint pos;
- g_object_get(G_OBJECT(X->display_buffer), "cursor-position", &pos, NULL);
+ g_object_get(G_OBJECT(X.display_buffer), "cursor-position", &pos, NULL);
/* Convert the last position to -1 */
- if (pos == gtk_text_buffer_get_char_count(X->display_buffer)) {
+ if (pos == gtk_text_buffer_get_char_count(X.display_buffer)) {
return (-1);
} else {
return (pos);
@@ -876,14 +857,14 @@
int i;
const gchar *label;
- gtk_widget_set_sensitive(X->bit_panel, enabled);
+ gtk_widget_set_sensitive(X.bit_panel, enabled);
for (i = 0; i < MAXBITS; i++) {
if (bits & (1LL << (MAXBITS-i-1)))
label = " 1";
else
label = " 0";
- gtk_label_set_text(GTK_LABEL(X->bits[i]), label);
+ gtk_label_set_text(GTK_LABEL(X.bits[i]), label);
}
}
@@ -895,23 +876,23 @@
static void
do_finc(char* dialog)
{
- if (X->financial == NULL) {
+ if (X.financial == NULL) {
setup_finc_dialogs();
}
- gtk_dialog_run(GTK_DIALOG(glade_xml_get_widget(X->financial, dialog)));
- gtk_widget_hide(GTK_WIDGET(glade_xml_get_widget(X->financial, dialog)));
+ gtk_dialog_run(GTK_DIALOG(glade_xml_get_widget(X.financial, dialog)));
+ gtk_widget_hide(GTK_WIDGET(glade_xml_get_widget(X.financial, dialog)));
}
void
-ui_set_mode(enum mode_type mode)
+ui_set_mode(ModeType mode)
{
GtkRequisition *r;
gint w, h;
char *hostname, title[MAXLINE];
GtkWidget *menu;
- if (v->modetype != mode) {
- v->modetype = mode;
+ if (X.mode != mode) {
+ X.mode = mode;
ui_set_base(DEC);
ui_set_numeric_mode(FIX);
@@ -922,20 +903,20 @@
}
/* Save mode */
- set_resource(R_MODE, Rmstr[(int)mode]);
+ set_enumerated_resource(R_MODE, mode_names, (int)mode);
/* Show/enable the widgets used in this mode */
- g_object_set(G_OBJECT(X->bas_panel), "visible", mode == BASIC, NULL);
- g_object_set(G_OBJECT(X->adv_panel), "visible", mode != BASIC, NULL);
- g_object_set(G_OBJECT(X->fin_panel), "visible", mode == FINANCIAL, NULL);
- g_object_set(G_OBJECT(X->sci_mode_panel), "visible",
+ g_object_set(G_OBJECT(X.bas_panel), "visible", mode == BASIC, NULL);
+ g_object_set(G_OBJECT(X.adv_panel), "visible", mode != BASIC, NULL);
+ g_object_set(G_OBJECT(X.fin_panel), "visible", mode == FINANCIAL, NULL);
+ g_object_set(G_OBJECT(X.sci_mode_panel), "visible",
mode == SCIENTIFIC, NULL);
- g_object_set(G_OBJECT(X->prog_mode_panel), "visible",
+ g_object_set(G_OBJECT(X.prog_mode_panel), "visible",
mode == PROGRAMMING, NULL);
- g_object_set(G_OBJECT(X->sci_panel), "visible", mode == SCIENTIFIC, NULL);
- g_object_set(G_OBJECT(X->prog_panel), "visible",
+ 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);
+ g_object_set(G_OBJECT(X.bit_panel), "visible", mode == PROGRAMMING, NULL);
gtk_widget_set_sensitive(GET_WIDGET("show_trailing_zeroes_menu"),
mode == SCIENTIFIC || mode == PROGRAMMING);
gtk_widget_set_sensitive(GET_WIDGET("show_registers_menu"),
@@ -944,47 +925,47 @@
/* HACK: Some horrible hack down below to keep the buttons the same size.
* There must be a safer way of doing this... */
r = g_new0(GtkRequisition, 1);
- gtk_widget_size_request(X->menubar, r);
+ gtk_widget_size_request(X.menubar, r);
w = r->width;
h = r->height;
- gtk_widget_size_request(X->display_item, r);
+ gtk_widget_size_request(X.display_item, r);
w = MAX(w, r->width);
h += r->height;
- if (GTK_WIDGET_VISIBLE(X->fin_panel)) {
- gtk_widget_size_request(X->fin_panel, r);
+ if (GTK_WIDGET_VISIBLE(X.fin_panel)) {
+ gtk_widget_size_request(X.fin_panel, r);
w = MAX(w, r->width);
h += r->height;
}
- if (GTK_WIDGET_VISIBLE(X->sci_mode_panel)) {
- gtk_widget_size_request(X->sci_mode_panel, r);
+ if (GTK_WIDGET_VISIBLE(X.sci_mode_panel)) {
+ gtk_widget_size_request(X.sci_mode_panel, r);
w = MAX(w, r->width);
h += r->height;
}
- if (GTK_WIDGET_VISIBLE(X->prog_mode_panel)) {
- gtk_widget_size_request(X->prog_mode_panel, r);
+ if (GTK_WIDGET_VISIBLE(X.prog_mode_panel)) {
+ gtk_widget_size_request(X.prog_mode_panel, r);
w = MAX(w, r->width);
h += r->height;
}
- if (GTK_WIDGET_VISIBLE(X->sci_panel)) {
- gtk_widget_size_request(X->sci_panel, r);
+ if (GTK_WIDGET_VISIBLE(X.sci_panel)) {
+ gtk_widget_size_request(X.sci_panel, r);
w = MAX(w, r->width);
h += r->height;
}
- if (GTK_WIDGET_VISIBLE(X->prog_panel)) {
- gtk_widget_size_request(X->prog_panel, r);
+ if (GTK_WIDGET_VISIBLE(X.prog_panel)) {
+ gtk_widget_size_request(X.prog_panel, r);
w = MAX(w, r->width);
h += r->height;
}
g_free(r);
/* For initial display. */
- gtk_window_set_default_size(GTK_WINDOW(X->kframe), w, h);
- gtk_window_resize(GTK_WINDOW(X->kframe), w, h);
+ gtk_window_set_default_size(GTK_WINDOW(X.kframe), w, h);
+ gtk_window_resize(GTK_WINDOW(X.kframe), w, h);
/* Set the title */
if((hostname = make_hostname())) {
@@ -993,7 +974,7 @@
} else {
SNPRINTF(title, MAXLINE, "%s", gettext(titles[mode]));
}
- gtk_window_set_title(GTK_WINDOW(X->kframe), title);
+ gtk_window_set_title(GTK_WINDOW(X.kframe), title);
/* Update the menu */
switch (mode) {
@@ -1028,15 +1009,15 @@
void
ui_set_statusbar(const gchar *text, const gchar *imagename)
{
- GtkImage *image = GTK_IMAGE(X->status_image);
+ GtkImage *image = GTK_IMAGE(X.status_image);
assert(text);
assert(imagename);
assert(image);
gtk_image_set_from_stock(image, imagename, GTK_ICON_SIZE_BUTTON);
- gtk_statusbar_pop(GTK_STATUSBAR(X->statusbar), 0);
- gtk_statusbar_push(GTK_STATUSBAR(X->statusbar), 0, text);
+ gtk_statusbar_pop(GTK_STATUSBAR(X.statusbar), 0);
+ gtk_statusbar_push(GTK_STATUSBAR(X.statusbar), 0, text);
}
@@ -1047,15 +1028,15 @@
GtkTextIter start, end, cursor;
gint cursor_position;
- gtk_text_buffer_get_start_iter(X->display_buffer, &start);
- gtk_text_buffer_get_end_iter(X->display_buffer, &end);
- text = gtk_text_buffer_get_text(X->display_buffer, &start, &end, FALSE);
-
- g_object_get(G_OBJECT(X->display_buffer), "cursor-position", &cursor_position, NULL);
-
- gtk_text_buffer_set_text(X->display_buffer, text, -1);
- gtk_text_buffer_get_iter_at_offset(X->display_buffer, &cursor, cursor_position);
- gtk_text_buffer_place_cursor(X->display_buffer, &cursor);
+ gtk_text_buffer_get_start_iter(X.display_buffer, &start);
+ gtk_text_buffer_get_end_iter(X.display_buffer, &end);
+ text = gtk_text_buffer_get_text(X.display_buffer, &start, &end, FALSE);
+
+ g_object_get(G_OBJECT(X.display_buffer), "cursor-position", &cursor_position, NULL);
+
+ gtk_text_buffer_set_text(X.display_buffer, text, -1);
+ gtk_text_buffer_get_iter_at_offset(X.display_buffer, &cursor, cursor_position);
+ gtk_text_buffer_place_cursor(X.display_buffer, &cursor);
g_free(text);
@@ -1077,15 +1058,15 @@
str = localized;
}
- gtk_text_buffer_set_text(X->display_buffer, str, -1);
+ gtk_text_buffer_set_text(X.display_buffer, str, -1);
if (cursor < 0) {
- gtk_text_buffer_get_end_iter(X->display_buffer, &iter);
+ gtk_text_buffer_get_end_iter(X.display_buffer, &iter);
} else {
- gtk_text_buffer_get_iter_at_offset(X->display_buffer, &iter, cursor);
+ gtk_text_buffer_get_iter_at_offset(X.display_buffer, &iter, cursor);
}
- gtk_text_buffer_place_cursor(X->display_buffer, &iter);
- gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(X->display_item), &iter, 0.0, TRUE, 1.0, 0.0);
+ gtk_text_buffer_place_cursor(X.display_buffer, &iter);
+ gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(X.display_item), &iter, 0.0, TRUE, 1.0, 0.0);
/* This is a workaround for bug #524602.
* Basically the above code can cause the display to disappear when going from
@@ -1097,7 +1078,7 @@
/* Align to the right */
if (cursor < 0) {
adj = gtk_scrolled_window_get_hadjustment(
- GTK_SCROLLED_WINDOW(X->scrolledwindow));
+ GTK_SCROLLED_WINDOW(X.scrolledwindow));
gtk_adjustment_set_value(adj, adj->upper - adj->page_size);
}
}
@@ -1122,18 +1103,18 @@
v->error = error;
for (i = 0; i < NBUTTONS; i++) {
- gtk_widget_set_sensitive(X->buttons[i], !v->error);
+ gtk_widget_set_sensitive(X.buttons[i], !v->error);
}
/* Clr button always sensitive. */
- gtk_widget_set_sensitive(X->clear_buttons[0], TRUE);
- gtk_widget_set_sensitive(X->clear_buttons[1], TRUE);
+ gtk_widget_set_sensitive(X.clear_buttons[0], TRUE);
+ gtk_widget_set_sensitive(X.clear_buttons[1], TRUE);
if (!v->error) {
ui_set_base(v->base);
}
- gtk_widget_set_sensitive(X->sci_mode_panel, !v->error);
- gtk_widget_set_sensitive(X->prog_mode_panel, !v->error);
+ gtk_widget_set_sensitive(X.sci_mode_panel, !v->error);
+ gtk_widget_set_sensitive(X.prog_mode_panel, !v->error);
gtk_widget_set_sensitive(GET_WIDGET("copy_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("paste_menu"), !v->error);
@@ -1146,8 +1127,8 @@
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_trailing_zeroes_menu"),
- !v->error && (v->modetype == SCIENTIFIC ||
- v->modetype == PROGRAMMING));
+ !v->error && (X.mode == SCIENTIFIC ||
+ X.mode == PROGRAMMING));
gtk_widget_set_sensitive(GET_WIDGET("show_thousands_separator_menu"),
!v->error);
gtk_widget_set_sensitive(GET_WIDGET("show_registers_menu"), !v->error);
@@ -1164,16 +1145,16 @@
void
-ui_set_base(enum base_type base)
+ui_set_base(BaseType base)
{
int i, baseval = basevals[(int) base];
v->base = base;
for (i = 0; i < 16; i++) {
- gtk_widget_set_sensitive(X->digit_buttons[i], i < baseval);
+ gtk_widget_set_sensitive(X.digit_buttons[i], i < baseval);
}
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X->base[base]), 1);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X.base[base]), 1);
}
@@ -1187,17 +1168,17 @@
menu = GET_WIDGET("show_registers_menu");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), visible);
- gtk_widget_realize(X->rframe);
+ gtk_widget_realize(X.rframe);
if (visible) {
- if (gdk_window_is_visible(X->rframe->window)) {
- gdk_window_raise(X->rframe->window);
+ if (gdk_window_is_visible(X.rframe->window)) {
+ gdk_window_raise(X.rframe->window);
return;
}
- ds_position_popup(X->kframe, X->rframe, DS_POPUP_ABOVE);
- gtk_widget_show(X->rframe);
+ ds_position_popup(X.kframe, X.rframe, DS_POPUP_ABOVE);
+ gtk_widget_show(X.rframe);
} else {
- gtk_widget_hide(X->rframe);
+ gtk_widget_hide(X.rframe);
}
set_boolean_resource(R_REGS, visible);
@@ -1240,7 +1221,7 @@
"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\n")
};
- gtk_show_about_dialog(GTK_WINDOW(X->kframe),
+ gtk_show_about_dialog(GTK_WINDOW(X.kframe),
/* Translators: Program name in the about dialog */
"name", _("Gcalctool"),
"version", VERSION,
@@ -1320,9 +1301,10 @@
char *ch;
if (response_id == GTK_RESPONSE_OK) {
- ch = (char *) gtk_entry_get_text(GTK_ENTRY(X->aframe_ch));
- mp_set_from_integer(ch[0], v->MPdisp_val);
- display_set_number(&v->display, v->MPdisp_val);
+ int value[MP_SIZE];
+ ch = (char *) gtk_entry_get_text(GTK_ENTRY(X.aframe_ch));
+ mp_set_from_integer(ch[0], value);
+ display_set_number(&v->display, value);
}
gtk_widget_hide(dialog);
@@ -1341,7 +1323,7 @@
static void
aframe_activate_cb(GtkWidget *entry)
{
- aframe_response_cb(X->aframe, GTK_RESPONSE_OK);
+ aframe_response_cb(X.aframe, GTK_RESPONSE_OK);
}
@@ -1374,9 +1356,9 @@
void
base_cb(GtkWidget *widget)
{
- enum base_type base;
+ BaseType base;
- base = (enum base_type) g_object_get_data(G_OBJECT(widget), "base_mode");
+ base = (BaseType) g_object_get_data(G_OBJECT(widget), "base_mode");
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
do_button(FN_SET_BASE, base);
}
@@ -1389,13 +1371,13 @@
GdkScreen *screen;
GError *error = NULL;
- screen = gtk_widget_get_screen (GTK_WIDGET (X->kframe));
+ screen = gtk_widget_get_screen (GTK_WIDGET (X.kframe));
gtk_show_uri (screen, "ghelp:gcalctool", gtk_get_current_event_time (), &error);
if (error != NULL)
{
GtkWidget *d;
- d = gtk_message_dialog_new (GTK_WINDOW (X->kframe),
+ d = gtk_message_dialog_new (GTK_WINDOW (X.kframe),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"%s", _("Unable to open help file"));
@@ -1469,7 +1451,7 @@
if (i < FINC_NUM_ARGS - 1 &&
finc_dialog_fields[dialog][i+1] != NULL) {
- next_widget = glade_xml_get_widget(X->financial,
+ next_widget = glade_xml_get_widget(X.financial,
finc_dialog_fields[dialog][i+1]);
gtk_widget_grab_focus(next_widget);
return;
@@ -1502,12 +1484,12 @@
if (finc_dialog_fields[dialog][i] == NULL) {
continue;
}
- entry = glade_xml_get_widget(X->financial,
+ entry = glade_xml_get_widget(X.financial,
finc_dialog_fields[dialog][i]);
mp_set_from_string(gtk_entry_get_text(GTK_ENTRY(entry)), 10, arg[i]);
gtk_entry_set_text(GTK_ENTRY(entry), "0");
}
- gtk_widget_grab_focus(glade_xml_get_widget(X->financial,
+ gtk_widget_grab_focus(glade_xml_get_widget(X.financial,
finc_dialog_fields[dialog][0]));
do_finc_expression(dialog, arg[0], arg[1], arg[2], arg[3]);
@@ -1517,40 +1499,40 @@
static void
setup_finc_dialogs(void)
{
- X->financial = glade_xml_new(PACKAGE_GLADE_DIR "/financial.glade", NULL,
+ X.financial = glade_xml_new(PACKAGE_GLADE_DIR "/financial.glade", NULL,
NULL);
- glade_xml_signal_connect_data(X->financial, "finc_ctrm_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_ctrm_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_CTRM_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_ddb_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_ddb_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_DDB_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_fv_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_fv_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_FV_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_gpm_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_gpm_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_GPM_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_pmt_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_pmt_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_PMT_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_pv_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_pv_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_PV_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_rate_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_rate_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_RATE_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_sln_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_sln_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_SLN_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_syd_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_syd_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_SYD_DIALOG));
- glade_xml_signal_connect_data(X->financial, "finc_term_response_cb",
+ glade_xml_signal_connect_data(X.financial, "finc_term_response_cb",
G_CALLBACK(finc_response_cb),
GINT_TO_POINTER(FINC_TERM_DIALOG));
- glade_xml_signal_connect(X->financial, "finc_activate_cb",
+ glade_xml_signal_connect(X.financial, "finc_activate_cb",
G_CALLBACK(finc_activate_cb));
}
@@ -1561,12 +1543,12 @@
int i;
for (i = 0; i < MAX_CONSTANTS; i++) {
- display_make_number(value, MAXLINE, constant_get_value(i), DEC, TRUE);
+ display_make_number(&v->display, value, MAXLINE, constant_get_value(i), DEC, TRUE);
SNPRINTF(mline, MAXLINE,
"<span weight=\"bold\">%s_%1d:</span> %s [%s]", _("C"), i,
value,
constant_get_name(i));
- gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->constant_menu_labels[i]), mline);
+ gtk_label_set_markup_with_mnemonic(GTK_LABEL(X.constant_menu_labels[i]), mline);
}
}
@@ -1587,11 +1569,11 @@
SNPRINTF(mline, MAXLINE,
"<span weight=\"bold\">%s_%1d:</span> %s [%s]",
_("F"), i, value, name);
- gtk_widget_show(gtk_widget_get_parent(X->function_menu_labels[i]));
- gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->function_menu_labels[i]), mline);
+ gtk_widget_show(gtk_widget_get_parent(X.function_menu_labels[i]));
+ gtk_label_set_markup_with_mnemonic(GTK_LABEL(X.function_menu_labels[i]), mline);
}
else
- gtk_widget_hide(gtk_widget_get_parent(X->function_menu_labels[i]));
+ gtk_widget_hide(gtk_widget_get_parent(X.function_menu_labels[i]));
}
}
@@ -1609,16 +1591,16 @@
}
if (id == GTK_RESPONSE_ACCEPT) {
- if (gtk_tree_model_get_iter_first(X->constants_model, &iter)) {
+ if (gtk_tree_model_get_iter_first(X.constants_model, &iter)) {
do {
int temp[MP_SIZE];
- gtk_tree_model_get(X->constants_model, &iter,
+ gtk_tree_model_get(X.constants_model, &iter,
COLUMN_NUMBER, &number,
COLUMN_VALUE, &value,
COLUMN_DESCRIPTION, &description, -1);
mp_set_from_string(value, 10, temp);
constant_set(number, description, temp);
- } while (gtk_tree_model_iter_next(X->constants_model, &iter));
+ } while (gtk_tree_model_iter_next(X.constants_model, &iter));
}
}
@@ -1647,14 +1629,14 @@
}
if (id == GTK_RESPONSE_ACCEPT) {
- if (gtk_tree_model_get_iter_first(X->functions_model, &iter)) {
+ if (gtk_tree_model_get_iter_first(X.functions_model, &iter)) {
do {
- gtk_tree_model_get(X->functions_model, &iter,
+ gtk_tree_model_get(X.functions_model, &iter,
COLUMN_NUMBER, &number,
COLUMN_VALUE, &value,
COLUMN_DESCRIPTION, &description, -1);
- function_set(number, description, convert(value));
- } while (gtk_tree_model_iter_next(X->functions_model, &iter));
+ function_set(number, description, value);
+ } while (gtk_tree_model_iter_next(X.functions_model, &iter));
}
}
@@ -1684,7 +1666,7 @@
for (i = 0; i < MAX_CONSTANTS; i++) {
gtk_list_store_append(model, &iter);
- display_make_number(constant, MAXLINE, constant_get_value(i), DEC, TRUE);
+ display_make_number(&v->display, constant, MAXLINE, constant_get_value(i), DEC, TRUE);
gtk_list_store_set(model, &iter,
COLUMN_NUMBER, i,
COLUMN_EDITABLE, TRUE,
@@ -1732,12 +1714,12 @@
int temp[MP_SIZE];
register_get(n, temp);
- display_make_number(mval, MAXLINE, temp, v->base, TRUE);
- gtk_entry_set_width_chars(GTK_ENTRY(X->regs[n]), strlen(mval));
- gtk_entry_set_text(GTK_ENTRY(X->regs[n]), mval);
+ display_make_number(&v->display, mval, MAXLINE, temp, v->base, TRUE);
+ gtk_entry_set_width_chars(GTK_ENTRY(X.regs[n]), strlen(mval));
+ gtk_entry_set_text(GTK_ENTRY(X.regs[n]), mval);
SNPRINTF(key, MAXLINE, "register%d", n);
- display_make_number(value, MAXLINE, temp, DEC, TRUE);
+ display_make_number(&v->display, value, MAXLINE, temp, DEC, TRUE);
set_resource(key, value);
}
}
@@ -1748,7 +1730,7 @@
{
int x, y;
- (void) gdk_window_get_origin(X->kframe->window, &x, &y);
+ (void) gdk_window_get_origin(X.kframe->window, &x, &y);
set_int_resource(R_XPOS, x);
set_int_resource(R_YPOS, y);
}
@@ -1768,7 +1750,7 @@
static void
menu_item_select_cb(GtkWidget *widget)
{
- GtkStatusbar *statusbar = GTK_STATUSBAR(X->statusbar);
+ GtkStatusbar *statusbar = GTK_STATUSBAR(X.statusbar);
gchar *tooltip;
guint context_id;
@@ -1785,7 +1767,7 @@
static void
menu_item_deselect_cb(GtkWidget *widget)
{
- GtkStatusbar *statusbar = GTK_STATUSBAR(X->statusbar);
+ GtkStatusbar *statusbar = GTK_STATUSBAR(X.statusbar);
guint context_id;
context_id = gtk_statusbar_get_context_id(statusbar, "menuhelp");
@@ -1815,13 +1797,13 @@
for (i = 0; i < MAX_REGISTERS; i++) {
int temp[MP_SIZE];
register_get(i, temp);
- display_make_number(value, MAXLINE, temp, v->base, TRUE);
+ display_make_number(&v->display, value, MAXLINE, temp, v->base, TRUE);
SNPRINTF(mstr, MAXLINE, "<span weight=\"bold\">%s_%d:</span> %s",
/* Translators: R is the short form of register used inter alia in popup menus */
_("R"), i, value);
- gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->memory_store_labels[i]), mstr);
- gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->memory_recall_labels[i]), mstr);
- gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->memory_exchange_labels[i]), mstr);
+ gtk_label_set_markup_with_mnemonic(GTK_LABEL(X.memory_store_labels[i]), mstr);
+ gtk_label_set_markup_with_mnemonic(GTK_LABEL(X.memory_recall_labels[i]), mstr);
+ gtk_label_set_markup_with_mnemonic(GTK_LABEL(X.memory_exchange_labels[i]), mstr);
}
}
@@ -1831,19 +1813,19 @@
gchar *string = NULL;
GtkTextIter start, end;
- if (gtk_text_buffer_get_selection_bounds(X->display_buffer, &start, &end) == TRUE) {
- string = gtk_text_buffer_get_text(X->display_buffer, &start, &end, FALSE);
+ if (gtk_text_buffer_get_selection_bounds(X.display_buffer, &start, &end) == TRUE) {
+ string = gtk_text_buffer_get_text(X.display_buffer, &start, &end, FALSE);
} else {
string = ui_get_display();
}
- if (X->shelf != NULL) {
- free(X->shelf);
+ if (X.shelf != NULL) {
+ free(X.shelf);
}
- X->shelf = g_locale_from_utf8(string, strlen(string), NULL, NULL, NULL);
+ X.shelf = g_locale_from_utf8(string, strlen(string), NULL, NULL, NULL);
g_free(string);
- gtk_clipboard_set_text(gtk_clipboard_get(X->clipboard_atom), X->shelf, -1);
+ gtk_clipboard_set_text(gtk_clipboard_get(X.clipboard_atom), X.shelf, -1);
}
@@ -1956,9 +1938,9 @@
{
GtkTextIter iter;
- gtk_text_buffer_get_iter_at_offset(X->display_buffer, &iter, offset);
- gtk_text_buffer_place_cursor(X->display_buffer, &iter);
- gtk_widget_grab_focus(X->display_item);
+ gtk_text_buffer_get_iter_at_offset(X.display_buffer, &iter, offset);
+ gtk_text_buffer_place_cursor(X.display_buffer, &iter);
+ gtk_widget_grab_focus(X.display_item);
}
@@ -1978,8 +1960,8 @@
}
/* Accuracy shortcuts */
- if (state == GDK_CONTROL_MASK && (v->modetype == SCIENTIFIC ||
- v->modetype == PROGRAMMING)) {
+ if (state == GDK_CONTROL_MASK && (X.mode == SCIENTIFIC ||
+ X.mode == PROGRAMMING)) {
switch (event->keyval) {
case GDK_0:
do_button(FN_SET_ACCURACY, 0);
@@ -2015,7 +1997,7 @@
}
/* Connect home and end keys to move into the display entry */
- if (!gtk_widget_is_focus(X->display_item)) {
+ if (!gtk_widget_is_focus(X.display_item)) {
if (event->keyval == GDK_Home) { /* || event->keyval == GDK_Left) { */
select_display_entry(0);
return (TRUE);
@@ -2033,13 +2015,13 @@
/* Shift inverse mode based on if shift is pressed */
if (event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X->inverse_toggle),
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X.inverse_toggle),
TRUE);
return (TRUE);
}
for (i = 0; i < NBUTTONS; i++) {
- button = X->buttons[i];
+ button = X.buttons[i];
/* Check if function is available */
if (!GTK_WIDGET_IS_SENSITIVE(button)) {
@@ -2047,7 +2029,7 @@
}
/* In basic mode only allow buttons that the user can see */
- if (v->modetype == BASIC &&
+ if (X.mode == BASIC &&
(!GTK_WIDGET_VISIBLE(gtk_widget_get_parent(button)) ||
!GTK_WIDGET_VISIBLE(button))) {
continue;
@@ -2081,7 +2063,7 @@
kframe_key_release_cb(GtkWidget *widget, GdkEventKey *event)
{
if (event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X->inverse_toggle),
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X.inverse_toggle),
FALSE);
return (TRUE);
}
@@ -2095,9 +2077,9 @@
{
gboolean can_paste, can_copy;
- can_copy = gtk_text_buffer_get_has_selection(X->display_buffer);
+ can_copy = gtk_text_buffer_get_has_selection(X.display_buffer);
can_paste = gtk_clipboard_wait_is_text_available(
- gtk_clipboard_get(X->clipboard_atom));
+ gtk_clipboard_get(X.clipboard_atom));
gtk_widget_set_sensitive(GET_WIDGET("copy_menu"), can_copy);
gtk_widget_set_sensitive(GET_WIDGET("paste_menu"), can_paste);
@@ -2183,10 +2165,8 @@
}
*dstp++ = '\0';
- display_set_cursor(&v->display, get_cursor()); // FIXME: Move out of gtk.c
- display_insert(&v->display, (char *) text);
+ display_insert(&v->display, get_cursor(), (char *)text);
display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
free(text);
}
@@ -2196,7 +2176,7 @@
mouse_button_cb(GtkWidget *widget, GdkEventButton *event)
{
if (event->button == 2) {
- gtk_clipboard_request_text(gtk_clipboard_get(X->primary_atom),
+ gtk_clipboard_request_text(gtk_clipboard_get(X.primary_atom),
get_proc, NULL);
}
@@ -2208,7 +2188,7 @@
static void
paste_cb(GtkWidget *widget)
{
- gtk_clipboard_request_text(gtk_clipboard_get(X->clipboard_atom),
+ gtk_clipboard_request_text(gtk_clipboard_get(X.clipboard_atom),
get_proc, NULL);
}
@@ -2234,8 +2214,6 @@
redo_cb(GtkWidget *widget)
{
do_button(FN_REDO, 0);
- display_set_cursor(&v->display, -1);
- display_refresh(&v->display);
}
@@ -2250,7 +2228,7 @@
// FIXME: WTF?
if (strcmp(gtk_label_get_text(GTK_LABEL(label)), _("Paste")) == 0) {
if (gtk_clipboard_wait_is_text_available(
- gtk_clipboard_get(X->clipboard_atom))) {
+ gtk_clipboard_get(X.clipboard_atom))) {
gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE);
g_signal_connect(GTK_OBJECT(widget), "activate",
G_CALLBACK(popup_paste_cb), NULL);
@@ -2272,11 +2250,11 @@
static void
insert_ascii_cb(GtkWidget *widget)
{
- if (!GTK_WIDGET_VISIBLE(X->aframe)) {
- ds_position_popup(X->kframe, X->aframe, DS_POPUP_LEFT);
+ if (!GTK_WIDGET_VISIBLE(X.aframe)) {
+ ds_position_popup(X.kframe, X.aframe, DS_POPUP_LEFT);
}
- gtk_window_set_focus(GTK_WINDOW(X->kframe), GTK_WIDGET(X->aframe_ch));
- gtk_widget_show(X->aframe);
+ gtk_window_set_focus(GTK_WINDOW(X.kframe), GTK_WIDGET(X.aframe_ch));
+ gtk_widget_show(X.aframe);
}
@@ -2330,11 +2308,11 @@
static void
accuracy_other_cb(GtkWidget *widget)
{
- if (!GTK_WIDGET_VISIBLE(X->spframe)) {
- ds_position_popup(X->kframe, X->spframe, DS_POPUP_LEFT);
+ if (!GTK_WIDGET_VISIBLE(X.spframe)) {
+ ds_position_popup(X.kframe, X.spframe, DS_POPUP_LEFT);
}
- gtk_window_set_focus(GTK_WINDOW(X->spframe), GTK_WIDGET(X->precision_spin));
- gtk_widget_show(X->spframe);
+ gtk_window_set_focus(GTK_WINDOW(X.spframe), GTK_WIDGET(X.precision_spin));
+ gtk_widget_show(X.spframe);
}
@@ -2371,7 +2349,7 @@
{
int val;
if (response_id == GTK_RESPONSE_OK) {
- val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(X->precision_spin));
+ val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(X.precision_spin));
do_button(FN_SET_ACCURACY, val);
}
@@ -2391,7 +2369,7 @@
static void
spframe_activate_cb(GtkWidget *spin)
{
- spframe_response_cb(X->spframe, GTK_RESPONSE_OK);
+ spframe_response_cb(X.spframe, GTK_RESPONSE_OK);
}
@@ -2410,7 +2388,7 @@
static void
edit_constants_cb(GtkMenuItem *item)
{
- gtk_widget_show(X->con_dialog);
+ gtk_widget_show(X.con_dialog);
}
@@ -2418,7 +2396,7 @@
static void
edit_functions_cb(GtkMenuItem *item)
{
- gtk_widget_show(X->fun_dialog);
+ gtk_widget_show(X.fun_dialog);
}
@@ -2445,7 +2423,7 @@
}
}
- gtk_window_move(GTK_WINDOW(X->kframe), x, y);
+ gtk_window_move(GTK_WINDOW(X.kframe), x, y);
}
@@ -2460,8 +2438,8 @@
GtkAccelGroup *accel_group;
GtkWidget *treeview;
- X->ui = glade_xml_new(UI_FILE, NULL, NULL);
- if (X->ui == NULL) {
+ X.ui = glade_xml_new(UI_FILE, NULL, NULL);
+ if (X.ui == NULL) {
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL, 0,
@@ -2483,7 +2461,7 @@
* See http://library.gnome.org/devel/libglade/unstable and
* http://www.jamesh.id.au/software/libglade/
* for some information on how to get this to work
- * glade_xml_signal_autoconnect(X->ui);
+ * glade_xml_signal_autoconnect(X.ui);
*/
CONNECT_SIGNAL(kframe_key_press_cb);
CONNECT_SIGNAL(kframe_key_release_cb);
@@ -2537,49 +2515,49 @@
CONNECT_SIGNAL(edit_functions_response_cb);
CONNECT_SIGNAL(edit_functions_delete_cb);
- X->clipboard_atom = gdk_atom_intern("CLIPBOARD", FALSE);
- X->primary_atom = gdk_atom_intern("PRIMARY", FALSE);
- X->kframe = GET_WIDGET("calc_window");
- X->aframe = GET_WIDGET("ascii_dialog");
- X->aframe_ch = GET_WIDGET("ascii_entry");
- X->spframe = GET_WIDGET("precision_dialog");
- X->precision_spin = GET_WIDGET("spframe_spin");
- X->rframe = GET_WIDGET("register_dialog");
- X->con_dialog = GET_WIDGET("edit_constants_dialog");
- X->fun_dialog = GET_WIDGET("edit_functions_dialog");
- X->menubar = GET_WIDGET("menubar");
- X->scrolledwindow = GET_WIDGET("display_scroll"),
- X->display_item = GET_WIDGET("displayitem"),
- X->bas_panel = GET_WIDGET("basic_panel");
- X->sci_panel = GET_WIDGET("scientific_panel");
- X->prog_panel = GET_WIDGET("programming_panel");
- X->adv_panel = GET_WIDGET("advanced_panel");
- X->fin_panel = GET_WIDGET("financial_panel");
- X->bit_panel = GET_WIDGET("bit_panel");
- X->clear_buttons[0] = GET_WIDGET("calc_clear_simple_button");
- X->clear_buttons[1] = GET_WIDGET("calc_clear_advanced_button");
- X->sci_mode_panel = GET_WIDGET("scientific_mode_panel");
- X->prog_mode_panel = GET_WIDGET("programming_mode_panel");
- X->trig[0] = GET_WIDGET("degrees_radio");
- X->trig[1] = GET_WIDGET("gradians_radio");
- X->trig[2] = GET_WIDGET("radians_radio");
- X->base[0] = GET_WIDGET("binary_radio");
- X->base[1] = GET_WIDGET("octal_radio");
- X->base[2] = GET_WIDGET("decimal_radio");
- X->base[3] = GET_WIDGET("hexadecimal_radio");
- X->disp[0] = GET_WIDGET("engineering_radio");
- X->disp[1] = GET_WIDGET("fixed_point_radio");
- X->disp[2] = GET_WIDGET("scientific_radio");
- X->inverse_toggle = GET_WIDGET("inverse_check");
- X->hyperbolic_toggle = GET_WIDGET("hyperbolic_check");
- X->statusbar = GET_WIDGET("statusbar");
+ X.clipboard_atom = gdk_atom_intern("CLIPBOARD", FALSE);
+ X.primary_atom = gdk_atom_intern("PRIMARY", FALSE);
+ X.kframe = GET_WIDGET("calc_window");
+ X.aframe = GET_WIDGET("ascii_dialog");
+ X.aframe_ch = GET_WIDGET("ascii_entry");
+ X.spframe = GET_WIDGET("precision_dialog");
+ X.precision_spin = GET_WIDGET("spframe_spin");
+ X.rframe = GET_WIDGET("register_dialog");
+ X.con_dialog = GET_WIDGET("edit_constants_dialog");
+ X.fun_dialog = GET_WIDGET("edit_functions_dialog");
+ X.menubar = GET_WIDGET("menubar");
+ X.scrolledwindow = GET_WIDGET("display_scroll"),
+ X.display_item = GET_WIDGET("displayitem"),
+ X.bas_panel = GET_WIDGET("basic_panel");
+ X.sci_panel = GET_WIDGET("scientific_panel");
+ X.prog_panel = GET_WIDGET("programming_panel");
+ X.adv_panel = GET_WIDGET("advanced_panel");
+ X.fin_panel = GET_WIDGET("financial_panel");
+ X.bit_panel = GET_WIDGET("bit_panel");
+ X.clear_buttons[0] = GET_WIDGET("calc_clear_simple_button");
+ X.clear_buttons[1] = GET_WIDGET("calc_clear_advanced_button");
+ X.sci_mode_panel = GET_WIDGET("scientific_mode_panel");
+ X.prog_mode_panel = GET_WIDGET("programming_mode_panel");
+ X.trig[0] = GET_WIDGET("degrees_radio");
+ X.trig[1] = GET_WIDGET("gradians_radio");
+ X.trig[2] = GET_WIDGET("radians_radio");
+ X.base[0] = GET_WIDGET("binary_radio");
+ X.base[1] = GET_WIDGET("octal_radio");
+ X.base[2] = GET_WIDGET("decimal_radio");
+ X.base[3] = GET_WIDGET("hexadecimal_radio");
+ X.disp[0] = GET_WIDGET("engineering_radio");
+ X.disp[1] = GET_WIDGET("fixed_point_radio");
+ X.disp[2] = GET_WIDGET("scientific_radio");
+ X.inverse_toggle = GET_WIDGET("inverse_check");
+ X.hyperbolic_toggle = GET_WIDGET("hyperbolic_check");
+ X.statusbar = GET_WIDGET("statusbar");
for (i = 0; i < 16; i++) {
SNPRINTF(name, MAXLINE, "calc_%x_button", i);
- X->digit_buttons[i] = GET_WIDGET(name);
+ X.digit_buttons[i] = GET_WIDGET(name);
}
for (i = 0; i < MAX_REGISTERS; i++) {
SNPRINTF(name, MAXLINE, "register_entry_%d", i);
- X->regs[i] = GET_WIDGET(name);
+ X.regs[i] = GET_WIDGET(name);
}
/* Load buttons and set them all to be the same size */
@@ -2587,12 +2565,12 @@
for (i = 0; i < NBUTTONS; i++) {
SNPRINTF(name, MAXLINE, "calc_%s_button",
button_widgets[i].widget_name);
- X->buttons[i] = GET_WIDGET(name);
- assert(X->buttons[i] != NULL);
+ X.buttons[i] = GET_WIDGET(name);
+ assert(X.buttons[i] != NULL);
- gtk_size_group_add_widget(size_group, X->buttons[i]);
+ gtk_size_group_add_widget(size_group, X.buttons[i]);
- g_object_set_data(G_OBJECT(X->buttons[i]), "calc_function",
+ g_object_set_data(G_OBJECT(X.buttons[i]), "calc_function",
GINT_TO_POINTER(button_widgets[i].function));
}
@@ -2610,7 +2588,7 @@
SNPRINTF(name, MAXLINE, "constant_menu_item%d", i);
widget = GET_WIDGET(name);
g_object_set_data(G_OBJECT(widget), "constant_id", GINT_TO_POINTER(i));
- X->constant_menu_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
+ X.constant_menu_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
}
g_object_set_data(G_OBJECT(GET_WIDGET("calc_functions_button")),
@@ -2619,7 +2597,7 @@
SNPRINTF(name, MAXLINE, "function_menu_item%d", i);
widget = GET_WIDGET(name);
g_object_set_data(G_OBJECT(widget), "function_id", GINT_TO_POINTER(i));
- X->function_menu_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
+ X.function_menu_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
}
g_object_set_data(G_OBJECT(GET_WIDGET("calc_store_button")),
@@ -2632,24 +2610,24 @@
SNPRINTF(name, MAXLINE, "store_menu_item%d", i);
widget = GET_WIDGET(name);
g_object_set_data(G_OBJECT(widget), "register_id", GINT_TO_POINTER(i));
- X->memory_store_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
+ X.memory_store_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
SNPRINTF(name, MAXLINE, "recall_menu_item%d", i);
widget = GET_WIDGET(name);
g_object_set_data(G_OBJECT(widget), "register_id", GINT_TO_POINTER(i));
- X->memory_recall_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
+ X.memory_recall_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
SNPRINTF(name, MAXLINE, "exchange_menu_item%d", i);
widget = GET_WIDGET(name);
g_object_set_data(G_OBJECT(widget), "register_id", GINT_TO_POINTER(i));
- X->memory_exchange_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
+ X.memory_exchange_labels[i] = gtk_bin_get_child(GTK_BIN(widget));
}
/* Load bit panel */
for (i = 0; i < MAXBITS; i++)
{
SNPRINTF(name, MAXLINE, "bit_label_%d", i);
- X->bits[i] = GET_WIDGET(name);
+ X.bits[i] = GET_WIDGET(name);
SNPRINTF(name, MAXLINE, "bit_eventbox_%d", i);
g_object_set_data(G_OBJECT(GET_WIDGET(name)),
"bit_index", GINT_TO_POINTER(i));
@@ -2675,25 +2653,25 @@
// ???
widget = GET_WIDGET("kvbox");
gtk_widget_set_direction(widget, GTK_TEXT_DIR_LTR);
- gtk_widget_set_direction(X->fin_panel, GTK_TEXT_DIR_LTR);
+ gtk_widget_set_direction(X.fin_panel, GTK_TEXT_DIR_LTR);
/* Make dialogs transient of the main window */
- gtk_window_set_transient_for(GTK_WINDOW(X->aframe), GTK_WINDOW(X->kframe));
- gtk_window_set_transient_for(GTK_WINDOW(X->spframe), GTK_WINDOW(X->kframe));
- gtk_window_set_transient_for(GTK_WINDOW(X->rframe), GTK_WINDOW(X->kframe));
- gtk_window_set_transient_for(GTK_WINDOW(X->con_dialog),
- GTK_WINDOW(X->kframe));
+ gtk_window_set_transient_for(GTK_WINDOW(X.aframe), GTK_WINDOW(X.kframe));
+ gtk_window_set_transient_for(GTK_WINDOW(X.spframe), GTK_WINDOW(X.kframe));
+ gtk_window_set_transient_for(GTK_WINDOW(X.rframe), GTK_WINDOW(X.kframe));
+ gtk_window_set_transient_for(GTK_WINDOW(X.con_dialog),
+ GTK_WINDOW(X.kframe));
/* Can't set max length for spin buttons in Glade 2 */
- gtk_entry_set_max_length(GTK_ENTRY(X->precision_spin), 2);
+ gtk_entry_set_max_length(GTK_ENTRY(X.precision_spin), 2);
- gtk_dialog_set_default_response(GTK_DIALOG(X->con_dialog),
+ gtk_dialog_set_default_response(GTK_DIALOG(X.con_dialog),
GTK_RESPONSE_ACCEPT);
/* Make constant tree model */
- X->constants_model = create_constants_model();
+ X.constants_model = create_constants_model();
treeview = GET_WIDGET("edit_constants_treeview");
- gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), X->constants_model);
+ gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), X.constants_model);
gtk_tree_selection_set_mode(
gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)),
GTK_SELECTION_SINGLE);
@@ -2708,13 +2686,13 @@
COLUMN_DESCRIPTION, TRUE);
/* Make function tree model */
- X->functions_model = create_functions_model();
+ X.functions_model = create_functions_model();
treeview = GET_WIDGET("edit_functions_treeview");
- gtk_dialog_set_default_response(GTK_DIALOG(X->fun_dialog),
+ gtk_dialog_set_default_response(GTK_DIALOG(X.fun_dialog),
GTK_RESPONSE_ACCEPT);
- gtk_window_set_transient_for(GTK_WINDOW(X->fun_dialog),
- GTK_WINDOW(X->kframe));
- gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), X->functions_model);
+ gtk_window_set_transient_for(GTK_WINDOW(X.fun_dialog),
+ GTK_WINDOW(X.kframe));
+ gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), X.functions_model);
gtk_tree_selection_set_mode(
gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)),
GTK_SELECTION_SINGLE);
@@ -2728,34 +2706,34 @@
add_cf_column(GTK_TREE_VIEW(treeview), _("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);
- font_desc = pango_font_description_copy(X->display_item->style->font_desc);
+ X.display_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(X.display_item));
+ gtk_widget_ensure_style(X.display_item);
+ font_desc = pango_font_description_copy(X.display_item->style->font_desc);
pango_font_description_set_size(font_desc, 16 * PANGO_SCALE);
- gtk_widget_modify_font(X->display_item, font_desc);
+ gtk_widget_modify_font(X.display_item, font_desc);
pango_font_description_free(font_desc);
- gtk_widget_set_name(X->display_item, "displayitem");
- atk_object_set_role(gtk_widget_get_accessible(X->display_item),
+ gtk_widget_set_name(X.display_item, "displayitem");
+ atk_object_set_role(gtk_widget_get_accessible(X.display_item),
ATK_ROLE_EDITBAR);
- gtk_widget_realize(X->kframe);
+ gtk_widget_realize(X.kframe);
set_win_position();
for (i = 0; i < 3; i++)
- g_object_set_data(G_OBJECT(X->trig[i]),
+ g_object_set_data(G_OBJECT(X.trig[i]),
"trig_mode", GINT_TO_POINTER(i));
for (i = 0; i < 4; i++)
- g_object_set_data(G_OBJECT(X->base[i]),
+ g_object_set_data(G_OBJECT(X.base[i]),
"base_mode", GINT_TO_POINTER(i));
for (i = 0; i < 3; i++)
- g_object_set_data(G_OBJECT(X->disp[i]),
+ g_object_set_data(G_OBJECT(X.disp[i]),
"numeric_mode", GINT_TO_POINTER(i));
/* Put status image into statusbar (glade doesn't support child widgets
* in statusbars) */
- X->status_image = gtk_image_new_from_stock("", GTK_ICON_SIZE_BUTTON);
- gtk_widget_show(X->status_image);
- gtk_box_pack_start(GTK_BOX(X->statusbar), X->status_image, FALSE, TRUE, 0);
+ X.status_image = gtk_image_new_from_stock("", GTK_ICON_SIZE_BUTTON);
+ gtk_widget_show(X.status_image);
+ gtk_box_pack_start(GTK_BOX(X.statusbar), X.status_image, FALSE, TRUE, 0);
/* Set modes for menu items */
for (i = 1; i < 16; i++) {
@@ -2779,7 +2757,7 @@
/* Make shortcuts for accuracy menus */
accel_group = gtk_accel_group_new();
- gtk_window_add_accel_group(GTK_WINDOW(X->kframe), accel_group);
+ gtk_window_add_accel_group(GTK_WINDOW(X.kframe), accel_group);
for (i = 0; i < 10; i++) {
SNPRINTF(name, MAXLINE, "acc_item%d", i);
widget = GET_WIDGET(name);
@@ -2818,14 +2796,18 @@
{
gchar *path;
const gchar *home;
-
- X = (XVars) LINT_CAST(calloc(1, sizeof(struct Xobject)));
-
+ int value;
+
gtk_init(argc, argv);
- X->shelf = NULL; /* No selection for shelf initially. */
+ memset(&X, 0, sizeof(X));
gtk_rc_get_default_files();
+
+ if (get_enumerated_resource(R_MODE, mode_names, &value))
+ X.mode = (ModeType) value;
+ else
+ X.mode = BASIC;
home = g_get_home_dir();
path = g_build_path(home, RCNAME, NULL);
@@ -2847,10 +2829,10 @@
create_kframe();
/* Load configuration */
- ui_set_show_thousands_separator(v->show_tsep);
- ui_set_show_trailing_zeroes(v->show_zeroes);
+ ui_set_show_thousands_separator(v->display.show_tsep);
+ ui_set_show_trailing_zeroes(v->display.show_zeroes);
- ui_set_mode(v->modetype);
+ ui_set_mode(X.mode);
ui_set_numeric_mode(FIX);
ui_set_base(v->base);
ui_set_accuracy(v->accuracy);
@@ -2863,12 +2845,12 @@
ui_set_registers_visible(boolval);
/* Focus on the clear button */
- if (v->modetype == BASIC) {
- gtk_window_set_focus(GTK_WINDOW(X->kframe),
- GTK_WIDGET(X->clear_buttons[0]));
+ if (X.mode == BASIC) {
+ gtk_window_set_focus(GTK_WINDOW(X.kframe),
+ GTK_WIDGET(X.clear_buttons[0]));
} else {
- gtk_window_set_focus(GTK_WINDOW(X->kframe),
- GTK_WIDGET(X->clear_buttons[1]));
+ gtk_window_set_focus(GTK_WINDOW(X.kframe),
+ GTK_WIDGET(X.clear_buttons[1]));
}
/* Set default accuracy menu item */
@@ -2883,11 +2865,9 @@
{
ui_set_base(v->base);
ui_set_trigonometric_mode(v->ttype);
- ui_set_numeric_mode(v->dtype);
-
- gtk_widget_show(X->kframe);
+ ui_set_numeric_mode(v->display.format);
- reset_display();
+ gtk_widget_show(X.kframe);
gtk_main();
}
Modified: trunk/gcalctool/mp-convert.c
==============================================================================
--- trunk/gcalctool/mp-convert.c (original)
+++ trunk/gcalctool/mp-convert.c Sun Dec 21 09:25:01 2008
@@ -536,7 +536,7 @@
}
/* Stop if there is no fractional component or not showing fractional part */
- if ((mp_is_zero(fractional_component) && !v->show_zeroes) || accuracy == 0) {
+ if ((mp_is_zero(fractional_component) && !v->display.show_zeroes) || accuracy == 0) {
*optr = '\0';
return;
}
@@ -562,7 +562,7 @@
} while (!mp_is_zero(temp) && accuracy > 0);
/* Strip trailing zeroes */
- if (!v->show_zeroes)
+ if (!v->display.show_zeroes)
optr = last_non_zero;
*optr = '\0';
Modified: trunk/gcalctool/mp.c
==============================================================================
--- trunk/gcalctool/mp.c (original)
+++ trunk/gcalctool/mp.c Sun Dec 21 09:25:01 2008
@@ -19,6 +19,7 @@
* 02111-1307, USA.
*/
+#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
@@ -1830,7 +1831,7 @@
mpovfl(int *x, const char *error)
{
if (mp_show_errors) {
- FPRINTF(stderr, "%s", error);
+ fprintf(stderr, "%s", error);
}
mpchk(1, 4);
Modified: trunk/gcalctool/register.c
==============================================================================
--- trunk/gcalctool/register.c (original)
+++ trunk/gcalctool/register.c Sun Dec 21 09:25:01 2008
@@ -61,8 +61,17 @@
void register_init()
{
int i;
+ char key[MAXLINE], *value;
+
for (i = 0; i < MAX_REGISTERS; i++) {
- mp_set_from_integer(0, registers[i]);
+ SNPRINTF(key, MAXLINE, "register%d", i);
+ value = get_resource(key);
+ if (value) {
+ int temp[MP_SIZE];
+ mp_set_from_string(value, 10, temp);
+ g_free(value);
+ register_set(i, temp);
+ }
}
for (i = 0; i < MAX_CONSTANTS; i++) {
@@ -105,7 +114,7 @@
}
if (nline && vline) {
- function_set(i, nline, convert(vline));
+ function_set(i, nline, vline);
g_free(nline);
g_free(vline);
}
Modified: trunk/gcalctool/ui.h
==============================================================================
--- trunk/gcalctool/ui.h (original)
+++ trunk/gcalctool/ui.h Sun Dec 21 09:25:01 2008
@@ -27,6 +27,13 @@
#include "calctool.h"
+/* Calculator modes. */
+typedef enum { BASIC,
+ ADVANCED,
+ FINANCIAL,
+ SCIENTIFIC,
+ PROGRAMMING } ModeType;
+
void ui_init(int *argc, char ***argv);
void ui_load(void);
void ui_start(void);
@@ -40,10 +47,10 @@
void ui_set_registers_visible(gboolean);
void ui_set_accuracy(int);
-void ui_set_mode(enum mode_type);
-void ui_set_base(enum base_type);
-void ui_set_trigonometric_mode(enum trig_type);
-void ui_set_numeric_mode(enum base_type);
+void ui_set_mode(ModeType);
+void ui_set_base(BaseType);
+void ui_set_trigonometric_mode(TrigType);
+void ui_set_numeric_mode(BaseType);
void ui_set_show_thousands_separator(gboolean);
void ui_set_show_trailing_zeroes(gboolean);
Modified: trunk/gcalctool/unittest.c
==============================================================================
--- trunk/gcalctool/unittest.c (original)
+++ trunk/gcalctool/unittest.c Sun Dec 21 09:25:01 2008
@@ -54,8 +54,6 @@
void
test_parser()
{
- v->modetype = SCIENTIFIC;
-
test("0", "0", 0);
test("1", "1", 0);
test("+1", "1", 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]