kspread

kcalc.h
1/*
2 $Id: kcalc.h 466447 2005-10-02 17:54:10Z zander $
3
4 KCalc, a scientific calculator for the X window system using the
5 TQt widget libraries, available at no cost at http://www.troll.no
6
7 Copyright (C) 1996 Bernd Johannes Wuebben
8 wuebben@math.cornell.edu
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24
25*/
26
27#ifndef TQTCALC_H
28#define TQTCALC_H
29
30#include <queue>
31using std::queue;
32
33#include <unistd.h>
34#include <stdlib.h>
35#include <ctype.h>
36
37#include <tqlistbox.h>
38#include <tqclipboard.h>
39#include <tqptrlist.h>
40#include <tqaccel.h>
41#include <tqtabdialog.h>
42#include <tqwidget.h>
43#include <tqtimer.h>
44#include <tqdialog.h>
45#include <tqpixmap.h>
46#include <tqapplication.h>
47#include <tqfont.h>
48#include <tqlabel.h>
49#include <tqbuttongroup.h>
50#include <tqcheckbox.h>
51#include <tqframe.h>
52#include <tqgroupbox.h>
53#include <tqlineedit.h>
54#include <tqpushbutton.h>
55#include <tqradiobutton.h>
56#include <tqtooltip.h>
57#include <tqstring.h>
58#include <tqrect.h>
59
60
61#include "dlabel.h"
62#include "stats.h"
63
64// IMPORTANT this has to come after ../config.h
65#include "kcalctype.h"
66
67#define STACK_SIZE 100
68#define TEMP_STACK_SIZE 1000 // the number of numbers kept in the temp stack
69 // which are accessible with the up and down arrow
70 // key
71
72#define PRECEDENCE_INCR 20
73
74#define FUNC_NULL 0
75#define FUNC_OR 1
76#define FUNC_XOR 2
77#define FUNC_AND 3
78#define FUNC_LSH 4
79#define FUNC_RSH 5
80#define FUNC_ADD 6
81#define FUNC_SUBTRACT 7
82#define FUNC_MULTIPLY 8
83#define FUNC_DIVIDE 9
84#define FUNC_MOD 10
85#define FUNC_POWER 11
86#define FUNC_PWR_ROOT 12
87#define FUNC_INTDIV 13
88
89#define DEC_SIZE 19
90#define BOH_SIZE 16
91#define DSP_SIZE 50 //25
92
93#define DEG2RAD(x) (((2L*pi)/360L)*x)
94#define GRA2RAD(x) ((pi/200L)*x)
95#define RAD2DEG(x) ((360L/(2L*pi))*x)
96#define RAD2GRA(x) ((200L/pi)*x)
97#define POS_ZERO 1e-19L /* What we consider zero is */
98#define NEG_ZERO -1e-19L /* anything between these two */
99
100
101typedef CALCAMNT (*Arith)(CALCAMNT, CALCAMNT);
102typedef CALCAMNT (*Prcnt)(CALCAMNT, CALCAMNT, CALCAMNT);
103typedef CALCAMNT (*Trig)(CALCAMNT);
104
105typedef enum _last_input_type {
106 DIGIT = 1, OPERATION = 2, RECALL = 3, PASTE = 4
107} last_input_type;
108
109typedef enum _num_base {
110 NB_BINARY = 2, NB_OCTAL = 8, NB_DECIMAL = 10, NB_HEX = 16
111} num_base;
112
113typedef enum _angle_type {
114 ANG_DEGREE = 0, ANG_RADIAN = 1, ANG_GRADIENT = 2
115} angle_type;
116
117typedef enum _item_type {
118 ITEM_FUNCTION, ITEM_AMOUNT
119} item_type;
120
121typedef struct _func_data {
122 int item_function;
123 int item_precedence;
124} func_data;
125
126typedef union _item_data { /* The item data */
127 CALCAMNT item_amount; /* an amount */
128 func_data item_func_data; /* or a function */
129} item_data; /* called item_data */
130
131typedef struct _item_contents { /* The item contents */
132 item_type s_item_type; /* a type flag */
133 item_data s_item_data; /* and data */
134} item_contents;
135
136typedef struct stack_item *stack_ptr;
137
138typedef struct stack_item {
139
140 /* Contents of an item on the input stack */
141
142 stack_ptr prior_item; /* Pointer to prior item */
143 stack_ptr prior_type; /* Pointer to prior type */
144 item_contents item_value; /* The value of the item */
145
146} stack_item; /* all called stack_item */
147
148
149CALCAMNT ExecOr(CALCAMNT left_op, CALCAMNT right_op);
150CALCAMNT ExecXor(CALCAMNT left_op, CALCAMNT right_op);
151CALCAMNT ExecAnd(CALCAMNT left_op, CALCAMNT right_op);
152CALCAMNT ExecLsh(CALCAMNT left_op, CALCAMNT right_op);
153CALCAMNT ExecRsh(CALCAMNT left_op, CALCAMNT right_op);
154CALCAMNT ExecAdd(CALCAMNT left_op, CALCAMNT right_op);
155CALCAMNT ExecSubtract(CALCAMNT left_op, CALCAMNT right_op);
156CALCAMNT ExecMultiply(CALCAMNT left_op, CALCAMNT right_op);
157CALCAMNT ExecDivide(CALCAMNT left_op, CALCAMNT right_op);
158CALCAMNT ExecMod(CALCAMNT left_op, CALCAMNT right_op);
159CALCAMNT ExecPower(CALCAMNT left_op, CALCAMNT right_op);
160CALCAMNT ExecPwrRoot(CALCAMNT left_op, CALCAMNT right_op);
161CALCAMNT ExecIntDiv(CALCAMNT left_op, CALCAMNT right_op);
162
163CALCAMNT ExecAddSubP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
164CALCAMNT ExecMultiplyP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
165CALCAMNT ExecDivideP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
166CALCAMNT ExecPowerP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
167CALCAMNT ExecPwrRootP(CALCAMNT left_op, CALCAMNT right_op, CALCAMNT result);
168
169
170int UpdateStack(int run_precedence);
171CALCAMNT ExecFunction(CALCAMNT left_op, int function, CALCAMNT right_op);
172int cvb(char *out_str, long amount, int max_out);
173
174void PrintStack(void);
175void InitStack(void);
176void PushStack(item_contents *add_item);
177item_contents *PopStack(void);
178item_contents *TopOfStack(void);
179item_contents *TopTypeStack(item_type rqstd_type);
180
181
182#define DISPLAY_AMOUNT display_data.s_item_data.item_amount
183
184
185
186typedef struct _DefStruct{
187 TQColor forecolor;
188 TQColor backcolor;
189 int precision;
190 int fixedprecision;
191 int style;
192 bool fixed;
193 bool beep;
194 TQFont font;
195}DefStruct;
196
197class Calculator;
198
199class TQtCalculator : public TQDialog
200{
201 TQ_OBJECT
202
203
204public:
205
206 TQtCalculator( Calculator* _corba, TQWidget *parent=0, const char *name=0 );
207 ~TQtCalculator();
208
209 void keyPressEvent( TQKeyEvent *e );
210 void keyReleaseEvent( TQKeyEvent *e );
211 void closeEvent( TQCloseEvent *e );
212 void readSettings();
213 void writeSettings();
214 void set_precision();
215 void set_style();
216 void set_display_font();
217 void temp_stack_next();
218 void temp_stack_prev();
219 void ComputeMean();
220 void ComputeSin();
221 void ComputeStd();
222 void ComputeCos();
223 void ComputeMedean();
224 void ComputeTan();
225 void ComputeSum();
226 void ComputeMul();
227 void ComputeMin();
228 void ComputeMax();
229
230 void setLabel( const char *_text );
231 void setValue( double _value );
232 void setData( const TQRect& _range, const char *_sheet );
233 void useData();
234
235public slots:
236
237 void helpclicked();
238 void set_colors();
239 void display_selected();
240 void invertColors();
241 void selection_timed_out();
242 void clear_buttons();
243 void clear_status_label();
244 void setStatusLabel(const TQString&);
245 void EnterDigit(int data);
246 void EnterDecimal();
247 void EnterStackFunction(int data);
248 void EnterNegate();
249 void EnterOpenParen();
250 void EnterCloseParen();
251 void EnterRecip();
252 void EnterInt();
253 void EnterFactorial();
254 void EnterSquare();
255 void EnterNotCmp();
256 void EnterHyp();
257 void EnterPercent();
258 void EnterLogr();
259 void EnterLogn();
260 void SetDeg();
261 void SetGra();
262 void SetRad();
263 void SetHex();
264 void SetOct();
265 void SetBin();
266 void SetDec();
267 void Deg_Selected();
268 void Rad_Selected();
269 void Gra_Selected();
270 void Hex_Selected();
271 void Dec_Selected();
272 void Oct_Selected();
273 void Bin_Selected();
274 void SetInverse();
275 void EnterEqual();
276 void Clear();
277 void ClearAll();
278 void RefreshCalculator(void);
279 void InitializeCalculator(void);
280 void UpdateDisplay();
281 void ExecSin();
282 void ExecCos();
283 void ExecTan();
284 void button0();
285 void button1();
286 void button2();
287 void button3();
288 void button4();
289 void button5();
290 void button6();
291 void button7();
292 void button8();
293 void button9();
294 void buttonA();
295 void buttonB();
296 void buttonC();
297 void buttonD();
298 void buttonE();
299 void buttonF();
300 void base_selected(int number);
301 void angle_selected(int number);
302 void Or();
303 void And();
304 void Shift();
305 void Plus();
306 void Minus();
307 void Multiply();
308 void Divide();
309 void Mod();
310 void Power();
311 void EE();
312 void MR();
313 void Mplusminus();
314 void MC();
315 void exit();
316 void EEtoggled(bool myboolean);
317 void pbinvtoggled(bool myboolean);
318 void pbMRtoggled(bool myboolean);
319 void pbAtoggled(bool myboolean);
320 void pbSintoggled(bool myboolean);
321 void pbplusminustoggled(bool myboolean);
322 void pbMplusminustoggled(bool myboolean);
323 void pbBtoggled(bool myboolean);
324 void pbCostoggled(bool myboolean);
325 void pbrecitoggled(bool myboolean);
326 void pbCtoggled(bool myboolean);
327 void pbTantoggled(bool myboolean);
328 void pbfactorialtoggled(bool myboolean);
329 void pbDtoggled(bool myboolean);
330 void pblogtoggled(bool myboolean);
331 void pbsquaretoggled(bool myboolean);
332 void pbEtoggled(bool myboolean);
333 void pblntoggled(bool myboolean);
334 void pbpowertoggled(bool myboolean);
335 void pbFtoggled(bool myboolean);
336 void pbMCtoggled(bool myboolean);
337 void pbCleartoggled(bool myboolean);
338 void pbACtoggled(bool myboolean);
339 void pb7toggled(bool myboolean);
340 void pb8toggled(bool myboolean);
341 void pb9toggled(bool myboolean);
342 void pbparenopentoggled(bool myboolean);
343 void pbparenclosetoggled(bool myboolean);
344 void pbandtoggled(bool myboolean);
345 void pb4toggled(bool myboolean);
346 void pb5toggled(bool myboolean);
347 void pb6toggled(bool myboolean);
348 void pbXtoggled(bool myboolean);
349 void pbdivisiontoggled(bool myboolean);
350 void pbortoggled(bool myboolean);
351 void pb1toggled(bool myboolean);
352 void pb2toggled(bool myboolean);
353 void pb3toggled(bool myboolean);
354 void pbplustoggled(bool myboolean);
355 void pbminustoggled(bool myboolean);
356 void pbshifttoggled(bool myboolean);
357 void pbperiodtoggled(bool myboolean);
358 void pb0toggled(bool myboolean);
359 void pbequaltoggled(bool myboolean);
360 void pbpercenttoggled(bool myboolean);
361 void pbnegatetoggled(bool myboolean);
362 void pbmodtoggled(bool myboolean);
363 void pbhyptoggled(bool myboolean);
364 void configclicked();
365
366public:
367
368 DefStruct kcalcdefaults;
369
370private:
371 void updateGeometry();
372
373 TQTimer* selection_timer;
374 TQLabel* statusINVLabel;
375 TQLabel* statusHYPLabel;
376 TQLabel* statusERRORLabel;
377 DLabel* calc_display;
378 TQRadioButton* anglebutton[3];
379 TQRadioButton* basebutton[4];
380 TQPushButton* pbhyp;
381 TQPushButton* pbEE;
382 TQPushButton* pbinv;
383 TQPushButton* pbMR;
384 TQPushButton* pbA;
385 TQPushButton* pbSin;
386 TQPushButton* pbplusminus;
387 TQPushButton* pbMplusminus;
388 TQPushButton* pbB;
389 TQPushButton* pbCos;
390 TQPushButton* pbreci;
391 TQPushButton* pbC;
392 TQPushButton* pbTan;
393 TQPushButton* pbfactorial;
394 TQPushButton* pbD;
395 TQPushButton* pblog;
396 TQPushButton* pbsquare;
397 TQPushButton* pbE;
398 TQPushButton* pbln;
399 TQPushButton* pbpower;
400 TQPushButton* pbF;
401 TQPushButton* pbMC;
402 TQPushButton* pbClear;
403 TQPushButton* pbAC;
404 TQPushButton* pb7;
405 TQPushButton* pb8;
406 TQPushButton* pb9;
407 TQPushButton* pbparenopen;
408 TQPushButton* pbparenclose;
409 TQPushButton* pband;
410 TQPushButton* pb4;
411 TQPushButton* pb5;
412 TQPushButton* pb6;
413 TQPushButton* pbX;
414 TQPushButton* pbdivision;
415 TQPushButton* pbor;
416 TQPushButton* pb1;
417 TQPushButton* pb2;
418 TQPushButton* pb3;
419 TQPushButton* pbplus;
420 TQPushButton* pbminus;
421 TQPushButton* pbshift;
422 TQPushButton* pbperiod;
423 TQPushButton* pb0;
424 TQPushButton* pbequal;
425 TQPushButton* pbpercent;
426 TQPushButton* pbnegate;
427 TQPushButton* pbmod;
428
429 TQPtrList<TQPushButton> mNumButtonList;
430 TQPtrList<TQPushButton> mFunctionButtonList;
431 TQPtrList<TQPushButton> mHexButtonList;
432 TQPtrList<TQPushButton> mMemButtonList;
433 TQPtrList<TQPushButton> mOperationButtonList;
434
435 bool key_pressed;
436 KStats stats;
437 TQListBox *paper;
438 TQTimer *status_timer;
439
440 TQRect sheet_range;
441 TQString sheet_name;
442 Calculator* corba;
443 TQWidget *mSmallPage;
444 TQWidget *mLargePage;
445 int mInternalSpacing;
446};
447
448#endif //TQTCLAC_H