home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / demos / calc.h < prev    next >
C/C++ Source or Header  |  1998-01-19  |  3KB  |  118 lines

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