unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, LibV, MathUnit;

type
  TMainForm = class(TForm)
    MainMenu1: TMainMenu;
    FileMenu: TMenuItem;
    FileOpen: TMenuItem;
    HelpMenu: TMenuItem;
    HelpContents: TMenuItem;
    FileSave: TMenuItem;
    FileSeperator_01: TMenuItem;
    FileExit: TMenuItem;
    LoadDialog: TOpenDialog;
    SaveDialog: TSaveDialog;
    procedure FileExitClick(Sender: TObject);
    procedure HelpContentsClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormHide(Sender: TObject);
    procedure FileMenuClick(Sender: TObject);
    procedure FileOpenClick(Sender: TObject);
    procedure FileSaveClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.FileExitClick(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.HelpContentsClick(Sender: TObject);
begin
  WinHelp(Handle,'nd_interp.hlp',HELP_CONTENTS,0);
end;

procedure TMainForm.FormShow(Sender: TObject);
begin
  vglCreateChildWindow('output',0,0,ClientWidth,ClientHeight,Handle);
end;

procedure TMainForm.FormHide(Sender: TObject);
begin
  vglDestroyWindow(vglGetCurrentWindow);
end;

procedure TMainForm.FormPaint(Sender: TObject);
begin
  MathUnit.DrawAll(ClientWidth,ClientHeight);
end;

procedure TMainForm.FileMenuClick(Sender: TObject);
begin
  FileSave.Enabled := HaveData;
end;

procedure TMainForm.FileOpenClick(Sender: TObject);
var
  fname : array[0..255] of char;
begin
  if LoadDialog.Execute then
  begin
    fsNative2Unix(fname,PChar(LoadDialog.FileName));
    LoadCoords(fname);
  end;
end;

procedure TMainForm.FileSaveClick(Sender: TObject);
var
  fname : array[0..255] of char;
begin
  if SaveDialog.Execute then
  begin
    fsNative2Unix(fname,PChar(SaveDialog.FileName));
    SaveCoords(fname);
  end;
end;

initialization
  logStartConsoleLog;
  logUpperLevel(LOG_TRACE);
finalization
  logStopConsoleLog;
end.

