lcl: introduce TListBox.GetItemAtXY, TListBox.GetItemAtY exists for compatibility with existing projects

interfaces: replace TWSCustomListBox.GetIndexAtY by TWSCustomListBox.GetIndexAtXY
win32, wince, qt, carbon: use X coord too
(based on patch of Yuriy Yeroshkin, #0011923)

git-svn-id: trunk@16801 -
This commit is contained in:
paul 2008-09-30 02:15:17 +00:00
parent f5c5b2ab66
commit 898d951e30
10 changed files with 52 additions and 42 deletions

View File

@ -636,15 +636,20 @@ begin
end;
{------------------------------------------------------------------------------
function TCustomListBox.GetIndexAtY(Y: integer): integer;
function TCustomListBox.GetIndexAtXY(X, Y: integer): integer;
Returns item index at y coordinate (including scrolling)
Returns item index at x, y coordinate (including scrolling)
------------------------------------------------------------------------------}
function TCustomListBox.GetIndexAtXY(X, Y: integer): integer;
begin
Result := -1;
if (not HandleAllocated) then Exit;
Result := TWSCustomListBoxClass(WidgetSetClass).GetIndexAtXY(Self, X, Y);
end;
function TCustomListBox.GetIndexAtY(Y: integer): integer;
begin
Result:=-1;
if (not HandleAllocated) then exit;
Result := TWSCustomListBoxClass(WidgetSetClass).GetIndexAtY(Self, Y);
Result := GetIndexAtXY(1, Y);
end;
{------------------------------------------------------------------------------
@ -671,12 +676,15 @@ end;
function TCustomListBox.ItemAtPos(const Pos: TPoint; Existing: Boolean
): Integer;
begin
Result:=GetIndexAtY(Pos.Y);
if Existing then begin
if Result>=Items.Count then Result:=-1;
end else begin
if (Result<0) and (Result>Items.Count) and PtInRect(ClientRect,Pos) then
Result:=Items.Count;
Result := GetIndexAtXY(Pos.X, Pos.Y);
if Existing then
begin
if Result >= Items.Count then
Result := -1;
end else
begin
if (Result < 0) and (Result > Items.Count) and PtInRect(ClientRect, Pos) then
Result := Items.Count;
end;
end;

View File

@ -107,7 +107,7 @@ type
protected
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetIndexAtY(const ACustomListBox: TCustomListBox; y: integer): integer; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
@ -538,18 +538,19 @@ begin
end;
{------------------------------------------------------------------------------
Method: TCarbonWSCustomListBox.GetIndexAtY
Method: TCarbonWSCustomListBox.GetIndexAtXY
Params: ACustomListBox - LCL custom list box
X - X coordinate
Y - Y coordinate
Returns: The list box item at the specified position or -1
------------------------------------------------------------------------------}
class function TCarbonWSCustomListBox.GetIndexAtY(
const ACustomListBox: TCustomListBox; y: integer): integer;
class function TCarbonWSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; X, Y: integer): integer;
begin
Result := -1;
if not CheckHandle(ACustomListBox, Self, 'GetIndexAtY') then Exit;
if not CheckHandle(ACustomListBox, Self, 'GetIndexAtXY') then Exit;
Result := TCarbonListBox(ACustomListBox.Handle).GetItemAt(0, Y);
Result := TCarbonListBox(ACustomListBox.Handle).GetItemAt(X, Y);
end;
{------------------------------------------------------------------------------

View File

@ -109,7 +109,7 @@ type
protected
public
{ class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetIndexAtY(const ACustomListBox: TCustomListBox; y: integer): integer; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;

View File

@ -124,7 +124,7 @@ type
public
{$IFDEF GTK1}
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetIndexAtY(const ACustomListBox: TCustomListBox; y: integer): integer; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
@ -487,8 +487,8 @@ begin
TGtkPrivateListClass(WSPrivate).SetCallbacks(Widget, WidgetInfo);
end;
class function TGtkWSCustomListBox.GetIndexAtY(
const ACustomListBox: TCustomListBox; y: integer): integer;
class function TGtkWSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; X, Y: integer): integer;
var
ScrolledWindow: PGtkScrolledWindow;
VertAdj: PGTKAdjustment;
@ -650,7 +650,7 @@ end;
class function TGtkWSCustomListBox.GetTopIndex(const ACustomListBox: TCustomListBox): integer;
begin
Result := GetIndexAtY(ACustomListBox, 0);
Result := GetIndexAtXY(ACustomListBox, 0, 0);
end;
class procedure TGtkWSCustomListBox.SelectItem(const ACustomListBox: TCustomListBox;

View File

@ -152,7 +152,7 @@ type
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetIndexAtY(const ACustomListBox: TCustomListBox; y: integer): integer; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
@ -419,7 +419,7 @@ end;
class function TGtk2WSCustomListBox.GetTopIndex(
const ACustomListBox: TCustomListBox): integer;
begin
Result := GetIndexAtY(ACustomListBox, 0);
Result := GetIndexAtXY(ACustomListBox, 0, 0);
end;
class procedure TGtk2WSCustomListBox.SelectItem(
@ -664,15 +664,15 @@ begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
end;
class function TGtk2WSCustomListBox.GetIndexAtY(
const ACustomListBox: TCustomListBox; y: integer): integer;
class function TGtk2WSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; X, Y: integer): integer;
var
aTreeView: PGtkTreeView;
aTreeColumn: PGtkTreeViewColumn;
aTreePath: PGtkTreePath;
begin
Result := -1;
if not WSCheckHandleAllocated(ACustomListBox, 'GetIndexAtY') then
if not WSCheckHandleAllocated(ACustomListBox, 'GetIndexAtXY') then
Exit;
case ACustomListBox.fCompStyle of
csListBox, csCheckListBox:

View File

@ -118,7 +118,7 @@ type
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
public
class function GetIndexAtY(const ACustomListBox: TCustomListBox; y: integer): integer; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
@ -417,12 +417,12 @@ begin
Result := TLCLIntfHandle(QtListWidget);
end;
class function TQtWSCustomListBox.GetIndexAtY(
const ACustomListBox: TCustomListBox; y: integer): integer;
class function TQtWSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; X, Y: integer): integer;
var
APoint: TQtPoint;
begin
APoint := QtPoint(1, y);
APoint := QtPoint(X, Y);
Result := TQtListWidget(ACustomListBox.Handle).indexAt(@APoint);
end;

View File

@ -130,7 +130,7 @@ type
var Left, Top, Width, Height: integer; var SuppressMove: boolean); override;
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class function GetIndexAtY(const ACustomListBox: TCustomListBox; y: integer): integer; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
@ -605,10 +605,10 @@ begin
Result := Params.Window;
end;
class function TWin32WSCustomListBox.GetIndexAtY(
const ACustomListBox: TCustomListBox; y: integer): integer;
class function TWin32WSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; X, Y: integer): integer;
begin
Result := Windows.SendMessage(ACustomListBox.Handle, LB_ITEMFROMPOINT, 0, MakeLParam(0,y));
Result := Windows.SendMessage(ACustomListBox.Handle, LB_ITEMFROMPOINT, 0, MakeLParam(X,Y));
if hi(Result)=0 then
Result := lo(Result)
else

View File

@ -117,7 +117,7 @@ type
public
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class function GetIndexAtY(const ACustomListBox: TCustomListBox; y: integer): integer; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
@ -465,10 +465,10 @@ begin
Result := Params.Window;
end;
class function TWinCEWSCustomListBox.GetIndexAtY(
const ACustomListBox: TCustomListBox; y: integer): integer;
class function TWinCEWSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; X, Y: integer): integer;
begin
Result := Windows.SendMessage(ACustomListBox.Handle, LB_ITEMFROMPOINT, 0, MakeLParam(0,y));
Result := Windows.SendMessage(ACustomListBox.Handle, LB_ITEMFROMPOINT, 0, MakeLParam(X,Y));
if hi(Result)=0 then
Result := lo(Result)
else

View File

@ -533,6 +533,7 @@ type
procedure Click; override; // make it public
procedure Clear; virtual;
procedure ClearSelection;
function GetIndexAtXY(X, Y: integer): integer;
function GetIndexAtY(Y: integer): integer;
function GetSelectedText: string;
function ItemAtPos(const Pos: TPoint; Existing: Boolean): Integer;

View File

@ -100,7 +100,7 @@ type
{ TWSCustomListBox }
TWSCustomListBox = class(TWSWinControl)
class function GetIndexAtY(const ACustomListBox: TCustomListBox; y: integer): integer; virtual;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; virtual;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; virtual;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; virtual;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; virtual;
@ -232,8 +232,8 @@ end;
{ TWSCustomListBox }
class function TWSCustomListBox.GetIndexAtY(
const ACustomListBox: TCustomListBox; y: integer): integer;
class function TWSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; X, Y: integer): integer;
begin
Result := -1;
end;