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

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