mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-05 13:37:14 +01:00
lcl: split listitems to ownerdatalistitems. fix #16069
git-svn-id: trunk@29669 -
This commit is contained in:
parent
dc8e82e76f
commit
90a7d1e94e
@ -829,18 +829,18 @@ type
|
||||
procedure WriteLazData(Stream: TStream); // write date in a 64 bits safe way
|
||||
protected
|
||||
procedure DefineProperties(Filer: TFiler); override;
|
||||
function GetCount: Integer;
|
||||
function GetItem(const AIndex: Integer): TListItem;
|
||||
function GetCount: Integer; virtual;
|
||||
function GetItem(const AIndex: Integer): TListItem; virtual;
|
||||
function GetOwner: TPersistent; override;
|
||||
procedure WSCreateItems;
|
||||
procedure DoFinalizeWnd;
|
||||
procedure SetCount(const ACount: Integer);
|
||||
procedure SetCount(const ACount: Integer); virtual;
|
||||
procedure SetItem(const AIndex: Integer; const AValue: TListItem);
|
||||
public
|
||||
function Add: TListItem;
|
||||
procedure AddItem(AItem: TListItem);
|
||||
procedure BeginUpdate;
|
||||
procedure Clear;
|
||||
procedure Clear; virtual;
|
||||
constructor Create(AOwner : TCustomListView);
|
||||
destructor Destroy; override;
|
||||
procedure Delete(const AIndex : Integer);
|
||||
@ -859,6 +859,18 @@ type
|
||||
property Owner: TCustomListView read FOwner;
|
||||
end;
|
||||
|
||||
{ TOwnerDataListItems }
|
||||
|
||||
TOwnerDataListItems = class(TListItems)
|
||||
private
|
||||
fItemsCount : Integer;
|
||||
protected
|
||||
function GetCount: Integer; override;
|
||||
procedure SetCount(const ACount: Integer); override;
|
||||
function GetItem(const AIndex: Integer): TListItem; override;
|
||||
procedure Clear; override;
|
||||
end;
|
||||
|
||||
|
||||
{ TListColumn }
|
||||
|
||||
|
||||
@ -1037,7 +1037,14 @@ procedure TCustomListView.SetOwnerData(const AValue: Boolean);
|
||||
begin
|
||||
if FOwnerData=AValue then exit;
|
||||
FOwnerData:=AValue;
|
||||
if AValue then FSelectedIdx:=-1;
|
||||
Items.Free;
|
||||
if AValue then
|
||||
begin
|
||||
FSelectedIdx:=-1;
|
||||
Items:=TOwnerDataListItems.Create(Self);
|
||||
end else
|
||||
Items:=TListItems.Create(Self);
|
||||
|
||||
if HandleAllocated then
|
||||
TWSCustomListViewClass(WidgetSetClass).SetOwnerData(Self, AValue);
|
||||
end;
|
||||
|
||||
@ -36,15 +36,7 @@ end;
|
||||
|
||||
procedure TListItems.SetCount(const ACount: Integer);
|
||||
begin
|
||||
if not FOwner.OwnerData then Exit;
|
||||
FItems.Count := ACount;
|
||||
if WSUpdateAllowed then
|
||||
WSSetItemsCount(FItems.Count);
|
||||
// reset ownerdata
|
||||
if (FOwner.FOwnerDataItem.Index >= ACount) then
|
||||
FOwner.FOwnerDataItem.SetDataIndex(-1);
|
||||
// invalidate selection
|
||||
FOwner.InvalidateSelected;
|
||||
//just ignore!
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
@ -52,31 +44,18 @@ end;
|
||||
{------------------------------------------------------------------------------}
|
||||
function TListItems.GetItem(const AIndex: Integer): TListItem;
|
||||
begin
|
||||
if not FOwner.OwnerData then
|
||||
begin
|
||||
if (FCacheIndex <> -1) and (FCacheIndex = AIndex)
|
||||
then begin
|
||||
Result := FCacheItem;
|
||||
Exit;
|
||||
end;
|
||||
|
||||
if FItems.Count - 1 < AIndex
|
||||
then Result := nil
|
||||
else begin
|
||||
Result := TListItem(FItems.Items[AIndex]);
|
||||
FCacheItem := Result;
|
||||
FCacheIndex := AIndex;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if (AIndex >= FItems.Count) then
|
||||
begin
|
||||
Result := nil;
|
||||
Exit;
|
||||
end;
|
||||
FOwner.FOwnerDataItem.SetDataIndex(AIndex);
|
||||
Result := FOwner.FOwnerDataItem;
|
||||
if (FCacheIndex <> -1) and (FCacheIndex = AIndex)
|
||||
then begin
|
||||
Result := FCacheItem;
|
||||
Exit;
|
||||
end;
|
||||
|
||||
if FItems.Count - 1 < AIndex
|
||||
then Result := nil
|
||||
else begin
|
||||
Result := TListItem(FItems.Items[AIndex]);
|
||||
FCacheItem := Result;
|
||||
FCacheIndex := AIndex;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -92,7 +71,7 @@ procedure TListItems.SetItem(const AIndex: Integer; const AValue: TListItem);
|
||||
var
|
||||
OldItem: TListItem;
|
||||
begin
|
||||
if FItems.Count - 1 < AIndex then Exit;
|
||||
if Count - 1 < AIndex then Exit;
|
||||
|
||||
OldItem := GetItem(AIndex);
|
||||
if OldItem = AValue then Exit;
|
||||
@ -147,20 +126,8 @@ end;
|
||||
TListItems Clear
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TListItems.Clear;
|
||||
var
|
||||
i : Integer;
|
||||
begin
|
||||
if not Owner.OwnerData then
|
||||
while Count > 0 do Delete(Count-1)
|
||||
else
|
||||
begin
|
||||
for i := 0 to FItems.Count - 1 do
|
||||
begin
|
||||
TListItem(FItems[i]).Free;
|
||||
FItems[i]:=nil;
|
||||
end;
|
||||
Count := 0;
|
||||
end;
|
||||
while Count > 0 do Delete(Count-1)
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
@ -629,3 +596,47 @@ begin
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TOwnerDataListItems }
|
||||
|
||||
function TOwnerDataListItems.GetCount: Integer;
|
||||
begin
|
||||
Result:=fItemsCount;
|
||||
end;
|
||||
|
||||
procedure TOwnerDataListItems.SetCount(const ACount: Integer);
|
||||
begin
|
||||
if (ACount<0) or (ACount=fItemsCount) then Exit;
|
||||
fItemsCount:=ACount;
|
||||
if WSUpdateAllowed then WSSetItemsCount(fItemsCount);
|
||||
// reset ownerdata
|
||||
if (FOwner.FOwnerDataItem.Index >= fItemsCount) then
|
||||
FOwner.FOwnerDataItem.SetDataIndex(-1);
|
||||
// invalidate selection
|
||||
FOwner.InvalidateSelected;
|
||||
end;
|
||||
|
||||
function TOwnerDataListItems.GetItem(const AIndex: Integer): TListItem;
|
||||
begin
|
||||
if (AIndex >= FItemsCount) then
|
||||
begin
|
||||
Result := nil;
|
||||
Exit;
|
||||
end;
|
||||
FOwner.FOwnerDataItem.SetDataIndex(AIndex);
|
||||
Result := FOwner.FOwnerDataItem;
|
||||
end;
|
||||
|
||||
procedure TOwnerDataListItems.Clear;
|
||||
var
|
||||
i : Integer;
|
||||
begin
|
||||
for i := 0 to FItems.Count - 1 do
|
||||
begin
|
||||
TListItem(FItems[i]).Free;
|
||||
FItems[i]:=nil;
|
||||
end;
|
||||
Count := 0;
|
||||
fItemsCount := 0;
|
||||
end;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user