2 * WineCalc (winecalc.h)
4 * Copyright 2003 James Briggs
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.
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.
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
21 //////////////////////////////////////////////////////////////////
23 // numerics are defined here for easier porting
25 typedef double calcfloat
;
26 #define FMT_DESC_FLOAT "%.32g"
27 #define FMT_DESC_EXP "%.32e"
29 #define CALC_ATOF(x) atof(x)
31 #define CONST_PI 3.1415926535897932384626433832795
33 /////////////////////////////////////////////////////////////////
35 #define CALC_BUF_SIZE 128
37 // statistics dialog dimensions
39 #define CALC_STA_X 235
40 #define CALC_STA_Y 180
42 // sentinel for differentiating Return from Ctrl+M events
44 #define NUMBER_OF_THE_BEAST 666
46 #define CALC_COLOR_BLUE 0
47 #define CALC_COLOR_RED 1
48 #define CALC_COLOR_GRAY 2
49 #define CALC_COLOR_MAGENTA 3
51 // gray hilite on rectangle owner-drawn controls RGB(CALC_GRAY, CALC_GRAY, CALC_GRAY)
55 // count of buttons needing special toggle states depending on number base
57 #define TOGGLE_COUNT 23
59 // there are 3 window menus, standard, decimal measurement system and word size menus
68 #define CALC_BUTTONS_STANDARD 28
69 #define CALC_BUTTONS_SCIENTIFIC 73
71 // winecalc window outer dimensions
73 #define CALC_STANDARD_WIDTH 260
74 #define CALC_STANDARD_HEIGHT 252
75 #define CALC_SCIENTIFIC_WIDTH 480
76 #define CALC_SCIENTIFIC_HEIGHT 310
78 // winecalc private ids for events
80 #define ID_CALC_ZERO 0
83 #define ID_CALC_THREE 3
84 #define ID_CALC_FOUR 4
85 #define ID_CALC_FIVE 5
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
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
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
141 // Number System Radio Buttons
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
149 #define NBASE_DECIMAL 0
150 #define NBASE_BINARY 1
151 #define NBASE_OCTAL 2
154 #define CALC_NS_OFFSET_X 15
155 #define CALC_NS_OFFSET_Y 37
157 #define SZ_RADIO_NS_X 50
158 #define SZ_RADIO_NS_Y 15
160 #define CALC_NS_HEX_LEFT 0
161 #define CALC_NS_HEX_TOP 0
163 #define CALC_NS_DEC_LEFT 50
164 #define CALC_NS_DEC_TOP 0
166 #define CALC_NS_OCT_LEFT 98
167 #define CALC_NS_OCT_TOP 0
169 #define CALC_NS_BIN_LEFT 148
170 #define CALC_NS_BIN_TOP 0
172 // Measurement System Radio Buttons
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
179 #define TRIGMODE_DEGREES 0
180 #define TRIGMODE_RADIANS 1
181 #define TRIGMODE_GRADS 2
183 #define CALC_MS_OFFSET_X 225
184 #define CALC_MS_OFFSET_Y 37
186 #define SZ_RADIO_MS_X 75
187 #define SZ_RADIO_MS_Y 15
189 #define CALC_MS_DEGREES_LEFT 0
190 #define CALC_MS_DEGREES_TOP 0
192 #define CALC_MS_RADIANS_LEFT 82
193 #define CALC_MS_RADIANS_TOP 0
195 #define CALC_MS_GRADS_LEFT 162
196 #define CALC_MS_GRADS_TOP 0
198 // Inv and Hyp Checkboxes
200 #define CALC_CB_COUNT 2
201 #define ID_CALC_CB_INV 2020
202 #define ID_CALC_CB_HYP 2021
204 #define WORDSIZE_BYTE 1
205 #define WORDSIZE_WORD 2
206 #define WORDSIZE_DWORD 4
207 #define WORDSIZE_QWORD 8
209 #define CALC_CB_OFFSET_X 15
210 #define CALC_CB_OFFSET_Y 58
212 #define CALC_CB_INV_LEFT 0
213 #define CALC_CB_INV_TOP 10
215 #define SZ_RADIO_CB_X 50
216 #define SZ_RADIO_CB_Y 14
218 #define CALC_CB_HYP_LEFT 58
219 #define CALC_CB_HYP_TOP 10
221 // Word Size Radio Buttons
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
229 #define CALC_WS_OFFSET_X CALC_MS_OFFSET_X
230 #define CALC_WS_OFFSET_Y CALC_MS_OFFSET_Y
232 #define CALC_WS_QWORD_LEFT 0
233 #define CALC_WS_QWORD_TOP 0
235 #define CALC_WS_DWORD_LEFT 57
236 #define CALC_WS_DWORD_TOP 0
238 #define CALC_WS_WORD_LEFT 120
239 #define CALC_WS_WORD_TOP 0
241 #define CALC_WS_BYTE_LEFT 175
242 #define CALC_WS_BYTE_TOP 0
244 #define SZ_RADIO_WS_X 50
245 #define SZ_RADIO_WS_Y 15
249 #define CALC_EDIT_HEIGHT 20
251 #define SZ_FILLER_X 32
252 #define SZ_FILLER_Y 30
254 #define SZ_BIGBTN_X 62
255 #define SZ_BIGBTN_Y 30
257 #define SZ_MEDBTN_X 36
258 #define SZ_MEDBTN_Y 30
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
267 #define SZ_SPACER_X 11
269 // winecalc results display area
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
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
283 typedef struct tagCalcBtn
{
284 int id
; // private id
285 HWND hBtn
; // button child window handle
286 char label
[80]; // text on buttonface
287 int color
; // text color
289 int enable
; // 1 = control enbabled, 0 = disabled
293 typedef struct tagPos
{
299 typedef struct tagCalc
{
300 HINSTANCE hInst
; // this HINSTANCE
301 HWND hWnd
; // main window's HWND
304 int numButtons
; // standard = 28, scientific = more
306 char buffer
[CALC_BUF_SIZE
]; // current keyboard buffer
307 char display
[CALC_BUF_SIZE
]; // display buffer before output
309 calcfloat value
; // most recent computer value
310 calcfloat memory
; // most recent stored memory value from display buffer
311 int paren
; // current parentheses level
313 int sciMode
; // standard = 1, scientific = 0
314 int displayMode
; // 0 = float, 1 = scientific exponential notation like 1.0e+10
316 char 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
323 int digitGrouping
; // no separators = 0, separators = 1
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
331 int new; // first time 0 = false, 1 = true
332 CALCBTN cb
[80]; // enough buttons for standard or scientific mode
336 BOOL CALLBACK
AboutDlgProc( HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
337 LRESULT WINAPI
MainProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
340 void InitMenus(HINSTANCE hInst
);
342 void InitCalc (CALC
*calc
);
343 void DestroyCalc (CALC
*calc
);
345 void calc_buffer_format(CALC
*calc
);
346 void calc_buffer_display(CALC
*calc
);
347 char *calc_sep(char *s
);
349 void DrawCalcText (HDC hdc
, HDC hMemDC
, PAINTSTRUCT
*ps
, CALC
*calc
, int object
, char *s
);
350 void CalcRect (HDC hdc
, HDC hMemDC
, PAINTSTRUCT
*ps
, CALC
*calc
, int object
);
351 void DrawCalcRectSci(HDC hdc
, HDC hMemDC
, PAINTSTRUCT
*ps
, CALC
*calc
, RECT
*r
);
352 void DrawCalc (HDC hdc
, HDC hMemDC
, PAINTSTRUCT
*ps
, CALC
*calc
);
354 void calc_setmenuitem_radio(HMENU hMenu
, UINT id
);
356 void show_debug(CALC
*calc
, char *title
, long wParam
, long lParam
);
358 calcfloat
calc_atof(char *s
, int base
);
359 void calc_ftoa(CALC
*calc
, calcfloat r
, char *buf
);
360 long factorial(long n
);
362 calcfloat
calc_convert_to_radians(CALC
*calc
);
363 calcfloat
calc_convert_from_radians(CALC
*calc
);