{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Tools.ChartImage;
{$I TeeDefs.inc}

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Editor.Tools.Series,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  FMX.ListBox, FMXTee.Tools, FMX.Objects;

type
  TChartImageToolEditor = class(TSeriesToolEditor)
    BBorder: TButton;
    GBImage: TGroupBox;
    BBrowse: TButton;
    BFilters: TButton;
    BSave: TButton;
    Bevel1: TRectangle;
    Image1: TImage;
    procedure FormActivate(Sender: TObject);
    procedure BBorderClick(Sender: TObject);
    procedure BBrowseClick(Sender: TObject);
    procedure BSaveClick(Sender: TObject);
    procedure BFiltersClick(Sender: TObject);
  private
    { Private declarations }
    ChartImage : TChartImageTool;

    Procedure CheckImageButton;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke, FMXTee.Constants, FMXTee.Procs, FMXTee.Editor.Picture;

procedure TChartImageToolEditor.FormActivate(Sender: TObject);
(*var
  ChartImageEditor : TForm;
begin
  inherited;

  if not Assigned(ChartImage) then
  begin
    ChartImage:=TChartImageTool(TagObject);

    if Assigned(ChartImage) then
    With ChartImage do
    begin
      ChartImageEditor:=TBackImageEditor.CreateEmbedd(Self, ChartImage.Picture, Panel2);
    end;
  end; *)
begin
  inherited;

  if not Assigned(ChartImage) then
  begin
    ChartImage:=TChartImageTool(Tool);

    if Assigned(ChartImage) then
      CheckImageButton;
  end;
end;

procedure TChartImageToolEditor.BBorderClick(Sender: TObject);
begin
  if Assigned(ChartImage) then
    TStrokeEditor.Edit(Self,ChartImage.Pen);
end;

procedure TChartImageToolEditor.BBrowseClick(Sender: TObject);
var tmp : String;
begin
  if BBrowse.Tag=1 then
    ChartImage.Picture.SetSize(0,0)
  else
  begin
    tmp:=TBackImageEditor.GetPictureFileName(Self);
    if tmp<>'' then
    begin
      ChartImage.Picture.LoadFromFile(tmp);
      ChartImage.Repaint;
    end;
  end;

  CheckImageButton;
end;

procedure TChartImageToolEditor.BFiltersClick(Sender: TObject);
begin
  // TODO
end;

procedure TChartImageToolEditor.BSaveClick(Sender: TObject);
begin
  //if Assigned(ChartImage.Picture.Graphic) then
  //   TeeSavePictureDialog(Self,Image.Picture.Graphic);
end;

Procedure TChartImageToolEditor.CheckImageButton;
begin
  if not ChartImage.Picture.IsEmpty then
  begin
    BBrowse.Tag:=1;
    BBrowse.Text:=StripHotKey(TeeMsg_ClearImage);
    Image1.Bitmap.Assign(ChartImage.Picture.Graphic);
    BSave.Enabled:=True;
  end
  else
  begin
    BBrowse.Tag:=0;
    BBrowse.Text:=StripHotKey(TeeMsg_BrowseImage);
    Image1.Bitmap.SetSize(0,0);
    BSave.Enabled:=False;
  end;
end;

initialization
  RegisterSeriesEditor(TChartImageToolEditor);
end.
