main.c (gdcalc-2.20) | : | main.c (gdcalc-3.0) | ||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation; either version 2 of the License, or | the Free Software Foundation; either version 2 of the License, or | |||
(at your option) any later version. | (at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | |||
along with this program; see the file COPYING. If not, write to | along with this program; see the file COPYING. If not, write to | |||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | the Free Software Foundation, Inc., 51 Franklin Street, Fifth | |||
Boston, MA 02111-1307, USA. | Floor, Boston, MA 02110-1301 USA | |||
*/ | */ | |||
/* $Id: main.c,v 1.15 2006/12/31 09:06:53 bhepple Exp $ */ | /* $Id: main.c,v 1.15 2006/12/31 09:06:53 bhepple Exp $ */ | |||
/* With glade 0.5.11 that every time the menubar is edited, one item | ||||
in every radio group is turned on and interface.c gets a | ||||
gtk_check_menu_item_set_active for that item. This results in | ||||
seemingly harmless but distracting runtime errors. */ | ||||
/* To build: | /* To build: | |||
cd .../dcalc/gtk | ./autogen.sh | |||
aclocal | ./configure | |||
autoconf | ||||
autoheader | ||||
automake | ||||
configure | ||||
(the above may happen automagically by typing 'make') | (the above may happen automagically by typing 'make') | |||
cd src | ||||
make | make | |||
make install | make install | |||
whew | ||||
*/ | */ | |||
#ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | |||
# include <config.h> | # include <config.h> | |||
#endif | #endif | |||
#include <ctype.h> | #include <ctype.h> | |||
#include <gnome.h> | #include <gtk/gtk.h> | |||
#include <sys/param.h> | #include <sys/param.h> | |||
#include "interface.h" | ||||
#include "support.h" | ||||
#include "dcalc.h" | #include "dcalc.h" | |||
#include "callbacks.h" | #include "callbacks.h" | |||
#include "main.h" | #include "main.h" | |||
/* naughty global exported to callbacks.c: */ | /* naughty global exported to callbacks.c: */ | |||
GtkBuilder *builder; | ||||
GtkWidget *main_window; | GtkWidget *main_window; | |||
GtkWidget *mem_dialog; | ||||
GtkWidget *eval_dialog; | ||||
GtkWidget *convert; | GtkWidget *convert; | |||
GtkWidget *registers = NULL; | GtkWidget *registers_popup = NULL; | |||
GtkEntry *entryX; | GtkEntry *entry_x; | |||
GtkButton *invert_button; | GtkWidget *mem_dialog; | |||
int mem_value; | int mem_value; | |||
int raw_mode = 0; | int raw_mode = 0; | |||
int is_resident = 0; | int is_resident = 0; | |||
int insertedTextIsFromDcalc = 1; | int insertedTextIsFromDcalc = 1; | |||
char *registers_label = "gdcalc registers"; | ||||
dcalc_button *l_buttons, *r_buttons; | dcalc_button *l_buttons, *r_buttons; | |||
char calculatorFont[100]; | ||||
char buttonFont[100]; | ||||
char plusMinusFont[100]; | ||||
dcalc_button sci_buttons[] = { | dcalc_button sci_buttons[] = { | |||
{ 0, 0, SIN, "SIN", "Sine of X (or INV)", "SIN(", "ASIN(" }, | { 0, 0, SIN, "SIN", "Sine of X (or INV)", "SIN(", "ASIN(" }, | |||
{ 0, 1, COS, "COS", "Cosine of X (or INV)", "COS(", "ACOS(" }, | { 0, 1, COS, "COS", "Cosine of X (or INV)", "COS(", "ACOS(" }, | |||
{ 0, 2, TAN, "TAN", "Tangent of X (or INV)", "TAN(", "ATAN(" }, | { 0, 2, TAN, "TAN", "Tangent of X (or INV)", "TAN(", "ATAN(" }, | |||
{ 0, 3, HMS, "h.ms", "Convert X to Hours.MinsSecs (or INV)", "HMS(", "HOURS(" }, | { 0, 3, HMS, "h.ms", "Convert X to Hours.MinsSecs (or INV)", "HMS(", "HOURS(" }, | |||
{ 0, 4, RTOP, "r->p", "Convert (X,Y) to polar coordinates (or INV)", "RTOP ", "PTOR " }, | { 0, 4, RTOP, "r->p", "Convert (X,Y) to polar coordinates (or INV)", "RTOP ", "PTOR " }, | |||
{ 0, 5, DTOR, "d->r", "Convert degrees to radians (or INV)", "DTOR(", "RTOD(" }, | { 0, 5, DTOR, "d->r", "Convert degrees to radians (or INV)", "DTOR(", "RTOD(" }, | |||
{ 0, 6, LOG10, "LOG", "Logarithm (base 10) (or INV)", "LOG10(", "ALOG10(" }, | { 0, 6, LOG10, "LOG", "Logarithm (base 10) (or INV)", "LOG10(", "ALOG10(" }, | |||
{ 0, 7, LOGE, "LN", "Natural logarithm (base e) (or INV)", "LOGe(", "ALOGe" }, | { 0, 7, LOGE, "LN", "Natural logarithm (base e) (or INV)", "LOGe(", "ALOGe" }, | |||
skipping to change at line 121 | skipping to change at line 105 | |||
{ 0, 1, INTST, "i", "Interest rate in % per period (or INV)", "", "" }, | { 0, 1, INTST, "i", "Interest rate in % per period (or INV)", "", "" }, | |||
{ 0, 2, PVAL, "PV", "Present value (or INV)", "", "" }, | { 0, 2, PVAL, "PV", "Present value (or INV)", "", "" }, | |||
{ 0, 3, PMT, "PMT", "Payment (or INV)", "", "" }, | { 0, 3, PMT, "PMT", "Payment (or INV)", "", "" }, | |||
{ 0, 4, FVAL, "FV", "Future value (or INV)", "", "" }, | { 0, 4, FVAL, "FV", "Future value (or INV)", "", "" }, | |||
{ 0, 5, FCLR, "CLf", "Clear compound interest registers (5-9)", "", "" }, | { 0, 5, FCLR, "CLf", "Clear compound interest registers (5-9)", "", "" }, | |||
{ 0, 6, LOG10, "LOG", "Logarithm (base 10) (or INV)", "LOG(", " 10^" }, | { 0, 6, LOG10, "LOG", "Logarithm (base 10) (or INV)", "LOG(", " 10^" }, | |||
{ 0, 7, LOGE, "LN", "Natural logarithm (base e)", "LN(", " e^" }, | { 0, 7, LOGE, "LN", "Natural logarithm (base e)", "LN(", " e^" }, | |||
{ 1, 0, TIMES12, "x12", "X times 12", "x12 ", "/12 " }, | { 1, 0, TIMES12, "x12", "X times 12", "x12 ", "/12 " }, | |||
{ 1, 1, DIVIDE12, "/12", "X divided by 12", "/12 ", "x12 " }, | { 1, 1, DIVIDE12, "/12", "X divided by 12", "/12 ", "x12 " }, | |||
{ 1, 2, BEGIN, "B/E", "Toggle Annuity at beginning of period", "", "" }, | { 1, 2, BEGIN, "B/E", "Toggle Annuity at beginning of period", "", "" }, | |||
{ 1, 3, DYS, "DYS", "Days between dates", " DYS ", "" }, | { 1, 3, DYS, "DYS", "Days between dates YYYY.MMDD (or INV: date(y) + days(x))" , " DYS ", "" }, | |||
{ 1, 4, TDY, "TDY", "Today's date", " TDY ", "" }, | { 1, 4, TDY, "TDY", "Today's date", " TDY ", "" }, | |||
{ 1, 5, PI, "PI", "PI", "PI ", "" }, | { 1, 5, PI, "PI", "PI", "PI ", "" }, | |||
{ 1, 6, INT, "INT", "Integer part of X", "INT(", "" }, | { 1, 6, INT, "INT", "Integer part of X", "INT(", "" }, | |||
{ 1, 7, FRC, "FRC", "Fractional part of X", "FRC(", "" }, | { 1, 7, FRC, "FRC", "Fractional part of X", "FRC(", "" }, | |||
{ 2, 0, INV, "INV", "Invert functions", "", "" }, | { 2, 0, INV, "INV", "Invert functions", "", "" }, | |||
{ 2, 1, NOP, " ", " ", "", "" }, | { 2, 1, NOP, " ", " ", "", "" }, | |||
{ 2, 2, NOP, " ", " ", "", "" }, | { 2, 2, NOP, " ", " ", "", "" }, | |||
{ 2, 3, NOP, " ", " ", "", "" }, | { 2, 3, NOP, " ", " ", "", "" }, | |||
{ 2, 4, NOP, " ", " ", "", "" }, | { 2, 4, NOP, " ", " ", "", "" }, | |||
{ 2, 5, E, "e", "Base of natural logs", " e ", "" }, | { 2, 5, E, "e", "Base of natural logs", " e ", "" }, | |||
skipping to change at line 206 | skipping to change at line 190 | |||
{ 0, 2, PROG, "PRO", "Programmers mode", "", "" }, | { 0, 2, PROG, "PRO", "Programmers mode", "", "" }, | |||
{ 0, 3, NOP, " ", " ", "", "" }, | { 0, 3, NOP, " ", " ", "", "" }, | |||
{ 0, 4, 'E', "E", " ", "E", "" }, | { 0, 4, 'E', "E", " ", "E", "" }, | |||
{ 0, 5, PERCENT, "%", "X percent of Y (or INV)", "%", "" }, | { 0, 5, PERCENT, "%", "X percent of Y (or INV)", "%", "" }, | |||
{ 1, 0, YTOX, "y^X", "Y to the power of X", "^", "" }, | { 1, 0, YTOX, "y^X", "Y to the power of X", "^", "" }, | |||
{ 1, 1, SQR, "x2", "X squared", "^2 ", "" }, | { 1, 1, SQR, "x2", "X squared", "^2 ", "" }, | |||
{ 1, 2, ROOT, "SQRT", "Square root of X", "SQRT(", "" }, | { 1, 2, ROOT, "SQRT", "Square root of X", "SQRT(", "" }, | |||
{ 1, 3, NOP, " ", " ", "", "" }, | { 1, 3, NOP, " ", " ", "", "" }, | |||
{ 1, 4, RECI, "1/X", "Reciprocal of X", " 1/", "" }, | { 1, 4, RECI, "1/X", "Reciprocal of X", " 1/", "" }, | |||
{ 1, 5, PERCENTCH, "%CH", "Percentage change from Y to X (or INV)", "%ch ", "" }, | { 1, 5, PERCENTCH, "%CH", "Percentage change from Y to X (or INV)", "%ch ", "" }, | |||
{ 2, 0, FIX, "FIX", "Floating point notation", "", "" }, | { 2, 0, FIXFORMAT, "FIX", "Floating point notation", "", "" }, | |||
{ 2, 1, SCIFORMAT, "SCI", "Scientific notation", "", "" }, | { 2, 1, SCIFORMAT, "SCI", "Scientific notation", "", "" }, | |||
{ 2, 2, ENG, "ENG", "Engineering notation", "", "" }, | { 2, 2, ENGFORMAT, "ENG", "Engineering notation", "", "" }, | |||
{ 2, 3, '7', "7", " ", "7", "" }, | { 2, 3, '7', "7", " ", "7", "" }, | |||
{ 2, 4, '8', "8", " ", "8", "" }, | { 2, 4, '8', "8", " ", "8", "" }, | |||
{ 2, 5, '9', "9", " ", "9", "" }, | { 2, 5, '9', "9", " ", "9", "" }, | |||
{ 3, 0, STORE, "STO", "Store X to a register", "", "" }, | { 3, 0, STORE, "STO", "Store X to a register", "", "" }, | |||
{ 3, 1, STOPLUS, "ST+", "Add X to a register", "", "" }, | { 3, 1, STOPLUS, "ST+", "Add X to a register", "", "" }, | |||
{ 3, 2, STOMINUS, "ST-", "Subtract X from a register", "", "" }, | { 3, 2, STOMINUS, "ST-", "Subtract X from a register", "", "" }, | |||
{ 3, 3, '4', "4", " ", "4", "" }, | { 3, 3, '4', "4", " ", "4", "" }, | |||
{ 3, 4, '5', "5", " ", "5", "" }, | { 3, 4, '5', "5", " ", "5", "" }, | |||
{ 3, 5, '6', "6", " ", "6", "" }, | { 3, 5, '6', "6", " ", "6", "" }, | |||
{ 4, 0, RECALL, "RCL", "Recall from a register", "", "" }, | { 4, 0, RECALL, "RCL", "Recall from a register", "", "" }, | |||
skipping to change at line 276 | skipping to change at line 260 | |||
{ 5, 2, BACKSPACE, "BSP", "Backspace", "", "" }, | { 5, 2, BACKSPACE, "BSP", "Backspace", "", "" }, | |||
{ 5, 3, '0', "0", " ", "0", "" }, | { 5, 3, '0', "0", " ", "0", "" }, | |||
{ 5, 4, '.', ".", " ", ".", "" }, | { 5, 4, '.', ".", " ", ".", "" }, | |||
{ 5, 5, CHS, "CHS", "Change sign of X", "", "" }, | { 5, 5, CHS, "CHS", "Change sign of X", "", "" }, | |||
{ -1, -1, 0, " ", " ", "", "" } | { -1, -1, 0, " ", " ", "", "" } | |||
}; | }; | |||
void | void | |||
set_x(char *inbuf) { | set_x(char *inbuf) { | |||
insertedTextIsFromDcalc = 1; | insertedTextIsFromDcalc = 1; | |||
gtk_entry_set_text(entryX, inbuf); | gtk_entry_set_text(entry_x, inbuf); | |||
insertedTextIsFromDcalc = 0; | insertedTextIsFromDcalc = 0; | |||
} | } | |||
void | void | |||
append_x(char *inbuf) { | append_x(char *inbuf) { | |||
char *oldbuf, *newbuf; | ||||
insertedTextIsFromDcalc = 1; | insertedTextIsFromDcalc = 1; | |||
gtk_entry_append_text(entryX, inbuf); | oldbuf = (char *)gtk_entry_get_text(entry_x); | |||
newbuf = malloc(strlen(oldbuf) + strlen(inbuf) + 1); | ||||
strcpy(newbuf, oldbuf); | ||||
strcat(newbuf, inbuf); | ||||
gtk_entry_set_text(entry_x, newbuf); | ||||
free(newbuf); | ||||
insertedTextIsFromDcalc = 0; | insertedTextIsFromDcalc = 0; | |||
} | } | |||
const char *get_x() { | const char *get_x() { | |||
return(gtk_entry_get_text(entryX)); | return(gtk_entry_get_text(entry_x)); | |||
} | } | |||
static int | static int | |||
prepareKey(dcalc_button *b) { | prepareKey(dcalc_button *b) { | |||
if (!algebraic_mode) | if (!algebraic_mode) | |||
return(b->command); /* RPN is too easy! */ | return(b->command); /* RPN is too easy! */ | |||
switch (b->command) { | switch (b->command) { | |||
/* These needY: */ | /* These needY: */ | |||
case COMB: | case COMB: | |||
skipping to change at line 460 | skipping to change at line 451 | |||
int | int | |||
button_command(dcalc_button *b, int i, int j) { | button_command(dcalc_button *b, int i, int j) { | |||
while (b != NULL && b->i >= 0) | while (b != NULL && b->i >= 0) | |||
if (b->i == i && b->j == j) | if (b->i == i && b->j == j) | |||
return(prepareKey(b)); | return(prepareKey(b)); | |||
else | else | |||
b++; | b++; | |||
return(NOP); | return(NOP); | |||
} | } | |||
GtkWidget *get_widget(char *location, char *widget_name) { | ||||
GtkWidget *retval = (GtkWidget *) gtk_builder_get_object(builder, widget_nam | ||||
e); | ||||
if (!retval) { | ||||
fprintf(stderr, "gdcalc: %s(): Can't find widget %s\n", location, widget | ||||
_name); | ||||
exit(1); | ||||
} | ||||
return retval; | ||||
} | ||||
static void display_panel(char which_panel, dcalc_button *b) { | static void display_panel(char which_panel, dcalc_button *b) { | |||
gpointer g; | GtkWidget *g; | |||
char widget_name[80]; | char widget_name[80]; | |||
if (which_panel == 'R') | if (which_panel == 'R') | |||
r_buttons = b; | r_buttons = b; | |||
else | else | |||
l_buttons = b; | l_buttons = b; | |||
while (b != NULL && b->i >= 0) { | while (b != NULL && b->i >= 0) { | |||
sprintf(widget_name, "%c%d_%d", which_panel, b->i, b->j); | sprintf(widget_name, "%c%d_%d", which_panel, b->i, b->j); | |||
g = gtk_object_get_data(GTK_OBJECT (main_window), widget_name); | g = get_widget("display_panel", widget_name); | |||
if (g) { | if (g) { | |||
GtkWidget *child; | if (GTK_IS_LABEL (g)) { | |||
GtkTooltipsData *tooltipsdata; | gtk_label_set_text (GTK_LABEL (g), b->label); | |||
} else { // a button | ||||
child = GTK_BIN (g)->child; | gtk_button_set_label(GTK_BUTTON(g), b->label); | |||
if (GTK_IS_LABEL (child)) { | } | |||
gtk_label_set_text (GTK_LABEL (child), b->label); | if (b->tooltip[0] == 0) { | |||
} | gtk_widget_set_has_tooltip(g, FALSE); | |||
tooltipsdata = gtk_tooltips_data_get(g); | } else { | |||
if (tooltipsdata) { | gtk_widget_set_has_tooltip(g, TRUE); | |||
if (b->tooltip[0] == 0) { | gtk_widget_set_tooltip_text(g, b->tooltip); | |||
gtk_tooltips_disable(tooltipsdata->tooltips); | } | |||
} else { | } | |||
gtk_tooltips_enable(tooltipsdata->tooltips); | ||||
gtk_tooltips_set_tip(tooltipsdata->tooltips, g, b->tooltip, | ||||
NULL); | ||||
} | ||||
} else | ||||
fprintf(stderr, "gdcalc: Can't find tooltip for w | ||||
idget %s\n", widget_name); | ||||
} else | ||||
fprintf(stderr, "gdcalc: Can't find widget %s\n", widget_ | ||||
name); | ||||
b++; | b++; | |||
} | } | |||
} | } | |||
void display_buttons(int c) { | void display_buttons(int c) { | |||
GtkWidget *w; | GtkWidget *w; | |||
if (c == PROG) { | if (c == PROG) { | |||
display_panel('R', int_buttons); | display_panel('R', int_buttons); | |||
display_panel('L', prog_buttons); | display_panel('L', prog_buttons); | |||
skipping to change at line 543 | skipping to change at line 536 | |||
strcpy(float_buttons[1].label, "STA"); | strcpy(float_buttons[1].label, "STA"); | |||
strcpy(float_buttons[1].tooltip, "Statistics mode"); | strcpy(float_buttons[1].tooltip, "Statistics mode"); | |||
float_buttons[2].command = PROG; | float_buttons[2].command = PROG; | |||
strcpy(float_buttons[2].label, "PRO"); | strcpy(float_buttons[2].label, "PRO"); | |||
strcpy(float_buttons[2].tooltip, "Programmers mode"); | strcpy(float_buttons[2].tooltip, "Programmers mode"); | |||
display_panel('L', sci_buttons); | display_panel('L', sci_buttons); | |||
break; | break; | |||
} | } | |||
display_panel('R', float_buttons); | display_panel('R', float_buttons); | |||
} | } | |||
w = gtk_object_get_data(GTK_OBJECT(main_window), "degree"); | w = get_widget("display_buttons","degree"); | |||
if (w) | gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | |||
gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: can't find degree menu item\n"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "radians"); | w = get_widget("display_buttons","radians"); | |||
if (w) | gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | |||
gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: can't find radians menu item\n"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "annuity_in_advance"); | w = get_widget("display_buttons","annuity_in_advance"); | |||
if (w) | gtk_widget_set_sensitive(w, (c==FIN)? 1: 0); | |||
gtk_widget_set_sensitive(w, (c==FIN)? 1: 0); | ||||
else | ||||
fprintf(stderr, "gdcalc: can't find annuity menu item\n"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "convert"); | w = get_widget("display_buttons","convert_dialog"); | |||
if (w) | gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | |||
gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: can't find convert menu item\n"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "fixed_point_numbering") | w = get_widget("display_buttons","fixed_point_numbering"); | |||
; | gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | |||
if (w) | ||||
gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: can't find fixed_point_mode menu item\n" | ||||
); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "engineering_numbering") | w = get_widget("display_buttons","engineering_numbering"); | |||
; | gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | |||
if (w) | ||||
gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: can't find engineering_mode menu item\n" | ||||
); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "scientific_numbering"); | w = get_widget("display_buttons","scientific_numbering"); | |||
if (w) | gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | |||
gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: can't find scientific_numberingmenu item | ||||
\n"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "places"); | w = get_widget("display_buttons","places"); | |||
if (w) | gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | |||
gtk_widget_set_sensitive(w, (c==PROG)? 0: 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: can't find places menu item\n"); | ||||
#ifdef HAS_ALGEBRAIC_MODE | #ifdef HAS_ALGEBRAIC_MODE | |||
if (algebraic_mode) { | if (algebraic_mode) { | |||
on_algebraic_activate(NULL, NULL); | on_algebraic_activate(NULL, NULL); | |||
} else { | } else { | |||
on_rpn_activate(NULL, NULL); | on_rpn_activate(NULL, NULL); | |||
} | } | |||
#endif | #endif | |||
} | } | |||
static void print_number(char *buf, char *name) | static void print_number(char *buf, char *name) | |||
{ | { | |||
gpointer g; | GtkWidget *g; | |||
g = gtk_object_get_data(GTK_OBJECT (main_window), name); | g = get_widget("print_number", name); | |||
gtk_entry_set_text (GTK_ENTRY (g), buf); | gtk_entry_set_text (GTK_ENTRY (g), buf); | |||
} | } | |||
void print_x(char *buf) { | void print_x(char *buf) { | |||
set_x(buf); | set_x(buf); | |||
} | } | |||
void | void | |||
add_x(char *buf) { | add_x(char *buf) { | |||
skipping to change at line 648 | skipping to change at line 617 | |||
prep_for_output(outbuf); | prep_for_output(outbuf); | |||
print_number(outbuf, "entry_T"); | print_number(outbuf, "entry_T"); | |||
fmt_base(outbuf, liReg, lfReg); | fmt_base(outbuf, liReg, lfReg); | |||
prep_for_output(outbuf); | prep_for_output(outbuf); | |||
print_number(outbuf, "entry_L"); | print_number(outbuf, "entry_L"); | |||
} | } | |||
/* only used for the bell ... */ | /* only used for the bell ... */ | |||
void put_a_char(int i) { | void put_a_char(int i) { | |||
gdk_beep(); | // gdk_beep(); | |||
} | } | |||
static char *printBase() { | static char *printBase() { | |||
if (mode == PROG) | if (mode == PROG) | |||
switch (intmode) { | switch (intmode) { | |||
case ASCIIM: | case ASCIIM: | |||
return("prog:asc: "); | return("prog:asc: "); | |||
case BIN: | case BIN: | |||
return("prog:bin: "); | return("prog:bin: "); | |||
case OCT: | case OCT: | |||
skipping to change at line 701 | skipping to change at line 670 | |||
gpointer status_bar; | gpointer status_bar; | |||
char status[200]; | char status[200]; | |||
strcpy(status, printBase()); | strcpy(status, printBase()); | |||
if (mode != PROG) { | if (mode != PROG) { | |||
strcat(status, printDeg()); | strcat(status, printDeg()); | |||
} | } | |||
strcat(status, printInv()); | strcat(status, printInv()); | |||
strcat(status, " "); | strcat(status, " "); | |||
strcat(status, buf); | strcat(status, buf); | |||
status_bar = gtk_object_get_data(GTK_OBJECT (main_window), _("statusbar") ); | status_bar = get_widget("msg", "statusbar"); | |||
context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(status_bar), | context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(status_bar), | |||
"Statusbar example"); | "Statusbar example"); | |||
gtk_statusbar_push( GTK_STATUSBAR(status_bar), context_id, status); | gtk_statusbar_push( GTK_STATUSBAR(status_bar), context_id, status); | |||
} | } | |||
void clear_msg() { | void clear_msg() { | |||
msg(""); | msg(""); | |||
} | } | |||
void print_inv() { | void print_inv() { | |||
GtkButton *invert_button; | ||||
invert_button = (GtkButton *) get_widget("main", "L2_0"); | ||||
gtk_button_set_relief(invert_button, invert? GTK_RELIEF_NONE: GTK_RELIEF_ NORMAL); | gtk_button_set_relief(invert_button, invert? GTK_RELIEF_NONE: GTK_RELIEF_ NORMAL); | |||
} | } | |||
/* These not needed for GTK version: */ | /* These not needed for GTK version: */ | |||
void prinbase() {}; | void prinbase() {}; | |||
void print_string(char *buf) {} | void print_string(char *buf) {} | |||
void print_deg(){} | void print_deg(){} | |||
void pop_up_help(void) {} | void pop_up_help(void) {} | |||
void os_raw_mode(int i) { raw_mode = 0 /* i */; } | void os_raw_mode(int i) { raw_mode = 0 /* i */; } | |||
void os_init(void) {} | void os_init(void) {} | |||
void os_term(void) {gtk_main_quit();} | void os_term(void) {gtk_main_quit();} | |||
int get_a_char(int *c) {return 0;} | int get_a_char(int *c) {return 0;} | |||
int dialog(char *buf) { | int dialog(char *buf) { | |||
GtkWidget *dialog_popup; | GtkWidget *dialog_popup; | |||
gpointer g; | GtkWidget *g; | |||
int reply; | int reply; | |||
dialog_popup = create_gen_dialog (); | dialog_popup = get_widget("dialog", "gen_dialog"); | |||
g = gtk_object_get_data(GTK_OBJECT (dialog_popup), _("msg")); | g = get_widget("dialog", "msg"); | |||
gtk_label_set_text(GTK_LABEL(g), buf); | gtk_label_set_text(GTK_LABEL(g), buf); | |||
reply = gtk_dialog_run(GTK_DIALOG(dialog_popup)); | reply = gtk_dialog_run(GTK_DIALOG(dialog_popup)); | |||
gtk_widget_destroy(dialog_popup); | gtk_widget_hide(dialog_popup); | |||
return (reply==0)? 'Y': 'N'; | return (reply==0)? 'Y': 'N'; | |||
} | } | |||
int places(char *buf) { | int places(char *buf) { | |||
GtkWidget *places_dialog; | GtkWidget *places_dialog; | |||
GtkSpinButton *spinbutton; | GtkSpinButton *spinbutton; | |||
int reply; | int reply; | |||
gfloat decplacesf = decplaces; | gfloat decplacesf = decplaces; | |||
places_dialog = create_places (); | places_dialog = get_widget("places", "places_dialog"); | |||
spinbutton = gtk_object_get_data(GTK_OBJECT (places_dialog), _("places_sp | spinbutton = (GtkSpinButton *) get_widget("places", "places_spinbutton"); | |||
inbutton")); | ||||
gtk_spin_button_set_value(spinbutton, decplacesf); | gtk_spin_button_set_value(spinbutton, decplacesf); | |||
reply = gtk_dialog_run(GTK_DIALOG(places_dialog)); | reply = gtk_dialog_run(GTK_DIALOG(places_dialog)); | |||
if (reply == 0) | if (reply == 0) { | |||
reply = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutt on)); | reply = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutt on)); | |||
else | ||||
decplaces = reply; | ||||
dispnums(); | ||||
} else | ||||
reply = -1; | reply = -1; | |||
gtk_widget_destroy(places_dialog); | gtk_widget_hide(places_dialog); | |||
return reply; | return reply; | |||
} | } | |||
int eval(char *buf, char *expr) { | int eval(char *buf, char *expr) { | |||
GtkEntry *eval_expr_entry; | GtkEntry *eval_expr_entry; | |||
GtkWidget *eval_dialog; | ||||
int reply; | int reply; | |||
eval_dialog = create_eval (); | eval_dialog = get_widget("eval", "eval_dialog"); | |||
eval_expr_entry = gtk_object_get_data(GTK_OBJECT (eval_dialog), _("eval_e | eval_expr_entry = (GtkEntry *) get_widget("eval", "eval_expr"); | |||
xpr")); | ||||
gtk_entry_set_text( eval_expr_entry, buf); | gtk_entry_set_text( eval_expr_entry, buf); | |||
reply = gtk_dialog_run(GTK_DIALOG(eval_dialog)); | reply = gtk_dialog_run(GTK_DIALOG(eval_dialog)); | |||
if (reply == 0) { | if (reply == 0) { | |||
strcpy(expr, gtk_entry_get_text(eval_expr_entry)); | strcpy(expr, gtk_entry_get_text(eval_expr_entry)); | |||
} else | } else | |||
reply = -1; | reply = -1; | |||
gtk_widget_destroy(eval_dialog); | gtk_widget_hide(eval_dialog); | |||
return reply; | return reply; | |||
} | } | |||
static void | ||||
setFont(char *widgetName, GtkWidget *main_window, GdkFont *newFont) { | ||||
GtkWidget *widget; | ||||
GtkStyle *style; | ||||
widget = gtk_object_get_data(GTK_OBJECT (main_window), widgetName); | ||||
if (!widget) { | ||||
fprintf(stderr, "gdcalc: setFont: can't find %s\n", widgetName); | ||||
return; | ||||
} | ||||
style = gtk_widget_get_style(widget); | ||||
if (!style) { | ||||
fprintf(stderr, "gdcalc: setFont: can't find for widget %s\n", wi | ||||
dgetName); | ||||
return; | ||||
} | ||||
gdk_font_unref (style->private_font); | ||||
style->private_font = newFont; | ||||
gdk_font_ref (style->private_font); | ||||
gtk_widget_set_style (widget, style); | ||||
} | ||||
void | ||||
setPlusMinusFont(char *fontName) { | ||||
GdkFont *newFont; | ||||
newFont = gdk_font_load(fontName); | ||||
if (!newFont) { | ||||
fprintf(stderr, "gdcalc: can't find font \"%s\"\n", fontName); | ||||
return; | ||||
} | ||||
setFont("Equals", main_window, newFont); | ||||
setFont("LeftBrace", main_window, newFont); | ||||
setFont("RightBrace", main_window, newFont); | ||||
setFont("Plus", main_window, newFont); | ||||
setFont("Minus", main_window, newFont); | ||||
setFont("Mult", main_window, newFont); | ||||
setFont("Divide", main_window, newFont); | ||||
} | ||||
void | ||||
setButtonFont(char *fontName) { | ||||
GdkFont *newFont; | ||||
int row, col; | ||||
char widgetName[100]; | ||||
newFont = gdk_font_load(fontName); | ||||
if (!newFont) { | ||||
fprintf(stderr, "gdcalc: can't find font \"%s\"\n", fontName); | ||||
return; | ||||
} | ||||
for (row = 0; row < 3; row++) | ||||
for (col = 0; col < 8; col++) { | ||||
sprintf(widgetName, "L%d_%d", row, col); | ||||
setFont(widgetName, main_window, newFont); | ||||
} | ||||
for (row = 0; row < 6; row++) | ||||
for (col = 0; col < 6; col++) { | ||||
sprintf(widgetName, "R%d_%d", row, col); | ||||
setFont(widgetName, main_window, newFont); | ||||
} | ||||
setFont("Enter", main_window, newFont); | ||||
} | ||||
#ifdef RUNTIME_FONT_CHANGES_ARE_WORKING | ||||
void | ||||
fixFont(char *newFont, GtkWidget *this_main_window, char *name) { | ||||
GdkFont *fixed_font; | ||||
fixed_font = gdk_font_load(newFont); | ||||
if (!fixed_font) { | ||||
fprintf(stderr, "gdcalc: fixFont: can't find font \"%s\"\n", newF | ||||
ont); | ||||
return; | ||||
} | ||||
setFont(name, this_main_window, fixed_font); | ||||
} | ||||
#endif | ||||
static void xdispreg(GtkWidget *dialog, int i) { | static void xdispreg(GtkWidget *dialog, int i) { | |||
char labelname[80], outbuf[80]; | char labelname[80], outbuf[80]; | |||
GtkWidget *entry; | GtkWidget *entry; | |||
if (dialog) { | if (dialog) { | |||
sprintf(labelname, "mem%d", i); | sprintf(labelname, "mem%d", i); | |||
#ifdef RUNTIME_FONT_CHANGES_ARE_WORKING | entry = get_widget("xdispreg", labelname); | |||
fixFont(calculatorFont, dialog, labelname); | ||||
#endif | ||||
entry = gtk_object_get_data(GTK_OBJECT (dialog), labelname); | ||||
fmt_base(outbuf, reg[i], regf[i]); | fmt_base(outbuf, reg[i], regf[i]); | |||
prep_for_output(outbuf); | prep_for_output(outbuf); | |||
if (l_buttons == fin_buttons) | if (l_buttons == fin_buttons) | |||
switch (i) { | switch (i) { | |||
case FIN_NUM_REG: strcat(outbuf, " = periods"); break; | case FIN_NUM_REG: strcat(outbuf, " = periods"); break; | |||
case FIN_INT_REG: strcat(outbuf, " = interest (%)"); brea k; | case FIN_INT_REG: strcat(outbuf, " = interest (%)"); brea k; | |||
case FIN_PVAL_REG: strcat(outbuf, " = PVal"); break; | case FIN_PVAL_REG: strcat(outbuf, " = PVal"); break; | |||
case FIN_PMT_REG: strcat(outbuf, " = payment"); break; | case FIN_PMT_REG: strcat(outbuf, " = payment"); break; | |||
case FIN_FVAL_REG: strcat(outbuf, " = FVal"); break; | case FIN_FVAL_REG: strcat(outbuf, " = FVal"); break; | |||
} | } | |||
skipping to change at line 893 | skipping to change at line 788 | |||
case STAT_SUMY_REG: strcat(outbuf, " = sum of Y's"); brea k; | case STAT_SUMY_REG: strcat(outbuf, " = sum of Y's"); brea k; | |||
case STAT_SUMY2_REG: strcat(outbuf, " = sum of y2's"); br eak; | case STAT_SUMY2_REG: strcat(outbuf, " = sum of y2's"); br eak; | |||
case STAT_SUMXY_REG: strcat(outbuf, " = sum of XY's"); br eak; | case STAT_SUMXY_REG: strcat(outbuf, " = sum of XY's"); br eak; | |||
} | } | |||
gtk_entry_set_text(GTK_ENTRY(entry), outbuf); | gtk_entry_set_text(GTK_ENTRY(entry), outbuf); | |||
} | } | |||
} | } | |||
void dispreg(int i) { | void dispreg(int i) { | |||
xdispreg(registers, i); | xdispreg(registers_popup, i); | |||
} | } | |||
void dispregs(void) { | void dispregs(void) { | |||
int i; | int i; | |||
if (registers) | if (registers_popup) { | |||
for (i = 0; i < NUMREGS; i++) | for (i = 0; i < NUMREGS; i++) | |||
dispreg(i); | dispreg(i); | |||
} | ||||
} | } | |||
void toggle_registers(void) { | void toggle_registers(void) { | |||
if (!registers) { | static int toggle_registers_recursing = 0; | |||
registers = create_mem_dialog(); | ||||
if (toggle_registers_recursing) { | ||||
/* it recurses on ..._set_active(). I don't have the handler | ||||
* as they were set up in gtk_builder_connect_signals() so I | ||||
* can't disable the signal!! | ||||
*/ | ||||
return; | ||||
} | ||||
GtkCheckMenuItem *register_window_menu_item = (GtkCheckMenuItem *) get_widge | ||||
t("toggle_registers", | ||||
"register_window_menu_item"); | ||||
toggle_registers_recursing = 1; | ||||
if (!registers_popup) { | ||||
GtkLabel *mem_label = GTK_LABEL(get_widget("toggle_registers", "mem_labe | ||||
l")); | ||||
registers_popup = get_widget("toggle_registers", "mem_dialog"); | ||||
dispregs(); | dispregs(); | |||
gtk_widget_show(registers); | gtk_label_set_text(mem_label, registers_label); | |||
gtk_widget_show(registers_popup); | ||||
gtk_window_set_title(GTK_WINDOW(registers_popup), registers_label); | ||||
gtk_check_menu_item_set_active(register_window_menu_item, TRUE); | ||||
} else { | } else { | |||
gtk_widget_destroy(registers); | gtk_widget_hide(registers_popup); | |||
registers = NULL; | registers_popup = NULL; | |||
gtk_check_menu_item_set_active(register_window_menu_item, FALSE); | ||||
} | } | |||
toggle_registers_recursing = 0; | ||||
} | } | |||
void pop_up_reg(void) { | void pop_up_reg(void) { | |||
toggle_registers(); | toggle_registers(); | |||
} | } | |||
static int do_mem_dialog(char *buf) { | static int do_mem_dialog(char *buf) { | |||
int reply, i; | int reply, i; | |||
GtkLabel *mem_label = GTK_LABEL(get_widget("do_mem_dialog", "mem_label")); | ||||
char tbuf[MAXPATHLEN]; | ||||
mem_dialog = create_mem_dialog (); | strcpy(tbuf, buf); | |||
gtk_window_set_title (GTK_WINDOW (mem_dialog), buf); | strcat(tbuf, registers_label); | |||
mem_dialog = get_widget("do_mem_dialog", "mem_dialog"); | ||||
gtk_window_set_title(GTK_WINDOW (mem_dialog), buf); | ||||
gtk_label_set_text(mem_label, tbuf); | ||||
for (i=0; i < NUMREGS; i++) | for (i=0; i < NUMREGS; i++) | |||
xdispreg(mem_dialog, i); | xdispreg(mem_dialog, i); | |||
reply = gtk_dialog_run(GTK_DIALOG(mem_dialog)); | reply = gtk_dialog_run(GTK_DIALOG(mem_dialog)); | |||
gtk_widget_destroy(mem_dialog); | ||||
return (reply==0)? -1: mem_value+'0'; | return (reply==0)? -1: mem_value+'0'; | |||
} | } | |||
int store(char *buf) { | int store(char *buf) { | |||
msg(buf); | ||||
return(do_mem_dialog("Store...")); | return(do_mem_dialog("Store...")); | |||
} | } | |||
int recall(char *buf) { | int recall(char *buf) { | |||
msg(buf); | ||||
return(do_mem_dialog("Recall...")); | return(do_mem_dialog("Recall...")); | |||
} | } | |||
void on_algebraic_activate(); | void on_algebraic_activate(); | |||
static void | static void | |||
setName(char *widgetName, char *name) { | set_name(char *widgetName, char *name) { | |||
GtkWidget *w; | GtkWidget *w; | |||
w = (GtkWidget *) gtk_object_get_data(GTK_OBJECT (main_window), widgetNa | w = get_widget("set_name", widgetName); | |||
me); | ||||
if (!w) { | ||||
fprintf(stderr, "gdcalc: Can't find widget %s\n", widgetName); | ||||
return; | ||||
} | ||||
gtk_widget_set_name(w, name); | gtk_widget_set_name(w, name); | |||
} | } | |||
int | int | |||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | |||
{ | { | |||
char *cfont = NULL, *bfont = NULL, *pfont = NULL; | GtkWidget *w = NULL; | |||
char rcFileName[MAXPATHLEN]; | typedef char Filename[MAXPATHLEN]; | |||
struct poptOption options[] = { | int retval; | |||
{"calculatorFont", 'f', POPT_ARG_STRING, NULL, 0, "Font for numbe | Filename *filename; | |||
rs", "FONT"}, | ||||
{"buttonFont", 'b', POPT_ARG_STRING, NULL, 0, "Font for buttons", | gtk_init(&argc, &argv); | |||
"FONT"}, | ||||
{"plusMinusFont", 'p', POPT_ARG_STRING, NULL, 0, "Font for +, - e | /* Pull in glade file */ | |||
tc", "FONT"}, | builder = gtk_builder_new(); | |||
{NULL, '\0', 0, NULL, 0, NULL, NULL} /* end the list */ | { | |||
}; | Filename glade_candidates[] = { | |||
GtkWidget *w; | PACKAGE_DATA_DIR "/gdcalc/gdcalc.glade", | |||
"./gdcalc.glade", | ||||
/* apparently not needed: | "../gdcalc.glade", | |||
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR); | "" | |||
textdomain (PACKAGE); | }; | |||
*/ | ||||
for (filename = glade_candidates; strlen(*filename); filename++) { | ||||
options[0].arg = &cfont; | retval = gtk_builder_add_from_file(builder, *filename, NULL); | |||
options[0].arg = &bfont; | if (retval) { | |||
options[0].arg = &pfont; | printf("gdcalc: using glade file '%s'\n", *filename); | |||
gnome_init_with_popt_table("gdcalc", VERSION, argc, argv, options, 0, NUL | break; | |||
L); | } | |||
printf("gdcalc: tried to read '%s' and failed\n", *filename); | ||||
if (cfont && *cfont) | } | |||
strcpy(calculatorFont, cfont); | if (retval == 0) { | |||
else | fprintf(stderr, "gdcalc: can't find the glade file\n"); | |||
strcpy(calculatorFont, "-misc-fixed-medium-r-*-*-14-*-*-*-*-*-*-* | exit(1); | |||
"); | } | |||
} | ||||
if (bfont && *bfont) | ||||
strcpy(buttonFont, bfont); | ||||
else | ||||
strcpy(buttonFont, "-misc-fixed-medium-r-*-*-14-*-*-*-*-*-*-*"); | ||||
if (pfont && *pfont) | ||||
strcpy(plusMinusFont, pfont); | ||||
else | ||||
strcpy(plusMinusFont, "-misc-fixed-medium-r-*-*-14-*-*-*-*-*-*-*" | ||||
); | ||||
main_window = create_main_window (); | /* get a handle for the main_window */ | |||
main_window = get_widget("main", "main_window"); | ||||
/* Assign names that can be picked up by resource file: */ | /* setup 'about' dialog */ | |||
setName("Plus", "big_button"); | w = get_widget("main", "about_dialog"); | |||
setName("Minus", "big_button"); | { | |||
setName("Mult", "big_button"); | GError *err = NULL; | |||
setName("Divide", "big_button"); | GdkPixbuf *icon; | |||
setName("LeftBrace", "big_button"); | Filename icon_candidates[] = { | |||
setName("RightBrace", "big_button"); | PACKAGE_DATA_DIR "/icons/hicolor/48x48/apps/gdcalc.png", | |||
setName("Equals", "big_button"); | "../pixmaps/HP-16C-48.png", | |||
/* setName("R5_4", "big_button"); .. decimal - distorts the display too m | "" | |||
uch */ | }; | |||
for (filename = icon_candidates; strlen(*filename); filename++) { | ||||
strcpy(rcFileName, getenv("HOME")); | err = NULL; | |||
strcat(rcFileName, "/.gdcalc.rc"); | icon = gdk_pixbuf_new_from_file(*filename, &err); | |||
gtk_rc_parse(rcFileName); | if (err == NULL && icon) { | |||
printf("gdcalc: using icon file '%s'\n", *filename); | ||||
#ifdef RUNTIME_FONT_CHANGES_ARE_WORKING | break; | |||
/* Load a fixed font for the numeric displays: */ | } | |||
fixFont(calculatorFont, main_window, "entry_X"); | if (err) g_error_free(err); | |||
fixFont(calculatorFont, main_window, "entry_Y"); | printf("gdcalc: tried to read icon from '%s' and failed\n", *filenam | |||
fixFont(calculatorFont, main_window, "entry_Z"); | e); | |||
fixFont(calculatorFont, main_window, "entry_T"); | /* but we can continue without an icon ... */ | |||
fixFont(calculatorFont, main_window, "entry_L"); | } | |||
gtk_about_dialog_set_logo((GtkAboutDialog *)w, icon); | ||||
} | ||||
setButtonFont(buttonFont); | /* Assign names that can be picked up by resource (CSS?) file: */ | |||
setPlusMinusFont(plusMinusFont); | set_name("Plus", "big_button"); | |||
#endif | set_name("Minus", "big_button"); | |||
set_name("Mult", "big_button"); | ||||
set_name("Divide", "big_button"); | ||||
set_name("LeftBrace", "big_button"); | ||||
set_name("RightBrace", "big_button"); | ||||
set_name("Equals", "big_button"); | ||||
/* set_name("R5_4", "big_button"); .. decimal - distorts the display too | ||||
much */ | ||||
gtk_widget_draw(main_window, NULL); | gtk_widget_show(main_window); | |||
gtk_widget_show (main_window); | ||||
entryX = (GtkEntry *) gtk_object_get_data(GTK_OBJECT (main_window), "entr | entry_x = (GtkEntry *) get_widget("main", "entry_X"); | |||
y_X"); | ||||
if (!entryX) { | ||||
fprintf(stderr, "gdcalc: Can't find widget entry_X\n"); | ||||
exit(1); | ||||
} | ||||
invert_button = (GtkButton *) gtk_object_get_data(GTK_OBJECT (main_window | ||||
), "L2_0"); | ||||
if (!invert_button) { | ||||
fprintf(stderr, "gdcalc: Can't find widget for invert button\n"); | ||||
exit(1); | ||||
} | ||||
/* initialise dcalc engine */ | ||||
initialise(); | initialise(); | |||
display_buttons(mode); | display_buttons(mode); | |||
/* gtk_check_menu_item_set_active actually calls the widgets activate met | /* gtk_check_menu_item_set_active actually calls the widgets | |||
hod - ie | activate method - ie simulating a button release!! This can | |||
simulating a button release!! This can lead to an infinite loop of inv | lead to an infinite loop of invocations - so we call | |||
ocations */ | gtk_builder_connect_signals() _after_ this code. */ | |||
w = gtk_object_get_data(GTK_OBJECT(main_window), | w = get_widget("main", | |||
(mode==SCI)? "scientific_ | (mode==SCI)? "scientific_mode": | |||
mode": | (mode==FIN)? "financial_mode": | |||
(mode==FIN)? "financial_m | (mode==STAT)? "statistics_mode": | |||
ode": | "programming_mode"); | |||
(mode==STAT)? "statistics | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1); | |||
_mode": | ||||
"programming_mode"); | w = get_widget("main", degree? "degree": "radians"); | |||
if (w) | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1); | |||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1); | ||||
else | w = get_widget("main", | |||
fprintf(stderr, "gdcalc: Can't find main mode item in menu\n"); | (floatmode==ENGFORMAT)? "engineering_numbering": | |||
(floatmode==SCIFORMAT)? "scientific_numbering": | ||||
"fixed_point_numbering"); | ||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), degree? "degree": "radia | w = get_widget("main","annuity_in_advance"); | |||
ns"); | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), finPayAt0? 1: 0); | |||
if (w) | ||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: Can't find degree/radians item in menu\n | ||||
"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), | w = get_widget("main",algebraic_mode?"algebraic":"rpn"); | |||
(floatmode==ENG)? "engine | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1); | |||
ering_numbering": | ||||
(floatmode==SCI)?"scienti | ||||
fic_numbering": | ||||
"fixed_point_numbering"); | ||||
if (w) | ||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: Can't find floating point item in menu\n | ||||
"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "annuity_in_advance"); | gtk_builder_connect_signals(builder, NULL); | |||
if (w) | ||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), finPayAt0? | ||||
1: 0); | ||||
else | ||||
fprintf(stderr, "gdcalc: Can't find annuity item in menu\n"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), algebraic_mode?"algebrai | ||||
c":"rpn"); | ||||
if (w) | ||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1); | ||||
else | ||||
fprintf(stderr, "gdcalc: Can't find algebraic/rpn item in menu\n" | ||||
); | ||||
#ifndef RUNTIME_FONT_CHANGES_ARE_WORKING | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "font"); | ||||
if (w) | ||||
gtk_widget_hide(w); | ||||
else | ||||
fprintf(stderr, "gdcalc: Can't find font item in menu\n"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "button_font"); | ||||
if (w) | ||||
gtk_widget_hide(w); | ||||
else | ||||
fprintf(stderr, "gdcalc: Can't find button_font item in menu\n"); | ||||
w = gtk_object_get_data(GTK_OBJECT(main_window), "plus_minus_font"); | ||||
if (w) | ||||
gtk_widget_hide(w); | ||||
else | ||||
fprintf(stderr, "gdcalc: Can't find plus_minus_font item in menu\ | ||||
n"); | ||||
#endif | ||||
dispnums(); | dispnums(); | |||
msg(DEF_SIG(VERSION)); | msg(DEF_SIG(VERSION)); | |||
if (registers) { /* set to 1 by readGuiSettings */ | if (registers_popup) { /* set to 1 by readGuiSettings */ | |||
registers = NULL; | registers_popup = NULL; | |||
toggle_registers(); | toggle_registers(); | |||
} | } | |||
{ | ||||
/* Pull in CSS style info */ | ||||
Filename css_candidates[] = { | ||||
"", | ||||
"/etc/gdcalc/gdcalc.css", | ||||
"" | ||||
}; | ||||
GError *err = NULL; | ||||
GtkCssProvider *css_provider = gtk_css_provider_new(); | ||||
GdkDisplay* Display = gdk_display_get_default(); | ||||
GdkScreen* Screen = gdk_display_get_default_screen(Display); | ||||
gtk_style_context_add_provider_for_screen(Screen, | ||||
GTK_STYLE_PROVIDER(css_provide | ||||
r), | ||||
GTK_STYLE_PROVIDER_PRIORITY_US | ||||
ER); | ||||
strcpy(css_candidates[0], getenv("HOME")); | ||||
strcat(css_candidates[0], "/.config/gdcalc/gdcalc.css"); | ||||
for (filename = css_candidates; strlen(*filename); filename++) { | ||||
err = NULL; | ||||
gtk_css_provider_load_from_path(css_provider, *filename, &err); | ||||
if (err == NULL) { | ||||
printf("gdcalc: using CSS style from '%s'\n", *filename); | ||||
break; | ||||
} | ||||
if (err) g_error_free(err); | ||||
printf("gdcalc: tried to read '%s' and failed\n", *filename); | ||||
} | ||||
} | ||||
gtk_main (); | gtk_main (); | |||
return 0; | return 0; | |||
} | } | |||
/* For emacs: */ | /* For emacs: */ | |||
/* Local Variables: */ | /* Local Variables: */ | |||
/* eval:(setq tab-width 4) */ | /* eval:(setq tab-width 4) */ | |||
/* End: */ | /* End: */ | |||
End of changes. 74 change blocks. | ||||
371 lines changed or deleted | 259 lines changed or added |