//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "lebcb_2a.h"
#include "lebcb_2b.h"
#include "lebcb_2z.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileNewItemClick(TObject *Sender)
{
  CreateMDIChild("Untitled" + IntToStr(MDIChildCount + 1));
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileOpenItemClick(TObject *Sender)
{
  if (OpenDialog->Execute()) {
    CreateMDIChild(OpenDialog->FileName);
    ((TMDIChild*)this->ActiveMDIChild)->LEdit1->LoadFromFile(OpenDialog->FileName);
  }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileCloseItemClick(TObject *Sender)
{
  if (this->ActiveMDIChild != NULL)
    ((TMDIChild*)this->ActiveMDIChild)->Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileSaveItemClick(TObject *Sender)
{
  // save current file (ActiveMDIChild points to the window)
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->SaveFile();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileSaveAsItemClick(TObject *Sender)
{
  // save current file under new name
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->SaveFileAs();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileExitItemClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CutItemClick(TObject *Sender)
{
  //cut selection to clipboard
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->CutToClipboard();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CopyItemClick(TObject *Sender)
{
  //copy selection to clipboard
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->CopyToClipboard();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::PasteItemClick(TObject *Sender)
{
  //paste from clipboard
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->PasteFromClipboard();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Insert1Click(TObject *Sender)
{
  Insert1->Checked = !(Insert1->Checked);
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->InsertMode = Insert1->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Search1Click(TObject *Sender)
{
  //Search
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->ShowFindDialog();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FindNext1Click(TObject *Sender)
{
  //Find Next
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->FindNext();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Replace1Click(TObject *Sender)
{
  //Replace
  ((TMDIChild*)this->ActiveMDIChild)->LEdit1->ShowReplaceDialog();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WindowCascadeItemClick(TObject *Sender)
{
  Cascade();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WindowTileItemClick(TObject *Sender)
{
  TileMode = tbVertical;
  Tile();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WindowArrangeItemClick(TObject *Sender)
{
  ArrangeIcons();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WindowMinimizeItemClick(TObject *Sender)
{
  // Must be done backwards through the MDIChildren array
  for (int i=MDIChildCount-1; i >= 0; i--)
    MDIChildren[i]->WindowState = wsMinimized;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::HelpAboutItemClick(TObject *Sender)
{
  LEMDIAboutBox->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UpdateMenuItems(TObject *Sender)
{
  FileCloseItem->Enabled = MDIChildCount > 0;
  FileSaveItem->Enabled = MDIChildCount > 0;
  FileSaveAsItem->Enabled = MDIChildCount > 0;
  CutItem->Enabled = MDIChildCount > 0;
  CopyItem->Enabled = MDIChildCount > 0;
  PasteItem->Enabled = MDIChildCount > 0;
  SaveBtn->Enabled = MDIChildCount > 0;
  SaveAsBtn->Enabled = MDIChildCount > 0;
  CloseBtn->Enabled = MDIChildCount > 0;
  CutBtn->Enabled = MDIChildCount > 0;
  CopyBtn->Enabled = MDIChildCount > 0;
  PasteBtn->Enabled = MDIChildCount > 0;
  WindowCascadeItem->Enabled = MDIChildCount > 0;
  WindowTileItem->Enabled = MDIChildCount > 0;
  WindowArrangeItem->Enabled = MDIChildCount > 0;
  WindowMinimizeItem->Enabled = MDIChildCount > 0;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CreateMDIChild(AnsiString Name)
{
  TMDIChild *Child = new TMDIChild(this);

  // create a new MDI child window
//  Child = TMDIChild->Create(Application);
  Child->Caption = Name;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ShowHint(TObject *Sender)
{
  StatusLine->Caption = Application->Hint;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  Application->OnHint = ShowHint;
  Screen->OnActiveFormChange = UpdateMenuItems;
  Application->HintColor = clAqua;
  Application->HintPause = 0;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
  Screen->OnActiveFormChange = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::TileHorizontally1Click(TObject *Sender)
{
  TileMode = tbHorizontal;
  Tile();
}
//---------------------------------------------------------------------------
