home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 9.2 KB | 319 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Tracker.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Container.hpp"
-
- #ifndef TRACKER_H
- #include "Tracker.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWVIEW_H
- #include "FWView.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfcontainer
- #endif
-
- //========================================================================================
- // class CTrackRect
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTrackRect constructor
- //----------------------------------------------------------------------------------------
- CTrackRect::CTrackRect(const FW_CInk& frameInk, const FW_CStyle& frameStyle) :
- fFrameStyle(frameStyle),
- fFrameInk(frameInk)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTrackRect destructor
- //----------------------------------------------------------------------------------------
- CTrackRect::~CTrackRect()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTrackRect::GetRectBounds
- //----------------------------------------------------------------------------------------
- void CTrackRect::GetRectBounds(FW_CRect& bounds) const
- {
- bounds = fRect;
- }
-
- //----------------------------------------------------------------------------------------
- // CTrackRect::SetRectGeometry
- //----------------------------------------------------------------------------------------
- void CTrackRect::SetRectGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint)
- {
- if (anchorPoint.x < currentPoint.x)
- {
- fRect.left = anchorPoint.x;
- fRect.right = currentPoint.x;
- }
- else
- {
- fRect.left = currentPoint.x;
- fRect.right = anchorPoint.x;
- }
-
- if (anchorPoint.y < currentPoint.y)
- {
- fRect.top = anchorPoint.y;
- fRect.bottom = currentPoint.y;
- }
- else
- {
- fRect.top = currentPoint.y;
- fRect.bottom = anchorPoint.y;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTrackRect::TrackFeedback
- //----------------------------------------------------------------------------------------
- void CTrackRect::TrackFeedback(Environment* ev,
- ODFacet* facet,
- FW_CGraphicContext& gc,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& currentPoint,
- FW_Boolean erase)
- {
- if (!erase)
- SetRectGeometry(anchorPoint, currentPoint);
-
- FW_CRect rect(fRect);
- FW_Fixed pensize = fFrameStyle.GetPenSize();
- FW_Fixed half = FW_Half(pensize);
- rect.Inset(-half, -half);
-
- FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
- }
-
- //========================================================================================
- // class CResizeTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::CResizeTracker
- //----------------------------------------------------------------------------------------
-
- CResizeTracker::CResizeTracker(Environment* ev,
- FW_CView* view, ODFacet* facet,
- CProxy* theProxy, short whichHandle,
- const FW_CInk& resizeInk, const FW_CStyle& resizeStyle)
- : FW_CTracker(ev, view, facet),
- fProxy(theProxy),
- fWhichHandle(whichHandle),
- fResizeInk(resizeInk),
- fResizeStyle(resizeStyle),
- fErase(FALSE),
- fScroller(view->GetFrame(ev)->GetScroller(ev))
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::~CResizeTracker
- //----------------------------------------------------------------------------------------
-
- CResizeTracker::~CResizeTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::BeginTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CResizeTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- FW_CRectShape handle(FW_kZeroRect, FW_kFill);
- handle.SetInk(FW_kInvertInk);
- FW_CPoint penSize = vc.DeviceToLogical(2, 2);
- fProxy->CalcHandle(fWhichHandle, &handle, penSize);
- handle.Render(vc); // redraw the handle
-
- FW_CPoint handleCenter;
- fProxy->GetHandleCenter(fWhichHandle, handleCenter);
- fDelta = anchorPoint - handleCenter;
-
- fScroller->InitializeAutoScroll(ev);
-
- return handleCenter;
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::ContinueTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CResizeTracker::ContinueTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& previousPoint,
- const FW_CPoint& currentPoint)
- {
- FW_UNUSED(anchorPoint);
-
- // ----- Adjust for the size of the handle
- FW_CPoint curLoc(currentPoint - fDelta);
-
- if (previousPoint != curLoc)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- if (fErase)
- fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, previousPoint); // erase
- else
- fProxy->RenderSelectionFrame(vc);
-
- fScroller->AutoScroll(ev, currentPoint, &vc);
-
- fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, curLoc); // draw
-
- fErase = TRUE;
- }
-
- return curLoc;
- }
-
- //----------------------------------------------------------------------------------------
- // CResizeTracker::EndTracking
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CResizeTracker::EndTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& lastPoint)
- {
- fLastLocation = lastPoint - fDelta;
-
- if (fErase)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, fLastLocation);
- }
-
- return anchorPoint != lastPoint;
- }
-
- //========================================================================================
- // class CSelectTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CSelectTracker constructor
- //----------------------------------------------------------------------------------------
-
- CSelectTracker::CSelectTracker(Environment* ev, FW_CView* view, ODFacet* facet, CTrackRect* theShape) :
- FW_CTracker(ev, view, facet),
- fShape(theShape),
- fErase(FALSE),
- fScroller(view->GetFrame(ev)->GetScroller(ev))
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectTracker destructor
- //----------------------------------------------------------------------------------------
-
- CSelectTracker::~CSelectTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectTracker::BeginTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CSelectTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
- {
- fScroller->InitializeAutoScroll(ev);
- return anchorPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectTracker::ContinueTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CSelectTracker::ContinueTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& previousPoint,
- const FW_CPoint& currentPoint)
- {
- FW_CPoint curLoc(currentPoint);
-
- if (previousPoint != curLoc)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- if (fErase)
- fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, previousPoint, TRUE);
-
- fScroller->AutoScroll(ev, currentPoint, &vc);
-
- fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, curLoc, FALSE);
-
- fErase = TRUE;
- }
-
- return curLoc;
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectTracker::EndTracking
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CSelectTracker::EndTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& lastPoint)
- {
- if (fErase)
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
-
- fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, lastPoint, TRUE);
- }
-
- return anchorPoint != lastPoint;
- }
-
-