unit U_NormBase;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TF_NormBase = class(TForm)
    procedure FormStartDock(Sender: TObject; var DragObject: TDragDockObject);
    procedure FormCreate(Sender: TObject);
    procedure FormEndDock(Sender, Target: TObject; X, Y: Integer);
    procedure FormPaint(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Docking: Bool;
  end;

var
  F_NormBase: TF_NormBase;

implementation
uses USCS_Main, U_CAD;

{$R *.dfm}


procedure TF_NormBase.FormStartDock(Sender: TObject;
  var DragObject: TDragDockObject);
begin
  Docking := True;
end;

procedure TF_NormBase.FormCreate(Sender: TObject);
begin
  Docking := False;
end;

procedure TF_NormBase.FormEndDock(Sender, Target: TObject; X, Y: Integer);
begin
  Docking := False;
  if TForm(Sender).Left > Screen.Width -100 then
    TForm(Sender).Left := TForm(Sender).Left - 50;
  if TForm(Sender).Top > Screen.Height -100 then
    TForm(Sender).Top := TForm(Sender).Top - 50;
end;

procedure TF_NormBase.FormPaint(Sender: TObject);
begin
  if TForm(Sender).Left > Screen.Width -100 then
    TForm(Sender).Left := TForm(Sender).Left - 50;
  if TForm(Sender).Top > Screen.Height -100 then
    TForm(Sender).Top := TForm(Sender).Top - 50;
end;

procedure TF_NormBase.FormClose(Sender: TObject; var Action: TCloseAction);
var
  ParentPanel: TComponent;
begin
  FSCS_Main.aViewNormBase.Checked := false;
  ParentPanel := TForm(Sender).GetParentComponent;
  if CurrActiveForm = nil then
    Exit;

  if ParentPanel = TF_CAD(CurrActiveForm).pDock1 then
    TF_CAD(CurrActiveForm).CountDock1 := TF_CAD(CurrActiveForm).CountDock1 - 1;
  if ParentPanel = TF_CAD(CurrActiveForm).pDock2 then
    TF_CAD(CurrActiveForm).CountDock2 := TF_CAD(CurrActiveForm).CountDock2 - 1;

  if TF_CAD(CurrActiveForm).CountDock1 = 0 then
  begin
    TF_CAD(CurrActiveForm).pDock1.Width := 1;
    TF_CAD(CurrActiveForm).sDiv1.Visible := False;
  end;
  if TF_CAD(CurrActiveForm).CountDock2 = 0 then
  begin
    TF_CAD(CurrActiveForm).sDiv2.Visible := False;
    TF_CAD(CurrActiveForm).pDock2.Width := 1;
  end;
end;

procedure TF_NormBase.FormShow(Sender: TObject);
begin
  FSCS_Main.aViewNormBase.Checked := true;
//  Left := 800;
//  Top := 40;
end;

end.
