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 / Selection.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  10.7 KB  |  378 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Selection.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. // ----- TablePart Includes -----
  13.  
  14. #ifndef SELECTION_H
  15. #include "Selection.h"
  16. #endif
  17.  
  18. #ifndef PROXY_H
  19. #include "Proxy.h"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef LINKING_H
  27. #include "Linking.h"
  28. #endif
  29.  
  30. #ifndef CONTENT_H
  31. #include "Content.h"
  32. #endif
  33.  
  34. // ----- ODF Includes -----
  35.  
  36. #ifndef FWFRAME_H
  37. #include "FWFrame.h"
  38. #endif
  39.  
  40. #ifndef FWRECT_H
  41. #include "FWRect.h"
  42. #endif
  43.  
  44. #ifndef FWUTIL_H
  45. #include "FWUtil.h"
  46. #endif
  47.  
  48. #ifndef FWPRESEN_H
  49. #include "FWPresen.h"
  50. #endif
  51.  
  52. #ifndef FWITERS_H
  53. #include "FWIters.h"
  54. #endif
  55.  
  56. #ifndef FWCONTXT_H
  57. #include "FWContxt.h"
  58. #endif
  59.  
  60. // ----- OS Layer -----
  61.  
  62. #ifndef FWODGEOM_H
  63. #include "FWODGeom.h"
  64. #endif
  65.  
  66. #ifndef FWEVENT_H
  67. #include "FWEvent.h"
  68. #endif
  69.  
  70. // ----- OpenDoc Includes -----
  71.  
  72. #ifndef SOM_ODShape_xh
  73. #include <Shape.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODTransform_xh
  77. #include <Trnsform.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODSession_xh
  81. #include <ODSessn.xh>
  82. #endif
  83.  
  84. //========================================================================================
  85. // RunTime Info
  86. //========================================================================================
  87.  
  88. #ifdef FW_BUILD_MAC
  89. #pragma segment odfTable
  90. #endif
  91.  
  92. FW_DEFINE_AUTO(CTableSelection)
  93.  
  94. //========================================================================================
  95. //    class CTableSelection
  96. //========================================================================================
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    CTableSelection::CTableSelection
  100. //----------------------------------------------------------------------------------------
  101.  
  102. CTableSelection::CTableSelection(Environment* ev, CTablePart* tablePart, CTableContent* content) :
  103.     FW_CSelection(ev, true, true),    // allow linking
  104.     fTablePart(tablePart),
  105.     fTableContent(content)
  106. {
  107.     fSelectionContent = FW_NEW(CTableSelectionContent, (ev, tablePart, content));
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    CTableSelection::~CTableSelection
  112. //----------------------------------------------------------------------------------------
  113.  
  114. CTableSelection::~CTableSelection()
  115. {
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. //    CTableSelection::GetSelectedContent
  120. //----------------------------------------------------------------------------------------
  121.  
  122. FW_CContent* CTableSelection::GetSelectedContent(Environment* ev)
  123. {
  124.     return fSelectionContent;
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    CTableSelection::IsEmpty
  129. //----------------------------------------------------------------------------------------
  130.  
  131. FW_Boolean CTableSelection::IsEmpty(Environment* ev) const
  132. {
  133.     return fSelectionContent->GetSelectedProxy(ev) == NULL;
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    CTableSelection::CloseSelection
  138. //----------------------------------------------------------------------------------------
  139.  
  140. void CTableSelection::CloseSelection(Environment* ev)
  141. {
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. //    CTableSelection::ClearSelection
  146. //----------------------------------------------------------------------------------------
  147.  
  148. void CTableSelection::ClearSelection(Environment* ev)
  149. {
  150.     CTableProxy* proxy = fSelectionContent->GetSelectedProxy(ev);
  151.     if (proxy)
  152.     {
  153.         fTablePart->AboutToClearCell(ev, fSelectionContent->GetCell());    // break existing links before removing the proxy
  154.  
  155.         fTablePart->PartChanged(ev);
  156.  
  157.         //--- Remove the proxy ---
  158.         proxy->DetachEmbeddedFrames(ev);
  159.         fTableContent->RemoveProxy(proxy);
  160.         InvalidateSelection(ev);
  161.     }
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    CTableSelection::SelectAll
  166. //----------------------------------------------------------------------------------------
  167.  
  168. void CTableSelection::SelectAll(Environment* ev)
  169. {
  170. }
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    CTableSelection::Select
  174. //----------------------------------------------------------------------------------------
  175.  
  176. void CTableSelection::Select(Environment* ev, const CCell& cell)
  177. {
  178.     // Get the active frame
  179.     CTableFrame* activeFrame = (CTableFrame*)fTablePart->GetLastActiveFrame(ev);
  180.  
  181.     // Get the previous selected cell and proxy
  182.     CCell oldCell = fSelectionContent->GetCell();
  183.     CTableProxy* proxy = fTableContent->CellToProxy(oldCell);
  184.  
  185.     // Get the link manager so we can check for links
  186.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  187.     CTableLink* link = NULL;
  188.     CTableLinkSource* linkSource = NULL;
  189.  
  190.     // if the previous selected cell was containing a proxy then change its selected state
  191.     // and change its hilite
  192.     if (proxy)
  193.     {
  194.         proxy->Selected(FALSE);
  195.  
  196.         link = linkMgr->CellToLink(ev, oldCell);
  197.         if (link)
  198.             link->Select(ev, false);
  199.         linkSource = linkMgr->CellToSourceLink(ev, oldCell);
  200.         if (linkSource)
  201.             linkSource->Select(ev, false);
  202.     }
  203.     
  204.     // Draw the cell hilite
  205.     if (activeFrame)
  206.         activeFrame->ChangeHiliteState(ev, FALSE);
  207.  
  208.     // select the new cell
  209.     fSelectionContent->SetCell(cell);
  210.     
  211.     // get the proxy contained in the new selected cell
  212.     proxy = fTableContent->CellToProxy(cell);
  213.     
  214.     // if the new selected cell contains a proxy then change its selected state
  215.     // and hilite
  216.     if (proxy)
  217.     {
  218.         proxy->Selected(TRUE);
  219.  
  220.         link = linkMgr->CellToLink(ev, cell);
  221.         if (link)
  222.             link->Select(ev, true);
  223.         linkSource = linkMgr->CellToSourceLink(ev, cell);
  224.         if (linkSource)
  225.             linkSource->Select(ev, true);
  226.     }
  227.  
  228.     // Draw the cell hilite
  229.     if (activeFrame)
  230.         activeFrame->ChangeHiliteState(ev, TRUE);    
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    CTableSelection::CreateSelectionShape
  235. //----------------------------------------------------------------------------------------
  236.  
  237. ODShape* CTableSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
  238. {
  239.     FW_UNUSED(facet);
  240.     FW_UNUSED(frame);
  241.  
  242.     return fSelectionContent->CreateDataFrameShape(ev);
  243. }
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    CTableSelection::InvalidateSelection
  247. //----------------------------------------------------------------------------------------
  248.  
  249. void CTableSelection::InvalidateSelection(Environment* ev)
  250. {
  251.     FW_CAcquiredODShape aqShape(fSelectionContent->CreateDataFrameShape(ev));
  252.     GetPresentation(ev)->Invalidate(ev, aqShape);
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. // CTableSelection::SelectProxy
  257. //----------------------------------------------------------------------------------------
  258.  
  259. void CTableSelection::SelectProxy(Environment* ev, CTableProxy* proxy)
  260. {
  261.     CCell cell = proxy->GetCell();
  262.     this->Select(ev, cell);
  263. }
  264.  
  265. //----------------------------------------------------------------------------------------
  266. // CTableSelection::GetSelectedCell
  267. //----------------------------------------------------------------------------------------
  268.  
  269. CCell CTableSelection::GetSelectedCell() const
  270. {
  271.     return fSelectionContent->GetCell();
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    CTableSelection::IsMouseInDraggableItem
  276. //----------------------------------------------------------------------------------------
  277.  
  278. FW_Boolean CTableSelection::IsMouseInDraggableItem(Environment* ev, 
  279.                                                 FW_CFrame* frame, 
  280.                                                 const FW_CMouseEvent& theMouseEvent, 
  281.                                                 FW_Boolean inBackground)
  282. {
  283.     FW_UNUSED(inBackground);
  284.  
  285.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  286.  
  287.     CCell cell;
  288.     ETableLoc tl = ((CTableFrame*)frame)->HitTest(ev, where, cell);
  289.     
  290.     return (tl == kTLCell && fTableContent->CellToProxy(cell) != NULL);
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. // CTableSelection::UpdateSelectionOnMouseDown
  295. //----------------------------------------------------------------------------------------
  296.  
  297. void CTableSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  298.                                             const FW_CMouseEvent& mouseEvent,
  299.                                             ODFacet* embeddedFacet,
  300.                                             FW_Boolean inEmbeddedFrameBorder,
  301.                                             FW_Boolean inBackground)
  302. {
  303.     FW_UNUSED(inBackground);
  304.  
  305.     CTableFrame* tableFrame = (CTableFrame*)FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
  306.     
  307.     if (tableFrame->IsGridShown(ev))
  308.     {
  309.         FW_Boolean select = FALSE;
  310.         CCell cell;
  311.         
  312.         if (inEmbeddedFrameBorder)
  313.         {
  314.             FW_MProxy* proxy = tableFrame->GetProxy(ev, embeddedFacet->GetFrame(ev));
  315.             FW_ASSERT(proxy);
  316.             
  317.             cell = ((CTableProxy*)proxy)->GetCell();    
  318.             select = TRUE;
  319.         }
  320.         else
  321.         {
  322.             FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  323.     
  324.             ETableLoc tl = tableFrame->HitTest(ev, where, cell);
  325.         
  326.             select = (tl == kTLCell && cell != GetSelectedCell());
  327.         }
  328.         
  329.         if (select)
  330.             Select(ev, cell);
  331.     }
  332. }
  333.  
  334. //----------------------------------------------------------------------------------------
  335. //    CTableSelection::CanPasteAsLink
  336. //---------------------------------------------------------------------------------------
  337.  
  338. FW_Boolean CTableSelection::CanPasteAsLink(Environment* ev, ODPasteAsMergeSetting& setting,
  339.                                             ODStorageUnit* su)
  340. {
  341.     FW_UNUSED(su);
  342.     setting = kODPasteAsEmbedOnly;    // table has no content to merge
  343.  
  344.     // Check whether the selected cell already contains an embedded part.
  345.     // If it doesn't, allow Paste As.
  346.     return this->IsEmpty(ev);
  347. }
  348.  
  349. //----------------------------------------------------------------------------------------
  350. //    CTableSelection::IsSelectionLinkable
  351. //----------------------------------------------------------------------------------------
  352.  
  353. FW_Boolean CTableSelection::IsSelectionLinkable(Environment* ev)
  354. {
  355.     FW_Boolean result = fAllowLinkSource;
  356.  
  357.     if (fAllowLinkSource)
  358.     {
  359.         // make sure the cell is not a link destination
  360.         CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  361.         if (linkMgr->CellToLink(ev, this->GetSelectedCell()))
  362.             result = FALSE;
  363.     }
  364.  
  365.     return result;
  366. }
  367.  
  368. //----------------------------------------------------------------------------------------
  369. //    CTableSelection::DoFindLinkSource
  370. //----------------------------------------------------------------------------------------
  371.  
  372. FW_CLinkSource* CTableSelection::DoFindLinkSource(Environment* ev)    // Override
  373. {
  374.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  375.     return linkMgr->CellToSourceLink(ev, fSelectionContent->GetCell());
  376. }
  377.  
  378.