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

#include "Demo4Frm.h"
//---------------------------------------------------------------------------
#pragma link "RichView"
#pragma link "RVScroll"
#pragma link "RVStyle"
#pragma resource "*.dfm"
TfrmDemo4 *frmDemo4;
//---------------------------------------------------------------------------
__fastcall TfrmDemo4::TfrmDemo4(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
const UnicodeString Descriptions[8] =
{
   "Exact time twice a day!",
   "Unique 9-button model",
   "Additional keys available on request",
   "Must have for any airline!",
   "Second hand",
   "Universal thing",
   "2 kg",
   "Brooklyn Bridge, available only today, 10% discount for first 10 buyers!"
};
//---------------------------------------------------------------------------
void TfrmDemo4::BuildDoc()
{
  int VPos = rv->VScrollPos;
  rv->Clear();
  rv->AddNLWTag("Welcome to our shop!",1,1,0);
  rv->AddNLWTag("Today we have:",2,1,0);
  for (int i=0; i<GoodsCount; i++)
  {
	rv->AddBulletEx("", Goods[i], ilGoods, 0);
	rv->AddNLWTag(pm->Items->Items[Goods[i]]->Caption,3,-1,0);
	rv->AddNLWTag(" ("+Descriptions[Goods[i]]+") ",0,-1,0);
	rv->AddHotspotEx("", 2,3, il, -1);
	rv->AddBreak();
  }
  if (GoodsCount!=10)
	rv->AddHotspotEx("", 0,1, il, 0);
  rv->Format();
  rv->VScrollPos = VPos;
}
void __fastcall TfrmDemo4::FormCreate(TObject *Sender)
{
  pm->AutoHotkeys = maManual;
  BuildDoc();
}
//---------------------------------------------------------------------------
void __fastcall TfrmDemo4::rvJump(TObject *Sender, int id)
{
  if (id==GoodsCount)
  {
	// adding
	TPoint p;
	GetCursorPos(&p);
	pm->Popup(p.x, p.y);
  }
  else
  {
	// deleting
	for (int i=id; i<GoodsCount-1; i++)
	  Goods[i] = Goods[i+1];
	GoodsCount--;
	BuildDoc();
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmDemo4::pmItemClick(TObject *Sender)
{
  Goods[GoodsCount++] = ((TMenuItem*)(Sender))->MenuIndex;
  BuildDoc();
  rv->VScrollPos = rv->VScrollMax;
}
//---------------------------------------------------------------------------
void __fastcall TfrmDemo4::FormKeyDown(TObject *Sender, WORD &Key,
    TShiftState Shift)
{
  if (Key==VK_ESCAPE)
    Close();    
}
//---------------------------------------------------------------------------
