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 / BoundShp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.0 KB  |  407 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BoundShp.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 BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef UTILS_H
  23. #include "Utils.h"
  24. #endif
  25.  
  26. #ifndef CONSTANT_H
  27. #include "Constant.h"
  28. #endif
  29.  
  30. #ifndef DRAWPART_H
  31. #include "DrawPart.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWFRM_H
  39. #include "DrawFrm.h"
  40. #endif
  41.  
  42. #ifndef DRAWPRXY_H
  43. #include "DrawPrxy.h"
  44. #endif
  45.  
  46. #ifndef DRAWLINK_H
  47. #include "DrawLink.h"
  48. #endif
  49.  
  50. #ifndef DRAWCLIP_H
  51. #include "DrawClip.h"
  52. #endif
  53.  
  54. // ----- Part Layer -----
  55.  
  56. #ifndef FWDSCOPR_H
  57. #include "FWDscOpr.h"
  58. #endif
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. // ----- OpenDoc Includes -----
  107.  
  108. #ifndef SOM_ODTransform_xh
  109. #include <Trnsform.xh>
  110. #endif
  111.  
  112. //========================================================================================
  113. // Runtime Information
  114. //========================================================================================
  115.  
  116. #ifdef FW_BUILD_MAC
  117. #pragma segment odfdrawshapes
  118. #endif
  119.  
  120. //========================================================================================
  121. // RunTime Info
  122. //========================================================================================
  123.  
  124. FW_DEFINE_CLASS_M1(CBoundedShape, CBaseShape)
  125. FW_DEFINE_AUTO(CBoundedShape)
  126.  
  127. //========================================================================================
  128. // class CBoundedShape
  129. //========================================================================================
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // CBoundedShape::CBoundedShape
  133. //----------------------------------------------------------------------------------------
  134.  
  135. CBoundedShape::CBoundedShape(CDrawPart* drawPart, unsigned short shapeType, unsigned short renderVerb) :
  136.     CBaseShape(drawPart, 4, shapeType, renderVerb)
  137. {
  138.     FW_END_CONSTRUCTOR
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. // CBoundedShape::CBoundedShape
  143. //----------------------------------------------------------------------------------------
  144.  
  145. CBoundedShape::CBoundedShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  146.     CBaseShape(drawPart, archive)
  147. {    
  148.     FW_CRect tempRect;
  149.     archive >> tempRect;
  150.     
  151.     SetRectGeometry(tempRect);
  152.     
  153.     FW_END_CONSTRUCTOR
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // CBoundedShape::~CBoundedShape
  158. //----------------------------------------------------------------------------------------
  159.  
  160. CBoundedShape::~CBoundedShape()
  161. {
  162.     FW_START_DESTRUCTOR
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. // CBoundedShape::GetHandleCenter
  167. //----------------------------------------------------------------------------------------
  168.  
  169. void CBoundedShape::GetHandleCenter(short whichHandle, FW_CPoint& center) const
  170. {    
  171.     if (fNumberOfHandles == 1)
  172.         whichHandle = kInTopLeftCorner;
  173.     else if (fNumberOfHandles == 2)
  174.     {
  175.         whichHandle = (whichHandle == kInTopLeftCorner) ? kInTopLeftCorner : kInBottomRightCorner;
  176.     }
  177.     
  178.     switch (whichHandle)
  179.     {
  180.         case kInTopLeftCorner:
  181.             center.x = fRect.left;
  182.             center.y = fRect.top;
  183.             break;
  184.         case kInTopRightCorner:
  185.             center.x = fRect.right;
  186.             center.y = fRect.top;
  187.             break;
  188.         case kInBottomLeftCorner:
  189.             center.x = fRect.left;
  190.             center.y = fRect.bottom;
  191.             break;
  192.         case kInBottomRightCorner:
  193.             center.x = fRect.right;
  194.             center.y = fRect.bottom;
  195.             break;
  196.     }
  197. }
  198.  
  199. //----------------------------------------------------------------------------------------
  200. // CBoundedShape::ResizeFeedback
  201. //----------------------------------------------------------------------------------------
  202.  
  203. void CBoundedShape::ResizeFeedback(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, 
  204.                                     short whichHandle, const FW_CPoint& mouseLoc)
  205. {
  206.     FW_CRect srcRect, dstRect;
  207.     GetMapRects(whichHandle, mouseLoc, srcRect, dstRect);
  208.     dstRect.Sort();
  209.     OutlineShape(gc, ink, style, dstRect);
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // CBoundedShape::GetMapRects
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void CBoundedShape::GetMapRects(short whichHandle, const FW_CPoint& mouseLoc,
  217.                                 FW_CRect& srcRect, FW_CRect& dstRect)
  218. {
  219.     srcRect = fRect;
  220.     dstRect = srcRect;
  221.     
  222.     switch (whichHandle)
  223.     {
  224.         case kInTopLeftCorner:
  225.             dstRect.left = mouseLoc.x;
  226.             dstRect.top = mouseLoc.y;
  227.             break;
  228.         case kInTopRightCorner:
  229.             dstRect.right = mouseLoc.x;
  230.             dstRect.top = mouseLoc.y;
  231.             break;
  232.         case kInBottomLeftCorner:
  233.             dstRect.left = mouseLoc.x;
  234.             dstRect.bottom = mouseLoc.y;
  235.             break;
  236.         case kInBottomRightCorner:
  237.             dstRect.right = mouseLoc.x;
  238.             dstRect.bottom = mouseLoc.y;
  239.             break;
  240.     }
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. // CBoundedShape::MapShape
  245. //----------------------------------------------------------------------------------------
  246.  
  247. void CBoundedShape::MapShape(Environment *ev, const FW_CRect& srcRect, const FW_CRect& dstRect)
  248. {
  249.     CheckPromise(ev);
  250.     
  251.     ClearCache(ev);
  252.  
  253.     FW_CRect tempRect = fRect;
  254.     tempRect.Map(srcRect, dstRect);    
  255.     tempRect.Sort();
  256.     
  257.     SetRectGeometry(tempRect);
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. // CBoundedShape::OffsetShape
  262. //----------------------------------------------------------------------------------------
  263.  
  264. void CBoundedShape::OffsetShape(Environment *ev, FW_Fixed xDelta, FW_Fixed yDelta)
  265. {
  266. FW_UNUSED(ev);
  267. //    CheckPromise(ev); [HLX] Do not call CheckPromise from OffsetShape or end up in a infinity loop
  268. //                        because externalize of a pict calls OffsetShape
  269.     ClearCache(ev);
  270.     FW_CRect tempRect = fRect;
  271.     tempRect.Offset(xDelta, yDelta);
  272.     SetRectGeometry(tempRect);
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. // CBoundedShape::SetShapeGeometry
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void CBoundedShape::SetShapeGeometry(const FW_CPoint& anchorPoint,  const FW_CPoint& currentPoint)
  280. {
  281.     FW_CRect tempRect = fRect;
  282.     if (anchorPoint.x < currentPoint.x)
  283.     {
  284.         tempRect.left = anchorPoint.x;
  285.         tempRect.right = currentPoint.x;
  286.     }
  287.     else
  288.     {
  289.         tempRect.left = currentPoint.x;
  290.         tempRect.right = anchorPoint.x;
  291.     }
  292.     
  293.     if (anchorPoint.y < currentPoint.y)
  294.     {
  295.         tempRect.top = anchorPoint.y;
  296.         tempRect.bottom = currentPoint.y;
  297.     }
  298.     else
  299.     {
  300.         tempRect.top = currentPoint.y;
  301.         tempRect.bottom = anchorPoint.y;
  302.     }
  303.     
  304.     SetRectGeometry(tempRect);
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // CBoundedShape::Flatten
  309. //----------------------------------------------------------------------------------------
  310.  
  311. void CBoundedShape::Flatten(FW_CWritableStream& archive)
  312. {    
  313.     CBaseShape::Flatten(archive);
  314.     archive << fRect;
  315. }
  316.  
  317. //----------------------------------------------------------------------------------------
  318. // CBoundedShape::SetRectGeometry
  319. //----------------------------------------------------------------------------------------
  320.  
  321. void CBoundedShape::SetRectGeometry(const FW_CRect& bounds)
  322. {
  323.     fRect = bounds;
  324.     
  325.     // Change the number of handles
  326.     if ((fRect.left == fRect.right) && (fRect.top == fRect.bottom))
  327.     {
  328.         fNumberOfHandles = 1;
  329.     }
  330.     if ((fRect.left == fRect.right) || (fRect.top == fRect.bottom))
  331.     {
  332.         fNumberOfHandles = 2;
  333.     }
  334.     else 
  335.         fNumberOfHandles = 4; 
  336. }
  337.     
  338. //----------------------------------------------------------------------------------------
  339. // CBoundedShape::GetRectGeometry
  340. //----------------------------------------------------------------------------------------
  341.  
  342. FW_CRect CBoundedShape::GetRectGeometry() const
  343. {
  344.     return fRect;
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. // CBoundedShape::HasProperty
  349. //----------------------------------------------------------------------------------------
  350.  
  351. FW_Boolean CBoundedShape::HasProperty(ODDescType whichProperty) const
  352. {
  353.     FW_Boolean result;
  354.     
  355.     if (whichProperty == pBounds)
  356.         result = TRUE;
  357.     else
  358.         result = CBaseShape::HasProperty(whichProperty);
  359.         
  360.     return result;
  361. }
  362.  
  363. //----------------------------------------------------------------------------------------
  364. // CBoundedShape::GetProperty
  365. //----------------------------------------------------------------------------------------
  366.  
  367. FW_Boolean CBoundedShape::GetProperty(Environment* ev,
  368.                                     FW_CPart* part,
  369.                                     FW_CDesc& propertyValue, 
  370.                                     ODDescType whichProperty,
  371.                                     ODDescType desiredType) const
  372. {
  373.     FW_Boolean result;
  374.     
  375.     if (whichProperty == pBounds)
  376.     {
  377.         propertyValue << GetRectGeometry();
  378.         result = TRUE;
  379.     }
  380.     else
  381.         result = CBaseShape::GetProperty(ev, part, propertyValue, whichProperty, desiredType);
  382.                 
  383.     return result;
  384. }
  385.  
  386. //----------------------------------------------------------------------------------------
  387. // CBoundedShape::SetProperty
  388. //----------------------------------------------------------------------------------------
  389.  
  390. void CBoundedShape::SetProperty(Environment* ev,
  391.                                 FW_CPart* part,
  392.                                 FW_CDesc& propertyValue,
  393.                                 ODDescType whichProperty)
  394. {
  395.     if (whichProperty == pBounds)
  396.     {
  397.         FW_CRect newBounds;
  398.         
  399.         propertyValue >> newBounds;
  400.         SetRectGeometry(newBounds);
  401.         
  402.         Invalidate(ev);
  403.     }
  404.     else
  405.         CBaseShape::SetProperty(ev, part, propertyValue, whichProperty);
  406. }
  407.