unit uStatus;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  GR32_Image, GR32_Layers, StdCtrls, ComCtrls, Gauges, ExtCtrls;

type
  TFormStatus = class(TForm)
    ImageLogo: TImage32;
    LabelFrontendVersion: TLabel;
    LabelStatusType: TLabel;
    LabelMessage: TLabel;
    ProgressBar: TGauge;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ImageLogoMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
    procedure ImageLogoMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer; Layer: TCustomLayer);
    procedure ImageLogoMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
    procedure FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private declarations }
    OldX,
    OldY,
    OldLeft,
    OldTop: Integer;
    ScreenDC: HDC;
    MoveRect: TRect;
    Moving: Boolean;
  public
    { Public declarations }
  end;

var
  FormStatus: TFormStatus;

implementation

uses uMain, uCommon;

{$R *.DFM}

procedure TFormStatus.FormCreate(Sender: TObject);
begin
  LabelStatusType.Caption:= '';
  LabelMessage.Caption:= '';
end;

procedure TFormStatus.FormActivate(Sender: TObject);
var
  tmpString: String;
begin
  if FormMain.LogoFileName = '' then
     FormMain.LogoFileName:= 'resources\images\logo\logo.jpg';
  if ImageLogo.Bitmap.Empty then
     begin
       tmpString:= FormMain.FullFolderFix(FormMain.LogoFileName);
       ImageLogo.Bitmap.Clear;
       try
         if FileExists(tmpString) then
            ImageLogo.Bitmap.LoadFromFile(tmpString);
       except

       end;
     end;
end;

procedure TFormStatus.FormShow(Sender: TObject);
begin
  if Application.Terminated then
     begin
       PostMessage(Handle, wm_Close, 0, 0);
       Exit;
     end;
  FormStatus.Left:= (Screen.Width shr 1)-(Width shr 1)-1;
  FormStatus.Top:=  (Screen.Height shr 1)-(Height shr 1)-1;
  SetWindowPos(FormStatus.Handle, hWnd_TopMost, 0, 0, 0, 0, SWP_NOMOVE+SWP_NOSIZE);
end;

procedure TFormStatus.ImageLogoMouseDown(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 TFormStatus.ImageLogoMouseMove(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 TFormStatus.ImageLogoMouseUp(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 TFormStatus.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then
     FormMain.CancelCurrentOperation:= True;
end;

procedure TFormStatus.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if CanClose then
     ProgressBar.Progress:= 0;
end;

end.
