db984f07602d05141c903b2fde16bbd08b46a9d2
[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 /* HTMLHELP SUPPORT */
55 typedef HWND (WINAPI* type_HtmlHelpA)(HWND, LPCSTR, UINT, DWORD);
56 typedef HWND (WINAPI* type_HtmlHelpW)(HWND, LPCWSTR, UINT, DWORD);
57
58 extern type_HtmlHelpA calc_HtmlHelpA;
59 extern type_HtmlHelpW calc_HtmlHelpW;
60
61 #ifndef UNICODE
62 #define calc_HtmlHelp calc_HtmlHelpA
63 #else
64 #define calc_HtmlHelp calc_HtmlHelpW
65 #endif
66
67 void HtmlHelp_Start(HINSTANCE hInstance);
68 void HtmlHelp_Stop(void);
69
70 /*#define USE_KEYBOARD_HOOK*/
71
72 #define SIZEOF(_ar) (sizeof(_ar)/sizeof(_ar[1]))
73
74 // RPN.C
75
76 enum {
77 RPN_OPERATOR_PARENT,
78 RPN_OPERATOR_PERCENT,
79 RPN_OPERATOR_EQUAL,
80
81 RPN_OPERATOR_OR,
82 RPN_OPERATOR_XOR,
83 RPN_OPERATOR_AND,
84 RPN_OPERATOR_LSH,
85 RPN_OPERATOR_RSH,
86 RPN_OPERATOR_ADD,
87 RPN_OPERATOR_SUB,
88 RPN_OPERATOR_MULT,
89 RPN_OPERATOR_DIV,
90 RPN_OPERATOR_MOD,
91 RPN_OPERATOR_POW,
92 RPN_OPERATOR_SQR,
93
94 RPN_OPERATOR_NONE
95 };
96
97 typedef union {
98 #ifdef ENABLE_MULTI_PRECISION
99 mpfr_t mf;
100 #else
101 double f;
102 INT64 i;
103 UINT64 u;
104 #endif
105 } calc_number_t;
106
107 typedef struct {
108 calc_number_t number;
109 unsigned int operation;
110 DWORD base;
111 } calc_node_t;
112
113 void run_operator(calc_node_t *result, calc_node_t *a,
114 calc_node_t *b, unsigned int operation);
115 int exec_infix2postfix(calc_number_t *, unsigned int);
116 void exec_closeparent(calc_number_t *);
117 int eval_parent_count(void);
118 void flush_postfix(void);
119 void exec_change_infix(void);
120 void start_rpn_engine(void);
121 void stop_rpn_engine(void);
122
123 typedef struct {
124 char *data;
125 char *ptr;
126 UINT wm_msg;
127 } sequence_t;
128
129 typedef struct {
130 calc_number_t num;
131 DWORD base;
132 void *next;
133 } statistic_t;
134
135 enum {
136 CALC_LAYOUT_SCIENTIFIC=0,
137 CALC_LAYOUT_STANDARD,
138 CALC_LAYOUT_CONVERSION,
139 };
140
141 typedef struct {
142 HINSTANCE hInstance;
143 #ifdef USE_KEYBOARD_HOOK
144 HHOOK hKeyboardHook;
145 #endif
146 HWND hWnd;
147 DWORD layout;
148 TCHAR buffer[MAX_CALC_SIZE];
149 TCHAR source[MAX_CALC_SIZE];
150 TCHAR *ptr;
151 calc_number_t code;
152 calc_number_t prev;
153 calc_node_t memory;
154 statistic_t *stat;
155 BOOL is_memory;
156 BOOL is_nan;
157 BOOL sci_out;
158 BOOL sci_in;
159 BOOL usesep;
160 BOOL is_menu_on;
161 signed int esp;
162 DWORD base;
163 DWORD size;
164 DWORD degr;
165 DWORD action;
166 HWND hStatWnd;
167 HWND hConvWnd;
168 sequence_t Clipboard;
169 sequence_t Convert[2];
170 unsigned int last_operator;
171 unsigned int prev_operator;
172 TCHAR sDecimal[8];
173 TCHAR sThousand[8];
174 unsigned int sDecimal_len;
175 unsigned int sThousand_len;
176 signed int x_coord;
177 signed int y_coord;
178 } calc_t;
179
180 extern calc_t calc;
181
182 /* IEEE constants */
183 #define CALC_E 2.718281828459045235360
184 #define CALC_PI_2 1.570796326794896619231
185 #define CALC_PI 3.141592653589793238462
186 #define CALC_3_PI_2 4.712388980384689857694
187 #define CALC_2_PI 6.283185307179586476925
188
189 #define MODIFIER_INV 0x01
190 #define MODIFIER_HYP 0x02
191 #define NO_CHAIN 0x04
192
193 void apply_int_mask(calc_number_t *a);
194 #ifndef ENABLE_MULTI_PRECISION
195 __int64 logic_dbl2int(calc_number_t *a);
196 double logic_int2dbl(calc_number_t *a);
197 #endif
198 void rpn_sin(calc_number_t *c);
199 void rpn_cos(calc_number_t *c);
200 void rpn_tan(calc_number_t *c);
201 void rpn_asin(calc_number_t *c);
202 void rpn_acos(calc_number_t *c);
203 void rpn_atan(calc_number_t *c);
204 void rpn_sinh(calc_number_t *c);
205 void rpn_cosh(calc_number_t *c);
206 void rpn_tanh(calc_number_t *c);
207 void rpn_asinh(calc_number_t *c);
208 void rpn_acosh(calc_number_t *c);
209 void rpn_atanh(calc_number_t *c);
210 BOOL rpn_validate_result(calc_number_t *c);
211 void rpn_int(calc_number_t *c);
212 void rpn_frac(calc_number_t *c);
213 void rpn_reci(calc_number_t *c);
214 void rpn_fact(calc_number_t *c);
215 void rpn_not(calc_number_t *c);
216 void rpn_pi(calc_number_t *c);
217 void rpn_2pi(calc_number_t *c);
218 void rpn_sign(calc_number_t *c);
219 void rpn_exp2(calc_number_t *c);
220 void rpn_exp3(calc_number_t *c);
221 void rpn_sqrt(calc_number_t *c);
222 void rpn_cbrt(calc_number_t *c);
223 void rpn_exp(calc_number_t *c);
224 void rpn_exp10(calc_number_t *c);
225 void rpn_ln(calc_number_t *c);
226 void rpn_log(calc_number_t *c);
227 void rpn_ave(calc_number_t *c);
228 void rpn_ave2(calc_number_t *c);
229 void rpn_sum(calc_number_t *c);
230 void rpn_sum2(calc_number_t *c);
231 void rpn_s(calc_number_t *c);
232 void rpn_s_m1(calc_number_t *c);
233 void rpn_dms2dec(calc_number_t *c);
234 void rpn_dec2dms(calc_number_t *c);
235 void rpn_zero(calc_number_t *c);
236 void rpn_copy(calc_number_t *dst, calc_number_t *src);
237 int rpn_is_zero(calc_number_t *c);
238 void rpn_alloc(calc_number_t *c);
239 void rpn_free(calc_number_t *c);
240
241 //
242
243 void prepare_rpn_result_2(calc_number_t *rpn, TCHAR *buffer, int size, int base);
244 void convert_text2number_2(calc_number_t *a);
245 void convert_real_integer(unsigned int base);
246
247 //
248
249 INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
250
251 //
252
253 void ConvExecute(HWND hWnd);
254 void ConvAdjust(HWND hWnd, int n_cat);
255 void ConvInit(HWND hWnd);
256
257 #endif /* __CALC_H__ */