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

  1. //========================================================================================
  2. //
  3. //    File:                FWCPat.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. #if defined(FW_PROFILER_CALLS) && defined(__MWERKS__)
  13. #pragma profile on
  14. #endif
  15.  
  16. #ifndef FWCPAT_H
  17. #include "FWCPat.h"
  18. #endif
  19.  
  20. #ifndef FWCOLOR_H
  21. #include "FWColor.h"
  22. #endif
  23.  
  24. #ifndef FWGRGLOB_H
  25. #include "FWGrGlob.h"
  26. #endif
  27.  
  28. #ifndef FWGRUTIL_H
  29. #include "FWGrUtil.h"
  30. #endif
  31.  
  32. #ifndef FWMEMHLP_H
  33. #include "FWMemHlp.h"
  34. #endif
  35.  
  36. #if defined(FW_BUILD_WIN) && !defined(FWWINDIB_H)
  37. #include "FWWinDIB.h"
  38. #endif
  39.  
  40. // ----- Foundation Includes -----
  41.  
  42. #ifndef FWSTREAM_H
  43. #include "FWStream.h"
  44. #endif
  45.  
  46. //========================================================================================
  47. // RunTime Info
  48. //========================================================================================
  49.  
  50. #if FW_LIB_EXPORT_PRAGMAS
  51. #pragma lib_export on
  52. #endif
  53.  
  54. #ifdef FW_BUILD_MAC
  55. #pragma segment FWGraphics_ColorPattern
  56. #endif
  57.  
  58. FW_DEFINE_CLASS_M1(FW_CColorPatternRep, FW_CPatternRep)
  59.  
  60. FW_REGISTER_ARCHIVABLE_CLASS(FW_LColorPatternRep, FW_CColorPatternRep, FW_CColorPatternRep::Read, FW_CPatternRep::Write)
  61.  
  62. //========================================================================================
  63. //    Forward Class Declarations
  64. //========================================================================================
  65.  
  66. //----------------------------------------------------------------------------------------
  67. //    FW_CColorPatternRep::FW_CColorPatternRep
  68. //----------------------------------------------------------------------------------------
  69.  
  70. FW_CColorPatternRep::FW_CColorPatternRep():
  71.     fPlatformColorPattern(NULL)
  72. {
  73.     FW_PixelPattern black =
  74.     {
  75.         {
  76.             {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  77.             {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  78.             {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  79.             {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  80.             {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  81.             {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  82.             {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  83.             {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}
  84.         }
  85.     };
  86.  
  87.     FW_CColor colors[2] = { FW_kRGBWhite, FW_kRGBBlack };
  88.     MakePixelPattern(black, 2, colors);
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    FW_CColorPatternRep::FW_CColorPatternRep
  93. //----------------------------------------------------------------------------------------
  94.  
  95. FW_CColorPatternRep::FW_CColorPatternRep(FW_PlatformColorPattern platformColorPattern) :
  96.     fPlatformColorPattern(platformColorPattern)
  97. {
  98.     FW_ASSERT(fPlatformColorPattern != NULL);
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    FW_CColorPatternRep::FW_CColorPatternRep
  103. //----------------------------------------------------------------------------------------
  104.  
  105. FW_CColorPatternRep::FW_CColorPatternRep(FW_CReadableStream& archive) :
  106.     fPlatformColorPattern(NULL)
  107. {
  108.     // Pattern data
  109.     FW_PixelPattern patData;
  110.     archive.Read(patData.fData, sizeof(patData));
  111.     
  112.     // Color count
  113.     unsigned short nbColors;
  114.     archive >> nbColors;
  115.     
  116.     // Colors
  117.     FW_CColor* colors = new FW_CColor[nbColors];
  118.     FW_TRY
  119.     {
  120.         for(int i = 0; i < nbColors; i ++)
  121.             archive >> colors[i];
  122.     
  123.         // Create the pattern
  124.         MakePixelPattern(patData, nbColors, colors);
  125.     }
  126.     FW_CATCH_BEGIN
  127.     FW_CATCH_EVERYTHING()
  128.     {
  129.         delete[] colors;
  130.         FW_THROW_SAME();
  131.     }
  132.     FW_CATCH_END
  133.     
  134.     // Clean up
  135.     delete[] colors;
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    FW_CColorPatternRep::FW_CColorPatternRep
  140. //----------------------------------------------------------------------------------------
  141.  
  142. FW_CColorPatternRep::FW_CColorPatternRep(const FW_PixelPattern& pixels, short nbColors, const FW_CColor* colorTable) :
  143.     fPlatformColorPattern(NULL)
  144. {
  145. #ifdef FW_BUILD_WIN
  146.     fWinCachedBitmap = NULL;
  147. #endif
  148.     
  149.     MakePixelPattern(pixels, nbColors, colorTable);
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_CColorPatternRep::~FW_CColorPatternRep
  154. //----------------------------------------------------------------------------------------
  155.  
  156. FW_CColorPatternRep::~FW_CColorPatternRep()
  157. {
  158. #ifdef FW_BUILD_MAC
  159.     if (fPlatformColorPattern)
  160.         ::DisposePixPat(fPlatformColorPattern);
  161. #endif
  162.  
  163. #ifdef FW_BUILD_WIN
  164.     if (fPlatformColorPattern != NULL)
  165.         FW_CPrivWinDIB::Free(fPlatformColorPattern);
  166.         
  167.     WinForgetCachedBitmap();
  168. #endif
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. //    FW_CColorPatternRep::IsBlack
  173. //----------------------------------------------------------------------------------------
  174.  
  175. FW_Boolean FW_CColorPatternRep::IsBlack() const
  176. {
  177.     return FALSE;
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. //    FW_CColorPatternRep::IsEqual
  182. //----------------------------------------------------------------------------------------
  183.  
  184. FW_Boolean FW_CColorPatternRep::IsEqual(const FW_CGraphicCountedPtrRep* other) const
  185. {
  186.     if (other == this)
  187.         return TRUE;
  188.         
  189.     FW_CColorPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CColorPatternRep, other);
  190.     if (patternRep == NULL)
  191.         return FALSE;
  192.  
  193.     // Compare the pixels        
  194.     FW_PixelPattern pixData1;
  195.     GetPixelData(pixData1);
  196.  
  197.     FW_PixelPattern pixData2;
  198.     patternRep->GetPixelData(pixData2);
  199.     
  200.     if(::memcmp(pixData1.fData, pixData2.fData, sizeof(FW_PixelPattern)) != 0)
  201.         return FALSE;
  202.     
  203.     // Compare the color tables
  204.     FW_CColor* colors1 = NULL;
  205.     unsigned short nbColors1 = GetColorTable(colors1);
  206.  
  207.     FW_CColor* colors2 = NULL;
  208.     unsigned short nbColors2 = patternRep->GetColorTable(colors2);
  209.     
  210.     if(nbColors1 != nbColors2)
  211.         return FALSE;
  212.         
  213.     if(::memcmp(colors1, colors2, sizeof(FW_CColor) * nbColors1) != 0)
  214.         return FALSE;
  215.  
  216.     return TRUE;
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    FW_CColorPatternRep::Copy
  221. //----------------------------------------------------------------------------------------
  222.  
  223. FW_PPattern FW_CColorPatternRep::Copy() const
  224. {
  225.     FW_PlatformColorPattern platformColorPattern;
  226.     
  227. #ifdef FW_BUILD_MAC
  228.     platformColorPattern = ::NewPixPat();
  229.     ::CopyPixPat(fPlatformColorPattern, platformColorPattern);
  230. #endif
  231.  
  232. #ifdef FW_BUILD_WIN
  233.     platformColorPattern = FW_CPrivWinDIB::CreateCopy(fPlatformColorPattern);
  234. #endif
  235.  
  236.     return FW_PPattern(platformColorPattern);
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    FW_CColorPatternRep::Flatten
  241. //----------------------------------------------------------------------------------------
  242.  
  243. void FW_CColorPatternRep::Flatten(FW_CWritableStream& archive) const
  244. {
  245.     // Pixel data
  246.     FW_PixelPattern pixData;
  247.     GetPixelData(pixData);
  248.     archive.Write(pixData.fData, sizeof(pixData));
  249.     
  250.     // ----- Colors
  251.     FW_CColor* colors = NULL;
  252.     unsigned short nbColors = GetColorTable(colors);
  253.     FW_TRY
  254.     {
  255.         archive << nbColors;
  256.         for(int i = 0; i < nbColors; i++)
  257.             archive << colors[i];
  258.     }
  259.     FW_CATCH_BEGIN
  260.     FW_CATCH_EVERYTHING()
  261.     {
  262.         // Clean up
  263.         delete[] colors;
  264.  
  265.         FW_THROW_SAME();
  266.     }
  267.     FW_CATCH_END
  268.     
  269.     // Clean up
  270.     delete[] colors;
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. //    FW_CColorPatternRep::Invert
  275. //----------------------------------------------------------------------------------------
  276.  
  277. void FW_CColorPatternRep::Invert()
  278. {
  279.     // Get current pattern info
  280.     FW_PixelPattern pixData;
  281.     GetPixelData(pixData);
  282.  
  283.     // ----- Look for minimum and maximun -----
  284.     unsigned char max = 0x00;
  285.     int i;
  286.     
  287.     for (i = 0; i < 8 * 8; i++)
  288.     {
  289.         unsigned char c = pixData.fDataRaw[i];
  290.         if (c > max)
  291.             max = c;            
  292.     }
  293.  
  294.     // ----- Invert it -----
  295.     for (i = 0; i < 8 * 8; i++)
  296.         pixData.fDataRaw[i] = max - pixData.fDataRaw[i];
  297.  
  298.     // Update the pattern
  299.     SetPixelData(pixData);
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. //    FW_CColorPatternRep::FlipVerticaly
  304. //----------------------------------------------------------------------------------------
  305.  
  306. void FW_CColorPatternRep::FlipVerticaly()
  307. {
  308.     // Get current pattern info
  309.     FW_PixelPattern pixData;
  310.     GetPixelData(pixData);
  311.     
  312.     // Flip it
  313.     for (short i = 0; i < 4; i++)
  314.         for (short j = 0; j < 2; j++)
  315.         {
  316.             unsigned long l = pixData.fDataLongs[i][j];
  317.             pixData.fDataLongs[i][j] = pixData.fDataLongs[7 - i][j];
  318.             pixData.fDataLongs[7 - i][j] = l;
  319.         }
  320.  
  321.     // Update the pattern
  322.     SetPixelData(pixData);
  323. }
  324.  
  325. //----------------------------------------------------------------------------------------
  326. //    FW_CColorPatternRep::FlipHorizontaly
  327. //----------------------------------------------------------------------------------------
  328.  
  329. void FW_CColorPatternRep::FlipHorizontaly()
  330. {    
  331.     // Get current pattern info
  332.     FW_PixelPattern pixData;
  333.     GetPixelData(pixData);
  334.     
  335.     // Flip it
  336.     for (short i = 0; i < 8; i++)
  337.         for (short j = 0; j < 4; j++)
  338.         {
  339.             unsigned char c = pixData.fData[i][j];
  340.             pixData.fData[i][j] = pixData.fData[i][7 - j];
  341.             pixData.fData[i][7 - j] = c;
  342.         }
  343.  
  344.     // Update the pattern
  345.     SetPixelData(pixData);
  346. }
  347.  
  348. //----------------------------------------------------------------------------------------
  349. //    FW_CColorPatternRep::ShiftRight
  350. //----------------------------------------------------------------------------------------
  351.  
  352. void FW_CColorPatternRep::ShiftRight()
  353. {
  354.     // Get current pattern info
  355.     FW_PixelPattern pixData;
  356.     GetPixelData(pixData);
  357.  
  358.     // Shift it
  359.     for (short i = 0; i < 8; i++)
  360.     {
  361.         unsigned char c = pixData.fData[i][7];
  362.         for(short j = 7; j > 0; j--)
  363.             pixData.fData[i][j] = pixData.fData[i][j - 1];
  364.         pixData.fData[i][0] = c;
  365.     }
  366.  
  367.     // Update the pattern
  368.     SetPixelData(pixData);
  369. }
  370.  
  371. //----------------------------------------------------------------------------------------
  372. //    FW_CColorPatternRep::ShiftLeft
  373. //----------------------------------------------------------------------------------------
  374.  
  375. void FW_CColorPatternRep::ShiftLeft()
  376. {
  377.     // Get current pattern info
  378.     FW_PixelPattern pixData;
  379.     GetPixelData(pixData);
  380.     
  381.     // Shift it
  382.     for (short i = 0; i < 8; i++)
  383.     {
  384.         unsigned char c = pixData.fData[i][0];
  385.         for(short j = 0; j < 7; j++)
  386.             pixData.fData[i][j] = pixData.fData[i][j + 1];
  387.         pixData.fData[i][7] = c;
  388.     }
  389.  
  390.     // Update the pattern
  391.     SetPixelData(pixData);
  392. }
  393.  
  394. //----------------------------------------------------------------------------------------
  395. //    FW_CColorPatternRep::ShiftUp
  396. //----------------------------------------------------------------------------------------
  397.  
  398. void FW_CColorPatternRep::ShiftUp()
  399. {
  400.     // Get current pattern info
  401.     FW_PixelPattern pixData;
  402.     GetPixelData(pixData);
  403.     
  404.     // Shift it
  405.     unsigned long temp0 = pixData.fDataLongs[0][0];
  406.     unsigned long temp1 = pixData.fDataLongs[0][1];
  407.     
  408.     for (short i = 0; i < 7; i++)
  409.     {
  410.         pixData.fDataLongs[i][0] = pixData.fDataLongs[i + 1][0];
  411.         pixData.fDataLongs[i][1] = pixData.fDataLongs[i + 1][1];
  412.     }
  413.         
  414.     pixData.fDataLongs[7][0] = temp0;
  415.     pixData.fDataLongs[7][1] = temp1;
  416.  
  417.     // Update the pattern
  418.     SetPixelData(pixData);
  419. }
  420.  
  421. //----------------------------------------------------------------------------------------
  422. //    FW_CColorPatternRep::ShiftDown
  423. //----------------------------------------------------------------------------------------
  424.  
  425. void FW_CColorPatternRep::ShiftDown()
  426. {
  427.     // Get current pattern info
  428.     FW_PixelPattern pixData;
  429.     GetPixelData(pixData);
  430.     
  431.     // Shift it
  432.     unsigned long temp0 = pixData.fDataLongs[7][0];
  433.     unsigned long temp1 = pixData.fDataLongs[7][1];
  434.     
  435.     for (short i = 7; i > 0; i--)
  436.     {
  437.         pixData.fDataLongs[i][0] = pixData.fDataLongs[i - 1][0];
  438.         pixData.fDataLongs[i][1] = pixData.fDataLongs[i - 1][1];
  439.     }
  440.  
  441.     pixData.fDataLongs[0][0] = temp0;
  442.     pixData.fDataLongs[0][1] = temp1;
  443.  
  444.     // Update the pattern
  445.     SetPixelData(pixData);
  446. }
  447.  
  448. //----------------------------------------------------------------------------------------
  449. //    FW_CColorPatternRep::Read
  450. //----------------------------------------------------------------------------------------
  451.  
  452. void* FW_CColorPatternRep::Read(FW_CReadableStream& archive)
  453. {
  454.     return new FW_CColorPatternRep(archive);
  455. }
  456.  
  457. #ifdef FW_BUILD_MAC
  458. //----------------------------------------------------------------------------------------
  459. //    FW_CColorPatternRep::MacSetInCurPort
  460. //----------------------------------------------------------------------------------------
  461.  
  462. void FW_CColorPatternRep::MacSetInCurPort() const
  463. {
  464.     FW_ASSERT(fPlatformColorPattern != NULL);
  465.  
  466.     FW_PlatformColorPattern platformColorPattern = ::NewPixPat();
  467.     ::CopyPixPat(fPlatformColorPattern, platformColorPattern);
  468.     ::PenPixPat(platformColorPattern);
  469. }
  470. #endif
  471.  
  472. #ifdef FW_BUILD_WIN
  473. //----------------------------------------------------------------------------------------
  474. //    FW_CColorPatternRep::WinCreatePatternBrush
  475. //----------------------------------------------------------------------------------------
  476.  
  477. HBRUSH FW_CColorPatternRep::WinCreatePatternBrush() const
  478. {
  479.     HBRUSH hBrush = NULL;
  480.  
  481.     // Convert into a DDB for effeciency
  482.     if (fWinCachedBitmap == NULL)
  483.         ((FW_CColorPatternRep*) this)->fWinCachedBitmap = FW_CPrivWinDIB::ConvertToBitmap(fPlatformColorPattern);
  484.  
  485.     // Create the brush
  486.     if(fWinCachedBitmap != NULL)
  487.         hBrush = ::CreatePatternBrush(fWinCachedBitmap);
  488.  
  489.     return hBrush;
  490. }
  491. #endif
  492.  
  493. #ifdef FW_BUILD_WIN
  494. //----------------------------------------------------------------------------------------
  495. //    FW_CColorPatternRep::WinForgetCachedBitmap
  496. //----------------------------------------------------------------------------------------
  497.  
  498. void FW_CColorPatternRep::WinForgetCachedBitmap()
  499. {
  500.     if (fWinCachedBitmap != NULL)
  501.     {
  502.         ::DeleteObject(fWinCachedBitmap);
  503.         fWinCachedBitmap = NULL;
  504.     }
  505. }
  506. #endif
  507.  
  508. #ifdef FW_BUILD_MAC
  509. //----------------------------------------------------------------------------------------
  510. //    FW_CColorPatternRep::MacNewPixPat
  511. //----------------------------------------------------------------------------------------
  512.  
  513. PixPatHandle FW_CColorPatternRep::MacNewPixPat(const void* pixels, 
  514.                                                 short rowBytes, short pixelSize,
  515.                                                 short withPower, short heightPower,
  516.                                                 short nbColors, const FW_CColor* colorTable)
  517. {
  518.     FW_ASSERT(pixels != NULL);
  519.     FW_ASSERT(colorTable != NULL);
  520.     FW_ASSERT((rowBytes & 0x0001) == 0);
  521.     FW_ASSERT(pixelSize == 1 || pixelSize == 2 || pixelSize == 4 || pixelSize == 8);
  522.     FW_ASSERT(withPower != 0);
  523.     FW_ASSERT(heightPower != 0);
  524.     FW_ASSERT(nbColors <= (1 << pixelSize));
  525.  
  526.     PixPatHandle pixPat = ::NewPixPat();
  527.     
  528.     (*pixPat)->patType = 1;
  529.         
  530.     // ----- Creates the pixMap -----
  531.     PixMapHandle pixMap = (*pixPat)->patMap;
  532.     
  533.     (*pixMap)->rowBytes = rowBytes | 0x8000;
  534.     (*pixMap)->bounds.left = 0;
  535.     (*pixMap)->bounds.top = 0;
  536.     (*pixMap)->bounds.right = 1 << withPower;
  537.     (*pixMap)->bounds.bottom = 1 << heightPower;
  538.     (*pixMap)->pixelSize = pixelSize;
  539.     (*pixMap)->cmpCount = 1;
  540.     (*pixMap)->cmpSize = pixelSize;
  541.     
  542.     // ----- Set up the color table -----
  543.     CTabHandle hColors = (*pixMap)->pmTable;    
  544.     Size colorTabSize = sizeof(ColorTable) + (nbColors * sizeof(ColorSpec));    
  545.     ::SetHandleSize((Handle)hColors, colorTabSize);
  546.     
  547.     ::HLock((Handle)hColors);
  548.     CTabPtr pColors = *hColors;
  549.     pColors->ctSeed = ::GetCTSeed();
  550.     pColors->ctFlags = 0;
  551.     pColors->ctSize = nbColors - 1;
  552.     
  553.     for (short i = 0; i<nbColors; i++)
  554.     {
  555.         pColors->ctTable[i].value = i;
  556.         pColors->ctTable[i].rgb = colorTable[i];
  557.     }
  558.     ::HUnlock((Handle)hColors);
  559.     
  560.     // ----- Creates the pattern data -----
  561.     Size dataSize = (Size)rowBytes * 8;
  562.     Handle patData = (*pixPat)->patData;
  563.     ::SetHandleSize(patData, dataSize);
  564.         
  565.     ::HLock(patData);
  566.     ::BlockMove(pixels, *patData, dataSize);
  567.     ::HUnlock(patData);
  568.     
  569.     return pixPat;
  570. }
  571. #endif
  572.  
  573. #ifdef FW_BUILD_WIN
  574.  
  575. //----------------------------------------------------------------------------------------
  576. //    FW_CColorPatternRep::WinFlipPixelCopy
  577. //----------------------------------------------------------------------------------------
  578.  
  579. void FW_CColorPatternRep::WinFlipPixelCopy(const void* source, void* dest)
  580. {
  581.     unsigned long* sourceL = (unsigned long*) source;
  582.     unsigned long* destL = (unsigned long*) dest;
  583.     
  584.     for(int i = 0; i < 16; i += 2)
  585.     {
  586.         destL[14 - i] = sourceL[i];
  587.         destL[15 - i] = sourceL[i + 1];
  588.     }
  589. }
  590.  
  591. #endif
  592.  
  593.  
  594. //----------------------------------------------------------------------------------------
  595. //    FW_CColorPatternRep::MakePixelPattern
  596. //----------------------------------------------------------------------------------------
  597.  
  598. void FW_CColorPatternRep::MakePixelPattern(const FW_PixelPattern& pixels, short nbColors, const FW_CColor* colorTable)
  599. {
  600. #ifdef FW_BUILD_MAC
  601.     fPlatformColorPattern = FW_CColorPatternRep::MacNewPixPat(&pixels, 8, 8, 3, 3, nbColors, colorTable);
  602. #endif
  603.  
  604. #ifdef FW_BUILD_WIN
  605.     // We need to flip the bits because DIBs are stored bottom-to-top
  606.     FW_PixelPattern pixData;
  607.     WinFlipPixelCopy(pixels.fData, pixData.fData);
  608.  
  609.     // Create a DIB
  610.     fPlatformColorPattern = FW_CPrivWinDIB::CreateDIB(8, 8, 8, nbColors, colorTable, pixData.fData);
  611. #endif
  612. }
  613.  
  614. //----------------------------------------------------------------------------------------
  615. //    FW_CColorPatternRep::GetPixelData
  616. //----------------------------------------------------------------------------------------
  617.  
  618. void FW_CColorPatternRep::GetPixelData(FW_PixelPattern& pixData) const
  619. {
  620. #ifdef FW_BUILD_MAC
  621.     Handle patData = (*fPlatformColorPattern)->patData;
  622.  
  623.     ::HLock(patData);
  624.     BlockMove((FW_PixelPattern*)*patData, pixData.fDataRaw, 64);
  625.     ::HUnlock(patData);
  626. #endif
  627. #ifdef FW_BUILD_WIN
  628.     const BITMAPINFO* bmi = (const BITMAPINFO*) ::GlobalLock(fPlatformColorPattern);
  629.     FW_CPrivWinDIB::PixelBufferPtr pixels = FW_CPrivWinDIB::GetPixelBuffer(bmi);
  630.     WinFlipPixelCopy(pixels, pixData.fData);
  631.     ::GlobalUnlock(fPlatformColorPattern);
  632. #endif
  633. }
  634.  
  635. //----------------------------------------------------------------------------------------
  636. //    FW_CColorPatternRep::SetPixelData
  637. //----------------------------------------------------------------------------------------
  638.  
  639. void FW_CColorPatternRep::SetPixelData(const FW_PixelPattern& pixData)
  640. {
  641. #ifdef FW_BUILD_MAC
  642.     Handle patData = (*fPlatformColorPattern)->patData;
  643.  
  644.     ::HLock(patData);
  645.     ::BlockMove(pixData.fDataRaw, (FW_PixelPattern*)*patData, 64);
  646.     ::HUnlock(patData);
  647.  
  648.     ::PixPatChanged(fPlatformColorPattern);
  649. #endif
  650. #ifdef FW_BUILD_WIN
  651.     const BITMAPINFO* bmi = (const BITMAPINFO*) ::GlobalLock(fPlatformColorPattern);
  652.     FW_CPrivWinDIB::PixelBufferPtr pixels = FW_CPrivWinDIB::GetPixelBuffer(bmi);
  653.     WinFlipPixelCopy(pixData.fData, pixels);
  654.     ::GlobalUnlock(fPlatformColorPattern);
  655.  
  656.     WinForgetCachedBitmap();
  657. #endif
  658. }
  659.  
  660. //----------------------------------------------------------------------------------------
  661. //    FW_CColorPatternRep::GetColorTable
  662. //----------------------------------------------------------------------------------------
  663.  
  664. unsigned short FW_CColorPatternRep::GetColorTable(FW_CColor*& colors) const
  665. {
  666. #ifdef FW_BUILD_MAC
  667.     PixMapHandle pixMap = (*fPlatformColorPattern)->patMap;
  668.  
  669.     CTabHandle hColors = (*pixMap)->pmTable;    
  670.     FW_CAcquireLockedSystemHandle lock((FW_PlatformHandle)hColors);
  671.     CTabPtr pColors = *hColors;
  672.  
  673.     unsigned short nbColors = pColors->ctSize + 1;
  674.     colors = new FW_CColor[nbColors];
  675.     for (unsigned short i = 0; i<nbColors; i++)
  676.         colors[i] = pColors->ctTable[i].rgb;
  677.  
  678.     return nbColors;
  679. #endif
  680. #ifdef FW_BUILD_WIN
  681.     return FW_CPrivWinDIB::GetColorTable(fPlatformColorPattern, colors);
  682. #endif
  683. }
  684.  
  685.