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 / Draw / Sources / DrawFrm.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  27.8 KB  |  907 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawFrm.cpp
  4. //    Release Version:    $ ODF 1 $
  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 DRAWFRM_H
  15. #include "DrawFrm.h"
  16. #endif
  17.  
  18. #ifndef DEFINES_K
  19. #include "Defines.k"
  20. #endif
  21.  
  22. #ifndef DRAWPART_H
  23. #include "DrawPart.h"
  24. #endif
  25.  
  26. #ifndef DRAWVIEW_H
  27. #include "DrawView.h"
  28. #endif
  29.  
  30. #ifndef CLIPCMDS_H
  31. #include "ClipCmds.h"
  32. #endif
  33.  
  34. #ifndef DRAWSEL_H
  35. #include "DrawSel.h"
  36. #endif
  37.  
  38. #ifndef INSRTCMD_H
  39. #include "InsrtCmd.h"
  40. #endif
  41.  
  42. #ifndef CONTENT_H
  43. #include "Content.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef SHPTRAKR_H
  51. #include "ShpTrakr.h"
  52. #endif
  53.  
  54. #ifndef DRAWCMDS_H
  55. #include "DrawCmds.h"
  56. #endif
  57.  
  58. #ifndef DRAWCLIP_H
  59. #include "DrawClip.h"
  60. #endif
  61.  
  62. #ifndef UTILS_H
  63. #include "Utils.h"
  64. #endif
  65.  
  66. #ifndef DRWDDCMD_H
  67. #include "DrwDDCmd.h"
  68. #endif
  69.  
  70. #ifndef RULER_H
  71. #include "Ruler.h"
  72. #endif
  73.  
  74. #ifndef DRAWCONT_H
  75. #include "DrawCont.h"
  76. #endif
  77.  
  78. #ifndef PRINTHDL_H
  79. #include "PrintHdl.h"
  80. #endif
  81.  
  82. // ----- Framework Layer -----
  83.  
  84. #ifndef FWCONTXT_H
  85. #include "FWContxt.h"
  86. #endif
  87.  
  88. #ifndef FWUTIL_H
  89. #include "FWUtil.h"
  90. #endif
  91.  
  92. #ifndef FWPRESEN_H
  93. #include "FWPresen.h"
  94. #endif
  95.  
  96. #ifndef FWSCROLR_H
  97. #include "FWScrolr.h"
  98. #endif
  99.  
  100. #ifndef FWSCLBAR_H
  101. #include "FWSclBar.h"
  102. #endif
  103.  
  104. #ifndef FWGROWBX_H
  105. #include "FWGrowBx.h"
  106. #endif
  107.  
  108. #ifndef FWPRHDLR_H
  109. #include "FWPrHdlr.h"
  110. #endif
  111.  
  112. // ----- OS Layer -----
  113.  
  114. #ifndef FWMENU_H
  115. #include "FWMenu.h"
  116. #endif
  117.  
  118. #ifndef FWRECSHP_H
  119. #include "FWRecShp.h"
  120. #endif
  121.  
  122. #ifndef FWCURSOR_H
  123. #include "FWCursor.h"
  124. #endif
  125.  
  126. #ifndef FWEVENT_H
  127. #include "FWEvent.h"
  128. #endif
  129.  
  130. #ifndef FWODGEOM_H
  131. #include "FWODGeom.h"
  132. #endif
  133.  
  134. #ifndef FWLINSHP_H
  135. #include "FWLinShp.h"
  136. #endif
  137.  
  138. #ifndef FWBMPSHP_H
  139. #include "FWBmpShp.h"
  140. #endif
  141.  
  142. // ----- OpenDoc Includes -----
  143.  
  144. #ifndef SOM_Module_OpenDoc_Commands_defined
  145. #include <CmdDefs.xh>
  146. #endif
  147.  
  148. #ifndef SOM_Module_OpenDoc_StdProps_defined
  149. #include <StdProps.xh>
  150. #endif
  151.  
  152. #ifndef SOM_ODSession_xh
  153. #include <ODSessn.xh>
  154. #endif
  155.  
  156. #ifndef SOM_ODDispatcher_xh
  157. #include <Disptch.xh>
  158. #endif
  159.  
  160. #ifndef FWFILEOP_H
  161. #include "FWFileOp.h"
  162. #endif
  163.  
  164. #ifndef FWEMBUTL_H
  165. #include "FWEmbUtl.h"
  166. #endif
  167.  
  168. //========================================================================================
  169. // RunTime Info
  170. //========================================================================================
  171.  
  172. #ifdef FW_BUILD_MAC
  173. #pragma segment odfdrawframes
  174. #endif
  175.  
  176. FW_DEFINE_AUTO(CDrawFrame)
  177. FW_DEFINE_CLASS_M1(CDrawFrame, FW_CEmbeddingFrame)
  178.  
  179. //========================================================================================
  180. // CDrawFrame
  181. //========================================================================================
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // CDrawFrame::CDrawFrame
  185. //----------------------------------------------------------------------------------------
  186.  
  187. CDrawFrame::CDrawFrame(Environment* ev, 
  188.                         ODFrame* odFrame, 
  189.                         FW_CPresentation* presentation, 
  190.                         CDrawPart* drawPart,
  191.                         FW_ResourceId id) :
  192.     FW_CEmbeddingFrame(ev, odFrame, presentation, drawPart, id),
  193.     FW_MDraggableFrame(ev, this),
  194.     FW_MDroppableFrame(ev, this),
  195.     fDrawPart(drawPart),
  196.     fSelection((CDrawSelection*)GetPresentation(ev)->GetSelection(ev)),
  197.     fHorzRuler(NULL),
  198.     fVertRuler(NULL),
  199.     fGridShown(TRUE),
  200.     fZoomFactor(FW_kFixedPos1),
  201.     fRulersShown(TRUE)
  202. {    
  203.     FW_END_CONSTRUCTOR
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. // CDrawFrame::~CDrawFrame
  208. //----------------------------------------------------------------------------------------
  209.  
  210. CDrawFrame::~CDrawFrame()
  211. {
  212.     FW_START_DESTRUCTOR
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    CDrawFrame::DoAdjustMenus
  217. //----------------------------------------------------------------------------------------
  218.  
  219. FW_Boolean CDrawFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  220. {
  221.     // ----- Edit Menu -----
  222.     if (hasMenuFocus)
  223.     {
  224.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContents, NULL)); // we don't care about the type
  225.         
  226.         menuBar->EnableAndToggleCommand(ev, cGraphicsGrid, TRUE, fGridShown);
  227.         menuBar->EnableAndToggleCommand(ev, cRulers, TRUE, fRulersShown);
  228.  
  229.         ODTypeToken defaultViewType = GetPresentation(ev)->GetDefaultEmbeddedFrameViewType(ev);
  230.         menuBar->EnableAndCheckCommand(ev, cAsFrame, TRUE, defaultViewType == FW_CPart::gViewAsFrameToken);
  231.         menuBar->EnableAndCheckCommand(ev, cAsLargeIcon, TRUE, defaultViewType == FW_CPart::gViewAsLargeIconToken);
  232.         menuBar->EnableAndCheckCommand(ev, cAsSmallIcon, TRUE, defaultViewType == FW_CPart::gViewAsSmallIconToken);
  233.         menuBar->EnableAndCheckCommand(ev, cAsThumbnail, TRUE, defaultViewType == FW_CPart::gViewAsThumbnailToken);
  234.  
  235.         menuBar->EnableAndCheckCommand(ev, cZoom50, TRUE, fZoomFactor == FW_DoubleToFixed(.5));
  236.         menuBar->EnableAndCheckCommand(ev, cZoom100, TRUE, fZoomFactor == FW_kFixedPos1);
  237.         menuBar->EnableAndCheckCommand(ev, cZoom200, TRUE, fZoomFactor == FW_IntToFixed(2));
  238.     }
  239.     
  240.     return FALSE;
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. //    CDrawFrame::ChangeZoomFactor
  245. //----------------------------------------------------------------------------------------
  246.  
  247. void CDrawFrame::ChangeZoomFactor(Environment* ev, FW_Fixed zoomFactor)
  248. {
  249.     fHorzRuler->ZoomFactorChanged(ev, zoomFactor);
  250.     fVertRuler->ZoomFactorChanged(ev, zoomFactor);
  251.     fZoomFactor = zoomFactor;
  252.  
  253.     AdjustContentViewSize(ev, FALSE);
  254.  
  255.     FW_ASSERT(GetScroller(ev));
  256.     GetScroller(ev)->ScaleBy(ev, FW_CPoint(zoomFactor, zoomFactor));    // Will invalidate
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    CDrawFrame::DoMenu
  261. //----------------------------------------------------------------------------------------
  262.  
  263. FW_Boolean CDrawFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  264. {
  265.     FW_Boolean handled = TRUE;
  266.     
  267.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  268.     switch (commandID)
  269.     {
  270.         case cGraphicsGrid:
  271.             fGridShown = !fGridShown;
  272.             GetContentView(ev)->Invalidate(ev);
  273.             break;
  274.         
  275.         case cRulers:
  276.             fRulersShown = !fRulersShown;
  277.             ToggleRulers(ev, fRulersShown, TRUE);
  278.             break;
  279.         
  280.         case cZoom50:
  281.             if (fZoomFactor != FW_DoubleToFixed(0.5))
  282.                 ChangeZoomFactor(ev, FW_DoubleToFixed(0.5));
  283.             break;
  284.         case cZoom100:
  285.             if (fZoomFactor != FW_kFixedPos1)
  286.                 ChangeZoomFactor(ev, FW_kFixedPos1);
  287.             break;
  288.         case cZoom200:
  289.             if (fZoomFactor != FW_IntToFixed(2))
  290.                 ChangeZoomFactor(ev, FW_IntToFixed(2));
  291.             break;
  292.                     
  293.         case cAsFrame:
  294.             GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, FW_CPart::gViewAsFrameToken);
  295.             break;
  296.         case cAsLargeIcon:
  297.             GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, FW_CPart::gViewAsLargeIconToken);
  298.             break;
  299.         case cAsSmallIcon:
  300.             GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, FW_CPart::gViewAsSmallIconToken);
  301.             break;
  302.         case cAsThumbnail:
  303.             GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, FW_CPart::gViewAsThumbnailToken);
  304.             break;
  305.             
  306.         default:
  307.             handled = FALSE;
  308.     }
  309.     
  310.     return handled;
  311. }
  312.  
  313. //----------------------------------------------------------------------------------------
  314. //    CDrawFrame::NewClipboardCommand
  315. //----------------------------------------------------------------------------------------
  316.  
  317. FW_CClipboardCommand* CDrawFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  318. {
  319.     return FW_NEW(CDrawClipboardCommand, (ev, commandID, fDrawPart, this, fSelection, FW_kCanUndo));
  320. }
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    CDrawFrame::NewInsertCommand
  324. //----------------------------------------------------------------------------------------
  325.  
  326. FW_CInsertCommand* CDrawFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  327. {
  328.     return FW_NEW(CDrawInsertCommand, (ev, this, fileSpec, fSelection, FW_kCanUndo));
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. //    CDrawFrame::CanAcceptDrop
  333. //----------------------------------------------------------------------------------------
  334. // As an embedding frame I can accept anything
  335.  
  336. ODDragResult CDrawFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  337. {
  338.     return TRUE;
  339. }
  340.  
  341. //----------------------------------------------------------------------------------------
  342. //    CDrawFrame::DoActivateEvent
  343. //----------------------------------------------------------------------------------------
  344.  
  345. void CDrawFrame::DoActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
  346. {
  347.     if (HasSelectionFocus(ev))
  348.         fSelection->RenderAllHandles(ev, this);
  349. }
  350.  
  351.  
  352. //----------------------------------------------------------------------------------------
  353. //    CDrawFrame::AdjustZoomedWindowSize
  354. //----------------------------------------------------------------------------------------
  355.  
  356. void CDrawFrame::AdjustZoomedWindowSize(Environment* ev, FW_CPoint& proposedSize)
  357. {
  358.     proposedSize = fDrawPart->GetDrawingSize();
  359.     proposedSize.x *= fZoomFactor;
  360.     proposedSize.y *= fZoomFactor;
  361.  
  362.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  363.  
  364.     if (fRulersShown)
  365.     {
  366.         sbSize.x += kRulerWidth;
  367.         sbSize.y += kRulerWidth;
  368.     }
  369.     
  370.     proposedSize.x += sbSize.x + FW_IntToFixed(3);    // I want to leave a little space around
  371.     proposedSize.y += sbSize.y + FW_IntToFixed(3);
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. //    CDrawFrame::AdjustWindowGrowLimits
  376. //----------------------------------------------------------------------------------------
  377.  
  378. void CDrawFrame::AdjustWindowGrowLimits(Environment* ev, FW_CPoint& minSize, FW_CPoint& maxSize)
  379. {
  380.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  381.  
  382.     if (fRulersShown)
  383.     {
  384.         sbSize.x += kRulerWidth;
  385.         sbSize.y += kRulerWidth;
  386.     }
  387.     
  388.     minSize.x = FW_IntToFixed(72) + sbSize.x;
  389.     minSize.y = FW_IntToFixed(72) + sbSize.y;
  390. }
  391.  
  392. //----------------------------------------------------------------------------------------
  393. //    CDrawFrame::GeometryChanged
  394. //----------------------------------------------------------------------------------------
  395. //    the geometry (clip shape, external or Internal transform) of one of my facet or one of my
  396. //    embedding facet as changed
  397.  
  398. void CDrawFrame::GeometryChanged(Environment *ev,
  399.                                 ODFacet* odFacet,
  400.                                 FW_Boolean clipShapeChanged,
  401.                                 FW_Boolean externalTransformChanged)
  402. {
  403.     FW_CEmbeddingFrame::GeometryChanged(ev, odFacet, clipShapeChanged, externalTransformChanged);
  404.     
  405.     if (externalTransformChanged)
  406.     {
  407.         CDrawFacetClipper facetClipper(ev, fDrawPart);
  408.         facetClipper.ClipEmbeddedFacets(ev, this, odFacet, NULL);
  409.     }
  410. }
  411.  
  412. //----------------------------------------------------------------------------------------
  413. //    CDrawFrame::CreateEmbeddedFacet
  414. //----------------------------------------------------------------------------------------
  415.  
  416. FW_DECLARE_THROW_POINT (CDrawFrame_CreateEmbeddedFacet);
  417.  
  418. ODFacet* CDrawFrame::CreateEmbeddedFacet(Environment* ev,
  419.                                         ODFacet* embeddingFacet,
  420.                                         FW_MProxy* proxy,
  421.                                         ODFrame* embeddedFrame,
  422.                                         ODShape* proposedClipShape)
  423. {
  424.     FW_CRect embeddedFrameBounds = ((CProxyShape*)proxy)->GetFrameRect(ev);
  425.     
  426.     FW_CAcquiredODTransform aqExternalTransform = ::FW_NewODTransform(ev, embeddedFrameBounds.TopLeft());
  427.  
  428.     FW_CHECK_THROW_POINT (CDrawFrame_CreateEmbeddedFacet);
  429.     return embeddingFacet->CreateEmbeddedFacet(ev,
  430.                                                 embeddedFrame,
  431.                                                 proposedClipShape,
  432.                                                 aqExternalTransform,
  433.                                                 NULL,                    // Canvas
  434.                                                 NULL,                    // biasCanvas
  435.                                                 NULL,                    // siblingFacet
  436.                                                 kODFrameInFront);
  437. }
  438.  
  439. //----------------------------------------------------------------------------------------
  440. //    CDrawFrame::PostCreateViewFromStream
  441. //----------------------------------------------------------------------------------------
  442. // PostCreateViewFromStream is called after subviews are created from resources.  
  443. // Add code which cannot be handled by current resource types.
  444.  
  445. void CDrawFrame::PostCreateViewFromStream(Environment* ev)
  446. {
  447.     fHorzRuler = (CRuler*) FindViewById(ev, kHorzRulerID);
  448.     fVertRuler = (CRuler*) FindViewById(ev, kVertRulerID);
  449.  
  450.     if (!fRulersShown)
  451.         ToggleRulers(ev, FALSE, FALSE);
  452.     
  453.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  454.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  455.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);    
  456.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);    
  457. }
  458.  
  459. //----------------------------------------------------------------------------------------
  460. // CDrawFrame::CreateSubViews
  461. //----------------------------------------------------------------------------------------
  462. /** CreateSubViews doesn't need to be implemented if CDrawFrame is created with a 
  463.     non-null resource id in CDrawPart::NewFrame.
  464.  
  465. void CDrawFrame::CreateSubViews(Environment* ev)
  466. {        
  467. #if 1
  468.     // Load a different set of resources depending on whether this frame is embedded or not
  469.     // because we don't want to create a grow-box and scroll-bars in embedded frames.
  470.     // NOTE: Another solution is to use only 1 set of resources and remove the grow-box
  471.     // and scroll-bars in PostCreateViewFromStream().  See the Container sample.
  472.     
  473.     if (IsRoot(ev))
  474.         CreateSubViewsFromResource(ev, kDrawView);
  475.     else
  476.         CreateSubViewsFromResource(ev, kDrawViewNotRoot);
  477.         
  478. #else
  479.     // NOTE: This section is not compiled by default (change #if 1 by #if 0 above)
  480.     //         It was left in the sample to show how to create views by program
  481.     //         instead of using resources. 
  482.     
  483.     FW_CRect frameRect = GetBounds(ev);    
  484.     FW_CRect contentRect = GetContentRect(ev);
  485.     
  486.     FW_CPoint drawingSize = fDrawPart->GetDrawingSize();
  487.     
  488.     // ----- Create the content view -----
  489.     FW_CRect drawViewBounds(contentRect);
  490.     if (drawViewBounds.Width() > drawingSize.x)
  491.         drawViewBounds.right = drawViewBounds.left + drawingSize.x;
  492.     if (drawViewBounds.Height() > drawingSize.y)
  493.         drawViewBounds.bottom = drawViewBounds.top + drawingSize.y;
  494.         
  495.     CDrawView* contentView = new CDrawView(ev, this, drawViewBounds, drawingSize, fDrawPart);
  496.     contentView->MakeContentView(ev);
  497.  
  498.     // ----- Create scroll bars and grow box in root frame only -----
  499.     FW_CScrollBar* vertSB = NULL;
  500.     FW_CScrollBar* horzSB = NULL;
  501.     if (this->IsRoot(ev))
  502.     {    
  503.         // ----- Create the vertical scroll bar
  504.         FW_CRect vertSbRect(contentRect.right, frameRect.top - FW_kFixedPos1, 
  505.                         frameRect.right + FW_kFixedPos1, contentRect.bottom + FW_kFixedPos1);
  506.         vertSB = FW_NEW(FW_CScrollBar, (ev, this, 0, vertSbRect));
  507.         
  508.         // ----- Create the horizontan scroll bar
  509.         FW_CRect horzSbRect(frameRect.left - FW_kFixedPos1, contentRect.bottom, 
  510.                     contentRect.right + FW_kFixedPos1, frameRect.bottom + FW_kFixedPos1);
  511.         horzSB = FW_NEW(FW_CScrollBar, (ev, this, 0, horzSbRect));
  512.         
  513.         // ----- Create the GrowBox gadget
  514.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, contentRect.BotRight());
  515.     }
  516.  
  517.     // ----- add a scroller to the Frame -----
  518.     FW_CScroller* scroller = FW_NEW(FW_CScrollBarScroller, (ev, this, horzSB, vertSB));
  519.     scroller->SetAutoScrollIncrement(ev, FW_CPoint(FW_IntToFixed(20), FW_IntToFixed(20)));
  520.     scroller->SetAutoScrollInset(ev, FW_IntToFixed(15));
  521.     AdoptScroller(ev, scroller);
  522.     
  523.     // ----- Horizontal ruler
  524.      FW_CRect HorzRulerRect(contentRect.left, 
  525.                              contentRect.top - kRulerWidth,
  526.                              contentRect.left + FW_Minimum(drawingSize.x, contentRect.Width()), 
  527.                              contentRect.top);
  528.     fHorzRuler = FW_NEW(CRuler, (ev, this, HorzRulerRect, FW_kXscrolling, fZoomFactor));
  529.     
  530.     // Set the content's extent
  531.     fHorzRuler->SetExtent(ev, FW_CPoint(drawingSize.x, kRulerWidth));    
  532.     // Change default view binding (ruler's size will be set in AdjustContentViewSize)
  533.     fHorzRuler->SetBindings(ev, FW_kFixedBounds);
  534.  
  535.     // ----- Vertical ruler
  536.      FW_CRect VertRulerRect(contentRect.left - kRulerWidth, 
  537.                              contentRect.top,
  538.                              contentRect.left, 
  539.                              contentRect.top + FW_Minimum(drawingSize.y, contentRect.Height()));
  540.     fVertRuler = FW_NEW(CRuler, (ev, this, VertRulerRect, FW_kYscrolling, fZoomFactor));
  541.     
  542.     // Set the content's extent
  543.     fVertRuler->SetExtent(ev, FW_CPoint(kRulerWidth, drawingSize.y));    
  544.     // Change default view binding (ruler's size will be set in AdjustContentViewSize)
  545.     fVertRuler->SetBindings(ev, FW_kFixedBounds);
  546.  
  547.     if (!fRulersShown)
  548.     {
  549.         fHorzRuler->SetVisible(ev, FALSE);
  550.         fVertRuler->SetVisible(ev, FALSE);
  551.     }
  552. #endif
  553. }
  554. **/
  555.  
  556. //----------------------------------------------------------------------------------------
  557. // CDrawFrame::GetContentRect
  558. //----------------------------------------------------------------------------------------
  559.  
  560. FW_CRect CDrawFrame::GetContentRect(Environment* ev) const
  561. {
  562.     FW_CRect contentRect = GetBounds(ev);
  563.  
  564.     if (fRulersShown) 
  565.     {
  566.         // Make space for rulers
  567.         contentRect.top += kRulerWidth;
  568.         contentRect.left += kRulerWidth;
  569.     }
  570.     
  571.     if (IsRoot(ev))
  572.     {
  573.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  574.     
  575.         contentRect.bottom -= sbSize.y;
  576.         contentRect.right -= sbSize.x;
  577.     }
  578.     
  579.     return contentRect;
  580. }
  581.  
  582. //----------------------------------------------------------------------------------------
  583. // CDrawFrame::AdjustContentViewSize
  584. //----------------------------------------------------------------------------------------
  585.  
  586. void CDrawFrame::AdjustContentViewSize(Environment* ev, FW_Boolean refresh)
  587. {
  588.     FW_CRect contentRect = GetContentRect(ev);    
  589.  
  590.     FW_CPoint drawingSize = fDrawPart->GetDrawingSize();
  591.     
  592.     // ----- I need to take into account the zoom factor -----
  593.     drawingSize.x *= fZoomFactor;
  594.     drawingSize.y *= fZoomFactor;
  595.  
  596.     FW_CPoint drawViewSize(FW_Minimum(drawingSize.x, contentRect.Width()),
  597.                             FW_Minimum(drawingSize.y, contentRect.Height()));
  598.  
  599.     FW_CPoint currentSize = GetContentView(ev)->GetSize(ev);
  600.     if (currentSize != drawViewSize)
  601.     {
  602.         fHorzRuler->SetSize(ev, FW_CPoint(drawViewSize.x, kRulerWidth), refresh);
  603.         fVertRuler->SetSize(ev, FW_CPoint(kRulerWidth, drawViewSize.y), refresh);            
  604.         GetContentView(ev)->SetSize(ev, drawViewSize, refresh);
  605.     }
  606. }
  607.  
  608. //----------------------------------------------------------------------------------------
  609. //    CDrawFrame::NewDragCommand
  610. //----------------------------------------------------------------------------------------
  611.  
  612. FW_CDragCommand* CDrawFrame::NewDragCommand(Environment *ev, FW_CFrame* theFrame, const FW_CMouseEvent& theMouseEvent)
  613. {
  614.     return FW_NEW(CDrawDragCommand, (ev, fDrawPart, theFrame,
  615.                                 fSelection,
  616.                                 FW_kCanUndo));
  617. }
  618.  
  619. //----------------------------------------------------------------------------------------
  620. //    CDrawFrame::NewDropCommand
  621. //----------------------------------------------------------------------------------------
  622.  
  623. FW_CDropCommand* CDrawFrame::NewDropCommand(Environment *ev,
  624.                                             FW_CFrame* frame,
  625.                                             ODDragItemIterator* dropInfo, 
  626.                                             ODFacet* facet, 
  627.                                             const FW_CPoint& dropPoint)
  628. {
  629.     return FW_NEW(CDrawDropCommand, (ev, fDrawPart, frame,
  630.                                     dropInfo, facet, dropPoint,
  631.                                     FW_kCanUndo));
  632. }
  633.  
  634. //----------------------------------------------------------------------------------------
  635. //    CDrawFrame::ToggleRulers
  636. //----------------------------------------------------------------------------------------
  637.  
  638. void CDrawFrame::ToggleRulers(Environment *ev, FW_Boolean visible, FW_Boolean refresh)
  639. {
  640.     FW_ASSERT(fHorzRuler != NULL && fVertRuler != NULL);
  641.     fHorzRuler->SetVisible(ev, visible);
  642.     fVertRuler->SetVisible(ev, visible);
  643.     
  644.     FW_CRect frameRect = GetContentRect(ev);
  645.     
  646.     GetContentView(ev)->SetLocation(ev, frameRect.TopLeft());
  647.     AdjustContentViewSize(ev, refresh);
  648. }
  649.  
  650. //----------------------------------------------------------------------------------------
  651. //    CDrawFrame::Draw
  652. //----------------------------------------------------------------------------------------
  653.  
  654. void CDrawFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  655. {    
  656.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  657.  
  658.     FW_CSuperView* contentView = GetContentView(ev);
  659.     FW_CRect contentRect = GetContentRect(ev);
  660.     FW_CRect contentBounds = contentView->GetBounds(ev);
  661.         
  662.     // The only thing to draw is the top left corner box
  663.     if (fRulersShown)
  664.     {
  665.         FW_CRect box(FW_kFixedNeg1, FW_kFixedNeg1, kRulerWidth, kRulerWidth);
  666.         FW_CRectShape::RenderRect(vc, box, FW_kFill, FW_kWhiteEraseInk);
  667.         FW_CRectShape::RenderRect(vc, box, FW_kFrame);
  668.         
  669.         contentRect.left -= kRulerWidth;
  670.         contentRect.top -= kRulerWidth;
  671.         
  672.         contentBounds.left -= kRulerWidth;
  673.         contentBounds.top -= kRulerWidth;
  674.     }
  675.     
  676.     FW_CAcquiredODShape shape1 = ::FW_NewODShape(ev, contentRect);
  677.     FW_CAcquiredODShape shape2 = ::FW_NewODShape(ev, contentBounds);
  678.     shape1->Subtract(ev, shape2);
  679.     if (!shape1->IsEmpty(ev))
  680.     {
  681.         FW_CRegionShape::RenderRegion(vc, shape1, FW_kFill, FW_kRGBLightGray);
  682.         
  683.         contentBounds.Inset(FW_kFixedNeg1, FW_kFixedNeg1);
  684.         FW_CRectShape::RenderRect(vc, contentBounds, FW_kFrame);
  685.     }
  686. }
  687.  
  688. //----------------------------------------------------------------------------------------
  689. //    CDrawFrame::NewPrintHandler
  690. //----------------------------------------------------------------------------------------
  691.  
  692. FW_CPrintHandler* CDrawFrame::NewPrintHandler(Environment* ev)
  693. {
  694.     return new CDrawPrintHandler(ev, this, fDrawPart->GetDrawContent(), GetPresentation(ev));
  695. }
  696.  
  697. //----------------------------------------------------------------------------------------
  698. //    CDrawFrame::RevealFrame
  699. //----------------------------------------------------------------------------------------
  700.  
  701. FW_Boolean CDrawFrame::RevealFrame(Environment *ev, 
  702.                                    ODFrame* embeddedFrame, 
  703.                                    ODShape* revealShape)
  704. {
  705.     FW_UNUSED(revealShape);
  706.  
  707.     // Look thru shape list for a proxy shape that matches the embeddedFrame
  708.     CDrawContentShapeIterator iter(fDrawPart->GetDrawContent());
  709.     for (CBaseShape* shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
  710.     {
  711.         if (shape->GetShapeType() == kProxyShape)
  712.         {
  713.             CProxyShape* proxyShape = (CProxyShape*)shape;
  714.             FW_CAcquiredODFrame proxyEmbeddedFrame = proxyShape->AcquireEmbeddedFrame(ev, this);
  715.             if (proxyEmbeddedFrame == embeddedFrame)
  716.             {
  717.                 // Select the proxy shape and redraw it
  718.                 fSelection->CloseSelection(ev);
  719.                 fSelection->AddToSelection(ev, proxyShape, TRUE);
  720.                 return TRUE;
  721.             }
  722.         }
  723.     }
  724.  
  725.     return FALSE;
  726. }
  727.  
  728. //----------------------------------------------------------------------------------------
  729. //    CDrawFrame::FacetAdded
  730. //----------------------------------------------------------------------------------------
  731.  
  732. void CDrawFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  733. {
  734.     FW_CEmbeddingFrame::FacetAdded(ev, facet, facetCount);    // Call inherited
  735.  
  736.     // Perform "DoPostCreate"-type initialization here.
  737.     fDrawPart->DoPostCreate(ev);
  738. }
  739.  
  740. //----------------------------------------------------------------------------------------
  741. //    CDrawFrame::ExternalizeFrame
  742. //----------------------------------------------------------------------------------------
  743.  
  744. void CDrawFrame::ExternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  745. {
  746.     FW_CEmbeddingFrame::ExternalizeFrame(ev, storageUnitView);
  747.     
  748.     FW_PStorageUnitSink suSink(ev, storageUnitView);
  749.     FW_CWritableStream stream(suSink);
  750.     
  751.     stream << fGridShown;
  752.     stream << fRulersShown;
  753.     stream << fZoomFactor;
  754. }
  755.  
  756. //----------------------------------------------------------------------------------------
  757. //    CDrawFrame::InternalizeFrame
  758. //----------------------------------------------------------------------------------------
  759.  
  760. void CDrawFrame::InternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  761. {
  762.     FW_CEmbeddingFrame::InternalizeFrame(ev, storageUnitView);
  763.  
  764.     FW_PStorageUnitSink suSink(ev, storageUnitView);
  765.     FW_PBufferedSink sink(ev, suSink);
  766.     FW_CReadableStream stream(sink);
  767.     
  768.     stream >> fGridShown;
  769.     stream >> fRulersShown;
  770.     stream >> fZoomFactor;
  771. }
  772.  
  773. //----------------------------------------------------------------------------------------
  774. //    CDrawFrame::FocusStateChanged
  775. //----------------------------------------------------------------------------------------
  776.  
  777. void CDrawFrame::FocusStateChanged(Environment *ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  778. {
  779.     FW_CEmbeddingFrame::FocusStateChanged(ev, focus, newState, newOwner);
  780.     
  781.     if (focus == FW_CPart::gSelectionFocusToken)
  782.     {        //    If I am losing the selection focus for a frame other than one of mine then
  783.         //    set back the current tool to the selection tool
  784.         if (!this->IsSiblingFrameOf(ev, newOwner))
  785.             fDrawPart->SetTool(ev, kSelectTool);
  786.         
  787.         //    • If I get the selection focus I redraw the handles only if the window is not active
  788.         //    if the window is active they already have been redrawn by DoActivateEvent
  789.         //    • If I am loosing the selection focus I redraw the handles only if the window is active
  790.         //    if the window is not active they already have been redrawn by DoActivateEvent
  791.         //    The events order is:
  792.         //        - Window 1 deactivated
  793.         //        - Frame 1 lose selection focus
  794.         //        - Frame 2 gain selection focus
  795.         //        - Window 2 activated
  796.         FW_Boolean windowActive = GetWindow(ev)->IsActive(ev);
  797.         FW_Boolean hilite = newState ? !windowActive : windowActive;
  798.         if (hilite)
  799.             fSelection->RenderAllHandles(ev, this);
  800.     }
  801. }
  802.  
  803. //----------------------------------------------------------------------------------------
  804. //    CDrawFrame::IsInLinkDestination
  805. //----------------------------------------------------------------------------------------
  806.  
  807. FW_Boolean CDrawFrame::IsInLinkDestination(Environment* ev)
  808. {
  809.     return (this->GetODFrame(ev)->GetLinkStatus(ev) == kODInLinkDestination);
  810. }
  811.  
  812. //----------------------------------------------------------------------------------------
  813. //    CDrawFrame::EmbeddedFrameRequested
  814. //----------------------------------------------------------------------------------------
  815.  
  816. FW_MProxy* CDrawFrame::EmbeddedFrameRequested(Environment *ev,
  817.                                             FW_MProxy* baseProxy,
  818.                                             ODFrame* baseFrame,
  819.                                             ODShape* frameShape,
  820.                                             ODPart* embeddedPart,
  821.                                             ODTypeToken viewType,
  822.                                             ODTypeToken presentation,
  823.                                             ODID frameGroupID,
  824.                                             FW_Boolean isOverlaid,
  825.                                             FW_Boolean isSubFrame)
  826. {
  827.     
  828.     FW_CPresentation* myPresentation = GetPresentation(ev);
  829.     
  830.     CProxyShape* baseProxyShape = (CProxyShape*)baseProxy;
  831.     FW_CRect embeddedFrameBounds = baseProxyShape->GetFrameRect(ev);
  832.  
  833.     embeddedFrameBounds.Offset(embeddedFrameBounds.Width(), FW_kFixed0);
  834.     
  835.     CProxyShape* proxy = FW_NEW(CProxyShape, (ev, embeddedFrameBounds, fDrawPart));
  836.         
  837.     FW_CRect tempRect(embeddedFrameBounds);
  838.     tempRect.Place(FW_kFixed0, FW_kFixed0);
  839.     FW_CAcquiredODShape aqFrameShape = ::FW_NewODShape(ev, tempRect);
  840.     
  841.     FW_TRY
  842.     {
  843.          myPresentation->Embed(ev, 
  844.                                 embeddedPart,
  845.                                 NULL,
  846.                                 kODFrameObject,
  847.                                 proxy,
  848.                                 aqFrameShape,
  849.                                 viewType,
  850.                                 presentation,
  851.                                 frameGroupID,
  852.                                 isOverlaid,
  853.                                 isSubFrame);
  854.     }
  855.     FW_CATCH_BEGIN
  856.     FW_CATCH_EVERYTHING () 
  857.     {
  858.         delete proxy;
  859.         FW_THROW_SAME ();
  860.     }
  861.     FW_CATCH_END
  862.     
  863.     // ----- Now I can add it to my data                
  864.     fDrawPart->AddShapeToPart(ev, proxy);
  865.  
  866.     // ----- Clip the facets -----
  867.     CDrawFacetClipper facetClipper(ev, fDrawPart);
  868.     FW_CAcquiredODShape limitShape = ::FW_NewODShape(ev, embeddedFrameBounds);
  869.     facetClipper.Clip(ev, myPresentation, limitShape);
  870.     
  871.     return proxy;
  872. }
  873.  
  874. //----------------------------------------------------------------------------------------
  875. // CDrawFrame::DoMouseDownInEmbeddedFrameBorder
  876. //----------------------------------------------------------------------------------------
  877. //    Start Dragging an embedded frame using the active border
  878.  
  879. FW_Boolean CDrawFrame::DoMouseDownInEmbeddedFrameBorder(Environment *ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  880. {    
  881.     fDrawPart->SetTool(ev, kSelectTool);
  882.  
  883.     Drag(ev, theBorderMouseEvent);
  884.     
  885.     return TRUE;
  886. }
  887.  
  888. //----------------------------------------------------------------------------------------
  889. // CDrawFrame::DoMouseDownInEmbeddedFrame
  890. //----------------------------------------------------------------------------------------
  891. //    Test for double click in a embeddedFrame
  892.  
  893. FW_Boolean CDrawFrame::DoMouseDownInEmbeddedFrame(Environment* ev, 
  894.                                                 const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
  895. {
  896.     FW_Boolean handled = FALSE;
  897.     
  898.     if (theEmbeddedMouseEvent.GetNumberOfClicks(ev) > 1)
  899.     {
  900.         ((FW_CEmbeddingFrame*)GetFrame(ev))->OpenSelection(ev);
  901.         handled = TRUE;
  902.     }
  903.     
  904.     return handled;
  905. }
  906.  
  907.