Revert, thx Thomas, wasnt sure.
[reactos.git] / reactos / subsys / system / calc / winecalc.h
1 /*
2 * WineCalc (winecalc.h)
3 *
4 * Copyright 2003 James Briggs
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 //////////////////////////////////////////////////////////////////
22
23 // numerics are defined here for easier porting
24
25 typedef double calcfloat;
26 #define FMT_DESC_FLOAT TEXT("%g")
27 #define FMT_DESC_EXP TEXT("%e")
28
29 #define CALC_ATOF(x) atof(x)
30
31 #define CONST_PI 3.1415926535897932384626433832795
32
33 /////////////////////////////////////////////////////////////////
34
35 #define CALC_BUF_SIZE 128
36
37 // statistics dialog dimensions
38
39 #define CALC_STA_X 235
40 #define CALC_STA_Y 180
41
42 // sentinel for differentiating Return from Ctrl+M events
43
44 #define NUMBER_OF_THE_BEAST 666
45
46 #define CALC_COLOR_BLUE 0
47 #define CALC_COLOR_RED 1
48 #define CALC_COLOR_GRAY 2
49 #define CALC_COLOR_MAGENTA 3
50
51 // gray hilite on rectangle owner-drawn controls RGB(CALC_GRAY, CALC_GRAY, CALC_GRAY)
52
53 #define CALC_GRAY 132
54
55 // count of buttons needing special toggle states depending on number base
56
57 #define TOGGLE_COUNT 23
58
59 // there are 3 window menus, standard, decimal measurement system and word size menus
60
61 #define COUNT_MENUS 3
62 #define MENU_STD 0
63 #define MENU_SCIMS 1
64 #define MENU_SCIWS 2
65
66 // count of buttons
67
68 #define CALC_BUTTONS_STANDARD 28
69 #define CALC_BUTTONS_SCIENTIFIC 73
70
71 // winecalc window outer dimensions
72
73 #define CALC_STANDARD_WIDTH 260
74 #define CALC_STANDARD_HEIGHT 252
75 #define CALC_SCIENTIFIC_WIDTH 480
76 #define CALC_SCIENTIFIC_HEIGHT 310
77
78 // winecalc private ids for events
79
80 #define ID_CALC_ZERO 0
81 #define ID_CALC_ONE 1
82 #define ID_CALC_TWO 2
83 #define ID_CALC_THREE 3
84 #define ID_CALC_FOUR 4
85 #define ID_CALC_FIVE 5
86 #define ID_CALC_SIX 6
87 #define ID_CALC_SEVEN 7
88 #define ID_CALC_EIGHT 8
89 #define ID_CALC_NINE 9
90 #define ID_CALC_BACKSPACE 20
91 #define ID_CALC_CLEAR_ENTRY 21
92 #define ID_CALC_CLEAR_ALL 22
93 #define ID_CALC_MEM_CLEAR 23
94 #define ID_CALC_DIVIDE 24
95 #define ID_CALC_SQRT 25
96 #define ID_CALC_MEM_RECALL 26
97 #define ID_CALC_MULTIPLY 27
98 #define ID_CALC_PERCENT 28
99 #define ID_CALC_MEM_STORE 29
100 #define ID_CALC_MINUS 30
101 #define ID_CALC_RECIPROCAL 31
102 #define ID_CALC_MEM_PLUS 32
103 #define ID_CALC_SIGN 33
104 #define ID_CALC_DECIMAL 34
105 #define ID_CALC_PLUS 35
106 #define ID_CALC_EQUALS 36
107 #define ID_CALC_STA 37
108 #define ID_CALC_FE 38
109 #define ID_CALC_LEFTPAREN 39
110 #define ID_CALC_RIGHTPAREN 40
111 #define ID_CALC_MOD 41
112 #define ID_CALC_AND 42
113 #define ID_CALC_OR 43
114 #define ID_CALC_XOR 44
115 #define ID_CALC_SUM 45
116 #define ID_CALC_SIN 46
117 #define ID_CALC_LOG10 47
118 #define ID_CALC_LSH 48
119 #define ID_CALC_NOT 49
120 #define ID_CALC_S 50
121 #define ID_CALC_COS 52
122 #define ID_CALC_FACTORIAL 53
123 #define ID_CALC_INT 54
124 #define ID_CALC_DAT 55
125 #define ID_CALC_TAN 56
126 #define ID_CALC_SQUARE 57
127 #define ID_CALC_A 58
128 #define ID_CALC_B 59
129 #define ID_CALC_C 60
130 #define ID_CALC_D 61
131 #define ID_CALC_E 62
132 #define ID_CALC_F 63
133 #define ID_CALC_AVE 64
134 #define ID_CALC_DMS 65
135 #define ID_CALC_EXP 66
136 #define ID_CALC_LN 67
137 #define ID_CALC_PI 68
138 #define ID_CALC_CUBE 69
139 #define ID_CALC_POWER 51
140
141 // Number System Radio Buttons
142
143 #define CALC_NS_COUNT 4
144 #define ID_CALC_NS_HEX 2000
145 #define ID_CALC_NS_DEC 2001
146 #define ID_CALC_NS_OCT 2002
147 #define ID_CALC_NS_BIN 2003
148
149 #define NBASE_DECIMAL 0
150 #define NBASE_BINARY 1
151 #define NBASE_OCTAL 2
152 #define NBASE_HEX 3
153
154 #define CALC_NS_OFFSET_X 15
155 #define CALC_NS_OFFSET_Y 37
156
157 #define SZ_RADIO_NS_X 50
158 #define SZ_RADIO_NS_Y 15
159
160 #define CALC_NS_HEX_LEFT 0
161 #define CALC_NS_HEX_TOP 0
162
163 #define CALC_NS_DEC_LEFT 50
164 #define CALC_NS_DEC_TOP 0
165
166 #define CALC_NS_OCT_LEFT 98
167 #define CALC_NS_OCT_TOP 0
168
169 #define CALC_NS_BIN_LEFT 148
170 #define CALC_NS_BIN_TOP 0
171
172 // Measurement System Radio Buttons
173
174 #define CALC_MS_COUNT 3
175 #define ID_CALC_MS_DEGREES 2010
176 #define ID_CALC_MS_RADIANS 2011
177 #define ID_CALC_MS_GRADS 2012
178
179 #define TRIGMODE_DEGREES 0
180 #define TRIGMODE_RADIANS 1
181 #define TRIGMODE_GRADS 2
182
183 #define CALC_MS_OFFSET_X 225
184 #define CALC_MS_OFFSET_Y 37
185
186 #define SZ_RADIO_MS_X 75
187 #define SZ_RADIO_MS_Y 15
188
189 #define CALC_MS_DEGREES_LEFT 0
190 #define CALC_MS_DEGREES_TOP 0
191
192 #define CALC_MS_RADIANS_LEFT 82
193 #define CALC_MS_RADIANS_TOP 0
194
195 #define CALC_MS_GRADS_LEFT 162
196 #define CALC_MS_GRADS_TOP 0
197
198 // Inv and Hyp Checkboxes
199
200 #define CALC_CB_COUNT 2
201 #define ID_CALC_CB_INV 2020
202 #define ID_CALC_CB_HYP 2021
203
204 #define WORDSIZE_BYTE 1
205 #define WORDSIZE_WORD 2
206 #define WORDSIZE_DWORD 4
207 #define WORDSIZE_QWORD 8
208
209 #define CALC_CB_OFFSET_X 15
210 #define CALC_CB_OFFSET_Y 58
211
212 #define CALC_CB_INV_LEFT 0
213 #define CALC_CB_INV_TOP 10
214
215 #define SZ_RADIO_CB_X 50
216 #define SZ_RADIO_CB_Y 14
217
218 #define CALC_CB_HYP_LEFT 58
219 #define CALC_CB_HYP_TOP 10
220
221 // Word Size Radio Buttons
222
223 #define CALC_WS_COUNT 4
224 #define ID_CALC_WS_QWORD 2030
225 #define ID_CALC_WS_DWORD 2031
226 #define ID_CALC_WS_WORD 2032
227 #define ID_CALC_WS_BYTE 2033
228
229 #define CALC_WS_OFFSET_X CALC_MS_OFFSET_X
230 #define CALC_WS_OFFSET_Y CALC_MS_OFFSET_Y
231
232 #define CALC_WS_QWORD_LEFT 0
233 #define CALC_WS_QWORD_TOP 0
234
235 #define CALC_WS_DWORD_LEFT 57
236 #define CALC_WS_DWORD_TOP 0
237
238 #define CALC_WS_WORD_LEFT 120
239 #define CALC_WS_WORD_TOP 0
240
241 #define CALC_WS_BYTE_LEFT 175
242 #define CALC_WS_BYTE_TOP 0
243
244 #define SZ_RADIO_WS_X 50
245 #define SZ_RADIO_WS_Y 15
246
247 // drawing offsets
248
249 #define CALC_EDIT_HEIGHT 20
250
251 #define SZ_FILLER_X 32
252 #define SZ_FILLER_Y 30
253
254 #define SZ_BIGBTN_X 62
255 #define SZ_BIGBTN_Y 30
256
257 #define SZ_MEDBTN_X 36
258 #define SZ_MEDBTN_Y 30
259
260 #define MARGIN_LEFT 7
261 #define MARGIN_SMALL_X 3
262 #define MARGIN_SMALL_Y 3
263 #define MARGIN_BIG_X 274
264 #define MARGIN_STANDARD_BIG_X 11
265 #define MARGIN_BIG_Y 6
266
267 #define SZ_SPACER_X 11
268
269 // winecalc results display area
270
271 #define WDISPLAY_STANDARD_LEFT MARGIN_LEFT + 4
272 #define WDISPLAY_STANDARD_TOP 5
273 #define WDISPLAY_STANDARD_RIGHT 244
274 #define WDISPLAY_STANDARD_BOTTOM 24
275 #define CALC_STANDARD_MARGIN_TOP 16
276
277 #define WDISPLAY_SCIENTIFIC_LEFT MARGIN_LEFT + 4
278 #define WDISPLAY_SCIENTIFIC_TOP 5
279 #define WDISPLAY_SCIENTIFIC_RIGHT 465
280 #define WDISPLAY_SCIENTIFIC_BOTTOM 24
281 #define CALC_SCIENTIFIC_MARGIN_TOP 44
282
283 typedef struct tagCalcBtn {
284 int id; // private id
285 HWND hBtn; // button child window handle
286 TCHAR label[80]; // text on buttonface
287 int color; // text color
288 RECT r; // location
289 int enable; // 1 = control enbabled, 0 = disabled
290 }
291 CALCBTN;
292
293 typedef struct tagPos {
294 int x;
295 int y;
296 }
297 POS;
298
299 typedef struct tagCalc {
300 HINSTANCE hInst; // this HINSTANCE
301 HWND hWnd; // main window's HWND
302
303 POS pos;
304 int numButtons; // standard = 28, scientific = more
305
306 TCHAR buffer [CALC_BUF_SIZE]; // current keyboard buffer
307 TCHAR display[CALC_BUF_SIZE]; // display buffer before output
308
309 calcfloat value; // most recent computer value
310 calcfloat memory; // most recent stored memory value from display buffer
311 int paren; // current parentheses level
312
313 int sciMode; // standard = 1, scientific = 0
314 int displayMode; // 0 = float, 1 = scientific exponential notation like 1.0e+10
315
316 TCHAR oper; // most recent operator pushed
317 calcfloat operand; // most recent operand pushed
318 int newenter; // track multiple =
319 int next; // binary operation flag
320 int err; // errror status for divide by zero, infinity, etc.
321 int init; // starting buffer
322
323 int digitGrouping; // no separators = 0, separators = 1
324
325 int trigMode; // degrees = 0, radians = 1, grads = 2
326 int numBase; // 10 = decimal, 2 = binary, 8 = octal, 16 = hex
327 int wordSize; // 1 = byte, 2 = word, 4 = dword, 8 = qword
328 int invMode; // INV mode 0 = off, 1 = on
329 int hypMode; // HYP mode 0 = off, 1 = on
330
331 int new; // first time 0 = false, 1 = true
332 CALCBTN cb[80]; // enough buttons for standard or scientific mode
333 }
334 CALC;
335
336 BOOL CALLBACK AboutDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
337 LRESULT WINAPI MainProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
338
339 void InitLuts(void);
340 void InitMenus(HINSTANCE hInst);
341 void DestroyMenus();
342
343 void InitCalc (CALC *calc);
344 void DestroyCalc (CALC *calc);
345
346 void calc_buffer_format(CALC *calc);
347 void calc_buffer_display(CALC *calc);
348 TCHAR *calc_sep(TCHAR *s);
349
350 void DrawCalcText (HDC hdc, HDC hMemDC, PAINTSTRUCT *ps, CALC *calc, int object, TCHAR *s);
351 void CalcRect (HDC hdc, HDC hMemDC, PAINTSTRUCT *ps, CALC *calc, int object);
352 void DrawCalcRectSci(HDC hdc, HDC hMemDC, PAINTSTRUCT *ps, CALC *calc, RECT *r);
353 void DrawCalc (HDC hdc, HDC hMemDC, PAINTSTRUCT *ps, CALC *calc);
354
355 void calc_setmenuitem_radio(HMENU hMenu, UINT id);
356
357 void show_debug(CALC *calc, TCHAR *title, long wParam, long lParam);
358
359 calcfloat calc_atof(const TCHAR *s, int base);
360 void calc_ftoa(CALC *calc, calcfloat r, TCHAR *buf);
361 long factorial(long n);
362
363 calcfloat calc_convert_to_radians(CALC *calc);
364 calcfloat calc_convert_from_radians(CALC *calc);
365