lcl: add support for invisible sections in THeaderControl (from Benito van der Zander #0011727)

git-svn-id: trunk@16817 -
This commit is contained in:
paul 2008-10-01 05:42:41 +00:00
parent e6b1fe55e0
commit 220ada332c
2 changed files with 39 additions and 4 deletions

View File

@ -2575,8 +2575,10 @@ type
FMaxWidth: Integer;
FState: THeaderSectionState;
FText: string;
FVisible: Boolean;
FWidth: Integer;
FOriginalIndex: Integer;
function GetWidth: Integer;
function GetLeft: Integer;
function GetRight: Integer;
procedure SetAlignment(const AValue: TAlignment);
@ -2584,6 +2586,7 @@ type
procedure SetMinWidth(AValue: Integer);
procedure SetState(const AValue: THeaderSectionState);
procedure SetText(const Value: string);
procedure SetVisible(const AValue: Boolean);
procedure SetWidth(Value: Integer);
procedure SetImageIndex(const Value: TImageIndex);
procedure CheckConstraints;
@ -2599,7 +2602,8 @@ type
property MaxWidth: Integer read FMaxWidth write SetMaxWidth default 10000;
property MinWidth: Integer read FMinWidth write SetMinWidth default 0;
property Text: string read FText write SetText;
property Width: Integer read FWidth write SetWidth;
property Width: Integer read GetWidth write SetWidth;
property Visible: Boolean read FVisible write SetVisible;
//index which doesn't change when the user reorders the sections
property OriginalIndex: Integer read FOriginalIndex;
end;
@ -2658,6 +2662,7 @@ type
FOnSectionDrag: TSectionDragEvent;
FOnSectionEndDrag: TNotifyEvent;
FOnCreateSectionClass: TCustomHCCreateSectionClassEvent;
function GetSectionFromOriginalIndex(OriginalIndex: Integer): THeaderSection;
procedure SetImages(const AValue: TCustomImageList);
procedure SetSections(const AValue: THeaderSections);
procedure UpdateSection(Index: Integer);
@ -2682,6 +2687,8 @@ type
procedure UpdateState;
class function GetControlClassDefaultSize: TPoint; override;
public
property SectionFromOriginalIndex[OriginalIndex: Integer]: THeaderSection read GetSectionFromOriginalIndex;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

View File

@ -28,6 +28,16 @@ begin
FImages := AValue;
end;
function TCustomHeaderControl.GetSectionFromOriginalIndex(OriginalIndex: Integer): THeaderSection;
var
i: Longint;
begin
Result := nil;
for i := 0 to FSections.Count - 1 do
if FSections[i].OriginalIndex = OriginalIndex then
Exit(FSections[i]);
end;
procedure TCustomHeaderControl.SetSections(const AValue: THeaderSections);
begin
FSections := AValue;
@ -107,7 +117,7 @@ var
begin
Result := -1;
for i := 0 to Sections.Count - 1 do
if (Sections[i].Left <= P.X) and (Sections[i].Right >= P.X) then
if Sections[i].Visible and (Sections[i].Left <= P.X) and (Sections[i].Right >= P.X) then
begin
Result := i;
break;
@ -141,8 +151,7 @@ begin
FOnSectionTrack(Self, Section, Section.FWidth, State);
end;
procedure TCustomHeaderControl.SectionSeparatorDblClick(Section: THeaderSection
);
procedure TCustomHeaderControl.SectionSeparatorDblClick(Section: THeaderSection);
begin
if Assigned(FOnSectionSeparatorDblClick) then
FOnSectionSeparatorDblClick(Self, Section);
@ -364,6 +373,7 @@ var
Section: THeaderSection;
begin
Section := Sections[Index];
if not Section.Visible then Exit;
ARect := FPaintRect;
ARect.Left := FPaintRect.Left + Section.Left;
ARect.Right := FPaintRect.Left + Section.Right;
@ -459,6 +469,14 @@ end;
{ THeaderSection }
function THeaderSection.GetWidth: Integer;
begin
if Visible then
Result := FWidth
else
Result := 0;
end;
function THeaderSection.GetLeft: Integer;
var
i: integer;
@ -530,6 +548,15 @@ begin
end;
end;
procedure THeaderSection.SetVisible(const AValue: Boolean);
begin
if FVisible <> AValue then
begin
FVisible := AValue;
Changed(False);
end;
end;
procedure THeaderSection.SetWidth(Value: Integer);
begin
if FWidth <> Value then
@ -565,6 +592,7 @@ begin
FText := '';
FAlignment := taLeftJustify;
FState := hsNormal;
FVisible := True;
FMinWidth := 0;
FMaxWidth := 10000;
FOriginalIndex:=ACollection.Count-1;