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 / ODF / Framewrk / FWPart / Sources / FWTrackr.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  10.7 KB  |  369 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTrackr.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWTRACKR_H
  13. #include "FWTrackr.h"
  14. #endif
  15.  
  16. #ifndef FWVIEW_H
  17. #include "FWView.h"
  18. #endif
  19.  
  20. #ifndef FWFRAME_H
  21. #include "FWFrame.h"
  22. #endif
  23.  
  24. #ifndef FWDRGDRP_H
  25. #include "FWDrgDrp.h"
  26. #endif
  27.  
  28. #ifndef FWPART_H
  29. #include "FWPart.h"
  30. #endif
  31.  
  32. #ifndef FWCONTXT_H
  33. #include "FWContxt.h"
  34. #endif
  35.  
  36. #ifndef FWUTIL_H
  37. #include "FWUtil.h"
  38. #endif
  39.  
  40. #ifndef FWSCROLR_H
  41. #include "FWScrolr.h"
  42. #endif
  43.  
  44. // ----- OS Includes -----
  45.  
  46. #ifndef FWRECT_H
  47. #include "FWRect.h"
  48. #endif
  49.  
  50. #ifndef FWEVENT_H
  51. #include "FWEvent.h"
  52. #endif
  53.  
  54. #ifndef FWEVENTU_H
  55. #include "FWEventU.h"
  56. #endif
  57.  
  58. #ifndef FWACQUIR_H
  59. #include "FWAcquir.h"
  60. #endif
  61.  
  62. // ----- Foundation Includes -----
  63.  
  64. #ifndef FWDEBUG_H
  65. #include "FWDebug.h"
  66. #endif
  67.  
  68. // ----- OpenDoc Includes -----
  69.  
  70. #ifndef SOM_ODTransform_xh
  71. #include <Trnsform.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODFacet_xh
  75. #include <Facet.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODFrame_xh
  79. #include <Frame.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODSession_xh
  83. #include <ODSessn.xh>
  84. #endif
  85.  
  86. #ifndef SOM_ODDragAndDrop_xh
  87. #include <DragDrp.xh>
  88. #endif
  89.  
  90. //========================================================================================
  91. //    Runtime Info
  92. //========================================================================================
  93.  
  94. #ifdef FW_BUILD_MAC
  95. #pragma segment framework
  96. #endif
  97.  
  98. //========================================================================================
  99. //    class FW_CBaseTracker
  100. //========================================================================================
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    FW_CBaseTracker::FW_CBaseTracker
  104. //----------------------------------------------------------------------------------------
  105.  
  106. FW_CBaseTracker::FW_CBaseTracker(Environment *ev, FW_CView* view, ODFacet* facet) :
  107.     fFacet(facet),
  108.     fView(view)
  109. {
  110. FW_UNUSED(ev);
  111.     FW_ASSERT(view);
  112.     FW_ASSERT(facet);
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. //    FW_CBaseTracker::~FW_CBaseTracker
  117. //----------------------------------------------------------------------------------------
  118.  
  119. FW_CBaseTracker::~FW_CBaseTracker()
  120. {
  121. }
  122.  
  123. //========================================================================================
  124. //    class FW_CDropTracker
  125. //========================================================================================
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    FW_CDropTracker::FW_CDropTracker
  129. //----------------------------------------------------------------------------------------
  130.  
  131. FW_CDropTracker::FW_CDropTracker(Environment *ev, FW_CView* view, ODFacet* facet) :
  132.     FW_CBaseTracker(ev, view, facet),
  133.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  134. #ifdef FW_BUILD_MAC
  135.     ,fMacHiliteOn(FALSE),
  136.     fSavedHiliteState(FALSE)
  137. #endif
  138. {
  139.     fSession = view->GetFrame(ev)->GetPart(ev)->GetSession(ev);
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_CDropTracker::~FW_CDropTracker
  144. //----------------------------------------------------------------------------------------
  145.  
  146. FW_CDropTracker::~FW_CDropTracker()
  147. {
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    FW_CDropTracker::HandleBeginTracking
  152. //----------------------------------------------------------------------------------------
  153. //    where is in frame coordinate
  154.  
  155. void FW_CDropTracker::HandleBeginTracking(Environment *ev, const FW_CPoint& where, unsigned long dragAttributes)
  156. {        
  157.     fDragAttributes = dragAttributes;
  158.     
  159.     FW_CPoint anchorPoint(where);
  160.     FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), anchorPoint);
  161.     fAnchorPoint = this->BeginTracking(ev, anchorPoint);
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    FW_CDropTracker::HandleContinueTracking
  166. //----------------------------------------------------------------------------------------
  167. //    where is in frame coordinate
  168.  
  169. void FW_CDropTracker::HandleContinueTracking(Environment *ev, const FW_CPoint& where)
  170. {
  171.     FW_CPoint currentPoint(where);
  172.     FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), currentPoint);
  173.     fPreviousPoint = this->ContinueTracking(ev, fAnchorPoint, fPreviousPoint, currentPoint);
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CDropTracker::HandleEndTracking
  178. //----------------------------------------------------------------------------------------
  179. //    where is in frame coordinate
  180.  
  181. FW_Boolean FW_CDropTracker::HandleEndTracking(Environment *ev, const FW_CPoint& where)
  182. {
  183.     FW_CPoint currentPoint(where);
  184.     FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), currentPoint);
  185.     return this->EndTracking(ev, fAnchorPoint, currentPoint);
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    FW_CDropTracker::BeginTracking
  190. //----------------------------------------------------------------------------------------
  191.  
  192. FW_CPoint FW_CDropTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  193. {
  194.     if (!IsInSourceFrame(ev))
  195.         PrivShowDefaultHilite(ev);
  196.     
  197.     if(fScroller)
  198.         fScroller->InitializeAutoScroll(ev);
  199.  
  200.     return anchorPoint;
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    FW_CDropTracker::BeginTracking
  205. //----------------------------------------------------------------------------------------
  206.  
  207. FW_CPoint FW_CDropTracker::ContinueTracking(Environment* ev,
  208.                                             const FW_CPoint& anchorPoint, 
  209.                                             const FW_CPoint& previousPoint, 
  210.                                             const FW_CPoint& currentPoint)
  211. {
  212. FW_UNUSED(anchorPoint);
  213. FW_UNUSED(previousPoint);
  214.     if (fScroller)
  215.     {
  216.         FW_CPoint autoScrollOffset = fScroller->AutoScrollOffset(ev, currentPoint, 30);
  217.         if (autoScrollOffset != FW_kZeroPoint)
  218.         {
  219.             if (fMacHiliteOn)
  220.             {
  221.                 fSavedHiliteState = fMacHiliteOn;
  222.                 this->HideDragHilite(ev);
  223.             }    
  224.             fScroller->ScrollBy(ev, autoScrollOffset);    
  225.         }
  226.         else
  227.         {
  228.             if (fSavedHiliteState)
  229.                 PrivShowDefaultHilite(ev);
  230.         }
  231.     }
  232.  
  233.     return currentPoint;
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. //    FW_CDropTracker::EndTracking
  238. //----------------------------------------------------------------------------------------
  239.  
  240. FW_Boolean FW_CDropTracker::EndTracking(Environment* ev,
  241.                                         const FW_CPoint& anchorPoint, 
  242.                                         const FW_CPoint& lastPoint)
  243. {
  244.     this->HideDragHilite(ev);    
  245.     return anchorPoint != lastPoint;
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    FW_CDropTracker::ShowDragHilite
  250. //----------------------------------------------------------------------------------------
  251. // hiliteShape is in frame coordinate
  252.  
  253. void FW_CDropTracker::ShowDragHilite(Environment* ev, ODShape* hiliteShape, FW_Boolean showInside)
  254. {    
  255. #ifdef FW_BUILD_MAC
  256.     FW_ASSERT(fMacHiliteOn == FALSE);
  257.     FW_ASSERT(hiliteShape);
  258.     
  259.     ODFacet* facet = GetFacet(ev);
  260.     FW_CFrame* frame = GetView(ev)->GetFrame(ev);
  261.     FW_ASSERT(facet->GetFrame(ev) == frame->GetODFrame(ev));    //just to be sure
  262.  
  263.     FW_CWindowContext gc(ev, facet);        // focus drawing to the window
  264.  
  265.     FW_CAcquiredODShape aqHiliteShape = hiliteShape->Copy(ev);
  266.  
  267.     // ----- Intersect it with the aggregateClipShape -----
  268.     FW_CAcquiredODShape aqClipShape = GetFacet(ev)->AcquireAggregateClipShape(ev, NULL);
  269.     aqHiliteShape->Intersect(ev, aqClipShape);
  270.  
  271.     FW_FrameToWindow(ev, GetFacet(ev), aqHiliteShape);
  272.     
  273.     ::ShowDragHilite(fSession->GetDragAndDrop(ev)->GetDragReference(ev), 
  274.                      aqHiliteShape->GetQDRegion(ev), 
  275.                      showInside);
  276.     fMacHiliteOn = TRUE;
  277.     fSavedHiliteState = FALSE;
  278. #endif
  279. }
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //    FW_CDropTracker::HideDragHilite
  283. //----------------------------------------------------------------------------------------
  284.  
  285. void FW_CDropTracker::HideDragHilite(Environment* ev)
  286. {
  287. #ifdef FW_BUILD_MAC
  288.     if (fMacHiliteOn)
  289.     {
  290.         FW_CWindowContext gc(ev, GetFacet(ev));        // focus drawing to the window
  291.         ::HideDragHilite(fSession->GetDragAndDrop(ev)->GetDragReference(ev));
  292.         
  293.         fMacHiliteOn = FALSE;
  294.     }
  295. #endif
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. //    FW_CDropTracker::PrivShowDefaultHilite
  300. //----------------------------------------------------------------------------------------
  301.  
  302. void FW_CDropTracker::PrivShowDefaultHilite(Environment* ev)
  303. {
  304.     FW_CAcquiredODShape aqHiliteShape = GetView(ev)->GetFrame(ev)->GetDroppable(ev)->AcquireDragHiliteShape(ev, GetFacet(ev));
  305.     this->ShowDragHilite(ev, aqHiliteShape, TRUE);
  306. }
  307.  
  308. //========================================================================================
  309. //    class FW_CTracker
  310. //========================================================================================
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    FW_CTracker::FW_CTracker
  314. //----------------------------------------------------------------------------------------
  315.  
  316. FW_CTracker::FW_CTracker(Environment *ev, FW_CView* view, ODFacet* facet, FW_Boolean waitMouseMoved) :
  317.     FW_CBaseTracker(ev, view, facet),
  318.     fWaitMouseMoved(waitMouseMoved)
  319. {
  320. }
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    FW_CTracker::~FW_CTracker
  324. //----------------------------------------------------------------------------------------
  325.  
  326. FW_CTracker::~FW_CTracker()
  327. {
  328. }
  329.  
  330. //----------------------------------------------------------------------------------------
  331. //     FW_CTracker::Track
  332. //----------------------------------------------------------------------------------------
  333.  
  334. FW_Boolean FW_CTracker::Track(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  335. {
  336.     FW_ASSERT(GetFacet(ev) != NULL);
  337.     FW_ASSERT(GetView(ev) != NULL);
  338.  
  339.     // ----- Flush update event pending for this window
  340.     FW_CAcquiredODWindow aqWindow = GetFacet(ev)->GetFrame(ev)->AcquireWindow(ev);
  341.     aqWindow->Update(ev);
  342.     
  343.     if (fWaitMouseMoved && !theMouseEvent.WaitUntilMouseMoved(ev))
  344.         return FALSE;
  345.     
  346.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  347.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, GetFacet(ev)->GetFrame(ev));
  348.     frame->GetContentView(ev)->FrameToViewContent(ev, where);
  349.  
  350.     fAnchorPoint = BeginTracking(ev, where);
  351.     
  352.     FW_CPoint currentLoc;
  353.     fPreviousPoint = fAnchorPoint;
  354.     
  355.     do  
  356.     {    
  357.         {
  358.             FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  359.             currentLoc = ::FW_GetMouseLocation(aqWindow, vc);
  360.         }
  361.         
  362.         fPreviousPoint = ContinueTracking(ev, fAnchorPoint, fPreviousPoint, currentLoc);
  363.     } 
  364.     while (FW_WaitMouseUp());
  365.     
  366.     return EndTracking(ev, fAnchorPoint, currentLoc);
  367. }
  368.  
  369.