home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / Utils.cpp < prev   
Encoding:
Text File  |  1995-11-08  |  10.2 KB  |  339 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Utils.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef UTILS_H
  15. #include "Utils.h"
  16. #endif
  17.  
  18. #ifndef DRAWPART_H
  19. #include "DrawPart.h"
  20. #endif
  21.  
  22. #ifndef DRAWFRM_H
  23. #include "DrawFrm.h"
  24. #endif
  25.  
  26. // ----- Part Layer -----
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. // ----- OS Layer -----
  33.  
  34. #ifndef FWRECT_H
  35. #include "FWRect.h"
  36. #endif
  37.  
  38. #ifndef FWACQUIR_H
  39. #include "FWAcquir.h"
  40. #endif
  41.  
  42. #ifndef FWBMPSHP_H
  43. #include "FWBmpShp.h"
  44. #endif
  45.  
  46. #ifndef FWPICSHP_H
  47. #include "FWPicShp.h"
  48. #endif
  49.  
  50. #ifndef FWLINSHP_H
  51. #include "FWLinShp.h"
  52. #endif
  53.  
  54. #ifndef FWRESOUR_H
  55. #include "FWResour.h"
  56. #endif
  57.  
  58. #ifndef FWSUSINK_H
  59. #include "FWSUSink.h"
  60. #endif
  61.  
  62. #ifndef SOM_ODFacet_xh
  63. #include <Facet.xh>
  64. #endif
  65.  
  66. //========================================================================================
  67. //    Runtime Informations
  68. //========================================================================================
  69.  
  70. #ifdef FW_BUILD_MAC
  71. #pragma segment odfdraw
  72. #endif
  73.  
  74. //========================================================================================
  75. //    class CGrid
  76. //========================================================================================
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    CGrid::CGrid
  80. //----------------------------------------------------------------------------------------
  81.  
  82. CGrid::CGrid(unsigned short rows, unsigned short columns, 
  83.             const FW_CPoint& position, 
  84.             const FW_CPoint& cellInterior, 
  85.             FW_CFixed penSize) :
  86.     fRows(rows),
  87.     fColumns(columns),
  88.     fCellSize(cellInterior.x + penSize, cellInterior.y + penSize),
  89.     fHalfPenSize(penSize.Half()),
  90.     fPosition(position.x + penSize.Half(), position.y + penSize.Half())
  91. {
  92.     
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //    CGrid::FindCell
  97. //----------------------------------------------------------------------------------------
  98.  
  99. FW_Boolean CGrid::FindCell(const FW_CPoint& where, unsigned long& index) const
  100. {
  101.     FW_CRect rect;
  102.     unsigned long lastIndex = fRows * fColumns;
  103.     for (unsigned long x = 0; x < lastIndex; x++)
  104.     {
  105.         GetCellInterior(x, rect);
  106.         if (rect.Contains(where))
  107.         {
  108.             index = x;
  109.             return TRUE;
  110.         }
  111.     }
  112.     
  113.     return FALSE;
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    CGrid::FindCell
  118. //----------------------------------------------------------------------------------------
  119.  
  120. FW_Boolean CGrid::FindCell(const FW_CPoint& where, unsigned short& row, unsigned short& column) const
  121. {
  122.     FW_CRect rect;
  123.     for (unsigned short x = 0; x < fColumns; x++)
  124.         for (unsigned short y = 0; y < fRows; y++)
  125.         {
  126.             GetCellInterior(y, x, rect);
  127.             if (rect.Contains(where))
  128.             {
  129.                 column = x;
  130.                 row = y;
  131.                 return TRUE;
  132.             }
  133.         }
  134.     
  135.     return FALSE;
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    CGrid::GetCellInterior
  140. //----------------------------------------------------------------------------------------
  141.  
  142. void CGrid::GetCellInterior(unsigned short row, unsigned short column, FW_CRect& rect) const
  143. {
  144.     FW_ASSERT(row <= fRows && column <= fColumns);
  145.     rect.Set(FW_IntToFixed(0), FW_IntToFixed(0), fCellSize.x, fCellSize.y);
  146.     rect.Place(fCellSize.x.MultipliedByInt(column), fCellSize.y.MultipliedByInt(row));
  147.     rect.Inset(fHalfPenSize, fHalfPenSize);
  148.     rect.Offset(fPosition.x, fPosition.y);
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    CGrid::GetCellInterior
  153. //----------------------------------------------------------------------------------------
  154.  
  155. void CGrid::GetCellInterior(unsigned long index, FW_CRect& rect) const
  156. {
  157.     unsigned short row, column;
  158.     GetRowColumn(index, row, column);
  159.     GetCellInterior(row, column, rect);
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    CGrid::GetCellExterior
  164. //----------------------------------------------------------------------------------------
  165.  
  166. void CGrid::GetCellExterior(unsigned short row, unsigned short column, FW_CRect& rect) const
  167. {
  168.     FW_ASSERT(row <= fRows && column <= fColumns);
  169.     rect.Set(FW_IntToFixed(0), FW_IntToFixed(0), fCellSize.x, fCellSize.y);
  170.     rect.Place(fCellSize.x.MultipliedByInt(column), fCellSize.y.MultipliedByInt(row));
  171.     rect.Inset(-fHalfPenSize, -fHalfPenSize);
  172.     rect.Offset(fPosition.x, fPosition.y);
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    CGrid::GetCellExterior
  177. //----------------------------------------------------------------------------------------
  178.  
  179. void CGrid::GetCellExterior(unsigned long index, FW_CRect& rect) const
  180. {
  181.     unsigned short row, column;
  182.     GetRowColumn(index, row, column);
  183.     GetCellExterior(row, column, rect);
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    CGrid::GetRowColumn
  188. //----------------------------------------------------------------------------------------
  189.  
  190. void CGrid::GetRowColumn(unsigned long index, unsigned short& row, unsigned short& column) const
  191. {
  192.     row = index / fColumns;
  193.     column = index - (row * fColumns);
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    CGrid::GetExteriorGridRect
  198. //----------------------------------------------------------------------------------------
  199.  
  200. void CGrid::GetExteriorGridRect(FW_CRect& rect) const
  201. {
  202.     rect.Set(FW_IntToFixed(0), FW_IntToFixed(0), fCellSize.x.MultipliedByInt(fColumns), fCellSize.y.MultipliedByInt(fRows));
  203.     rect.Inset(-fHalfPenSize, -fHalfPenSize);
  204.     rect.Offset(fPosition.x, fPosition.y);
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    CGrid::GetInteriorGridRect
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void CGrid::GetInteriorGridRect(FW_CRect& rect) const
  212. {
  213.     rect.Set(FW_IntToFixed(0), FW_IntToFixed(0), fCellSize.x.MultipliedByInt(fColumns), fCellSize.y.MultipliedByInt(fRows));
  214.     rect.Inset(fHalfPenSize, fHalfPenSize);
  215.     rect.Offset(fPosition.x, fPosition.y);
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    CGrid::DrawGridBorders
  220. //----------------------------------------------------------------------------------------
  221.  
  222. void CGrid::DrawGridBorders(FW_CFacetContext& fc, const FW_PInk& ink, const FW_PStyle& style)
  223. {
  224.     FW_CPoint position(fPosition.x - fHalfPenSize, fPosition.y - fHalfPenSize);
  225.     FW_CLineShape line(position.x, position.y, position.x + fCellSize.x.MultipliedByInt(fColumns), position.y);
  226.     line.SetInk(ink);
  227.     line.SetStyle(style);
  228.     unsigned short i;
  229.     for (i = 0; i <= fRows; i++)
  230.     {
  231.         line.Render(fc);
  232.         line.MoveShape(FW_IntToFixed(0), fCellSize.y);
  233.     }
  234.  
  235.     line.SetLineStart(position.x, position.y);
  236.     line.SetLineEnd(position.x, position.y + fCellSize.y.MultipliedByInt(fRows));
  237.     for (i = 0; i <= fColumns; i++)
  238.     {
  239.         line.Render(fc);
  240.         line.MoveShape(fCellSize.x, FW_IntToFixed(0));
  241.     }
  242. }
  243.  
  244. //========================================================================================
  245. //    class CWidget
  246. //========================================================================================
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    CWidget::CWidget
  250. //----------------------------------------------------------------------------------------
  251.  
  252. CWidget::CWidget(FW_ResourceId resId) :
  253.     fResId(resId)
  254. {
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    CWidget::~CWidget
  259. //----------------------------------------------------------------------------------------
  260.  
  261. CWidget::~CWidget()
  262. {
  263. }
  264.  
  265. //----------------------------------------------------------------------------------------
  266. //    CWidget::Render
  267. //----------------------------------------------------------------------------------------
  268.  
  269. void CWidget::Render(FW_CFacetContext& fc, const FW_CRect& rect)
  270. {
  271.     FW_CSharedLibraryResourceFile partResFile;
  272.  
  273. #ifdef FW_BUILD_MAC
  274.     FW_PPicture    picture(partResFile, fResId);
  275.     FW_CPictureShape::RenderPicture(fc, picture, rect);
  276. #endif
  277. #ifdef FW_BUILD_WIN
  278.     FW_PBitmap bitmap(partResFile, fResId);
  279.     FW_CBitmapShape::RenderBitmap(fc, bitmap, rect);
  280. #endif
  281. }
  282.  
  283. //========================================================================================
  284. //    class CDrawReadableStream
  285. //========================================================================================
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    CDrawReadableStream::CDrawReadableStream
  289. //----------------------------------------------------------------------------------------
  290.  
  291. CDrawReadableStream::CDrawReadableStream(Environment* ev, 
  292.                                          CDrawPart* drawPart, 
  293.                                          FW_CStorageUnitSink* sink,
  294.                                          FW_CCloneInfo* cloneInfo):
  295.     FW_CReadableStream(sink),
  296.     fEnvironment(ev),
  297.     fDrawPart(drawPart),
  298.     fCloneInfo(cloneInfo)
  299. {
  300.     FW_END_CONSTRUCTOR
  301. }
  302.  
  303. //----------------------------------------------------------------------------------------
  304. //    CDrawReadableStream::CDrawReadableStream
  305. //----------------------------------------------------------------------------------------
  306.  
  307. CDrawReadableStream::~CDrawReadableStream()
  308. {
  309.     FW_START_DESTRUCTOR
  310. }
  311.  
  312. //========================================================================================
  313. //    class CDrawWritableStream
  314. //========================================================================================
  315.  
  316. //----------------------------------------------------------------------------------------
  317. //    CDrawWritableStream::CDrawWritableStream
  318. //----------------------------------------------------------------------------------------
  319.  
  320. CDrawWritableStream::CDrawWritableStream(Environment* ev, FW_CStorageUnitSink* sink, FW_CCloneInfo* cloneInfo):
  321.     FW_CWritableStream(sink),
  322.     fEnvironment(ev),
  323.     fCloneInfo(cloneInfo)
  324. {
  325.     FW_END_CONSTRUCTOR
  326. }
  327.  
  328. //----------------------------------------------------------------------------------------
  329. //    CDrawWritableStream::CDrawWritableStream
  330. //----------------------------------------------------------------------------------------
  331.  
  332. CDrawWritableStream::~CDrawWritableStream()
  333. {
  334.     FW_START_DESTRUCTOR
  335. }
  336.  
  337.  
  338.  
  339.