{**********************************************}
{   TWorldSeries GIS / Mapping Charts          }
{   Copyright (c) 2007-2020 by Steema Software }
{**********************************************}
unit TeeWorldSeriesEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows,
  {$ENDIF}

  Classes, Controls, Graphics, StdCtrls, ExtCtrls, Buttons, Grids, ComCtrls,

  TeCanvas, TeeProcs, TeEngine, Chart, Series, TeeMapSeries,
  TeeMapSeriesEdit, TeeLisB, TeeNavigator, TeeChartGrid, TeeEdiGrad, TeePenDlg,
  TeeWorldSeries,

  {$IFDEF MSWINDOWS}
  TeeGDIPlus,
  {$ENDIF}

  TeeDragPoint, TeeTools;

type
  TWorldSeriesEditor=class(TMapSeriesEditor)
    CBKeepAspect: TCheckBox;
    TabSheet2: TTabSheet;
    CBFlags: TCheckBox;
    CBStates: TCheckBox;
    CBCities: TCheckBox;
    PanelLeftHeader: TPanel;
    LMap: TLabel;
    LWorldMap: TListBox;
    Label10: TLabel;
    CBCitiesSize: TComboFlat;
    ECitySize: TEdit;
    UDCitySize: TUpDown;
    procedure FormShow(Sender: TObject);
    procedure CBKeepAspectClick(Sender: TObject);
    procedure CBFlagsClick(Sender: TObject);
    procedure CBStatesClick(Sender: TObject);
    procedure CBCitiesClick(Sender: TObject);
    procedure LWorldMapClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBCitiesSizeChange(Sender: TObject);
    procedure ECitySizeChange(Sender: TObject);
  private
    PreparedMapList : Boolean;

    procedure Refresh(const AMap:TWorldSeries);
    function World:TWorldSeries; {$IFDEF D9}inline;{$ENDIF}
  public
    class procedure PrepareWorldMapListBox(const AItems:TStrings);
  end;

implementation

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

uses
  SysUtils;

function TWorldSeriesEditor.World:TWorldSeries;
begin
  result:=TWorldSeries(Map);
end;

type
  TWorldLayersAccess=class(TWorldLayers);

procedure TWorldSeriesEditor.Refresh(const AMap:TWorldSeries);
var tmpCities : Boolean;
begin
  LWorldMap.ItemIndex:=LWorldMap.Items.IndexOfObject(TObject(AMap));
  CBKeepAspect.Checked:=AMap.KeepAspect;
  CBFlags.Checked:=AMap.Flags.Visible;
  CBStates.Checked:=AMap.Layers.States;

  tmpCities:=TWorldLayersAccess(AMap.Layers).HasCities;

  CBCities.Checked:=tmpCities and AMap.Layers.Cities.Visible;
  CBCitiesSize.Enabled:=CBCities.Checked;

  if tmpCities then
  begin
    CBCitiesSize.ItemIndex:=Ord(AMap.Layers.Cities.Size);
    ECitySize.Enabled:=AMap.Layers.Cities.Size=csCustom;
    UDCitySize.Position:=Round(AMap.Layers.Cities.Series.Pointer.SizeFloat);
  end
  else
  begin
    CBCitiesSize.ItemIndex:=0;
    ECitySize.Enabled:=False;
    UDCitySize.Position:=0;
  end;
end;

procedure TWorldSeriesEditor.FormShow(Sender: TObject);
begin
  inherited;

  if not PreparedMapList then
  begin
    PrepareWorldMapListBox(LWorldMap.Items);
    PreparedMapList:=True;
  end;

  if Assigned(Map) then
     Refresh(TWorldSeries(Map));
end;

procedure TWorldSeriesEditor.CBKeepAspectClick(Sender: TObject);
begin
  World.KeepAspect:=CBKeepAspect.Checked;
end;

procedure TWorldSeriesEditor.CBFlagsClick(Sender: TObject);
begin
  World.Flags.Visible:=CBFlags.Checked;
end;

procedure TWorldSeriesEditor.CBStatesClick(Sender: TObject);
begin
  World.Layers.States:=CBStates.Checked;
end;

procedure TWorldSeriesEditor.CBCitiesClick(Sender: TObject);
begin
  World.Layers.Cities.Visible:=CBCities.Checked;
  CBCitiesSize.Enabled:=CBCities.Checked;
end;

procedure TWorldSeriesEditor.LWorldMapClick(Sender: TObject);
begin
  World.Map:=TWorldMap(LWorldMap.Items.Objects[LWorldMap.ItemIndex]);
  LShapeCount.Caption:=IntToStr(Map.Shapes.Count);
  DirtyList:=True;
end;

procedure TWorldSeriesEditor.FormCreate(Sender: TObject);
begin
  inherited;
  PanelLeft.Visible:=True;
end;

class procedure TWorldSeriesEditor.PrepareWorldMapListBox(const AItems:TStrings);
var t : Integer;
    s : String;
begin
  AItems.BeginUpdate;
  try
    for t:=0 to AItems.Count-1 do
    begin
      s:=AItems[t];

      AItems.Objects[t]:=TObject(StrToInt(Copy(s,1,2)));
      AItems[t]:=Copy(s,4,Length(s));
    end;
  finally
    AItems.EndUpdate;
  end;
end;

procedure TWorldSeriesEditor.CBCitiesSizeChange(Sender: TObject);
begin
  World.Layers.Cities.Size:=TWorldCitiesSize(CBCitiesSize.ItemIndex);
  ECitySize.Enabled:=World.Layers.Cities.Size=csCustom;
end;

procedure TWorldSeriesEditor.ECitySizeChange(Sender: TObject);
begin
  if Showing then
     World.Layers.Cities.Series.Pointer.SizeFloat:=UDCitySize.Position;
end;

initialization
  RegisterClass(TWorldSeriesEditor);
end.
