From d9b419c78b89e89747aa93848c78a2913c02b9e3 Mon Sep 17 00:00:00 2001 From: michl Date: Thu, 26 Jan 2017 07:30:44 +0000 Subject: [PATCH] LCL: TTabControl: make mouse messages working in tabs. Issue #27467 git-svn-id: branches/fixes_1_6@54007 - --- lcl/comctrls.pp | 20 +++++-- lcl/include/customnotebook.inc | 102 ++++++++++++++++----------------- lcl/include/pagecontrol.inc | 20 +++++++ lcl/include/tabcontrol.inc | 47 +++++++++++++++ 4 files changed, 133 insertions(+), 56 deletions(-) diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index 310bf124f7..9e839ffbb4 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -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; diff --git a/lcl/include/customnotebook.inc b/lcl/include/customnotebook.inc index 38443f4491..9b0f785767 100644 --- a/lcl/include/customnotebook.inc +++ b/lcl/include/customnotebook.inc @@ -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 diff --git a/lcl/include/pagecontrol.inc b/lcl/include/pagecontrol.inc index e0e70b705f..fdfd775915 100644 --- a/lcl/include/pagecontrol.inc +++ b/lcl/include/pagecontrol.inc @@ -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; diff --git a/lcl/include/tabcontrol.inc b/lcl/include/tabcontrol.inc index d1fab5df6a..803ee7d2fd 100644 --- a/lcl/include/tabcontrol.inc +++ b/lcl/include/tabcontrol.inc @@ -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);