unit uInputBox;

interface

uses
  Windows, Classes, Controls, Forms, StdCtrls, GR32_Image, GR32_Layers,
  Graphics, SysUtils, Buttons;

type
  TFormInputBox = class(TForm)
    NewText: TEdit;
    ImageBackground: TImage32;
    LabelTitle: TLabel;
    ButtonOk: TSpeedButton;
    ButtonCancel: TSpeedButton;
    LabelText: TLabel;
    procedure ButtonOkClick(Sender: TObject);
    procedure NewTextKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ImageBackgroundMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer;
      Layer: TCustomLayer);
    procedure ImageBackgroundMouseMove(Sender: TObject; Shift: TShiftState;
      X, Y: Integer; Layer: TCustomLayer);
    procedure ImageBackgroundMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
    procedure ButtonCancelClick(Sender: TObject);
  private
    OldX,
    OldY,
    OldLeft,
    OldTop,
    ScreenDC           : HDC;
    MoveRect           : TRect;
    Moving             : Boolean;
    { Private declarations }
  public
    MsgResult: Integer;
    { Public declarations }
  end;

var
  FormInputBox: TFormInputBox;

implementation

uses uMain, uPreferences;

{$R *.dfm}

procedure TFormInputBox.ButtonOkClick(Sender: TObject);
begin
  MsgResult:= mrOk;
  Close;
end;

procedure TFormInputBox.NewTextKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
     ButtonOk.Click
  else
  if Key = #27 then
     ButtonCancel.Click;
end;

procedure TFormInputBox.FormCreate(Sender: TObject);
begin
  ImageBackground.SetupBitmap;
  with ImageBackground.Bitmap.Font do
  begin
    Color:= clWhite;
    Name := 'Tahoma';
    Size := 10;
    Style:= [fsBold];
  end;
  case FileExists(FormMain.AppPath+'images\inputbox_background.png') of
    True : ImageBackground.Bitmap.LoadFromFile(FormMain.AppPath+'images\inputbox_background.png');
    False: ImageBackground.Bitmap.RenderText(10, 25, 'File "images\inputbox_background.png" not found', 4, $FFFFFFFF);
  end;
end;

procedure TFormInputBox.FormShow(Sender: TObject);
begin
  //FormMain.UpdateGeneralAppearance(FormInputBox);
  FormMain.LoadButtonIcon(ButtonOk, 6, False);
  FormMain.LoadButtonIcon(ButtonCancel, 7, False);
end;

procedure TFormInputBox.ImageBackgroundMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer;
  Layer: TCustomLayer);
begin
  if Button = mbLeft then
     begin
       ScreenDC:= GetDC(0);
       OldX:= X;
       OldY:= Y;
       OldLeft:= X;
       OldTop:= Y;
       MoveRect:= BoundsRect;
       DrawFocusRect(ScreenDC, MoveRect);
       Moving:= True;
     end;
end;

procedure TFormInputBox.ImageBackgroundMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
begin
  if Moving then
     begin
       DrawFocusRect(ScreenDC,MoveRect);
       OldX:= X;
       OldY:= Y;
       MoveRect:= Rect(Left+OldX-OldLeft,Top+OldY-OldTop,
                       Left+Width+OldX-OldLeft,Top+Height+OldY-OldTop);
       DrawFocusRect(ScreenDC,MoveRect);
     end;
end;

procedure TFormInputBox.ImageBackgroundMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer;
  Layer: TCustomLayer);
begin
  if Button = mbLeft then
     begin
       ReleaseCapture;
       DrawFocusRect(ScreenDC, MoveRect);
       Left:= Left+X-OldLeft;
       Top:= Top+Y-OldTop;
       ReleaseDC(0, ScreenDC);
       Moving:= False;
     end;
end;

procedure TFormInputBox.ButtonCancelClick(Sender: TObject);
begin
  MsgResult:= mrCancel;
  Close;
end;

end.
