TAChart: Add item caption and TLegendItem object to TChartListbox.Items.

+ Few minor style fixes

git-svn-id: trunk@31636 -
This commit is contained in:
ask 2011-07-10 03:49:13 +00:00
parent d8477e5555
commit 2252e97508

View File

@ -67,6 +67,7 @@ type
procedure SetShowSeriesIcons(AValue: Boolean); procedure SetShowSeriesIcons(AValue: Boolean);
protected protected
procedure DblClick; override;
procedure DrawItem( procedure DrawItem(
AIndex: Integer; ARect: TRect; AState: TOwnerDrawState); override; AIndex: Integer; ARect: TRect; AState: TOwnerDrawState); override;
procedure KeyDown(var AKey: Word; AShift: TShiftState); override; procedure KeyDown(var AKey: Word; AShift: TShiftState); override;
@ -79,7 +80,6 @@ type
procedure ClickedItem(AIndex: Integer); virtual; procedure ClickedItem(AIndex: Integer); virtual;
procedure ClickedSeriesIcon(AIndex: Integer); virtual; procedure ClickedSeriesIcon(AIndex: Integer); virtual;
function CreateLegendItems: TChartLegendItems; function CreateLegendItems: TChartLegendItems;
procedure DblClick; override;
function FirstCheckedIndex: Integer; function FirstCheckedIndex: Integer;
function IsLocked: Boolean; function IsLocked: Boolean;
procedure Lock; procedure Lock;
@ -198,7 +198,7 @@ destructor TChartListbox.Destroy;
begin begin
FreeAndNil(FListener); FreeAndNil(FListener);
FreeAndNil(FLegendItems); FreeAndNil(FLegendItems);
inherited Destroy; inherited;
end; end;
procedure TChartListbox.CalcRects( procedure TChartListbox.CalcRects(
@ -382,7 +382,7 @@ begin
Result := FLockCount <> 0; Result := FLockCount <> 0;
end; end;
procedure TChartListBox.KeyDown(var AKey: Word; AShift: TShiftState); procedure TChartListbox.KeyDown(var AKey: Word; AShift: TShiftState);
{ allows checking/unchecking of items by means of pressing the space bar } { allows checking/unchecking of items by means of pressing the space bar }
begin begin
if (AKey = VK_SPACE) and (AShift = []) and FShowCheckboxes then begin if (AKey = VK_SPACE) and (AShift = []) and FShowCheckboxes then begin
@ -393,14 +393,14 @@ begin
inherited KeyDown(AKey, AShift); inherited KeyDown(AKey, AShift);
end; end;
procedure TChartListBox.Lock; procedure TChartListbox.Lock;
{ locking mechanism to avoid excessive broadcasting of chart changes. { locking mechanism to avoid excessive broadcasting of chart changes.
See also: IsLocked and UnLock } See also: IsLocked and UnLock }
begin begin
FLockCount += 1; FLockCount += 1;
end; end;
procedure TChartListBox.MeasureItem(AIndex: Integer; var AHeight: Integer); procedure TChartListbox.MeasureItem(AIndex: Integer; var AHeight: Integer);
{ inherited from ancestor: measures the height of a listbox item taking into { inherited from ancestor: measures the height of a listbox item taking into
account the height of the checkbox } account the height of the checkbox }
begin begin
@ -451,19 +451,18 @@ procedure TChartListbox.Populate;
var var
i: Integer; i: Integer;
begin begin
Items.BeginUpdate;
try try
Items.BeginUpdate;
Items.Clear; Items.Clear;
if FChart = nil then exit; if FChart = nil then exit;
FreeAndNil(FLegendItems); FreeAndNil(FLegendItems);
FLegendItems := CreateLegendItems; FLegendItems := CreateLegendItems;
for i := 0 to FLegendItems.Count - 1 do for i := 0 to FLegendItems.Count - 1 do
Items.Add(''); // The caption is owner-drawn, but add it anyway for user convenience.
// the caption is owner-drawn using info from the FLegendItems Items.AddObject(FLegendItems[i].Text, FLegendItems[i]);
// --> no need to pass the text here
if Assigned(OnPopulate) then if Assigned(OnPopulate) then
OnPopulate(self); OnPopulate(Self);
finally finally
Items.EndUpdate; Items.EndUpdate;
end; end;