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

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