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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Generics.Collections, 
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D19}
  FMX.Graphics,
  {$ENDIF}
  FMX.Edit, FMX.ListBox, FMX.Dialogs, FMX.Layouts, FMX.TabControl,
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMXTee.Chart, FMXTee.RadioGroup, FMXTee.Editor.Font, FMXTee.Canvas,
  FMX.Objects, FMXTee.Editor.Stroke, FMXTee.Editor.Brush;

type
  TGeneralEditor = class(TForm)
    PageControl1: TTabControl;
    TabZoom: TTabItem;
    TabScroll: TTabItem;
    Label4: TLabel;
    CBScrollMouse: TComboBox;
    CBInsideBounds: TCheckBox;
    TabCursor: TTabItem;
    TabFont: TTabItem;
    Splitter1: TSplitter;
    LBFonts: TListBox;
    Panel1: TPanel;
    PanelFont: TPanel;
    Panel2: TPanel;
    LTextSize: TLabel;
    Label5: TLabel;
    CBAllFonts: TCheckBox;
    UDTextSize: TSpinBox;
    CBZoomText: TComboBox;
    TabPalette: TTabItem;
    LBPalette: TListBox;
    RGScroll: TRadioGroup;
    LBCursor: TListBox;
    PaintBox1: TPaintBox;
    TabMouse: TTabItem;
    GroupBox1: TGroupBox;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    CBLeftButton: TComboBox;
    ListBoxItem13: TListBoxItem;
    ListBoxItem14: TListBoxItem;
    ListBoxItem15: TListBoxItem;
    CBMidButton: TComboBox;
    ListBoxItem16: TListBoxItem;
    ListBoxItem17: TListBoxItem;
    ListBoxItem18: TListBoxItem;
    CBRightButton: TComboBox;
    ListBoxItem19: TListBoxItem;
    ListBoxItem20: TListBoxItem;
    ListBoxItem21: TListBoxItem;
    GroupBox2: TGroupBox;
    RBWheelNone: TRadioButton;
    RGWheelScroll: TRadioButton;
    RGWheelData: TRadioButton;
    RGWheelChart: TRadioButton;
    CBInvWheel: TCheckBox;
    TabControlZoom: TTabControl;
    TabItem1: TTabItem;
    TabZoomBorder: TTabItem;
    TabZoomPattern: TTabItem;
    CBAllowZoom: TCheckBox;
    CBAnimatedZoom: TCheckBox;
    LSteps: TLabel;
    UDAniZoomSteps: TSpinBox;
    Label1: TLabel;
    UDMinPix: TSpinBox;
    Label2: TLabel;
    CBDir: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    Label3: TLabel;
    CBZoomMouse: TComboBox;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    ListBoxItem6: TListBoxItem;
    CBUpLeft: TCheckBox;
    CBHistory: TCheckBox;
    CBZoomAspect: TCheckBox;
    Layout1: TLayout;
    Label7: TLabel;
    Layout2: TLayout;
    Label11: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBDirChange(Sender: TObject);
    procedure CBZoomMouseChange(Sender: TObject);
    procedure CBScrollMouseChange(Sender: TObject);
    procedure LBFontsKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
    procedure ETextSizeChange(Sender: TObject);
    procedure CBZoomTextChange(Sender: TObject);
    procedure CBAllowZoomChange(Sender: TObject);
    procedure CBAnimatedZoomChange(Sender: TObject);
    procedure UDAniZoomStepsChangeTracking(Sender: TObject);
    procedure UDMinPixChangeTracking(Sender: TObject);
    procedure CBUpLeftChange(Sender: TObject);
    procedure CBHistoryChange(Sender: TObject);
    procedure CBZoomAspectChange(Sender: TObject);
    procedure CBInsideBoundsChange(Sender: TObject);
    procedure CBAllFontsChange(Sender: TObject);
    procedure LBPaletteChange(Sender: TObject);
    procedure RGScrollChange(Sender: TObject);
    procedure UDTextSizeChangeTracking(Sender: TObject);
    procedure LBFontsChange(Sender: TObject);
    procedure LBCursorChange(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject; const Canvas: TCanvas);
    procedure UDTextSizeChange(Sender: TObject);
    procedure TabControlZoomChange(Sender: TObject);
    procedure CBLeftButtonChange(Sender: TObject);
    procedure CBRightButtonChange(Sender: TObject);
    procedure CBMidButtonChange(Sender: TObject);
    procedure RBWheelNoneChange(Sender: TObject);
    procedure CBInvWheelChange(Sender: TObject);
  private
   { Private declarations }
    Chart : TCustomChart;
    IFont : TTeeFont;
    IBackup : TTeeFont;
    IFontEditor : TFontEditor;
    OldChange   : TNotifyEvent;

    Changing : Boolean;

    IZoomBorder : TStrokeEditor;
    IZoomPattern: TBrushEditor;

    procedure FillCursors;
    procedure ChangedFont(Sender: TObject);
    procedure CheckMouseButton(const Combo1,Combo2:TComboBox;
                               const Button1,Button2:TMouseButton);
    procedure FillFonts;
    procedure FillPalette;
    class procedure GetChartObjects(const AChart:TCustomChart;
                              const AList:TCustomListBox; WithFonts:Boolean=False);
    procedure RefreshChart(const AChart:TCustomChart);
    procedure ResetIFont;
    function SelectedFont(Index:Integer):TTeeFont;
    procedure SetCursor;
    procedure SetPalette;
  public
   { Public declarations }
    class function CreateEditor(const AOwner:TComponent; const AChart:TCustomChart):TForm;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Constants, FMXTee.Procs, FMXTee.Engine;

procedure TGeneralEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActiveTab:=TabMouse;
end;

procedure TGeneralEditor.FillCursors;

  procedure AddItem(const AText:String; ACursor:Integer);
  var item : TListBoxItem;
  begin
    item:=TListBoxItem.Create(Self);
    item.Text:=AText;
    item.Tag:=ACursor;
    LBCursor.AddObject(item);

    if Chart.Cursor=ACursor then
       item.IsSelected:=True;
  end;

begin
  LBCursor.BeginUpdate;
  LBCursor.Clear;

  AddItem('Default     ',0);
  AddItem('None        ',-1);
  AddItem('Arrow       ',-2);
  AddItem('Cross       ',-3);
  AddItem('IBeam       ',-4);
  AddItem('Size        ',-22);
  AddItem('SizeNESW    ',-6);
  AddItem('SizeNS      ',-7);
  AddItem('SizeNWSE    ',-8);
  AddItem('SizeWE      ',-9);
  AddItem('UpArrow     ',-10);
  AddItem('HourGlass   ',-11);
  AddItem('Drag        ',-12);
  AddItem('NoDrop      ',-13);
  AddItem('HSplit      ',-14);
  AddItem('VSplit      ',-15);
  AddItem('MultiDrag   ',-16);
  AddItem('SQLWait     ',-17);
  AddItem('No          ',-18);
  AddItem('AppStart    ',-19);
  AddItem('Help        ',-20);
  AddItem('HandPoint   ',-21);
  AddItem('SizeAll     ',-22);

  LBCursor.Sorted:=True;
  LBCursor.EndUpdate;
end;

procedure TGeneralEditor.FormDestroy(Sender: TObject);
begin
  ResetIFont;
end;

function FontOfPersistent(const Instance:TPersistent; const FilterOut:TPersistent=nil):TTeeFont;
begin
  result:=nil;
end;

class procedure TGeneralEditor.GetChartObjects(const AChart:TCustomChart;
                     const AList:TCustomListBox; WithFonts:Boolean=False);

  procedure AddItem(const AText:String; const AObject:TObject);
  var item : TListBoxItem;
  begin
    item:=TListBoxItem.Create(AList.Owner);
    item.Text:=AText;
    item.Data:=AObject;
    item.Parent:=AList;
  end;

  procedure AddAxis(const Description:String; const Axis:TChartAxis);
  begin
    AddItem(Description,Axis);
    AddItem(Description+' ('+TeeMsg_AxisTitle+')',Axis.Title);
  end;

var t : Integer;
begin
  with AList do
  begin
    AddItem(teeMsg_Legend,AChart.Legend);
    AddItem(teeMsg_LegendTitle,AChart.Legend.Title);
    AddItem(teeMsg_Title,AChart.Title);
    AddItem(teeMsg_Foot,AChart.Foot);
    AddItem(teeMsg_SubTitle,AChart.SubTitle);
    AddItem(teeMsg_SubFoot,AChart.SubFoot);

    for t:=0 to AChart.SeriesCount-1 do
    begin
      if (not WithFonts) or
         Assigned(FontOfPersistent(AChart[t],AChart[t].Marks.Font)) then
            AddItem(SeriesTitleOrName(AChart[t]),AChart[t]);

      AddItem(SeriesTitleOrName(AChart[t])+' ('+TeeTranslateString(TeeMsg_Marks)+')',
                AChart[t].Marks);
    end;

    for t:=0 to AChart.Tools.Count-1 do
      if (not WithFonts) or Assigned(FontOfPersistent(AChart.Tools[t])) then
         AddItem(AChart.Tools[t].Name,AChart.Tools[t]);
  end;

  // Do not translate string constants

  AddAxis(teeMsg_LeftAxis,AChart.Axes.Left);
  AddAxis(teeMsg_RightAxis,AChart.Axes.Right);
  AddAxis(teeMsg_TopAxis,AChart.Axes.Top);
  AddAxis(teeMsg_BottomAxis,AChart.Axes.Bottom);
  AddAxis(teeMsg_DepthTopAxis,AChart.Axes.DepthTop);
  AddAxis(teeMsg_DepthAxis,AChart.Axes.Depth);

  for t:=0 to AChart.CustomAxes.Count-1 do
      AddAxis(TeeTranslateString('Custom axis')+' '+IntToStr(t),AChart.CustomAxes[t]);
end;

procedure TGeneralEditor.FillFonts;
begin
  LBFonts.Clear;
  GetChartObjects(Chart,LBFonts,True);

//  LBFonts.ItemIndex:=IndexOfObject(Chart.Title);
end;

procedure TGeneralEditor.FillPalette;

  procedure AddPalette(const AText:String; ATag:Integer);
  var tmp : TListBoxItem;
  begin
    tmp:=TListBoxItem.Create(Self);
    tmp.Text:=AText;
    tmp.Tag:=ATag;

    LBPalette.AddObject(tmp);
  end;

var t : Integer;
begin
  LBPalette.BeginUpdate;
  LBPalette.Clear;

  AddPalette(TeeMsg_Default,-1);

  for t:=0 to ColorPalettes.Count-1 do
      AddPalette(ColorPalettes[t],t);

  LBPalette.Sorted:=True;
  LBPalette.EndUpdate;

  SetPalette;
end;

procedure TGeneralEditor.SetPalette;
var t : Integer;
    tmp : Integer;
begin
  if LBPalette.Count>0 then
  begin
    if Chart.ColorPaletteIndex=0 then
       tmp:=-1
     else
       tmp:=Chart.ColorPaletteIndex;

     for t := 0 to LBPalette.Count-1 do
         if LBPalette.ItemByIndex(t).Tag=tmp then
         begin
           LBPalette.ItemIndex:=t;
           break;
         end;
  end;
end;

procedure TGeneralEditor.SetCursor;

  function IndexOfCursor(const ACursor:TCursor):Integer;
  var t : Integer;
  begin
    for t := 0 to LBCursor.Count-1 do
      if LBCursor.ListItems[t].Tag=ACursor then
         Exit(t);

    result:=-1;
  end;

begin
  if LBCursor.Count>0 then
     LBCursor.ItemIndex:=IndexOfCursor(Chart.Cursor);
end;

procedure TGeneralEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActiveTab=TabFont) and (LBFonts.Count=0) then
     FillFonts
  else
  if (PageControl1.ActiveTab=TabPalette) and (LBPalette.Count=0) then
     FillPalette
  else
  if (PageControl1.ActiveTab=TabCursor) and (LBCursor.Count=0) then
     FillCursors;
end;

procedure TGeneralEditor.PaintBox1Paint(Sender: TObject; const Canvas: TCanvas);
var R : TRect;
    t,
    tmpL : Integer;
    tmpP : TColorArray;
    tmpW : Single;
begin
  tmpP:=Chart.ColorPalette;
  if not Assigned(tmpP) then
     tmpP:=TeeColorPalette;

  tmpL:=Length(tmpP);

  R.Left:=PaintBox1.Width*0.25;
  R.Right:=R.Left+(PaintBox1.Width*0.5);

  tmpW:=((PaintBox1.Height-8)/(tmpL));

  for t:=0 to tmpL-1 do
  begin
    R.Top:=4+Round(t*tmpW);
    R.Bottom:=4+Round((t+1)*tmpW);

    PaintBox1.Canvas.Fill.Color:=tmpP[t];
    PaintBox1.Canvas.FillRect(R, 0,0, AllCorners, 1);
  end;
end;

procedure TGeneralEditor.CBAllowZoomChange(Sender: TObject);
begin
  Chart.Zoom.Allow:=CBAllowZoom.IsChecked;
end;

procedure TGeneralEditor.CBAnimatedZoomChange(Sender: TObject);
begin
  Chart.Zoom.Animated:=CBAnimatedZoom.IsChecked;
end;

function TGeneralEditor.SelectedFont(Index: Integer): TTeeFont;
var tmp : TObject;
begin
  tmp:=LBFonts.Selected.Data;

  if tmp is TTeeCustomShape then
     result:=TTeeCustomShape(tmp).Font
  else
  if tmp is TChartAxis then
     result:=TChartAxis(tmp).LabelsFont
  else
  if tmp is TChartSeries then
     result:=FontOfPersistent(tmp as TPersistent,TChartSeries(tmp).Marks.Font)
  else
     result:=FontOfPersistent(tmp as TPersistent);
end;

procedure TGeneralEditor.TabControlZoomChange(Sender: TObject);
begin
  if (TabControlZoom.ActiveTab=TabZoomBorder) and (not Assigned(IZoomBorder)) then
     IZoomBorder:=TStrokeEditor.InsertForm(Chart.Zoom.Pen,TabZoomBorder)
  else
  if (TabControlZoom.ActiveTab=TabZoomPattern) and (not Assigned(IZoomPattern)) then
     IZoomPattern:=TBrushEditor.InsertForm(Chart.Zoom.Brush,TabZoomPattern);
end;

procedure TGeneralEditor.UDAniZoomStepsChangeTracking(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.Zoom.AnimatedSteps:=Round(UDAniZoomSteps.Value);
end;

procedure TGeneralEditor.UDMinPixChangeTracking(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.Zoom.MinimumPixels:=Round(UDMinPix.Value);
end;

procedure TGeneralEditor.UDTextSizeChange(Sender: TObject);
begin
  UDTextSizeChangeTracking(Sender);
end;

procedure TGeneralEditor.UDTextSizeChangeTracking(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.View3DOptions.FontZoom:=Round(UDTextSize.Value);
end;

procedure TGeneralEditor.RBWheelNoneChange(Sender: TObject);
var tmp : TMouseWheelStyle;
begin
  if Changing then
     Exit;

  Changing:=True;

  RBWheelNone.IsChecked:=Sender=RBWheelNone;
  RGWheelScroll.IsChecked:=Sender=RGWheelScroll;
  RGWheelData.IsChecked:=Sender=RGWheelData;
  RGWheelChart.IsChecked:=Sender=RGWheelChart;

  Chart.Panning.MouseWheel:=pmwNone;
  Chart.Zoom.MouseWheel:=pmwNone;
  Chart.ZoomWheel:=pmwNone;

  if CBInvWheel.IsChecked then
     tmp:=pmwInverted
  else
     tmp:=pmwNormal;

  if RGWheelScroll.IsChecked then
     Chart.Panning.MouseWheel:=tmp
  else
  if RGWheelData.IsChecked then
     Chart.Zoom.MouseWheel:=tmp
  else
  if RGWheelChart.IsChecked then
     Chart.ZoomWheel:=tmp;

  Changing:=False;
end;

procedure TGeneralEditor.RefreshChart(const AChart:TCustomChart);

  procedure CheckButtons(const AMouseButton:TMouseButton; AIndex:Integer);
  begin
    if AMouseButton=TMouseButton.mbLeft then
       CBLeftButton.ItemIndex:=AIndex
    else
    if AMouseButton=TMouseButton.mbMiddle then
       CBMidButton.ItemIndex:=AIndex
    else
    if AMouseButton=TMouseButton.mbRight then
       CBRightButton.ItemIndex:=AIndex;
  end;

begin
  Chart:=AChart;

  Changing:=True;

  CBAllowZoom.IsChecked:=Chart.Zoom.Allow;
  CBAnimatedZoom.IsChecked:=Chart.Zoom.Animated;
  UDAniZoomSteps.Value:=Chart.Zoom.AnimatedSteps;
  UDMinPix.Value:=Chart.Zoom.MinimumPixels;
  CBDir.ItemIndex:=Ord(Chart.Zoom.Direction);
  CBZoomMouse.ItemIndex:=Ord(Chart.Zoom.MouseButton);
  CBUpLeft.IsChecked:=Chart.Zoom.UpLeftZooms;
  CBHistory.IsChecked:=Chart.Zoom.History;
  CBZoomAspect.IsChecked:=Chart.Zoom.KeepAspectRatio;
  CBZoomText.ItemIndex:=Ord(Chart.View3DOptions.ZoomText);

  UDTextSize.Value:=Chart.View3DOptions.FontZoom;

  RGScroll.ItemIndex:=Ord(Chart.AllowPanning);
  CBScrollMouse.ItemIndex:=Ord(Chart.ScrollMouseButton);
  CBInsideBounds.IsChecked:=Chart.Panning.InsideBounds;

  if Chart.Panning.MouseWheel<>pmwNone then
  begin
    RGWheelScroll.IsChecked:=True;
    CBInvWheel.IsChecked:=Chart.Panning.MouseWheel=pmwInverted;
  end
  else
  if Chart.Zoom.MouseWheel<>pmwNone then
  begin
    RGWheelData.IsChecked:=True;
    CBInvWheel.IsChecked:=Chart.Zoom.MouseWheel=pmwInverted;
  end
  else
  if Chart.ZoomWheel<>pmwNone then
  begin
    RGWheelChart.IsChecked:=True;
    CBInvWheel.IsChecked:=Chart.ZoomWheel=pmwInverted;
  end
  else
    RBWheelNone.IsChecked:=True;

  CBInvWheel.Enabled:=not RBWheelNone.IsChecked;

  CBLeftButton.ItemIndex:=2;
  CBMidButton.ItemIndex:=2;
  CBRightButton.ItemIndex:=2;

  if Chart.Zoom.Allow then
     CheckButtons(Chart.Zoom.MouseButton,0);

  if CBScrollMouse.Enabled then
     CheckButtons(Chart.ScrollMouseButton,1);

  SetPalette;
  SetCursor;

  Changing:=False;
end;

class function TGeneralEditor.CreateEditor(const AOwner: TComponent; const AChart: TCustomChart):TForm;
begin
  result:=TGeneralEditor.Create(AOwner);
  TGeneralEditor(result).RefreshChart(AChart);
end;

procedure TGeneralEditor.CBDirChange(Sender: TObject);
begin
  Chart.Zoom.Direction:=TTeeZoomDirection(CBDir.ItemIndex);
end;

procedure TGeneralEditor.CBZoomMouseChange(Sender: TObject);
begin
  Chart.Zoom.MouseButton:=TMouseButton(CBZoomMouse.ItemIndex);
end;

procedure TGeneralEditor.CBUpLeftChange(Sender: TObject);
begin
  Chart.Zoom.UpLeftZooms:=CBUpLeft.IsChecked;
end;

procedure TGeneralEditor.CBInvWheelChange(Sender: TObject);
var tmp : TMouseWheelStyle;
begin
  //if Changing then
  //   Exit;

  if CBInvWheel.IsChecked then
     tmp:=pmwInverted
  else
     tmp:=pmwNormal;

  if RGWheelScroll.IsChecked then
     Chart.Panning.MouseWheel:=tmp
  else
  if RGWheelData.IsChecked then
     Chart.Zoom.MouseWheel:=tmp
  else
  if RGWheelChart.IsChecked then
     Chart.ZoomWheel:=tmp;
end;

procedure TGeneralEditor.CBHistoryChange(Sender: TObject);
begin
  Chart.Zoom.History:=CBHistory.IsChecked;
end;

procedure TGeneralEditor.CBZoomAspectChange(Sender: TObject);
begin
  Chart.Zoom.KeepAspectRatio:=CBZoomAspect.IsChecked;
end;

procedure TGeneralEditor.RGScrollChange(Sender: TObject);
begin
  Chart.AllowPanning:=TPanningMode(RGScroll.ItemIndex);
end;

procedure TGeneralEditor.CBScrollMouseChange(Sender: TObject);
begin
  Chart.ScrollMouseButton:=TMouseButton(CBScrollMouse.ItemIndex);
end;

procedure TGeneralEditor.CBInsideBoundsChange(Sender: TObject);
begin
  Chart.Panning.InsideBounds:=CBInsideBounds.IsChecked;
end;

procedure TGeneralEditor.CBLeftButtonChange(Sender: TObject);
begin
  CheckMouseButton(CBLeftButton,CBRightButton,TMouseButton.mbLeft,TMouseButton.mbRight);
end;

procedure TGeneralEditor.CBMidButtonChange(Sender: TObject);
begin
  CheckMouseButton(CBMidButton,CBRightButton,TMouseButton.mbMiddle,TMouseButton.mbRight);
end;

procedure TGeneralEditor.CBRightButtonChange(Sender: TObject);
begin
  CheckMouseButton(CBRightButton,CBLeftButton,TMouseButton.mbRight,TMouseButton.mbLeft);
end;

procedure TGeneralEditor.ResetIFont;
begin
  if Assigned(IFont) then
  begin
    IFont.OnChanged:=OldChange;
    IFont:=nil;
  end;

  FreeAndNil(IBackup);
end;

procedure TGeneralEditor.LBCursorChange(Sender: TObject);
begin
  if LBCursor.Selected<>nil then
  begin
    Chart.Cursor:=TCursor(LBCursor.Selected.Tag);
    Chart.OriginalCursor:=Chart.Cursor;
  end;
end;

procedure TGeneralEditor.LBFontsChange(Sender: TObject);
begin
  ResetIFont;

  if LBFonts.ItemIndex<>-1 then
  begin
    IFont:=SelectedFont(LBFonts.ItemIndex);
    IBackup:=TTeeFont.Create(nil);
    IBackup.Assign(IFont);

    if Assigned(IFontEditor) then
       IFontEditor.RefreshFont(IFont)
    else
       IFontEditor:=TFontEditor.Embedd(nil,IFont,PanelFont);

    OldChange:=IFont.OnChanged;
    IFont.OnChanged:=ChangedFont;
  end;
end;

procedure TGeneralEditor.LBFontsKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
// TODO
end;

procedure TGeneralEditor.LBPaletteChange(Sender: TObject);
begin
  if not (csDestroying in ComponentState) then
  begin
    if LBPalette.ItemIndex<>-1 then
    begin
      Chart.ColorPaletteIndex:=LBPalette.Selected.Tag;
      PaintBox1.Repaint;
    end;
  end;
end;

procedure TGeneralEditor.CBAllFontsChange(Sender: TObject);
begin
  if CBAllFonts.IsChecked then
     LBFonts.SelectAll
  else
  begin
    LBFonts.ClearSelection;
    LBFonts.ItemIndex:=0;
  end;
end;

procedure TGeneralEditor.ETextSizeChange(Sender: TObject);
begin
// TODO
end;

procedure TGeneralEditor.CBZoomTextChange(Sender: TObject);
begin
  Chart.View3DOptions.ZoomText:=TCanvasZoomText(CBZoomText.ItemIndex);
end;

procedure TGeneralEditor.ChangedFont(Sender: TObject);
var t   : Integer;
    tmp : TTeeFont;
begin
  if Assigned(IFont) then
  begin
    for t:=0 to LBFonts.Count-1 do
    if LBFonts.ListItems[t].IsSelected then
    begin
      tmp:=SelectedFont(t);

      if tmp<>IFont then
      begin
        if IFont.Name<>IBackup.Name then
           tmp.Name:=IFont.Name;

        if IFont.Size<>IBackup.Size then
           tmp.Size:=IFont.Size;

        if IFont.Style<>IBackup.Style then
           tmp.Style:=IFont.Style;

        if IFont.Color<>IBackup.Color then
           tmp.Color:=IFont.Color;

        if IFont.InterCharSize<>IBackup.InterCharSize then
           tmp.InterCharSize:=IFont.InterCharSize;

        if IFont.Shadow.HorizSize<>IBackup.Shadow.HorizSize then
           tmp.Shadow.HorizSize:=IFont.Shadow.HorizSize;

        if IFont.Shadow.VertSize<>IBackup.Shadow.VertSize then
           tmp.Shadow.VertSize:=IFont.Shadow.VertSize;

        if IFont.Shadow.Color<>IBackup.Shadow.Color then
           tmp.Shadow.Color:=IFont.Shadow.Color;

        if IFont.Shadow.Visible<>IBackup.Shadow.Visible then
           tmp.Shadow.Visible:=IFont.Shadow.Visible;

        if IFont.Shadow.Transparency<>IBackup.Shadow.Transparency then
           tmp.Shadow.Transparency:=IFont.Shadow.Transparency;

        if IFont.Shadow.Smooth<>IBackup.Shadow.Smooth then
           tmp.Shadow.Smooth:=IFont.Shadow.Smooth;

        if IFont.Gradient.Visible<>IBackup.Gradient.Visible then
           tmp.Gradient.Visible:=IFont.Gradient.Visible;

        //tmp.Assign(IFont); // everything?
      end;
    end;

    IBackup.Assign(IFont);

    if Assigned(OldChange) then
       OldChange(IFont);
  end;
end;

procedure TGeneralEditor.CheckMouseButton(const Combo1,Combo2:TComboBox;
                                          const Button1,Button2:TMouseButton);
begin
  if Changing then
     Exit;

  if Combo1.ItemIndex=0 then
  begin
    Chart.Zoom.Allow:=True;
    Chart.Zoom.MouseButton:=Button1;

    if Chart.ScrollMouseButton=Button1 then
    begin
      Chart.ScrollMouseButton:=Button2;

      if Chart.AllowPanning<>pmNone then
         Combo2.ItemIndex:=1;
    end;
  end
  else
  if Combo1.ItemIndex=1 then
  begin
    if Chart.AllowPanning=pmNone then
       Chart.AllowPanning:=pmBoth;

    Chart.ScrollMouseButton:=Button1;

    if Chart.Zoom.MouseButton=Button1 then
    begin
      Chart.Zoom.MouseButton:=Button2;

      if Chart.Zoom.Allow then
         Combo2.ItemIndex:=0;
    end;
  end
  else
  begin
    if Chart.Zoom.Allow and (Chart.Zoom.MouseButton=Button1) then
       Chart.Zoom.Allow:=False;

    if Chart.ScrollMouseButton=Button1 then
       if Chart.AllowPanning<>pmNone then
          Chart.AllowPanning:=pmNone;
  end;
end;

end.
