unit Tools;

interface
{$I ..\units\RX.INC}
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, TabNotBk, ExtCtrls, RxPicClip, RxClipView, RxPlacemnt,
  {$IFDEF RX_D17}System.Types,{$ENDIF}
  RxDualList, RxDataConv, Spin, RXCtrls, RXCalc, Mask, RxToolEdit, ComCtrls;

type
  TToolsForm = class(TForm)
    TabbedNotebook1: TTabbedNotebook;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Button1: TButton;
    GroupBox2: TGroupBox;
    ClipboardViewer1: TClipboardViewer;
    Label8: TLabel;
    Label9: TLabel;
    ComboBox1: TComboBox;
    GroupBox3: TGroupBox;
    GroupBox5: TGroupBox;
    Image1: TImage;
    Image3: TImage;
    Label13: TLabel;
    ComboBox2: TComboBox;
    Label17: TLabel;
    DualListDialog1: TDualListDialog;
    ListBox1: TListBox;
    Label21: TLabel;
    Button2: TButton;
    GroupBox6: TGroupBox;
    GroupBox7: TGroupBox;
    PicClip1: TPicClip;
    Label27: TLabel;
    CheckBox1: TCheckBox;
    Label30: TLabel;
    Label31: TLabel;
    SpinEdit1: TSpinEdit;
    Label32: TLabel;
    Bevel1: TBevel;
    Image4: TImage;
    SecretPanel1: TSecretPanel;
    Button3: TButton;
    Label34: TLabel;
    ComboBox5: TComboBox;
    Image5: TImage;
    Label22: TLabel;
    Image2: TImage;
    Label2: TLabel;
    Label3: TLabel;
    GroupBox4: TGroupBox;
    ComboEdit1: TComboEdit;
    rxCalculator1: TrxCalculator;
    Image6: TImage;
    Label4: TLabel;
    FormStorage1: TFormStorage;
    PicImage: TImage;
    RadioGroup1: TRadioGroup;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure SpinEdit1Change(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ComboBox5Change(Sender: TObject);
    procedure ClipboardViewer1Change(Sender: TObject);
    procedure ComboEdit1ButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SecretPanel1DblClick(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
  private
    { Private declarations }
    procedure PopulateListBox1;
  public
    { Public declarations }
  end;

implementation

{$R *.DFM}

uses Main, Clipbrd, RxClipIcon;

procedure TToolsForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TToolsForm.Button1Click(Sender: TObject);
var
  P: TPoint;
begin
  P := Point(MainForm.Toolbar.Left + 50, MainForm.Toolbar.Top + 6);
  P := MainForm.ClientToScreen(P);
  MainForm.ToolbarMenu.Popup(P.X, P.Y);
end;

procedure TToolsForm.ComboBox1Change(Sender: TObject);
begin
  case ComboBox1.ItemIndex of
    0: Clipboard.AsText := MainForm.Caption;
    1:
      begin
        Clipboard.Assign(Image5.Picture);
      end;
    2: CopyIconToClipboard(Application.Icon, clWindow);
    3: Clipboard.SetComponent(Button1);
  end;
end;

procedure TToolsForm.FormShow(Sender: TObject);
begin
  ComboBox2.ItemIndex := 0;
  PopulateListBox1;
  SpinEdit1Change(Self);
  ComboBox5.ItemIndex := 2;
end;

procedure TToolsForm.ComboBox2Change(Sender: TObject);
var
  V: TClipboardViewFormat;
begin
  if ComboBox2.ItemIndex >= 0 then begin
    V := ClipboardFormatToView(Clipboard.Formats[
      Integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex])]);
    ClipboardViewer1.ViewFormat := V;
  end;
end;

procedure TToolsForm.Button2Click(Sender: TObject);
begin
  DualListDialog1.Execute;
  PopulateListBox1;
end;

procedure TToolsForm.PopulateListBox1;
begin
  ListBox1.Clear;
  ListBox1.Items.AddStrings(DualListDialog1.List2);
end;

procedure TToolsForm.CheckBox1Click(Sender: TObject);
begin
  PicImage.Visible := CheckBox1.Checked;
end;

procedure TToolsForm.SpinEdit1Change(Sender: TObject);
begin
  Image4.Picture.Bitmap := PicClip1.GraphicCell[SpinEdit1.Value];
end;

procedure TToolsForm.Button3Click(Sender: TObject);
begin
  if ComboBox5.ItemIndex > 1 then
    SecretPanel1.Font.Size := 11
  else
    SecretPanel1.Font.Size := 10;
  SecretPanel1.Active := True;
end;

procedure TToolsForm.ComboBox5Change(Sender: TObject);
begin
  SecretPanel1.GlyphLayout := TGlyphLayout(ComboBox5.ItemIndex);
end;

procedure TToolsForm.ClipboardViewer1Change(Sender: TObject);
var
  I: Integer;
  S: string;
begin
  ComboBox2.Items.Clear;
  ComboBox2.Items.AddObject('Auto', TObject(-1));
  for I := 0 to Clipboard.FormatCount do begin
    S := ClipboardViewer1.ClipboardFormatNames[I];
    if S <> '' then ComboBox2.Items.AddObject(S, TObject(I));
  end;
  ComboBox2.ItemIndex := 0;
end;

procedure TToolsForm.ComboEdit1ButtonClick(Sender: TObject);
begin
  try
    rxCalculator1.Value := StrToFloat(ComboEdit1.Text);
  except
    ComboEdit1.Text := '0';
  end;
  if rxCalculator1.Execute then
    ComboEdit1.Text := FloatToStr(rxCalculator1.Value);
end;

procedure TToolsForm.FormCreate(Sender: TObject);
begin
  PicImage.Picture := PicClip1.Picture;
end;

procedure TToolsForm.SecretPanel1DblClick(Sender: TObject);
begin
  if SecretPanel1.Active then SecretPanel1.Active := False;
end;

procedure TToolsForm.RadioGroup1Click(Sender: TObject);
begin
  SecretPanel1.ScrollDirection := TScrollDirection(RadioGroup1.ItemIndex);
end;

initialization
  {- to copy button to clipboard }
  RegisterClasses([TButton]);
end.
