{**********************************************}
{  TTeeCombo Tool Editor Dialog                }
{  Copyright (c) 1999-2020 by Steema Software  }
{**********************************************}
unit TeeComboEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFDEF MSWINDOWS}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, TeeTools, ComCtrls, StdCtrls, TeeCustomShapeEditor, TeCanvas,
  ExtCtrls;

type
  TComboToolEditor = class(TForm)
    PageControl1: TPageControl;
    TabItems: TTabSheet;
    TabFormat: TTabSheet;
    Items: TMemo;
    Panel1: TPanel;
    Label1: TLabel;
    ComboSelected: TComboFlat;
    CBAutoHide: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ItemsChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure ComboSelectedChange(Sender: TObject);
    procedure PageControl1GetImageIndex(Sender: TObject; TabIndex: Integer;
      var ImageIndex: Integer);
    procedure CBAutoHideClick(Sender: TObject);
  private
    { Private declarations }

    ICreating : Boolean;

    Combo : TTeeCombo;
    ShapeForm : TFormTeeShape;
  public
    { Public declarations }
  end;

implementation

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

procedure TComboToolEditor.FormShow(Sender: TObject);
begin
  Combo:=TTeeCombo(Tag);

  if Assigned(Combo) then
  begin
    ICreating:=True;
    try
      Items.Lines:=Combo.Items;

      ComboSelected.Items:=Combo.Items;
      ComboSelected.ItemIndex:=Combo.ItemIndex;

      CBAutoHide.Checked:=Combo.AutoHide;
    finally
      ICreating:=False;
    end;
  end;
end;

procedure TComboToolEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActivePage:=TabItems;
end;

procedure TComboToolEditor.ItemsChange(Sender: TObject);
begin
  if not ICreating then
  begin
    Combo.Items.Assign(Items.Lines);

    ComboSelected.Items:=Combo.Items;
    ComboSelected.ItemIndex:=Combo.ItemIndex;
  end;
end;

procedure TComboToolEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabFormat) and (not Assigned(ShapeForm)) then
     ShapeForm:=TFormTeeShape.CreateForm(Self,Combo.Shape,TabFormat);
end;

procedure TComboToolEditor.ComboSelectedChange(Sender: TObject);
begin
  Combo.ItemIndex:=ComboSelected.ItemIndex;
end;

procedure TComboToolEditor.PageControl1GetImageIndex(Sender: TObject;
  TabIndex: Integer; var ImageIndex: Integer);
begin
  // Dummy, to avoid VCL exception
end;

procedure TComboToolEditor.CBAutoHideClick(Sender: TObject);
begin
  Combo.AutoHide:=CBAutoHide.Checked;
end;

initialization
  TeeActivateGroup;
  RegisterClass(TComboToolEditor);
end.
