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

  1. /*
  2.  * objects.h
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. #if defined( Uses_TPoint ) && !defined( __TPoint )
  13. #define __TPoint
  14.  
  15. class TPoint
  16. {
  17.  
  18. public:
  19.  
  20.     TPoint& operator+=( const TPoint& adder );
  21.     TPoint& operator-=( const TPoint& subber );
  22.     friend TPoint operator - ( const TPoint& one, const TPoint& two);
  23.     friend TPoint operator + ( const TPoint& one, const TPoint& two);
  24.     friend int operator == ( const TPoint& one, const TPoint& two);
  25.     friend int operator != ( const TPoint& one, const TPoint& two);
  26.  
  27.     int x,y;
  28.  
  29. };
  30.  
  31. inline TPoint& TPoint::operator += ( const TPoint& adder )
  32. {
  33.     x += adder.x;
  34.     y += adder.y;
  35.     return *this;
  36. }
  37.  
  38. inline TPoint& TPoint::operator -= ( const TPoint& subber )
  39. {
  40.     x -= subber.x;
  41.     y -= subber.y;
  42.     return *this;
  43. }
  44.  
  45. inline ipstream& operator >> ( ipstream& is, TPoint& p )
  46.     { return is >> p.x >> p.y; }
  47. inline ipstream& operator >> ( ipstream& is, TPoint*& p )
  48.     { return is >> p->x >> p->y; }
  49.  
  50. inline opstream& operator << ( opstream& os, TPoint& p )
  51.     { return os << p.x << p.y; }
  52. inline opstream& operator << ( opstream& os, TPoint* p )
  53.     { return os << p->x << p->y; }
  54.  
  55. #endif  // Uses_TPoint
  56.  
  57. #if defined( Uses_TRect ) && !defined( __TRect )
  58. #define __TRect
  59.  
  60. class TRect
  61. {
  62.  
  63. public:
  64.  
  65.     TRect( int ax, int ay, int bx, int by );
  66.     TRect( TPoint p1, TPoint p2 );
  67.     TRect();
  68.  
  69.     void move( int aDX, int aDY );
  70.     void grow( int aDX, int aDY );
  71.     void intersect( const TRect& r );
  72.     void Union( const TRect& r );
  73.     Boolean contains( const TPoint& p ) const;
  74.     Boolean operator == ( const TRect& r ) const;
  75.     Boolean operator != ( const TRect& r ) const;
  76.     Boolean isEmpty();
  77.  
  78.     TPoint a, b;
  79.  
  80. };
  81.  
  82. inline TRect::TRect( int ax, int ay, int bx, int by)
  83. {
  84.     a.x = ax;
  85.     a.y = ay;
  86.     b.x = bx;
  87.     b.y = by;
  88. }
  89.  
  90. inline TRect::TRect( TPoint p1, TPoint p2 )
  91. {
  92.     a = p1;
  93.     b = p2;
  94. }
  95.  
  96. inline TRect::TRect()
  97. {
  98. }
  99.  
  100. inline void TRect::move( int aDX, int aDY )
  101. {
  102.     a.x += aDX;
  103.     a.y += aDY;
  104.     b.x += aDX;
  105.     b.y += aDY;
  106. }
  107.  
  108. inline void TRect::grow( int aDX, int aDY )
  109. {
  110.     a.x -= aDX;
  111.     a.y -= aDY;
  112.     b.x += aDX;
  113.     b.y += aDY;
  114. }
  115.  
  116. inline void TRect::intersect( const TRect& r )
  117. {
  118.     a.x = max( a.x, r.a.x );
  119.     a.y = max( a.y, r.a.y );
  120.     b.x = min( b.x, r.b.x );
  121.     b.y = min( b.y, r.b.y );
  122. }
  123.  
  124. inline void TRect::Union( const TRect& r )
  125. {
  126.     a.x = min( a.x, r.a.x );
  127.     a.y = min( a.y, r.a.y );
  128.     b.x = max( b.x, r.b.x );
  129.     b.y = max( b.y, r.b.y );
  130. }
  131.  
  132. inline Boolean TRect::contains( const TPoint& p ) const
  133. {
  134.     return Boolean(
  135.         p.x >= a.x && p.x < b.x && p.y >= a.y && p.y < b.y
  136.         );
  137. }
  138.  
  139. inline Boolean TRect::operator == ( const TRect& r) const
  140. {
  141.     return Boolean( a == r.a && b == r.b );
  142. }
  143.  
  144. inline Boolean TRect::operator != ( const TRect& r ) const
  145. {
  146.     return Boolean( !(*this == r) );
  147. }
  148.  
  149. inline Boolean TRect::isEmpty()
  150. {
  151.     return Boolean( a.x >= b.x || a.y >= b.y );
  152. }
  153.  
  154. inline ipstream& operator >> ( ipstream& is, TRect& r )
  155.     { return is >> r.a >> r.b; }
  156. inline ipstream& operator >> ( ipstream& is, TRect*& r )
  157.     { return is >> r->a >> r->b; }
  158.  
  159. inline opstream& operator << ( opstream& os, TRect& r )
  160.     { return os << r.a << r.b; }
  161. inline opstream& operator << ( opstream& os, TRect* r )
  162.     { return os << r->a << r->b; }
  163.  
  164. #endif  // Uses_TRect
  165.  
  166. #if defined( Uses_TCollection ) && !defined( __TCollection )
  167. #define __TCollection
  168.  
  169. class TCollection : public virtual TNSCollection, public TStreamable
  170. {
  171.  
  172. public:
  173.  
  174.     TCollection( ccIndex aLimit, ccIndex aDelta )
  175.         { delta = aDelta; setLimit( aLimit ); }
  176.  
  177. private:
  178.  
  179.     virtual const char *streamableName() const
  180.         { return name; }
  181.  
  182.     virtual void *readItem( ipstream& ) = 0;
  183.     virtual void writeItem( void *, opstream& ) = 0;
  184.  
  185.  
  186. protected:
  187.  
  188.     TCollection( StreamableInit );
  189.     virtual void *read( ipstream& );
  190.     virtual void write( opstream& );
  191.  
  192. public:
  193.  
  194.     static const char * const name;
  195.  
  196. };
  197.  
  198. inline ipstream& operator >> ( ipstream& is, TCollection& cl )
  199.     { return is >> (TStreamable&)cl; }
  200. inline ipstream& operator >> ( ipstream& is, TCollection*& cl )
  201.     { return is >> (void *&)cl; }
  202.  
  203. inline opstream& operator << ( opstream& os, TCollection& cl )
  204.     { return os << (TStreamable&)cl; }
  205. inline opstream& operator << ( opstream& os, TCollection* cl )
  206.     { return os << (TStreamable *)cl; }
  207.  
  208. #endif  // Uses_TCollection
  209.  
  210. #if defined( Uses_TSortedCollection ) && !defined( __TSortedCollection )
  211. #define __TSortedCollection
  212.  
  213. class TSortedCollection : public TNSSortedCollection, public TCollection
  214. {
  215.  
  216. public:
  217.  
  218.     TSortedCollection( ccIndex aLimit, ccIndex aDelta) :
  219.         TCollection( aLimit, aDelta ) {}
  220.  
  221. private:
  222.  
  223.     virtual int compare( void *key1, void *key2 ) = 0;
  224.  
  225.     virtual const char *streamableName() const
  226.         { return name; }
  227.     virtual void *readItem( ipstream& ) = 0;
  228.     virtual void writeItem( void *, opstream& ) = 0;
  229.  
  230. protected:
  231.  
  232.     TSortedCollection( StreamableInit );
  233.     virtual void *read( ipstream& );
  234.     virtual void write( opstream& );
  235.  
  236. public:
  237.  
  238.     static const char * const name;
  239.  
  240. };
  241.  
  242. inline ipstream& operator >> ( ipstream& is, TSortedCollection& cl )
  243.     { return is >> (TStreamable&)cl; }
  244. inline ipstream& operator >> ( ipstream& is, TSortedCollection*& cl )
  245.     { return is >> (void *&)cl; }
  246.  
  247. inline opstream& operator << ( opstream& os, TSortedCollection& cl )
  248.     { return os << (TStreamable&)cl; }
  249. inline opstream& operator << ( opstream& os, TSortedCollection* cl )
  250.     { return os << (TStreamable *)cl; }
  251.  
  252. #endif  // Uses_TSortedCollection
  253.