home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / TVDEMOS.ZIP / CALC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.9 KB  |  114 lines

  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.  
  9. #if !defined( __CALC_H )
  10. #define __CALC_H
  11.  
  12. #if !defined( __MATH_H )
  13. #include <math.h>
  14. #endif       // __MATH_H
  15.  
  16. #define DISPLAYLEN  25      // Length (width) of calculator display
  17.  
  18. enum TCalcState { csFirst = 1, csValid, csError };
  19.  
  20. const int cmCalcButton  = 200;
  21.  
  22.  
  23. class TCalcDisplay : public TView
  24. {
  25.  
  26. public:
  27.  
  28.     TCalcDisplay(TRect& r);
  29.     TCalcDisplay( StreamableInit ) : TView(streamableInit) { };
  30.     ~TCalcDisplay();
  31.     virtual TPalette& getPalette() const;
  32.     virtual void handleEvent(TEvent& event);
  33.     virtual void draw();
  34.  
  35. private:
  36.  
  37.     TCalcState status;
  38.     char *number;
  39.     char sign;
  40.     char operate;           // since 'operator' is a reserved word.
  41.     double operand;
  42.  
  43.     void calcKey(unsigned char key);
  44.     void checkFirst();
  45.     void setDisplay(double r);
  46.     void clear();
  47.     void error();
  48.     inline double getDisplay() { return( atof( number ) ); };
  49.  
  50.     virtual const char *streamableName() const
  51.         { return name; }
  52.  
  53. protected:
  54.  
  55.     virtual void write( opstream& );
  56.     virtual void *read( ipstream& );
  57.  
  58. public:
  59.  
  60.     static const char * const name;
  61.     static TStreamable *build();
  62.  
  63. };
  64.  
  65. inline ipstream& operator >> ( ipstream& is, TCalcDisplay& cl )
  66.     { return is >> (TStreamable&) cl; }
  67. inline ipstream& operator >> ( ipstream& is, TCalcDisplay*& cl )
  68.     { return is >> (void *&) cl; }
  69.  
  70. inline opstream& operator << ( opstream& os, TCalcDisplay& cl )
  71.     { return os << (TStreamable&) cl; }
  72. inline opstream& operator << ( opstream& os, TCalcDisplay* cl )
  73.     { return os << (TStreamable *) cl; }
  74.  
  75.  
  76. class TCalculator : public TDialog
  77. {
  78.  
  79. public:
  80.  
  81.     TCalculator();
  82.     TCalculator( StreamableInit ) :
  83.         TDialog(streamableInit), TWindowInit(&TCalculator::initFrame) { };
  84.  
  85. private:
  86.  
  87.     virtual const char *streamableName() const
  88.         { return name; }
  89.  
  90. //protected:
  91.  
  92. //    virtual void write( opstream& );
  93. //    virtual void *read( ipstream& );
  94.  
  95. public:
  96.  
  97.     static const char * const name;
  98.     static TStreamable *build();
  99.  
  100. };
  101.  
  102. inline ipstream& operator >> ( ipstream& is, TCalculator& cl )
  103.     { return is >> (TStreamable&) cl; }
  104. inline ipstream& operator >> ( ipstream& is, TCalculator*& cl )
  105.     { return is >> (void *&) cl; }
  106.  
  107. inline opstream& operator << ( opstream& os, TCalculator& cl )
  108.     { return os << (TStreamable&) cl; }
  109. inline opstream& operator << ( opstream& os, TCalculator* cl )
  110.     { return os << (TStreamable *) cl; }
  111.  
  112.  
  113. #endif      // __CALC_H
  114.