home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Container / Sources / Tracker.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  9.2 KB  |  319 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Tracker.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef TRACKER_H
  13. #include "Tracker.h"
  14. #endif
  15.  
  16. #ifndef PROXY_H
  17. #include "Proxy.h"
  18. #endif
  19.  
  20. #ifndef FRAME_H
  21. #include "Frame.h"
  22. #endif
  23.  
  24. // ----- Part Layer -----
  25.  
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"
  28. #endif
  29.  
  30. #ifndef FWUTIL_H
  31. #include "FWUtil.h"
  32. #endif
  33.  
  34. #ifndef FWVIEW_H
  35. #include "FWView.h"
  36. #endif
  37.  
  38. #ifndef FWSCROLR_H
  39. #include "FWScrolr.h"
  40. #endif
  41.  
  42. // ----- OS Layer -----
  43.  
  44. #ifndef FWRECSHP_H
  45. #include "FWRecShp.h"
  46. #endif
  47.  
  48. //========================================================================================
  49. // Runtime Information
  50. //========================================================================================
  51.  
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment odfcontainer
  54. #endif
  55.  
  56. //========================================================================================
  57. //    class CTrackRect
  58. //========================================================================================
  59.  
  60. //----------------------------------------------------------------------------------------
  61. //    CTrackRect constructor
  62. //----------------------------------------------------------------------------------------
  63. CTrackRect::CTrackRect(const FW_CInk& frameInk, const FW_CStyle& frameStyle) :
  64.     fFrameStyle(frameStyle),
  65.     fFrameInk(frameInk)
  66. {
  67. }
  68.  
  69. //----------------------------------------------------------------------------------------
  70. //    CTrackRect destructor
  71. //----------------------------------------------------------------------------------------
  72. CTrackRect::~CTrackRect()
  73. {
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    CTrackRect::GetRectBounds
  78. //----------------------------------------------------------------------------------------
  79. void CTrackRect::GetRectBounds(FW_CRect& bounds) const
  80. {
  81.     bounds = fRect;
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //    CTrackRect::SetRectGeometry
  86. //----------------------------------------------------------------------------------------
  87. void CTrackRect::SetRectGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint)
  88. {
  89.     if (anchorPoint.x < currentPoint.x)
  90.     {
  91.         fRect.left = anchorPoint.x;
  92.         fRect.right = currentPoint.x;
  93.     }
  94.     else
  95.     {
  96.         fRect.left = currentPoint.x;
  97.         fRect.right = anchorPoint.x;
  98.     }
  99.     
  100.     if (anchorPoint.y < currentPoint.y)
  101.     {
  102.         fRect.top = anchorPoint.y;
  103.         fRect.bottom = currentPoint.y;
  104.     }
  105.     else
  106.     {
  107.         fRect.top = currentPoint.y;
  108.         fRect.bottom = anchorPoint.y;
  109.     }
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    CTrackRect::TrackFeedback
  114. //----------------------------------------------------------------------------------------
  115. void CTrackRect::TrackFeedback(Environment* ev,
  116.                                 ODFacet* facet,
  117.                                 FW_CGraphicContext& gc,
  118.                                 const FW_CPoint& anchorPoint, 
  119.                                 const FW_CPoint& currentPoint, 
  120.                                 FW_Boolean erase)
  121. {
  122.     if (!erase)
  123.         SetRectGeometry(anchorPoint, currentPoint);
  124.  
  125.     FW_CRect rect(fRect);
  126.     FW_Fixed pensize = fFrameStyle.GetPenSize();
  127.     FW_Fixed half = FW_Half(pensize);
  128.     rect.Inset(-half, -half);
  129.  
  130.     FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  131. }
  132.  
  133. //========================================================================================
  134. //    class CResizeTracker
  135. //========================================================================================
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    CResizeTracker::CResizeTracker
  139. //----------------------------------------------------------------------------------------
  140.  
  141. CResizeTracker::CResizeTracker(Environment* ev,
  142.                                 FW_CView* view, ODFacet* facet, 
  143.                                 CProxy* theProxy, short whichHandle,
  144.                                 const FW_CInk& resizeInk, const FW_CStyle& resizeStyle) 
  145. :    FW_CTracker(ev, view, facet),
  146.     fProxy(theProxy),
  147.     fWhichHandle(whichHandle),
  148.     fResizeInk(resizeInk),
  149.     fResizeStyle(resizeStyle),
  150.     fErase(FALSE),
  151.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  152. {
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    CResizeTracker::~CResizeTracker
  157. //----------------------------------------------------------------------------------------
  158.  
  159. CResizeTracker::~CResizeTracker()
  160. {
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    CResizeTracker::BeginTracking
  165. //----------------------------------------------------------------------------------------
  166.  
  167. FW_CPoint CResizeTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  168. {
  169.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  170.     
  171.     FW_CRectShape handle(FW_kZeroRect, FW_kFill);
  172.     handle.SetInk(FW_kInvertInk);
  173.     FW_CPoint penSize = vc.DeviceToLogical(2, 2);
  174.     fProxy->CalcHandle(fWhichHandle, &handle, penSize);
  175.     handle.Render(vc);    // redraw the handle
  176.  
  177.     FW_CPoint handleCenter;
  178.     fProxy->GetHandleCenter(fWhichHandle, handleCenter);
  179.     fDelta = anchorPoint - handleCenter;
  180.  
  181.     fScroller->InitializeAutoScroll(ev);
  182.     
  183.     return handleCenter;
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    CResizeTracker::ContinueTracking
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_CPoint CResizeTracker::ContinueTracking(Environment* ev,
  191.                                             const FW_CPoint& anchorPoint, 
  192.                                             const FW_CPoint& previousPoint, 
  193.                                             const FW_CPoint& currentPoint)
  194. {
  195. FW_UNUSED(anchorPoint);
  196.  
  197.     // ----- Adjust for the size of the handle
  198.     FW_CPoint curLoc(currentPoint - fDelta);        
  199.  
  200.     if (previousPoint != curLoc)
  201.     {
  202.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  203.     
  204.         if (fErase)
  205.             fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, previousPoint);    // erase
  206.         else
  207.             fProxy->RenderSelectionFrame(vc);
  208.                 
  209.         fScroller->AutoScroll(ev, currentPoint, &vc);
  210.  
  211.         fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, curLoc);    // draw
  212.         
  213.         fErase = TRUE;                
  214.     }
  215.     
  216.     return curLoc;
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    CResizeTracker::EndTracking
  221. //----------------------------------------------------------------------------------------
  222.  
  223. FW_Boolean CResizeTracker::EndTracking(Environment* ev,
  224.                                     const FW_CPoint& anchorPoint, 
  225.                                     const FW_CPoint& lastPoint)
  226. {
  227.     fLastLocation = lastPoint - fDelta;
  228.     
  229.     if (fErase)
  230.     {
  231.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  232.     
  233.         fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, fLastLocation);
  234.     }
  235.     
  236.     return anchorPoint != lastPoint;
  237. }
  238.  
  239. //========================================================================================
  240. //    class CSelectTracker
  241. //========================================================================================
  242.  
  243. //----------------------------------------------------------------------------------------
  244. //    CSelectTracker constructor
  245. //----------------------------------------------------------------------------------------
  246.  
  247. CSelectTracker::CSelectTracker(Environment* ev, FW_CView* view, ODFacet* facet, CTrackRect* theShape) :
  248.     FW_CTracker(ev, view, facet),
  249.     fShape(theShape),
  250.     fErase(FALSE),
  251.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  252. {
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    CSelectTracker destructor
  257. //----------------------------------------------------------------------------------------
  258.  
  259. CSelectTracker::~CSelectTracker()
  260. {
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. //    CSelectTracker::BeginTracking
  265. //----------------------------------------------------------------------------------------
  266.  
  267. FW_CPoint CSelectTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  268. {
  269.     fScroller->InitializeAutoScroll(ev);
  270.     return anchorPoint;
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. //    CSelectTracker::ContinueTracking
  275. //----------------------------------------------------------------------------------------
  276.  
  277. FW_CPoint CSelectTracker::ContinueTracking(Environment* ev,
  278.                                         const FW_CPoint& anchorPoint, 
  279.                                         const FW_CPoint& previousPoint, 
  280.                                         const FW_CPoint& currentPoint)
  281. {
  282.     FW_CPoint curLoc(currentPoint);
  283.     
  284.     if (previousPoint != curLoc)
  285.     {
  286.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  287.         
  288.         if (fErase)
  289.             fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, previousPoint, TRUE);
  290.         
  291.         fScroller->AutoScroll(ev, currentPoint, &vc);
  292.  
  293.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, curLoc, FALSE);
  294.         
  295.         fErase = TRUE;
  296.     }
  297.     
  298.     return curLoc;
  299. }
  300.  
  301. //----------------------------------------------------------------------------------------
  302. //    CSelectTracker::EndTracking
  303. //----------------------------------------------------------------------------------------
  304.  
  305. FW_Boolean CSelectTracker::EndTracking(Environment* ev,
  306.                                     const FW_CPoint& anchorPoint, 
  307.                                     const FW_CPoint& lastPoint)
  308. {
  309.     if (fErase)
  310.     {
  311.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  312.         
  313.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, lastPoint, TRUE);
  314.     }
  315.     
  316.     return anchorPoint != lastPoint;
  317. }
  318.  
  319.