//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "PageSize.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void __fastcall SetThumbTab();
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: PageSize
// Property: StdCtrls.TScrollBar.PageSize

// Warning: Doesn't work.  Only sets the tabsize.  Doesn't scroll the text or anything.
// Warning: The rich edit is not even part of the calculation.

// BeginCode
/*
The following code sets the thumb tab of a scroll bar so
that it represents the proportion of the scrolling range
that is visible:
*/
void __fastcall SetThumbTab()
{
  // Get the minimum (default) size of the thumb tab
  int MinHeight = GetSystemMetrics(SM_CYVTHUMB);
  // Get the size of the scrollbar track
  int TrackHeight = Form1->ScrollBar1->ClientHeight - 2*GetSystemMetrics(SM_CYVSCROLL);
  // set PageSize to represent the visible portion of the scrolling range:
  Form1->ScrollBar1->PageSize = TrackHeight/(Form1->ScrollBar1->Max - Form1->ScrollBar1->Min + 1);
  // Don’t let the thumb tab get too small
  if (Form1->ScrollBar1->PageSize < MinHeight)
  Form1->ScrollBar1->PageSize = MinHeight;
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  const AnsiString Path = "../overview.rtf";
  RichEdit1->PlainText = False;
  RichEdit1->Lines->LoadFromFile(Path);
  SetThumbTab();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RichEdit1Change(TObject *Sender)
{
 SetThumbTab();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
 SetThumbTab();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RichEdit1EndDrag(TObject *Sender, TObject *Target,
      int X, int Y)
{
 SetThumbTab();
}
// EndCode
// EndExample: PageSize
//---------------------------------------------------------------------------
