home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd1.bin / zkuste / delphi / kolekce / d567 / FLEXCEL.ZIP / Demo / XlsViewer / UFormatDialog.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-10-06  |  4.2 KB  |  155 lines

  1. unit UFormatDialog;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils,
  7.   {$IFDEF WIN32}
  8.     Graphics, Controls, Forms, Dialogs,
  9.     StdCtrls, ComCtrls, ImgList, ToolWin, ExtCtrls,
  10.   {$ENDIF}
  11.   {$IFDEF LINUX}
  12.     QGraphics, QControls, QForms, QDialogs,
  13.     QStdCtrls, QComCtrls, QImgList, QTypes, QExtCtrls,
  14.   {$ENDIF}
  15.   Classes, UFlexCelImport, UFlxFormats, UFlxMessages;
  16.  
  17. type
  18.   TFormatDialog = class(TForm)
  19.     ToolBar: TToolBar;
  20.     BtnSave: TToolButton;
  21.     BtnClose: TToolButton;
  22.     Label1: TLabel;
  23.     cbFormat: TListBox;
  24.     Bevel1: TBevel;
  25.     DemoCell: TPanel;
  26.     BorderL: TShape;
  27.     BorderT: TShape;
  28.     BorderB: TShape;
  29.     BorderR: TShape;
  30.     DemoCell2: TPanel;
  31.     ImageList1: TImageList;
  32.     ImageList2: TImageList;
  33.     ImageList3: TImageList;
  34.     procedure BtnSaveClick(Sender: TObject);
  35.     procedure BtnCloseClick(Sender: TObject);
  36.     procedure cbFormatClick(Sender: TObject);
  37.     procedure FormShow(Sender: TObject);
  38.   private
  39.     FFli: TFlexCelImport;
  40.     
  41.     function GetSelectedFormat: integer;
  42.     procedure SetSelectedFormat(const Value: integer);
  43.     procedure DoBorders(const Border: TShape; const BorFmt: TFlxOneBorder);
  44.     { Private declarations }
  45.   public
  46.     property SelectedFormat: integer read GetSelectedFormat write SetSelectedFormat;
  47.     procedure SetData(const Fli: TFlexCelImport);
  48.     procedure Load;
  49.     { Public declarations }
  50.   end;
  51.  
  52. implementation
  53.  
  54. {$IFDEF WIN32}
  55.   {$R *.dfm}
  56. {$ENDIF}
  57. {$IFDEF LINUX}
  58.   {$R *.xfm}
  59. {$ENDIF}
  60.  
  61. { TFormatDialog }
  62.  
  63. function TFormatDialog.GetSelectedFormat: integer;
  64. begin
  65.   Result:= cbFormat.ItemIndex;
  66.   if Result<0 then Result:=0;
  67. end;
  68.  
  69. procedure TFormatDialog.SetSelectedFormat(const Value: integer);
  70. begin
  71.   cbFormat.ItemIndex:=Value;
  72. end;
  73.  
  74. procedure TFormatDialog.BtnSaveClick(Sender: TObject);
  75. begin
  76.   ModalResult:=mrOk
  77. end;
  78.  
  79. procedure TFormatDialog.BtnCloseClick(Sender: TObject);
  80. begin
  81.   ModalResult:=mrCancel;
  82. end;
  83.  
  84. procedure TFormatDialog.SetData(const Fli: TFlexCelImport);
  85. begin
  86.   FFli:=Fli;
  87. end;
  88.  
  89. procedure TFormatDialog.Load;
  90. var
  91.   i: integer;
  92. begin
  93.   cbFormat.Items.BeginUpdate;
  94.   try
  95.     for i:=cbFormat.Items.Count to FFli.FormatListCount-1 do cbFormat.Items.Add(IntToStr(i));
  96.     for i:=cbFormat.Items.Count-1 downto FFli.FormatListCount do cbFormat.Items.Delete(i);
  97.   finally
  98.     cbFormat.Items.EndUpdate;
  99.   end; //finally
  100. end;
  101.  
  102. procedure TFormatDialog.DoBorders(const Border: TShape; const BorFmt: TFlxOneBorder );
  103. begin
  104.   if (BorFmt.ColorIndex>0) and (BorFmt.ColorIndex<=High(TColorPaletteRange)) then
  105.     Border.Pen.Color:=FFli.ColorPalette[BorFmt.ColorIndex]
  106.     else Border.Pen.Color:=clBlack;
  107.  
  108.   case BorFmt.Style of
  109.     fbs_Double: Border.Brush.Color:=DemoCell.Color;
  110.     else Border.Brush.Color:=Border.Pen.Color;
  111.   end; //case
  112.   Border.Visible:=BorFmt.Style<>fbs_None;
  113. end;
  114.  
  115. procedure TFormatDialog.cbFormatClick(Sender: TObject);
  116. var
  117.   F: TFlxFormat;
  118. begin
  119.   //this is a really silly way to show the format, but is funny
  120.   if CbFormat.ItemIndex<0 then exit;
  121.   F:= FFli.FormatList[cbFormat.ItemIndex];
  122.  
  123.   DemoCell.Font.Name:=F.Font.Name;
  124.   if (F.Font.ColorIndex>0) and (F.Font.ColorIndex<=High(TColorPaletteRange)) then
  125.     DemoCell.Font.Color:=FFli.ColorPalette[F.Font.ColorIndex] else
  126.     DemoCell.Font.Color:=clBlack;
  127.   DemoCell.Font.Height:=Round(F.Font.Size20/20);
  128.  
  129.   if (F.FillPattern.FgColorIndex>0) and (F.FillPattern.FgColorIndex<=High(TColorPaletteRange)) then
  130.     DemoCell.Color:=FFli.ColorPalette[F.FillPattern.FgColorIndex]
  131.     else demoCell.Color:=clWhite;
  132.   if F.HAlignment=fha_right then DemoCell.Alignment:=taRightJustify else
  133.   if F.HAlignment=fha_left then DemoCell.Alignment:=taLeftJustify else
  134.   DemoCell.Alignment:=taCenter;
  135.  
  136.   if F.VAlignment=fva_top then DemoCell.Top:=BorderT.Top+BorderT.Height else
  137.   if F.VAlignment=fva_center then DemoCell.Top:=(BorderT.Top+BorderB.Top+BorderB.Height-DemoCell.Height) div 2 else
  138.     DemoCell.Top:=BorderB.Top-DemoCell.Height;
  139.  
  140.   DoBorders( BorderL, F.Borders.Left);
  141.   DoBorders( BorderT, F.Borders.Top);
  142.   DoBorders( BorderR, F.Borders.Right);
  143.   DoBorders( BorderB, F.Borders.Bottom);
  144.  
  145.   DemoCell2.Color:=DemoCell.Color;
  146.  
  147. end;
  148.  
  149. procedure TFormatDialog.FormShow(Sender: TObject);
  150. begin
  151.   cbFormatClick(Self);
  152. end;
  153.  
  154. end.
  155.