home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / AltPoint.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  43KB  |  1,538 lines

  1. /* @(#)Z 1.27 com/src/pubutils/src/AltPoint.cpp, odpubutils, od96os2, odos29712d 97/03/21 17:21:13 (96/10/30 09:23:46) */
  2.  //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odpubutils
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27,94
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. /*
  30.     File:        AltPoint.cpp
  31.  
  32.     Contains:    Alternate ODPoint, ODRect (C++ savvy)
  33.  
  34.     Owned by:    Jens Alfke
  35.  
  36.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  37.  
  38. */
  39.  
  40. #define _OD_DONT_IMPORT_CPP_
  41.  
  42. #ifndef _ALTPOINT_
  43. #include "AltPoint.h"
  44. #endif
  45.  
  46. #ifndef SOM_Module_OpenDoc_Global_Types_defined
  47. #include "ODTypesM.xh"
  48. #endif
  49.  
  50. #ifndef _ODEXCEPT_
  51. #include "ODExcept.h"
  52. #endif
  53.  
  54. #ifndef _ODDEBUG_
  55. #include "ODDebug.h"
  56. #endif
  57.  
  58. #ifndef _LINEOPS_
  59. #include "LineOps.h"        /* For kFixedEpsilon */
  60. #endif
  61.  
  62. #include <string.h>
  63.  
  64.  
  65. #ifdef _PLATFORM_MACINTOSH_
  66.     #ifndef __GXMATH__
  67.     #include <GXMath.h>
  68.     #endif
  69. #endif
  70.  
  71. #ifndef _ODDEBUG_
  72. #include "ODDebug.h"
  73. #endif
  74.  
  75. #if ((defined (_PLATFORM_WIN32_) || defined (_PLATFORM_OS2_)) \
  76.       || defined (_PLATFORM_AIX_) ) && defined(DEBUG)
  77. #include <stdio.h>
  78.  
  79. // define vars
  80.  
  81. char tBuf[1024];
  82. static HWND testWindow = kODNULL;
  83.  
  84. // define macros
  85.  
  86. #ifdef _PLATFORM_WIN32_
  87. #define CHECKRES(x) \
  88.   if( ( x ) ) { \
  89.     if (testWindow) { \
  90.       sprintf(tBuf, "PASS\n"); \
  91.       SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tBuf); \
  92.     } \
  93.     else { \
  94.       printf("PASS\n"); \
  95.     } \
  96.   } \
  97.   else { \
  98.     if (testWindow) { \
  99.       sprintf(tBuf, "FAIL\n"); \
  100.       SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tBuf); \
  101.     } \
  102.     else { \
  103.       printf("FAIL\n"); \
  104.     } \
  105.   }
  106. #elif defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  107. #define CHECKRES(x) \
  108.   if( ( x ) ) \
  109.       printf("PASS\n"); \
  110.   else \
  111.       printf("FAIL\n");
  112. #endif
  113.  
  114. #define myLine "-----------------------------------------------------\n"
  115. #endif // defined (_PLATFORM_WIN32_ || OS2 || AIX ) && defined(DEBUG)
  116.  
  117. #ifdef _PLATFORM_MACINTOSH_
  118. #pragma segment ODShape
  119. #endif  // _PLATFORM_MACINTOSH_
  120.  
  121. //==============================================================================
  122. // ODPoint
  123. //==============================================================================
  124.  
  125.  
  126. #ifdef _PLATFORM_MACINTOSH_
  127. ODPoint::ODPoint( Point qdpt )
  128. {
  129.     x = IntToFixed(qdpt.h);
  130.     y = IntToFixed(qdpt.v);
  131. }
  132. #endif
  133.  
  134. #ifdef _PLATFORM_WIN32_
  135. WIN32_DLLEXPORT ODPoint::ODPoint( Point pt )
  136. {
  137.     x = IntToFixed(pt.x);
  138.     y = IntToFixed(pt.y);
  139. }
  140. #endif
  141.  
  142. #ifdef _PLATFORM_OS2_
  143. ODPoint::ODPoint( POINTL ptl)
  144. {
  145.   x = IntToFixed(ptl.x);
  146.   y = IntToFixed(ptl.y);
  147. }
  148. #endif // _PLATFORM_OS2_
  149.  
  150. #ifdef _PLATFORM_AIX_
  151. ODPoint::ODPoint( Point pt )
  152. {
  153.     x = IntToFixed(pt.x);
  154.     y = IntToFixed(pt.y);
  155. }
  156. #endif
  157.  
  158. WIN32_DLLEXPORT ODPoint::ODPoint( const ODPoint &pt )
  159. {
  160.     x = pt.x;
  161.     y = pt.y;
  162. }
  163.  
  164.  
  165. WIN32_DLLEXPORT ODPoint& ODPoint::operator= ( const ODPoint &pt )
  166. {
  167.     x = pt.x;
  168.     y = pt.y;
  169.     return *this;
  170. }
  171.  
  172.  
  173. #ifdef _PLATFORM_MACINTOSH_
  174. ODPoint& ODPoint::operator= ( const Point &pt )
  175. {
  176.     x = IntToFixed(pt.h);
  177.     y = IntToFixed(pt.v);
  178.     return *this;
  179. }
  180. #endif
  181.  
  182. #ifdef _PLATFORM_WIN32_
  183. WIN32_DLLEXPORT ODPoint& ODPoint::operator= ( const Point &pt )
  184. {
  185.     x = IntToFixed(pt.x);
  186.     y = IntToFixed(pt.y);
  187.     return *this;
  188. }
  189. #endif
  190.  
  191. #ifdef _PLATFORM_OS2_
  192. ODPoint& ODPoint::operator= ( const POINTL &ptl)
  193. {
  194.     x = IntToFixed(ptl.x);
  195.     y = IntToFixed(ptl.y);
  196.     return *this;
  197. }
  198. #endif
  199.  
  200. #ifdef _PLATFORM_AIX_
  201. ODPoint& ODPoint::operator= ( const Point &pt )
  202. {
  203.     x = IntToFixed(pt.x);
  204.     y = IntToFixed(pt.y);
  205.     return *this;
  206. }
  207. #endif
  208.  
  209. WIN32_DLLEXPORT void ODPoint::Offset ( ODCoordinate xx, ODCoordinate yy )
  210. {
  211.     x += xx;
  212.     y += yy;
  213. }
  214.  
  215.  
  216. WIN32_DLLEXPORT void ODPoint::operator+= ( const ODPoint &pt )
  217. {
  218.     x += pt.x;
  219.     y += pt.y;
  220. }
  221.  
  222.  
  223. WIN32_DLLEXPORT void ODPoint::operator-= ( const ODPoint &pt )
  224. {
  225.     x -= pt.x;
  226.     y -= pt.y;
  227. }
  228.  
  229.  
  230. #ifdef _PLATFORM_MACINTOSH_
  231. void ODPoint::operator+= ( const Point &pt )
  232. {
  233.     x += IntToFixed(pt.h);
  234.     y += IntToFixed(pt.v);
  235. }
  236.  
  237.  
  238. void ODPoint::operator-= ( const Point &pt )
  239. {
  240.     x -= IntToFixed(pt.h);
  241.     y -= IntToFixed(pt.v);
  242. }
  243.  
  244. Point
  245. ODPoint::AsQDPoint( ) const
  246. {
  247.     Point pt;
  248.     pt.h = FixedToInt(x);
  249.     pt.v = FixedToInt(y);
  250.     return pt;
  251. }
  252. #endif
  253.  
  254. #ifdef _PLATFORM_WIN32_
  255. WIN32_DLLEXPORT void ODPoint::operator+= ( const Point &pt )
  256. {
  257.     x += IntToFixed(pt.x);
  258.     y += IntToFixed(pt.y);
  259. }
  260.  
  261.  
  262. WIN32_DLLEXPORT void ODPoint::operator-= ( const Point &pt )
  263. {
  264.     x -= IntToFixed(pt.x);
  265.     y -= IntToFixed(pt.y);
  266. }
  267.  
  268. WIN32_DLLEXPORT Point
  269. ODPoint::AsWinPoint( ) const
  270. {
  271.     Point pt;
  272.     pt.x = FixedToInt(x);
  273.     pt.y = FixedToInt(y);
  274.     return pt;
  275. }
  276. #endif
  277.  
  278. #ifdef _PLATFORM_OS2_
  279. void ODPoint::operator+= ( const POINTL &ptl )
  280. {
  281.     x += IntToFixed(ptl.x);
  282.     y += IntToFixed(ptl.y);
  283. }
  284.  
  285.  
  286. void ODPoint::operator-= ( const POINTL &ptl )
  287. {
  288.     x -= IntToFixed(ptl.x);
  289.     y -= IntToFixed(ptl.y);
  290. }
  291.  
  292. POINTL
  293. ODPoint::AsPOINTL( ) const
  294. {
  295.     POINTL ptl;
  296.     ptl.x = FixedToInt(x);
  297.     ptl.y = FixedToInt(y);
  298.     return ptl;
  299. }
  300. #endif // _PLATFORM_OS2_
  301.  
  302. #ifdef _PLATFORM_AIX_
  303. void ODPoint::operator+= ( const Point &pt )
  304. {
  305.     x += IntToFixed(pt.x);
  306.     y += IntToFixed(pt.y);
  307. }
  308.  
  309.  
  310. void ODPoint::operator-= ( const Point &pt )
  311. {
  312.     x -= IntToFixed(pt.x);
  313.     y -= IntToFixed(pt.y);
  314. }
  315.  
  316. Point
  317. ODPoint::AsXPoint( ) const
  318. {
  319.     Point pt;
  320.     pt.x = FixedToInt(x);
  321.     pt.y = FixedToInt(y);
  322.     return pt;
  323. }
  324. #endif
  325.   
  326. WIN32_DLLEXPORT ODSShort
  327. ODPoint::IntX( ) const
  328. {
  329.     return FixedToInt(x);
  330. }
  331.  
  332.  
  333. WIN32_DLLEXPORT ODSShort
  334. ODPoint::IntY( ) const
  335. {
  336.     return FixedToInt(y);
  337. }
  338.  
  339.  
  340. WIN32_DLLEXPORT ODBoolean
  341. ODPoint::operator==( const ODPoint &pt ) const
  342. {
  343.     return x==pt.x && y==pt.y;
  344. }
  345.  
  346.  
  347. WIN32_DLLEXPORT ODBoolean
  348. ODPoint::operator!=( const ODPoint &pt ) const
  349. {
  350.     return x!=pt.x || y!=pt.y;
  351. }
  352.  
  353.  
  354. WIN32_DLLEXPORT ODBoolean
  355. ODPoint::ApproxEquals( const ODPoint& pt ) const
  356. {
  357.     ODFixed delta;
  358.     delta = x-pt.x;
  359.     if( delta>kFixedEpsilon || delta<-kFixedEpsilon )
  360.         return kODFalse;
  361.     delta = y-pt.y;
  362.     if( delta>kFixedEpsilon || delta<-kFixedEpsilon )
  363.         return kODFalse;
  364.     return kODTrue;
  365. }
  366.  
  367.  
  368. //==============================================================================
  369. // ODRect
  370. //==============================================================================
  371.  
  372.  
  373. #ifdef _PLATFORM_MACINTOSH_
  374. #pragma segment ODShape
  375. #endif  // _PLATFORM_MACINTOSH_
  376.  
  377.  
  378. #ifdef _PLATFORM_OS2_
  379. #define ASSERTVALID()        WASSERT(right>=left && top>=bottom)
  380. #else
  381. #define ASSERTVALID()        WASSERT(right>=left && bottom>=top)
  382. #endif // _PLATFORM_OS2_ 
  383.  
  384.  
  385. //------------------------------------------------------------------------------
  386. // ::ODRect( corner1, corner2 )
  387. //
  388. // Construct a rectangle given two opposite corners (not necessarily topLeft,botRight)
  389. //------------------------------------------------------------------------------
  390.  
  391. WIN32_DLLEXPORT ODRect::ODRect( const ODPoint &a, const ODPoint &b )
  392. {
  393.     this->Set(a,b);
  394. }
  395.  
  396.  
  397. //------------------------------------------------------------------------------
  398. // ::ODRect( topLeft, width, height )
  399. //
  400. // Construct a rectangle given its origin, width and height.
  401. //------------------------------------------------------------------------------
  402.  
  403. #ifdef _PLATFORM_OS2_
  404. ODRect::ODRect( const ODPoint &bottomLeft, ODCoordinate width, ODCoordinate height )
  405. {
  406.     WASSERT(width>=0);
  407.     WASSERT(height>=0);
  408.     
  409.     left = bottomLeft.x;
  410.     right = bottomLeft.x + width;
  411.     top  = bottomLeft.y;
  412.         bottom= bottomLeft.y + height;
  413. }
  414.  
  415. #else
  416. WIN32_DLLEXPORT ODRect::ODRect( const ODPoint &topLeft, ODCoordinate width, ODCoordinate height )
  417. {
  418.     WASSERT(width>=0);
  419.     WASSERT(height>=0);
  420.     
  421.     left = topLeft.x;
  422.     right = topLeft.x + width;
  423.     top  = topLeft.y;
  424.         bottom= topLeft.y + height;
  425. }
  426. #endif
  427.  
  428. #if defined _PLATFORM_MACINTOSH_ || _PLATFORM_WIN32_
  429. //------------------------------------------------------------------------------
  430. // ::ODRect( Rect )
  431. //
  432. // Construct an ODRect from a QuickDraw Rect
  433. //------------------------------------------------------------------------------
  434.  
  435. WIN32_DLLEXPORT ODRect::ODRect( const Rect &r )
  436. {
  437.     left = ff(r.left);        right = ff(r.right);
  438.     top  = ff(r.top);        bottom= ff(r.bottom);
  439. }
  440.  
  441.  
  442. //------------------------------------------------------------------------------
  443. // ::= Rect
  444. //
  445. // Set an ODRect from a QuickDraw Rect
  446. //------------------------------------------------------------------------------
  447.  
  448. WIN32_DLLEXPORT ODRect&
  449. ODRect:: operator= ( const Rect &r )
  450. {
  451.     left = ff(r.left);        right = ff(r.right);
  452.     top  = ff(r.top);        bottom= ff(r.bottom);
  453.     ASSERTVALID();
  454.     return *this;
  455. }
  456. #endif
  457.  
  458. #if defined _PLATFORM_AIX_
  459. //------------------------------------------------------------------------------
  460. // ::ODRect( Rect )
  461. //
  462. // Construct an ODRect from an AIX Rect (XRectangle)
  463. //------------------------------------------------------------------------------
  464.  
  465. ODRect::ODRect( const Rect &r )
  466. {
  467.     left = ff(r.x);        right = ff(r.x + r.width);
  468.     top  = ff(r.y);        bottom= ff(r.y + r.height);
  469. }
  470.  
  471.  
  472. //------------------------------------------------------------------------------
  473. // ::= Rect
  474. //
  475. // Set an ODRect from a QuickDraw Rect
  476. //------------------------------------------------------------------------------
  477.  
  478. ODRect&
  479. ODRect:: operator= ( const Rect &r )
  480. {
  481.     left = ff(r.x);        right = ff(r.x + r.width);
  482.     top  = ff(r.y);        bottom= ff(r.y + r.height);
  483.     ASSERTVALID();
  484.     return *this;
  485. }
  486. #endif  // _PLATFORM_AIX_
  487.  
  488.  
  489. #ifdef _PLATFORM_OS2_
  490. //------------------------------------------------------------------------------
  491. // ::ODRect( RECTL )
  492. //
  493. // Construct an ODRect from a GPI RECTL
  494. //------------------------------------------------------------------------------
  495. ODRect::ODRect( const RECTL &r )
  496. {
  497.   left = IntToFixed(r.xLeft);
  498.   right = IntToFixed(r.xRight); 
  499.   top = IntToFixed(r.yTop);
  500.   bottom = IntToFixed(r.yBottom);
  501. }
  502.  
  503. //------------------------------------------------------------------------------
  504. // ::= Rect
  505. //
  506. // Set an ODRect from a GPI RECTL
  507. //------------------------------------------------------------------------------
  508. ODRect&
  509. ODRect:: operator= ( const RECTL &r )
  510. {
  511.   left = IntToFixed(r.xLeft);
  512.   right = IntToFixed(r.xRight); 
  513.   top = IntToFixed(r.yTop);
  514.   bottom = IntToFixed(r.yBottom);
  515.   ASSERTVALID();
  516.   return *this;
  517. }
  518. #endif // _PLATFORM_OS2_
  519.  
  520. //------------------------------------------------------------------------------
  521. // ::Set
  522. //
  523. // Set all four coordinates of a rectangle. Warn if the resulting rect is bogus.
  524. //------------------------------------------------------------------------------
  525.  
  526. WIN32_DLLEXPORT void
  527. ODRect::Set( ODCoordinate l, ODCoordinate t, ODCoordinate r, ODCoordinate b )
  528. {
  529.     left = l;                right = r;
  530.     top  = t;                bottom= b;
  531.     ASSERTVALID();
  532. }
  533.  
  534.  
  535. //------------------------------------------------------------------------------
  536. // ::Set
  537. //
  538. // Set all four coordinates of a rectangle. Warn if the resulting rect is bogus.
  539. //------------------------------------------------------------------------------
  540.  
  541. WIN32_DLLEXPORT void
  542. ODRect::Set( const ODPoint &origin, ODCoordinate width, ODCoordinate height )
  543. {
  544.     WASSERT(width>=0);
  545.     WASSERT(height>=0);
  546.     left = origin.x;
  547.         right = left+width;
  548. #ifdef _PLATFORM_OS2_ 
  549.         bottom = origin.y; 
  550.         top = bottom + height; 
  551. #else 
  552.     top  = origin.y;
  553.         bottom= top +height;
  554. #endif
  555.  
  556. }
  557.  
  558.  
  559. //------------------------------------------------------------------------------
  560. // ::Set
  561. //
  562. // Construct a rectangle given two opposite corners (not necessarily topLeft,botRight)
  563. //------------------------------------------------------------------------------
  564.  
  565. WIN32_DLLEXPORT void
  566. ODRect::Set( const ODPoint &a, const ODPoint &b )
  567. {
  568.     if( a.x<b.x ) {
  569.         left = a.x;
  570.         right= b.x;
  571.     } else {
  572.         left = b.x;
  573.         right= a.x;
  574.     }
  575. #ifdef _PLATFORM_OS2_ 
  576.         if( b.y < a.y ) { 
  577. #else 
  578.     if( a.y<b.y ) {
  579. #endif
  580.         top   = a.y;
  581.         bottom= b.y;
  582.     } else {
  583.         top   = b.y;
  584.         bottom= a.y;
  585.     }
  586. }
  587.  
  588.  
  589. //------------------------------------------------------------------------------
  590. // ::SetInt
  591. //
  592. // Set coordinates of a rectangle from integers. Warn if the resulting rect is bogus.
  593. //------------------------------------------------------------------------------
  594.  
  595. WIN32_DLLEXPORT void
  596. ODRect::SetInt( short l, short t, short r, short b )
  597. {
  598.     left = ff(l);            right = ff(r);
  599.     top  = ff(t);            bottom= ff(b);
  600.     ASSERTVALID();
  601. }
  602.  
  603.  
  604. //------------------------------------------------------------------------------
  605. // ::Offset
  606. //
  607. // Move a rectangle.
  608. //------------------------------------------------------------------------------
  609.  
  610. WIN32_DLLEXPORT void
  611. ODRect::Offset( ODCoordinate x, ODCoordinate y )
  612. {
  613.     left += x;                right += x;
  614.     top  += y;                bottom+= y;
  615. }
  616.  
  617. WIN32_DLLEXPORT void
  618. ODRect::Offset( const ODPoint &pt )
  619. {
  620.     left += pt.x;            right += pt.x;
  621.     top  += pt.y;            bottom+= pt.y;
  622. }
  623.  
  624. #if 0
  625. #ifdef _PLATFORM_WIN32_
  626. void
  627. ODRect::Transform( const void *xform )
  628. {
  629.     *((ODPoint*)&left) = ((ODTransform *)xform)->TransformPoint(*((ODPoint*)&left));
  630.     *((ODPoint*)&right) = ((ODTransform *)xform)->TransformPoint(*((ODPoint*)&right));
  631. }
  632. #endif
  633. #endif
  634.  
  635. //------------------------------------------------------------------------------
  636. // ::Inset
  637. //
  638. // Inset the edges of a rectangle, without collapsing to negative dimensions.
  639. //------------------------------------------------------------------------------
  640.  
  641. WIN32_DLLEXPORT void
  642. ODRect::Inset( ODCoordinate x, ODCoordinate y )
  643. {
  644.     left += x;
  645.     right = Max(left,right-x);
  646. #ifdef _PLATFORM_OS2_ 
  647.         bottom += y; 
  648.         top = Max( bottom, top - y ); 
  649. #else 
  650.     top += y;
  651.     bottom = Max(top,bottom-y);
  652. #endif
  653. }
  654.  
  655.  
  656. //------------------------------------------------------------------------------
  657. // ::Clear
  658. //
  659. // Zero all coordinates
  660. //------------------------------------------------------------------------------
  661.  
  662. WIN32_DLLEXPORT void
  663. ODRect::Clear( )
  664. {
  665.     left = right = top = bottom = 0;
  666. }
  667.  
  668.  
  669. //------------------------------------------------------------------------------
  670. // :: &=
  671. //
  672. // Intersect me with another rectangle (result stored in me)
  673. //------------------------------------------------------------------------------
  674.  
  675. WIN32_DLLEXPORT void
  676. ODRect:: operator&= ( const ODRect &r )
  677. {
  678.     left = Max(left,r.left);
  679.         right = Min(right, r.right);
  680. #ifdef _PLATFORM_OS2_ 
  681.         top = Min( top, r.top ); 
  682.         bottom = Max( bottom, r.bottom ); 
  683. #else 
  684.     top  = Max(top, r.top);
  685.         bottom= Min(bottom,r.bottom);
  686. #endif
  687.     if( this->IsEmpty() )
  688.         this->Clear();
  689. }
  690.  
  691.  
  692. //------------------------------------------------------------------------------
  693. // :: |=
  694. //
  695. // Union me with another rectangle (result stored in me)
  696. //------------------------------------------------------------------------------
  697.  
  698. WIN32_DLLEXPORT void
  699. ODRect:: operator|= ( const ODRect &r )
  700. {
  701.     if( this->IsEmpty() )
  702.         *this = r;
  703.     else if( !r.IsEmpty() ) {
  704.         left = Min(left,r.left);
  705.         right= Max(right,r.right);
  706. #ifdef _PLATFORM_OS2_ 
  707.                 top = Max( top, r.top ); 
  708.                 bottom = Min( bottom, r.bottom ); 
  709. #else 
  710.         top  = Min(top,r.top);
  711.         bottom=Max(bottom,r.bottom);
  712. #endif
  713.     }
  714. }
  715.  
  716.  
  717. //------------------------------------------------------------------------------
  718. // :: |= ODPoint
  719. //
  720. // Union me with a point (expand to fit point)
  721. //------------------------------------------------------------------------------
  722.  
  723. WIN32_DLLEXPORT void
  724. ODRect:: operator|= ( const ODPoint &pt )
  725. {
  726.     left = Min(left,pt.x);
  727.     right= Max(right,pt.x);
  728. #ifdef _PLATFORM_OS2_ 
  729.         top = Max( top, pt.y ); 
  730.         bottom = Min( bottom, pt.y ); 
  731. #else 
  732.     top  = Min(top,pt.y);
  733.     bottom=Max(bottom,pt.y);
  734. #endif
  735. }
  736.  
  737.  
  738. #ifdef _PLATFORM_MACINTOSH_
  739. //------------------------------------------------------------------------------
  740. // :: AsQDRect
  741. //
  742. // Turn me into a QuickDraw rect
  743. //------------------------------------------------------------------------------
  744.  
  745. void
  746. ODRect::AsQDRect( Rect &r ) const
  747. {
  748.     SetRect(&r, FixedToInt(left), FixedToInt(top), FixedToInt(right), FixedToInt(bottom));
  749. }
  750. #endif
  751.  
  752. #ifdef  _PLATFORM_WIN32_
  753. //------------------------------------------------------------------------------
  754. // :: AsWinRect
  755. //
  756. // Turn me into a Windows rect
  757. //------------------------------------------------------------------------------
  758.  
  759. WIN32_DLLEXPORT void
  760. ODRect::AsWinRect( Rect &r ) const
  761. {
  762.     SetRect(&r, FixedToInt(left), FixedToInt(top), FixedToInt(right), FixedToInt(bottom));
  763. }
  764. #endif  // _PLATFORM_WIN32_
  765.  
  766. #ifdef _PLATFORM_OS2_
  767. //------------------------------------------------------------------------------
  768. // :: AsRECTL
  769. //
  770. // Turn me into a GPI RECTL
  771. //------------------------------------------------------------------------------
  772.  
  773. void ODRect::AsRECTL( RECTL& r) const
  774. {
  775.  
  776.   r.xLeft = FixedToInt(left);
  777.   r.xRight = FixedToInt(right);
  778.   r.yTop = FixedToInt(top);
  779.   r.yBottom = FixedToInt(bottom);
  780.   
  781.  
  782. }
  783. #endif // _PLATFORM_OS2_
  784.  
  785. #ifdef _PLATFORM_AIX_
  786. //------------------------------------------------------------------------------
  787. // :: AsXRect
  788. //
  789. // Turn me into a AIX rect (XRectangle)
  790. //------------------------------------------------------------------------------
  791.  
  792. void
  793. ODRect::AsXRect( Rect &r ) const
  794. {
  795.   r.x = FixedToInt(left);
  796.   r.width = FixedToInt(right) - FixedToInt(left);
  797.   r.y = FixedToInt(top);
  798.   r.height = FixedToInt(bottom) - FixedToInt(top);
  799. }
  800. #endif  // _PLATFORM_AIX_
  801.  
  802. //------------------------------------------------------------------------------
  803. // :: IsEmpty
  804. //
  805. // Do I have no area?
  806. //------------------------------------------------------------------------------
  807.  
  808. #if defined (_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  809. WIN32_DLLEXPORT ODBoolean
  810. #else
  811. Boolean
  812. #endif
  813. ODRect::IsEmpty( ) const
  814. {
  815. #ifdef _PLATFORM_OS2_ 
  816.         return (ODBoolean) ( right <= left ) || ( top <= bottom ); 
  817. #else 
  818.     return right<=left || bottom<=top;
  819. #endif
  820. }
  821.  
  822.  
  823. //------------------------------------------------------------------------------
  824. // :: Contains( Point )
  825. //
  826. // Do I contain a point? (Remember, I don't contain my right and bottom edges, 
  827. //                                  or right and top edges for OS/2.) 
  828. //------------------------------------------------------------------------------
  829.  
  830. #if defined (_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  831. WIN32_DLLEXPORT ODBoolean
  832. #else
  833. Boolean
  834. #endif
  835. ODRect::Contains( const ODPoint &pt ) const
  836. {
  837.     return left<=pt.x && pt.x<right
  838. #ifdef _PLATFORM_OS2_ 
  839.             && bottom <= pt.y && pt.y < top; 
  840. #else 
  841.         && top <=pt.y && pt.y<bottom;
  842. #endif
  843. }
  844.  
  845.  
  846. //------------------------------------------------------------------------------
  847. // :: Contains( Rect )
  848. //
  849. // Do I contain an entire rect?
  850. //------------------------------------------------------------------------------
  851.  
  852. #if defined (_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  853. WIN32_DLLEXPORT ODBoolean
  854. #else
  855. Boolean
  856. #endif // _PLATFORM_WIN32_
  857. ODRect::Contains( const ODRect &r ) const
  858. {
  859. #ifdef _PLATFORM_OS2_ 
  860.         return left<=r.left && r.right<=right 
  861.             && top >=r.top  && r.bottom>=bottom; 
  862. #else 
  863.         return left<=r.left && r.right<=right
  864.             && top <=r.top  && r.bottom<=bottom;
  865. #endif
  866. }
  867.  
  868.  
  869. //------------------------------------------------------------------------------
  870. // :: ApproxContains( Rect )
  871. //
  872. // Do I approximately (within epsilon) contain an entire rect?
  873. //------------------------------------------------------------------------------
  874.  
  875. #if defined (_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  876. WIN32_DLLEXPORT ODBoolean
  877. #else
  878. Boolean
  879. #endif // _PLATFORM_WIN32_
  880. ODRect::ApproxContains( const ODRect &r ) const
  881. {
  882.     if( r.right<=r.left || r.bottom<=r.top )
  883.         return kODTrue;                    // Empty rect contained in anything
  884.     else
  885.         return left-kFixedEpsilon<=r.left && r.right<=right+kFixedEpsilon
  886. #ifdef _PLATFORM_OS2_ 
  887.             && bottom-kFixedEpsilon <=r.bottom  && r.top<=top+kFixedEpsilon; 
  888. #else 
  889.             && top-kFixedEpsilon <=r.top  && r.bottom<=bottom+kFixedEpsilon;
  890. #endif
  891. }
  892.  
  893.  
  894. //------------------------------------------------------------------------------
  895. // :: ==
  896. //
  897. // Am I equal to another rect?
  898. //------------------------------------------------------------------------------
  899.  
  900. #if defined (_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  901. WIN32_DLLEXPORT ODBoolean
  902. #else
  903. Boolean
  904. #endif // _PLATFORM_WIN32_
  905.  
  906. ODRect::operator==( const ODRect &r ) const
  907. {
  908.     return memcmp(this,&r,sizeof(ODRect)) == 0;
  909. }
  910.  
  911.  
  912. //------------------------------------------------------------------------------
  913. // :: ApproxEquals
  914. //
  915. // Am I approximately equal (within epsilon) to another rect?
  916. //------------------------------------------------------------------------------
  917.  
  918. WIN32_DLLEXPORT ODBoolean
  919. ODRect::ApproxEquals( const ODRect &r ) const
  920. {
  921.     return left-r.left<=kFixedEpsilon     && left-r.left>=-kFixedEpsilon
  922.         && right-r.right<=kFixedEpsilon   && right-r.right>=-kFixedEpsilon
  923.         && top-r.top<=kFixedEpsilon       && top-r.top>=-kFixedEpsilon
  924.         && bottom-r.bottom<=kFixedEpsilon && bottom-r.bottom>=-kFixedEpsilon;
  925. }
  926.  
  927.  
  928. //------------------------------------------------------------------------------
  929. // :: Intersects
  930. //
  931. // Do I intersect another rectangle?
  932. // (Remember, I don't contain my right and bottom edges.)
  933. //------------------------------------------------------------------------------
  934.  
  935. #if defined (_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  936. WIN32_DLLEXPORT ODBoolean
  937. #else
  938. Boolean
  939. #endif // _PLATFORM_WIN32_
  940. ODRect::Intersects( const ODRect &r ) const
  941. {
  942.     return Max(left,r.left) < Min(right,r.right)
  943. #ifdef _PLATFORM_OS2_ 
  944.                 && Min(top, r.top) > Max(bottom, r.bottom); 
  945. #else 
  946.         && Max(top,r.top) < Min(bottom,r.bottom);
  947. #endif
  948. }
  949.  
  950.  
  951. #if ( (defined (_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)) \
  952.       || defined (_PLATFORM_AIX_) ) 
  953. //=======================================================
  954. // ODToolSpaceRect
  955. //======================================================
  956.  
  957. //-----------------------------------------------------
  958. // ODToolSpaceRect::ODToolSpaceRect
  959. //----------------------------------------------------
  960.  
  961. WIN32_DLLEXPORT ODToolSpaceRect::ODToolSpaceRect(ODCoordinate l, ODCoordinate t,
  962.                                  ODCoordinate r, ODCoordinate b, ODRect* aFloatRect)
  963. {
  964.   left = l; top = t; right = r; bottom = b;
  965.   if (aFloatRect) {
  966.     floatRect = *aFloatRect;
  967.   } else {
  968.     floatRect.Clear();
  969.   }
  970. }
  971.  
  972. //----------------------------------------------------
  973. // ODToolSpaceRect::IsEmpty
  974. //----------------------------------------------------
  975.  
  976. WIN32_DLLEXPORT ODBoolean ODToolSpaceRect::IsEmpty() const
  977. {
  978.   if ((left==0) && (top==0) && (right==0) && (bottom==0) && floatRect.IsEmpty()) {
  979.     return(kODTrue);
  980.   } else {
  981.     return(kODFalse);
  982.   }
  983. }
  984.  
  985. //----------------------------------------------------
  986. // ODToolSpaceRect::Set
  987. //----------------------------------------------------
  988.  
  989. WIN32_DLLEXPORT void ODToolSpaceRect::Set(ODCoordinate l, ODCoordinate t,
  990.                           ODCoordinate r, ODCoordinate b, ODRect* aFloatRect)
  991. {
  992.   left=l;
  993.   top=t;
  994.   right=r;
  995.   bottom=b;
  996.   if (aFloatRect) {
  997.     floatRect = *aFloatRect;
  998.   } else {
  999.     floatRect.Clear();
  1000.   }
  1001. }
  1002.  
  1003. //----------------------------------------------------
  1004. // ODToolSpaceRect::Clear
  1005. //----------------------------------------------------
  1006.  
  1007. WIN32_DLLEXPORT void ODToolSpaceRect::Clear(void)
  1008. {
  1009.   left=0;
  1010.   top=0;
  1011.   right=0;
  1012.   bottom=0;
  1013.   floatRect.Clear();
  1014. }
  1015. #endif // _PLATFORM_WIN32_
  1016.  
  1017.  
  1018. #if ((defined (_PLATFORM_WIN32_) || defined (_PLATFORM_OS2_)) \
  1019.       || defined (_PLATFORM_AIX_) ) && defined(DEBUG)
  1020.  
  1021. /////////////////////////////////////////////////////////
  1022. // Testing code below
  1023. //
  1024. // I updated the SelfTest methods to optionally take a HWND.
  1025. // I use this in my PUTest test case.  This is a Public
  1026. // Utilities part that tests focuslib and calls some of
  1027. // these SelfTest methods.  So if you aren't wanting to 
  1028. // test from a full-blown part, just don't pass in a 
  1029. // HWND and write a simple command-line test case. Rob
  1030. /////////////////////////////////////////////////////////
  1031.  
  1032. WIN32_DLLEXPORT void ODPoint::SelfTest(HWND testWin)
  1033. // the  HWND is ignored for OS/2
  1034. {
  1035. #ifdef _PLATFORM_WIN32_
  1036.   if(testWin) {
  1037.     testWindow = testWin;
  1038.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)"\n\nBEGIN ODPoint::SelfTest\n\n");
  1039.   }
  1040.   else {
  1041.   printf ("\n\nBEGIN ODPoint::SelfTest\n\n");
  1042.   }
  1043. #else
  1044.   printf ("\n\nBEGIN ODPoint::SelfTest\n\n");
  1045. #endif
  1046.  
  1047.   ODCoordinate x1 = IntToFixed(50);
  1048.   ODCoordinate y1 = IntToFixed(100);
  1049.  
  1050.   // test default ctor
  1051.   ODPoint point2;
  1052.  
  1053.  
  1054.   ODPoint *point1 = new ODPoint(x1, y1);  
  1055.   point1->PrintIt("point1: testing 'new' of ODPoint::ODPoint");
  1056.   CHECKRES( (point1->x == x1) && (point1->y == y1) );
  1057.  
  1058.   // test operator = 
  1059.   ODPoint *point3 = point1;  
  1060.   point3->PrintIt("point3: testing ODPoint::operator=");
  1061.   CHECKRES( (point3->x == x1) && (point3->y == y1) );
  1062.  
  1063.   // test copy ctor
  1064.   ODPoint *point4 = new ODPoint(*point1);
  1065.   point4->PrintIt("point4: testing ODPoint copy ctor");
  1066.   CHECKRES( (point4->x == x1) && (point4->y == y1) );
  1067.  
  1068.   // Modification tests
  1069.  
  1070.   // test ::Clear()
  1071.   point1->Clear();
  1072.   point1->PrintIt("point1.Clear()");
  1073.   CHECKRES( (point1->x == 0) && (point1->y == 0) );
  1074.       
  1075.   // test ::Set()
  1076.   point2.Set( x1, y1);
  1077.   point2.PrintIt("point2.Set(50,100)");
  1078.   CHECKRES( (point2.x == x1) && (point2.y == y1) );
  1079.  
  1080.   // test ::Offset()
  1081.   point2.Set( x1, y1);
  1082.   point2.Offset( y1, x1);
  1083.   point2.PrintIt("point2.Offset(100, 50)"); 
  1084.   CHECKRES( (point2.x == x1+y1) && (point2.y == y1+x1) );
  1085.  
  1086.  
  1087.   // test operator+=
  1088.   point2.Set( x1, y1);
  1089.   point3->Set( x1, y1);
  1090.   point2 += *point3;
  1091.   point2.PrintIt("point2 operator+= point3"); 
  1092.   CHECKRES( (point2.x == x1+x1) && (point2.y == y1+y1) );
  1093.  
  1094.   // test operator-=
  1095.   point2.Set( x1, y1);
  1096.   point3->Set( x1, y1);
  1097.   point2 -= *point3;
  1098.   point2.PrintIt("point2 operator-= point3 "); 
  1099.   CHECKRES( (point2.x == 0) && (point2.y == 0) );
  1100.  
  1101.   // test ::IntX(), ::IntY()
  1102.   printf ("-----------------------------------------------------\n");
  1103.   point2.Set( x1, y1);
  1104.   ODSShort theX = FixedToInt(x1);
  1105.   ODSShort theY = FixedToInt(y1);
  1106.   ODSShort retX = point2.IntX();
  1107.   printf("IntX = %d\n", retX);
  1108.   CHECKRES( retX == theX );
  1109.  
  1110.   ODSShort retY = point2.IntY();
  1111.   printf("IntY = %d\n", retY);
  1112.   CHECKRES( retY == theY );
  1113.  
  1114.   // test operator==
  1115.   point1->PrintIt("point1 operator== point4");
  1116.   CHECKRES (*point1 == *point4);
  1117.  
  1118.   // test operator!=
  1119.   point1->PrintIt("point1 operator!= point4");
  1120.   CHECKRES (!(*point1 != *point4));
  1121.  
  1122.   // test ::ApproxEquals()
  1123.   point1->PrintIt("point1->ApproxEquals(point2)");
  1124.   CHECKRES (point1->ApproxEquals(point2) );
  1125.  
  1126.   // test ODPoint(Point) ctor
  1127.   Point p;
  1128.   p.x = 33;
  1129.   p.y = 99;
  1130.   ODPoint point5(p);
  1131.   point5.PrintIt("point5(Point(33,99))");
  1132.   CHECKRES ( (point5.x == IntToFixed(33)) && (point5.y == IntToFixed(99)) );
  1133.  
  1134. #ifdef _PLATFORM_WIN32_
  1135.   // test ::AsWinPoint()
  1136.   point1->PrintIt("testing AsWinPoint");
  1137.   Point winPoint = point1->AsWinPoint();
  1138. #elif _PLATFORM_OS2_
  1139.   // test ::AsPOINTL()
  1140.   point1->PrintIt("testing AsPOINTL");
  1141.   POINTL winPoint = point1->AsPOINTL();
  1142. #elif _PLATFORM_AIX_
  1143.   // test ::AsXPoint()
  1144.   point1->PrintIt("testing AsXPoint");
  1145.   Point winPoint = point1->AsXPoint();
  1146. #endif
  1147.   printf("winPoint.x = %d, winPoint.y = %d\n", winPoint.x, winPoint.y);
  1148.   CHECKRES ( (IntToFixed(winPoint.x) == point1->x) && (IntToFixed(winPoint.y) == point1->y) );
  1149.  
  1150.   // test Point operator+=
  1151.   winPoint.x = 33;
  1152.   winPoint.y = 99;
  1153.   *point1 += p;
  1154.   point1->PrintIt("testing point1 operator+= winPoint");
  1155.   CHECKRES ( (point1->x == IntToFixed(83)) && (point1->y == IntToFixed(199)) );
  1156.  
  1157.   // test Point operator+-
  1158.   *point1 -= p;
  1159.   point1->PrintIt("testing point1 operator+- winPoint");
  1160.   CHECKRES ( (point1->x == IntToFixed(50)) && (point1->y == IntToFixed(100)) );
  1161.  
  1162.   // delete point4
  1163.   delete point4;
  1164.  
  1165. #ifdef _PLATFORM_WIN32_
  1166.   if(testWin) {
  1167.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)"\n\nEND ODPoint::SelfTest\n\n");
  1168.   }
  1169.   else {
  1170.     printf ("\n\nEND ODPoint::SelfTest\n\n");
  1171.   } 
  1172. #else
  1173.     printf ("\n\nEND ODPoint::SelfTest\n\n");
  1174. #endif
  1175.   // end of unit test
  1176. }
  1177.  
  1178. WIN32_DLLEXPORT void ODPoint::PrintIt(char *msg)
  1179. {
  1180. #ifdef _PLATFORM_WIN32_
  1181.   if(!testWindow) {
  1182.     printf (myLine);
  1183.     if(msg != NULL)
  1184.       printf ("%s\n",msg);
  1185.     printf ("X-Coordinate is: %d\n", x);
  1186.     printf ("Y-Coordinate is: %d\n", y);
  1187.   }
  1188.   else {
  1189.     char tmpBuff[1024];
  1190.     sprintf (tmpBuff, myLine);
  1191.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1192.     if(msg != NULL) {
  1193.       sprintf (tmpBuff, "%s\n",msg );
  1194.       SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1195.     }
  1196.     sprintf (tmpBuff, "X-Coordinate is: %d\n", x);
  1197.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1198.     sprintf (tmpBuff, "Y-Coordinate is: %d\n", y);
  1199.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1200.   }
  1201. #else
  1202.   printf (myLine);
  1203.   if(msg != NULL)
  1204.     printf ("%s\n",msg);
  1205.   printf ("X-Coordinate is: %d\n", x);
  1206.   printf ("Y-Coordinate is: %d\n", y);
  1207. #endif
  1208.   
  1209. }
  1210.  
  1211. WIN32_DLLEXPORT void ODRect::SelfTest(HWND testWin) 
  1212. {
  1213.  
  1214. #ifdef _PLATFORM_OS2_
  1215.   ODCoordinate myLeft = IntToFixed(20);
  1216.   ODCoordinate myTop = IntToFixed(100);
  1217.   ODCoordinate myRight = IntToFixed(100);
  1218.   ODCoordinate myBottom = IntToFixed(20);
  1219. #else
  1220.   ODCoordinate myLeft = IntToFixed(20);
  1221.   ODCoordinate myTop = IntToFixed(20);
  1222.   ODCoordinate myRight = IntToFixed(100);
  1223.   ODCoordinate myBottom = IntToFixed(100);
  1224. #endif  // _PLATFORM_OS2_
  1225.  
  1226.   ODPoint point1(IntToFixed(20), IntToFixed(20));
  1227.   ODPoint point2(IntToFixed(80), IntToFixed(80));
  1228.  
  1229.   Rect myRect;
  1230. #ifdef _PLATFORM_WIN32_
  1231.   myRect.left = 40;
  1232.   myRect.top = 40;
  1233.   myRect.right = 90;
  1234.   myRect.bottom = 90;
  1235. #elif _PLATFORM_OS2_
  1236.   myRect.xLeft = 40;
  1237.   myRect.yTop = 90;
  1238.   myRect.xRight = 90;
  1239.   myRect.yBottom = 40;
  1240. #elif _PLATFORM_AIX_
  1241.   myRect.x = 40;
  1242.   myRect.y = 40;
  1243.   myRect.width = 50;
  1244.   myRect.height = 50;
  1245. #endif
  1246.  
  1247. #ifdef _PLATFORM_WIN32_
  1248.   if(testWin) {
  1249.     testWindow = testWin;
  1250.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)"\n\nBEGIN ODRect::SelfTest\n\n");
  1251.   }
  1252.   else {
  1253.     printf ("\n\nBEGIN ODRect::SelfTest\n\n");
  1254.   }
  1255. #else
  1256.   printf ("\n\nBEGIN ODRect::SelfTest\n\n");
  1257. #endif
  1258.  
  1259.   // test default ctor
  1260.   ODRect rect1;
  1261.  
  1262.   // test ctor
  1263.   ODRect rect2(myLeft, myTop, myRight, myBottom);
  1264.   rect2.PrintIt("rect2: testing ODRect::ODRect");
  1265.   CHECKRES ( ( (rect2.left == myLeft) && (rect2.top == myTop) 
  1266.     && (rect2.right == myRight) && (rect2.bottom == myBottom) ) );
  1267.  
  1268.   // test ctor
  1269.   ODRect rect3(point1, point2);
  1270.   rect3.PrintIt("rect3: testing ODRect::ODRect(ODPoint, ODPoint) ctor");
  1271. #ifdef _PLATFORM_OS2_
  1272.   CHECKRES ( ( (rect3.left == point1.x) && (rect3.top == point2.y) 
  1273.     && (rect3.right == point2.x) && (rect3.bottom == point1.y) ) );
  1274. #else
  1275.   CHECKRES ( ( (rect3.left == point1.x) && (rect3.top == point1.y) 
  1276.     && (rect3.right == point2.x) && (rect3.bottom == point2.y) ) );
  1277. #endif
  1278.  
  1279.   // test ctor
  1280.   ODRect rect4(point1, myRight, myBottom);
  1281.   rect4.PrintIt("rect4: testing ODRect::ODRect(ODPoint, ODCoordinate, ODCoordinate) ctor");
  1282.   CHECKRES ( ( (rect4.left == point1.x) && (rect4.top == point1.y) 
  1283.     && (rect4.right == point1.x + myRight) && (rect4.bottom == point1.y + myBottom) ) );
  1284.  
  1285.   // test ctor
  1286.   ODRect rect5(myRect);
  1287.   rect5.PrintIt("rect5: testing ODRect::ODRect(Rect)");
  1288. #ifdef _PLATFORM_WIN32_
  1289.   CHECKRES ( ( (rect5.left == IntToFixed(myRect.left)) && (rect5.top == IntToFixed(myRect.top) ) 
  1290.     && (rect5.right == IntToFixed(myRect.right) ) && (rect5.bottom == IntToFixed(myRect.bottom )) ) );
  1291. #elif defined(_PLATFORM_OS2_)
  1292.   CHECKRES ( ( (rect5.left == IntToFixed(myRect.xLeft)) && (rect5.top == IntToFixed(myRect.yTop) ) 
  1293.     && (rect5.right == IntToFixed(myRect.xRight) ) && (rect5.bottom == IntToFixed(myRect.yBottom )) ) );
  1294. #elif defined(_PLATFORM_AIX_)
  1295.   CHECKRES ( ( (rect5.left == IntToFixed(myRect.x)) && (rect5.top == IntToFixed(myRect.y) ) 
  1296.     && (rect5.right == IntToFixed(myRect.x + myRect.width) ) && (rect5.bottom == IntToFixed(myRect.y + myRect.height )) ) );
  1297. #endif
  1298.  
  1299.   // test operator=
  1300.   ODRect rect6 = myRect;
  1301.   rect6.PrintIt("rect6: testing ODRect::operator= Rect");
  1302. #ifdef _PLATFORM_WIN32_
  1303.   CHECKRES ( ( (rect6.left == IntToFixed(myRect.left) ) && (rect6.top == IntToFixed(myRect.top) ) 
  1304.     && (rect6.right == IntToFixed(myRect.right) ) && (rect6.bottom == IntToFixed(myRect.bottom) ) ) );
  1305. #elif defined(_PLATFORM_OS2_)
  1306.   CHECKRES ( ( (rect6.left == IntToFixed(myRect.xLeft) ) && (rect6.top == IntToFixed(myRect.yTop) ) 
  1307.     && (rect6.right == IntToFixed(myRect.xRight) ) && (rect6.bottom == IntToFixed(myRect.yBottom) ) ) );
  1308. #elif defined(_PLATFORM_AIX_)
  1309.   CHECKRES ( (rect6.left == IntToFixed(myRect.x)) && (rect6.top == IntToFixed(myRect.y)) 
  1310.     && (rect6.right == (IntToFixed(myRect.x) + IntToFixed(myRect.width))) && (rect6.bottom == (IntToFixed(myRect.y) + IntToFixed(myRect.height))) );
  1311. #endif
  1312.  
  1313.   // test ::Clear()
  1314.   rect2.Clear();
  1315.   rect2.PrintIt("rect2: testing ODRect::Clear()");
  1316.   CHECKRES ( ( (rect2.left == 0) && (rect2.top == 0) 
  1317.     && (rect2.right == 0) && (rect2.bottom == 0) ) );
  1318.  
  1319.   // test ::Set()
  1320.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1321.   rect1.PrintIt("rect1: testing ODRect::Set() using coordinates");
  1322.   CHECKRES ( ( (rect1.left == myLeft) && (rect1.top == myTop) 
  1323.     && (rect1.right == myRight) && (rect1.bottom == myBottom) ) );
  1324.  
  1325.   // test ::Set()
  1326.   rect1.Set(point1, myRight, myBottom); 
  1327.   rect1.PrintIt("rect1: testing ODRect::Set() using points and coordinates");
  1328. #ifdef _PLATFORM_OS2_
  1329.   CHECKRES ( ( (rect1.left == point1.x) && (rect1.top == point1.y + myBottom) 
  1330.     && (rect1.right == point1.x + myRight) && (rect1.bottom == point1.y) ) );
  1331. #else
  1332.   CHECKRES ( ( (rect1.left == point1.x) && (rect1.top == point1.y) 
  1333.     && (rect1.right == point1.x + myRight) && (rect1.bottom == point1.y + myBottom) ) );
  1334. #endif
  1335.  
  1336.   // test ::Set()
  1337.   rect1.Set(point1, point2);
  1338.   rect1.PrintIt("rect1: testing ODRect::Set() using points");
  1339. #ifdef _PLATFORM_OS2_
  1340.   CHECKRES ( ( (rect1.left == point1.x) && (rect1.top == point2.y) 
  1341.     && (rect1.right == point2.x) && (rect1.bottom == point1.y) ) );
  1342. #else
  1343.   CHECKRES ( ( (rect1.left == point1.x) && (rect1.top == point1.y) 
  1344.     && (rect1.right == point2.x) && (rect1.bottom == point2.y) ) );
  1345. #endif
  1346.  
  1347.   // test ::Set()
  1348.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1349.   rect1.SetInt((short)33, (short)33, (short)99, (short)99);
  1350.   rect1.PrintIt("rect1: testing ODRect::SetInt() using shorts");
  1351.   CHECKRES ( ( (rect1.left == IntToFixed(33)) && (rect1.top == IntToFixed(33)) 
  1352.     && (rect1.right == IntToFixed(99)) && (rect1.bottom == IntToFixed(99) ) ) );
  1353.  
  1354.   // test ::Offset()
  1355.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1356.   rect1.Offset(myRight, myBottom);
  1357.   rect1.PrintIt("rect1: testing ODRect::Offset()");
  1358.   CHECKRES ( (rect1.left == myLeft + myRight) && (rect1.top == myTop+myBottom) 
  1359.     && (rect1.right == myRight+myRight) && (rect1.bottom == myBottom+myBottom) ) ;
  1360.  
  1361.   // test ::Offset()
  1362.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1363.   rect1.Offset(point1);
  1364.   rect1.PrintIt("rect1: testing ODRect::Offset(ODPoint)");
  1365.   rect1.PrintIt("rect1: testing ODRect::Offset()");
  1366.   CHECKRES ( (rect1.left == myLeft + point1.x) && (rect1.top == myTop+point1.y) 
  1367.     && (rect1.right == myRight+point1.x) && (rect1.bottom == myBottom+point1.y)  );
  1368.  
  1369.   // test ::Inset()
  1370.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1371.   rect1.PrintIt("rect1: after rect1.Set(myLeft, myTop, myRight, myBottom);");
  1372. #ifdef _PLATFORM_OS2_
  1373.   rect1.Inset(myLeft, myBottom);
  1374. #else
  1375.   rect1.Inset(myLeft, myTop);
  1376. #endif  // _PLATFORM_OS2_
  1377.   rect1.PrintIt("rect1: testing ODRect::Inset()");
  1378.  
  1379.   // test operator&=
  1380.   rect6.Set(point1, point2);
  1381.   rect6.PrintIt("rect6: After rect6.Set(point1, point2);");
  1382.   rect1 &= rect6; 
  1383.   rect1.PrintIt("rect1: testing ODRect::operator&=() rect6");
  1384.  
  1385.   // test operator|=
  1386.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1387.   rect1.PrintIt("rect1: after rect1.Set(myLeft, myTop, myRight, myBottom);");
  1388.   rect1 |= rect6; 
  1389.   rect1.PrintIt("rect1: testing ODRect::operator|=() rect6");
  1390.  
  1391.   // test operator|=
  1392.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1393.   rect1.PrintIt("rect1: after rect1.Set(myLeft, myTop, myRight, myBottom);");
  1394.   rect1 |= point2; 
  1395.   rect1.PrintIt("rect1: testing ODRect::operator|=() ODPoint");
  1396.  
  1397.   // test ::TopLeft, ::BotRight, ::Width, ::Height
  1398.   ODPoint topLeft = rect1.TopLeft();
  1399.   ODPoint botRight = rect1.BotRight();
  1400.   printf("\nTopLeft = %d,%d\n",topLeft.x, topLeft.y);
  1401.   printf("\nBotRight = %d,%d\n",botRight.x, botRight.y);
  1402.  
  1403.   ODCoordinate myWidth = rect1.Width();
  1404.   ODCoordinate myHeight = rect1.Height();
  1405.   printf("\nWidth = %d\n",myWidth);
  1406.   printf("\nHeight = %d\n",myHeight);
  1407.   myWidth = FixedToInt(rect1.Width());
  1408.   myHeight = FixedToInt(rect1.Height());
  1409.   printf("\nFixedToInt Width = %d\n",myWidth);
  1410.   printf("\nFixedToInt Height = %d\n",myHeight);
  1411.  
  1412.   // test ::AsWinRect
  1413.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1414. #ifdef _PLATFORM_WIN32_
  1415.   rect1.AsWinRect(myRect);
  1416.   rect1.PrintIt("rect1: testing ODRect::AsWinRect(Rect)");
  1417.   CHECKRES ( ( (rect1.left == IntToFixed(myRect.left)) && (rect1.top == IntToFixed(myRect.top) ) 
  1418.     && (rect1.right == IntToFixed(myRect.right)) && (rect1.bottom == IntToFixed(myRect.bottom)) ) );
  1419. #elif defined(_PLATFORM_OS2_)
  1420.   rect1.AsRECTL(myRect);
  1421.   rect1.PrintIt("rect1: testing ODRect::AsRECTL(Rect)");
  1422.   CHECKRES ( ( (rect1.left == IntToFixed(myRect.xLeft)) && (rect1.top == IntToFixed(myRect.yTop) ) 
  1423.     && (rect1.right == IntToFixed(myRect.xRight)) && (rect1.bottom == IntToFixed(myRect.yBottom)) ) );
  1424. #elif defined(_PLATFORM_AIX_)
  1425.   rect1.AsXRect(myRect);
  1426.   rect1.PrintIt("rect1: testing ODRect::AsXRect(Rect)");
  1427.   CHECKRES (  (rect1.left == IntToFixed(myRect.x)) && (rect1.top == IntToFixed(myRect.y)) 
  1428.     && (rect1.right == (IntToFixed(myRect.x) + IntToFixed(myRect.width)) ) && (rect1.bottom == (IntToFixed(myRect.y) + IntToFixed(myRect.height)))  );
  1429. #endif
  1430.  
  1431.   // test of operator==
  1432.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1433.   rect2.Set(myLeft, myTop, myRight, myBottom);
  1434.   rect1.PrintIt("rect1: testing ODRect::operator==");
  1435.   CHECKRES (rect1 == rect2) ;
  1436.  
  1437.  
  1438.   // test of operator!=
  1439.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1440.   rect2.Set(myLeft, myTop, myRight, myBottom);
  1441.   rect1.Inset(myLeft, myTop);
  1442.   rect1.PrintIt("rect1: testing ODRect::operator!=");
  1443.   CHECKRES (rect1 != rect2) ;
  1444.  
  1445.   // test ::ApproxEquals()
  1446.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1447.   rect2.Clear();
  1448.   rect1.PrintIt("rect1.ApproxEquals(rect2)");
  1449.   CHECKRES (!(rect1.ApproxEquals(rect2)) );
  1450.  
  1451.   rect2.Clear();
  1452.   rect2.PrintIt("rect2.IsEmpty()");
  1453.   CHECKRES (rect2.IsEmpty() );
  1454.  
  1455. #ifdef _PLATFORM_OS2_
  1456.   rect1.Set(IntToFixed(20), IntToFixed(100), IntToFixed(100), IntToFixed(20));
  1457. #else
  1458.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1459. #endif
  1460.   rect1.PrintIt("rect1.Contains()");
  1461.   CHECKRES (rect1.Contains(point2) );
  1462.  
  1463. #ifdef _PLATFORM_OS2_
  1464.   rect1.Set(IntToFixed(20), IntToFixed(100), IntToFixed(100), IntToFixed(20));
  1465. #else
  1466.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1467. #endif
  1468.   rect2.Set(point1,point2);
  1469.   rect1.PrintIt("rect1.Contains()");
  1470.   CHECKRES (rect1.Contains(rect2) );
  1471.  
  1472.   rect1.PrintIt("rect1.ApproxContains()");
  1473.   CHECKRES (rect1.Contains(rect2) );
  1474.  
  1475. #ifdef _PLATFORM_OS2_
  1476.   rect2.Set(IntToFixed(20), IntToFixed(100), IntToFixed(100), IntToFixed(20));
  1477.   rect1.Set(IntToFixed(20), IntToFixed(100), IntToFixed(100), IntToFixed(20));
  1478. #else
  1479.   rect2.Set(myLeft, myTop, myRight, myBottom);
  1480.   rect1.Set(myLeft, myTop, myRight, myBottom);
  1481. #endif
  1482.   rect1.Offset(point1);
  1483.   rect1.PrintIt("rect1: testing ODRect::Intersects()");
  1484.   CHECKRES (rect1.Intersects(rect2) );
  1485.  
  1486. #ifdef _PLATFORM_WIN32_
  1487.   if(testWin)
  1488.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)"\n\nEND ODRect::SelfTest\n\n");
  1489.   else
  1490.     printf ("\n\nEND ODRect::SelfTest\n\n");
  1491. #else
  1492.   printf ("\n\nEND ODRect::SelfTest\n\n");
  1493. #endif
  1494.  
  1495. }
  1496.  
  1497. WIN32_DLLEXPORT void ODRect::PrintIt(char *msg)
  1498. {
  1499. #ifdef _PLATFORM_WIN32_
  1500.   if(!testWindow) {
  1501.     printf (myLine);
  1502.     if(msg != NULL)
  1503.       printf ("%s\n",msg);
  1504.     printf ("left is: %d\n", left);
  1505.     printf ("top is: %d\n", top);
  1506.     printf ("right is: %d\n", right);
  1507.     printf ("bottom is: %d\n", bottom);
  1508.   }
  1509.   else {
  1510.     char tmpBuff[1024];
  1511.     sprintf (tmpBuff, myLine);
  1512.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1513.     if(msg != NULL) {
  1514.       sprintf (tmpBuff, "%s\n",msg );
  1515.       SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1516.     }
  1517.     sprintf (tmpBuff, "left is: %d\n", left);
  1518.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1519.     sprintf (tmpBuff, "top is: %d\n", top);
  1520.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1521.     sprintf (tmpBuff,"right is: %d\n", right);
  1522.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1523.     sprintf (tmpBuff, "bottom is: %d\n", bottom);
  1524.     SendMessage(testWindow, LB_ADDSTRING, 0, (LONG)tmpBuff);
  1525.   }
  1526. #else
  1527.   printf (myLine);
  1528.   if(msg != NULL)
  1529.     printf ("%s\n",msg);
  1530.   printf ("left is: %d\n", left);
  1531.   printf ("top is: %d\n", top);
  1532.   printf ("right is: %d\n", right);
  1533.   printf ("bottom is: %d\n", bottom);
  1534. #endif
  1535. }
  1536.  
  1537. #endif // (_PLATFORM_WIN32_ || _PLATFORM_OS2_ || _PLATFORM_AIX_) && DEBUG
  1538.