mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-23 11:40:35 +02:00
LCL: Change selection properly when setting TListBox.ItemIndex. Issue #34967, patch from Denis Kozlov.
git-svn-id: trunk@62312 -
This commit is contained in:
parent
733d74e407
commit
065d7f1e25
@ -25,8 +25,14 @@ type
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TCustomListBox.AssignCacheToItemData(const AIndex: Integer;
|
||||
const AData: Pointer);
|
||||
var
|
||||
SelectItem: Boolean;
|
||||
begin
|
||||
if PCustomListBoxItemRecord(AData)^.Selected or (not MultiSelect and (FItemIndex = AIndex)) then
|
||||
if MultiSelect then
|
||||
SelectItem := PCustomListBoxItemRecord(AData)^.Selected
|
||||
else
|
||||
SelectItem := FItemIndex = AIndex;
|
||||
if SelectItem then
|
||||
begin
|
||||
LockSelectionChange;
|
||||
SendItemSelected(AIndex, True);
|
||||
@ -90,6 +96,38 @@ begin
|
||||
PCustomListBoxItemRecord(AData)^.Selected := Selected[AIndex];
|
||||
end;
|
||||
|
||||
procedure TCustomListBox.ClearSelectedCache;
|
||||
var
|
||||
i: Integer;
|
||||
CacheItems: TExtendedStringList;
|
||||
begin
|
||||
if not FCacheValid then
|
||||
raise EInvalidOperation.Create('Cache is not valid.');
|
||||
CacheItems := FItems as TExtendedStringList;
|
||||
for i := 0 to CacheItems.Count - 1 do
|
||||
PCustomListBoxItemRecord(CacheItems.Records[i])^.Selected := False;
|
||||
end;
|
||||
|
||||
procedure TCustomListBox.SetSelectedCache(Index: Integer; IsSelected: Boolean);
|
||||
var
|
||||
CacheItems: TExtendedStringList;
|
||||
begin
|
||||
if not FCacheValid then
|
||||
raise EInvalidOperation.Create('Cache is not valid.');
|
||||
CacheItems := FItems as TExtendedStringList;
|
||||
PCustomListBoxItemRecord(CacheItems.Records[Index])^.Selected := IsSelected;
|
||||
end;
|
||||
|
||||
function TCustomListBox.GetSelectedCache(Index: Integer): Boolean;
|
||||
var
|
||||
CacheItems: TExtendedStringList;
|
||||
begin
|
||||
if not FCacheValid then
|
||||
raise EInvalidOperation.Create('Cache is not valid.');
|
||||
CacheItems := FItems as TExtendedStringList;
|
||||
Result := PCustomListBoxItemRecord(CacheItems.Records[Index])^.Selected;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
procedure TCustomListBox.InitializeWnd
|
||||
------------------------------------------------------------------------------}
|
||||
@ -392,7 +430,7 @@ begin
|
||||
if HandleAllocated then
|
||||
SendItemSelected(Index, Val)
|
||||
else
|
||||
PCustomListBoxItemRecord(GetCachedData(Index))^.Selected := Val;
|
||||
SetSelectedCache(Index, Val);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -405,7 +443,7 @@ begin
|
||||
if HandleAllocated then
|
||||
Result := TWSCustomListBoxClass(WidgetSetClass).GetSelected(Self, Index)
|
||||
else
|
||||
Result := PCustomListBoxItemRecord(GetCachedData(Index))^.Selected;
|
||||
Result := GetSelectedCache(Index);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
@ -610,8 +648,17 @@ begin
|
||||
RaiseIndexOutOfBounds(AIndex);
|
||||
if AIndex < 0 then AIndex := -1;
|
||||
FItemIndex := AIndex;
|
||||
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
|
||||
SendItemIndex;
|
||||
if HandleAllocated then
|
||||
begin
|
||||
if ([csLoading,csDestroying]*ComponentState=[]) then
|
||||
SendItemIndex;
|
||||
end
|
||||
else
|
||||
begin
|
||||
ClearSelectedCache;
|
||||
if FItemIndex >= 0 then
|
||||
SetSelectedCache(FItemIndex, True);
|
||||
end;
|
||||
DoSelectionChange(false);
|
||||
end;
|
||||
|
||||
|
@ -540,6 +540,9 @@ type
|
||||
procedure LMSelChange(var TheMessage); message LM_SelChange;
|
||||
procedure WMLButtonUp(Var Message: TLMLButtonUp); message LM_LBUTTONUP;
|
||||
procedure SendItemSelected(Index: integer; IsSelected: boolean);
|
||||
procedure ClearSelectedCache;
|
||||
procedure SetSelectedCache(Index: Integer; IsSelected: Boolean);
|
||||
function GetSelectedCache(Index: Integer): Boolean;
|
||||
protected
|
||||
class procedure WSRegisterClass; override;
|
||||
procedure AssignItemDataToCache(const AIndex: Integer; const AData: Pointer); virtual; // called to store item data while the handle isn't created
|
||||
|
Loading…
Reference in New Issue
Block a user