LCL: TTabControl: make mouse messages working in tabs. Issue #27467

git-svn-id: branches/fixes_1_6@54007 -
This commit is contained in:
michl 2017-01-26 07:30:44 +00:00
parent dabd63aa99
commit d9b419c78b
4 changed files with 133 additions and 56 deletions

View File

@ -437,6 +437,10 @@ type
function DialogChar(var Message: TLMKey): boolean; override;
procedure InternalSetPageIndex(AValue: Integer); // No OnChange
procedure ShowControl(APage: TControl); override;
function IndexOfTabAt(X, Y: Integer): Integer; virtual; overload;
function IndexOfTabAt(P: TPoint): Integer; virtual; overload;
function IndexOfPageAt(X, Y: Integer): Integer; virtual; overload;
function IndexOfPageAt(P: TPoint): Integer; virtual; overload;
procedure UpdateTabProperties; virtual;
class function GetControlClassDefaultSize: TSize; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
@ -479,10 +483,6 @@ type
function GetCapabilities: TNoteBookCapabilities; virtual;
function TabToPageIndex(AIndex: integer): integer;
function PageToTabIndex(AIndex: integer): integer;
function IndexOfTabAt(X, Y: Integer): Integer; overload;
function IndexOfTabAt(P: TPoint): Integer; overload;
function IndexOfPageAt(X, Y: Integer): Integer; overload;
function IndexOfPageAt(P: TPoint): Integer; overload;
public
procedure DoCloseTabClicked(APage: TCustomPage); virtual;
property Images: TCustomImageList read FImages write SetImages;
@ -587,6 +587,10 @@ type
GoForward, CheckTabVisible: Boolean): TTabSheet;
procedure SelectNextPage(GoForward: Boolean);
procedure SelectNextPage(GoForward: Boolean; CheckTabVisible: Boolean);
function IndexOfTabAt(X, Y: Integer): Integer; override;
function IndexOfTabAt(P: TPoint): Integer; override;
function IndexOfPageAt(X, Y: Integer): Integer; override;
function IndexOfPageAt(P: TPoint): Integer; override;
function AddTabSheet: TTabSheet;
property ActivePageIndex: Integer read GetActivePageIndex
write SetActivePageIndex;
@ -720,6 +724,11 @@ type
protected
FHandelCreated: TNotifyEvent;
procedure CreateHandle; override;
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
procedure MouseEnter; override;
procedure MouseLeave; override;
class procedure WSRegisterClass; override;
end;
TNoteBookStringsTabControlClass = class of TNoteBookStringsTabControl;
@ -825,7 +834,8 @@ type
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function IndexOfTabAt(X, Y: Integer): Integer;
function IndexOfTabAt(X, Y: Integer): Integer; override;
function IndexOfTabAt(P: TPoint): Integer; override;
function GetHitTestInfoAt(X, Y: Integer): THitTests;
function GetImageIndex(ATabIndex: Integer): Integer; override;
function IndexOfTabWithCaption(const TabCaption: string): Integer;

View File

@ -439,57 +439,6 @@ begin
end;
end;
{------------------------------------------------------------------------------
function TCustomTabControl.IndexOfTabAt(X, Y: Integer): Integer;
Returns the index of the visible tab at the client position.
------------------------------------------------------------------------------}
function TCustomTabControl.IndexOfTabAt(X, Y: Integer): Integer;
begin
Result := IndexOfTabAt(Point(X, Y));
end;
{------------------------------------------------------------------------------
function TCustomTabControl.IndexOfTabAt(P: TPoint): Integer;
Returns the index of the visible tab at the client position.
For example:
Index:=NoteBook1.IndexOfTabAt(
NoteBook1.ScreenToClient(Mouse.CursorPos));
------------------------------------------------------------------------------}
function TCustomTabControl.IndexOfTabAt(P: TPoint): Integer;
begin
if HandleAllocated then
Result := TWSCustomTabControlClass(WidgetSetClass).GetTabIndexAtPos(Self, P)
else
Result := -1;
end;
{------------------------------------------------------------------------------
function TCustomTabControl.IndexOfPageAt(X, Y: Integer): Integer;
Returns the index of the page at the client position.
------------------------------------------------------------------------------}
function TCustomTabControl.IndexOfPageAt(X, Y: Integer): Integer;
begin
Result := IndexOfPageAt(Point(X, Y));
end;
{------------------------------------------------------------------------------
function TCustomTabControl.IndexOfPageAt(X, Y: Integer): Integer;
Returns the index of the page at the client position.
For example:
Index:=NoteBook1.IndexOfPageAt(
NoteBook1.ScreenToClient(Mouse.CursorPos));
------------------------------------------------------------------------------}
function TCustomTabControl.IndexOfPageAt(P: TPoint): Integer;
begin
Result := IndexOfTabAt(P);
if Result <> -1 then
Result := TabToPageIndex(Result);
end;
function TCustomTabControl.TabToPageIndex(AIndex: integer): integer;
var
I: integer;
@ -962,6 +911,57 @@ begin
inherited ShowControl(APage);
end;
{------------------------------------------------------------------------------
function TCustomTabControl.IndexOfTabAt(X, Y: Integer): Integer;
Returns the index of the visible tab at the client position.
------------------------------------------------------------------------------}
function TCustomTabControl.IndexOfTabAt(X, Y: Integer): Integer;
begin
Result := IndexOfTabAt(Point(X, Y));
end;
{------------------------------------------------------------------------------
function TCustomTabControl.IndexOfTabAt(P: TPoint): Integer;
Returns the index of the visible tab at the client position.
For example:
Index:=NoteBook1.IndexOfTabAt(
NoteBook1.ScreenToClient(Mouse.CursorPos));
------------------------------------------------------------------------------}
function TCustomTabControl.IndexOfTabAt(P: TPoint): Integer;
begin
if HandleAllocated then
Result := TWSCustomTabControlClass(WidgetSetClass).GetTabIndexAtPos(Self, P)
else
Result := -1;
end;
{------------------------------------------------------------------------------
function TCustomTabControl.IndexOfPageAt(X, Y: Integer): Integer;
Returns the index of the page at the client position.
------------------------------------------------------------------------------}
function TCustomTabControl.IndexOfPageAt(X, Y: Integer): Integer;
begin
Result := IndexOfPageAt(Point(X, Y));
end;
{------------------------------------------------------------------------------
function TCustomTabControl.IndexOfPageAt(X, Y: Integer): Integer;
Returns the index of the page at the client position.
For example:
Index:=NoteBook1.IndexOfPageAt(
NoteBook1.ScreenToClient(Mouse.CursorPos));
------------------------------------------------------------------------------}
function TCustomTabControl.IndexOfPageAt(P: TPoint): Integer;
begin
Result := IndexOfTabAt(P);
if Result <> -1 then
Result := TabToPageIndex(Result);
end;
{------------------------------------------------------------------------------
method TCustomTabControl UpdateTabProperties
Params: none

View File

@ -165,6 +165,26 @@ begin
if NextPage<>nil then ActivePage:=NextPage;
end;
function TPageControl.IndexOfTabAt(X, Y: Integer): Integer;
begin
Result:=inherited IndexOfTabAt(X, Y);
end;
function TPageControl.IndexOfTabAt(P: TPoint): Integer;
begin
Result:=inherited IndexOfTabAt(P);
end;
function TPageControl.IndexOfPageAt(X, Y: Integer): Integer;
begin
Result:=inherited IndexOfPageAt(X, Y);
end;
function TPageControl.IndexOfPageAt(P: TPoint): Integer;
begin
Result:=inherited IndexOfPageAt(P);
end;
// Convenience routine, to make the TPageControl more intuitive to use
// A Lazarus addition
function TPageControl.AddTabSheet: TTabSheet;

View File

@ -148,6 +148,48 @@ begin
FHandelCreated(self);
end;
procedure TNoteBookStringsTabControl.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if Assigned(Parent) and (Parent is TTabControl)
and Assigned(TTabControl(Parent).OnMouseDown) then
TTabControl(Parent).OnMouseDown(Parent, Button, Shift, X, Y);
end;
procedure TNoteBookStringsTabControl.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited MouseMove(Shift, X, Y);
if Assigned(Parent) and (Parent is TTabControl)
and Assigned(TTabControl(Parent).OnMouseMove) then
TTabControl(Parent).OnMouseMove(Parent, Shift, X, Y);
end;
procedure TNoteBookStringsTabControl.MouseUp(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, Y);
if Assigned(Parent) and (Parent is TTabControl)
and Assigned(TTabControl(Parent).OnMouseUp) then
TTabControl(Parent).OnMouseUp(Parent, Button, Shift, X, Y);
end;
procedure TNoteBookStringsTabControl.MouseEnter;
begin
inherited MouseEnter;
if Assigned(Parent) and (Parent is TTabControl)
and Assigned(TTabControl(Parent).OnMouseEnter) then
TTabControl(Parent).OnMouseEnter(Parent);
end;
procedure TNoteBookStringsTabControl.MouseLeave;
begin
inherited MouseLeave;
if Assigned(Parent) and (Parent is TTabControl)
and Assigned(TTabControl(Parent).OnMouseLeave) then
TTabControl(Parent).OnMouseLeave(Parent);
end;
class procedure TNoteBookStringsTabControl.WSRegisterClass;
begin
inherited WSRegisterClass;
@ -725,6 +767,11 @@ begin
Result:=TTabControlStrings(FTabs).IndexOfTabAt(X,Y);
end;
function TTabControl.IndexOfTabAt(P: TPoint): Integer;
begin
Result:=TTabControlStrings(FTabs).IndexOfTabAt(P.x, P.y);
end;
function TTabControl.GetHitTestInfoAt(X, Y: Integer): THitTests;
begin
Result:=TTabControlStrings(FTabs).GetHitTestInfoAt(X,Y);