home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / tfield / tfield.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-24  |  15.9 KB  |  581 lines

  1. //
  2. // Compiler:            Borland C++, Release 3.0x
  3. //
  4. //   TFIELD.H -- Version 1.1.1
  5. //
  6. //   Portions Copyright (c) Borland International 1991
  7. //   All Rights Reserved.
  8. //
  9. //   TV Extensions are Copyright (c) 1992 by Michael Bonner
  10. //   These extensions may be freely used by any programmer
  11. //   including royalty free inclusion in any commercial
  12. //   application, but any commercial rights to the source
  13. //   code or object files of the Extensions are reserved.
  14. //
  15. //   defines the classes TField, TUpperField, TDateField, TDate, TIntField
  16. //                       TLowerField, TLongField, TFloatField, TDoubleField
  17. //                       TLongDoubleField
  18. //
  19. //   Thanks to Jerry Jankura CI$ 70170,306 who contributed the TLower and TDouble
  20. //      fields.
  21. //
  22.  
  23.  
  24. //
  25. //      class TField
  26. //
  27. //      Palette layout
  28. //        1 = Passive
  29. //        2 = Active
  30. //        3 = Selected
  31. //        4 = Arrows
  32. //
  33.  
  34. #if !defined( __CTYPE_H )
  35. #include <ctype.h>
  36. #endif  // __CTYPE_H
  37.  
  38. #if !defined( __STDIO_H )
  39. #include <stdio.h>
  40. #endif
  41.  
  42. #if !defined( __STRING_H )
  43. #include <string.h>
  44. #endif
  45.  
  46. #if !defined( __STDLIB_H )
  47. #include <stdlib.h>
  48. #endif
  49.  
  50. #if !defined( __IOSTREAM_H )
  51. #include <iostream.h>
  52. #endif
  53.  
  54. #if !defined( __DOS_H )
  55. #include <dos.h>
  56. #endif
  57.  
  58. #if defined( Uses_TDateField )
  59. #define Uses_TField
  60. #define Uses_TDate
  61. #endif
  62.  
  63. #if defined ( Uses_TDoubleField )
  64. #define Uses_Tfield
  65. #endif
  66.  
  67. #if defined ( Uses_TLongDoubleField )
  68. #define Uses_Tfield
  69. #endif
  70.  
  71. #if defined( Uses_TIntField )
  72. #define Uses_TField
  73. #endif
  74.  
  75. #if defined( Uses_TLongField )
  76. #define Uses_TField
  77. #endif
  78.  
  79. #if defined( Uses_TLowerField )
  80. #define Uses_TField
  81. #endif
  82.  
  83. #if defined( Uses_TFloatField )
  84. #define Uses_TField
  85. #endif
  86.  
  87. #if defined( Uses_TUpperField )
  88. #define Uses_TField
  89. #endif
  90.  
  91. #if defined( Uses_TDate )
  92. #define Uses_TStringCollection
  93. #endif
  94.  
  95. #if defined ( Uses_TStringCollection ) && !defined( __TStringCollection )
  96. #include <tv.h>
  97. #endif
  98.  
  99. #if defined( Uses_TField ) && !defined( __TField )
  100. #define __TField
  101.  
  102. inline void beep (void)
  103. {
  104.   cout << (char) 7;
  105. }
  106.  
  107. //************************************************************************
  108. // 2/1/92 -- MBB
  109. // Added the following codes for tfOptions
  110. //************************************************************************
  111. const ushort
  112.     tfRight = 0x0001,
  113.     tfNoScroll = 0x0002,
  114.     tfHideSecure = 0x0004,
  115.     tfValidateMax = 0x0008,
  116.     tfValidateMin = 0x0010,
  117.     tfMustFill = 0x0020,
  118.     tfNotEmpty = 0x0040,
  119.     tfBeepError = 0x0080,
  120.     tfEnterTabs = 0x0100,
  121.     tfStayError = 0x0200,
  122.     tfPopUp = 0x0400,
  123.     tfPreValidate = 0x1000;
  124.  
  125. //
  126. // Field Type Constants
  127. //
  128. const int TFieldType = 1;
  129. const int TUpperFieldType = 2;
  130. const int TLowerFieldType = 3;
  131. const int TDateFieldType = 4;
  132. const int TIntFieldType = 5;
  133. const int TLongFieldType = 6;
  134. const int TFloatFieldType = 7;
  135. const int TDoubleFieldType = 8;
  136. const int TLongDoubleFieldType = 9;
  137.  
  138. //
  139. // Added by JFJ to remove hard coded values from member functions
  140. // and consolidate them into one place.
  141. //
  142.  
  143. const int SizeLongDouble = 25;  // Buffer Size for Long Double Precision
  144. const int SizeDouble = 25;      // Buffer Size for Double Precision
  145. const int SizeFloat = 25;       // Buffer Size for Single Precision
  146. const int SizeInt = 18;         // Buffer Size for Integer
  147. const int SizeLong = 18;        // Buffer Size for Long Integer
  148.  
  149. //
  150. // BroadCast Messages for TField
  151. //
  152. const ushort
  153.     cmUpdateSecurity = 0xCC01,        // message to fields to reset the current
  154.                                             // security level
  155.     cmLeaving = 0xCC02,           // validate on leaving the current field
  156.     cmArriving = 0xCC03;          // validate on arriving at the current field
  157.  
  158.  
  159. class far TRect;
  160. class far TEvent;
  161.  
  162. class TField : public TView
  163.     {
  164.  
  165.     public:
  166.  
  167.         TField (const TRect & bounds, int aMaxLen);
  168.         ~TField ();
  169.  
  170.         virtual void convertData (void);
  171.         virtual ushort dataSize ();
  172.         virtual void draw ();
  173.         virtual ushort filterCharCode (ushort charCode);
  174.         virtual void getData (void * rec);
  175.         virtual TPalette & getPalette () const;
  176.         virtual void gotFocus (void);
  177.         virtual void handleEvent (TEvent & event);
  178.         virtual Boolean isValid (ushort command);
  179.         virtual void lostFocus (void);
  180.         virtual ushort processKeyCode (ushort keyCode);
  181.         void selectAll (Boolean enable);
  182.         virtual void setCurrentSecurity (ushort newSecurityLevel);
  183.         virtual void setData (void * rec);
  184.         virtual void setFieldHint (char * aString);
  185.         virtual void setFieldName (char * aString);
  186.         virtual void setHideChar (char aChar);
  187.         virtual void setTFOptions (ushort anOption, Boolean enable);
  188.         virtual Boolean valid (ushort command);
  189.  
  190.         char * data;
  191.         int maxLen;
  192.         int curPos;
  193.         int firstPos;
  194.         int selStart;
  195.         int selEnd;
  196.         ushort tfOptions;
  197.  
  198. //
  199. // tfRight -- right justification on, otherwise will left justify
  200. // tfNoScroll -- scrolling off, otherwise will scroll
  201. // tfHideSecure -- if fieldSecurity > currentSecurity then mask the field
  202. //               with securityChar
  203. // tfValidateMax -- check the fields value against the specified Max value
  204. // tfValidateMin -- check the fields value against the specified Min value
  205. // tfMustFill -- field must contain maxLen characters
  206. // tfNotEmpty -- field must contain at least 1 character
  207. // tfBeepError -- beep at invalid keystrokes and error
  208. // tfEnterTabs -- map the enter key to the tab key
  209. // tfStayError -- if set, the field can't be left unless it is valid
  210. // tfPopUp -- enable popup fill-in (eg. calendar for dates &
  211. //            calculator for numbers)
  212. // tfPreValidate -- call the isValid function before performing other
  213. //                  standard validations
  214.  
  215.         char hideChar;                   // if hideChar > ' ' then field is masked
  216.         char securityChar;// used with security checking for masking secure fields
  217.         ushort fieldSecurity;            // security level for this field
  218.         ushort currentSecurity;          // security level from the owner
  219.         char * fieldHint;                // used for the hint line
  220.         char * fieldName;                // holds a name for the current field
  221.         int fieldType; // for determining type is passed as a generic TField * pointer
  222.  
  223.     private:
  224.  
  225.         Boolean canScroll (int delta);
  226.         int mouseDelta (TEvent & event);
  227.         int mousePos (TEvent & event);
  228.         void deleteSelect ();
  229.  
  230.         static const char near rightArrow;
  231.         static const char near leftArrow;
  232.  
  233.         virtual const char * streamableName () const
  234.             { return name; }
  235.  
  236.     protected:
  237.         Boolean dataChanged;             // tracks is data needs convertsion
  238.  
  239.         TField (StreamableInit);
  240.         virtual void write (opstream&);
  241.         virtual void * read (ipstream&);
  242.  
  243.     public:
  244.  
  245.         static const char * const near name;
  246.         static TStreamable * build ();
  247.  
  248.     };
  249.  
  250. inline ipstream & operator >> (ipstream & is, TField & cl)
  251. { return is >> (TStreamable&) cl; }
  252. inline ipstream & operator >> (ipstream & is, TField * &cl)
  253. { return is >> (void * &) cl; }
  254.  
  255. inline opstream & operator << (opstream & os, TField & cl)
  256. { return os << (TStreamable&) cl; }
  257. inline opstream & operator << (opstream & os, TField * cl)
  258. { return os << (TStreamable *) cl; }
  259.  
  260. #endif  // Uses_TField
  261.  
  262.  
  263. #if defined( Uses_TDate ) && !defined( __TDate )
  264. #define __TDate
  265.  
  266. #define ABBR_LENGTH 3
  267.  
  268. const int maxLine = 81;
  269.  
  270. const enum format_type { MDY, DAY, MONTH, FULL, EUROPEAN };
  271. const enum { OFF, ON };
  272.  
  273. const unsigned char NO_CENTURY = 0x02;
  274. const unsigned char DATE_ABBR = 0x04;
  275.  
  276. const long PXOffset = 1721424L;
  277.  
  278. class TParser : public TStringCollection
  279. {
  280.  
  281. public:
  282.  
  283.   TParser (short aLimit, short aDelta) :
  284.     TStringCollection (aLimit, aDelta) { }
  285. #pragma argsused
  286.   virtual int compare (void * key1, void * key2)
  287.   {
  288.     // add in order encountered
  289.     return - 1;
  290.   };
  291.   void parse (char * line);
  292.  
  293. };
  294.  
  295.  
  296. class TDate
  297. {
  298. protected:
  299.   unsigned long julian;            // days since 1/1/4713 B.C.
  300.   int tdate_year;
  301.   int tdate_month;
  302.   int tdate_day;
  303.   int day_of_week;                 // 1 = Sunday, ... 7 = Saturday
  304.  
  305. private:
  306.   static int displayFormat;
  307.   static unsigned char displayOptions;
  308.  
  309.   void julian_to_mdy (void);       // convert julian day to mdy
  310.   void julian_to_wday (void);      // convert julian day to day_of_week
  311.   void mdy_to_julian (void);       // convert mdy to julian day
  312.  
  313.   int char_to_month (const char * charMonth);
  314.   // convert month name to month value
  315.  
  316. public:
  317.  
  318.   TDate ();
  319.   TDate (const long aJulDate, const long offset = 0);
  320.   TDate (const int m, const int d, const int y);
  321.   TDate (char * dat);
  322.   TDate (const date & ds);
  323.   TDate (const TDate & dt);
  324.  
  325.   TDate operator + (const long i);
  326.   TDate operator - (const long i);
  327.   long operator - (const TDate & dt);
  328.   TDate & operator += (const long i);
  329.   TDate & operator -= (const long i);
  330.   TDate & operator++(void);        // pre increment function
  331.   TDate & operator++(int);         // post increment function
  332.   TDate & operator--(void);        // pre decrement function
  333.   TDate & operator--(int);         // post decrement function
  334.  
  335.   friend int operator < (const TDate & dt1, const TDate & dt2);
  336.   friend int operator <= (const TDate & dt1, const TDate & dt2);
  337.   friend int operator > (const TDate & dt1, const TDate & dt2);
  338.   friend int operator >= (const TDate & dt1, const TDate & dt2);
  339.   friend int operator == (const TDate & dt1, const TDate & dt2);
  340.   friend int operator != (const TDate & dt1, const TDate & dt2);
  341.  
  342.   friend ostream & operator << (ostream & os, const TDate & dt);
  343.   friend ostream & operator << (ostream & os, const date & dt);
  344.  
  345.   char * formatDate (int type = -1) const;
  346.   static void setFormat (const int format);
  347.   static int setOption (const int option, const int action = ON);
  348.   int setDate (const char * charDate);  // returns 1 if successful, 0 if not
  349.   int setDate (const long aJulDate, const long offset = 0);
  350.   // returns 1 if successful, 0 if not
  351.   void incrMonth (void);
  352.   void decrMonth (void);
  353.   void incrYear (void);
  354.   void decrYear (void);
  355.  
  356.   long julDate (void) const;       // returns julian date
  357.   long PXDate (void) const;        // returns date in PX format
  358.   int day (void) const;
  359.   int dow (void) const;
  360.   int month (void) const;
  361.   int year (void) const;
  362.   int dayOfYear (void) const;      // returns relative date since Jan. 1
  363.   int isLeapYear (void) const;     // returns 1 if leap year, 0 if not
  364.  
  365.   // note that the next functions return a date struct as defined in
  366.   // dos.h (distinct from the TDate class) Order is year, day, month.
  367.   date eom (void) const;           // returns last day of month in object
  368.   date getDate (void) const;       // returns a date structure
  369. };
  370.  
  371. #endif // Uses_TDate
  372.  
  373.  
  374. #if defined( Uses_TDateField ) && !defined( __TDateField )
  375. #define __TDateField
  376.  
  377. class TDateField : public TField
  378. {
  379. public:
  380.   TDateField (const TRect & bounds, int aMaxLen);
  381.  
  382.   virtual void convertData (void);
  383.   virtual ushort dataSize ();
  384.   virtual ushort filterCharCode (ushort charCode);
  385.   virtual void getData (void * rec);
  386.   virtual Boolean isValid (ushort command);
  387.   virtual ushort processKeyCode (ushort keyCode);
  388.   virtual void setData (void * rec);
  389.   virtual void setMax (TDate newMax);
  390.   virtual void setMin (TDate newMin);
  391.  
  392.   void setJulian (long julDate);
  393.   void setParadox (long pxDate);
  394.  
  395.   TDate value,                     // field's current value
  396.   maxValue,
  397.   minValue;
  398.  
  399.   static const char * const near name;
  400. };
  401.  
  402. #endif // Uses_TDateField
  403.  
  404. #if defined( Uses_TDoubleField ) && !defined( __TDoubleField )
  405. #define __TDoubleField
  406.  
  407. class TDoubleField : public TField
  408. {
  409. public:
  410.   TDoubleField (const TRect & bounds, int aMaxLen);
  411.   ~TDoubleField ();
  412.  
  413.   virtual void convertData ();
  414.   virtual ushort dataSize ();
  415.   virtual ushort filterCharCode (ushort charCode);
  416.   virtual void getData (void * rec);
  417.   virtual Boolean isValid (ushort command);
  418.   virtual ushort processKeyCode (ushort keyCode);
  419.   virtual void setData (void * rec);
  420.   virtual void setFormat (char * newFormat);
  421.   virtual void setMax (float newMax);
  422.   virtual void setMin (float newMin);
  423.  
  424.   double value,          // field's current value
  425.   maxValue,
  426.   minValue;
  427.  
  428.   char * formatString;   // field's format string for sprintf function call
  429.  
  430.   static const char * const near name;
  431. };
  432.  
  433. #endif // Uses_TDoubleField
  434.  
  435. #if defined( Uses_TFloatField ) && !defined( __TFloatField )
  436. #define __TFloatField
  437.  
  438. class TFloatField : public TField
  439. {
  440. public:
  441.   TFloatField (const TRect & bounds, int aMaxLen);
  442.   ~TFloatField ();
  443.  
  444.   virtual void convertData ();
  445.   virtual ushort dataSize ();
  446.   virtual ushort filterCharCode (ushort charCode);
  447.   virtual void getData (void * rec);
  448.   virtual Boolean isValid (ushort command);
  449.   virtual ushort processKeyCode (ushort keyCode);
  450.   virtual void setData (void * rec);
  451.   virtual void setFormat (char * newFormat);
  452.   virtual void setMax (float newMax);
  453.   virtual void setMin (float newMin);
  454.  
  455.   float value,                     // field's current value
  456.   maxValue,
  457.   minValue;
  458.  
  459.   char * formatString;   // field's format string for sprintf function call
  460.  
  461.   static const char * const near name;
  462. };
  463.  
  464. #endif // Uses_TFloatField
  465.  
  466. #if defined( Uses_TLongDoubleField ) && !defined( __TLongDoubleField )
  467. #define __TLongDoubleField
  468.  
  469. class TLongDoubleField : public TField
  470. {
  471. public:
  472.   TLongDoubleField (const TRect & bounds, int aMaxLen);
  473.   ~TLongDoubleField ();
  474.  
  475.   virtual void convertData ();
  476.   virtual ushort dataSize ();
  477.   virtual ushort filterCharCode (ushort charCode);
  478.   virtual void getData (void * rec);
  479.   virtual Boolean isValid (ushort command);
  480.   virtual ushort processKeyCode (ushort keyCode);
  481.   virtual void setData (void * rec);
  482.   virtual void setFormat (char * newFormat);
  483.   virtual void setMax (long double newMax);
  484.   virtual void setMin (long double newMin);
  485.  
  486.   long double value,                     // field's current value
  487.   maxValue,
  488.   minValue;
  489.  
  490.   char * formatString;   // field's format string for sprintf function call
  491.  
  492.   static const char * const near name;
  493. };
  494.  
  495. #endif // Uses_TLongDoubleField
  496.  
  497. #if defined( Uses_TIntField ) && !defined( __TIntField )
  498. #define __TIntField
  499.  
  500. class TIntField : public TField
  501. {
  502. public:
  503.   TIntField (const TRect & bounds, int aMaxLen);
  504.  
  505.   virtual void convertData (void);
  506.   virtual ushort dataSize ();
  507.   virtual ushort filterCharCode (ushort charCode);
  508.   virtual void getData (void * rec);
  509.   virtual Boolean isValid (ushort command);
  510.   virtual ushort processKeyCode (ushort keyCode);
  511.   virtual void setData (void * rec);
  512.   virtual void setMax (int newMax);
  513.   virtual void setMin (int newMin);
  514.  
  515.   int value,                       // field's current value
  516.   maxValue,
  517.   minValue;
  518.  
  519.   static const char * const near name;
  520. };
  521.  
  522. #endif // Uses_TIntField
  523.  
  524. #if defined( Uses_TLongField ) && !defined( __TLongField )
  525. #define __TLongField
  526.  
  527. class TLongField : public TField
  528. {
  529. public:
  530.   TLongField (const TRect & bounds, int aMaxLen);
  531.  
  532.   virtual void convertData (void);
  533.   virtual ushort dataSize ();
  534.   virtual ushort filterCharCode (ushort charCode);
  535.   virtual void getData (void * rec);
  536.   virtual Boolean isValid (ushort command);
  537.   virtual ushort processKeyCode (ushort keyCode);
  538.   virtual void setData (void * rec);
  539.   virtual void setMax (long newMax);
  540.   virtual void setMin (long newMin);
  541.  
  542.   long value,                      // field's current value
  543.   maxValue,
  544.   minValue;
  545.  
  546.   static const char * const near name;
  547. };
  548.  
  549. #endif // Uses_TLongField
  550.  
  551. #if defined( Uses_TLowerField ) && !defined( __TLowerField )
  552. #define __TLowerField
  553.  
  554. class TLowerField : public TField
  555. {
  556. public:
  557.   TLowerField (const TRect & bounds, int aMaxLen);
  558.  
  559.   virtual ushort filterCharCode (ushort charCode);
  560.   virtual void setData (void * rec);
  561.  
  562.   static const char * const near name;
  563. };
  564. #endif // Uses_TLowerField
  565.  
  566. #if defined( Uses_TUpperField ) && !defined( __TUpperField )
  567. #define __TUpperField
  568.  
  569. class TUpperField : public TField
  570. {
  571. public:
  572.   TUpperField (const TRect & bounds, int aMaxLen);
  573.  
  574.   virtual ushort filterCharCode (ushort charCode);
  575.   virtual void setData (void * rec);
  576.  
  577.   static const char * const near name;
  578. };
  579. #endif // Uses_TUpperField
  580.  
  581.