home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 10.4 KB | 317 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWShLiSh.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWSHLISH_H
- #include "FWShLiSh.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_ShapeListShape
- #endif
-
- //========================================================================================
- // class FW_CShapeListShape
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CShapeListShape)
- FW_DEFINE_CLASS_M1(FW_CShapeListShape, 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_CShapeListShape::FW_CShapeListShape
- //----------------------------------------------------------------------------------------
-
- FW_CShapeListShape::FW_CShapeListShape(const FW_PShapeList& list) :
- FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
- fShapeList(list)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::FW_CShapeListShape
- //----------------------------------------------------------------------------------------
-
- FW_CShapeListShape::FW_CShapeListShape(FW_CReadableStream& stream) :
- FW_CShape(stream),
- fShapeList(stream)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::FW_CShapeListShape
- //----------------------------------------------------------------------------------------
-
- FW_CShapeListShape::FW_CShapeListShape(const FW_CShapeListShape& other) :
- FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
- fShapeList(other.fShapeList)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::~FW_CShapeListShape
- //----------------------------------------------------------------------------------------
-
- FW_CShapeListShape::~FW_CShapeListShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::HitTestList
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CShapeListShape::HitTestList(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_Fixed tolerance) const
- {
- // Shapes are rendered in reverse order of the list so I need to test them from
- // first (frontmost) to last (backmost)
- FW_CShapeListIterator ite(fShapeList);
- for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if(shape->HitTest(gc, test, tolerance))
- return shape;
- }
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CShapeListShape& FW_CShapeListShape::operator=(const FW_CShapeListShape& other)
- {
- fShapeList = other.fShapeList;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::GetShapeList
- //----------------------------------------------------------------------------------------
-
- const FW_PShapeList& FW_CShapeListShape::GetShapeList() const
- {
- return fShapeList;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::GetShapeList
- //----------------------------------------------------------------------------------------
-
- FW_PShapeList& FW_CShapeListShape::GetShapeList()
- {
- return fShapeList;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::GetUnSharedShapeList
- //----------------------------------------------------------------------------------------
-
- FW_PShapeList& FW_CShapeListShape::GetUnSharedShapeList()
- {
- if (fShapeList->GetReferenceCount() > 1)
- fShapeList = fShapeList.Copy();
-
- return fShapeList;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::SetShapeList
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::SetShapeList(const FW_PShapeList& list)
- {
- fShapeList = list;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::Purge
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::Purge()
- {
- fShapeList->Purge();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::Render(FW_CGraphicContext& gc) const
- {
- // Draw shapes in reverse order of the list
- if (GetRenderVerb() != FW_kNoRendering)
- FW_CShapeListShape::RenderShapeList(gc, fShapeList);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::RenderShapeList(FW_CGraphicContext& gc,
- const FW_PShapeList& shapeList)
- {
- // Draw shapes in reverse order of the list
- FW_CShapeListIterator ite(shapeList);
- for (FW_CShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
- {
- shape->Render(gc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CShapeListShape::Copy() const
- {
- return FW_NEW(FW_CShapeListShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CShapeListShape::HitTest(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_Fixed tolerance) const
- {
- if (GetRenderVerb() == FW_kNoRendering)
- return NULL;
-
- return HitTestList(gc, test, tolerance) != NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::Transform(Environment *ev, ODTransform* transform)
- {
- FW_CShapeListIterator ite(fShapeList);
- for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->Transform(ev, transform);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::InverseTransform(Environment *ev, ODTransform* transform)
- {
- FW_CShapeListIterator ite(fShapeList);
- for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->InverseTransform(ev, transform);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
- {
- FW_CShapeListIterator ite(fShapeList);
- for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->MoveShape(deltaX, deltaY);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::MoveShapeTo
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
- {
- FW_CPoint shapeListAnchor(GetAnchorPoint());
- FW_CPoint delta(x - shapeListAnchor.x, y - shapeListAnchor.y);
-
- FW_CShapeListIterator ite(fShapeList);
- for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->MoveShape(delta.x, delta.y);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::Inset
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::Inset(FW_Fixed h, FW_Fixed v)
- {
- FW_CShapeListIterator ite(fShapeList);
- for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->Inset(h, v);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::GetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
- {
- FW_Boolean first = TRUE;
-
- FW_CShapeListIterator ite(fShapeList);
- for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- FW_CRect bounds;
- shape->GetBounds(gc, bounds);
- if (first)
- rect = bounds;
- else
- rect.Union(bounds);
- first = FALSE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::GetAnchorPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CShapeListShape::GetAnchorPoint() const
- {
- return fShapeList->GetAnchorPoint();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CShapeListShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CShapeListShape::Flatten(FW_CWritableStream& stream) const
- {
- FW_CShape::Flatten(stream);
- stream << fShapeList;
- }
-
-