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

  1. //========================================================================================
  2. //
  3. //    File:                TextShp.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 BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef TEXTSHP_H
  23. #include "TextShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  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. #ifndef FWGRUTIL_H
  107. #include "FWGrUtil.h"
  108. #endif
  109.  
  110. // ----- Foundation Includes -----
  111.  
  112. #ifndef FWSTREAM_H
  113. #include "FWStream.h"
  114. #endif
  115.  
  116. // ----- OpenDoc Includes -----
  117.  
  118. #ifndef SOM_ODTransform_xh
  119. #include <Trnsform.xh>
  120. #endif
  121.  
  122. //========================================================================================
  123. // Runtime Information
  124. //========================================================================================
  125.  
  126. #ifdef FW_BUILD_MAC
  127. #pragma segment odfdrawshapes
  128. #endif
  129.  
  130. //========================================================================================
  131. // RunTime Info
  132. //========================================================================================
  133.  
  134. FW_DEFINE_AUTO(CTextShape)
  135. FW_DEFINE_CLASS_M1(CTextShape, CBoundedShape)
  136.  
  137. const FW_ClassTypeConstant LTextShape = FW_TYPE_CONSTANT('s','h','t','x');
  138. FW_REGISTER_ARCHIVABLE_CLASS(LTextShape, CTextShape, CTextShape::Read, 0, 0, CBaseShape::Write)
  139.  
  140. //========================================================================================
  141. // class CTextShape
  142. //========================================================================================
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // CTextShape::CTextShape
  146. //----------------------------------------------------------------------------------------
  147.  
  148. CTextShape::CTextShape(CDrawPart* drawPart) :
  149.     CBoundedShape(drawPart, kTextShape, kFrameOnly),
  150.     fText
  151. (
  152. "\"Young man\", said the Russian playwright Anton Chekhov, "
  153. "\"I see a brilliant future written on your face.\" "
  154. "These words were spoken to Serge Rachmaninoff."
  155. )
  156. {
  157.     FW_END_CONSTRUCTOR
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // CTextShape::CTextShape
  162. //----------------------------------------------------------------------------------------
  163.  
  164. CTextShape::CTextShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  165.     CBoundedShape(drawPart, archive)
  166. {
  167.     archive >> fText;
  168.     FW_END_CONSTRUCTOR
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. // CTextShape::~CTextShape
  173. //----------------------------------------------------------------------------------------
  174.  
  175. CTextShape::~CTextShape()
  176. {
  177.     FW_START_DESTRUCTOR
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. // CTextShape::RenderShape
  182. //----------------------------------------------------------------------------------------
  183.  
  184. void CTextShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  185. {
  186. FW_UNUSED(ev);
  187. FW_UNUSED(facet);
  188.     // Draw a frame
  189.     FW_CRect rect = GetRectGeometry();
  190.     AdjustRectForPenSize(rect, GetPenSize());
  191.  
  192.     if (HasFrameStyle())
  193.         FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  194.  
  195.     // Draw the text
  196.     FW_CFont font(FW_GetTimesFontName(), FW_kPlain, FW_IntToFixed(12));
  197.  
  198.     rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
  199.     FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxWordWrap | FW_kTextBoxWordBreak | FW_kTextBoxClipToBox;
  200.     FW_CTextBoxShape::RenderTextBox(gc, fText, rect, font, options, fFrameInk);
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. // CTextShape::HitTest
  205. //----------------------------------------------------------------------------------------
  206.  
  207. FW_Boolean CTextShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  208. {
  209.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  210.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  211.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  212.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  213.     
  214.     FW_CTextBoxShape textShape(fText, GetRectGeometry());
  215.     return textShape.HitTest(gc, mouse, FW_IntToFixed(2));
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. // CTextShape::OutlineShape
  220. //----------------------------------------------------------------------------------------
  221.  
  222. void CTextShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  223. {
  224.     FW_CRectShape::RenderRect(gc,
  225.                               rect,
  226.                               FW_kFrame,
  227.                               ink, style);
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. // CTextShape::CalcClipShape
  232. //----------------------------------------------------------------------------------------
  233.  
  234. ODShape* CTextShape::CalcClipShape(Environment *ev)
  235. {
  236.     return ::FW_NewODShape(ev, GetRectGeometry());
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. // CTextShape::CreateShapeOutline
  241. //----------------------------------------------------------------------------------------
  242.  
  243. ODShape* CTextShape::CreateShapeOutline(Environment *ev)
  244. {
  245.     // We don't acquire it because we return it
  246.     ODShape* dragRgn = ::FW_NewODShape(ev, GetRectGeometry());
  247.  
  248.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  249.  
  250.     return dragRgn;
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. // CTextShape::Flatten
  255. //----------------------------------------------------------------------------------------
  256.  
  257. void CTextShape::Flatten(FW_CWritableStream& archive)
  258. {    
  259.     CBoundedShape::Flatten(archive);
  260.     archive << fText;
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. // CTextShape::Read
  265. //----------------------------------------------------------------------------------------
  266.  
  267. void* CTextShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  268. {
  269. FW_UNUSED(type);
  270.     // [HLX] This is a hack until I can register object with the archiver
  271.     CDrawReadableStream *drawArchive = (CDrawReadableStream*)&stream;
  272.     return FW_NEW(CTextShape, (drawArchive->GetDrawPart(), stream));
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. // CTextShape::GetObjectClass
  277. //----------------------------------------------------------------------------------------
  278.  
  279. ODDescType CTextShape::GetObjectClass() const
  280. {
  281.     return cText;
  282. }
  283.  
  284.