diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index aea56ac878..be93a4b88f 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -1457,6 +1457,21 @@ type function FindData(StartIndex: Integer; Value: Pointer; Inclusive, Wrap: Boolean): TListItem; function GetHitTestInfoAt(X, Y: Integer): THitTests; function GetItemAt(x,y: integer): TListItem; + + + {GetNearestItem is used to locate a list item from a position specified in + pixel coordinates relative to the top left corner of the list view. + It starts looking at the position specified by the Point parameter, + and moves in the direction indicated by the Direction parameter + until it locates a list item.If no item is found Nil is returned.} + function GetNearestItem(APoint: TPoint; Direction: TSearchDirection): TListItem; + + {Used to find the next list item after StartItem in the direction + given by the Direction parameter. + Only items in the state indicated by the States parameter are considered. + If no item is found Nil is returned.} + function GetNextItem(StartItem: TListItem; Direction: TSearchDirection; States: TListItemStates): TListItem; + function IsEditing: Boolean; // Delphi compatibile function which returns if our listview editor is active property BoundingRect: TRect read GetBoundingRect; property BorderStyle default bsSingle; diff --git a/lcl/include/customlistview.inc b/lcl/include/customlistview.inc index bf295c401c..59fcdaf911 100644 --- a/lcl/include/customlistview.inc +++ b/lcl/include/customlistview.inc @@ -1142,6 +1142,81 @@ begin end; end; +function TCustomListView.GetNearestItem(APoint: TPoint; + Direction: TSearchDirection): TListItem; +var + AItem: TListItem; + AIndex: Integer; +begin + Result := nil; + AItem := GetItemAt(APoint.x, APoint.y); + if Assigned(AItem) then + begin + AIndex := AItem.Index; + case Direction of + sdAbove: if AIndex - 1 >= 0 then Result := Items[AIndex - 1]; + sdBelow: if AIndex - 1 < Items.Count then + Result := Items[AIndex + 1]; + end; + end; +end; + +function TCustomListView.GetNextItem(StartItem: TListItem; + Direction: TSearchDirection; States: TListItemStates): TListItem; +var + ACount: Integer; + AIndex: Integer; + + {TODO: create public property States which reads states of item} + function GetItemStatesInternal(AItem: TListItem): TListItemStates; + begin + Result := []; + if AItem.GetState(Ord(lisCut)) then + ; + if AItem.GetState(Ord(lisDropTarget)) then + ; + if AItem.GetState(Ord(lisSelected)) then + ; + if AItem.GetState(Ord(lisFocused)) then + ; + Result := AItem.FStates; + end; + +begin + Result := nil; + if Assigned(StartItem) then + begin + AIndex := StartItem.Index; + ACount := Items.Count; + case Direction of + sdAbove: if (AIndex -1) >= 0 then Result := Items[AIndex - 1]; + sdBelow: if (Aindex + 1) < ACount then Result := Items[AIndex + 1]; + sdAll: + while True do + begin + inc(AIndex); + if AIndex = StartItem.Index then + begin + Result := nil; + Exit; + end; + if AIndex >= ACount then + AIndex := -1; + if (AIndex >= 0) and (AIndex < ACount) then + begin + Result := Items[AIndex]; + if GetItemStatesInternal(Result) - States = [] then + Exit; + end; + end; + end; + if Result = nil then + exit; + if (GetItemStatesInternal(Result) * States = []) then + Result := nil; + end +end; + function TCustomListView.IsEditing: Boolean; begin Result := Assigned(Self.FEditor) and FEditor.Visible;