unit Childwin;

interface

uses Windows, Classes, Graphics, Forms, Controls, StdCtrls, ExtCtrls,
  PCPanel, PCDrawBox, PCDrawing, PowerCad,menus;

type
  TMDIChild = class(TForm)
    PowerCad1: TPowerCad;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure PowerCad1FileNameChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

uses Main;

{$R *.DFM}

procedure TMDIChild.FormClose(Sender: TObject; var Action: TCloseAction);
var i: Integer;
begin
  Action := caFree;
  if MainForm.MDIChildCount = 1 then begin
    MainForm.GUI.CadControl := nil;
    MainForm.PCMacroDialog1.CadControl := nil;
    MainForm.PCBlockDlg1.CadControl := nil;
    MainForm.PCLayerDlg1.CadControl := nil;
    MainForm.PCPluginDlg1.CadControl := nil;
    MainForm.PCFillDlg1.CadControl := nil;
  end;
  for i := 0 to MainForm.WMenu.Count -1 do
  begin
    if TMenuItem(MainForm.WMenu.Items[i]).Tag = Integer(Self) then
    begin
      MainForm.WMenu.Delete(i);
      exit;
    end;
  end;
end;

procedure TMDIChild.FormActivate(Sender: TObject);
begin
  MainForm.Gui.CadControl := Powercad1;
  MainForm.PCMacroDialog1.CadControl := Powercad1;
  MainForm.PCBlockDlg1.CadControl := Powercad1;
  MainForm.PCLayerDlg1.CadControl := Powercad1;
  MainForm.PCPluginDlg1.CadControl := Powercad1;
  MainForm.PCFillDlg1.CadControl := Powercad1;
end;

procedure TMDIChild.PowerCad1FileNameChange(Sender: TObject);
begin
  Caption := Powercad1.ActiveFile;
end;

end.
