From b88059e19b5b3ce40adcd130728ab51993a9c838 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 1 Dec 2009 23:49:24 +0000 Subject: [PATCH] Fixed bug #10622 where Listview.ItemIndex did not exist git-svn-id: trunk@22909 - --- lcl/comctrls.pp | 4 ++++ lcl/include/customlistview.inc | 18 ++++++++++++++++++ lcl/lclmessageglue.pas | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index 09353ce12e..1dfc742cc6 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -1030,6 +1030,7 @@ type function GetFocused: TListItem; function GetImageList(const ALvilOrd: Integer): TCustomImageList; function GetHoverTime: Integer; + function GetItemIndex: Integer; function GetProperty(const ALvpOrd: Integer): Boolean; function GetSelCount: Integer; function GetSelection: TListItem; @@ -1046,6 +1047,7 @@ type procedure SetHoverTime(const AValue: Integer); procedure SetIconOptions(const AValue: TIconOptions); procedure SetImageList(const ALvilOrd: Integer; const AValue: TCustomImageList); + procedure SetItemIndex(const AValue: Integer); procedure SetItems(const AValue : TListItems); procedure SetItemVisible(const AValue: TListItem; const APartialOK: Boolean); procedure SetOwnerData(const AValue: Boolean); @@ -1144,6 +1146,7 @@ type property HotTrackStyles: TListHotTrackStyles read FHotTrackStyles write SetHotTrackStyles default []; property IconOptions: TIconOptions read FIconOptions write SetIconOptions; property ItemFocused: TListItem read GetFocused write SetFocused; + property ItemIndex: Integer read GetItemIndex write SetItemIndex; property Items: TListItems read FListItems write SetItems; // MultiSelect and ReadOnly should be protected, but can't because Carbon Interface // needs to access this property and it cannot cast to TListItem, because we have @@ -1190,6 +1193,7 @@ type // property HotTrackStyles; // property HoverTime; property IconOptions; + property ItemIndex; property Items; property LargeImages; property MultiSelect; diff --git a/lcl/include/customlistview.inc b/lcl/include/customlistview.inc index f4b053b155..9a95d19ae9 100644 --- a/lcl/include/customlistview.inc +++ b/lcl/include/customlistview.inc @@ -737,6 +737,14 @@ begin else Result := FHoverTime; end; +function TCustomListView.GetItemIndex: Integer; +begin + Result := -1; + if Selected = nil then + Exit; + Result := Selected.Index; +end; + function TCustomListView.GetHitTestInfoAt(X, Y: Integer): THitTests; begin Result := []; @@ -909,6 +917,16 @@ begin TWSCustomListViewClass(WidgetSetClass).SetImageList(Self, lvil, AValue); end; +procedure TCustomListView.SetItemIndex(const AValue: Integer); +begin + if (AValue < -1) or (AValue >= Items.Count) then + raise Exception.Create(Format('index %d out of bounds',[AValue])); + if AValue = -1 then + Selected := nil + else + Selected := Items.Item[AValue]; +end; + {------------------------------------------------------------------------------ TCustomListView SetSelection ------------------------------------------------------------------------------} diff --git a/lcl/lclmessageglue.pas b/lcl/lclmessageglue.pas index 2eaafc1ddf..4fe7cd0f16 100644 --- a/lcl/lclmessageglue.pas +++ b/lcl/lclmessageglue.pas @@ -490,8 +490,8 @@ end; * Params * * * * Target : The Control that will recieve the message LM_CHANGED * - * ItemIndex : Only used by Listviews. The Index of the Item that has * - * changed. * + * ItemIndex : Only used by Listviews and CheckBoxes. The Index of * + * the Item that has changed. * * * ******************************************************************************} function LCLSendChangedMsg(const Target: TControl; ItemIndex: WPARAM = 0): PtrInt;