1 /*
2 
3 Copyright (C) 2002  Paul Wilkins
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 /* setup mode.c  by Paul Wilkins  2/8/98 */
21 
22 #include <stdio.h>
23 #include <string.h>
24 #include <gtk/gtk.h>
25 
26 #include "mode.h"
27 #include "number.h"
28 #include "complex.h"
29 
30 GtkWidget *ModeDisplay = NULL;
31 
32 int radixMode = RADIANS;
33 int polarMode = RECTANGULAR;
34 int baseMode = DECIMAL;
35 
getRadixMode()36 int getRadixMode(){
37    return radixMode;
38 }
setRadixMode(int mode)39 void setRadixMode(int mode){
40    if(mode == RADIANS) radixMode = RADIANS;
41    else if(mode == DEGREES) radixMode = DEGREES;
42    else printf("setRadixMode invalid mode\n");
43 }
44 
setPolarMode(int val)45 void setPolarMode(int val){
46    polarMode = val;
47 }
getPolarMode()48 int getPolarMode(){
49    return polarMode;
50 }
51 
52 
setBaseMode(int val)53 void setBaseMode(int val){
54    baseMode = val;
55 }
getBaseMode()56 int getBaseMode(){
57    return baseMode;
58 }
59 
60 
getModeDisplayString()61 char *getModeDisplayString(){
62    int rad_mode, pol_mode, base_mode;
63    static char buf[256];
64 
65    rad_mode = getRadixMode();
66    switch(rad_mode){
67       case DEGREES:
68          strcpy(buf, " Degrees   ");
69          break;
70       case RADIANS:
71          strcpy(buf, " Radians   ");
72          break;
73       default:
74          fprintf(stderr, "invalid Radix mode\n");
75          break;
76    }
77 
78    pol_mode = getPolarMode();
79    switch(pol_mode){
80       case RECTANGULAR:
81          strcat(buf, "Rectangular   ");
82          break;
83       case POLAR:
84          strcat(buf, "Polar   ");
85          break;
86       default:
87          fprintf(stderr, "invalid Polar mode\n");
88          break;
89    }
90 
91    base_mode = getBaseMode();
92    switch(base_mode){
93       case BINARY:
94          strcat(buf, "Binary");
95          break;
96       case OCTAL:
97          strcat(buf, "Octal");
98          break;
99       case DECIMAL:
100          strcat(buf, "Decimal");
101          break;
102       case DECIMAL_ENG:
103          strcat(buf, "Decimal-Eng");
104          break;
105       case HEXADECIMAL:
106          strcat(buf, "Hexadecimal");
107          break;
108       default:
109          fprintf(stderr, "invalid Base mode\n");
110          break;
111    }
112 
113    return buf;
114 }
115 
refreshModeDisplay()116 void refreshModeDisplay(){
117    char *str;
118 
119    str = getModeDisplayString();
120    gtk_label_set(GTK_LABEL(ModeDisplay), str);
121 
122 }
123 
setupModeDisplay(GtkWidget * parent)124 GtkWidget *setupModeDisplay(GtkWidget *parent){
125 
126    ModeDisplay = gtk_label_new(" ");
127    gtk_box_pack_start(GTK_BOX(parent), ModeDisplay, FALSE, FALSE, 0);
128    gtk_widget_show(ModeDisplay);
129 
130 
131    /* set the string */
132    refreshModeDisplay();
133 
134    return ModeDisplay;
135 }
136