home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 6.8 KB | 207 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFctClp.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWFCTCLP_H
- #include "FWFctClp.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fw_embedding
- #endif
-
- FW_DEFINE_AUTO(FW_CFacetClipper)
-
- //========================================================================================
- // class FW_CFacetClipper
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::FW_CFacetClipper
- //----------------------------------------------------------------------------------------
-
- FW_CFacetClipper::FW_CFacetClipper()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::~FW_CFacetClipper
- //----------------------------------------------------------------------------------------
-
- FW_CFacetClipper::~FW_CFacetClipper()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::Clip
- //----------------------------------------------------------------------------------------
-
- void FW_CFacetClipper::Clip(Environment *ev, FW_CPresentation *presentation, ODShape* limitShape)
- {
- FW_ASSERT(presentation);
-
- FW_CPresentationFrameIterator ite(ev, presentation);
- for (FW_CEmbeddingFrame* frame = (FW_CEmbeddingFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (FW_CEmbeddingFrame*)ite.Next(ev))
- {
- Clip(ev, frame, limitShape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::Clip
- //----------------------------------------------------------------------------------------
-
- FW_DECLARE_THROW_POINT (FW_CFacetClipper_Clip);
-
- void FW_CFacetClipper::Clip(Environment *ev, FW_CEmbeddingFrame* frame, ODShape* limitShape)
- {
- FW_CFrameFacetIterator iter(ev, frame);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
- ClipEmbeddedFacets(ev, frame, facet, limitShape);
- FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::ClipEmbeddedFacets
- //----------------------------------------------------------------------------------------
-
- void FW_CFacetClipper::ClipEmbeddedFacets(Environment *ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFacet* containingFacet,
- ODShape* limitShape)
- {
- // ----- Calculate the working clip -----
- // The workingClip is in Content Coordinates
- FW_CAcquiredODShape aqWorkingClip = FW_CopyAndRelease(ev, AcquireWorkingClip(ev, embeddingFrame, containingFacet));
- aqWorkingClip->SetGeometryMode(ev, kODLoseGeometry);
-
- // ----- Now iterates -----
- FW_CFacetIterator iter(ev, containingFacet, kODChildrenOnly, kODFrontToBack);
-
- for (ODFacet* embeddedFacet = iter.First(ev);
- iter.IsNotComplete(ev);
- embeddedFacet = iter.Next(ev))
- {
- ClipOneEmbeddedFacet(ev, embeddedFacet, aqWorkingClip, limitShape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::ClipOneEmbeddedFacet
- //----------------------------------------------------------------------------------------
- // the workingClip is in the containing frame content coordinates
-
- void FW_CFacetClipper::ClipOneEmbeddedFacet(Environment *ev,
- ODFacet* embeddedFacet,
- ODShape* workingClip,
- ODShape* limitShape)
- {
- // ----- Set the clip shape to the used shape (Frame coordinate) -----
- FW_CAcquiredODShape aqEmbeddedClipShape(FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireUsedShape(ev, NULL)));
-
- // ----- Transform the clip shape to the containing frame content coordinates -----
- FW_CAcquiredODTransform aqExternalTransform = embeddedFacet->AcquireExternalTransform(ev, NULL);
- aqEmbeddedClipShape->Transform(ev, aqExternalTransform); // Containing Frame Content Coordinates
- aqEmbeddedClipShape->SetGeometryMode(ev, kODLoseGeometry);
-
- // ----- Look if the facet is in the limitShape -----
- FW_Boolean changeClip = TRUE;
- if (limitShape)
- {
- FW_CRect limitRect, usedRect;
- limitShape->GetBoundingBox(ev, (ODRect*)&limitRect);
- aqEmbeddedClipShape->GetBoundingBox(ev, (ODRect*)&usedRect);
- changeClip = limitRect.IsIntersecting(usedRect);
- }
-
- // ----- intersect it with the working clip -----
- aqEmbeddedClipShape->Intersect(ev, workingClip);
-
- // ----- remove the clip shape from the working clip -----
- workingClip->Subtract(ev, aqEmbeddedClipShape);
-
- if (changeClip)
- {
- // ----- Put back the clip shape in embedded frame coordinates -----
- aqEmbeddedClipShape->InverseTransform(ev, aqExternalTransform);
-
- // ----- Change the clip shape of the embedded facet -----
- embeddedFacet->ChangeGeometry(ev, aqEmbeddedClipShape, NULL, NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::AcquireWorkingClip
- //----------------------------------------------------------------------------------------
- // returns the working clip in content coordinate of the containing frame.
-
- ODShape* FW_CFacetClipper::AcquireWorkingClip(Environment *ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFacet* containingFacet)
- {
- FW_CPoint extent;
- embeddingFrame->GetContentExtent(ev, extent);
- FW_CRect extentRect(FW_kFixed0, FW_kFixed0, extent.x, extent.y);
-
- // ----- Create the working clip (use the content shape or extent rect if static canvas) -----
- ODShape* workingClip;
- if (containingFacet->GetCanvas(ev)->IsDynamic(ev))
- {
- workingClip = FW_CopyAndRelease(ev, embeddingFrame->AcquireContentShape(ev)); // in Frame Coordinate
- FW_CAcquiredODTransform aqInternalTransform = embeddingFrame->AcquireInternalTransform(ev, NULL);
- workingClip->InverseTransform(ev, aqInternalTransform); // Content Coordinate
- }
- else
- {
- workingClip = ::FW_NewODShape(ev, extentRect);
- }
-
- return workingClip;
- }
-