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 / Table / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  26.8 KB  |  971 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.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 FRAME_H
  15. #include "Frame.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef PROXY_H
  23. #include "Proxy.h"
  24. #endif
  25.  
  26. #ifndef SELECTION_H
  27. #include "Selection.h"
  28. #endif
  29.  
  30. #ifndef TRACKER_H
  31. #include "Tracker.h"
  32. #endif
  33.  
  34. #ifndef COMMANDS_H
  35. #include "Commands.h"
  36. #endif
  37.  
  38. #ifndef LINKING_H
  39. #include "Linking.h"
  40. #endif
  41.  
  42. #ifndef CONTENT_H
  43. #include "Content.h"
  44. #endif
  45.  
  46. // ----- Framework Layer -----
  47.  
  48. #ifndef FWCLPCMD_H
  49. #include "FWClpCmd.h"
  50. #endif
  51.  
  52. #ifndef FWPROXY_H
  53. #include "FWProxy.h"
  54. #endif
  55.  
  56. #ifndef FWUTIL_H
  57. #include "FWUtil.h"
  58. #endif
  59.  
  60. #ifndef FWITERS_H
  61. #include "FWIters.h"
  62. #endif
  63.  
  64. #ifndef FWFCTCLP_H
  65. #include "FWFctClp.h"
  66. #endif
  67.  
  68. #ifndef FWLNKITE_H
  69. #include "FWLnkIte.h"
  70. #endif
  71.  
  72. #ifndef FWGROWBX_H
  73. #include "FWGrowBx.h"
  74. #endif
  75.  
  76. #ifndef FWSCLBAR_H
  77. #include "FWSclBar.h"
  78. #endif
  79.  
  80. // ----- OS Layer -----
  81.  
  82. #ifndef FWEVENT_H
  83. #include "FWEvent.h"
  84. #endif
  85.  
  86. #ifndef FWMNUBAR_H
  87. #include "FWMnuBar.h"
  88. #endif
  89.  
  90. #ifndef FWPOINT_H
  91. #include "FWPoint.h"
  92. #endif
  93.  
  94. #ifndef FWRECSHP_H
  95. #include "FWRecShp.h"
  96. #endif
  97.  
  98. #ifndef FWRECT_H
  99. #include "FWRect.h"
  100. #endif
  101.  
  102. #ifndef FWCFMRES_H
  103. #include "FWCFMRes.h"
  104. #endif
  105.  
  106. #ifndef FWRGNSHP_H
  107. #include "FWRgnShp.h"
  108. #endif
  109.  
  110. #ifndef FWODGEOM_H
  111. #include "FWODGeom.h"
  112. #endif
  113.  
  114. #ifndef FWCURSOR_H
  115. #include "FWCursor.h"
  116. #endif
  117.  
  118. #ifndef FWCONTXT_H
  119. #include "FWContxt.h"
  120. #endif
  121.  
  122. #ifndef FWEVEDEF_H
  123. #include "FWEveDef.h"
  124. #endif
  125.  
  126. // ----- Foundation Layer -----
  127.  
  128. #ifndef FWORDCOL_H
  129. #include "FWOrdCol.h"
  130. #endif
  131.  
  132. // ----- OpenDoc Includes -----
  133.  
  134. #ifndef SOM_ODClipboard_xh
  135. #include <Clipbd.xh>
  136. #endif
  137.  
  138. #ifndef SOM_ODDragItemIterator_xh
  139. #include <DgItmIt.xh>
  140. #endif
  141.  
  142. #ifndef SOM_ODDragAndDrop_xh
  143. #include <DragDrp.xh>
  144. #endif
  145.  
  146. #ifndef FWODTYPS_H
  147. #include "FWODTyps.h"
  148. #endif
  149.  
  150. #ifndef SOM_Module_OpenDoc_StdProps_defined
  151. #include <StdProps.xh>
  152. #endif
  153.  
  154. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  155. #include <StdTypes.xh>
  156. #endif
  157.  
  158. #ifndef SOM_ODStorageUnit_xh
  159. #include <StorageU.xh>
  160. #endif
  161.  
  162. #ifndef SOM_ODTransform_xh
  163. #include <Trnsform.xh>
  164. #endif
  165.  
  166. #ifndef SOM_ODSession_xh
  167. #include <ODSessn.xh>
  168. #endif
  169.  
  170. #ifndef SOM_ODDispatcher_xh
  171. #include <Disptch.xh>
  172. #endif
  173.  
  174. // ----- Macintosh Toolbox Includes -----
  175.  
  176. #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
  177. #include <Resources.h>
  178. #endif
  179.  
  180. //========================================================================================
  181. // RunTime Info
  182. //========================================================================================
  183.  
  184. #ifdef FW_BUILD_MAC
  185. #pragma segment odfTable
  186. #endif
  187.  
  188. FW_DEFINE_AUTO(CTableFrame)
  189.  
  190. //========================================================================================
  191. //    class CTableFrame
  192. //========================================================================================
  193.  
  194. //----------------------------------------------------------------------------------------
  195. //    CTableFrame::CTableFrame
  196. //----------------------------------------------------------------------------------------
  197.  
  198. CTableFrame::CTableFrame(Environment* ev, 
  199.                         ODFrame* odFrame, 
  200.                         FW_CPresentation* presentation, 
  201.                         CTablePart* tablePart,
  202.                         CTableContent* tableContent) :
  203.     FW_CEmbeddingFrame(ev, odFrame, presentation, tablePart),
  204.     FW_MDraggableFrame(ev, this),
  205.     FW_MDroppableFrame(ev, this),
  206.     fTablePart(tablePart),
  207.     fTableContent(tableContent),
  208.     fGridShown(TRUE),
  209.     fHiliteState(FALSE)
  210. {
  211.     ChangeDroppableState(ev, fGridShown ? FW_kFrameDroppable : FW_kNotDroppable);
  212.     fDraggedCell.fX = fDraggedCell.fY = -1;
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    CTableFrame::~CTableFrame
  217. //----------------------------------------------------------------------------------------
  218.  
  219. CTableFrame::~CTableFrame()
  220. {
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    CTableFrame::GetSelection
  225. //----------------------------------------------------------------------------------------
  226.  
  227. CTableSelection* CTableFrame::GetSelection(Environment* ev) const
  228. {
  229.     return (CTableSelection*)GetPresentation(ev)->GetSelection(ev);
  230. }
  231.  
  232. //----------------------------------------------------------------------------------------
  233. //    CTableFrame::DoMenu
  234. //----------------------------------------------------------------------------------------
  235.  
  236. FW_Boolean CTableFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  237. {
  238.     FW_Boolean result = TRUE;
  239.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  240.  
  241.     switch(commandID)
  242.     {
  243.         case cHideShowGrid:
  244.             HideShowGrid(ev);
  245.             break;
  246.  
  247.         default:
  248.             result = FALSE;
  249.             break;
  250.     }
  251.     
  252.     return result;
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. // CTableFrame::HideShowGrid
  257. //----------------------------------------------------------------------------------------
  258.  
  259. void CTableFrame::HideShowGrid(Environment* ev)
  260. {
  261.     fGridShown = !fGridShown;
  262.     ChangeDroppableState(ev, fGridShown ? FW_kFrameDroppable : FW_kNotDroppable);
  263.     
  264.     FW_CFrameFacetIterator ite(ev, this);
  265.     for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  266.     {        
  267.         FW_CViewContext fc(ev, this, facet);    
  268.         DrawGrid(ev, fc, fGridShown);
  269.     }    
  270.  
  271.     ChangeHiliteState(ev, fGridShown);
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    CDrawFrame::DoActivateEvent
  276. //----------------------------------------------------------------------------------------
  277.  
  278. void CTableFrame::DoActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
  279. {
  280.     // Got an activate(/deactivate) event. If I have the selection focus then redraw the hilite
  281.     
  282.     if (fGridShown && HasSelectionFocus(ev))
  283.         ChangeHiliteState(ev, theActivateEvent.IsActivating(ev));
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. // CTableFrame::Draw
  288. //----------------------------------------------------------------------------------------
  289.  
  290. void CTableFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  291. {
  292.     FW_CViewContext fc(ev, this, odFacet, invalidShape);
  293.     
  294.     FW_CRect invalidRect;
  295.     fc.GetClipRect(invalidRect);
  296.     
  297.     // Erase invalid portion of the frame
  298.     FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  299.     
  300.     // Draw the table grid
  301.     if (fGridShown)
  302.         DrawGrid(ev, fc, TRUE);    
  303.  
  304.     // Draw the selection
  305.     if (HasSelectionFocus(ev) && fGridShown && fHiliteState)
  306.         DrawCellHilite(ev, fc, GetSelection(ev)->GetSelectedCell());
  307.  
  308.     //--- Draw Link borders ---
  309.     FW_CAcquiredODWindow aqODWindow = odFacet->GetFrame(ev)->AcquireWindow(ev);
  310.     if (aqODWindow->ShouldShowLinks(ev))
  311.     {
  312.         //--- Draw borders around links ---
  313.         FW_CLinkIterator it(fTablePart->GetLinkManager(ev));
  314.         for (FW_CLink* link = it.FirstLink(); it.IsNotComplete(); link = it.NextLink())
  315.         {
  316.             link->ShowHideLinkBorder(ev, true, odFacet);
  317.         }
  318.     }
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    CTableFrame::ChangeHiliteState
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void CTableFrame::ChangeHiliteState(Environment* ev, FW_Boolean state)
  326. {
  327.     if (state == fHiliteState)
  328.         return;
  329.     
  330.     fHiliteState = state;
  331.     CCell cell = GetSelection(ev)->GetSelectedCell();
  332.     
  333.     FW_CFrameFacetIterator ite(ev, this);
  334.     for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  335.     {        
  336.         FW_CViewContext fc(ev, this, facet);
  337.         DrawCellHilite(ev, fc, cell);
  338.     }
  339.     
  340.     CTableProxy* proxy = fTableContent->CellToProxy(cell);
  341.     if (proxy)
  342.         proxy->ChangeHighlight(ev, state ? kODFullHighlight : kODNoHighlight, this);
  343. }
  344.  
  345. //----------------------------------------------------------------------------------------
  346. //    CTableFrame::DrawCellHilite
  347. //----------------------------------------------------------------------------------------
  348.  
  349. void CTableFrame::DrawCellHilite(Environment* ev, FW_CViewContext& fc, const CCell& cell)
  350. {
  351.     CTableProxy* proxy = fTableContent->CellToProxy(cell);
  352.     if (proxy == NULL)
  353.     {
  354.         FW_CRect rect;
  355.         fTableContent->FindRect(cell, rect);
  356.         FW_CRectShape::RenderRect(fc, rect, FW_kFill, FW_CInk(FW_kHilite));
  357.     }
  358.     else
  359.     {
  360.         FW_CAcquiredODShape hiliteShape = proxy->AcquireHiliteShape(ev, cell, this);
  361.         FW_CRegionShape::RenderRegion(fc, hiliteShape, FW_kFill, FW_CInk(FW_kHilite));
  362.     }
  363. }
  364.  
  365. //---------------------------------------------------------------------------------------
  366. //    CTableFrame::DrawGrid
  367. //---------------------------------------------------------------------------------------
  368.  
  369. void CTableFrame::DrawGrid(Environment* ev, FW_CGraphicContext& gc, FW_Boolean gray)
  370. {
  371.     // Get the frame's rect at (0,0), inset by margins
  372.     FW_CRect rect;
  373.     this->GetRect(ev, rect);
  374.     
  375.     // Draw the table grid
  376.     FW_CLineShape lineShape;
  377.     lineShape.GetStyle().SetPattern(gray ? FW_kGrayPat : FW_kWhitePat);
  378.         
  379.     FW_Fixed xy;
  380.     short rc;
  381.     for(xy = rect.top, rc = 0; xy < rect.bottom; xy += fTableContent->GetHeight(rc++) + kBorderHeight)
  382.     {
  383.         lineShape.SetLineStart(rect.left, xy);
  384.         lineShape.SetLineEnd(rect.right, xy);
  385.         lineShape.Render(gc);
  386.     }
  387.     
  388.     for(xy = rect.left, rc = 0;  xy < rect.right; xy += fTableContent->GetWidth(rc++) + kBorderHeight)
  389.     {
  390.         lineShape.SetLineStart(xy, rect.top);
  391.         lineShape.SetLineEnd(xy, rect.bottom);
  392.         lineShape.Render(gc);
  393.     }
  394. }
  395.  
  396. //---------------------------------------------------------------------------------------
  397. //    CTableFrame::DoAdjustMenus
  398. //---------------------------------------------------------------------------------------
  399.  
  400. FW_Boolean CTableFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  401. {
  402.     if (hasMenuFocus)
  403.     {
  404.         FW_Boolean hasSelection = !GetSelection(ev)->IsEmpty(ev);
  405.         FW_Boolean canEmbedInCell = fGridShown && GetSelection(ev)->IsEmpty(ev);
  406.         
  407.         menuBar->EnableAndToggleCommand(ev, cHideShowGrid, TRUE, fGridShown);
  408.         
  409.         // If an embedded part is selected, change Copy item to "Copy Part"
  410. #if 0
  411.         // CodeWarrior destructs the temporary before passing it into SetItemString!
  412.         menuBar->SetItemString(ev, kODCommandCopy, hasSelection ? FW_CString32("Copy Part") : FW_CString32("Copy"));
  413. #else
  414.         FW_CString32 itemName;
  415.         if (hasSelection)
  416.             itemName = "Copy Part";
  417.         else
  418.             itemName = "Copy";
  419.         menuBar->SetItemString(ev, kODCommandCopy, itemName);
  420. #endif
  421.  
  422.         menuBar->EnableCommand(ev, kODCommandCopy, fGridShown && hasSelection);
  423.         menuBar->EnableCommand(ev, kODCommandClear, fGridShown && hasSelection);
  424.         menuBar->EnableCommand(ev, kODCommandCut, fGridShown && hasSelection);
  425.  
  426.         menuBar->EnableCommand(ev, kODCommandInsert, canEmbedInCell);
  427.  
  428.         // Check clipboard for pastable property
  429.         menuBar->EnableCommand(ev, kODCommandPaste, canEmbedInCell && HasPropertyOnClipboard(ev, kODPropContentFrame, NULL));
  430.         menuBar->EnableCommand(ev, kODCommandPasteAs, canEmbedInCell && HasPropertyOnClipboard(ev, kODPropLinkSpec, kODLinkSpec));
  431.  
  432.         // Because all my embedded frames are always selected I need to do my own enabling
  433.         menuBar->EnableCommand(ev, kODCommandOpen, hasSelection);
  434.     }
  435.     
  436.     return FALSE;
  437. }
  438.  
  439. //----------------------------------------------------------------------------------------
  440. //    CTableFrame::FrameShapeChanged
  441. //----------------------------------------------------------------------------------------
  442.  
  443. void CTableFrame::FrameShapeChanged(Environment* ev)
  444. {
  445.     FW_CEmbeddingFrame::FrameShapeChanged(ev);
  446.     
  447.     // ----- Recalculate the clip of all my embedded facets -----
  448.     FW_CFacetClipper facetClipper(ev, fTablePart);
  449.     facetClipper.Clip(ev, GetPresentation(ev), NULL);
  450. }
  451.  
  452. //----------------------------------------------------------------------------------------
  453. //    CTableFrame::CanAcceptDrop
  454. //----------------------------------------------------------------------------------------
  455. // As an embedding frame I can accept anything
  456.  
  457. ODDragResult CTableFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  458. {
  459.     return TRUE;
  460. }
  461.  
  462. //----------------------------------------------------------------------------------------
  463. //    CTableFrame::DoVirtualKey
  464. //----------------------------------------------------------------------------------------
  465.  
  466. FW_Boolean CTableFrame::DoVirtualKey(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
  467. {
  468.     FW_Boolean    wasHandled = FALSE;
  469.     CCell        cell = this->GetSelection(ev)->GetSelectedCell();
  470.     CCell        size = fTableContent->GetSize();
  471.     
  472.     switch (theVirtualKeyEvent.GetKeyCode(ev))
  473.     {
  474.         case FW_kVKLeft:
  475.             if(cell.fX > 0)
  476.             {
  477.                 cell.fX -= 1;
  478.                 this->SelectCell(ev, cell);
  479.                 wasHandled = TRUE;
  480.             }
  481.             break;
  482.         case FW_kVKRight:
  483.             if(cell.fX < size.fX - 1)
  484.             {
  485.                 cell.fX += 1;
  486.                 this->SelectCell(ev, cell);
  487.                 wasHandled = TRUE;
  488.             }
  489.             break;
  490.         case FW_kVKUp:
  491.             if(cell.fY > 0)
  492.             {
  493.                 cell.fY -= 1;
  494.                 this->SelectCell(ev, cell);
  495.                 wasHandled = TRUE;
  496.             }
  497.             break;
  498.         case FW_kVKDown:
  499.             if(cell.fY < size.fY - 1)
  500.             {
  501.                 cell.fY += 1;
  502.                 this->SelectCell(ev, cell);
  503.                 wasHandled = TRUE;
  504.             }
  505.             break;
  506.  
  507.         case FW_kVKBackspace:
  508.         case FW_kVKClear:
  509.             FW_CClipboardCommand* cmd = this->NewClipboardCommand(ev, kODCommandClear);
  510.             if (cmd)
  511.             {
  512.                 cmd->Execute(ev);
  513.                 wasHandled = TRUE;
  514.             }
  515.             break;
  516.     }
  517.  
  518.     return wasHandled;
  519. }
  520.  
  521. //----------------------------------------------------------------------------------------
  522. //    CTableFrame::DoMouseDown
  523. //----------------------------------------------------------------------------------------
  524.  
  525. FW_Boolean CTableFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  526. {
  527.     FW_Boolean result = FALSE;
  528.  
  529.     if (fGridShown)
  530.     {        
  531.         if (GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
  532.         {
  533.             result = Drag(ev, theMouseEvent);
  534.         }
  535.         else 
  536.         {    
  537.             FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  538.     
  539.             CCell cell;
  540.             ETableLoc tl = HitTest(ev, where, cell);
  541.             
  542.             if (tl != kTLNone && tl != kTLCell)
  543.                 this->Resize(ev, theMouseEvent, cell, tl);
  544.             
  545.             result = TRUE;
  546.         }
  547.     }
  548.     
  549.     return result;
  550. }
  551.     
  552. //----------------------------------------------------------------------------------------
  553. //    CTableFrame::DoMouseDownInEmbeddedFrameBorder
  554. //----------------------------------------------------------------------------------------
  555.  
  556. FW_Boolean CTableFrame::DoMouseDownInEmbeddedFrameBorder(Environment* ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  557. {
  558.     FW_Boolean result = FALSE;
  559.     
  560.     if (fGridShown)
  561.         result = this->Drag(ev, theBorderMouseEvent);
  562.     
  563.     return result;
  564. }
  565.  
  566. //----------------------------------------------------------------------------------------
  567. //    CTableFrame::SelectCell
  568. //----------------------------------------------------------------------------------------
  569.  
  570. void CTableFrame::SelectCell(Environment* ev, const CCell& cell)
  571. {
  572.     GetSelection(ev)->Select(ev, cell);
  573. }
  574.  
  575. //----------------------------------------------------------------------------------------
  576. //    CTableFrame::Resize
  577. //----------------------------------------------------------------------------------------
  578.  
  579. FW_Boolean CTableFrame::Resize(Environment* ev, 
  580.                                const FW_CMouseEvent& theMouseEvent,
  581.                                const CCell& cell,
  582.                                ETableLoc tl)
  583. {
  584.     FW_ASSERT(tl != kTLNone && tl != kTLCell);
  585.     FW_Boolean result = FALSE;
  586.  
  587.     // maximum rectangle
  588.     FW_CRect maxRect;
  589.     this->GetRect(ev, maxRect);
  590.     maxRect.right  -= kPenWidth;
  591.     maxRect.bottom -= kPenHeight;
  592.  
  593.     // Location of borders
  594.     FW_CRect cellRect;
  595.     fTableContent->FindRect(cell, cellRect);
  596.     
  597.     FW_CPoint borders;
  598.     if ((tl & kTLLeftBorder) != 0)
  599.     {
  600.         maxRect.left = ((cell.fX == 0) ? cellRect.left : fTableContent->FindLeft(cell.fX - 1)) + kBorderWidth;
  601.         borders.x = cellRect.left;
  602.     }
  603.     else 
  604.     {
  605.         maxRect.left = cellRect.left + kBorderWidth;
  606.         borders.x = cellRect.right;
  607.     }
  608.         
  609.     if ((tl & kTLTopBorder) != 0)
  610.     {
  611.         maxRect.top = ((cell.fY == 0) ? cellRect.top : fTableContent->FindTop(cell.fY - 1)) + kBorderHeight;
  612.         borders.y = cellRect.top;
  613.     }
  614.     else 
  615.     {
  616.         maxRect.top = cellRect.top + kBorderHeight;
  617.         borders.y = cellRect.bottom;
  618.     }
  619.     
  620.  
  621.     // Create a tracker for the grid lines
  622.     CGridLineTracker tracker(ev, this, theMouseEvent.GetFacet(ev), tl, maxRect, borders);
  623.  
  624.     if (tracker.Track(ev, theMouseEvent))
  625.     {
  626.         // Set the new cell size
  627.         FW_CPoint delta = tracker.GetNewBorders() - tracker.GetOldBorders();
  628.         if (delta.x != FW_kFixed0 || delta.y != FW_kFixed0)
  629.         {
  630.             fTableContent->Resize(ev, cell, tl, delta);
  631.             GetPresentation(ev)->Invalidate(ev);
  632.             result = TRUE;
  633.         }
  634.     }
  635.  
  636.     return result;
  637. }
  638.  
  639. //----------------------------------------------------------------------------------------
  640. //    CTableFrame::Drag
  641. //----------------------------------------------------------------------------------------
  642.  
  643. FW_Boolean CTableFrame::Drag(Environment* ev, const FW_CMouseEvent& event)
  644. {
  645.     fDraggedCell = GetSelection(ev)->GetSelectedCell();
  646.     
  647.     FW_Boolean result = FW_MDraggableFrame::Drag(ev, event);
  648.     
  649.     fDraggedCell.fX = fDraggedCell.fY = -1;
  650.     
  651.     return result;
  652. }
  653.  
  654. //----------------------------------------------------------------------------------------
  655. //    CTableFrame::FocusStateChanged
  656. //----------------------------------------------------------------------------------------
  657.  
  658. void CTableFrame::FocusStateChanged(Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  659. {    
  660.     FW_CEmbeddingFrame::FocusStateChanged(ev, focus, newState, newOwner);
  661.  
  662.     if (focus == FW_CPart::gSelectionFocusToken)
  663.     {        
  664.         //    • If I get the selection focus I redraw the hilite only if the window is not active
  665.         //    if the window is active they already have been redrawn by DoActivateEvent
  666.         //    • If I am loosing the selection focus I redraw the hilite only if the window is active
  667.         //    if the window is not active they already have been redrawn by DoActivateEvent
  668.         //    The events order is:
  669.         //        - Window 1 deactivated
  670.         //        - Frame 1 lose selection focus
  671.         //        - Frame 2 gain selection focus
  672.         //        - Window 2 activated
  673.         FW_Boolean windowActive = GetWindow(ev)->IsActive(ev);
  674.         FW_Boolean hilite = newState ? !windowActive : windowActive;
  675.         if (hilite && fGridShown)
  676.             ChangeHiliteState(ev, newState);
  677.     }
  678. }
  679.  
  680. //----------------------------------------------------------------------------------------
  681. //    CTableFrame::AdjustCursor
  682. //----------------------------------------------------------------------------------------
  683.  
  684. FW_Boolean CTableFrame::AdjustCursor(Environment* ev, ODFacet* odFacet, const FW_CPoint& where)
  685. {
  686.     FW_Boolean cursorAdjusted = FALSE;
  687.     
  688.     //     I don't want the Open Hand Cursor if I have the grid hidden because I am not supposed to
  689.     //    be able to move anything
  690.     if (fGridShown)
  691.         cursorAdjusted = FW_CEmbeddingFrame::AdjustCursor(ev, odFacet, where);
  692.     
  693.     if (!cursorAdjusted && fGridShown)
  694.     {
  695.         CCell cell;
  696.         ETableLoc tl = HitTest(ev, where, cell);
  697.             
  698.         cursorAdjusted = TRUE;
  699.         
  700.         if (tl == kTLCell || tl == kTLNone)
  701.             FW_gArrowCursor.Select();
  702.         else if (tl == kTLLeftBorder || tl == kTLRightBorder)
  703.             FW_gSizeWECursor.Select();
  704.         else if (tl == kTLTopBorder || tl == kTLBottomBorder)
  705.             FW_gSizeNSCursor.Select();
  706.         else 
  707.             FW_gSizeNWSECursor.Select();
  708.     }
  709.     
  710.     return cursorAdjusted;
  711. }
  712.  
  713. //----------------------------------------------------------------------------------------
  714. //    CTableFrame::GetRect
  715. //----------------------------------------------------------------------------------------
  716.  
  717. void CTableFrame::GetRect(Environment* ev, FW_CRect& rect) const
  718. {
  719.     rect = GetBounds(ev);
  720.     rect.left += kHMargin;
  721.     rect.top += kVMargin;
  722. }
  723.  
  724. //----------------------------------------------------------------------------------------
  725. //    CTableFrame::NewDropCommand
  726. //----------------------------------------------------------------------------------------
  727.  
  728. FW_CDropCommand* CTableFrame::NewDropCommand(Environment* ev,
  729.                                             FW_CFrame* frame,
  730.                                             ODDragItemIterator* dropInfo, 
  731.                                             ODFacet* odFacet, 
  732.                                             const FW_CPoint& dropPoint)
  733. {
  734.     FW_ASSERT(frame == this);
  735.     
  736.     CCell dropCell;
  737.     HitTest(ev, dropPoint, dropCell);
  738.  
  739.     if (dropCell == fDraggedCell || fTableContent->CellToProxy(dropCell) != NULL)    // If alreay a proxy gave up
  740.         return NULL;
  741.     else
  742.         return FW_NEW(CCellDropCommand, (ev, fTablePart, fTableContent, this,
  743.                                          dropInfo, odFacet, dropPoint,
  744.                                         dropCell, fDraggedCell));
  745. }
  746.  
  747. //----------------------------------------------------------------------------------------
  748. //    CTableFrame::NewDropTracker
  749. //----------------------------------------------------------------------------------------
  750.  
  751. FW_CDropTracker* CTableFrame::NewDropTracker(Environment *ev, FW_CView* view, ODFacet* facet)
  752. {
  753.     return new CTableDropTracker(ev, fTablePart, fTableContent, this, facet, fDraggedCell);
  754. }
  755.  
  756. //----------------------------------------------------------------------------------------
  757. //    CTableFrame::CreateEmbeddedFacet
  758. //----------------------------------------------------------------------------------------
  759.  
  760. ODFacet* CTableFrame::CreateEmbeddedFacet(Environment* ev,
  761.                                         ODFacet* embeddingFacet,
  762.                                         FW_MProxy* proxy,
  763.                                         ODFrame* embeddedFrame,
  764.                                         ODShape* proposedClipShape)
  765. {
  766.     CCell cell = ((CTableProxy*)proxy)->GetCell();
  767.     
  768.     FW_CRect rect;
  769.     fTableContent->FindRect(cell, rect);
  770.     
  771.     FW_CAcquiredODTransform aqExternalTransform = ::FW_NewODTransform(ev, rect.TopLeft());
  772.  
  773.     return embeddingFacet->CreateEmbeddedFacet(ev,
  774.                                                 embeddedFrame,
  775.                                                 proposedClipShape,
  776.                                                 aqExternalTransform,
  777.                                                 NULL,                    // Canvas
  778.                                                 NULL,                    // biasCanvas
  779.                                                 NULL,                    // siblingFacet
  780.                                                 kODFrameInFront);
  781. }
  782.  
  783. //----------------------------------------------------------------------------------------
  784. // CTableFrame::NewClipboardCommand
  785. //----------------------------------------------------------------------------------------
  786.  
  787. FW_CClipboardCommand* CTableFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  788. {
  789.     return FW_NEW(CTableEditCommand, (ev,
  790.                                       commandID,
  791.                                       fTablePart,
  792.                                       fTableContent,
  793.                                       this,
  794.                                       this->GetSelection(ev)));
  795. }
  796.  
  797. //----------------------------------------------------------------------------------------
  798. // CTableFrame::NewDragCommand
  799. //----------------------------------------------------------------------------------------
  800.  
  801. FW_CDragCommand* CTableFrame::NewDragCommand(Environment* ev, 
  802.                                              FW_CFrame* theFrame,
  803.                                              const FW_CMouseEvent& theMouseEvent)
  804. {
  805.     return FW_NEW(CCellDragCommand, (ev, fTableContent, theFrame, this->GetSelection(ev)));
  806. }
  807.  
  808. //----------------------------------------------------------------------------------------
  809. //    CTableFrame::NewInsertCommand
  810. //----------------------------------------------------------------------------------------
  811. FW_CInsertCommand* CTableFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  812. {
  813.     return FW_NEW(CTableInsertCommand, (ev,
  814.                                         this,
  815.                                         fileSpec,
  816.                                         fTablePart,
  817.                                         GetSelection(ev)->GetSelectedCell()));
  818. }
  819.  
  820. //----------------------------------------------------------------------------------------
  821. // CTableFrame::MoveProxy
  822. //----------------------------------------------------------------------------------------
  823.  
  824. void CTableFrame::MoveProxy(Environment* ev, CTableProxy* proxy, const CCell& destCell)
  825. {
  826.     // Invalidate the source cell
  827.     FW_CRect rect;
  828.     CCell srcCell = proxy->GetCell();
  829.     fTableContent->FindRect(srcCell, rect);
  830.     this->GetPresentation(ev)->Invalidate(ev, rect);
  831.  
  832.     proxy->MoveEmbeddedFrames(ev, destCell);
  833.     proxy->SetCell(destCell);
  834.     this->SelectCell(ev, destCell);
  835.  
  836.     // Invalidate the destination cell
  837.     fTableContent->FindRect(destCell, rect);
  838.     this->GetPresentation(ev)->Invalidate(ev, rect);
  839.  
  840.     // Notify frame
  841.     fTablePart->PartChanged(ev);
  842. }
  843.  
  844. //---------------------------------------------------------------------------------------
  845. //    CTableFrame::FacetAdded
  846. //---------------------------------------------------------------------------------------
  847.  
  848. void CTableFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  849. {
  850.     FW_CEmbeddingFrame::FacetAdded(ev, facet, facetCount);    // call inherited
  851.  
  852.     // We need to register any link destinations that were just internalized.
  853.     fTablePart->RegisterSubscribers(ev);
  854. }
  855.  
  856. //---------------------------------------------------------------------------------------
  857. //    CTableFrame::ShowPartInfo
  858. //---------------------------------------------------------------------------------------
  859.  
  860. void CTableFrame::ShowPartInfo(Environment* ev)
  861. {
  862.     if (fTablePart->ShowLinkInfo(ev, this)) return;
  863.  
  864.     // Table part didn't handle it, so call inherited
  865.     FW_CEmbeddingFrame::ShowPartInfo(ev);
  866. }
  867.  
  868. //---------------------------------------------------------------------------------------
  869. //    CTableFrame::RevealFrame
  870. //---------------------------------------------------------------------------------------
  871. FW_Boolean CTableFrame::RevealFrame(Environment *ev, 
  872.                                     ODFrame* embeddedFrame, 
  873.                                     ODShape* revealShape)
  874. {
  875.     FW_UNUSED(revealShape);
  876.  
  877.     // Change table selection to the cell of the embedded frame
  878.     CTableProxy* proxy = (CTableProxy*) this->GetProxy(ev, embeddedFrame);
  879.     if (proxy)
  880.     {
  881.         this->SelectCell(ev, proxy->GetCell());
  882.         return TRUE;
  883.     }
  884.  
  885.     return FALSE;
  886. }
  887.  
  888. //----------------------------------------------------------------------------------------
  889. //    CTableFrame::HitTest
  890. //----------------------------------------------------------------------------------------
  891.  
  892. ETableLoc CTableFrame::HitTest(Environment* ev, 
  893.                               const FW_CPoint& where,
  894.                               CCell& cell) const
  895. {
  896.     // Verify point is in table area (also exclude the top or left margins)
  897.     FW_CRect rect;
  898.     GetRect(ev, rect);
  899.     
  900.     cell.fX = cell.fY = 0;
  901.  
  902.     if(!rect.Contains(where))
  903.         return kTLNone;
  904.         
  905.     FW_CRect cellRect;
  906.     while (TRUE)
  907.     {
  908.         fTableContent->FindRect(cell, cellRect);
  909.         cellRect.Inset(-kPenWidth, -kPenHeight);
  910.         FW_CPoint testPoint(where.x, cellRect.top);
  911.         if (cellRect.Contains(testPoint))
  912.             break;
  913.         cell.fX += 1;
  914.     } 
  915.     
  916.     while (TRUE)
  917.     {
  918.         fTableContent->FindRect(cell, cellRect);
  919.         cellRect.Inset(-kPenWidth, -kPenHeight);
  920.         FW_CPoint testPoint(cellRect.left, where.y);
  921.         if (cellRect.Contains(testPoint))
  922.             break;
  923.         cell.fY += 1;
  924.     } 
  925.  
  926.     ETableLoc tl = kTLCell;
  927.  
  928.     fTableContent->FindRect(cell, cellRect);
  929.     
  930.     if (where.x <= cellRect.left + kHMargin)
  931.         tl += kTLLeftBorder;
  932.     else if (cellRect.right - kHMargin <= where.x)
  933.         tl += kTLRightBorder;
  934.  
  935.     if (where.y <= cellRect.top + kVMargin)
  936.         tl += kTLTopBorder;
  937.     else if (cellRect.bottom - kVMargin <= where.y)
  938.         tl += kTLBottomBorder;
  939.         
  940.     if (cell.fY == 0 && ((tl & kTLTopBorder) != 0))
  941.         tl = kTLNone;
  942.  
  943.     if (cell.fX == 0 && ((tl & kTLLeftBorder) != 0))
  944.         tl = kTLNone;
  945.             
  946.     return tl;
  947. }
  948.  
  949. //----------------------------------------------------------------------------------------
  950. //     CTableFrame::CreateSubViews
  951. //----------------------------------------------------------------------------------------
  952.  
  953. void CTableFrame::CreateSubViews(Environment* ev)
  954. {        
  955.     // Create a GrowBox only in root frame
  956.     // Note: you do not need CreateSubViews if the views are defined in resources.
  957.     //        See the Container or Form samples.
  958.     
  959.     if (this->IsRoot(ev)) 
  960.     {
  961.         FW_CRect frameRect = GetBounds(ev);  
  962.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  963.         frameRect.right -= sbSize.x;
  964.         frameRect.bottom -= sbSize.y;
  965.         
  966.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
  967.     }
  968. }
  969.  
  970.  
  971.