unit uMessages;

interface

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

type
  TFormMessages = class(TForm)
    ImageBackground: TImage32;
    LabelMessageTitle: TLabel;
    LabelMessage: TRichEdit;
    ButtonYes: TSpeedButton;
    ButtonNo: TSpeedButton;
    procedure FormCreate(Sender: TObject);
    procedure LabelMessageTitleChanged(Sender: TObject);
    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 ImageBackgroundMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer;
      Layer: TCustomLayer);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure ButtonYesClick(Sender: TObject);
    procedure ButtonNoClick(Sender: TObject);
  private
    OldX,
    OldY,
    OldLeft,
    OldTop,
    ScreenDC           : HDC;
    MoveRect           : TRect;
    Moving             : Boolean;
    
    { Private declarations }
  public
    MsgResult: Integer;
    { Public declarations }
  end;

var
  FormMessages: TFormMessages;

implementation

uses uMain, uPreferences;

{$R *.DFM}

procedure TFormMessages.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\msg_background.png') of
    True : ImageBackground.Bitmap.LoadFromFile(FormMain.AppPath+'images\msg_background.png');
    False: ImageBackground.Bitmap.RenderText(10, 25, 'File "images\msg_background.png" not found', 4, $FFFFFFFF);
  end;
  FormMain.LoadButtonIcon(ButtonYes, 6, False);
  FormMain.LoadButtonIcon(ButtonNo, 7, False);
end;

procedure TFormMessages.LabelMessageTitleChanged(Sender: TObject);
begin
  LabelMessageTitle.Width:= 370;
end;

procedure TFormMessages.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 TFormMessages.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 TFormMessages.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 TFormMessages.FormKeyPress(Sender: TObject; var Key: Char);

  {function ClickButtonYes: Boolean;
  begin
    case ButtonYes.Visible of
      True : ButtonYes.OnClick(Self);
      False: ButtonNo.OnClick(Self);
    end;
  end;}

begin
  if Key = #13 then
     ButtonYes.Click //ClickButtonYes
  else
  if Key = #27 then
     ButtonNo.Click;
end;

procedure TFormMessages.FormShow(Sender: TObject);
begin
  //FormMain.UpdateGeneralAppearance(FormMessages);
  BringToFront;
end;

procedure TFormMessages.ButtonYesClick(Sender: TObject);
begin
  MsgResult:= mrYes;
  Close;
end;

procedure TFormMessages.ButtonNoClick(Sender: TObject);
begin
  MsgResult:= mrNo;
  Close;
end;

end.
