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