home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWDrgDrp.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  14.1 KB  |  514 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDrgDrp.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 FWDRGDRP_H
  13. #include "FWDrgDrp.h"
  14. #endif
  15.  
  16. #ifndef FWPART_H
  17. #include "FWPart.h"
  18. #endif
  19.  
  20. #ifndef FWFRAME_H
  21. #include "FWFrame.h"
  22. #endif
  23.  
  24. #ifndef FWSELECT_H
  25. #include "FWSelect.h"
  26. #endif
  27.  
  28. #ifndef FWDRCMD_H
  29. #include "FWDrCmd.h"
  30. #endif
  31.  
  32. #ifndef FWTRACKR_H
  33. #include "FWTrackr.h"
  34. #endif
  35.  
  36. #ifndef FWUTIL_H
  37. #include "FWUtil.h"
  38. #endif
  39.  
  40. #ifndef FWCONTXT_H
  41. #include "FWContxt.h"
  42. #endif
  43.  
  44. #ifndef FWPRESEN_H
  45. #include "FWPresen.h"
  46. #endif
  47.  
  48. // ----- OS Includes -----
  49.  
  50. #ifndef FWEVENT_H
  51. #include "FWEvent.h"
  52. #endif
  53.  
  54. #ifndef FWBARRAY_H
  55. #include "FWBArray.h"
  56. #endif
  57.  
  58. #ifndef FWACQUIR_H
  59. #include "FWAcquir.h"
  60. #endif
  61.  
  62. // ----- Foundation Includes -----
  63.  
  64. #ifndef FWMEMMGR_H
  65. #include "FWMemMgr.h"
  66. #endif
  67.  
  68. #ifndef FWDEBUG_H
  69. #include "FWDebug.h"
  70. #endif
  71.  
  72. // ----- OpenDoc Includes -----
  73.  
  74. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  75. #include <StdDefs.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODDragAndDrop_xh
  79. #include <DragDrp.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODDragItemIterator_xh
  83. #include <DgItmIt.xh>
  84. #endif
  85.  
  86. #ifndef SOM_ODSession_xh
  87. #include <ODSessn.xh>
  88. #endif
  89.  
  90. #ifndef SOM_ODTranslation_xh
  91. #include <Translt.xh>
  92. #endif
  93.  
  94. #ifndef SOM_ODTransform_xh
  95. #include <Trnsform.xh>
  96. #endif
  97.  
  98. #ifndef SOM_Module_OpenDoc_StdProps_defined
  99. #include <StdProps.xh>
  100. #endif
  101.  
  102. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  103. #include <StdTypes.xh>
  104. #endif
  105.  
  106. // ----- Macintosh Includes -----
  107.  
  108. #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
  109. #include <Drag.h>
  110. #endif
  111.  
  112. //========================================================================================
  113. //    RunTime Info
  114. //========================================================================================
  115.  
  116. #ifdef FW_BUILD_MAC
  117. #pragma segment FWFrameworkCommands
  118. #endif
  119.  
  120. //========================================================================================
  121. //    class FW_MDraggableFrame
  122. //========================================================================================
  123.  
  124. FW_DEFINE_CLASS_M0(FW_MDraggableFrame)
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    FW_MDraggableFrame::FW_MDraggableFrame
  128. //----------------------------------------------------------------------------------------
  129.  
  130. FW_MDraggableFrame::FW_MDraggableFrame(Environment *ev, FW_CFrame* frame) :
  131.     fPart(frame->GetPart(ev)),
  132.     fFrame(frame)
  133. {
  134.     fFrame->PrivSetDraggable(ev, this);
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    FW_MDraggableFrame::~FW_MDraggableFrame
  139. //----------------------------------------------------------------------------------------
  140.  
  141. FW_MDraggableFrame::~FW_MDraggableFrame()
  142. {
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_MDraggableFrame::Drag
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_Boolean FW_MDraggableFrame::Drag(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  150. {
  151.     if (!theMouseEvent.WaitUntilMouseMoved(ev))
  152.         return FALSE;
  153.  
  154. #ifdef FW_DEBUG    
  155.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, theMouseEvent.GetFacet(ev)->GetFrame(ev));
  156.     FW_ASSERT(frame == fFrame);
  157. #endif    
  158.  
  159.     FW_CDragCommand* dragCommand = this->NewDragCommand(ev, fFrame, theMouseEvent);
  160.     if (dragCommand)
  161.     {
  162.         FW_CPresentation* presentation = fFrame->GetPresentation(ev);
  163.         presentation->PrivSetDragPending(TRUE);
  164.  
  165.         FW_TRY
  166.         {
  167.             dragCommand->BeginDrag(ev, theMouseEvent);
  168.             dragCommand->Execute(ev);
  169.         }
  170.         FW_CATCH_BEGIN
  171.         FW_CATCH_EVERYTHING()
  172.         {
  173.             presentation->PrivSetDragPending(FALSE);
  174.             
  175.             FW_THROW_SAME();
  176.         }
  177.         FW_CATCH_END
  178.         
  179.         presentation->PrivSetDragPending(FALSE);
  180.  
  181.         return TRUE;
  182.     }
  183.  
  184.     return FALSE;
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. //    FW_MDraggableFrame::SetDragging
  189. //----------------------------------------------------------------------------------------
  190.  
  191. void FW_MDraggableFrame::SetDragging(Environment* ev, FW_Boolean dragging)
  192. {
  193.     fFrame->GetODFrame(ev)->SetDragging(ev, dragging);
  194. }
  195.  
  196. //========================================================================================
  197. //    class FW_MDroppableFrame
  198. //========================================================================================
  199.  
  200. FW_DEFINE_CLASS_M0(FW_MDroppableFrame)
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    FW_MDroppableFrame::FW_MDroppableFrame
  204. //----------------------------------------------------------------------------------------
  205.  
  206. FW_MDroppableFrame::FW_MDroppableFrame(Environment *ev, FW_CFrame* frame) :
  207.     fPart(frame->GetPart(ev)),
  208.     fFrame(frame),
  209.     fCursorInContent(FALSE),
  210.     fCanAcceptDrop(FALSE),
  211.     fDropTracker(NULL)
  212. {
  213.     FW_ASSERT(fFrame);
  214.     
  215.     fFrame->PrivSetDroppable(ev, this, PrivIsDroppable(ev));
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    FW_MDroppableFrame::~FW_MDroppableFrame
  220. //----------------------------------------------------------------------------------------
  221.  
  222. FW_MDroppableFrame::~FW_MDroppableFrame()
  223. {
  224.     delete    fDropTracker;
  225.     fDropTracker = NULL;
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. //    FW_MDroppableFrame::GetCanAcceptDrop
  230. //----------------------------------------------------------------------------------------
  231.  
  232. FW_Boolean FW_MDroppableFrame::GetCanAcceptDrop(Environment* ev) const
  233. {
  234. FW_UNUSED(ev);
  235.  
  236.     return fCanAcceptDrop && PrivIsDroppable(ev);
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    FW_MDroppableFrame::GetDropTracker
  241. //----------------------------------------------------------------------------------------
  242.  
  243. FW_CDropTracker* FW_MDroppableFrame::GetDropTracker(Environment* ev) const
  244. {
  245. FW_UNUSED(ev);
  246.     return fDropTracker;
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250. //    FW_MDroppableFrame::ChangeDroppableState
  251. //----------------------------------------------------------------------------------------
  252.  
  253. void FW_MDroppableFrame::ChangeDroppableState(Environment* ev, FW_DroppableState droppable)
  254. {
  255.     fFrame->PrivSetDroppableState(droppable);
  256.     fFrame->PrivSetDroppable(ev, this, PrivIsDroppable(ev));
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_MDroppableFrame::CanAcceptDrop
  261. //----------------------------------------------------------------------------------------
  262.  
  263. ODDragResult FW_MDroppableFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  264. {
  265.     ODDragResult canAcceptDrop = FALSE;
  266.     
  267.     if (PrivIsDroppable(ev))
  268.     {
  269.         ODStorageUnit *dragSU;
  270.         ODTranslation *translate = fPart->GetSession(ev)->GetTranslation(ev);
  271.         ODType applehfs = translate->GetISOTypeFromPlatformType(ev, 0x68667320UL, kODPlatformDataType); // 'hfs '
  272.     
  273.         for (dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
  274.             if (dragSU->Exists(ev, kODPropContents, fPart->GetPartKind(ev), 0))
  275.             {
  276.                 canAcceptDrop = TRUE;
  277.                 break;
  278.             }
  279.             else if (dragSU->Exists(ev, kODPropContents, applehfs, 0))
  280.             {
  281. #ifdef FW_BUILD_MAC
  282.                 HFSFlavor *valueData;
  283.                 long valueSize;
  284.                 
  285.                 dragSU->Focus(ev, kODPropContents, kODPosUndefined, applehfs, 0, kODPosUndefined);        
  286.                 valueSize = dragSU->GetSize(ev);
  287.                 valueData = (HFSFlavor*)FW_CMemoryManager::AllocateBlock(valueSize);
  288.                 if (valueData)
  289.                 {
  290.                     FW_CByteArray byteArray;    
  291.                     dragSU->GetValue(ev, valueSize, byteArray);
  292.                     byteArray.CopyBuffer(valueData, valueSize);
  293.                     
  294.                     if (valueData->fileType == 'bnto')
  295.                     {
  296.                         canAcceptDrop = TRUE;
  297.                         break;
  298.                     }
  299.                 }
  300.                 FW_CMemoryManager::FreeBlock(valueData);
  301. #endif
  302.             }
  303.     }
  304.     
  305.     return canAcceptDrop;
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    FW_MDroppableFrame::DragEnter
  310. //----------------------------------------------------------------------------------------
  311. // 'where' is in frame coordinate
  312.  
  313. ODDragResult FW_MDroppableFrame::DragEnter(Environment *ev, 
  314.                                             ODFacet* facet, 
  315.                                             ODDragItemIterator* dragInfo, 
  316.                                             const FW_CPoint& where)
  317. {    
  318. FW_UNUSED(where);
  319.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  320.     FW_ASSERT(frame != NULL);
  321.  
  322.     FW_CView* contentView = frame->GetContentView(ev);
  323.     FW_ASSERT(contentView != NULL);
  324.     
  325.     fCanAcceptDrop = fPart->IsReadOnly(ev) ? FALSE : CanAcceptDrop(ev, dragInfo);
  326.     
  327.     fDropTracker = NewDropTracker(ev, contentView, facet);
  328.     
  329.     fCursorInContent = FALSE;
  330.         
  331.     return fCanAcceptDrop;
  332. }
  333.  
  334. //----------------------------------------------------------------------------------------
  335. //    FW_MDroppableFrame::DragWithin
  336. //----------------------------------------------------------------------------------------
  337. // 'where' is in frame coordinate
  338.  
  339. ODDragResult FW_MDroppableFrame::DragWithin(Environment* ev, 
  340.                                             ODFacet* facet, 
  341.                                             ODDragItemIterator* dragInfo, 
  342.                                             const FW_CPoint& where)
  343. {
  344.     FW_UNUSED(dragInfo);
  345.  
  346.     if (!fCanAcceptDrop)
  347.         return FALSE;
  348.         
  349. // [HLX] OpenDoc Bug Begin
  350. //    OpenDoc sometimes call DragWithin without calling DragEnter
  351.     if (fDropTracker == NULL)
  352.         DragEnter(ev, facet, dragInfo, where);
  353. //     [HLX] OpenDoc Bug End    
  354.  
  355.     ODSession* session = fPart->GetSession(ev);
  356.     unsigned long attributes = session->GetDragAndDrop(ev)->GetDragAttributes(ev);
  357.  
  358.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  359.     FW_ASSERT(frame != NULL);
  360.  
  361.     FW_CView* contentView = frame->GetContentView(ev);
  362.     
  363.     FW_Boolean cursorInContent = contentView->IsMouseWithin(ev, facet, where);
  364.     
  365.     if (cursorInContent)
  366.     {
  367.         if (!fCursorInContent)
  368.             fDropTracker->HandleBeginTracking(ev, where, attributes);
  369.     }
  370.     else
  371.     {
  372.         if (fCursorInContent)
  373.             fDropTracker->HandleEndTracking(ev, where);
  374.     }
  375.     
  376.     fCursorInContent = cursorInContent;
  377.     
  378.     if (fCursorInContent)
  379.         fDropTracker->HandleContinueTracking(ev, where);
  380.         
  381.     return TRUE;
  382. }
  383.  
  384. //----------------------------------------------------------------------------------------
  385. //    FW_MDroppableFrame::DragLeave
  386. //----------------------------------------------------------------------------------------
  387. // 'where' is in frame coordinate
  388.  
  389. void FW_MDroppableFrame::DragLeave(Environment *ev, ODFacet* facet, const FW_CPoint& where)
  390. {
  391. FW_UNUSED(facet);
  392.     if (!fCanAcceptDrop)
  393.         return;
  394.     
  395.     FW_ASSERT(fDropTracker);
  396.     
  397.     if (fCursorInContent)    
  398.         fDropTracker->HandleEndTracking(ev, where);
  399.     
  400.     fCursorInContent = FALSE;
  401.     
  402.     // If there was a tracker delete it
  403.     delete fDropTracker;        
  404.     fDropTracker = NULL;
  405. }
  406.  
  407. //----------------------------------------------------------------------------------------
  408. //    FW_MDroppableFrame::AcquireDragHiliteShape
  409. //----------------------------------------------------------------------------------------
  410.  
  411. ODShape* FW_MDroppableFrame::AcquireDragHiliteShape(Environment* ev, ODFacet* facet)
  412. {
  413. FW_UNUSED(facet);
  414.  
  415.     FW_ASSERT(fFrame->GetODFrame(ev) == facet->GetFrame(ev));
  416.     return fFrame->AcquireContentShape(ev);
  417. }
  418.  
  419. //----------------------------------------------------------------------------------------
  420. //    FW_MDroppableFrame::Drop    
  421. //----------------------------------------------------------------------------------------
  422.  
  423. FW_DECLARE_THROW_POINT (FW_MDroppableFrame_Drop_BeforePerform);
  424.  
  425. ODDropResult FW_MDroppableFrame::Drop(Environment *ev, ODDragItemIterator* dropInfo,
  426.                                     ODFacet* facet, const FW_CPoint& where)    // in frame coordinate
  427. {
  428.     ODDropResult dropResult = kODDropFail;
  429.  
  430.     if (fCursorInContent)
  431.     {
  432.         FW_ASSERT(fDropTracker);
  433.         fDropTracker->HandleEndTracking(ev, where);
  434.     }
  435.     
  436.     delete fDropTracker;    
  437.     fDropTracker = NULL;
  438.  
  439.     if (fPart->IsReadOnly(ev))
  440.         return dropResult;
  441.  
  442.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  443.     FW_ASSERT(frame != NULL);
  444.             
  445.     // ----- 'where' is in frame coordinate. Put it in content coordinate
  446.     FW_CPoint dropPoint(where);
  447.     FW_FrameToContent(ev, frame->GetODFrame(ev), dropPoint);
  448.     
  449.     FW_CDropCommand* dropCommand = this->NewDropCommand(ev, frame, dropInfo, facet, dropPoint);
  450.     
  451.     if (dropCommand)
  452.     {
  453.         FW_Boolean undoable = dropCommand->Execute(ev, FALSE);    // do not delete if not undoable        
  454.         
  455.         dropResult = dropCommand->GetDropResult(ev);
  456.         
  457.         if (!undoable)
  458.             delete dropCommand;
  459.     }
  460.  
  461.     return dropResult;
  462. }
  463.  
  464. //----------------------------------------------------------------------------------------
  465. //    FW_MDroppableFrame::NewDropTracker
  466. //----------------------------------------------------------------------------------------
  467.  
  468. FW_CDropTracker* FW_MDroppableFrame::NewDropTracker(Environment *ev, FW_CView* view, ODFacet* facet)
  469. {
  470.     return new FW_CDropTracker(ev, view, facet);
  471. }
  472.  
  473. //----------------------------------------------------------------------------------------
  474. //    FW_MDroppableFrame::GetDroppableState
  475. //----------------------------------------------------------------------------------------
  476.  
  477. FW_DroppableState FW_MDroppableFrame::GetDroppableState(Environment* ev) const
  478. {
  479. FW_UNUSED(ev);
  480.  
  481.     return fFrame->PrivGetDroppableState();
  482. }
  483.  
  484. //----------------------------------------------------------------------------------------
  485. //    FW_MDroppableFrame::PrivIsDroppable
  486. //----------------------------------------------------------------------------------------
  487.  
  488. FW_Boolean FW_MDroppableFrame::PrivIsDroppable(Environment *ev) const
  489. {
  490.     return FW_MDroppableFrame::PrivDroppableStateToBoolean(fFrame->PrivGetDroppableState(), fFrame->GetViewType(ev));
  491. }
  492.  
  493. //----------------------------------------------------------------------------------------
  494. //    FW_MDroppableFrame::PrivDroppableStateToBoolean
  495. //----------------------------------------------------------------------------------------
  496.  
  497. FW_Boolean FW_MDroppableFrame::PrivDroppableStateToBoolean(FW_DroppableState droppable, ODTypeToken viewType)
  498. {
  499.     if (droppable == FW_kNotDroppable)
  500.         return FALSE;
  501.     else if (((droppable & FW_kFrameDroppable) != 0)  && (viewType == FW_CPart::gViewAsFrameToken))
  502.         return TRUE;
  503.     else if (((droppable & FW_kThumbnailDroppable) != 0)  && (viewType == FW_CPart::gViewAsThumbnailToken))
  504.         return TRUE;
  505.     else if (((droppable & FW_kIconDroppable) != 0)  && (viewType == FW_CPart::gViewAsSmallIconToken || viewType == FW_CPart::gViewAsLargeIconToken))
  506.         return TRUE;
  507.     
  508.     return FALSE;
  509. }
  510.  
  511.  
  512.  
  513.  
  514.