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 / Table / Sources / Tracker.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  9.7 KB  |  331 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 "Table.hpp"
  11.  
  12. #ifndef TRACKER_H
  13. #include "Tracker.h"
  14. #endif
  15.  
  16. #ifndef FRAME_H
  17. #include "Frame.h"
  18. #endif
  19.  
  20. #ifndef CONTENT_H
  21. #include "Content.h"
  22. #endif
  23.  
  24. // ----- Part Layer -----
  25.  
  26. #ifndef FWUTIL_H
  27. #include "FWUtil.h"
  28. #endif
  29.  
  30. // ----- OS Layer -----
  31.  
  32. #ifndef FWODGEOM_H
  33. #include "FWODGeom.h"
  34. #endif
  35.  
  36. #ifndef FWACQUIR_H
  37. #include "FWAcquir.h"
  38. #endif
  39.  
  40. #ifndef FWPOINT_H
  41. #include "FWPoint.h"
  42. #endif
  43.  
  44. #ifndef FWCONTXT_H
  45. #include "FWContxt.h"
  46. #endif
  47.  
  48. // ----- OpenDoc Layer -----
  49.  
  50. #ifndef SOM_ODSession_xh
  51. #include <ODSessn.xh>
  52. #endif
  53.  
  54. #ifndef SOM_ODDragAndDrop_xh
  55. #include <DragDrp.xh>
  56. #endif
  57.  
  58. //========================================================================================
  59. // RunTime Info
  60. //========================================================================================
  61.  
  62. #ifdef FW_BUILD_MAC
  63. #pragma segment odfTable
  64. #endif
  65.  
  66. //========================================================================================
  67. //    class CTableDropTracker
  68. //========================================================================================
  69.  
  70. //----------------------------------------------------------------------------------------
  71. //    CTableDropTracker::CTableDropTracker
  72. //----------------------------------------------------------------------------------------
  73.  
  74. CTableDropTracker::CTableDropTracker(Environment* ev, 
  75.                                     CTablePart* part,
  76.                                     CTableContent* content,
  77.                                     CTableFrame* frame,
  78.                                     ODFacet* facet,
  79.                                     const CCell& sourceCell) :
  80.     FW_CDropTracker(ev, frame, facet),
  81.     fTableFrame(frame),
  82.     fTablePart(part),
  83.     fTableContent(content),
  84.     fSourceCell(sourceCell),
  85.     fCurCell(-1, -1)
  86. {
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. //    CTableDropTracker::~CTableDropTracker
  91. //----------------------------------------------------------------------------------------
  92.  
  93. CTableDropTracker::~CTableDropTracker()
  94. {
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. //    CTableDropTracker::ShouldHilite
  99. //----------------------------------------------------------------------------------------
  100. // Because I don't want to drop on a cell already containing a proxy
  101.  
  102. FW_Boolean CTableDropTracker::ShouldHilite(Environment* ev, const FW_CPoint& point, CCell& cell)
  103. {
  104.     return (fTableFrame->HitTest(ev, point, cell) == kTLCell) && (fTableContent->CellToProxy(cell) == NULL);
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    CTableDropTracker::BeginTracking
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_CPoint CTableDropTracker::BeginTracking(Environment* ev, 
  112.                                             const FW_CPoint& anchorPoint)
  113. {
  114.     CCell cell;
  115.     
  116.     if (ShouldHilite(ev, anchorPoint, cell))
  117.         Hilite(ev, cell, GetFacet(ev));
  118.         
  119.     return anchorPoint;
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    CTableDropTracker::ContinueTracking
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_CPoint CTableDropTracker::ContinueTracking(Environment* ev,
  127.                                                 const FW_CPoint& anchorPoint, 
  128.                                                 const FW_CPoint& previousPoint, 
  129.                                                 const FW_CPoint& currentPoint)
  130. {
  131.     CCell cell;
  132.     if (ShouldHilite(ev, currentPoint, cell))
  133.         Hilite(ev, cell, GetFacet(ev));
  134.     
  135.     return currentPoint;
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    CTableDropTracker::Hilite
  140. //----------------------------------------------------------------------------------------
  141.  
  142. void CTableDropTracker::Hilite(Environment* ev, const CCell& cell, ODFacet* facet)
  143. {
  144.     if (cell == fCurCell)
  145.         return;
  146.     
  147.     fCurCell = cell;
  148.  
  149. #ifdef FW_BUILD_MAC
  150.     this->HideDragHilite(ev);
  151.  
  152.     FW_CWindowContext gc(ev, facet);        // focus drawing to the window
  153.  
  154.     if (cell != fSourceCell)
  155.     {    
  156.         FW_CRect cellRect;
  157.         fTableContent->FindRect(cell, cellRect);
  158.         
  159.         FW_CRect shapeBounds = fTableFrame->GetBounds(ev);
  160.         FW_CAcquiredODTransform aqInternalXForm = fTableFrame->AcquireInternalTransform(ev, NULL);
  161.         shapeBounds.Transform(ev, aqInternalXForm);
  162.         cellRect.Intersection(shapeBounds);
  163.         
  164.         FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, cellRect);
  165.  
  166.         this->ShowDragHilite(ev, aqShape, TRUE);
  167.     }
  168. #endif
  169. }
  170.  
  171. //========================================================================================
  172. //    class CGridLineTracker
  173. //========================================================================================
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    CGridLineTracker constructor
  177. //----------------------------------------------------------------------------------------
  178. CGridLineTracker::CGridLineTracker(Environment* ev, 
  179.                                      FW_CView* view,
  180.                                     ODFacet* facet,
  181.                                        ETableLoc tl,
  182.                                        FW_CRect dragArea,
  183.                                        FW_CPoint borders) :
  184.     FW_CTracker(ev, view, facet),
  185.     fDragArea(dragArea),
  186.     fOldBorders(borders),
  187.     fNewBorders(borders),
  188.     fCross(borders, dragArea.BotRight())
  189. {
  190.     // Get direction of resize
  191.     fHorizMove = ((tl & (kTLLeftBorder + kTLRightBorder)) != 0);
  192.     fVertMove = ((tl & (kTLTopBorder + kTLBottomBorder)) != 0);
  193.  
  194.     if (fHorizMove)
  195.         fCross.SetVLineToMove();
  196.     if (fVertMove)
  197.         fCross.SetHLineToMove();
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    CGridLineTracker destructor
  202. //----------------------------------------------------------------------------------------
  203. CGridLineTracker::~CGridLineTracker()
  204. {
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    CGridLineTracker::BeginTracking
  209. //----------------------------------------------------------------------------------------
  210. FW_CPoint CGridLineTracker::BeginTracking(Environment* ev, 
  211.                                           const FW_CPoint& anchorPoint)
  212. {
  213.     // Display borders that are moving
  214.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  215.     fCross.Render(vc);
  216.  
  217.     return anchorPoint;
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. //    CGridLineTracker::ContinueTracking
  222. //----------------------------------------------------------------------------------------
  223. FW_CPoint CGridLineTracker::ContinueTracking(Environment* ev,
  224.                                              const FW_CPoint& anchorPoint, 
  225.                                              const FW_CPoint& previousPoint, 
  226.                                              const FW_CPoint& currentPoint)
  227. {
  228.     FW_UNUSED(anchorPoint);
  229.     FW_CPoint now(currentPoint);
  230.  
  231.     // Stay in permissible drag area
  232.     if (now.x < fDragArea.left)
  233.         now.x = fDragArea.left;
  234.     if (now.x > fDragArea.right)
  235.         now.x = fDragArea.right;
  236.     if (now.y < fDragArea.top)
  237.         now.y = fDragArea.top;
  238.     if (now.y > fDragArea.bottom)
  239.         now.y = fDragArea.bottom;
  240.  
  241.     // Move the borders
  242.     if (now != previousPoint)
  243.     {
  244.         FW_Fixed x = (fHorizMove ? now.x - previousPoint.x : FW_IntToFixed(0));
  245.         FW_Fixed y = (fVertMove ? now.y - previousPoint.y : FW_IntToFixed(0));
  246.         
  247.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  248.         fCross.Render(vc);
  249.         fCross.MoveShape(x, y);
  250.         fCross.Render(vc);
  251.         
  252.         fNewBorders.x += x;
  253.         fNewBorders.y += y;
  254.     }
  255.  
  256.     return now;
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    CGridLineTracker::EndTracking
  261. //----------------------------------------------------------------------------------------
  262. FW_Boolean CGridLineTracker::EndTracking(Environment* ev,
  263.                                          const FW_CPoint& anchorPoint, 
  264.                                          const FW_CPoint& lastPoint)
  265. {
  266.     // Restore the borders
  267.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  268.     fCross.Render(vc);
  269.  
  270.     return anchorPoint != lastPoint;
  271. }
  272.  
  273. //========================================================================================
  274. //    class CCrossShape
  275. //========================================================================================
  276.  
  277. //----------------------------------------------------------------------------------------
  278. //    CCrossShape::CCrossShape
  279. //----------------------------------------------------------------------------------------
  280.  
  281. CCrossShape::CCrossShape(const FW_CPoint& brCell, FW_CPoint& brFrm)
  282.     : vLine(brCell.x, kHMargin, brCell.x, brFrm.y),
  283.       hLine(kVMargin, brCell.y, brFrm.x, brCell.y)
  284. {
  285.     vLine.SetInk(FW_kInvertInk);
  286.     hLine.SetInk(FW_kInvertInk);
  287.     
  288.     vLine.SetRenderVerb(FW_kNoRendering);
  289.     hLine.SetRenderVerb(FW_kNoRendering);
  290. }
  291.  
  292. //----------------------------------------------------------------------------------------
  293. //    CCrossShape::Render
  294. //----------------------------------------------------------------------------------------
  295.  
  296. void CCrossShape::Render(FW_CGraphicContext& graphicContext)
  297. {
  298.     vLine.Render(graphicContext);
  299.     hLine.Render(graphicContext);
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. //    CCrossShape::MoveShape
  304. //----------------------------------------------------------------------------------------
  305.  
  306. void CCrossShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
  307. {
  308.     vLine.MoveShape(deltaX, FW_IntToFixed(0));
  309.     hLine.MoveShape(FW_IntToFixed(0), deltaY);
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    CCrossShape::SetHLineToMove
  314. //----------------------------------------------------------------------------------------
  315.  
  316. void CCrossShape::SetHLineToMove()
  317. {
  318.     hLine.SetRenderVerb(FW_kFrame);
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    CCrossShape::SetVLineToMove
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void CCrossShape::SetVLineToMove()
  326. {
  327.     vLine.SetRenderVerb(FW_kFrame);
  328. }
  329.  
  330.  
  331.