home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.9 KB | 282 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: PRODGeom.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef PRODGEOM_H
- #include "PRODGeom.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwodmisc_odgeom
- #endif
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- // [HLX] We need to release them when the library is unloaded
- static ODShape* FW_gShapeMaker = NULL;
- static ODTransform* FW_gTransformMaker = NULL;
-
- //----------------------------------------------------------------------------------------
- // FW_PrivSetShapeTransformMaker
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivSetShapeTransformMaker(Environment *ev, ODFrame* odFrame)
- {
- FW_SOM_TRY
- {
- if (FW_gShapeMaker == NULL)
- {
- FW_gShapeMaker = odFrame->CreateShape(ev);
-
- FW_gShapeMaker->SetRectangle(ev, (ODRect*) &FW_kZeroRect);
- }
-
- if (FW_gTransformMaker == NULL)
- FW_gTransformMaker = odFrame->CreateTransform(ev);
- }
- FW_SOM_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODShape_Empty
- //----------------------------------------------------------------------------------------
-
- ODShape* SL_API FW_PrivNewODShape_Empty(Environment* ev)
- {
- // If you get this assert it means that you are trying to create a shape before your
- // part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
- // to create new shapes you cannot create a new shape before having a frame or facet.
- FW_ASSERT(FW_gShapeMaker != NULL);
-
- FW_SOM_TRY
- {
- return FW_gShapeMaker->NewShape(ev);
- }
- FW_SOM_CATCH
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODShape_PlatformRect
- //----------------------------------------------------------------------------------------
-
- ODShape* SL_API FW_PrivNewODShape_PlatformRect(Environment *ev, const FW_PlatformRect& rect)
- {
- // No try block necessary - Do not throw
- return FW_PrivNewODShape_Rect(ev, FW_CRect(rect));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODShape_Rect
- //----------------------------------------------------------------------------------------
-
- ODShape* SL_API FW_PrivNewODShape_Rect(Environment *ev, const FW_SRect& rect)
- {
- // If you get this assert it means that you are trying to create a shape before your
- // part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
- // to create new shapes you cannot create a new shape before having a frame or facet.
- FW_ASSERT(FW_gShapeMaker != NULL);
-
- ODShape *odShape = NULL;
- FW_VOLATILE(odShape);
-
- FW_TRY
- {
- odShape = FW_gShapeMaker->NewShape(ev);
- odShape->SetRectangle(ev, (ODRect*) &rect);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (odShape!=NULL)
- odShape->Release(ev);
- odShape = NULL;
- }
- FW_CATCH_END
-
- return odShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODShape_Region
- //----------------------------------------------------------------------------------------
-
- ODShape* SL_API FW_PrivNewODShape_Region(Environment *ev, ODRgnHandle rgnHandleToAdopt)
- {
- // If you get this assert it means that you are trying to create a shape before your
- // part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
- // to create new shapes you cannot create a new shape before having a frame or facet.
- FW_ASSERT(FW_gShapeMaker != NULL);
-
- ODShape *odShape = NULL;
- FW_VOLATILE(odShape);
-
- FW_TRY
- {
- odShape = FW_gShapeMaker->NewShape(ev);
- #ifdef FW_BUILD_MAC
- odShape->SetQDRegion(ev, rgnHandleToAdopt);
- #endif
- #ifdef FW_BUILD_WIN
- odShape->SetWinRegion(ev, rgnHandleToAdopt);
- #endif
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (odShape!=NULL)
- odShape->Release(ev);
- odShape = NULL;
- }
- FW_CATCH_END
-
- return odShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODShape_Shape
- //----------------------------------------------------------------------------------------
-
- ODShape* SL_API FW_PrivNewODShape_Shape(Environment *ev, ODShape* otherShape)
- {
- FW_SOM_TRY
- {
- return otherShape->Copy(ev);
- }
- FW_SOM_CATCH
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODTransform_Empty
- //----------------------------------------------------------------------------------------
-
- ODTransform* SL_API FW_PrivNewODTransform_Empty(Environment* ev)
- {
- // If you get this assert it means that you are trying to create a transform before your
- // part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
- // to create new transforms you cannot create a new transform before having a frame
- // or facet.
- FW_ASSERT(FW_gTransformMaker != NULL);
- FW_SOM_TRY
- {
- return FW_gTransformMaker->NewTransform(ev);
- }
- FW_SOM_CATCH
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODTransform_Transform
- //----------------------------------------------------------------------------------------
-
- ODTransform* SL_API FW_PrivNewODTransform_Transform(Environment *ev, ODTransform* otherTransform)
- {
- FW_SOM_TRY
- {
- return otherTransform->Copy(ev);
- }
- FW_SOM_CATCH
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODTransform_Point
- //----------------------------------------------------------------------------------------
-
- ODTransform* SL_API FW_PrivNewODTransform_Point(Environment *ev, const FW_SPoint& offset)
- {
- // If you get this assert it means that you are trying to create a transform before your
- // part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
- // to create new transforms you cannot create a new transform before having a frame
- // or facet.
- FW_ASSERT(FW_gTransformMaker != NULL);
-
- ODTransform *odTransform = NULL;
- FW_VOLATILE(odTransform);
-
- FW_TRY
- {
- odTransform = FW_gTransformMaker->NewTransform(ev);
- odTransform->MoveBy(ev, (ODPoint*)&offset);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (odTransform)
- odTransform->Release(ev);
- odTransform = NULL;
- }
- FW_CATCH_END
-
- return odTransform;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivNewODTransform_Point2
- //----------------------------------------------------------------------------------------
-
- ODTransform* SL_API FW_PrivNewODTransform_Point2(Environment *ev, const FW_SPoint& offset, const FW_SPoint& scale)
- {
- // If you get this assert it means that you are trying to create a transform before your
- // part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
- // to create new transforms you cannot create a new transform before having a frame
- // or facet.
- FW_ASSERT(FW_gTransformMaker != NULL);
-
- ODTransform *odTransform = NULL;
- FW_VOLATILE(odTransform);
-
- FW_TRY
- {
- odTransform = FW_gTransformMaker->NewTransform(ev);
- odTransform->ScaleBy(ev, (ODPoint*)&scale);
- odTransform->MoveBy(ev, (ODPoint*)&offset);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (odTransform)
- odTransform->Release(ev);
- odTransform = NULL;
- }
- FW_CATCH_END
-
- return odTransform;
- }
-