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

#include "lebcb_5a.h"
//---------------------------------------------------------------------------
#pragma link "LEDlp32"
#pragma resource "*.dfm"
TCppPasForm *CppPasForm;

//---------------------------------------------------------------------------
__fastcall TCppPasForm::TCppPasForm(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TCppPasForm::FormCreate(TObject *Sender)
{
  WndCPP->LoadFromFile("lebcb_5a.cpp");
  WndPAS->LoadFromFile("lebcb_5a.pas");
}
//---------------------------------------------------------------------------
void __fastcall TCppPasForm::WndCPPControlHighlight(TObject *Sender,
	WORD WordType, long WordValue, AnsiString WordStr, TColor &ForeClr,
	TColor &BackClr)
{
//  TWordDesc MyWord;

//  MyWord = WndPAS->WordDesc;
  if (WordType == WD_SIMPLEWORD) {
    // Set default text color for words
    ForeClr = clBlack;
    BackClr = WndPAS->Color;

    // Mark C++ keywords if this is CPP window
    for (int i=0; i < CPP_WORDS -1; i++) {
      if (CompareText(WordStr,CPPWords[i]) == 0) {
        ForeClr = clBlue;
        break;
      }
    }
  }
  else if (WordType == WD_SYNTAXITEM) {
    // Set text color for syntax words
    ForeClr = (Graphics::TColor)RGB(0,0,192);
  }
  else if ((WordType == WD_BADLYQUOTEDTEXT) ||
          (WordType == WD_QUOTEDTEXT)) {
    // Set text color for quoted text
    if (HiWord(WordValue) == 1)
      ForeClr = (Graphics::TColor)RGB(0,128,0);
    else
      ForeClr = clRed;
  }
  else {
    // Set text color for the rest of words, that is
    // for numbers
    ForeClr = (Graphics::TColor)RGB(0,128,0);
  }
}
//---------------------------------------------------------------------------
void __fastcall TCppPasForm::WndCPPFindBrace(TObject *Sender, WORD WordType,
	long WordValue, AnsiString WordStr, TLEBraceStyle &BraceType)
{
  WORD SyntaxIndex;
  TWordDesc MyWord;

  MyWord.wCode = 0;
  MyWord.dwValue = 0;
  StrPCopy(MyWord.caWord, "");
  if (WordType == WD_SYNTAXITEM) {
    // Indicate braces for parantheses, brackets etc.
    SyntaxIndex = HiWord(WordValue);
    if (SyntaxIndex > 10)
      BraceType = brNone;

    if ((SyntaxIndex % 2) == 1) {
      SyntaxIndex++;
      BraceType = brLeftBrace;
    }
    else {
      SyntaxIndex--;
      BraceType = brRightBrace;
    }
    MyWord.dwValue = MakeLong(0, SyntaxIndex);
  }
  else {
    // No more braces for CPP
    BraceType = brNone;
  }
  WndCPP->WordDesc = MyWord;
}
//---------------------------------------------------------------------------
void __fastcall TCppPasForm::WndCPPWordClick(TObject *Sender, WORD WordType,
	long WordValue, AnsiString WordStr, bool &WordHandled)
{
  AnsiString MsgStr;
  WORD SyntaxIndex;

  // Show message about word supplied if it exists
  MsgStr = WordStr;
  MsgStr = MsgStr + "\n";
  if (WordType == WD_SYNTAXITEM) {
    SyntaxIndex = HiWord(WordValue);
    MsgStr = MsgStr + "Syntax: " + IntToStr(SyntaxIndex);
  }
  else if ((WordType & WDF_INTEGER) > 0)
    MsgStr = MsgStr + "Integer: " + IntToStr(WordValue);

  // Display the Message Dialog
  MessageDlg(MsgStr, mtInformation, TMsgDlgButtons() << mbOK, 0);
}
//---------------------------------------------------------------------------
void __fastcall TCppPasForm::WndPASControlHighlight(TObject *Sender,
	WORD WordType, long WordValue, AnsiString WordStr, TColor &ForeClr,
	TColor &BackClr)
{
//  TWordDesc MyWord;

//  MyWord = WndPAS->WordDesc;
  if (WordType == WD_SIMPLEWORD) {
    // Set default text color for words
    ForeClr = clBlack;
    BackClr = WndPAS->Color;

    // Mark Pascal keyword if this is PAS window
    for (int i=0; i < PAS_WORDS -1; i++) {
      if (CompareText(WordStr,PASWords[i]) == 0) {
        ForeClr = clBlue;
        break;
      }
    }
  }
  else if (WordType == WD_SYNTAXITEM) {
    // Set text color for syntax words
    ForeClr = (Graphics::TColor)RGB(0,0,192);
  }
  else if ((WordType == WD_BADLYQUOTEDTEXT) ||
          (WordType == WD_QUOTEDTEXT)) {
    // Set text color for quoted text
    if (HiWord(WordValue) == 1) {
      ForeClr = (Graphics::TColor)RGB(0,128,0);
    } else {
      ForeClr = clRed;
    }
  }
  else {
    // Set text color for the rest of words, that is
    // for numbers
    ForeClr = (Graphics::TColor)RGB(0,128,0);
  }
}
//---------------------------------------------------------------------------
void __fastcall TCppPasForm::WndPASFindBrace(TObject *Sender, WORD WordType,
	long WordValue, AnsiString WordStr, TLEBraceStyle &BraceType)
{
  WORD SyntaxIndex;
  TWordDesc MyWord;

  MyWord.wCode = 0;
  MyWord.dwValue = 0;
  StrPCopy(MyWord.caWord, "");
  if (WordType == WD_SYNTAXITEM) {
    // Indicate braces for parantheses, brackets etc.
    SyntaxIndex = HiWord(WordValue);
    if (SyntaxIndex > 10) {
      BraceType = brNone;
    }
    if ((SyntaxIndex % 2) == 1) {
      SyntaxIndex++;
      BraceType = brRightBrace;
    }
    else {
      SyntaxIndex--;
      BraceType = brLeftBrace;
    }
    MyWord.dwValue = MakeLong(0, SyntaxIndex);
  }
  else {
    // Look for "begin"
    if (CompareText(WordStr,PAS_LEFT_BRACE) == 0) {
      StrPCopy(MyWord.caWord, PAS_RIGHT_BRACE);
      BraceType = brNoCaseLeftBrace;
    }

    // Also look for "end"
    if (CompareText(WordStr,PAS_RIGHT_BRACE) == 0) {
      StrPCopy(MyWord.caWord, PAS_LEFT_BRACE);
      BraceType = brNoCaseRightBrace;
    }
  }
  WndPAS->WordDesc = MyWord;
}
//---------------------------------------------------------------------------
void __fastcall TCppPasForm::WndPASWordClick(TObject *Sender, WORD WordType,
	long WordValue, AnsiString WordStr, bool &WordHandled)
{
  AnsiString MsgStr;
  WORD SyntaxIndex;

  // Show message about word supplied if it exists
  MsgStr = WordStr;

  MsgStr = MsgStr + "\n";
  if (WordType == WD_SYNTAXITEM) {
    SyntaxIndex = HiWord(WordValue);
    MsgStr = MsgStr + "Syntax: " + IntToStr(SyntaxIndex);
  }
  else if ((WordType & WDF_INTEGER) > 0) {
    MsgStr = MsgStr + "Integer: " + IntToStr(WordValue);
  }

  // Display the Message Dialog
  MessageDlg(MsgStr, mtInformation, TMsgDlgButtons() << mbOK, 0);
}
//---------------------------------------------------------------------------