home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / database / ooed / ooed.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-27  |  4.6 KB  |  153 lines

  1. // INFINITY used for infinite loops -- while(!INFINITY)...
  2.  
  3. #define INFINITY 0
  4.  
  5. // Keystroke -- A key class for C++. Stores a key scan code with
  6. // KEYSTROKE::GETKEY(). Special will be 1 if alt is hit or one of the
  7. // other "special" keys are pressed.
  8.  
  9. #define HOMEKEY       71
  10. #define UPARROW       72
  11. #define LEFTARROW     75
  12. #define RIGHTARROW    77
  13. #define ENDKEY        79
  14. #define DOWNARROW     80
  15. #define INSERTKEY     82
  16. #define DELETEKEY     83
  17.  
  18. // Not so special keys
  19. #define BACKSPACE      8
  20. #define RETURN        13
  21. #define ESCAPE        27
  22.  
  23. class KEYSTROKE
  24.   {
  25.    protected:
  26.    union SCAN
  27.       {
  28.        int c;
  29.        char ch[2];
  30.       };
  31.  
  32.    void GETKEY();
  33.  
  34.    public:
  35.    char lastkey;    // Last key hit
  36.    char special;    // 1 if last key hit is special
  37.   };
  38.  
  39. // Derive various classes from ED. We can do less with ED itself than
  40. // we can with GETKEY.
  41.  
  42. class ED
  43.   {
  44.    int row, col;
  45.    public:
  46.    ED();           // Edits a variable at current cursor position
  47.    ED(int,         // Edits a variable at row,
  48.       int);        // Col
  49.    virtual void *get() = 0;
  50.    int startrow() { return row; }
  51.    int startcol() { return col; }
  52.   };
  53.  
  54. // EDSTR edits a simple string of a certian length at a screen position --
  55. // does not check to see if you went off the screen with your length
  56. // because I want to keep this moderately compatable with display
  57. // adapters that go over 80 columns.
  58.  
  59. class EDSTR : public ED, public KEYSTROKE
  60.   {
  61.    protected:
  62.    int datalen;
  63.    char *data;          // String to use
  64.    int curx,            // Current cursor X position
  65.        cury;            // Current cursor Y position
  66.    int loc;             // Current position in data
  67.    virtual int RIGHT(); // Moves cursor 1 space right
  68.    virtual int LEFT();  // Moves cursor 1 space left
  69.    virtual int DEL();   // Deletes 1 character -- Moves everthing right 1 space
  70.    virtual int BKSP();  // LEFT + DEL
  71.    virtual int INS();   // Inserts a space at the cursor
  72.    virtual int HOME();  // Home key -- moves to beginning of field
  73.    virtual int END();   // End key -- moves to end of field
  74.    virtual int NORMAL(); // Normal keypress -- insert in data
  75.    public:
  76.    EDSTR(char *,        // Edit a string at the current row, col of
  77.          int);          // n length.
  78.    EDSTR(int,           // Edit a string at row, col of n length
  79.          int,           // Col
  80.          char *,        // String to edit
  81.      int);          // length
  82.  
  83.    void *get();         // Overrides get in ED
  84.   };
  85.  
  86. // EDFANCY - Edits a string -- Alows a mask such as "  /  /  ". EDFANCY
  87. // will automagically skip over anything in that mask that is not a space.
  88. // The mask will be displayed before the string is edited.
  89. //
  90. // EDFANCY also does not check for bounds as some adapters may go more
  91. // than 80 columns. Also NORMAL still allows control chars.
  92.  
  93. class EDFANCY : public EDSTR
  94.    {
  95.     protected:
  96.     int ERR;
  97.     char *mask;
  98.     int INS();
  99.     int DEL();
  100.     int NORMAL();
  101.     virtual int ISKNOWN(int);
  102.     virtual int ISKNOWN();
  103.                  // Returns a 1 if loc (or whatever) is ' '
  104.     virtual int onmask();    // Returns a 1 if loc is on a mask char
  105.     virtual int onmask(int); // Returns a 1 if int is on a mask char
  106.     public:
  107.     EDFANCY(int,         // Row
  108.             int,         // Column
  109.             char *,      // Mask
  110.             char *,      // Data
  111.         int);        // Length
  112.     ~EDFANCY();
  113.  
  114.     virtual void DISPLAY(); // Displays mask before editing.
  115.     void *get();         // Check this out down the file a ways
  116.    };
  117.  
  118. // This is the good one...
  119.  
  120. // EDPIC allows the user to force input into a given picture.
  121. // Ex. A mask of "##/##/##" is supplied. If the user tries to enter
  122. // Alpha data, the data will not be accepted. The #'s will not show,
  123. // and the user will be able to type numbers over them.
  124. //
  125. // # - Numeric Data (0-9 and .)
  126. // (space) - Any data
  127. // A - Uppercase alpha
  128. // a - lowercase alpha
  129. // + - Extended numeric (Numeric and +,-,/,*,^,,)
  130. // X - Alphanumeric (No control characters)
  131. // H - Hex number characters 0-9 A-F
  132.  
  133. class EDPIC : public EDFANCY
  134. {
  135.  protected:
  136.  int NORMAL();
  137.  int ISKNOWN();
  138.  int ISKNOWN(int);
  139.  virtual int ISGOOD(int);
  140.  virtual int ISGOOD();
  141.               // Returns a 1 if lastkey is an acceptable character --
  142.               // compares it to mask. Characters forced into areas
  143.               // where they should not be with DEL and INS will go
  144.               // away.
  145.  public:
  146.  
  147.  EDPIC(int,       // Row
  148.        int,       // Column
  149.        char *,    // Mask
  150.        char *,    // Data
  151.        int);      // Length
  152.  };
  153.