home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / ALTPOINT.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  11KB  |  323 lines

  1. /* @(#)Z 1.20 com/src/pubutils/include/AltPoint.h, odpubutils, od96os2, odos29646d 96/11/15 15:29:11 (96/10/30 09:23:22) */
  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.h
  31.  
  32.     Contains:    C++ savvy points and rects (alternate ODPoint, ODRect)
  33.  
  34.     Owned by:    Jens Alfke
  35.  
  36.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  37.     
  38.     Notes:
  39.     
  40.     These are alternate definitions of the ODPoint and ODRect structs.
  41.     These definitions have the same size and data format and can be used
  42.     interchangeably with the basic definitions; but they're much more C++
  43.     savvy, with constructors, operators, conversions, and utility methods.
  44.     
  45.     To use these classes instead of the defaults, just include "AltPoint.h"
  46.     as the first thing in your source file. It has to be included first so
  47.     it can override the default struct definitions in PlfmType.h.
  48.     
  49.     This API and implementation are **NOT** an official part of the OpenDoc
  50.     API, just handy utilities for C++ programmers.
  51.     
  52. */
  53.  
  54.  
  55. #ifndef _ALTPOINT_
  56. #define _ALTPOINT_
  57.  
  58. // Make sure that built-in structs do not get defined by PlfmType.h.
  59. #if !defined(SOM_Module_OpenDoc_GeoTypes_defined)
  60.     #define SOM_Module_OpenDoc_GeoTypes_defined
  61. #else
  62.     #error "Must include AltPoint.h *before* ODTypes.h!"
  63. #endif
  64.  
  65.  
  66. #ifndef _ODTYPESF_
  67. #include "ODTypesF.h"        // Must include before ODTypesM.xh
  68. #endif
  69.  
  70. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  71. #include "ODTypesB.xh"        
  72. #endif
  73.  
  74. #ifdef _PLATFORM_MACINTOSH_
  75. #ifndef __TYPES__
  76. #include <Types.h>
  77. #endif
  78. #endif
  79.  
  80. #ifdef _PLATFORM_OS2_
  81. #ifndef __OS2DEF__
  82. #include <os2def.h>
  83. #endif
  84. #endif // _PLATFORM_OS2_
  85.  
  86. #ifndef _ODMVCLNK_
  87. #include <ODMvcLnk.h>
  88. #endif
  89.  
  90.  
  91. //==============================================================================
  92. // ODCoordinate
  93. //==============================================================================
  94.  
  95. typedef ODFixed ODCoordinate;
  96.  
  97. //==============================================================================
  98. // ODPoint
  99. //==============================================================================
  100.  
  101. struct ODPoint {
  102.     public:
  103.     
  104.     // CONTENTS:
  105.     
  106.     ODCoordinate x, y;
  107.     
  108.     // CONSTRUCTORS:
  109.     
  110.     ODPoint( ) { }
  111.     
  112.     ODPoint( ODCoordinate xx, ODCoordinate yy )
  113.                     {x=xx; y=yy;}
  114.     
  115.     _DLLIMPORTEXPORT_ ODPoint( const ODPoint& );                // Copy constructor
  116.     
  117.     // ASSIGNMENT:
  118.     
  119.     _DLLIMPORTEXPORT_ ODPoint& operator= ( const ODPoint& );    // Copy from another pt
  120.     
  121.     // MODIFICATION:
  122.     
  123.     inline void    Clear( )
  124.                     {x=y=0;}
  125.     inline void    Set( ODCoordinate xx, ODCoordinate yy )
  126.                     {x=xx; y=yy;}
  127.     _DLLIMPORTEXPORT_ void    Offset( ODCoordinate x, ODCoordinate y );
  128.     _DLLIMPORTEXPORT_ void    operator+=( const ODPoint& );
  129.     _DLLIMPORTEXPORT_ void    operator-=( const ODPoint& );
  130.     
  131.     // ACCESSORS:
  132.  
  133.     _DLLIMPORTEXPORT_ ODSShort    IntX( )        const;        // Returns X-coord as (16bit) integer
  134.     _DLLIMPORTEXPORT_ ODSShort    IntY( )        const;        // Returns Y-coord as (16bit) integer
  135.     
  136.     // COMPARISON:
  137.     
  138.     _DLLIMPORTEXPORT_ ODBoolean    operator==( const ODPoint& )    const;
  139.     _DLLIMPORTEXPORT_ ODBoolean    operator!=( const ODPoint& )    const;
  140.     _DLLIMPORTEXPORT_ ODBoolean    ApproxEquals( const ODPoint& )    const;        // to within roundoff error
  141.     
  142.     // MAC TOOLBOX CONVENIENCES:
  143.     
  144. #ifdef _PLATFORM_MACINTOSH_
  145.     ODPoint( Point );                            // Construct from QD point
  146.     ODPoint& operator= ( const Point& );        // Copy from a QD Point
  147.     Point    AsQDPoint( )                    const;    // Convert to integer (QD) point
  148.     void    operator+=( const    Point& );            // Add/subtract QD point
  149.     void    operator-=( const    Point& );
  150. #endif
  151.  
  152. #ifdef _PLATFORM_WIN32_
  153.         _DLLCTIMPORTEXPORT_ ODPoint( Point );
  154.     _DLLIMPORTEXPORT_ ODPoint& operator= ( const Point& );
  155.     _DLLIMPORTEXPORT_ Point    AsWinPoint( ) const;
  156.     _DLLIMPORTEXPORT_ void    operator+=( const    Point& );
  157.     _DLLIMPORTEXPORT_ void    operator-=( const    Point& );
  158. #endif // _PLATFORM_WIN32_
  159.  
  160. #ifdef _PLATFORM_OS2_
  161.        ODPoint( POINTL ptl);                       // Construct from GPI POINTL
  162.        ODPoint& operator= ( const POINTL& ptl);    // Copy from a GPI POINTL
  163.        POINTL  AsPOINTL( )          const;         // Convert to integer POINTL
  164.        void  operator+=( const    POINTL& ptl);    // Add/subtract POINTL
  165.        void  operator-=( const    POINTL& ptl);
  166. #endif // _PLATFORM_OS2_
  167.  
  168. #ifdef _PLATFORM_AIX_
  169.         ODPoint( Point );
  170.     ODPoint& operator= ( const Point& );
  171.     Point    AsXPoint( ) const;
  172.     void    operator+=( const    Point& );
  173.     void    operator-=( const    Point& );
  174. #endif // _PLATFORM_AIX_
  175.  
  176. #if ((defined (_PLATFORM_WIN32_) || defined (_PLATFORM_OS2_)) \
  177.       || defined (_PLATFORM_AIX_) ) && defined(DEBUG)
  178.         _DLLIMPORTEXPORT_ void    SelfTest(HWND testWin = NULL);  // a quick unit test
  179.         // PrintIt will print the x,y points and a text msg if you
  180.         // want to send one.
  181.         _DLLIMPORTEXPORT_ void    PrintIt(char *msg = NULL); 
  182. #endif //((_PLATFORM_WIN32_) || (_PLATFORM_OS2_) || (_PLATFORM_AIX_)) && (DEBUG)
  183. };
  184.  
  185.  
  186. //==============================================================================
  187. // ODRect
  188. //==============================================================================
  189.  
  190. struct ODRect {
  191.     public:
  192.     
  193.     // CONTENTS:
  194.     
  195.     ODCoordinate left, top, right, bottom;
  196.         
  197.     // CONSTRUCTORS:
  198.     
  199.     ODRect( )        { }
  200.     ODRect( ODCoordinate l, ODCoordinate t,
  201.                   ODCoordinate r, ODCoordinate b )
  202.             {left=l; top=t; right=r; bottom=b; }
  203.     _DLLIMPORTEXPORT_ ODRect( const ODPoint&, const ODPoint& );    // Any 2 opposite pts
  204. #ifdef _PLATFORM_OS2_
  205.     ODRect( const ODPoint &bottomLeft, ODCoordinate width, ODCoordinate height );
  206. #else
  207.     _DLLIMPORTEXPORT_ ODRect( const ODPoint &topLeft, ODCoordinate width, ODCoordinate height );
  208. #endif
  209. #if ((defined (_PLATFORM_MACINTOSH_) || defined(_PLATFORM_WIN32_)) \
  210.       || defined(_PLATFORM_AIX_) )
  211.     _DLLIMPORTEXPORT_ ODRect( const Rect& );
  212. #endif
  213. #ifdef _PLATFORM_OS2_
  214.     _DLLIMPORTEXPORT_ ODRect( const RECTL& );
  215. #endif
  216.     
  217.     // ASSIGNMENT:
  218.     
  219. #if ( (defined (_PLATFORM_MACINTOSH_) || defined(_PLATFORM_WIN32_)) \
  220.       || defined(_PLATFORM_AIX_) )
  221.     _DLLIMPORTEXPORT_ ODRect& operator= ( const Rect& );
  222. #endif
  223.  
  224. #ifdef _PLATFORM_OS2_
  225.     ODRect& operator= ( const RECTL& );
  226. #endif
  227.  
  228.     
  229.     // MODIFICATION:
  230.     
  231.     _DLLIMPORTEXPORT_ void    Clear( );
  232.     _DLLIMPORTEXPORT_ void    Set( ODCoordinate l, ODCoordinate t, ODCoordinate r, ODCoordinate b );
  233.     _DLLIMPORTEXPORT_ void    Set( const ODPoint&, ODCoordinate width, ODCoordinate height );
  234.     _DLLIMPORTEXPORT_ void    Set( const ODPoint&, const ODPoint& );    // Any 2 opposite pts
  235.     _DLLIMPORTEXPORT_ void    SetInt( short l, short t, short r, short b );
  236.     _DLLIMPORTEXPORT_ void    Offset( ODCoordinate x, ODCoordinate y );
  237.     _DLLIMPORTEXPORT_ void    Offset( const ODPoint& );
  238.     _DLLIMPORTEXPORT_ void    Inset( ODCoordinate x, ODCoordinate y );
  239.     
  240.     _DLLIMPORTEXPORT_ void    operator&= ( const ODRect& );    // Intersect with rectangle
  241.     _DLLIMPORTEXPORT_ void    operator|= ( const ODRect& );    // Union with rectangle
  242.     _DLLIMPORTEXPORT_ void    operator|= ( const ODPoint& );        // Expand to fit point
  243.         
  244.     // ACCESSORS
  245.     
  246.     const ODPoint& TopLeft( )                                        const
  247.                                 {return *(ODPoint*)&left;}
  248.     ODPoint&        TopLeft( )
  249.                                 {return *(ODPoint*)&left;}
  250.     const ODPoint& BotRight( )                                        const
  251.                                 {return *(ODPoint*)&right;}
  252.     ODPoint&        BotRight( )
  253.                                 {return *(ODPoint*)&right;}
  254.     ODCoordinate    Width( )                                        const
  255.                                 {return right-left;}
  256.     ODCoordinate    Height( )                                        const
  257. #ifdef _PLATFORM_OS2_
  258.                                 {return top-bottom;}
  259. #else
  260.                                 {return bottom-top;}
  261. #endif // _PLATFORM_OS2_
  262. #ifdef _PLATFORM_MACINTOSH_
  263.     void            AsQDRect( Rect& )                                const;
  264. #endif
  265. #ifdef _PLATFORM_WIN32_
  266.     _DLLIMPORTEXPORT_ void            AsWinRect( Rect& )                                const;
  267. #endif
  268. #ifdef _PLATFORM_OS2_
  269.     void            AsRECTL( RECTL& )                                const;
  270. #endif
  271. #ifdef _PLATFORM_AIX_
  272.     void            AsXRect( Rect& )                                const;
  273. #endif
  274.     
  275.     // TESTING
  276.  
  277.     _DLLIMPORTEXPORT_ ODBoolean    operator==( const ODRect& )                            const;
  278.     ODBoolean    operator!=( const ODRect &r )                        const
  279.                                 {return !(*this==r);}
  280.     _DLLIMPORTEXPORT_ ODBoolean    ApproxEquals( const ODRect &r )                        const;
  281.     
  282.     _DLLIMPORTEXPORT_ ODBoolean    IsEmpty( )                                            const;
  283.     _DLLIMPORTEXPORT_ ODBoolean    Contains( const ODPoint& )                            const;
  284.     _DLLIMPORTEXPORT_ ODBoolean    Contains( const ODRect& )                            const;
  285.     _DLLIMPORTEXPORT_ ODBoolean    ApproxContains( const ODRect& )                        const;
  286.     _DLLIMPORTEXPORT_ ODBoolean    Intersects( const ODRect& )                            const;
  287.  
  288. #if ((defined (_PLATFORM_WIN32_) || defined (_PLATFORM_OS2_)) \
  289.       || defined (_PLATFORM_AIX_) ) && defined(DEBUG)
  290.         _DLLIMPORTEXPORT_ void    SelfTest(HWND testWin = NULL);  // a quick unit test
  291.         // PrintIt will print the rect points and a text msg if you
  292.         // want to send one.
  293.         _DLLIMPORTEXPORT_ void    PrintIt(char *msg = NULL); 
  294. #endif //((_PLATFORM_WIN32_) || (_PLATFORM_OS2_) || (_PLATFORM_AIX_)) && (DEBUG)
  295. };
  296.  
  297. #if ( (defined (_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)) \
  298.       || defined (_PLATFORM_AIX_) ) 
  299. struct ODToolSpaceRect {
  300. public:
  301.        ODCoordinate    left;
  302.        ODCoordinate    top;
  303.        ODCoordinate    right;
  304.        ODCoordinate    bottom;
  305.        ODRect          floatRect;
  306.  
  307.        ODToolSpaceRect( )              { }
  308.  
  309.        _DLLIMPORTEXPORT_ ODToolSpaceRect(ODCoordinate l, ODCoordinate t,
  310.                        ODCoordinate r, ODCoordinate b, ODRect* aFloatRect);
  311.  
  312.        _DLLIMPORTEXPORT_ ODBoolean IsEmpty() const;
  313.  
  314.        _DLLIMPORTEXPORT_ void Set(ODCoordinate l, ODCoordinate t,
  315.                 ODCoordinate r, ODCoordinate b, ODRect* aFloatRect);
  316.  
  317.        _DLLIMPORTEXPORT_ void Clear(void);
  318. };
  319. #endif // _PLATFORM_WIN32_ || _PLATFORM_OS2_ || _PLATFORM_AIX_
  320.  
  321.  
  322. #endif //_ALTPOINT_
  323.