[CALC] Improve headers inclusion.
[reactos.git] / base / applications / calc / calc.h
1 #ifndef __CALC_H__
2 #define __CALC_H__
3
4 #define WIN32_LEAN_AND_MEAN
5 #include <windows.h>
6 #include <tchar.h>
7 #include <commctrl.h>
8 #include <shellapi.h>
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <math.h>
13 #include <float.h>
14 #include <malloc.h>
15 #ifndef DISABLE_HTMLHELP_SUPPORT
16 #include <htmlhelp.h>
17 #endif
18 #include <limits.h>
19
20 /* Messages reserved for the main dialog */
21 #define WM_CLOSE_STATS (WM_APP+1)
22 #define WM_HANDLE_CLIPBOARD (WM_APP+2)
23 #define WM_INSERT_STAT (WM_APP+3)
24 #define WM_LOAD_STAT (WM_APP+4)
25 #define WM_START_CONV (WM_APP+5)
26 #define WM_HANDLE_FROM (WM_APP+6)
27 #define WM_HANDLE_TO (WM_APP+7)
28
29 /* GNU MULTI-PRECISION LIBRARY support */
30 #ifdef ENABLE_MULTI_PRECISION
31 #include "mpfr.h"
32
33 #ifndef MPFR_DEFAULT_RND
34 #define MPFR_DEFAULT_RND mpfr_get_default_rounding_mode ()
35 #endif
36
37 #define LOCAL_EXP_SIZE 100000000L
38 #else
39
40 #define LOCAL_EXP_SIZE 10000L
41
42 #endif
43
44 #include "resource.h"
45
46 #ifndef IDC_STATIC
47 #define IDC_STATIC ((DWORD)-1)
48 #endif
49
50 #define CALC_VERSION _T("1.12")
51
52 #define MAX_CALC_SIZE 256
53
54 /*#define USE_KEYBOARD_HOOK*/
55
56 #define SIZEOF(_ar) (sizeof(_ar)/sizeof(_ar[1]))
57
58 // RPN.C
59
60 enum {
61 RPN_OPERATOR_PARENT,
62 RPN_OPERATOR_PERCENT,
63 RPN_OPERATOR_EQUAL,
64
65 RPN_OPERATOR_OR,
66 RPN_OPERATOR_XOR,
67 RPN_OPERATOR_AND,
68 RPN_OPERATOR_LSH,
69 RPN_OPERATOR_RSH,
70 RPN_OPERATOR_ADD,
71 RPN_OPERATOR_SUB,
72 RPN_OPERATOR_MULT,
73 RPN_OPERATOR_DIV,
74 RPN_OPERATOR_MOD,
75 RPN_OPERATOR_POW,
76 RPN_OPERATOR_SQR,
77
78 RPN_OPERATOR_NONE
79 };
80
81 typedef union {
82 #ifdef ENABLE_MULTI_PRECISION
83 mpfr_t mf;
84 #else
85 double f;
86 INT64 i;
87 UINT64 u;
88 #endif
89 } calc_number_t;
90
91 typedef struct {
92 calc_number_t number;
93 unsigned int operation;
94 DWORD base;
95 } calc_node_t;
96
97 void run_operator(calc_node_t *result, calc_node_t *a,
98 calc_node_t *b, unsigned int operation);
99 int exec_infix2postfix(calc_number_t *, unsigned int);
100 void exec_closeparent(calc_number_t *);
101 int eval_parent_count(void);
102 void flush_postfix(void);
103 void exec_change_infix(void);
104 void start_rpn_engine(void);
105 void stop_rpn_engine(void);
106
107 typedef struct {
108 char *data;
109 char *ptr;
110 UINT wm_msg;
111 } sequence_t;
112
113 typedef struct {
114 calc_number_t num;
115 DWORD base;
116 void *next;
117 } statistic_t;
118
119 enum {
120 CALC_LAYOUT_SCIENTIFIC=0,
121 CALC_LAYOUT_STANDARD,
122 CALC_LAYOUT_CONVERSION,
123 };
124
125 typedef struct {
126 HINSTANCE hInstance;
127 #ifdef USE_KEYBOARD_HOOK
128 HHOOK hKeyboardHook;
129 #endif
130 HWND hWnd;
131 DWORD layout;
132 TCHAR buffer[MAX_CALC_SIZE];
133 TCHAR source[MAX_CALC_SIZE];
134 TCHAR *ptr;
135 calc_number_t code;
136 calc_number_t prev;
137 calc_node_t memory;
138 statistic_t *stat;
139 BOOL is_memory;
140 BOOL is_nan;
141 BOOL sci_out;
142 BOOL sci_in;
143 BOOL usesep;
144 BOOL is_menu_on;
145 signed int esp;
146 DWORD base;
147 DWORD size;
148 DWORD degr;
149 DWORD action;
150 HWND hStatWnd;
151 HWND hConvWnd;
152 sequence_t Clipboard;
153 sequence_t Convert[2];
154 unsigned int last_operator;
155 unsigned int prev_operator;
156 TCHAR sDecimal[8];
157 TCHAR sThousand[8];
158 unsigned int sDecimal_len;
159 unsigned int sThousand_len;
160 signed int x_coord;
161 signed int y_coord;
162 } calc_t;
163
164 extern calc_t calc;
165
166 /* IEEE constants */
167 #define CALC_E 2.718281828459045235360
168 #define CALC_PI_2 1.570796326794896619231
169 #define CALC_PI 3.141592653589793238462
170 #define CALC_3_PI_2 4.712388980384689857694
171 #define CALC_2_PI 6.283185307179586476925
172
173 #define MODIFIER_INV 0x01
174 #define MODIFIER_HYP 0x02
175 #define NO_CHAIN 0x04
176
177 void apply_int_mask(calc_number_t *a);
178 #ifndef ENABLE_MULTI_PRECISION
179 __int64 logic_dbl2int(calc_number_t *a);
180 double logic_int2dbl(calc_number_t *a);
181 #endif
182 void rpn_sin(calc_number_t *c);
183 void rpn_cos(calc_number_t *c);
184 void rpn_tan(calc_number_t *c);
185 void rpn_asin(calc_number_t *c);
186 void rpn_acos(calc_number_t *c);
187 void rpn_atan(calc_number_t *c);
188 void rpn_sinh(calc_number_t *c);
189 void rpn_cosh(calc_number_t *c);
190 void rpn_tanh(calc_number_t *c);
191 void rpn_asinh(calc_number_t *c);
192 void rpn_acosh(calc_number_t *c);
193 void rpn_atanh(calc_number_t *c);
194 BOOL rpn_validate_result(calc_number_t *c);
195 void rpn_int(calc_number_t *c);
196 void rpn_frac(calc_number_t *c);
197 void rpn_reci(calc_number_t *c);
198 void rpn_fact(calc_number_t *c);
199 void rpn_not(calc_number_t *c);
200 void rpn_pi(calc_number_t *c);
201 void rpn_2pi(calc_number_t *c);
202 void rpn_sign(calc_number_t *c);
203 void rpn_exp2(calc_number_t *c);
204 void rpn_exp3(calc_number_t *c);
205 void rpn_sqrt(calc_number_t *c);
206 void rpn_cbrt(calc_number_t *c);
207 void rpn_exp(calc_number_t *c);
208 void rpn_exp10(calc_number_t *c);
209 void rpn_ln(calc_number_t *c);
210 void rpn_log(calc_number_t *c);
211 void rpn_ave(calc_number_t *c);
212 void rpn_ave2(calc_number_t *c);
213 void rpn_sum(calc_number_t *c);
214 void rpn_sum2(calc_number_t *c);
215 void rpn_s(calc_number_t *c);
216 void rpn_s_m1(calc_number_t *c);
217 void rpn_dms2dec(calc_number_t *c);
218 void rpn_dec2dms(calc_number_t *c);
219 void rpn_zero(calc_number_t *c);
220 void rpn_copy(calc_number_t *dst, calc_number_t *src);
221 int rpn_is_zero(calc_number_t *c);
222 void rpn_alloc(calc_number_t *c);
223 void rpn_free(calc_number_t *c);
224
225 //
226
227 void prepare_rpn_result_2(calc_number_t *rpn, TCHAR *buffer, int size, int base);
228 void convert_text2number_2(calc_number_t *a);
229 void convert_real_integer(unsigned int base);
230
231 //
232
233 INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
234
235 //
236
237 void ConvExecute(HWND hWnd);
238 void ConvAdjust(HWND hWnd, int n_cat);
239 void ConvInit(HWND hWnd);
240
241 #endif /* __CALC_H__ */