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 //////////////////////////////////////////////////////////////////
24 #define CF_TTEXT CF_UNICODETEXT
26 #define CF_TTEXT CF_TEXT
29 // numerics are defined here for easier porting
31 typedef double calcfloat
;
32 #define FMT_DESC_FLOAT TEXT("%g")
33 #define FMT_DESC_EXP TEXT("%e")
35 #define CALC_ATOF(x) atof(x)
37 #define CONST_PI 3.1415926535897932384626433832795
39 /////////////////////////////////////////////////////////////////
41 #define CALC_BUF_SIZE 128
43 // statistics dialog dimensions
45 #define CALC_STA_X 235
46 #define CALC_STA_Y 180
48 // sentinel for differentiating Return from Ctrl+M events
50 #define NUMBER_OF_THE_BEAST 666
52 #define CALC_COLOR_BLUE 0
53 #define CALC_COLOR_RED 1
54 #define CALC_COLOR_GRAY 2
55 #define CALC_COLOR_MAGENTA 3
57 // gray hilite on rectangle owner-drawn controls RGB(CALC_GRAY, CALC_GRAY, CALC_GRAY)
61 // count of buttons needing special toggle states depending on number base
63 #define TOGGLE_COUNT 23
65 // there are 3 window menus, standard, decimal measurement system and word size menus
74 #define CALC_BUTTONS_STANDARD 28
75 #define CALC_BUTTONS_SCIENTIFIC 73
77 // winecalc window outer dimensions
79 #define CALC_STANDARD_WIDTH 260
80 #define CALC_STANDARD_HEIGHT 252
81 #define CALC_SCIENTIFIC_WIDTH 480
82 #define CALC_SCIENTIFIC_HEIGHT 310
84 // winecalc private ids for events
86 #define ID_CALC_ZERO 0
89 #define ID_CALC_THREE 3
90 #define ID_CALC_FOUR 4
91 #define ID_CALC_FIVE 5
93 #define ID_CALC_SEVEN 7
94 #define ID_CALC_EIGHT 8
95 #define ID_CALC_NINE 9
96 #define ID_CALC_BACKSPACE 20
97 #define ID_CALC_CLEAR_ENTRY 21
98 #define ID_CALC_CLEAR_ALL 22
99 #define ID_CALC_MEM_CLEAR 23
100 #define ID_CALC_DIVIDE 24
101 #define ID_CALC_SQRT 25
102 #define ID_CALC_MEM_RECALL 26
103 #define ID_CALC_MULTIPLY 27
104 #define ID_CALC_PERCENT 28
105 #define ID_CALC_MEM_STORE 29
106 #define ID_CALC_MINUS 30
107 #define ID_CALC_RECIPROCAL 31
108 #define ID_CALC_MEM_PLUS 32
109 #define ID_CALC_SIGN 33
110 #define ID_CALC_DECIMAL 34
111 #define ID_CALC_PLUS 35
112 #define ID_CALC_EQUALS 36
113 #define ID_CALC_STA 37
114 #define ID_CALC_FE 38
115 #define ID_CALC_LEFTPAREN 39
116 #define ID_CALC_RIGHTPAREN 40
117 #define ID_CALC_MOD 41
118 #define ID_CALC_AND 42
119 #define ID_CALC_OR 43
120 #define ID_CALC_XOR 44
121 #define ID_CALC_SUM 45
122 #define ID_CALC_SIN 46
123 #define ID_CALC_LOG10 47
124 #define ID_CALC_LSH 48
125 #define ID_CALC_NOT 49
127 #define ID_CALC_COS 52
128 #define ID_CALC_FACTORIAL 53
129 #define ID_CALC_INT 54
130 #define ID_CALC_DAT 55
131 #define ID_CALC_TAN 56
132 #define ID_CALC_SQUARE 57
139 #define ID_CALC_AVE 64
140 #define ID_CALC_DMS 65
141 #define ID_CALC_EXP 66
142 #define ID_CALC_LN 67
143 #define ID_CALC_PI 68
144 #define ID_CALC_CUBE 69
145 #define ID_CALC_POWER 51
147 // Number System Radio Buttons
149 #define CALC_NS_COUNT 4
150 #define ID_CALC_NS_HEX 2000
151 #define ID_CALC_NS_DEC 2001
152 #define ID_CALC_NS_OCT 2002
153 #define ID_CALC_NS_BIN 2003
155 #define NBASE_DECIMAL 0
156 #define NBASE_BINARY 1
157 #define NBASE_OCTAL 2
160 #define CALC_NS_OFFSET_X 15
161 #define CALC_NS_OFFSET_Y 37
163 #define SZ_RADIO_NS_X 50
164 #define SZ_RADIO_NS_Y 15
166 #define CALC_NS_HEX_LEFT 0
167 #define CALC_NS_HEX_TOP 0
169 #define CALC_NS_DEC_LEFT 50
170 #define CALC_NS_DEC_TOP 0
172 #define CALC_NS_OCT_LEFT 98
173 #define CALC_NS_OCT_TOP 0
175 #define CALC_NS_BIN_LEFT 148
176 #define CALC_NS_BIN_TOP 0
178 // Measurement System Radio Buttons
180 #define CALC_MS_COUNT 3
181 #define ID_CALC_MS_DEGREES 2010
182 #define ID_CALC_MS_RADIANS 2011
183 #define ID_CALC_MS_GRADS 2012
185 #define TRIGMODE_DEGREES 0
186 #define TRIGMODE_RADIANS 1
187 #define TRIGMODE_GRADS 2
189 #define CALC_MS_OFFSET_X 225
190 #define CALC_MS_OFFSET_Y 37
192 #define SZ_RADIO_MS_X 75
193 #define SZ_RADIO_MS_Y 15
195 #define CALC_MS_DEGREES_LEFT 0
196 #define CALC_MS_DEGREES_TOP 0
198 #define CALC_MS_RADIANS_LEFT 82
199 #define CALC_MS_RADIANS_TOP 0
201 #define CALC_MS_GRADS_LEFT 162
202 #define CALC_MS_GRADS_TOP 0
204 // Inv and Hyp Checkboxes
206 #define CALC_CB_COUNT 2
207 #define ID_CALC_CB_INV 2020
208 #define ID_CALC_CB_HYP 2021
210 #define WORDSIZE_BYTE 1
211 #define WORDSIZE_WORD 2
212 #define WORDSIZE_DWORD 4
213 #define WORDSIZE_QWORD 8
215 #define CALC_CB_OFFSET_X 15
216 #define CALC_CB_OFFSET_Y 58
218 #define CALC_CB_INV_LEFT 0
219 #define CALC_CB_INV_TOP 10
221 #define SZ_RADIO_CB_X 50
222 #define SZ_RADIO_CB_Y 14
224 #define CALC_CB_HYP_LEFT 58
225 #define CALC_CB_HYP_TOP 10
227 // Word Size Radio Buttons
229 #define CALC_WS_COUNT 4
230 #define ID_CALC_WS_QWORD 2030
231 #define ID_CALC_WS_DWORD 2031
232 #define ID_CALC_WS_WORD 2032
233 #define ID_CALC_WS_BYTE 2033
235 #define CALC_WS_OFFSET_X CALC_MS_OFFSET_X
236 #define CALC_WS_OFFSET_Y CALC_MS_OFFSET_Y
238 #define CALC_WS_QWORD_LEFT 0
239 #define CALC_WS_QWORD_TOP 0
241 #define CALC_WS_DWORD_LEFT 57
242 #define CALC_WS_DWORD_TOP 0
244 #define CALC_WS_WORD_LEFT 120
245 #define CALC_WS_WORD_TOP 0
247 #define CALC_WS_BYTE_LEFT 175
248 #define CALC_WS_BYTE_TOP 0
250 #define SZ_RADIO_WS_X 50
251 #define SZ_RADIO_WS_Y 15
255 #define CALC_EDIT_HEIGHT 20
257 #define SZ_FILLER_X 32
258 #define SZ_FILLER_Y 30
260 #define SZ_BIGBTN_X 62
261 #define SZ_BIGBTN_Y 30
263 #define SZ_MEDBTN_X 36
264 #define SZ_MEDBTN_Y 30
266 #define MARGIN_LEFT 7
267 #define MARGIN_SMALL_X 3
268 #define MARGIN_SMALL_Y 3
269 #define MARGIN_BIG_X 274
270 #define MARGIN_STANDARD_BIG_X 11
271 #define MARGIN_BIG_Y 6
273 #define SZ_SPACER_X 11
275 // winecalc results display area
277 #define WDISPLAY_STANDARD_LEFT MARGIN_LEFT + 4
278 #define WDISPLAY_STANDARD_TOP 5
279 #define WDISPLAY_STANDARD_RIGHT 244
280 #define WDISPLAY_STANDARD_BOTTOM 24
281 #define CALC_STANDARD_MARGIN_TOP 16
283 #define WDISPLAY_SCIENTIFIC_LEFT MARGIN_LEFT + 4
284 #define WDISPLAY_SCIENTIFIC_TOP 5
285 #define WDISPLAY_SCIENTIFIC_RIGHT 465
286 #define WDISPLAY_SCIENTIFIC_BOTTOM 24
287 #define CALC_SCIENTIFIC_MARGIN_TOP 44
289 typedef struct tagCalcBtn
{
290 int id
; // private id
291 HWND hBtn
; // button child window handle
292 TCHAR label
[80]; // text on buttonface
293 int color
; // text color
295 int enable
; // 1 = control enbabled, 0 = disabled
299 typedef struct tagPos
{
305 typedef struct tagCalc
{
306 HINSTANCE hInst
; // this HINSTANCE
307 HWND hWnd
; // main window's HWND
310 int numButtons
; // standard = 28, scientific = more
312 TCHAR buffer
[CALC_BUF_SIZE
]; // current keyboard buffer
313 TCHAR display
[CALC_BUF_SIZE
]; // display buffer before output
315 calcfloat value
; // most recent computer value
316 calcfloat memory
; // most recent stored memory value from display buffer
317 int paren
; // current parentheses level
319 int sciMode
; // standard = 1, scientific = 0
320 int displayMode
; // 0 = float, 1 = scientific exponential notation like 1.0e+10
322 TCHAR oper
; // most recent operator pushed
323 calcfloat operand
; // most recent operand pushed
324 int newenter
; // track multiple =
325 int next
; // binary operation flag
326 int err
; // errror status for divide by zero, infinity, etc.
327 int init
; // starting buffer
329 int digitGrouping
; // no separators = 0, separators = 1
331 int trigMode
; // degrees = 0, radians = 1, grads = 2
332 int numBase
; // 10 = decimal, 2 = binary, 8 = octal, 16 = hex
333 int wordSize
; // 1 = byte, 2 = word, 4 = dword, 8 = qword
334 int invMode
; // INV mode 0 = off, 1 = on
335 int hypMode
; // HYP mode 0 = off, 1 = on
337 int new; // first time 0 = false, 1 = true
338 CALCBTN cb
[80]; // enough buttons for standard or scientific mode
342 BOOL CALLBACK
AboutDlgProc( HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
343 LRESULT WINAPI
MainProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
346 void InitMenus(HINSTANCE hInst
);
349 void InitCalc (CALC
*calc
);
350 void DestroyCalc (CALC
*calc
);
352 void calc_buffer_format(CALC
*calc
);
353 void calc_buffer_display(CALC
*calc
);
354 TCHAR
*calc_sep(TCHAR
*s
);
356 void DrawCalcText (HDC hdc
, HDC hMemDC
, PAINTSTRUCT
*ps
, CALC
*calc
, int object
, TCHAR
*s
);
357 void CalcRect (HDC hdc
, HDC hMemDC
, PAINTSTRUCT
*ps
, CALC
*calc
, int object
);
358 void DrawCalcRectSci(HDC hdc
, HDC hMemDC
, PAINTSTRUCT
*ps
, CALC
*calc
, RECT
*r
);
359 void DrawCalc (HDC hdc
, HDC hMemDC
, PAINTSTRUCT
*ps
, CALC
*calc
);
361 void calc_setmenuitem_radio(HMENU hMenu
, UINT id
);
363 void show_debug(CALC
*calc
, TCHAR
*title
, long wParam
, long lParam
);
365 calcfloat
calc_atof(const TCHAR
*s
, int base
);
366 void calc_ftoa(CALC
*calc
, calcfloat r
, TCHAR
*buf
);
367 long factorial(long n
);
369 calcfloat
calc_convert_to_radians(CALC
*calc
);
370 calcfloat
calc_convert_from_radians(CALC
*calc
);