You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.1 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*-------------------------------------------------------*/
  2. /* */
  3. /* Turbo Vision 1.0 */
  4. /* Copyright (c) 1991 by Borland International */
  5. /* */
  6. /* Calc.h: Header file for Calc.cpp */
  7. /*-------------------------------------------------------*/
  8. /* Ported by SET */
  9. #if defined(Uses_TCalcDisplay) && !defined( TCalcDisplay__ )
  10. #define TCalcDisplay__
  11. // SET: The following should be enough to hold the output of the %f modifier
  12. #define DISPLAYLEN 25 // Length (width) of calculator display
  13. enum TCalcState { csFirst = 1, csValid, csError };
  14. const int cmCalcButton = 200,
  15. // SET: Defined as commands
  16. cmCalcClear = cmCalcButton,
  17. cmCalcDelete = cmCalcButton+1,
  18. cmCalcPercent = cmCalcButton+2,
  19. cmCalcPlusMin = cmCalcButton+3,
  20. cmCalc7 = cmCalcButton+4,
  21. cmCalc8 = cmCalcButton+5,
  22. cmCalc9 = cmCalcButton+6,
  23. cmCalcDiv = cmCalcButton+7,
  24. cmCalc4 = cmCalcButton+8,
  25. cmCalc5 = cmCalcButton+9,
  26. cmCalc6 = cmCalcButton+10,
  27. cmCalcMul = cmCalcButton+11,
  28. cmCalc1 = cmCalcButton+12,
  29. cmCalc2 = cmCalcButton+13,
  30. cmCalc3 = cmCalcButton+14,
  31. cmCalcMinus = cmCalcButton+15,
  32. cmCalc0 = cmCalcButton+16,
  33. cmCalcDecimal = cmCalcButton+17,
  34. cmCalcEqual = cmCalcButton+18,
  35. cmCalcPlus = cmCalcButton+19;
  36. class TRect;
  37. class TPalette;
  38. struct TEvent;
  39. class TCalcDisplay : public TView
  40. {
  41. public:
  42. TCalcDisplay(TRect& r);
  43. ~TCalcDisplay();
  44. virtual TPalette& getPalette() const;
  45. virtual void handleEvent(TEvent& event);
  46. virtual void draw();
  47. private:
  48. TCalcState status;
  49. char *number;
  50. char sign;
  51. char operate; // since 'operator' is a reserved word.
  52. double operand;
  53. void calcKey(unsigned char key, unsigned code);
  54. void checkFirst();
  55. void setDisplay(double r);
  56. void clear();
  57. void error();
  58. inline double getDisplay() { return( atof( number ) ); };
  59. #if !defined( NO_STREAM )
  60. virtual const char *streamableName() const
  61. { return name; }
  62. protected:
  63. virtual void write( opstream& );
  64. virtual void *read( ipstream& );
  65. public:
  66. TCalcDisplay( StreamableInit ) : TView(streamableInit) { };
  67. static const char * const name;
  68. static TStreamable *build();
  69. #endif // NO_STREAM
  70. };
  71. #if !defined( NO_STREAM )
  72. inline ipstream& operator >> ( ipstream& is, TCalcDisplay& cl )
  73. { return is >> (TStreamable&) cl; }
  74. inline ipstream& operator >> ( ipstream& is, TCalcDisplay*& cl )
  75. { return is >> (void *&) cl; }
  76. inline opstream& operator << ( opstream& os, TCalcDisplay& cl )
  77. { return os << (TStreamable&) cl; }
  78. inline opstream& operator << ( opstream& os, TCalcDisplay* cl )
  79. { return os << (TStreamable *) cl; }
  80. #endif // NO_STREAM
  81. #endif // Uses_TCalcDisplay
  82. #if defined(Uses_TCalculator) && !defined( TCalculator__ )
  83. #define TCalculator__
  84. class TCalculator : public TDialog
  85. {
  86. public:
  87. TCalculator();
  88. static char *keyChar[20];
  89. #if !defined( NO_STREAM )
  90. TCalculator( StreamableInit ) :
  91. TWindowInit(&TCalculator::initFrame), TDialog(streamableInit) { };
  92. private:
  93. virtual const char *streamableName() const
  94. { return name; }
  95. //protected:
  96. // virtual void write( opstream& );
  97. // virtual void *read( ipstream& );
  98. public:
  99. static const char * const name;
  100. static TStreamable *build();
  101. #endif // NO_STREAM
  102. };
  103. #if !defined( NO_STREAM )
  104. inline ipstream& operator >> ( ipstream& is, TCalculator& cl )
  105. { return is >> (TStreamable&) cl; }
  106. inline ipstream& operator >> ( ipstream& is, TCalculator*& cl )
  107. { return is >> (void *&) cl; }
  108. inline opstream& operator << ( opstream& os, TCalculator& cl )
  109. { return os << (TStreamable&) cl; }
  110. inline opstream& operator << ( opstream& os, TCalculator* cl )
  111. { return os << (TStreamable *) cl; }
  112. #endif // NO_STREAM
  113. #endif // Uses_TCalculator