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 / ODF / OS / FWGraphx / FWTxtBox.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.7 KB  |  351 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTxtBox.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWTXTBOX_H
  13. #include "FWTxtBox.h"
  14. #endif
  15.  
  16. #ifndef SLRENDER_H
  17. #include "SLRender.h"
  18. #endif
  19.  
  20. // ----- Foundation Includes -----
  21.  
  22. #ifndef FWSTREAM_H
  23. #include "FWStream.h"
  24. #endif
  25.  
  26. // ----- OpenDoc Includes -----
  27.  
  28. #ifndef _TRANSFORM_
  29. #include <Trnsform.xh>
  30. #endif
  31.  
  32. //========================================================================================
  33. // File scope definitions
  34. //========================================================================================
  35.  
  36. #ifdef FW_BUILD_MAC
  37. #pragma segment FWGraphics_TextBoxShape
  38. #endif
  39.  
  40. //========================================================================================
  41. //    class FW_CTextBoxShape
  42. //========================================================================================
  43.  
  44. FW_DEFINE_AUTO(FW_CTextBoxShape)
  45. FW_DEFINE_CLASS_M1(FW_CTextBoxShape, FW_CBaseTextShape)
  46.  
  47. // This class is archivable, but we provide the archiving implementation in a separate
  48. // translation unit in order to enable deadstripping of the archiving-related code
  49. // in parts that do not use archiving with this class.
  50.  
  51. //----------------------------------------------------------------------------------------
  52. //    FW_CTextBoxShape::FW_CTextBoxShape
  53. //----------------------------------------------------------------------------------------
  54.  
  55. FW_CTextBoxShape::FW_CTextBoxShape(const FW_CTextBoxShape& other) :
  56.     FW_CBaseTextShape(other),
  57.     fTextBox(other.fTextBox),
  58.     fOptions(other.fOptions)
  59. {
  60.     FW_END_CONSTRUCTOR
  61. }
  62.  
  63. //----------------------------------------------------------------------------------------
  64. //    FW_CTextBoxShape::FW_CTextBoxShape
  65. //----------------------------------------------------------------------------------------
  66.  
  67. FW_CTextBoxShape::FW_CTextBoxShape() :
  68.     FW_CBaseTextShape(),
  69.     fOptions(kDefaultJustification)
  70.         // fTextBox is set to 0's to its default constructor
  71. {
  72.     FW_END_CONSTRUCTOR
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    FW_CTextBoxShape::FW_CTextBoxShape
  77. //----------------------------------------------------------------------------------------
  78.  
  79. FW_CTextBoxShape::FW_CTextBoxShape(const FW_CString& string, 
  80.                                    const FW_CRect& box,
  81.                                    const FW_CFont& font,
  82.                                    FW_TextBoxOptions options,
  83.                                    const FW_CInk& ink) :
  84.     FW_CBaseTextShape(string, ink, font),
  85.     fOptions(options),
  86.     fTextBox(box)
  87. {
  88.     FW_END_CONSTRUCTOR
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    FW_CTextBoxShape::FW_CTextBoxShape
  93. //----------------------------------------------------------------------------------------
  94.  
  95. FW_CTextBoxShape::FW_CTextBoxShape(FW_CTextReader& textReader, 
  96.                                   const FW_CRect& box,
  97.                                    const FW_CFont& font,
  98.                                    FW_TextBoxOptions options,
  99.                                    const FW_CInk& ink) :
  100.     FW_CBaseTextShape(textReader, ink, font),
  101.     fOptions(options),
  102.     fTextBox(box)
  103. {
  104.     FW_END_CONSTRUCTOR
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    FW_CTextBoxShape::FW_CTextBoxShape
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_CTextBoxShape::FW_CTextBoxShape(FW_CReadableStream& stream) :
  112.     FW_CBaseTextShape(stream)
  113. {
  114.     stream >> fTextBox;
  115.     stream >> fOptions;
  116.  
  117.     FW_END_CONSTRUCTOR
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    FW_CTextBoxShape::~FW_CTextBoxShape
  122. //----------------------------------------------------------------------------------------
  123.  
  124. FW_CTextBoxShape::~FW_CTextBoxShape()
  125. {
  126.     FW_START_DESTRUCTOR
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. //    FW_CTextBoxShape::operator=
  131. //----------------------------------------------------------------------------------------
  132.  
  133. FW_CTextBoxShape& FW_CTextBoxShape::operator=(const FW_CTextBoxShape& other)
  134. {
  135.     if (this != &other)
  136.     {
  137.         FW_CBaseTextShape::operator=(other);
  138.         
  139.         fTextBox = other.fTextBox;
  140.         fOptions = other.fOptions;
  141.     }
  142.     
  143.     return *this;
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. //    FW_CTextBoxShape::Render
  148. //----------------------------------------------------------------------------------------
  149.  
  150. void FW_CTextBoxShape::Render(FW_CGraphicContext& gc) const
  151. {    
  152.     FW_PrivRenderTextBoxString(gc.GetEnvironment(),
  153.         gc,
  154.         fString,
  155.         fTextBox,
  156.         fOptions,
  157.         GetRenderVerb(),
  158.         fInk,
  159.         fFont);
  160.     FW_FailOnEvError(gc.GetEnvironment());
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CTextBoxShape::RenderTextBox
  165. //----------------------------------------------------------------------------------------
  166.  
  167. FW_Fixed FW_CTextBoxShape::RenderTextBox(FW_CGraphicContext& gc, 
  168.                                               FW_CTextReader& textReader, 
  169.                                             const FW_CRect& box,
  170.                                               const FW_CFont& font,
  171.                                             FW_TextBoxOptions options,
  172.                                               const FW_CInk& ink)
  173. {    
  174.     FW_Fixed result = FW_PrivRenderTextBoxReader(gc.GetEnvironment(), gc,
  175.                                                 textReader,
  176.                                                 box,
  177.                                                 options,
  178.                                                 FW_kFill,
  179.                                                 ink,
  180.                                                 font);
  181.     FW_FailOnEvError(gc.GetEnvironment());
  182.     return result;
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_CTextBoxShape::RenderTextBox
  187. //----------------------------------------------------------------------------------------
  188.  
  189. FW_Fixed FW_CTextBoxShape::RenderTextBox(FW_CGraphicContext& gc, 
  190.                                                   const FW_CString& string, 
  191.                                                 const FW_CRect& box,
  192.                                                   const FW_CFont& font,
  193.                                                 FW_TextBoxOptions options,
  194.                                                   const FW_CInk& ink)
  195. {    
  196.     FW_Fixed result = FW_PrivRenderTextBoxString(gc.GetEnvironment(), gc,
  197.                                     string,
  198.                                     box,
  199.                                     options,
  200.                                     FW_kFill,
  201.                                     ink,
  202.                                     font);
  203.     FW_FailOnEvError(gc.GetEnvironment());
  204.     return result;
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    FW_CTextBoxShape::UpdateTextBox
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void FW_CTextBoxShape::UpdateTextBox(FW_CGraphicContext& gc)
  212. {
  213.     FW_PrivTextBoxSizeString(gc.GetEnvironment(), gc,
  214.                             fString, 
  215.                             fFont, 
  216.                             fOptions, 
  217.                             fTextBox);    
  218.     FW_FailOnEvError(gc.GetEnvironment());
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_CTextBoxShape::CalcTextBox
  223. //----------------------------------------------------------------------------------------
  224.  
  225. void FW_CTextBoxShape::CalcTextBox(FW_CGraphicContext& gc, 
  226.                                       FW_CTextReader& textReader, 
  227.                                     FW_TextBoxOptions options,
  228.                                       const FW_CFont& font,
  229.                                     FW_CRect& box)
  230. {
  231.     FW_ByteCount savedPosition = textReader.GetPosition();
  232.     FW_PrivTextBoxSizeReader(gc.GetEnvironment(), gc,
  233.                             textReader, 
  234.                             font, 
  235.                             options, 
  236.                             box);    
  237.     FW_FailOnEvError(gc.GetEnvironment());
  238.     textReader.SetPosition(savedPosition);        // restore original textReader position
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242. //    FW_CTextBoxShape::CalcTextBox
  243. //----------------------------------------------------------------------------------------
  244.  
  245. void FW_CTextBoxShape::CalcTextBox(FW_CGraphicContext& gc, 
  246.                                       const FW_CString& string, 
  247.                                     FW_TextBoxOptions options,
  248.                                       const FW_CFont& font,
  249.                                     FW_CRect& box)
  250. {
  251.     FW_PrivTextBoxSizeString(gc.GetEnvironment(), gc,
  252.                             string, 
  253.                             font, 
  254.                             options, 
  255.                             box);    
  256.     FW_FailOnEvError(gc.GetEnvironment());
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_CTextBoxShape::Transform
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void FW_CTextBoxShape::Transform(Environment* ev, ODTransform* odTransform)
  264. {
  265.     fTextBox.Transform(ev, odTransform);
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. //    FW_CTextBoxShape::InverseTransform
  270. //----------------------------------------------------------------------------------------
  271.  
  272. void FW_CTextBoxShape::InverseTransform(Environment* ev, ODTransform* odTransform)
  273. {
  274.     fTextBox.InverseTransform(ev, odTransform);
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. //    FW_CTextBoxShape::Inset
  279. //----------------------------------------------------------------------------------------
  280.  
  281. void FW_CTextBoxShape::Inset(FW_Fixed x, FW_Fixed y)
  282. {
  283.     fTextBox.Inset(x, y);
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. //    FW_CTextBoxShape::Copy
  288. //----------------------------------------------------------------------------------------
  289.  
  290. FW_CShape* FW_CTextBoxShape::Copy() const
  291. {
  292.     return FW_NEW(FW_CTextBoxShape, (*this));
  293. }
  294.  
  295. //----------------------------------------------------------------------------------------
  296. //    FW_CTextBoxShape::MoveShape
  297. //----------------------------------------------------------------------------------------
  298.  
  299. void FW_CTextBoxShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
  300. {
  301.     fTextBox.left += deltaX;
  302.     fTextBox.top += deltaY;
  303.     fTextBox.right += deltaX;
  304.     fTextBox.bottom += deltaY;
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    FW_CTextBoxShape::MoveShapeTo
  309. //----------------------------------------------------------------------------------------
  310.  
  311. void FW_CTextBoxShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
  312. {
  313.     fTextBox.right += x - fTextBox.left;
  314.     fTextBox.bottom += y - fTextBox.top;
  315.     fTextBox.left = x;
  316.     fTextBox.top = y;
  317. }
  318.  
  319. //----------------------------------------------------------------------------------------
  320. //    FW_CTextBoxShape::GetBounds
  321. //----------------------------------------------------------------------------------------
  322.  
  323. void FW_CTextBoxShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  324. {
  325. FW_UNUSED(gc);
  326.  
  327.     rect = fTextBox;
  328. }
  329.  
  330. //----------------------------------------------------------------------------------------
  331. //    FW_CTextBoxShape::GetAnchorPoint
  332. //----------------------------------------------------------------------------------------
  333.  
  334. FW_CPoint FW_CTextBoxShape::GetAnchorPoint() const
  335. {
  336.     return fTextBox.TopLeft();
  337. }
  338.  
  339. //----------------------------------------------------------------------------------------
  340. //    FW_CTextBoxShape::Flatten
  341. //----------------------------------------------------------------------------------------
  342.  
  343. void FW_CTextBoxShape::Flatten(FW_CWritableStream& stream) const
  344. {
  345.     FW_CBaseTextShape::Flatten(stream);
  346.     
  347.     stream << fTextBox;
  348.     stream << fOptions;
  349. }
  350.  
  351.