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 / ToolFrm.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  8.8 KB  |  311 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ToolFrm.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 TOOLFRM_H
  15. #include "ToolFrm.h"
  16. #endif
  17.  
  18. #ifndef DRAWPART_H
  19. #include "DrawPart.h"
  20. #endif
  21.  
  22. #ifndef CONSTANT_H
  23. #include "Constant.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 FWPOINT_H
  35. #include "FWPoint.h"
  36. #endif
  37.  
  38. #ifndef FWRECT_H
  39. #include "FWRect.h"
  40. #endif
  41.  
  42. #ifndef FWRECSHP_H
  43. #include "FWRecShp.h"
  44. #endif
  45.  
  46. #ifndef FWLINSHP_H
  47. #include "FWLinShp.h"
  48. #endif
  49.  
  50. #ifndef FWRESOUR_H
  51. #include "FWResour.h"
  52. #endif
  53.  
  54. #ifndef FWEVENT_H
  55. #include "FWEvent.h"
  56. #endif
  57.  
  58. // ----- OpenDoc Includes -----
  59.  
  60. #ifndef SOM_ODTransform_xh
  61. #include <Trnsform.xh>
  62. #endif
  63.  
  64. // ----- Platform Includes -----
  65.  
  66. #if defined(FW_BUILD_MAC) & !defined(__TOOLUTILS__)
  67. #include <ToolUtils.h>
  68. #endif
  69.  
  70. #if defined(FW_BUILD_MAC) & !defined(__LOWMEM__)
  71. #include <LowMem.h>
  72. #endif
  73.  
  74. //========================================================================================
  75. // Runtime Informations
  76. //========================================================================================
  77.  
  78. #ifdef FW_BUILD_MAC
  79. #pragma segment odfdrawframes
  80. #endif
  81.  
  82. //========================================================================================
  83. // CLASS CToolFrame
  84. //========================================================================================
  85.  
  86. //----------------------------------------------------------------------------------------
  87. // CToolFrame::CToolFrame
  88. //----------------------------------------------------------------------------------------
  89.  
  90. CToolFrame::CToolFrame(Environment *ev, ODFrame* odFrame, FW_CPresentation* presentation, CDrawPart *drawPart) :
  91.     CFloatingWindowFrame(ev, odFrame, presentation, drawPart),
  92.     fToolGrid(3, 2, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(2)), FW_CPoint(FW_IntToFixed(kToolCellSize), FW_IntToFixed(kToolCellSize)), FW_IntToFixed(1)),
  93.     fFillFrameGrid(1, 3, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(kFillFrameSelectorPos)), FW_CPoint(FW_IntToFixed(15), FW_IntToFixed(12)), FW_IntToFixed(0))
  94. {
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. // CToolFrame::~CToolFrame
  99. //----------------------------------------------------------------------------------------
  100.  
  101. CToolFrame::~CToolFrame()
  102. {
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. // CToolFrame::Draw
  107. //----------------------------------------------------------------------------------------
  108.  
  109. void CToolFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  110. {
  111.     FW_CFacetContext fc(ev, odFacet, invalidShape);
  112.     fc.SetMapping(fMapping);
  113.     
  114.     EraseBackground(ev, fc);
  115.     
  116.     DrawTools(fc);
  117.     DrawColors(fc);
  118.  
  119.     FW_CRect rect(
  120.         FW_IntToFixed(2),
  121.         FW_IntToFixed(2 + kToolHeight + 3),
  122.         FW_IntToFixed(kToolWidth + 2),
  123.         FW_IntToFixed(2 + kToolHeight + 3 + kSelectorHeight));
  124.         
  125.     CWidget    widget(131);
  126.     widget.Render(fc, rect);
  127.  
  128.     DrawRenderVerb(fc, fDrawPart->GetRenderVerb(), FW_kRGBBlack);
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // CToolFrame::DrawTools
  133. //----------------------------------------------------------------------------------------
  134.  
  135. void CToolFrame::DrawTools(FW_CFacetContext& fc)
  136. {    
  137.     FW_CRect toolRect;
  138.     fToolGrid.GetExteriorGridRect(toolRect);
  139.  
  140.     CWidget    widget(128 + fDrawPart->GetRenderVerb() - 1);
  141.     widget.Render(fc, toolRect);
  142.  
  143.     InvertTool(fc, fDrawPart->GetTool(), TRUE);
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. // CToolFrame::DrawColors
  148. //----------------------------------------------------------------------------------------
  149.  
  150. void CToolFrame::DrawColors(FW_CFacetContext& fc)
  151. {
  152.     FW_CFixed left = FW_IntToFixed(4);
  153.     FW_CFixed top = FW_IntToFixed(kToolsWindowHeight - kColorSelectorHeight - 4);
  154.     FW_CRect colorRect(left, top, left + FW_IntToFixed(kColorSelectorWidth), top + FW_IntToFixed(kColorSelectorHeight));
  155.     
  156.     FW_CColor color;
  157.     
  158.     FW_CRectShape rectShape(colorRect, FW_kFill);
  159.     
  160.     fDrawPart->GetFillColor(color);
  161.     rectShape.GetInk()->SetForeColor(color);
  162.     rectShape.GetStyle()->SetPattern(fDrawPart->GetFillPattern());
  163.     rectShape.Render(fc);            // fill
  164.     
  165.     fDrawPart->GetFrameColor(color);
  166.     rectShape.GetInk()->SetForeColor(color);    
  167.     rectShape.GetStyle()->SetPenSize(FW_IntToFixed(5));
  168.     rectShape.GetStyle()->SetPattern(fDrawPart->GetFramePattern());
  169.     rectShape.SetRenderVerb(FW_kFrame);
  170.     rectShape.Render(fc);            // frame
  171. }
  172.  
  173. //------------------------------------------------------------------------------
  174. // CToolFrame::DoMouseDown
  175. //------------------------------------------------------------------------------
  176.  
  177. FW_Boolean CToolFrame::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  178. {
  179.     FW_CPoint where = theMouseEvent.GetLogicalMousePosition(ev, fMapping);
  180.         
  181.     unsigned long tool;
  182.     if (fToolGrid.FindCell(where, tool))
  183.     {
  184.         fDrawPart->SetTool(ev, kSelectTool + tool);
  185.         return TRUE;
  186.     }
  187.     
  188.     unsigned long renderVerb;
  189.     if (fFillFrameGrid.FindCell(where, renderVerb))
  190.     {
  191.         fDrawPart->SetRenderVerb(ev, kFrameOnly + renderVerb);
  192.         return TRUE;
  193.     }
  194.         
  195.     return FALSE;
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. // CToolFrame::CheckTool
  200. //----------------------------------------------------------------------------------------
  201.  
  202. void CToolFrame::CheckTool(Environment *ev, unsigned short oldTool, unsigned short newTool)
  203. {
  204.     // ----- If we never have been shown fFacet == NULL
  205.     if (fFacet != NULL)
  206.     {
  207.         FW_CFacetContext fc(ev, fFacet);
  208.         fc.SetMapping(fMapping);
  209.         InvertTool(fc, oldTool, FALSE);
  210.         InvertTool(fc, newTool, TRUE);
  211.     }
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // CToolFrame::InvertTool
  216. //----------------------------------------------------------------------------------------
  217.  
  218. void CToolFrame::InvertTool(FW_CFacetContext& fc, unsigned short theTool, FW_Boolean state)
  219. {
  220.     if (theTool>0)
  221.     {
  222.         FW_CRect rect;
  223.         fToolGrid.GetCellInterior(theTool - kSelectTool, rect);
  224.  
  225. #ifdef FW_BUILD_MAC
  226.         if (state)
  227.         {
  228.             FW_PInk ink(FW_kRGBDarkGray, FW_kRGBWhite, FW_kHilite);    
  229.             FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
  230.             ink->SetForeColor(FW_kRGBWhite);
  231.             ink->SetBackColor(FW_kRGBGray);    
  232.             FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
  233.             ink->SetForeColor(FW_kRGBGray);
  234.             ink->SetBackColor(FW_kRGBLightGray);    
  235.             FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
  236.         }
  237.         else
  238.         {
  239.             FW_PInk ink(FW_kRGBLightGray, FW_kRGBGray, FW_kHilite);    
  240.             FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
  241.             ink->SetForeColor(FW_kRGBGray);
  242.             ink->SetBackColor(FW_kRGBWhite);    
  243.             FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
  244.             ink->SetForeColor(FW_kRGBWhite);
  245.             ink->SetBackColor(FW_kRGBDarkGray);    
  246.             FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
  247.         }
  248. #endif
  249.  
  250. #ifdef FW_BUILD_WIN
  251. FW_UNUSED(state);
  252.         FW_CRectShape::RenderRect(fc, rect, FW_kFill, FW_kInvertInk);
  253. #endif
  254.     }    
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. // CToolFrame::CheckRenderVerb
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void CToolFrame::CheckRenderVerb(Environment *ev, unsigned short oldRenderVerb, unsigned short newRenderVerb)
  262. {
  263.     // If we never have been shown fFacet == NULL
  264.     if (fFacet != NULL)
  265.     {
  266.         FW_CFacetContext fc(ev, fFacet);
  267.         fc.SetMapping(fMapping);
  268.         DrawRenderVerb(fc, oldRenderVerb, FW_kRGBLightGray);
  269.         DrawRenderVerb(fc, newRenderVerb, FW_kRGBBlack);
  270.         DrawTools(fc);
  271.     }
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. // CToolFrame::DrawRenderVerb
  276. //----------------------------------------------------------------------------------------
  277.  
  278. void CToolFrame::DrawRenderVerb(FW_CFacetContext& fc, unsigned short renderVerb, const FW_CColor& color)
  279. {
  280.     if (renderVerb>0)
  281.     {
  282.         FW_CRect rect;
  283.         fFillFrameGrid.GetCellInterior(renderVerb - kFrameOnly, rect);
  284.         rect.Offset(FW_IntToFixed(0), FW_IntToFixed(4));
  285.         rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
  286.         
  287.         FW_PStyle style(FW_IntToFixed(2));
  288.         FW_PInk ink(color);
  289.         FW_CLineShape::RenderLine(fc, 
  290.                                 FW_CPoint(rect.left + FW_IntToFixed(1), rect.bottom),
  291.                                 FW_CPoint(rect.right, rect.bottom),
  292.                                 ink,
  293.                                 style);
  294.     }
  295. }
  296.  
  297. //----------------------------------------------------------------------------------------
  298. // CToolFrame::UpdateColors
  299. //----------------------------------------------------------------------------------------
  300.  
  301. void CToolFrame::UpdateColors(Environment *ev)
  302. {
  303.     // If we never have been shown fFacet == NULL
  304.     if (fFacet != NULL)
  305.     {
  306.         FW_CFacetContext fc(ev, fFacet);
  307.         fc.SetMapping(fMapping);
  308.         DrawColors(fc);
  309.     }
  310. }
  311.