home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CADisplay.cpp
-
- Contains: Display code for CALib
-
- Written by: Rick Badertscher
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
-
- <2> 5/15/95 RB Adding CA_CATCH
- <1> 5/12/95 RB Created
-
- To Do:
- */
-
- #ifndef _CASESSN_
- #include "CASessn.h"
- #endif
-
- #ifndef _CAFRMUTL_
- #include "CAFrmUtl.h"
- #endif
-
- #ifndef _CAERROR_
- #include "CAError.h"
- #endif
-
- #ifndef _CADOCPRIV_
- #include "CADocPriv.h"
- #endif
-
- #ifndef _CAUTIL_
- #include "CAUtil.h"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef _ODMATH_
- #include <ODMath.h>
- #endif
-
- #ifndef _MATRIX_
- #include "Matrix.h"
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef _CADEBUG_
- #include "CADebug.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #pragma segment CALib
-
- //-------------------------------------------------------------------------
- // Variables
- //-------------------------------------------------------------------------
-
- const CATransform kCAIdentityMatrix = {{{kODFixed1, 0, 0},
- {0, kODFixed1, 0},
- {0, 0, kODFract1}}};
-
- //-------------------------------------------------------------------------
- // Layout
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
-
- pascal CAVisFrame
- CAGetVisFrame( CADocumentRef document, CAFrameRef frame )
- {
-
- #ifdef RUNTIME_DEBUG
- VALIDATE_DOCREF ("CAGetVisFrame", document);
- VALIDATE_FRAMEREF ("CAGetVisFrame", document, frame);
- #endif
-
- Environment* ev = gCASession->GetEV();
- ODFacet* facet = kODNULL;
-
- CA_TRY
-
- facet = FacetFromFrameRef (document, frame);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return (CAVisFrame) facet;
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal CAVisFrame
- CAMakeVisFrame( CADocumentRef document,
- CAFrameRef frame,
- RgnHandle clipRgn,
- CATransform* xform,
- GrafPtr port )
- {
- ODUnused(port);
-
- #ifdef RUNTIME_DEBUG
- VALIDATE_DOCREF ("CAMakeVisFrame", document);
- VALIDATE_FRAMEREF ("CAMakeVisFrame", document, frame);
- #endif
-
- Environment* ev = gCASession->GetEV();
- ODFacet* newFacet = kODNULL;
- ODShape* clipShape;
-
- if (FailIfNotVisible(document)) return NULL;
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef(document, frame);
- THROW_IF_NULL (tempFrame);
-
- if (clipRgn == NULL)
- {
- clipShape = ODCopyAndRelease (ev, tempFrame->AcquireFrameShape(ev, kODNULL));
- }
- else
- {
- clipShape = tempFrame->CreateShape (ev);
- clipShape->SetQDRegion(ev, clipRgn);
- }
-
- if (tempFrame->IsRoot (ev))
- {
-
- TempODWindow tempWindow = tempFrame->AcquireWindow (ev);
-
- // Set the root frame's shape to the clipping region
- tempFrame->ChangeFrameShape (ev, clipShape, kODNULL);
- ODRelease (ev, clipShape);
-
- // Create window root facet.
- tempWindow->Open(ev);
- tempWindow->Show(ev);
- tempWindow->Select(ev);
-
- newFacet = tempWindow->GetRootFacet (ev);
-
- }
- else
- {
-
- TempODFrame tempRootFrame = tempFrame->AcquireContainingFrame (ev);
- TempODWindow tempWindow = tempRootFrame->AcquireWindow (ev);
-
- TempODTransform tempXform = tempFrame->CreateTransform(ev);
- THROW_IF_NULL (tempXform);
-
- if (xform == NULL)
- tempXform->Reset (ev);
- else
- tempXform->SetMatrix (ev, (ODMatrix*) xform);
-
- newFacet = tempWindow->GetRootFacet(ev)->CreateEmbeddedFacet(ev, tempFrame, clipShape,
- tempXform, kODNULL, kODNULL, kODNULL, kODFrameInFront);
-
- ODRelease (ev, clipShape);
-
- }
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return (CAVisFrame)newFacet;
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal void
- CAAdjustVisFrame( CAVisFrame visFrame, RgnHandle clipRgn, CATransform* xform )
- {
-
- #ifdef RUNTIME_DEBUG
- VALIDATE_OBJECT ("CAAdjustVisFrame", visFrame);
- #endif
-
- Environment* ev = gCASession->GetEV();
- ODShape* clipShape = kODNULL;
- ODTransform* transform = kODNULL;
- ODFacet* facet = kODNULL;
-
-
- facet = (ODFacet*) visFrame;
-
- CA_TRY
-
- if (clipRgn)
- {
- clipShape = facet->GetFrame(ev)->CreateShape (ev);
- clipShape->SetQDRegion (ev, clipRgn);
- }
-
- if (xform)
- {
- // By default the external transform is identity
- transform = facet->GetFrame(ev)->CreateTransform(ev);
- THROW_IF_NULL (transform);
- transform->SetMatrix (ev, (ODMatrix*) xform);
- }
-
- facet->ChangeGeometry(ev, clipShape, transform, kODNULL);
- facet->GetFrame(ev)->Invalidate (ev, kODNULL, kODNULL);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- ODRelease (ev, clipShape);
- ODRelease (ev, transform);
-
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal void CARemoveVisFrame( CAVisFrame visFrame )
- {
-
- #ifdef RUNTIME_DEBUG
- VALIDATE_OBJECT ("CARemoveVisFrame", visFrame);
- #endif
-
- Environment* ev = gCASession->GetEV();
- ODFacet* targetFacet = (ODFacet*) visFrame;
- ODFrame* frame;
- ODFacet* facet;
-
- CA_TRY
-
- frame = targetFacet->GetFrame (ev);
-
- if (frame->IsRoot (ev))
- THROW (kCAErrIllegalOperation);
-
- facet = targetFacet->GetContainingFacet(ev);
- facet->RemoveFacet (ev, targetFacet);
- ODDeleteObject (targetFacet);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal Boolean
- CAGetSelected( CAVisFrame visFrame)
- {
- Environment* ev = gCASession->GetEV();
-
- CA_TRY
-
- return (((ODFacet*)visFrame)->IsSelected(ev));
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return (false);
- }
-
- //-------------------------------------------------------------------------
-
- pascal void
- CASetSelected( CAVisFrame visFrame, Boolean isSelected )
- {
-
- Environment* ev = gCASession->GetEV();
-
- CA_TRY
-
- ((ODFacet*)visFrame)->SetSelected(ev, isSelected);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal CAHighlight
- CAGetHighlight( CAVisFrame visFrame)
- {
- Environment* ev = gCASession->GetEV();
- ODHighlight highlight;
-
- CA_TRY
-
- highlight = ((ODFacet*)visFrame)->GetHighlight(ev);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return ((CAHighlight) highlight);
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal void
- CASetHighlight( CAVisFrame visFrame, CAHighlight highlight )
- {
- Environment* ev = gCASession->GetEV();
-
- CA_TRY
-
- ((ODFacet*)visFrame)->ChangeHighlight(ev, (ODHighlight) highlight );
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
-
-
- //-------------------------------------------------------------------------
-
- pascal void CAGetVisFrameTransform( CADocumentRef document,
- CAFrameRef frameRef,
- CATransform* transform)
- {
-
- Environment* ev = gCASession->GetEV();
- ODFacet* facet;
-
- CA_TRY
-
- facet = FacetFromFrameRef (document, frameRef);
-
- TempODTransform tempTransform = facet->AcquireExternalTransform (ev, kODNULL);
- THROW_IF_NULL (tempTransform);
-
- tempTransform->GetMatrix(ev, (ODMatrix*) transform);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal void CAMoveTransformBy (CATransform* transform, Point offset)
- {
-
- ODFixed x, y;
-
- x = offset.h;
- y = offset.v;
-
- CA_TRY
-
- MxMove( (ODMatrix*) transform, kODTranslateXform, x, y );
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal void CAMoveTransformTo (CATransform* transform, Point origin)
- {
-
- Environment* ev = gCASession->GetEV();
-
- CA_TRY
-
- TempODTransform tempTransform = new ODTransform;
- THROW_IF_NULL(tempTransform);
- tempTransform->InitTransform(ev);
-
- tempTransform->SetQDOffset (ev, &origin);
-
- tempTransform->GetMatrix (ev, (ODMatrix*) transform);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
-
- //===========================================================================
- #pragma mark ' Utility Routines
- //===========================================================================
-
-
- Boolean FailIfNotVisible (CADocumentRef doc)
- {
-
- if ( ((CADocument*)doc)->GetWindow() == NULL)
- {
- SetCAError (kCAErrFrameAccess);
- return true;
- }
-
- return false;
-
- }
-
-