{**********************************************}
{   TImageBarSeries Component Editor Dialog    }
{   Copyright (c) 1996-2020 by Steema Software }
{**********************************************}
unit TeeImaEd;
{$I TeeDefs.inc}

interface

uses {$IFNDEF LINUX}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,

     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons,

     Chart, Series, TeeProcs, ImageBar;

type
  TImageBarSeriesEditor = class(TForm)
    GroupBox1: TGroupBox;
    Image1: TImage;
    BBrowse: TButton;
    CBTiled: TCheckBox;
    Bevel1: TBevel;
    Button1: TButton;
    CBTransp: TCheckBox;
    Button2: TButton;
    Timer1: TTimer;
    procedure FormShow(Sender: TObject);
    procedure BBrowseClick(Sender: TObject);
    procedure CBTiledClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CBTranspClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    ImageBarSeries : TImageBarSeries;
    FBarForm : TCustomForm;
    
    procedure EnableImageControls;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

uses
  ExtDlgs,
  TeCanvas, TeePenDlg, TeeBrushDlg, TeeConst, TeeBarEdit, TeeEdiSeri, TeeEdiPane,
  TeeFiltersEditor;

procedure TImageBarSeriesEditor.FormShow(Sender: TObject);
begin
  ImageBarSeries:=TImageBarSeries(Tag);

  if Assigned(ImageBarSeries) then
  begin
    With ImageBarSeries do
    begin
      CBTiled.Checked:=ImageTiled;
      CBTransp.Checked:=ImageTransparent;

      Image1.Picture.Assign(Image);
    end;

    if not Assigned(FBarForm) then
       FBarForm:=TFormTeeSeries.InsertSeriesForm( Parent,TBarSeriesEditor,
                                                  1,TeeMsg_GalleryBar,
                                                  ImageBarSeries);

    with FBarForm as TBarSeriesEditor do
    begin
      LStyle.Visible:=False;
      CBBarStyle.Visible:=False;

      // Workaround VCL bug, use timer to force show the Bar tabs:
      Timer1.Enabled:=True;
    end;

    EnableImageControls;
  end;
end;

procedure TImageBarSeriesEditor.EnableImageControls;
begin
  CBTiled.Enabled:=Assigned(ImageBarSeries.Image.Graphic);

  if CBTiled.Enabled then BBrowse.Caption:=TeeMsg_ClearImage
                     else BBrowse.Caption:=TeeMsg_BrowseImage;

  Image1.Picture.Assign(ImageBarSeries.Image);
end;

procedure TImageBarSeriesEditor.BBrowseClick(Sender: TObject);
begin
  TeeLoadClearImage(Self,ImageBarSeries.Image);
  EnableImageControls;
end;

procedure TImageBarSeriesEditor.CBTiledClick(Sender: TObject);
begin
  ImageBarSeries.ImageTiled:=CBTiled.Checked;
end;

procedure TImageBarSeriesEditor.FormCreate(Sender: TObject);
begin
  BorderStyle:=TeeBorderStyle;
  {$IFDEF D6}
  Image1.HelpContext:=1934;
  {$ENDIF}
end;

procedure TImageBarSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FBarForm);
end;

procedure TImageBarSeriesEditor.Button1Click(Sender: TObject);
begin
  ShowFiltersEditor(Self, ImageBarSeries.Image);
end;

procedure TImageBarSeriesEditor.CBTranspClick(Sender: TObject);
begin
  ImageBarSeries.ImageTransparent:=CBTransp.Checked;
end;

procedure TImageBarSeriesEditor.Button2Click(Sender: TObject);
begin
  if TBrushDialog.ImageGallery(Self,ImageBarSeries.Image) then
     EnableImageControls;
end;

// Workaround VCL bug, use timer to force show the Bar tabs:
procedure TImageBarSeriesEditor.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled:=False;

  if FBarForm.Parent is TTabSheet then
  begin
    TTabSheet(FBarForm.Parent).PageControl.ActivePage:=TTabSheet(FBarForm.Parent);

    if Parent is TTabSheet then
       TTabSheet(FBarForm.Parent).PageControl.ActivePage:=TTabSheet(Parent);
  end;
end;

initialization
  RegisterClass(TImageBarSeriesEditor);
end.
