home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FACETV.ZIP / TINPUT.H < prev    next >
C/C++ Source or Header  |  1993-12-09  |  15KB  |  619 lines

  1. /************************************************************************
  2. **
  3. ** @(#)tinput.h        06/08/93    Chris Ahlstrom
  4. **
  5. ** C++
  6. **
  7. **    Contains, at present, an interface to the menu fields.
  8. ** Added support for byte-sized radio-buttons and check-boxes.
  9. **
  10. *************************************************************************/
  11.  
  12. #if !defined(TINPUT_h)                    // { TINPUT_h
  13. #define TINPUT_h
  14.  
  15. #if !defined(Uses_TInputLine)            // { Uses_TInputLine
  16. #define Uses_MsgBox
  17. #define Uses_TCheckBoxes
  18. #define Uses_TCluster
  19. #define Uses_TEvent
  20. #define Uses_TInputLine
  21. #define Uses_TKeys
  22. #define Uses_TRadioButtons
  23. #define Uses_TRect
  24. #define Uses_TStreamable
  25. #define Uses_TStreamableClass
  26. #include <tv.h>                    // Turbo Vision declarations
  27. #endif                        // } Uses_TInputLine
  28.  
  29. #if !defined(__STDIO_H)
  30. #include <stdio.h>                // sprintf() only
  31. #endif
  32.  
  33. #if !defined(__STDLIB_H)
  34. #include <stdlib.h>                // data conversion functions
  35. #endif
  36.  
  37. #if !defined(__STRING_H)
  38. #include <string.h>                // string manipulations
  39. #endif
  40.  
  41. #if !defined(__STRSTREAM_H)
  42. #include <strstream.h>                // stream functions
  43. #endif
  44.  
  45. #include "tinpextd.h"                // TExtended class declaration
  46. #include "tv_menu.h"                // for Range declaration
  47.  
  48.  
  49. /***********************************************************************
  50. ** Inheritance from TInputLine
  51. **
  52. **    TInputLine is a Turbo Vision class provided by Borland.
  53. ** We use it unaltered here for conventional NULL-terminated ASCII
  54. ** strings.
  55. **
  56. **    We don't need to define a new class for strings (lines), but
  57. ** we do need to specify our maximum buffer size.
  58. **
  59. ************************************************************************/
  60.  
  61. #define linBufSize    128    // maximum number of characters allowed
  62. #define linDatSize     20    // default databox size
  63.  
  64.  
  65. /***********************************************************************
  66. ** TByteString
  67. **
  68. **    This class is a minor extension of TInputLine designed to
  69. ** handle strings of bytes that have no NULL terminator.
  70. **
  71. ************************************************************************/
  72.  
  73. class TByteString : public TInputLine
  74. {
  75.  
  76. public:
  77.  
  78.     TByteString
  79.     (
  80.     const TRect& bounds,
  81.     int aMaxLen
  82.     );
  83.  
  84.     virtual ushort dataSize();
  85.     virtual void getData( void *rec );
  86.     virtual void setData( void *rec );
  87.  
  88. protected:
  89.  
  90.     TByteString( StreamableInit ) : TInputLine( streamableInit ) {};
  91.  
  92. private:
  93.  
  94.     virtual const char *streamableName() const
  95.     {
  96.     return name;
  97.     }
  98.  
  99. public:
  100.  
  101.     static const char * const name;
  102.     static TStreamable *build();
  103.  
  104. };
  105. #define bstrBufSize    128    // maximum number of characters allowed
  106. #define bstrDatSize     20    // default databox size
  107.  
  108. inline ipstream& operator >> ( ipstream& is, TByteString& cl )
  109. {
  110.     return is >> (TStreamable&)cl;
  111. }
  112.  
  113. inline ipstream& operator >> ( ipstream& is, TByteString*& cl )
  114. {
  115.     return is >> (void *&)cl;
  116. }
  117.  
  118. inline opstream& operator << ( opstream& os, TByteString& cl )
  119. {
  120.     return os << (TStreamable&)cl;
  121. }
  122.  
  123. inline opstream& operator << ( opstream& os, TByteString* cl )
  124. {
  125.     return os << (TStreamable *)cl;
  126. }
  127.  
  128.  
  129. /***********************************************************************
  130. ** TInputByte
  131. ************************************************************************/
  132.  
  133. class TInputByte : public TExtended
  134. {
  135.  
  136. public:
  137.  
  138.     TInputByte
  139.     (
  140.     const TRect& bounds,
  141.     int aMaxLen,
  142.     const Range& code,
  143.     char *formatstring,
  144.     int mapped,
  145.     const Range& user
  146.     );
  147.     // ~TInputByte();
  148.  
  149.     virtual ushort dataSize();
  150.     virtual void getData( void *rec );
  151.     virtual void setData( void *rec );
  152.     virtual Boolean valid( ushort command );
  153.     virtual double getValue();        // get current value (byte, long...)
  154.     virtual void putValue(double);    // put current value back
  155.     virtual void updateValue();        // redisplay current value
  156.  
  157.     unsigned char Value;        // current value of the Byte
  158.     char *format;            // pointer to desired Byte format
  159.  
  160. protected:
  161.  
  162.     TInputByte(StreamableInit) : TExtended(streamableInit) {};
  163.     virtual void write( opstream& );
  164.     virtual void *read( ipstream& );
  165.  
  166. private:
  167.  
  168.     virtual const char *streamableName() const
  169.     {
  170.     return name;
  171.     }
  172.  
  173. public:
  174.  
  175.     static const char * const name;
  176.     static TStreamable *build();
  177.  
  178. };
  179. #define byteBufSize    8        // maximum number of characters allowed
  180. #define byteDatSize    6        // default databox size
  181.  
  182. inline ipstream& operator >> ( ipstream& is, TInputByte& cl )
  183. {
  184.     return is >> (TStreamable&)cl;
  185. }
  186.  
  187. inline ipstream& operator >> ( ipstream& is, TInputByte*& cl )
  188. {
  189.     return is >> (void *&)cl;
  190. }
  191.  
  192. inline opstream& operator << ( opstream& os, TInputByte& cl )
  193. {
  194.     return os << (TStreamable&)cl;
  195. }
  196.  
  197. inline opstream& operator << ( opstream& os, TInputByte* cl )
  198. {
  199.     return os << (TStreamable *)cl;
  200. }
  201.  
  202.  
  203. /***********************************************************************
  204. ** TInputSignedByte
  205. ************************************************************************/
  206.  
  207. class TInputSignedByte : public TInputByte
  208. {
  209.  
  210. public:
  211.  
  212.     TInputSignedByte
  213.     (
  214.     const TRect& bounds,
  215.     int aMaxLen,
  216.     const Range& code,
  217.     char *formatstring,
  218.     int mapped,
  219.     const Range& user
  220.     );
  221.     // ~TInputSignedByte();
  222.  
  223.     virtual void getData( void *rec );
  224.     virtual void setData( void *rec );
  225.     virtual double getValue();        // get current value (byte, long...)
  226.     virtual void putValue(double);    // put current value back
  227.     virtual void updateValue();        // redisplay current value
  228.  
  229.     signed char Value;            // current value of the Byte
  230.     char *format;            // pointer to desired Byte format
  231.  
  232. protected:
  233.  
  234.     TInputSignedByte(StreamableInit) : TInputByte(streamableInit) {};
  235.  
  236. private:
  237.  
  238.     virtual const char *streamableName() const
  239.     {
  240.     return name;
  241.     }
  242.  
  243. public:
  244.  
  245.     static const char * const name;
  246.     static TStreamable *build();
  247.  
  248. };
  249.  
  250. inline ipstream& operator >> ( ipstream& is, TInputSignedByte& cl )
  251. {
  252.     return is >> (TStreamable&)cl;
  253. }
  254.  
  255. inline ipstream& operator >> ( ipstream& is, TInputSignedByte*& cl )
  256. {
  257.     return is >> (void *&)cl;
  258. }
  259.  
  260. inline opstream& operator << ( opstream& os, TInputSignedByte& cl )
  261. {
  262.     return os << (TStreamable&)cl;
  263. }
  264.  
  265. inline opstream& operator << ( opstream& os, TInputSignedByte* cl )
  266. {
  267.     return os << (TStreamable *)cl;
  268. }
  269.  
  270.  
  271. /***********************************************************************
  272. ** TInputInteger
  273. ************************************************************************/
  274.  
  275. class TInputInteger : public TExtended
  276. {
  277.  
  278. public:
  279.  
  280.     TInputInteger
  281.     (
  282.     const TRect& bounds,
  283.     int aMaxLen,
  284.     const Range& code,
  285.     char *formatstring,
  286.     int mapped,
  287.     const Range& user
  288.     );
  289.     // ~TInputInteger();
  290.  
  291.     virtual ushort dataSize();
  292.     virtual void getData( void *rec );
  293.     virtual void setData( void *rec );
  294.     virtual Boolean valid( ushort command );
  295.     virtual double getValue();        // get current value (byte, long...)
  296.     virtual void putValue(double);    // put current value back
  297.     virtual void updateValue();        // redisplay current value
  298.  
  299.     int Value;                // current value of the integer
  300.     char *format;            // pointer to desired integer format
  301.  
  302. protected:
  303.  
  304.     TInputInteger( StreamableInit ) : TExtended( streamableInit ) {};
  305.     virtual void write( opstream& );
  306.     virtual void *read( ipstream& );
  307.  
  308. private:
  309.  
  310.     virtual const char *streamableName() const
  311.     {
  312.     return name;
  313.     }
  314.  
  315. public:
  316.  
  317.     static const char * const name;
  318.     static TStreamable *build();
  319.  
  320. };
  321. #define intBufSize    18        // maximum number of characters allowed
  322. #define intDatSize     6        // default databox size
  323.  
  324. inline ipstream& operator >> ( ipstream& is, TInputInteger& cl )
  325. {
  326.     return is >> (TStreamable&)cl;
  327. }
  328.  
  329. inline ipstream& operator >> ( ipstream& is, TInputInteger*& cl )
  330. {
  331.     return is >> (void *&)cl;
  332. }
  333.  
  334. inline opstream& operator << ( opstream& os, TInputInteger& cl )
  335. {
  336.     return os << (TStreamable&)cl;
  337. }
  338.  
  339. inline opstream& operator << ( opstream& os, TInputInteger* cl )
  340. {
  341.     return os << (TStreamable *)cl;
  342. }
  343.  
  344.  
  345. /***********************************************************************
  346. ** TInputFloat
  347. ************************************************************************/
  348.  
  349. class TInputFloat : public TExtended
  350. {
  351.  
  352. public:
  353.  
  354.     TInputFloat
  355.     (
  356.     const TRect& bounds,
  357.     int aMaxLen,
  358.     const Range& code,
  359.     char *formatstring,
  360.     int mapped,
  361.     const Range& user
  362.     );
  363.     // ~TInputFloat();
  364.  
  365.     virtual ushort dataSize();
  366.     virtual void getData( void *rec );
  367.     virtual void setData( void *rec );
  368.     virtual Boolean valid( ushort command );
  369.     virtual double getValue();        // get current value (byte, long...)
  370.     virtual void putValue(double);    // put current value back
  371.     virtual void updateValue();        // redisplay current value
  372.  
  373.     double Value;            // current value of the float
  374.     char *format;            // pointer to floating-point format
  375.  
  376. protected:
  377.  
  378.     TInputFloat( StreamableInit ) : TExtended( streamableInit ) {};
  379.     virtual void write( opstream& );
  380.     virtual void *read( ipstream& );
  381.  
  382. private:
  383.  
  384.     virtual const char *streamableName() const
  385.     {
  386.     return name;
  387.     }
  388.  
  389. public:
  390.  
  391.     static const char * const name;
  392.     static TStreamable *build();
  393.  
  394. };
  395. #define floatBufSize    24        // maximum number of characters allowed
  396. #define floatDatSize     8        // default databox size
  397.  
  398. #ifdef DOUBLE_CRAP
  399. inline ipstream& operator >> ( ipstream& is, TInputFloat& cl )
  400. {
  401.     return is >> (TStreamable&)cl;
  402. }
  403.  
  404. inline ipstream& operator >> ( ipstream& is, TInputFloat*& cl )
  405. {
  406.     return is >> (void *&)cl;
  407. }
  408.  
  409. inline opstream& operator << ( opstream& os, TInputFloat& cl )
  410. {
  411.     return os << (TStreamable&)cl;
  412. }
  413.  
  414. inline opstream& operator << ( opstream& os, TInputFloat* cl )
  415. {
  416.     return os << (TStreamable *)cl;
  417. }
  418. #endif
  419.  
  420.  
  421. /***********************************************************************
  422. ** TInputLong
  423. ************************************************************************/
  424.  
  425. class TInputLong : public TExtended
  426. {
  427.  
  428. public:
  429.  
  430.     TInputLong
  431.     (
  432.     const TRect& bounds,
  433.     int aMaxLen,
  434.     const Range& code,
  435.     char *formatstring,
  436.     int mapped,
  437.     const Range& user
  438.     );
  439.     virtual ushort dataSize();
  440.     virtual void getData( void *);
  441.     virtual void setData( void *);
  442.     virtual Boolean valid( ushort );
  443.     virtual double getValue();        // get current value (byte, long...)
  444.     virtual void putValue(double);    // put current value back
  445.     virtual void updateValue();        // redisplay current value
  446.  
  447.     long Value;                // current value of the integer
  448.     char *format;            // pointer to desired integer format
  449.  
  450. protected:
  451.  
  452.     TInputLong( StreamableInit ) : TExtended( streamableInit ) {};
  453.     virtual void write( opstream& );
  454.     virtual void *read( ipstream& );
  455.  
  456. private:
  457.  
  458.     virtual const char *streamableName() const
  459.     {
  460.     return name;
  461.     }
  462.  
  463. public:
  464.  
  465.     static const char * const name;
  466.     static TStreamable *build();
  467.  
  468. };
  469. #define longBufSize    24        // maximum number of characters allowed
  470. #define longDatSize    10        // default databox size
  471.  
  472. inline ipstream& operator >> ( ipstream& is, TInputLong& cl )
  473. {
  474.     return is >> (TStreamable&)cl;
  475. }
  476.  
  477. inline ipstream& operator >> ( ipstream& is, TInputLong*& cl )
  478. {
  479.     return is >> (void *&)cl;
  480. }
  481.  
  482. inline opstream& operator << ( opstream& os, TInputLong& cl )
  483. {
  484.     return os << (TStreamable&)cl;
  485. }
  486.  
  487. inline opstream& operator << ( opstream& os, TInputLong* cl )
  488. {
  489.     return os << (TStreamable *)cl;
  490. }
  491.  
  492.  
  493. /***********************************************************************
  494. ** TByteRadioButtons
  495. ************************************************************************/
  496.  
  497. class TByteRadioButtons : public TRadioButtons
  498. {
  499.  
  500. public:
  501.  
  502.     TByteRadioButtons(const TRect& bounds, TSItem *aStrings);
  503.  
  504.     virtual ushort dataSize();
  505.     virtual void getData(void *rec);
  506.     virtual void setData(void *rec);
  507.     virtual Boolean mark( int item );
  508.     virtual void movedTo( int item );
  509.     virtual void press( int item );
  510.  
  511.     static const char * const name;
  512.     static TStreamable *build();
  513.     // virtual TStreamable *build();
  514.  
  515. protected:
  516.  
  517.     unsigned char bytevalue;
  518. //    virtual void write( opstream& );
  519. //    virtual void *read( ipstream& );
  520.     TByteRadioButtons(StreamableInit) : TRadioButtons(streamableInit)
  521.     { };
  522.  
  523. };
  524.  
  525. inline ipstream& operator >> ( ipstream& is, TByteRadioButtons& cl )
  526. {
  527.     return is >> (TStreamable&)cl;
  528. }
  529.  
  530. inline ipstream& operator >> ( ipstream& is, TByteRadioButtons*& cl )
  531. {
  532.     return is >> (void *&)cl;
  533. }
  534.  
  535. inline opstream& operator << ( opstream& os, TByteRadioButtons& cl )
  536. {
  537.     return os << (TStreamable&)cl;
  538. }
  539.  
  540. inline opstream& operator << ( opstream& os, TByteRadioButtons* cl )
  541. {
  542.     return os << (TStreamable *)cl;
  543. }
  544.  
  545. inline TByteRadioButtons::TByteRadioButtons
  546. (
  547.     const TRect& bounds,
  548.     TSItem *aStrings
  549. )
  550.     : TRadioButtons(bounds, aStrings)
  551. {
  552. }
  553.  
  554.  
  555. /***********************************************************************
  556. ** TByteCheckBoxes
  557. ************************************************************************/
  558.  
  559. class TByteCheckBoxes : public TCheckBoxes
  560. {
  561.  
  562. public:
  563.  
  564.     TByteCheckBoxes(const TRect& bounds, TSItem *aStrings);
  565.  
  566.     virtual ushort dataSize();
  567.     virtual void getData(void *rec);
  568.     virtual void setData(void *rec);
  569.     virtual Boolean mark( int item );
  570.     virtual void press( int item );
  571.  
  572.     static const char * const name;
  573.     static TStreamable *build();
  574.     // virtual TStreamable *build();
  575.  
  576. protected:
  577.  
  578.     unsigned char bytevalue;
  579. //    virtual void write( opstream& );
  580. //    virtual void *read( ipstream& );
  581.     TByteCheckBoxes(StreamableInit) : TCheckBoxes(streamableInit)
  582.     { };
  583.  
  584. };
  585.  
  586. inline ipstream& operator >> ( ipstream& is, TByteCheckBoxes& cl )
  587. {
  588.     return is >> (TStreamable&)cl;
  589. }
  590.  
  591. inline ipstream& operator >> ( ipstream& is, TByteCheckBoxes*& cl )
  592. {
  593.     return is >> (void *&)cl;
  594. }
  595.  
  596. inline opstream& operator << ( opstream& os, TByteCheckBoxes& cl )
  597. {
  598.     return os << (TStreamable&)cl;
  599. }
  600.  
  601. inline opstream& operator << ( opstream& os, TByteCheckBoxes* cl )
  602. {
  603.     return os << (TStreamable *)cl;
  604. }
  605.  
  606. inline TByteCheckBoxes::TByteCheckBoxes
  607. (
  608.     const TRect& bounds,
  609.     TSItem *aStrings
  610. )
  611.     : TCheckBoxes(bounds, aStrings)
  612. {
  613. }
  614.  
  615.  
  616.  
  617. #endif                            // } TINPUT_h
  618.  
  619.