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 / OS / FWGraphx / Sources / FWGrUtil.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  17.5 KB  |  646 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGrUtil.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWGRUTIL_H
  13. #include "FWGrUtil.h"
  14. #endif
  15.  
  16. #ifndef FWRECT_H
  17. #include "FWRect.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifndef FWBWPAT_H
  29. #include "FWBWPat.h"
  30. #endif
  31.  
  32. #ifndef FWGCONST_H
  33. #include "FWGConst.h"
  34. #endif
  35.  
  36. #ifndef FWREGION_H
  37. #include "FWRegion.h"
  38. #endif
  39.  
  40. #ifndef FWODGEOM_H
  41. #include "FWODGeom.h"
  42. #endif
  43.  
  44. // ----- Foundation Includes -----
  45.  
  46. #ifndef FWPRIDEB_H
  47. #include "FWPriDeb.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef SOM_ODShape_xh
  53. #include <Shape.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODTransform_xh
  57. #include <Trnsform.xh>
  58. #endif
  59.  
  60. // ----- C Includes -----
  61.  
  62. #if defined(FW_BUILD_MAC) & !defined(__FP__)
  63. #include <FP.h>
  64. #endif
  65.  
  66. #if defined(FW_BUILD_WIN) & !defined(__MATH_H)
  67. #include <Math.h>
  68. #endif
  69.  
  70. #ifdef FW_DEBUG
  71. #include <stdio.h>        // for sprintf()
  72. #endif
  73.  
  74. // ------ Platform includes ------
  75.  
  76. #if defined(FW_BUILD_MAC) & !defined(__QDOFFSCREEN__)
  77. #include <QDOffscreen.h>
  78. #endif
  79.  
  80. //========================================================================================
  81. //    RunTime Info
  82. //========================================================================================
  83.  
  84. #if FW_LIB_EXPORT_PRAGMAS
  85. #pragma lib_export on
  86. #endif
  87.  
  88. #ifdef FW_BUILD_MAC
  89. #pragma segment FWGraphx_GrUtil
  90. #endif
  91.  
  92. //========================================================================================
  93. //    Global Methods
  94. //========================================================================================
  95.  
  96. //-------------------------------------------------------------------------
  97. // FW_CreateLineODShape
  98. //-------------------------------------------------------------------------
  99.  
  100. FW_FUNC_ATTR ODShape* FW_CreateLineODShape(Environment *ev, const FW_CPoint& from, const FW_CPoint& to, FW_CFixed penSize)
  101. {
  102.     FW_CPoint lineThickness(penSize, penSize);
  103.     
  104.     ODShape* shape = ::FW_NewODShape(ev);
  105.     ::FW_SetShapeRegion(ev, shape, ::FW_CreateLineRegion( from, to, lineThickness));
  106.     return shape;
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CreateOvalODShape
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_FUNC_ATTR ODShape* FW_CreateOvalODShape(Environment *ev, const FW_CRect& rect)
  114. {
  115.     ODShape* shape = ::FW_NewODShape(ev);
  116.     ::FW_SetShapeRegion(ev, shape, ::FW_CreateOvalRegion(rect));
  117.     return shape;
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    FW_CreateArcODShape
  122. //----------------------------------------------------------------------------------------
  123.  
  124. FW_FUNC_ATTR ODShape* FW_CreateArcODShape(Environment *ev, const FW_CRect& rect, short startAngle, short arcAngle)
  125. {
  126.     ODShape* shape = ::FW_NewODShape(ev);
  127.     ::FW_SetShapeRegion(ev, shape, ::FW_CreateArcRegion(rect, startAngle, arcAngle));
  128.     return shape;
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CreateRoundRectODShape
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_FUNC_ATTR ODShape* FW_CreateRoundRectODShape(Environment *ev, const FW_CRect& rect, const FW_CPoint& ovalSize)
  136. {
  137.     ODShape* shape = ::FW_NewODShape(ev);
  138.     ::FW_SetShapeRegion(ev, shape, ::FW_CreateRoundRectRegion(rect, ovalSize));
  139.     return shape;
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_OutlineODShape
  144. //----------------------------------------------------------------------------------------
  145.  
  146. FW_FUNC_ATTR void FW_OutlineODShape(Environment *ev, ODShape* odShapeToOutline, FW_CFixed outlineSize)
  147. {
  148.     ODShape* odTempShape = ::FW_NewODShape(ev, odShapeToOutline);
  149.     
  150.     if (outlineSize <= FW_kFixed0)
  151.         outlineSize = FW_kFixedPos1;
  152.         
  153.     odTempShape->Outset(ev, -outlineSize.AsODFixed());
  154.     
  155.     odShapeToOutline->Subtract(ev, odTempShape);
  156.     odTempShape->Release(ev);
  157. }
  158.  
  159. #ifdef FW_BUILD_MAC
  160. //----------------------------------------------------------------------------------------
  161. //    FW_MacPrivGetPortTextStyle
  162. //----------------------------------------------------------------------------------------
  163.  
  164. void FW_MacPrivGetPortTextStyle(TextStyle& theTextStyle)
  165. {
  166.     GrafPtr curPort = FW_QDGlobals.thePort;
  167.     theTextStyle.tsFont = curPort->txFont;
  168.     theTextStyle.tsFace = curPort->txFace;
  169.     theTextStyle.tsSize = curPort->txSize;
  170. }
  171. #endif
  172.  
  173. #ifdef FW_BUILD_MAC
  174. //----------------------------------------------------------------------------------------
  175. //    FW_MacPrivSetPortTextStyle
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void FW_MacPrivSetPortTextStyle(const TextStyle& theTextStyle)
  179. {
  180.     ::TextFont(theTextStyle.tsFont);
  181.     ::TextFace(theTextStyle.tsFace);
  182.     ::TextSize(theTextStyle.tsSize);
  183. #endif
  184.  
  185. #ifdef FW_BUILD_MAC
  186. //----------------------------------------------------------------------------------------
  187. //    FW_MacIsColorPort
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_Boolean    FW_MacIsColorPort(GrafPtr grafPort)
  191. {
  192.     return ((CGrafPtr)grafPort)->portVersion < 0;
  193. }
  194. #endif
  195.  
  196. #ifdef FW_BUILD_MAC
  197. //========================================================================================
  198. //    class FW_CMacTempPort
  199. //========================================================================================
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CMacTempPort::FW_CMacTempPort
  203. //----------------------------------------------------------------------------------------
  204.  
  205. FW_CMacTempPort::FW_CMacTempPort(GrafPtr tempPort /* = NULL */)
  206. {
  207.     ::GetPort(&fMacPort);
  208.  
  209.     if (tempPort != NULL)
  210.         SetPort(tempPort);
  211.         
  212.     FW_END_CONSTRUCTOR
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    FW_CMacTempPort::~FW_CMacTempPort
  217. //----------------------------------------------------------------------------------------
  218.  
  219. FW_CMacTempPort::~FW_CMacTempPort()
  220. {
  221.     FW_START_DESTRUCTOR
  222.     
  223.     ::SetPort(fMacPort);
  224. }
  225.  
  226. #endif
  227.  
  228. #ifdef FW_BUILD_WIN
  229.  
  230. //----------------------------------------------------------------------------------------
  231. // FW_WinPrivGetDisplayColorInfo
  232. //----------------------------------------------------------------------------------------
  233.  
  234. FW_FUNC_ATTR void FW_WinPrivGetDisplayColorInfo(short& planeCount, short& bitsPixel)
  235. {
  236.     static short gPlaneCount = -1;
  237.     static short gBitsPixel = -1;
  238.     
  239.     if(gPlaneCount == -1)
  240.     {
  241.         HDC hDC = ::GetDC(NULL);
  242.         gPlaneCount = (short) ::GetDeviceCaps(hDC, PLANES);
  243.         gBitsPixel = (short) ::GetDeviceCaps(hDC, BITSPIXEL);
  244.         ::ReleaseDC(NULL, hDC);
  245.     }
  246.     
  247.     planeCount = gPlaneCount;
  248.     bitsPixel = gBitsPixel;
  249. }
  250.  
  251. #endif
  252.  
  253. //----------------------------------------------------------------------------------------
  254. //    FW_PtInOval
  255. //----------------------------------------------------------------------------------------
  256.  
  257. FW_FUNC_ATTR FW_Boolean FW_PtInOval(const FW_CRect& ovalRect, const FW_CPoint& test)
  258. {
  259.     // A brief refresher in fifth-grade geometry:
  260.     
  261.     // An ellipse (not an oval!) is defined as a set of points such as:
  262.     //    (x - x0/a)^2 + (y - y0/b)^2 <= 1, where:
  263.     //    <x0, y0> is the center of the ellipse
  264.     //    a is the x-radius and b is the y-radius
  265.  
  266.     // It is possible to get rid of division by evaluating
  267.     //    (bx)^2 + (ay)^2 <= a^2 * b^2, but this can overflow real easy
  268.  
  269.     if(ovalRect.Contains(test))
  270.     {
  271.         // Adjust center by 0.5 because of how rounding works
  272.         FW_CFixed xMiddle = (ovalRect.left + ovalRect.right  - FW_kFixedPos1).Half();
  273.         FW_CFixed yMiddle = (ovalRect.top  + ovalRect.bottom - FW_kFixedPos1).Half();
  274.         
  275.         FW_CFixed a = (ovalRect.right - ovalRect.left).Half();
  276.         FW_CFixed b = (ovalRect.bottom - ovalRect.top).Half();
  277.         
  278.         FW_CFixed xa = (test.x - xMiddle) / a;
  279.         xa *= xa;
  280.         
  281.         FW_CFixed xb = (test.y - yMiddle) / b;
  282.         xb *= xb;
  283.         
  284.         return xa + xb <= FW_IntToFixed(1);
  285.     }
  286.  
  287.     return FALSE;
  288. }
  289.  
  290. //----------------------------------------------------------------------------------------
  291. //    FW_PtInRoundRect
  292. //----------------------------------------------------------------------------------------
  293.  
  294. FW_FUNC_ATTR FW_Boolean    FW_PtInRoundRect(const FW_CRect& rect, const FW_CPoint& ovalSize, const FW_CPoint& test)
  295. {
  296.     if(rect.Contains(test))
  297.     {
  298.         // Find out if the test point may be inside of one of four corner ovals
  299.     
  300.         FW_CRect rectOval;
  301.     
  302.         if(test.x < rect.left + ovalSize.x.Half())
  303.         {
  304.             // Top-left and bottom-left ovals
  305.             rectOval.left = rect.left;
  306.             rectOval.right = rect.left + ovalSize.x;
  307.         }
  308.         else if(test.x > rect.right - ovalSize.x.Half())
  309.         {
  310.             // Top-right and bottom-right ovals
  311.             rectOval.left = rect.right - ovalSize.x;
  312.             rectOval.right = rect.right;
  313.         }
  314.  
  315.         if(test.y < rect.top + ovalSize.y.Half())
  316.         {
  317.             // Top-left and top-right
  318.             rectOval.top = rect.top;
  319.             rectOval.bottom = rect.top + ovalSize.y;
  320.         }
  321.         else if(test.y > rect.bottom - ovalSize.y.Half())
  322.         {
  323.             // Bottom-left and bottom-right ovals
  324.             rectOval.top = rect.bottom - ovalSize.y;
  325.             rectOval.bottom = rect.bottom;
  326.         }
  327.  
  328.         if(rectOval.IsEmpty())
  329.             return TRUE;
  330.  
  331.         return ::FW_PtInOval(rectOval, test);
  332.     }
  333.  
  334.     return FALSE;
  335. }
  336.  
  337. //----------------------------------------------------------------------------------------
  338. //    RegionCode
  339. //----------------------------------------------------------------------------------------
  340.  
  341. static short RegionCode(const FW_CPoint& line, const FW_CRect& rect)
  342. {
  343.     short regionCode = 0;
  344.     if (line.x < rect.left)
  345.         regionCode = 0x0008;
  346.     else if (line.x > rect.right)
  347.         regionCode = 0x0004;
  348.     
  349.     if (line.y < rect.top)
  350.         regionCode |= 0x0001;
  351.     else if (line.y > rect.bottom)
  352.         regionCode |= 0x0002;
  353.         
  354.     return regionCode;
  355. }
  356.  
  357. //----------------------------------------------------------------------------------------
  358. // ::FW_HitTestLine
  359. //----------------------------------------------------------------------------------------
  360. //    Uses a modified Cohen-Suterland with midpoint subdivision. Here we don't try to clip but
  361. //    just to find if a line intersect a rectangle of size 2*tolerance
  362.  
  363. FW_FUNC_ATTR FW_Boolean FW_HitTestLine(const FW_CPoint& pt1, const FW_CPoint& pt2,
  364.                                     const FW_CPoint& test, FW_CFixed tolerance)
  365. {
  366.     FW_CRect rect(test.x - tolerance,
  367.                 test.y - tolerance,
  368.                 test.x + tolerance,
  369.                 test.y + tolerance);
  370.     
  371.     short regionCode1, regionCode2, middleCode;
  372.     
  373.     if ((regionCode1 = RegionCode(pt1, rect)) == 0)
  374.         return TRUE;        // start is inside the rectangle
  375.         
  376.     if ((regionCode2 = RegionCode(pt2, rect)) == 0)
  377.         return TRUE;        // end is inside the rectangle
  378.         
  379.     if ((regionCode1 & regionCode2) != 0)
  380.         return FALSE;        // line totally outside
  381.     
  382.     FW_CPoint h1(pt1), h2(pt2);
  383.     FW_CPoint middle((h1.x + h2.x).Half(), (h1.y + h2.y).Half());
  384.  
  385.     while (middle != h1 || middle != h2)
  386.     {
  387.         if ((middleCode = RegionCode(middle, rect)) == 0)
  388.             return TRUE;    // middle is in the rectangle
  389.             
  390.         if ((middleCode & regionCode1) != 0)
  391.         {
  392.             // line (middle, h1) outside the rectangle 
  393.             h1 = middle;
  394.             regionCode1 = middleCode;
  395.         }
  396.         else
  397.         {
  398.             // line (h2, middle) outside the rectangle 
  399.             h2 = middle;
  400.             regionCode2 = middleCode;
  401.         }
  402.         
  403.         if ((regionCode1 & regionCode2) != 0)        
  404.             return FALSE;    // line (h1, h2) totally outside
  405.                  
  406.         middle.Set((h1.x + h2.x).Half(), (h1.y + h2.y).Half());
  407.     }
  408.     
  409.     return FALSE;
  410. }
  411.  
  412. //----------------------------------------------------------------------------------------
  413. //    FW_PrivCalcArcPoints
  414. //----------------------------------------------------------------------------------------
  415. //    [KVV] Need to be changed. Could do better than that.
  416.  
  417. void FW_PrivCalcArcPoints(const FW_SPlatformRect& rect, 
  418.                              short angle,
  419.                              FW_SPlatformPoint& arcPoint)
  420. {
  421.     if (angle >= 360)
  422.         angle = angle % 360;
  423.     else if(angle < 0)
  424.         angle = (angle % 360) + 360;
  425.         
  426.     FW_PlatformCoordinate middleX    = (rect.right + rect.left) / 2;
  427.     FW_PlatformCoordinate middleY    = (rect.right + rect.left) / 2;
  428.     const FW_CFixed halfX           = FW_IntToFixed((rect.right - rect.left) / 2);
  429.     const FW_CFixed halfY           = FW_IntToFixed((rect.bottom - rect.top) / 2);
  430.     
  431.     switch (angle)
  432.     {
  433.         case 0:
  434.             arcPoint.Set(middleX, rect.top);
  435.             break;
  436.         case 45:
  437.             arcPoint.Set(rect.right, rect.top);
  438.             break;
  439.         case 90:
  440.             arcPoint.Set(rect.right, middleY);
  441.             break;
  442.         case 135:
  443.             arcPoint.Set(rect.right, rect.bottom);
  444.             break;
  445.         case 180:
  446.             arcPoint.Set(middleX, rect.bottom);
  447.             break;
  448.         case 225:
  449.             arcPoint.Set(rect.left, rect.bottom);
  450.             break;
  451.         case 270:
  452.             arcPoint.Set(rect.left, middleY);
  453.             break;
  454.         case 315:
  455.             arcPoint.Set(rect.left, rect.top);
  456.             break;
  457.             
  458.         default:
  459.             FW_CFixed fxRad = (FW_IntToFixed(90 - angle) * FW_kFixedPI) / FW_IntToFixed(180);
  460.             if (angle < 45)
  461.                 arcPoint.Set((halfX * fxRad.Cos()).AsInt() + middleX, rect.top);
  462.             else if (angle > 45 && angle < 135)
  463.                 arcPoint.Set(rect.right, (halfY * fxRad.Sin()).AsInt() + middleY);
  464.             else if (angle < 180)
  465.                 arcPoint.Set((halfX * fxRad.Cos()).AsInt() + middleX, rect.bottom);
  466.             else
  467.             {
  468.                 fxRad = (FW_IntToFixed(angle - 270) * FW_kFixedPI) / FW_IntToFixed(180);
  469.                 if (angle < 45)
  470.                     arcPoint.Set(middleX - (halfX * fxRad.Cos()).AsInt(), rect.top);
  471.                 else if (angle > 45 && angle < 135)
  472.                     arcPoint.Set(rect.right, middleY - (halfY * fxRad.Sin()).AsInt());
  473.                 else if (angle < 180)
  474.                     arcPoint.Set(middleX - (halfX * fxRad.Cos()).AsInt(), rect.bottom);
  475.             }
  476.             break;
  477.     }
  478. }
  479.  
  480. //----------------------------------------------------------------------------------------
  481. // ::Priv_FormatPoint
  482. //----------------------------------------------------------------------------------------
  483.  
  484. static void Priv_FormatPoint(char *s, const char* prompt, const FW_CPoint& point)
  485. {
  486. #ifdef FW_DEBUG
  487.     sprintf(s, "%s X: %f Y: %f", prompt, point.x.AsDouble(), point.y.AsDouble());
  488. #endif
  489. }
  490.  
  491. //----------------------------------------------------------------------------------------
  492. // ::Priv_FormatRect
  493. //----------------------------------------------------------------------------------------
  494.  
  495. static void Priv_FormatRect(char *s, const char* prompt, const FW_CRect& rect)
  496. {
  497. #ifdef FW_DEBUG
  498.     sprintf(s, "%s left: %f top: %f right: %f bottom: %f",
  499.                 prompt, 
  500.                 rect.left.AsDouble(), 
  501.                 rect.top.AsDouble(),
  502.                 rect.right.AsDouble(), 
  503.                 rect.bottom.AsDouble());
  504. #endif
  505. }
  506.  
  507. //----------------------------------------------------------------------------------------
  508. // ::FW_LogPoint
  509. //----------------------------------------------------------------------------------------
  510.  
  511. FW_FUNC_ATTR void FW_LogPoint(Environment* ev, const char* prompt, const FW_CPoint& point)
  512. {
  513. #ifdef FW_DEBUG
  514.     char s[255];
  515.     Priv_FormatPoint(s, prompt, point);
  516.     FW_CDebugConsole::LogMessage(s);
  517. #endif
  518. }
  519.  
  520. //----------------------------------------------------------------------------------------
  521. // ::FW_LogRect
  522. //----------------------------------------------------------------------------------------
  523.  
  524. FW_FUNC_ATTR void FW_LogRect(Environment* ev, const char* prompt, const FW_CRect& rect)
  525. {
  526. #ifdef FW_DEBUG
  527.     char s[255];
  528.     Priv_FormatRect(s, prompt, rect);
  529.     FW_CDebugConsole::LogMessage(s);
  530. #endif
  531. }
  532.  
  533. //----------------------------------------------------------------------------------------
  534. // ::FW_LogShape
  535. //----------------------------------------------------------------------------------------
  536.  
  537. FW_FUNC_ATTR void FW_LogShape(Environment* ev, const char* prompt, ODShape* shape)
  538. {
  539. #ifdef FW_DEBUG
  540.     char s[255];
  541.     FW_CRect rect;
  542.     shape->GetBoundingBox(ev, (ODRect*) &rect);
  543.     FW_LogRect(ev, prompt, rect);
  544. #endif
  545. }
  546.  
  547. //----------------------------------------------------------------------------------------
  548. // ::FW_LogTransform
  549. //----------------------------------------------------------------------------------------
  550.  
  551. FW_FUNC_ATTR void FW_LogTransform(Environment* ev, const char* prompt, ODTransform* transform)
  552. {
  553. #ifdef FW_DEBUG
  554.     FW_CPoint ptScale;
  555.     transform->GetScale(ev, (ODPoint*) &ptScale);
  556.  
  557.     FW_CPoint ptOffset;
  558.     transform->GetOffset(ev, (ODPoint*) &ptOffset);
  559.  
  560.     char s[128];
  561.     ::sprintf(s,
  562.         "xform: %s: pt * [%.2f, %.2f] + [%.2f, %.2f]\n",
  563.         prompt,
  564.         ptScale.x.AsDouble(),            ptScale.y.AsDouble(),
  565.         ptOffset.x.AsDouble(),            ptOffset.y.AsDouble());
  566.         
  567.     FW_CDebugConsole::LogMessage(s);
  568. #endif
  569. }
  570.  
  571. #ifdef FW_BUILD_MAC
  572.  
  573. //----------------------------------------------------------------------------------------
  574. // ::FW_MacShowColorTable
  575. //----------------------------------------------------------------------------------------
  576.  
  577. FW_FUNC_ATTR void FW_MacShowColorTable(CTabHandle cth)
  578. {
  579. #ifdef FW_DEBUG
  580.     if (cth == NULL)
  581.         return;
  582.  
  583.     short nColors = (*cth)->ctSize + 1;
  584.  
  585.     short cellSize;
  586.     short xCount, yCount;
  587.     
  588.     if (nColors == 256)
  589.     {
  590.         cellSize = 30;
  591.         xCount = 16;
  592.         yCount = 16;
  593.     }
  594.     else
  595.     {
  596.         cellSize = 50;
  597.         xCount = 4;
  598.         yCount = nColors / xCount;
  599.     }
  600.     
  601.     GDHandle gd = ::GetMainDevice();
  602.     if ((*gd)->gdNextGD != NULL)
  603.         gd = (GDHandle) (*gd)->gdNextGD;
  604.  
  605.     PixMapHandle pmh = (*gd)->gdPMap;
  606.  
  607.     Rect rect;
  608.     rect.left    = (*pmh)->bounds.left + 50;
  609.     rect.top    = (*pmh)->bounds.top + 50;
  610.     rect.right    = rect.left + cellSize * xCount;
  611.     rect.bottom = rect.top + cellSize * yCount;
  612.  
  613.     WindowPtr window = ::NewCWindow(NULL, &rect, "\pColor table", TRUE,
  614.         noGrowDocProc, (WindowPtr) -1L, FALSE, 0);
  615.  
  616.     if (window != NULL)
  617.     {
  618.         FW_CMacTempPort port = window;
  619.         
  620.         short nCurColor = 0;
  621.         for (short xColor = 0; xColor < xCount; ++ xColor)
  622.         {
  623.             for (short yColor = 0; yColor < yCount; ++ yColor)
  624.             {
  625.                 ::RGBBackColor(&(*cth)->ctTable[nCurColor].rgb);
  626.  
  627.                 Rect cell;
  628.                 cell.left    = xColor * cellSize;
  629.                 cell.top    = yColor * cellSize;
  630.                 cell.right    = cell.left + cellSize;
  631.                 cell.bottom    = cell.top + cellSize;
  632.                 ::EraseRect(&cell);
  633.                 
  634.                 ++ nCurColor;
  635.             }
  636.         }
  637.     }
  638.     
  639.     if (window != NULL)
  640.         ::DisposeWindow(window);
  641. #endif
  642. }
  643.  
  644. #endif
  645.