home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / utils / AltPoly.h < prev    next >
C/C++ Source or Header  |  1997-04-02  |  12KB  |  367 lines

  1. /* @(#)Z 1.21 com/src/pubutils/include/AltPoly.h, odpubutils, od96os2, odos29712d 97/03/21 17:21:38 (97/03/14 16:57:56) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odpubutils
  6.  *
  7.  *   CLASSES:   ODPolygon
  8.  *        ODTempPolygon
  9.  *        ODTempPolygonPtr
  10.  *        PolyEdgeIterator
  11.  *        TempGXShape
  12.  *
  13.  *   ORIGINS: 82,27,94
  14.  *
  15.  *
  16.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  17.  *   All Rights Reserved
  18.  *   Licensed Materials - Property of IBM
  19.  *   US Government Users Restricted Rights - Use, duplication or
  20.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  21.  *       
  22.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  23.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  25.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  26.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  27.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  28.  *   OR PERFORMANCE OF THIS SOFTWARE.
  29.  */
  30. /*====END_GENERATED_PROLOG========================================
  31.  */
  32.  
  33. /*
  34.     File:        AltPoly.h
  35.  
  36.     Contains:    OpenDoc polygon: optional C++ savvy classes
  37.  
  38.     Owned by:    Jens Alfke
  39.  
  40.     Copyright:    (C) 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  41.  
  42.     
  43.     
  44.     
  45.     Theory of Operation:
  46.     
  47.         This is an alternate definition of ODPolygon and ODContour. The data format is
  48.         identical, but the structs defined here have a lot of useful methods including
  49.         constructors, accessors and conversion operators.
  50.         
  51.         To use these instead of the regular structs defined in Polygon.h, just include
  52.         this header file _before_ Polygon.h. An easy way to do this is to include it
  53.         first.
  54.         
  55.         QuickDraw GX users take note:
  56.         ODContour is identical in data format to a gxPolygon.
  57.         ODPolygonData (the data stored inside an ODPolygon) is identical in data
  58.             format to a gxPolygons <sic>.
  59.         See <GXTypes.h>.
  60.     
  61.         ** The way things are done has changed since A6. SOM wants all variable-sized
  62.         structures to adhere to a common data forma, where a small struct points to
  63.         the data and stores its size. This is so DSOM can tell how to copy the data
  64.         across an address-space boundary. The ODPolygon structure has most of the same
  65.         methods as before, but you can now create them directly. However, to get the
  66.         actual polygon data you'll need to call the GetData method. **
  67.     
  68.     In Progress:
  69.         
  70. */
  71.  
  72.  
  73. #ifndef _ALTPOLY_
  74. #define _ALTPOLY_
  75.  
  76. #ifdef SOM_Module_OpenDoc_Polygon_defined
  77.     #error "Must include AltPoly.h *before* Polygon.xh!"
  78. #else
  79.     /* Make sure Polygon.xh does NOT get included later! */
  80.     #define SOM_Module_OpenDoc_Polygon_defined 2
  81. #endif
  82.  
  83. #ifndef _ODTYPES_
  84. #include "ODTypes.h"
  85. #endif
  86.  
  87. #ifndef _ODEXCEPT_
  88. #include <ODExcept.h>                    /* For Destructo, used by ODTempPolygon */
  89. #endif
  90.  
  91. #include <stddef.h>                    /* for size_t */
  92.  
  93. #if _PLATFORM_MACINTOSH_
  94.     #ifndef __QUICKDRAW__
  95.     #include <QuickDraw.h>                /* for Region and Polygon types */
  96.     #endif
  97.     #ifndef __FIXMATH__
  98.     #include <FixMath.h>                /* Must include before GX headers... */
  99.     #endif
  100.     #ifndef __GXTYPES__
  101.     #include <GXTypes.h>                /* for gxShape type */
  102.     #endif
  103. #endif
  104.  
  105. #if _PLATFORM_OS2_
  106. #ifndef _ODOS2_
  107. #include "ODos2.h"
  108. #endif
  109. typedef struct _POLYGON POLYGON;    // defined in pmgpi.h
  110. #endif // _PLATFORM_OS2_
  111.  
  112. #ifndef _ODMVCLNK_
  113. #include <ODMvcLnk.h>
  114. #endif
  115.  
  116.  
  117. //==============================================================================
  118. // Classes used in this interface
  119. //==============================================================================
  120.  
  121. struct ODRect;
  122. class ODStorageUnit;
  123. class ODTransform;
  124.  
  125. //==============================================================================
  126. // ODContour
  127. //==============================================================================
  128.  
  129. struct ODContour
  130. {
  131.     public:
  132.     
  133.     ODSLong    nVertices;
  134.     ODPoint    vertex[1];        // Array size is actually nVertices
  135. #ifdef OD_BUG // 21439
  136.     _DLLIMPORTEXPORT_ ODContour* NextContourEx(const ODSLong& );
  137. #endif
  138.     ODContour* NextContour( )                const    {return (ODContour*)&vertex[nVertices];}
  139.     _DLLIMPORTEXPORT_ ODBoolean    IsRectangular( )            const;
  140.     _DLLIMPORTEXPORT_ ODBoolean    AsRectangle( ODRect* )        const;
  141.     _DLLIMPORTEXPORT_ ODBoolean    HasExactRegion( )            const;
  142. #if _PLATFORM_MACINTOSH_
  143.     PolyHandle    AsQDPolygon( )                const;
  144. #endif
  145. #if _PLATFORM_WIN32_
  146.     _DLLIMPORTEXPORT_ Point *AsWinPolygon ( )  const;
  147. #endif
  148. #if _PLATFORM_OS2_
  149.         void AsPOLYGON(POLYGON&) const;
  150. #endif    
  151. #ifdef  _PLATFORM_AIX_
  152.     Point *AsXPolygon ( )  const;
  153. #endif
  154.     
  155.     _DLLIMPORTEXPORT_ ODBoolean    operator== ( const ODContour& )            const;
  156.     ODBoolean    operator!= ( const ODContour &c )        const    {return !(*this==c);}
  157. };
  158.  
  159. //==============================================================================
  160. // ODPolygonData
  161. //==============================================================================
  162.  
  163. struct ODPolygonData {
  164.     ODSLong    nContours;                        // Number of contours
  165.     ODContour    firstContour;                // Rest of contours follow after first
  166. };
  167.  
  168. //==============================================================================
  169. // ODPolygon
  170. //==============================================================================
  171.  
  172. class ODPolygon
  173. {
  174.     public:
  175.     
  176.                     _DLLIMPORTEXPORT_ ODPolygon( );
  177. #ifdef _PLATFORM_OS2_
  178. // note: the orig os/2 port had a note about the ODPolygon dtor.  They
  179. // actually have it commented out. (Rob)
  180. #endif
  181. #if ODDebug
  182.                    ~ODPolygon( );        // Delete myself, but not data
  183. #endif
  184.     
  185.     _DLLIMPORTEXPORT_ void            Delete( );            // Delete myself & my data
  186.     _DLLIMPORTEXPORT_ void            Clear( );            // Just deletes my data
  187.     
  188.     // ACCESSORS:
  189.     
  190.     ODBoolean        HasData( )                        const    {return _length!=0;}
  191.     ODULong            GetDataSize( )                    const    {return _length;}
  192.     ODPolygonData*    GetData( )                        const    {return _buf;}
  193.     
  194.     _DLLIMPORTEXPORT_ void            SetData( const ODPolygonData* );    // Does not copy the data!
  195.     
  196.     _DLLIMPORTEXPORT_ ODSLong            GetNContours( )                    const;
  197.     _DLLIMPORTEXPORT_ ODContour*        FirstContour( );
  198.     _DLLIMPORTEXPORT_ const ODContour*FirstContour( )                    const;
  199.     
  200.     // GEOMETRY:
  201.     
  202.     _DLLIMPORTEXPORT_ void        ComputeBoundingBox( ODRect* )        const;
  203.     _DLLIMPORTEXPORT_ ODBoolean    IsRectangular( )                    const;
  204.     _DLLIMPORTEXPORT_ void        Transform( Environment*, ODTransform* );
  205.     
  206.     _DLLIMPORTEXPORT_ ODBoolean    operator== ( ODPolygon& )            const;
  207.     ODBoolean    operator!= ( ODPolygon& p )            const    {return !(*this==p);}
  208.     
  209.     _DLLIMPORTEXPORT_ ODSLong    Contains( ODPoint )                        const;
  210.     _DLLIMPORTEXPORT_ ODBoolean    IsEmpty( )                            const;
  211.     
  212.     // CONVERSIONS:
  213.     
  214.     _DLLIMPORTEXPORT_ ODBoolean    AsRectangle( ODRect* )                const;    // False if nonrectangular
  215.     _DLLIMPORTEXPORT_ ODBoolean    HasExactRegion( )                    const;
  216. #if _PLATFORM_MACINTOSH_
  217.     RgnHandle    AsQDRegion( )                        const;
  218.     gxShape        AsGXShape( )                        const;
  219. #endif
  220. #if _PLATFORM_WIN32_
  221.     _DLLIMPORTEXPORT_ ODRgnHandle    AsWinRegion( )                        const;
  222. #endif
  223. #if _PLATFORM_OS2_
  224.         HRGN AsRegion(HPS hps) const;
  225. #endif
  226. #ifdef _PLATFORM_AIX_
  227.         Region AsXRegion( ) const;
  228. #endif
  229. #if ((defined (_PLATFORM_WIN32_) || defined (_PLATFORM_OS2_)) \
  230.       || defined (_PLATFORM_AIX_) ) && defined(DEBUG)
  231.         _DLLIMPORTEXPORT_ void            SelfTest();  // test myself! 
  232.         _DLLIMPORTEXPORT_ void    PrintIt(char *msg = NULL); 
  233. #endif // (defined (_PLATFORM_WIN32_) || _OS2_ || _AIX_) && defined(DEBUG)
  234.     
  235.     // ALLOCATION:
  236.     
  237.     _DLLIMPORTEXPORT_ ODPolygon*    SetNVertices( ODSLong nVertices );
  238.     _DLLIMPORTEXPORT_ ODPolygon*    SetVertices( ODSLong nVertices, const ODPoint *vertices );
  239.     _DLLIMPORTEXPORT_ ODPolygon*    SetContours( ODSLong nContours, const ODSLong *contourVertices );
  240.     _DLLIMPORTEXPORT_ ODPolygon*    SetRect( const ODRect& );
  241.  
  242.     _DLLIMPORTEXPORT_ ODPolygon*    Copy( )                                const;
  243.     _DLLIMPORTEXPORT_ ODPolygon*    CopyFrom( const ODPolygon& );
  244. #if _PLATFORM_MACINTOSH_
  245.     ODPolygon*    CopyFrom( gxShape );        // Accepts rect, polygon(s), path(s)
  246. #endif
  247.     _DLLIMPORTEXPORT_ ODPolygon*    MoveFrom( ODPolygon& );        // Justs adjusts pointers, no copying
  248.     
  249.     // INPUT/OUTPUT:
  250.     
  251.     _DLLIMPORTEXPORT_ ODPolygon*    ReadFrom( Environment*, ODStorageUnit* );
  252.     _DLLIMPORTEXPORT_ ODPolygon*    WriteTo( Environment*, ODStorageUnit* )        const;
  253.     
  254.     private:
  255.     
  256.     void        Realloc( ODULong dataSize );
  257.     
  258.     // DATA MEMBERS:
  259.     
  260.     unsigned long _maximum;                        // Exact same data as an ODByteArray
  261.     unsigned long _length;
  262.     ODPolygonData *_buf;
  263. };
  264.  
  265.  
  266. //==============================================================================
  267. // ODTempPolygon
  268. //==============================================================================
  269.  
  270. /*    ODTempPolygon is a polygon whose destructor disposes of its data.
  271.     This is useful if you have a local variable that's a temporary polygon
  272.     and you want to make sure the data gets disposed.
  273.     This _is_ exception-safe: inheriting from Destructo guarantees that the
  274.     data will be cleaned up even if an exception is thrown.
  275. */
  276.  
  277. #if defined (_PLATFORM_WIN32_) ||  defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  278. // There is a slight problem here inheriting from Destructo since
  279. // we are compiling with _NATIVE_EXCEPTIONS_ defined.  The     
  280. // Destructo class is defined differently in this case (struct). (rob)
  281. class ODTempPolygon :public ODPolygon
  282. #else
  283. class ODTempPolygon :public ODPolygon, Destructo
  284. #endif // defined (_PLATFORM_WIN32_) ||  defined(_PLATFORM_OS2_)
  285. {
  286. public:
  287.     _DLLIMPORTEXPORT_ ODTempPolygon( );
  288.    _DLLIMPORTEXPORT_ ~ODTempPolygon( );
  289. };
  290.  
  291.  
  292. /*    ODTempPolygonPtr is a _pointer_ to a polygon, whose destructor deletes
  293.     the polygon structure (and its data.) Yes, it is a class, but due to the
  294.     magic of operator overloading it can be used just as a pointer. See the
  295.     implementation of ODPolygon::Copy in AltPoly.cpp for an example. */
  296.  
  297. #if defined (_PLATFORM_WIN32_) ||  defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  298. // There is a slight problem here inheriting from Destructo since
  299. // we are compiling with _NATIVE_EXCEPTIONS_ defined.  The     
  300. // Destructo class is defined differently in this case (struct). (rob)
  301. class ODTempPolygonPtr
  302. #else
  303. class ODTempPolygonPtr :Destructo
  304. #endif //  _PLATFORM_WIN32_
  305. {
  306. public:
  307.     _DLLIMPORTEXPORT_ ODTempPolygonPtr( );
  308.     _DLLIMPORTEXPORT_ ODTempPolygonPtr( ODPolygon* );
  309.     _DLLIMPORTEXPORT_ ~ODTempPolygonPtr( );
  310.     operator ODPolygon* ( )                    {return fPoly;}
  311.     ODPolygon* operator-> ( )                {return fPoly;}
  312.     ODPolygon* operator= ( ODPolygon *p )    {return (fPoly=p);}
  313.     ODPolygon* DontDelete( )                {ODPolygon* temp=fPoly; fPoly=kODNULL; return temp;}
  314.     
  315. private:
  316.     ODPolygon *fPoly;
  317. };
  318.  
  319.  
  320. /*    TempGXShape is a temporary reference to a gxShape. It will be released when
  321.     the reference goes out of scope. For an example, see the implementation of
  322.     ODPolygon::CopyFrom( gxShape ). */
  323.  
  324. #if !defined (_PLATFORM_WIN32_) &&  !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_AIX_)
  325. class TempGXShape :Destructo
  326. {
  327. public:
  328.     TempGXShape( );
  329.     TempGXShape( gxShape );
  330.     ~TempGXShape( );
  331.     operator gxShape ( )                {return fShape;}
  332.     gxShape operator= ( gxShape s )        {return (fShape=s);}
  333.     gxShape DontRelease( )                {gxShape temp=fShape; fShape=kODNULL; return temp;}
  334.     
  335. private:
  336.     gxShape fShape;
  337. };
  338. #endif // _PLATFORM_WIN32_
  339.  
  340.  
  341. //==============================================================================
  342. // Polygon Edge Iterator
  343. //==============================================================================
  344.  
  345. class PolyEdgeIterator {
  346.     public:
  347.  
  348.     _DLLIMPORTEXPORT_ PolyEdgeIterator( const ODPolygon* );
  349.     
  350.     _DLLIMPORTEXPORT_ void        CurrentEdge( const ODPoint* &v1, const ODPoint* &v2 );
  351.     const ODContour* CurrentContour( )            {return fCurContour;}
  352.     long        CurrentContourIndex( )            {return fCurContourIndex;}
  353.     long        CurrentEdgeIndex( )                {return fCurVertex;}
  354.     
  355.     _DLLIMPORTEXPORT_ ODBoolean    Next( );
  356.     _DLLIMPORTEXPORT_ ODBoolean    IsNotComplete( );
  357.     
  358.     private:
  359.     const ODPolygon*    const fPoly;
  360.     const ODContour*          fCurContour;
  361.     long                      fCurContourIndex;
  362.     long                      fCurVertex;
  363. };
  364.  
  365.  
  366. #endif //_ALTPOLY_
  367.