home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd1.bin / zkuste / delphi / kolekce / d567 / FLEXCEL.ZIP / XLSAdapter / UXlsPalette.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-10-04  |  4.7 KB  |  122 lines

  1. unit UXlsPalette;
  2.  
  3. interface
  4. uses Classes, SysUtils, UXlsBaseRecords, UXlsBaseRecordLists, XlsMessages, UFlxMessages;
  5. type
  6.   TPaletteRecord= class(TBaseRecord)
  7.   private
  8.     function GetColor(index: integer): LongWord;
  9.     procedure SetColor(index: integer; const Value: LongWord);
  10.     function GetCount: word;
  11.   public
  12.     property Count: word read GetCount;
  13.     property Color[index: integer]: LongWord read GetColor write SetColor;
  14.     constructor CreateStandard;
  15.   end;
  16.  
  17.   function StandardPalette(const Index: integer): LongWord;
  18. implementation
  19.  
  20. { TPaletteRecord }
  21.  
  22. constructor TPaletteRecord.CreateStandard;
  23. var
  24.   aData: PArrayOfByte;
  25.   aDataSize:integer;
  26.   i: integer;
  27. begin
  28.   aDataSize:=SizeOf(Word)+High(TColorPaletteRange)*SizeOf(LongWord);
  29.   GetMem(aData, aDataSize);
  30.   try
  31.     SetWord(aData,0,High(TColorPaletteRange));
  32.     for i:=Low(TColorPaletteRange)-1 to High(TColorPaletteRange)-1 do SetCardinal(aData,2+i*SizeOf(LongWord), StandardPalette(i));
  33.   except
  34.     FreeAndNil(aData);
  35.     raise;
  36.   end; //Except
  37.   inherited Create(xlr_PALETTE, aData, aDataSize);
  38. end;
  39.  
  40. function TPaletteRecord.GetColor(Index: integer): LongWord;
  41. begin
  42.   if (Index>=Count) or (Index<0) then raise Exception.CreateFmt(ErrXlsIndexOutBounds,[Index,'Palette Color Index',0, Count-1]);
  43.   Result:=GetCardinal(Data, 2+Index*4);
  44. end;
  45.  
  46. function TPaletteRecord.GetCount: word;
  47. begin
  48.   Result:=GetWord(Data, 0);
  49. end;
  50.  
  51. procedure TPaletteRecord.SetColor(index: integer; const Value: LongWord);
  52. begin
  53.   if (Index>=Count) or (Index<0) then raise Exception.CreateFmt(ErrTooManyEntries,[Index, Count-1]);
  54.   SetCardinal(Data, 2+Index*4, Value);
  55. end;
  56.  
  57. function StandardPalette(const Index: integer): LongWord;
  58. const
  59.   StdArray: array[Low(TColorPaletteRange)-1..High(TColorPaletteRange)-1] of LongWord=
  60.                                      (  0,
  61.                                         16777215,
  62.                                         255,
  63.                                         65280,
  64.                                         16711680,
  65.                                         65535,
  66.                                         16711935,
  67.                                         16776960,
  68.                                         128,
  69.                                         32768,
  70.                                         8388608,
  71.                                         32896,
  72.                                         8388736,
  73.                                         8421376,
  74.                                         12632256,
  75.                                         8421504,
  76.                                         16751001,
  77.                                         6697881,
  78.                                         13434879,
  79.                                         16777164,
  80.                                         6684774,
  81.                                         8421631,
  82.                                         13395456,
  83.                                         16764108,
  84.                                         8388608,
  85.                                         16711935,
  86.                                         65535,
  87.                                         16776960,
  88.                                         8388736,
  89.                                         128,
  90.                                         8421376,
  91.                                         16711680,
  92.                                         16763904,
  93.                                         16777164,
  94.                                         13434828,
  95.                                         10092543,
  96.                                         16764057,
  97.                                         13408767,
  98.                                         16751052,
  99.                                         10079487,
  100.                                         16737843,
  101.                                         13421619,
  102.                                         52377,
  103.                                         52479,
  104.                                         39423,
  105.                                         26367,
  106.                                         10053222,
  107.                                         9868950,
  108.                                         6697728,
  109.                                         6723891,
  110.                                         13056,
  111.                                         13107,
  112.                                         13209,
  113.                                         6697881,
  114.                                         10040115,
  115.                                         3355443);
  116.  
  117. begin
  118.   if (Index<0) or (Index>High(TColorPaletteRange)-1) then Raise Exception.CreateFmt(ErrXlsIndexOutBounds,[Index,'Palette index' ,0,High(TColorPaletteRange)-1]);
  119.   Result:= StdArray[Index];
  120. end;
  121. end.
  122.