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 / Utils.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  10.5 KB  |  358 lines  |  [TEXT/MPS ]

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