home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / DrawSel.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  27.4 KB  |  989 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawSel.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef DRAWSEL_H
  15. #include "DrawSel.h"
  16. #endif
  17.  
  18. #ifndef DRAWCONT_H
  19. #include "DrawCont.h"
  20. #endif
  21.  
  22. #ifndef DRAWFRM_H
  23. #include "DrawFrm.h"
  24. #endif
  25.  
  26. #ifndef DRAWPART_H
  27. #include "DrawPart.h"
  28. #endif
  29.  
  30. #ifndef BASESHP_H
  31. #include "BaseShp.h"
  32. #endif
  33.  
  34. #ifndef BOUNDSHP_H
  35. #include "BoundShp.h"
  36. #endif
  37.  
  38. #ifndef LINESHP_H
  39. #include "LineShp.h"
  40. #endif
  41.  
  42. #ifndef OVALSHP_H
  43. #include "OvalShp.h"
  44. #endif
  45.  
  46. #ifndef RECTSHP_H
  47. #include "RectShp.h"
  48. #endif
  49.  
  50. #ifndef RRECTSHP_H
  51. #include "RRectShp.h"
  52. #endif
  53.  
  54. #ifndef TEXTSHP_H
  55. #include "TextShp.h"
  56. #endif
  57.  
  58. #ifndef DRAWCLIP_H
  59. #include "DrawClip.h"
  60. #endif
  61.  
  62. #ifndef DRAWPRXY_H
  63. #include "DrawPrxy.h"
  64. #endif
  65.  
  66. #ifndef UTILS_H
  67. #include "Utils.h"
  68. #endif
  69.  
  70. #ifndef SHPTRAKR_H
  71. #include "ShpTrakr.h"
  72. #endif
  73.  
  74. #ifndef DRAWCMDS_H
  75. #include "DrawCmds.h"
  76. #endif
  77.  
  78. #ifndef DRAWLINK_H
  79. #include "DrawLink.h"
  80. #endif
  81.  
  82. #ifndef DRWPRMSE_H
  83. #include "DrwPrmse.h"
  84. #endif
  85.  
  86. // ----- Part Layer -----
  87.  
  88. #ifndef FWCONTXT_H
  89. #include "FWContxt.h"
  90. #endif
  91.  
  92. #ifndef FWSESION_H
  93. #include "FWSesion.h"
  94. #endif
  95.  
  96. #ifndef FWITERS_H
  97. #include "FWIters.h"
  98. #endif
  99.  
  100. #ifndef FWUTIL_H
  101. #include "FWUtil.h"
  102. #endif
  103.  
  104. #ifndef FWPRESEN_H
  105. #include "FWPresen.h"
  106. #endif
  107.  
  108. #ifndef FWKIND_H
  109. #include "FWKind.h"
  110. #endif
  111.  
  112. // ----- OS Layer -----
  113.  
  114. #ifndef FWORDCOL_H
  115. #include "FWOrdCol.h"
  116. #endif
  117.  
  118. #ifndef FWSUSINK_H
  119. #include "FWSUSink.h"
  120. #endif
  121.  
  122. #ifndef FWODGEOM_H
  123. #include "FWODGeom.h"
  124. #endif
  125.  
  126. #ifndef FWEVENT_H
  127. #include "FWEvent.h"
  128. #endif
  129.  
  130. #ifndef SLMixOS_H
  131. #include "SLMixOS.h"
  132. #endif
  133.  
  134. // ----- Foundation Includes -----
  135.  
  136. #ifndef FWSTREAM_H
  137. #include "FWStream.h"
  138. #endif
  139.  
  140. #ifndef FWSOMENV_H
  141. #include "FWSOMEnv.h"
  142. #endif
  143.  
  144. // ----- OpenDoc Includes -----
  145.  
  146. #ifndef SOM_ODShape_xh
  147. #include <Shape.xh>
  148. #endif
  149.  
  150. #ifndef SOM_ODStorageUnit_xh
  151. #include <StorageU.xh>
  152. #endif
  153.  
  154. #ifndef SOM_Module_OpenDoc_StdProps_defined
  155. #include <StdProps.xh>
  156. #endif
  157.  
  158. #ifndef SOM_ODSession_xh
  159. #include <ODSessn.xh>
  160. #endif
  161.  
  162. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  163. #include <StdTypes.xh>
  164. #endif
  165.  
  166. //========================================================================================
  167. //    Runtime Informations
  168. //========================================================================================
  169.  
  170. #ifdef FW_BUILD_MAC
  171. #pragma segment odfdraw2
  172. #endif
  173.  
  174. //========================================================================================
  175. //    class CDrawSelection
  176. //========================================================================================
  177.  
  178. FW_DEFINE_AUTO(CDrawSelection)
  179.     
  180. //----------------------------------------------------------------------------------------
  181. //    CDrawSelection::CDrawSelection
  182. //----------------------------------------------------------------------------------------
  183.  
  184. CDrawSelection::CDrawSelection(Environment* ev, CDrawPart* drawPart):
  185.     FW_CSelection(ev, TRUE, TRUE),
  186.     fDrawPart(drawPart),
  187.     fUpdateShape(NULL),
  188.     fFrozenCount(0),
  189.     fCount(0),
  190.     fSelectionContent(NULL),
  191.     fWorkingHandle(FW_kZeroRect, FW_kFill),
  192.     fDraggedContent(NULL)
  193. {
  194.     fSelectionContent = FW_NEW(CDrawSelectionContent, (ev, drawPart, this));
  195.     fWorkingHandle.SetInk(FW_kInvertInk);
  196.     FW_END_CONSTRUCTOR
  197. }
  198.  
  199. //----------------------------------------------------------------------------------------
  200. //    CDrawSelection::~CDrawSelection
  201. //----------------------------------------------------------------------------------------
  202.  
  203. CDrawSelection::~CDrawSelection()
  204. {
  205.     FW_START_DESTRUCTOR
  206.     if (fUpdateShape)
  207.     {
  208.         FW_SOMEnvironment ev;
  209.         fUpdateShape->Release(ev);
  210.     }
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    CDrawSelection::GetSelectedContent
  215. //----------------------------------------------------------------------------------------
  216.  
  217. FW_CContent* CDrawSelection::GetSelectedContent(Environment* ev)
  218. {
  219. FW_UNUSED(ev);
  220.     return fSelectionContent;
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    CDrawSelection::WhichHandle
  225. //----------------------------------------------------------------------------------------
  226.  
  227. CBaseShape* CDrawSelection::WhichHandle(Environment* ev, FW_CGraphicContext& gc, const FW_CPoint& mouse, short& whichHandle, FW_Fixed zoomFactor) const
  228. {
  229. FW_UNUSED(ev);
  230.     whichHandle = 0;
  231.     
  232.     if (fCount != 0)
  233.     {
  234.         CDrawContentShapeIterator ite(fSelectionContent);
  235.         for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  236.         {
  237.             whichHandle = shape->WhichHandle(gc, mouse, zoomFactor);
  238.             if (whichHandle != 0)
  239.                 return shape;
  240.         }
  241.     }
  242.     
  243.     return NULL;
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    CDrawSelection::RenderSelectionHandles
  248. //----------------------------------------------------------------------------------------
  249.  
  250. void CDrawSelection::RenderSelectionHandles(Environment* ev, FW_CGraphicContext& gc, FW_Fixed zoomFactor)
  251. {
  252. FW_UNUSED(ev);
  253.     CDrawContentShapeIterator ite(fSelectionContent);
  254.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  255.     {
  256.         shape->RenderHandles(gc, zoomFactor);    
  257.     }
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. //    CDrawSelection::InvalidateSelectionHandles
  262. //----------------------------------------------------------------------------------------
  263.  
  264. void CDrawSelection::InvalidateSelectionHandles(Environment* ev, CDrawFrame* frame)
  265. {    
  266.     FW_CSuperView* contentView = frame->GetContentView(ev);
  267.     FW_CAcquiredODShape workingShape = FW_NewODShape(ev);
  268.     FW_Fixed penSize = CalcHandlePenSize(frame->GetZoomFactor());
  269.     
  270.     CDrawContentShapeIterator ite(fSelectionContent);
  271.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  272.     {
  273.         shape->InvalidateHandles(ev, contentView, workingShape, penSize);
  274.     }
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. //    CDrawSelection::RenderAllHandles
  279. //----------------------------------------------------------------------------------------
  280.  
  281. void CDrawSelection::RenderAllHandles(Environment* ev, CDrawFrame* frame)
  282. {
  283.     if (fCount != 0)
  284.     {        
  285.         FW_CFrameFacetIterator ite(ev, frame);
  286.         for (ODFacet* facet = (ODFacet*)ite.First(ev); ite.IsNotComplete(ev); facet = (ODFacet*)ite.Next(ev))
  287.         {
  288.             FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  289.             RenderSelectionHandles(ev, vc, frame->GetZoomFactor());
  290.         }
  291.     }
  292. }
  293.  
  294. //----------------------------------------------------------------------------------------
  295. //    CDrawSelection::RenderHandles
  296. //----------------------------------------------------------------------------------------
  297.  
  298. void CDrawSelection::RenderHandles(Environment* ev, CBaseShape* shape)
  299. {
  300.     FW_CPresentationFrameIterator ite(ev, GetPresentation(ev));
  301.     for (CDrawFrame* frame = (CDrawFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (CDrawFrame*)ite.Next(ev))
  302.     {
  303.         if (frame->HasSelectionFocus(ev) && frame->GetWindow(ev)->IsActive(ev))
  304.         {
  305.             FW_CFrameFacetIterator i(ev, frame);            
  306.             for (ODFacet* facet = i.First(ev); i.IsNotComplete(ev); facet = i.Next(ev))
  307.             {
  308.                 FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  309.                 shape->RenderHandles(vc, frame->GetZoomFactor());
  310.             }
  311.         }
  312.     }
  313. }
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    CDrawSelection::CloseSelection
  317. //----------------------------------------------------------------------------------------
  318.  
  319. void CDrawSelection::CloseSelection(Environment* ev)
  320. {
  321.     CBaseShape* shape;
  322.     while ((shape = fSelectionContent->GetFirstShape()) != NULL)
  323.     {
  324.         DoRemove(ev, shape);
  325.         RenderHandles(ev, shape);        // turn off
  326.     }
  327.  
  328.     CalcCache(ev);
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. //    CDrawSelection::AddToSelection
  333. //----------------------------------------------------------------------------------------
  334.  
  335. void CDrawSelection::AddToSelection(Environment* ev, CBaseShape* theShape, FW_Boolean renderHandles)
  336. {                
  337.     if (theShape != NULL)
  338.     {
  339.         fDrawPart->SetTool(ev, kSelectTool);
  340.         DoAdd(ev, theShape);
  341.         if (renderHandles)
  342.             RenderHandles(ev, theShape);    // Turn on    
  343.     }        
  344.             
  345.     CalcCache(ev);
  346. }
  347.  
  348. //----------------------------------------------------------------------------------------
  349. //    CDrawSelection::RemoveFromSelection
  350. //----------------------------------------------------------------------------------------
  351.  
  352. void CDrawSelection::RemoveFromSelection(Environment* ev, CBaseShape* shape, FW_Boolean renderHandles)
  353. {                
  354.     if (shape != NULL)
  355.     {
  356.         DoRemove(ev, shape);
  357.         if (renderHandles)
  358.             RenderHandles(ev, shape);        // Turn Off
  359.     }    
  360.     
  361.     CalcCache(ev);
  362. }
  363.  
  364. //----------------------------------------------------------------------------------------
  365. //    CDrawSelection::DoAdd
  366. //----------------------------------------------------------------------------------------
  367.  
  368. void CDrawSelection::DoAdd(Environment* ev, CBaseShape *shape)
  369. {
  370.     fSelectionContent->AddShape(ev, shape);
  371.     this->ShapeAdded(ev, shape);
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. //    CDrawSelection::ShapeAdded
  376. //----------------------------------------------------------------------------------------
  377. void CDrawSelection::ShapeAdded(Environment* ev, CBaseShape* shape)
  378. {
  379.     shape->SelectShape(ev, true);
  380.     fCount++;
  381.     if (shape->IsFrozen())
  382.         fFrozenCount++;
  383. }
  384.  
  385. //----------------------------------------------------------------------------------------
  386. //    CDrawSelection::DoRemove
  387. //----------------------------------------------------------------------------------------
  388.  
  389. void CDrawSelection::DoRemove(Environment* ev, CBaseShape *shape)
  390. {
  391.     fSelectionContent->RemoveShape(ev, shape);
  392.     shape->SelectShape(ev, false);
  393.     fCount--;
  394.     if (shape->IsFrozen())
  395.         fFrozenCount--;
  396. }
  397.  
  398. //----------------------------------------------------------------------------------------
  399. //    CDrawSelection::ClearSelection
  400. //----------------------------------------------------------------------------------------
  401.  
  402. void CDrawSelection::ClearSelection(Environment* ev)
  403. {
  404.     CBaseShape *shape;
  405.     while ((shape = fSelectionContent->GetFirstShape()) != NULL)
  406.     {
  407.         shape->CheckPromise(ev);
  408.         
  409.         DoRemove(ev, shape);                // Remove from selection list
  410.         fDrawPart->RemoveShapeFromPart(ev, shape);    // Remove from part
  411.     }
  412.     
  413.     CDrawFacetClipper facetClipper(fDrawPart);
  414.     facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
  415.     GetPresentation(ev)->Invalidate(ev, fUpdateShape);
  416.     
  417.     CalcCache(ev);
  418. }
  419.  
  420. //----------------------------------------------------------------------------------------
  421. //    CDrawSelection::SelectAll
  422. //----------------------------------------------------------------------------------------
  423.  
  424. void CDrawSelection::SelectAll(Environment* ev)
  425. {    
  426.     CDrawFrame* activeFrame = (CDrawFrame*)fDrawPart->GetLastActiveFrame(ev);
  427.     
  428.     RenderAllHandles(ev, activeFrame);
  429.  
  430.     CDrawContentShapeIterator ite(fDrawPart->GetDrawContent());
  431.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  432.     {
  433.         if (!shape->IsSelectedShape())
  434.             DoAdd(ev, shape);
  435.     }
  436.     
  437.     RenderAllHandles(ev, activeFrame);
  438.  
  439.     CalcCache(ev);
  440.     
  441.     fDrawPart->SetTool(ev, kSelectTool);
  442. }
  443.  
  444. //----------------------------------------------------------------------------------------
  445. //    CDrawSelection::IsEmpty
  446. //----------------------------------------------------------------------------------------
  447.  
  448. FW_Boolean CDrawSelection::IsEmpty(Environment* ev) const
  449. {    
  450. FW_UNUSED(ev);
  451.     return fCount == 0;
  452. }
  453.  
  454. //----------------------------------------------------------------------------------------
  455. //    CDrawSelection::CenterSelection
  456. //----------------------------------------------------------------------------------------
  457.  
  458. FW_CPoint CDrawSelection::CenterSelection(Environment* ev, FW_CFrame* scopeFrame)
  459. {
  460.     FW_ASSERT(scopeFrame);
  461.     
  462.     fDrawPart->SetTool(ev, kSelectTool);
  463.  
  464.     CalcCache(ev);
  465.     
  466.     FW_CRect bounds = scopeFrame->GetContentView(ev)->GetBoundsInContent(ev);
  467.     FW_CRect box(fDragRect);
  468.     box.PlaceInCenterOf(bounds);
  469.             
  470.     FW_CPoint result(box.left - fDragRect.left, box.top - fDragRect.top);
  471.     OffsetSelection(ev, result.x, result.y);
  472.     
  473.     CDrawFacetClipper facetClipper(fDrawPart);
  474.     facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);    
  475.     GetPresentation(ev)->Invalidate(ev, fUpdateShape);
  476.  
  477.     return result;
  478. }
  479.  
  480. //----------------------------------------------------------------------------------------
  481. //    CDrawSelection::Resize
  482. //----------------------------------------------------------------------------------------
  483.  
  484. FW_Boolean CDrawSelection::Resize(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  485. {    
  486.     if (fClickedHandle == 0)
  487.         return FALSE;
  488.  
  489.     if (fDrawPart->IsReadOnly(ev))    // can't resize read only part
  490.         return TRUE;
  491.  
  492.     if (!theMouseEvent.WaitUntilMouseMoved(ev))
  493.         return TRUE;
  494.     
  495.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  496.     CDrawFrame *frame = (CDrawFrame*)FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  497.  
  498.     CBaseShape* anchorShape = GetAnchorShape();
  499.     
  500.     FW_CInk resizeInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
  501.     FW_CStyle resizeStyle(anchorShape->GetResizeStyle());
  502.     
  503.     CResizeTracker resizeTracker(ev, frame->GetContentView(ev), facet, anchorShape, fClickedHandle, resizeInk, resizeStyle, TRUE);
  504.     if (resizeTracker.Track(ev, theMouseEvent))
  505.     {
  506.         GetPresentation(ev)->Invalidate(ev, fUpdateShape);
  507.  
  508.         FW_CPoint lastLocation;
  509.         resizeTracker.GetLastLocation(lastLocation);
  510.         FW_CRect srcRect, dstRect;
  511.         anchorShape->GetMapRects(fClickedHandle, lastLocation, srcRect, dstRect);
  512.  
  513.         CResizeShapeCommand* cmd = FW_NEW(CResizeShapeCommand,
  514.                                             (ev, fDrawPart, frame, this,
  515.                                              srcRect, dstRect));
  516.         cmd->Execute(ev);
  517.     }
  518.     else
  519.     {
  520.         FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  521.         
  522.         FW_Fixed penSize = CalcHandlePenSize(frame->GetZoomFactor());
  523.         anchorShape->CalcHandle(fClickedHandle, &fWorkingHandle, penSize);
  524.         fWorkingHandle.Render(vc);    // redraw the handle
  525.     }
  526.     
  527.     return TRUE;
  528. }
  529.  
  530. //----------------------------------------------------------------------------------------
  531. //    CDrawSelection::CalcCache
  532. //----------------------------------------------------------------------------------------
  533.  
  534. void CDrawSelection::CalcCache(Environment* ev)
  535. {
  536.     fDragRect.Clear();
  537.     
  538.     if (fUpdateShape == NULL)
  539.         fUpdateShape = ::FW_NewODShape(ev);
  540.     
  541.     if (fCount == 0)
  542.         return;
  543.     
  544.     FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
  545.     FW_CRect tempRect;
  546.  
  547.     FW_Boolean first = TRUE;
  548.     CDrawContentShapeIterator ite(fSelectionContent);
  549.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  550.     {
  551.         shape->GetDragRect(tempRect);
  552.         shape->GetUpdateBox(ev, aqTempShape);
  553.         if (first)
  554.         {
  555.             fDragRect = tempRect;
  556.             fUpdateShape->CopyFrom(ev, aqTempShape);
  557.         }
  558.         else
  559.         {
  560.             fDragRect |= tempRect;
  561.             fUpdateShape->Union(ev, aqTempShape);
  562.         }
  563.                         
  564.         first = FALSE;
  565.     }
  566.     
  567. }
  568.  
  569. //----------------------------------------------------------------------------------------
  570. //    CDrawSelection::AcquireSelectionShape
  571. //----------------------------------------------------------------------------------------
  572.  
  573. ODShape* CDrawSelection::AcquireSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  574. {
  575. FW_UNUSED(frame);
  576. FW_UNUSED(facet);
  577.  
  578.     return ::FW_NewODShape(ev, fDragRect);
  579. }
  580.  
  581. //----------------------------------------------------------------------------------------
  582. //    CDrawSelection::AcquireSelectionOutline
  583. //----------------------------------------------------------------------------------------
  584.  
  585. ODShape* CDrawSelection::AcquireSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  586. {
  587.     FW_CAcquiredODShape outline;
  588.     
  589.     if (GetAnchorShape() == NULL)
  590.         outline = FW_CopyAndRelease(ev, AcquireSelectionShape(ev, facet, frame));
  591.     else
  592.         outline = GetAnchorShape()->CreateShapeOutline(ev);
  593.  
  594.     if (fCount > 1)
  595.     {
  596.         FW_CAcquiredODShape shapeOutline = FW_CSelection::AcquireSelectionOutline(ev, facet, frame);
  597.         outline->Union(ev, shapeOutline);
  598.     }
  599.  
  600.     return outline.Orphan();
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. //    CDrawSelection::OffsetSelection
  605. //----------------------------------------------------------------------------------------
  606.  
  607. void CDrawSelection::OffsetSelection(Environment* ev, FW_Fixed xDelta, FW_Fixed yDelta)
  608. {
  609.     FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
  610.     
  611.     CDrawContentShapeIterator ite(fSelectionContent);
  612.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  613.     {
  614.         shape->OffsetShape(ev, xDelta, yDelta);
  615.     }
  616.     
  617.     CalcCache(ev);
  618.  
  619.     aqUnionShape->Union(ev, fUpdateShape);
  620.     
  621.     CDrawFacetClipper facetClipper(fDrawPart);
  622.     facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
  623. }
  624.  
  625. //----------------------------------------------------------------------------------------
  626. //    CDrawSelection::SelectWithRectangle
  627. //----------------------------------------------------------------------------------------
  628.  
  629. void CDrawSelection::SelectWithRectangle(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  630. {
  631.     CRectShape rectShape(fDrawPart);    // Create a rect shape on the stack
  632.     FW_CStyle trackStyle(FW_kFixed0, FW_kAntPat);
  633.     FW_CInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
  634.     rectShape.ChangeRenderVerb(ev, kFrameOnly);
  635.     rectShape.SetFrameInk(trackInk);
  636.     rectShape.SetFrameStyle(trackStyle);
  637.     
  638.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  639.     FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  640.  
  641.     CShapeTracker tracker(ev, frame->GetContentView(ev), facet, &rectShape, FALSE);
  642.     if (tracker.Track(ev, theMouseEvent))
  643.     {
  644.         FW_Boolean isShift = theMouseEvent.IsExtendModifier(ev);
  645.         FW_CRect selectRect = rectShape.GetRectGeometry();
  646.         
  647.         CDrawContentShapeIterator ite(fDrawPart->GetDrawContent());
  648.         for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  649.         {
  650.             if (shape->InSelectionRect(selectRect))
  651.             {
  652.                 if (shape->IsSelectedShape())
  653.                 {
  654.                     if (isShift)
  655.                     {
  656.                         DoRemove(ev, shape);
  657.                         RenderHandles(ev, shape);        // Turn Off
  658.                     }
  659.                 }
  660.                 else
  661.                 {
  662.                     DoAdd(ev, shape);
  663.                     RenderHandles(ev, shape);    // Turn on    
  664.                 }
  665.             }
  666.             else if (shape->IsSelectedShape() && !isShift)
  667.             {
  668.                 DoRemove(ev, shape);
  669.                 RenderHandles(ev, shape);        // Turn Off
  670.             }
  671.         }            
  672.         CalcCache(ev);
  673.     }
  674.     else
  675.     {
  676.         if (!theMouseEvent.IsExtendModifier(ev))
  677.             CloseSelection(ev);
  678.     }
  679. }
  680.  
  681. //----------------------------------------------------------------------------------------
  682. //    CDrawSelection::SetFrozen
  683. //----------------------------------------------------------------------------------------
  684.  
  685. void CDrawSelection::SetFrozen(Environment* ev, FW_Boolean state)
  686. {
  687. FW_UNUSED(ev);
  688.     CDrawContentShapeIterator ite(fSelectionContent);
  689.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  690.     {
  691.         if (shape->SetFrozen(state))
  692.         {
  693.             state ? fFrozenCount++ : fFrozenCount--;
  694.         }
  695.     }
  696. }
  697.  
  698. //----------------------------------------------------------------------------------------
  699. //    CDrawSelection::SelectionChanged
  700. //----------------------------------------------------------------------------------------
  701.  
  702. void CDrawSelection::SelectionChanged(Environment* ev, ODUpdateID updateID)
  703. {
  704.     CDrawPublishLinkCollection temp;
  705.     
  706.     CDrawContentShapeIterator ite(fSelectionContent);
  707.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  708.     {
  709.         if (shape->IsPublished())
  710.         {
  711.             if (!temp.Contains(shape->GetPublishLink()))
  712.                 temp.AddLast(shape->GetPublishLink());
  713.         }
  714.     }
  715.     
  716.     CDrawPublishLinkCollectionIterator tempIte(&temp);
  717.     for (CDrawPublishLink* link = tempIte.First(); tempIte.IsNotComplete(); link = tempIte.Next())
  718.     {
  719.         link->ContentUpdated(ev, updateID);
  720.     }
  721.     
  722.     temp.RemoveAll();
  723. }
  724.  
  725. //----------------------------------------------------------------------------------------
  726. //    CDrawSelection::IsSelectionLinkable
  727. //----------------------------------------------------------------------------------------
  728. //    Don't write a link spec if any of the selected shapes is in a link destination
  729.  
  730. FW_Boolean CDrawSelection::IsSelectionLinkable(Environment* ev)
  731. {
  732.     FW_Boolean result = TRUE;
  733.     
  734.     CDrawContentShapeIterator ite(fSelectionContent);
  735.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  736.     {
  737.         if (shape->IsInLinkDestination(ev))
  738.         {
  739.             result = FALSE;
  740.             break;
  741.         }
  742.         else if (shape->IsPublished())    // don't allow a shape to be published more than once
  743.         {
  744.             result = FALSE;
  745.             break;
  746.         }
  747.     }
  748.     
  749.     return result;
  750. }
  751.  
  752. //----------------------------------------------------------------------------------------
  753. //    CDrawSelection::CanPasteAsLink
  754. //----------------------------------------------------------------------------------------
  755. FW_Boolean CDrawSelection::CanPasteAsLink(Environment* ev, ODPasteAsMergeSetting& setting,
  756.                                           ODStorageUnit* su)
  757. {
  758.     // Check whether the storage unit contains mergeable content
  759.     if (su->Exists(ev, kODPropContents, fDrawPart->GetPartKind(ev)->GetType(ev), 0))
  760.     {
  761.         if (su->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
  762.             setting = kODPasteAsEmbed;
  763.         else
  764.             setting = kODPasteAsMerge;
  765.     }
  766.     else    // foreign content - cannot be merged
  767.         setting = kODPasteAsEmbedOnly;
  768.     
  769.     return fAllowLink;
  770. }
  771.  
  772. //----------------------------------------------------------------------------------------
  773. //    CDrawSelection::IsMouseInDraggableItem
  774. //----------------------------------------------------------------------------------------
  775.  
  776. FW_Boolean CDrawSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame, 
  777.                                                 const FW_CMouseEvent& theMouseEvent, 
  778.                                                 FW_Boolean inBackground)
  779. {    
  780.     fClickedHandle = 0;
  781.     fAnchorShape = NULL;
  782.  
  783.     if (!inBackground && fDrawPart->GetTool() != kSelectTool)
  784.         return FALSE;
  785.         
  786.     FW_CViewContext vc(ev, frame->GetContentView(ev), theMouseEvent.GetFacet(ev));
  787.  
  788.     // ----- Look first for a handle -----
  789.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  790.     frame->GetContentView(ev)->FrameToViewContent(ev, where);
  791.  
  792.     CBaseShape* clickedShape = WhichHandle(ev, vc, where, fClickedHandle, ((CDrawFrame*)frame)->GetZoomFactor());
  793.     if (clickedShape != NULL)
  794.     {
  795.         fAnchorShape = clickedShape;
  796.         return FALSE;            // if in a handle we won't drag
  797.     }
  798.     
  799.     // ----- then look for a selected shape -----
  800.     CBaseShape* shape = fDrawPart->WhichShape(ev, vc, theMouseEvent, TRUE);
  801.     
  802.     if (shape != NULL && shape->IsSelectedShape())
  803.     {
  804.         fAnchorShape = shape;
  805.         return TRUE;
  806.     }
  807.     
  808.     return FALSE;
  809. }
  810.  
  811. //----------------------------------------------------------------------------------------
  812. // CDrawSelection::UpdateSelectionOnMouseDown
  813. //----------------------------------------------------------------------------------------
  814.  
  815. void CDrawSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  816.                                             const FW_CMouseEvent& mouseEvent,
  817.                                             ODFacet* embeddedFacet,
  818.                                             FW_Boolean inEmbeddedFrameBorder,
  819.                                             FW_Boolean inBackground)
  820. {
  821.     if (inEmbeddedFrameBorder)
  822.     {
  823.         fClickedHandle = 0;
  824.         fAnchorShape = NULL;
  825.  
  826.         CProxyShape *theShape = (CProxyShape*)fDrawPart->GetProxy(ev, embeddedFacet->GetFrame(ev));
  827.         FW_ASSERT(theShape);
  828.         
  829.         if (!theShape->IsSelectedShape())
  830.             AddToSelection(ev, theShape, TRUE);        
  831.         
  832.         fAnchorShape = theShape;
  833.     }
  834.     else if (fDrawPart->GetTool() == kSelectTool || inBackground)
  835.     {
  836.         FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
  837.         FW_CViewContext vc(ev, frame->GetContentView(ev), mouseEvent.GetFacet(ev));
  838.         
  839.         // ----- First look if we are in a resize handle -----
  840.         FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  841.         frame->GetContentView(ev)->FrameToViewContent(ev, where);
  842.     
  843.         short  clickedHandle;
  844.         if (WhichHandle(ev, vc, where, clickedHandle, ((CDrawFrame*)frame)->GetZoomFactor()) != NULL)
  845.             return;
  846.  
  847.         // ----- So now we are not in a handle -----
  848.         CBaseShape* clickedShape = fDrawPart->WhichShape(ev, vc, mouseEvent, FALSE);
  849.         if (clickedShape)
  850.         {
  851.             if (mouseEvent.IsExtendModifier(ev))
  852.             {
  853.                 if (clickedShape->IsSelectedShape())
  854.                 {
  855.                     RemoveFromSelection(ev, clickedShape, !inBackground);
  856.                     if (clickedShape == fAnchorShape)
  857.                         fAnchorShape = NULL;
  858.                 }
  859.                 else
  860.                 {
  861.                     AddToSelection(ev, clickedShape, !inBackground);
  862.                     fAnchorShape = clickedShape;
  863.                 }
  864.             }
  865.             else if (!clickedShape->IsSelectedShape())
  866.             {
  867.                 fAnchorShape = clickedShape;
  868.                 CloseSelection(ev);
  869.                 AddToSelection(ev, clickedShape, !inBackground);
  870.             }    
  871.         }
  872.     }
  873. }
  874.  
  875. //----------------------------------------------------------------------------------------
  876. //    CDrawSelection::DeleteSelection
  877. //----------------------------------------------------------------------------------------
  878. void CDrawSelection::DeleteSelection(Environment* ev)
  879. {
  880.     CBaseShape *shape;
  881.     while ((shape = fSelectionContent->GetFirstShape()) != NULL)
  882.     {
  883.         DoRemove(ev, shape);                        // Remove from selection
  884.         fDrawPart->RemoveShapeFromPart(ev, shape);    // Remove from part
  885.         delete shape;
  886.     }
  887. }
  888.  
  889. //----------------------------------------------------------------------------------------
  890. //    CDrawSelection::GetLinkDestination - override
  891. //----------------------------------------------------------------------------------------
  892.  
  893. FW_CLinkDestination* CDrawSelection::GetLinkDestination(Environment* ev, FW_Boolean& multipleLinks)
  894. {
  895. FW_UNUSED(ev);
  896.     // check whether any of the selected shapes is in a link destination
  897.     FW_CLinkDestination* linkDest = NULL;
  898.     multipleLinks = false;
  899.  
  900.     CDrawContentShapeIterator iter(fSelectionContent);
  901.     for (CBaseShape* shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
  902.     {
  903.         if (shape->IsSubscribed())
  904.         {
  905.             if (linkDest == NULL)
  906.                 linkDest = shape->GetSubscribeLink();        // return the link destination
  907.             else if (shape->GetSubscribeLink() != linkDest)
  908.             {
  909.                 multipleLinks = true;
  910.                 return NULL;
  911.             }
  912.         }
  913.     }
  914.  
  915.     return linkDest;
  916. }
  917.  
  918. //----------------------------------------------------------------------------------------
  919. //    CDrawSelection::GetSelectionPenSize
  920. //----------------------------------------------------------------------------------------
  921.  
  922. FW_Boolean CDrawSelection::GetSelectionPenSize(Environment* ev, FW_Fixed& penSize)
  923. {
  924. FW_UNUSED(ev);
  925.     CDrawContentShapeIterator iter(fSelectionContent);
  926.     FW_Boolean first = TRUE;
  927.     for (CBaseShape *shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
  928.     {
  929.         if (first)
  930.         {
  931.             penSize = shape->GetPenSize();
  932.             first = FALSE;
  933.         }
  934.         else
  935.         {
  936.             if (shape->GetPenSize() != penSize)
  937.                 return FALSE;
  938.         }
  939.     }
  940.     
  941.     return TRUE;
  942. }
  943.  
  944. //----------------------------------------------------------------------------------------
  945. //    CDrawSelection::SelectContent
  946. //----------------------------------------------------------------------------------------
  947. void CDrawSelection::SelectContent(Environment* ev, CDrawContent* content)
  948. {
  949.     this->CloseSelection(ev);
  950.  
  951.     CDrawContentShapeIterator it(content);
  952.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  953.     {
  954.         this->AddToSelection(ev, shape, TRUE);
  955.     }
  956. }
  957.  
  958. //----------------------------------------------------------------------------------------
  959. //    CDrawSelection::GetDrawContent
  960. //----------------------------------------------------------------------------------------
  961. CDrawContent* CDrawSelection::GetDrawContent(Environment*)
  962. {
  963.     return fSelectionContent;
  964. }
  965.  
  966. //----------------------------------------------------------------------------------------
  967. //    CDrawSelection::GetSelectedLinkSources
  968. //----------------------------------------------------------------------------------------
  969. CDrawPublishLinkCollection* CDrawSelection::GetSelectedLinkSources()
  970. {
  971.     CDrawPublishLinkCollection* sources = NULL;
  972.     
  973.     CDrawContentShapeIterator ite(fSelectionContent);
  974.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  975.     {
  976.         if (shape->IsPublished())
  977.         {
  978.             if (sources == NULL)
  979.                 sources = FW_NEW(CDrawPublishLinkCollection,());
  980.                 
  981.             if (!sources->Contains(shape->GetPublishLink()))
  982.                 sources->AddLast(shape->GetPublishLink());
  983.         }
  984.     }
  985.     
  986.     return sources;
  987. }
  988.  
  989.