home *** CD-ROM | disk | FTP | other *** search
- /*
- File: RealShpe.h
-
- Contains: RealShape class, private to ODShape.
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <10> 8/29/95 jpa Don't use kODErrInvalidValue. [1278284]
- <9> 5/25/95 jpa Use new GX headers [1241078, 1253324]
- <8> 2/24/95 jpa Removed private ODNewRgn. [1220810]
- <7> 12/5/94 jpa Code review cleanup [1203923]
- <6> 10/24/94 jpa Added NewGeometricShape [1195070]. Added
- ODNewRgn: allocate rgns from temp-mem.
- [1151710]
- <5> 9/29/94 RA 1189812: Mods for 68K build.
- <4> 8/2/94 jpa Added AsPolygonShape method.
- <3> 7/26/94 jpa Initialize gGX to 99, not -1 [it's
- unsigned]. Actually any value >1 will do.
- <2> 6/18/94 MB Update memory includes
- <1> 6/15/94 jpa first checked in
- --------Moved to SOM project and rearranged-----
- <9> 5/10/94 jpa Replaced 'inherited::' to appease %$#@
- cfront.
- <8> 5/9/94 MB #1162181: Changes necessary to install MMM.
- <7> 5/9/94 jpa Enable polygon clipper and GX support
- [1162090]
- <6> 3/25/94 JA Use new XMPTransform API. (1153438)
- <5> 3/15/94 MB Changes to support SCpp/ASLM builds,
- #1150864.
- <4> 2/17/94 JA Include new AltPoly.h.
- <3> 2/16/94 JA Stop using pointers to member fns. Include
- new AltPoint.h.
- <2> 2/9/94 JA ShapePrv.h --> ShapePvM.h
- <10> 2/7/94 JA Capitalized THROW.
- <9> 2/7/94 JA Further tigerings.
- <8> 2/3/94 JA Tiger Team Makeover!
- <7> 1/31/94 JA Mucho fixes to polygon shapes & region
- shapes. Other bugs squashed. Etc.
- <6> 12/3/93 TÇ Stop including XMPError.h, it is included
- as ErrorDef.h inside Except.h
- <5> 11/29/93 JA Fixed XMPRectShape::Union.
- <4> 11/24/93 JA cfront fixes.
- <3> 11/24/93 VL Rolled back changes as ASLM build breaks
- the THINK build.
- <2> 11/23/93 VL Made this work with ASLM.
- <1> 11/23/93 JA first checked in
-
- In Progress:
-
- */
-
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" /* Use C++ savvy XMPPoint and XMPRect*/
- #endif
-
- #ifndef _ALTPOLY_
- #include "AltPoly.h"
- #endif
-
-
- #ifndef _REALSHPE_
- #include "RealShpe.h"
- #endif
-
- #ifndef _GXSHPE_
- #include "GXShpe.h"
- #endif
-
- #ifndef _POLYSHPE_
- #include "PolyShpe.h"
- #endif
-
- #ifndef _RECTSHPE_
- #include "RectShpe.h"
- #endif
-
- #ifndef _RGNSHPE_
- #include "RgnShpe.h"
- #endif
-
- #ifndef _SHAPE_
- #include "Shape.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef __GXGRAPHICS__
- #include <GXGraphics.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _UTILERRS_
- #include <UtilErrs.h>
- #endif
-
-
- //==============================================================================
- // QuickDraw GX Utilities
- //==============================================================================
-
-
- ODBoolean gGX = 99; // Is GX installed? Initialized by ODShape constructor
-
-
- #pragma segment QDGXShape
-
-
- void
- ClearGXError( )
- {
- GXGetGraphicsError(kODNULL);
- // GX error status is cleared after asking for errors.
- }
-
-
- void
- ThrowIfGXError( )
- {
- gxGraphicsError err = GXGetGraphicsError(kODNULL); // Get latest graphics error
- if( err )
- THROW(err,"QuickDraw GX error");
- }
-
-
- void
- ThrowIfFirstGXError( )
- {
- gxGraphicsError err;
- (void) GXGetGraphicsError(&err); // Get first error, not last
- if( err )
- THROW(err,"QuickDraw GX error");
- }
-
-
- //==============================================================================
- // RealShape
- //==============================================================================
-
-
- #pragma segment ODShape
-
-
- RealShape::RealShape( ODGeometryMode mode )
- :fQDRegion(kODNULL),
- fMode(mode)
- {
- }
-
-
- RealShape::~RealShape( )
- {
- this->Purge(0);
- }
-
-
- ODSize
- RealShape::Purge( ODSize )
- {
- if( fQDRegion ) {
- ODSize size = GetHandleSize((Handle)fQDRegion);
- DisposeRgn(fQDRegion);
- fQDRegion = kODNULL;
- return size;
- } else
- return 0;
- }
-
-
- RealShape*
- RealShape::NewGeometricShape( ODGeometryMode mode ) //static method
- {
- if( gGX )
- return new QDGXShape(mode);
- else
- return new PolygonShape(mode);
- }
-
-
- void
- RealShape::SetGeometryMode( ODGeometryMode mode )
- {
- if( mode==kODNeedsGeometry && !this->HasGeometry() )
- THROW(kODErrNoShapeGeometry);
-
- fMode = mode;
- }
-
-
- ODGeometryMode
- RealShape::GetGeometryMode( )
- {
- return fMode;
- }
-
-
- RealShape*
- RealShape::SetPolygon( const ODPolygon &poly )
- {
- ODRect r;
- if( poly.AsRectangle(&r) )
- return this->SetRectangle(&r);
-
- else {
- RealShape *s;
- s = RealShape::NewGeometricShape(fMode);
- s = s->SetPolygon(poly);
- delete this;
- return s;
- }
- }
-
-
- void
- RealShape::Simplify( )
- {
- // Only PolygonShape does anything in this method.
- }
-
-
- ODPlatformShape
- RealShape::GetPlatformShape( ODGraphicsSystem system )
- {
- if( system==kODQuickDraw ) {
- if( !fQDRegion ) {
- fQDRegion = ODNewRgn();
- TRY{
- this->InitQDRegion();
- }CATCH_ALL{
- DisposeRgn(fQDRegion);
- fQDRegion = kODNULL;
- RERAISE;
- }ENDTRY
- }
- return fQDRegion;
-
- } else if( system==kODQuickDrawGX && gGX )
- return this->CopyGXShape();
-
- else {
- THROW(kODErrInvalidGraphicsSystem);
- return kODNULL;
- }
- }
-
-
- void
- RealShape::SetPlatformShape( ODGraphicsSystem, ODPlatformShape )
- {
- WARN("RealShape::SetPlatformShape should have been overridden by subclass!");
- THROW(kODErrInvalidGraphicsSystem);
- }
-
-
- ODBoolean
- RealShape::HasGeometry( )
- {
- return kODTrue; // ODRgnShape overrides this to return false if non-rectangular
- }
-
-
- RealShape*
- RealShape::Clear( )
- {
- // Delete me and return a new empty rect-shape:
-
- ODRect empty(0,0,0,0);
- RealShape *s = new RectShape(fMode,empty);
- delete this;
- return s;
- }
-
-
- RealShape*
- RealShape::ReplaceWith( RealShape *shape )
- {
- RealShape *s = shape->Copy();
- delete this;
- return s;
- }
-
-
- RealShape*
- RealShape::Combine( ODShapeOp op, RealShape *shape )
- {
- switch( op ) {
- case kShapeIntersection:
- return this->Intersect(shape);
- case kShapeUnion:
- return this->Union(shape);
- case kShapeDifference:
- return this->Subtract(shape);
- case kShapeNoOp:
- return this;
- #if ODDebug
- default:
- WARN("Bogus ShapeOp to Combine()");
- THROW(kODErrAssertionFailed);
- break;
- #endif
- }
- return kODNULL;
- }
-
-
- RealShape*
- RealShape::AsPolygonShape( )
- {
- RealShape *s = kODNULL; ODVolatile(s);
- ODPolygon poly; ODVolatile(poly);
-
- this->CopyPolygon(poly);
- TRY{
- s = RealShape::NewGeometricShape(fMode);
- s->SetPolygon(poly);
- }CATCH_ALL{
- delete s;
- poly.Clear();
- RERAISE;
- }ENDTRY
- poly.Clear();
-
- return s;
- }
-
-
- RealShape*
- RealShape::Promote( ODShapeOp op, RealShape *shape )
- {
- // Delete me and return an equivalent region- or polygon-shape.
- // Optionally perform a binary operation on the promoted shape.
-
- RealShape *s; ODVolatile(s);
-
- if( fMode!=kODLoseGeometry && (shape==kODNULL || shape->HasGeometry()) ) {
- s = this->AsPolygonShape();
- TRY{
- s = s->Combine(op,shape);
- }CATCH_ALL{
- delete s;
- RERAISE;
- }ENDTRY
-
- } else {
- if( fMode==kODNeedsGeometry )
- THROW(kODErrNoShapeGeometry);
-
- RgnHandle rgn = (RgnHandle) ODCopyHandle(
- (ODHandle)this->GetPlatformShape(kODQuickDraw) );
- TRY{
- s = new RgnShape(fMode);
- }CATCH_ALL{
- DisposeRgn(rgn);
- RERAISE;
- }ENDTRY
-
- TRY{
- s->SetPlatformShape(kODQuickDraw,rgn);
- s = s->Combine(op,shape);
- }CATCH_ALL{
- delete s;
- RERAISE;
- }ENDTRY
- }
-
- delete this;
- return s;
- }
-