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; 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; function TCustomListBox.GetIndexAtY(Y: integer): integer;
begin begin
Result:=-1; Result := GetIndexAtXY(1, Y);
if (not HandleAllocated) then exit;
Result := TWSCustomListBoxClass(WidgetSetClass).GetIndexAtY(Self, Y);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -671,12 +676,15 @@ end;
function TCustomListBox.ItemAtPos(const Pos: TPoint; Existing: Boolean function TCustomListBox.ItemAtPos(const Pos: TPoint; Existing: Boolean
): Integer; ): Integer;
begin begin
Result:=GetIndexAtY(Pos.Y); Result := GetIndexAtXY(Pos.X, Pos.Y);
if Existing then begin if Existing then
if Result>=Items.Count then Result:=-1; begin
end else begin if Result >= Items.Count then
if (Result<0) and (Result>Items.Count) and PtInRect(ClientRect,Pos) then Result := -1;
Result:=Items.Count; end else
begin
if (Result < 0) and (Result > Items.Count) and PtInRect(ClientRect, Pos) then
Result := Items.Count;
end; end;
end; end;

View File

@ -107,7 +107,7 @@ type
protected protected
public public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; 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 GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override; class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override; class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
@ -538,18 +538,19 @@ begin
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCarbonWSCustomListBox.GetIndexAtY Method: TCarbonWSCustomListBox.GetIndexAtXY
Params: ACustomListBox - LCL custom list box Params: ACustomListBox - LCL custom list box
X - X coordinate
Y - Y coordinate Y - Y coordinate
Returns: The list box item at the specified position or -1 Returns: The list box item at the specified position or -1
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
class function TCarbonWSCustomListBox.GetIndexAtY( class function TCarbonWSCustomListBox.GetIndexAtXY(
const ACustomListBox: TCustomListBox; y: integer): integer; const ACustomListBox: TCustomListBox; X, Y: integer): integer;
begin begin
Result := -1; 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; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -109,7 +109,7 @@ type
protected protected
public public
{ class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; { 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 GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override; class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override; class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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