home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 12.2 KB | 469 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWRgnShp.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWRGNSHP_H
- #include "FWRgnShp.h"
- #endif
-
- #ifndef SLGRGLOB_H
- #include "SLGrGlob.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWFXMATH_H
- #include "FWFxMath.h"
- #endif
-
- #ifndef SLRENDER_H
- #include "SLRender.h"
- #endif
-
- #ifndef SLREGION_H
- #include "SLRegion.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef FW_BUILD_WIN
- #ifndef SOM_Module_OpenDoc_Polygon_defined
- #include <Polygon.xh>
- #endif
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_RegionShape
- #endif
-
- //========================================================================================
- // class FW_CRegionShape
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CRegionShape)
- FW_DEFINE_CLASS_M1(FW_CRegionShape, FW_CShape)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::FW_CRegionShape
- //----------------------------------------------------------------------------------------
-
- FW_CRegionShape::FW_CRegionShape(ODShape* odShape,
- FW_ERenderVerbs renderVerb,
- const FW_CInk& ink,
- const FW_CStyle& style) :
- FW_CShape(renderVerb, ink, style, FW_kNormalFont),
- fODShape(odShape)
- {
- FW_ASSERT(odShape);
- FW_SOMEnvironment ev;
- fODShape->Acquire(ev);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::FW_CRegionShape
- //----------------------------------------------------------------------------------------
-
- FW_CRegionShape::FW_CRegionShape(const FW_CRegionShape& other) :
- FW_CShape(other),
- fODShape(NULL)
- {
- if (other.fODShape != NULL)
- {
- FW_SOMEnvironment ev;
- fODShape = other.fODShape->Copy(ev);
- }
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::FW_CRegionShape
- //----------------------------------------------------------------------------------------
-
- FW_CRegionShape::FW_CRegionShape(FW_CReadableStream& stream) :
- FW_CShape(stream),
- fODShape(NULL)
- {
- #ifndef FW_BUILD_WIN
- unsigned long dataSize;
- stream >> dataSize;
- if (dataSize != 0)
- {
- ODPolygon* polygon = (ODPolygon*)::operator new(dataSize);
- stream.Read((char*)polygon, dataSize);
-
- FW_SOMEnvironment ev;
- // [B1 Conversion] Should diseapear when region shape doesn't use ODShape
- fODShape = new ODShape;
- fODShape->InitShape(ev);
- fODShape->SetPolygon(ev, polygon);
- }
- #else
- FW_DEBUG_MESSAGE("Not Yet Implemented");
- #endif
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::~FW_CRegionShape
- //----------------------------------------------------------------------------------------
-
- FW_CRegionShape::~FW_CRegionShape()
- {
- FW_START_DESTRUCTOR
- FW_SOMEnvironment ev;
- DisposeODShape(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CRegionShape& FW_CRegionShape::operator=(const FW_CRegionShape& other)
- {
- if (this != &other)
- {
- FW_CShape::operator=(other);
-
- FW_SOMEnvironment ev;
- DisposeODShape(ev);
- fODShape = other.fODShape->Copy(ev);
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::Render(FW_CGraphicContext& gc) const
- {
- FW_ASSERT(fODShape != NULL);
-
- FW_PrivRenderRegion(gc.GetEnvironment(),
- gc,
- fODShape,
- GetRenderVerb(),
- fInk,
- fStyle);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::RenderRegion(FW_CGraphicContext& gc,
- ODShape* odShape,
- FW_ERenderVerbs renderVerb,
- const FW_CInk& ink,
- const FW_CStyle& style)
- {
- FW_ASSERT(odShape != NULL);
-
- FW_PrivRenderRegion(gc.GetEnvironment(),
- gc,
- odShape,
- renderVerb,
- ink,
- style);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::AdoptODShape
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::AdoptODShape(ODShape* odShape)
- {
- FW_ASSERT(odShape != NULL);
-
- FW_SOMEnvironment ev;
- DisposeODShape(ev);
- fODShape = odShape;
- fODShape->Acquire(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::OrphanODShape
- //----------------------------------------------------------------------------------------
- // Caller will be responsible for releasing the shape
-
- ODShape* FW_CRegionShape::OrphanODShape()
- {
- ODShape* odTempShape = fODShape;
- fODShape = NULL;
- return odTempShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::SetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::SetGeometry(ODShape* odShape)
- {
- FW_SOMEnvironment ev;
- DisposeODShape(ev);
- fODShape = odShape->Copy(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::DisposeODShape
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::DisposeODShape(Environment* ev)
- {
- if (fODShape != NULL)
- {
- fODShape->Release(ev);
- fODShape = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CRegionShape::HitTest(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_Fixed tolerance) const
- {
- FW_ASSERT(fODShape != NULL);
-
- FW_Boolean isInside = FALSE;
-
- if (fRenderVerb != FW_kNoRendering)
- {
- Environment* ev = gc.fEnvironment;
-
- ODRgnHandle rgn = ::FW_GetShapeRegion(ev, fODShape);
-
- FW_CRect testRect(test.x - tolerance, test.y - tolerance,
- test.x + tolerance, test.y + tolerance);
-
- if (::FW_RectInRegion(rgn, testRect))
- {
- isInside = TRUE;
- if (fRenderVerb == FW_kFrame)
- {
- FW_CAcquiredODShape insideShape = fODShape->Copy(ev);
- ::FW_OutlineODShape(ev, insideShape, GetPenSize());
-
- ODRgnHandle insideRgn = ::FW_GetShapeRegion(ev, insideShape);
-
- isInside = !::FW_RectInRegion(insideRgn, testRect);
- }
- }
- }
-
- return isInside;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CRegionShape::Copy() const
- {
- return FW_NEW(FW_CRegionShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::Flatten(FW_CWritableStream& stream) const
- {
- FW_CShape::Flatten(stream);
-
- if (fODShape != NULL)
- {
- #ifdef FW_BUILD_MAC
- FW_SOMEnvironment ev;
-
- ODPolygon* polygon = new ODPolygon;
- fODShape->CopyPolygon(ev, polygon);
-
- ODSLong nContours = polygon->GetNContours();
- unsigned long dataSize = sizeof(ODSLong) + nContours * sizeof(ODSLong);
-
- ODContour *c = polygon->FirstContour();
- for (ODSLong i = nContours; i>0; i-- )
- {
- dataSize += c->nVertices * sizeof(ODPoint);
- c = (ODContour*)&c->vertex[c->nVertices]; // give the next contour
- }
-
- FW_TRY
- {
- stream << dataSize;
- stream.Write((char*)polygon, dataSize);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete polygon;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- delete polygon;
- #else
- FW_UNUSED(stream);
- FW_DEBUG_MESSAGE("Not Yet Implemented");
- #endif
- }
- else
- {
- unsigned long dataSize = 0;
- stream << dataSize;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::GetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
- {
- FW_UNUSED(gc);
-
- FW_ASSERT(fODShape != NULL);
- fODShape->GetBoundingBox(gc.fEnvironment, rect);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::GetAnchorPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CRegionShape::GetAnchorPoint() const
- {
- FW_ASSERT(fODShape != NULL);
-
- FW_SOMEnvironment ev;
- FW_CRect rect;
- fODShape->GetBoundingBox(ev, rect);
-
- return rect.TopLeft();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::Transform(Environment* ev, ODTransform* odTransform)
- {
- FW_ASSERT(fODShape != NULL);
- fODShape->Transform(ev, odTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::InverseTransform(Environment* ev, ODTransform* odTransform)
- {
- FW_ASSERT(fODShape != NULL);
- fODShape->InverseTransform(ev, odTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
- {
- FW_ASSERT(fODShape != NULL);
-
- FW_SOMEnvironment ev;
-
- ODTransform* odTransform = ::FW_NewODTransform(ev, FW_CPoint(deltaX, deltaY));
- fODShape->Transform(ev, odTransform);
- odTransform->Release(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::MoveShapeTo
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
- {
- FW_ASSERT(fODShape != NULL);
-
- FW_SOMEnvironment ev;
-
- FW_CRect box;
- fODShape->GetBoundingBox(ev, (ODRect*) &box);
- MoveShape(x - box.left, y - box.top);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRegionShape::Inset
- //----------------------------------------------------------------------------------------
-
- void FW_CRegionShape::Inset(FW_Fixed x, FW_Fixed y)
- {
- FW_ASSERT(fODShape != NULL);
-
- FW_SOMEnvironment ev;
-
- ODRgnHandle plfmRgn = ::FW_CopyRegion(::FW_GetShapeRegion(ev, fODShape));
-
- ::FW_InsetRegion(plfmRgn, x, y);
-
- ::FW_SetShapeRegion(ev, fODShape, plfmRgn);
- ::FW_DisposeRegion(plfmRgn);
- }
-
-