lcl: add TApplication.ActivateHint method for delphi compatibility

git-svn-id: trunk@27014 -
This commit is contained in:
paul 2010-08-05 02:17:37 +00:00
parent ba4c288654
commit 66c72d1b3e
2 changed files with 70 additions and 63 deletions

View File

@ -1292,6 +1292,7 @@ type
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure ActivateHint(CursorPos: TPoint; CheckHintControlChange: Boolean = False);
procedure ControlDestroyed(AControl: TControl); procedure ControlDestroyed(AControl: TControl);
function BigIconHandle: HIcon; function BigIconHandle: HIcon;
function SmallIconHandle: HIcon; function SmallIconHandle: HIcon;

View File

@ -46,33 +46,22 @@ begin
Result := nil; Result := nil;
end; end;
function GetHintInfoAtMouse: THintInfoAtMouse; function GetHintInfoAt(CursorPos: TPoint): THintInfoAtMouse;
begin begin
if Mouse <> nil then Result.MousePos := CursorPos;
Result.Control := GetHintControl(FindControlAtPosition(Result.MousePos, True));
Result.ControlHasHint := Assigned(Result.Control) and Assigned(Application) and
Application.ShowHint and (GetCapture = 0) and
((GetKeyState(VK_LBUTTON) and $80) = 0) and
((GetKeyState(VK_MBUTTON) and $80) = 0) and
((GetKeyState(VK_RBUTTON) and $80) = 0);
if Result.ControlHasHint then
begin begin
Result.MousePos := Mouse.CursorPos; // if there is a modal form, then don't show hints for other forms
Result.Control := GetHintControl(FindControlAtPosition(Result.MousePos, True)); if Assigned(Screen.FFocusedForm) and
Result.ControlHasHint:= (fsModal in Screen.FFocusedForm.FormState) and
(Result.Control <> nil) (GetParentForm(Result.Control) <> Screen.FFocusedForm) then
and (Application <> nil) and (Application.ShowHint) Result.ControlHasHint := False;
and (GetCapture = 0)
and ((GetKeyState(VK_LBUTTON) and $80) = 0)
and ((GetKeyState(VK_MBUTTON) and $80) = 0)
and ((GetKeyState(VK_RBUTTON) and $80) = 0);
if Result.ControlHasHint then
begin
// if there is a modal form, then don't show hints for other forms
if (Screen.FFocusedForm<>nil)
and (fsModal in Screen.FFocusedForm.FormState)
and (GetParentForm(Result.Control) <> Screen.FFocusedForm)
then
Result.ControlHasHint := False;
end;
end else
begin
Result.MousePos := Point(0, 0);
Result.Control := nil;
Result.ControlHasHint := False;
end; end;
end; end;
@ -183,6 +172,47 @@ begin
OnGetApplicationName := nil; OnGetApplicationName := nil;
end; end;
procedure TApplication.ActivateHint(CursorPos: TPoint;
CheckHintControlChange: Boolean);
var
Info: THintInfoAtMouse;
HintControlChanged: Boolean;
begin
Info := GetHintInfoAt(CursorPos);
{$ifdef DebugHintWindow}
DebugLn('TApplication.DoOnMouseMove Info.ControlHasHint=',dbgs(Info.ControlHasHint),' Type=',dbgs(ord(FHintTimerType)),' FHintControl=',DbgSName(FHintControl),' Info.Control=',DbgSName(Info.Control));
{$endif}
HintControlChanged := not CheckHintControlChange or (FHintControl <> Info.Control);
if Info.ControlHasHint then
begin
if HintControlChanged then
begin
StopHintTimer;
HideHint;
FHintControl := Info.Control;
FHintRect := FHintControl.BoundsRect;
end;
case FHintTimerType of
ahttNone, ahttHideHint:
//react only if the hint control changed or if the mouse leave the previously set hint rect
if HintControlChanged or (not PtInRect(FHintRect, FHintControl.ScreenToClient(Info.MousePos))) then
begin
//if a hint is visible immediately query the app to show a new hint...
if FHintTimerType = ahttHideHint then
ShowHintWindow(Info);
//...if there's no hint window visible at this point than schedule a new query
if (FHintTimerType = ahttNone) or (FHintWindow = nil) or not FHintWindow.Visible then
StartHintTimer(HintPause, ahttShowHint);
end;
ahttShowHint:
StartHintTimer(HintPause, ahttShowHint);
end;
end
else
CancelHint;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TApplication BringToFront TApplication BringToFront
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -693,42 +723,12 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TApplication.DoOnMouseMove; procedure TApplication.DoOnMouseMove;
var var
Info: THintInfoAtMouse; CursorPos: TPoint;
HintControlChanged: Boolean;
begin begin
Info := GetHintInfoAtMouse; if not GetCursorPos(CursorPos) then
Exit;
{$ifdef DebugHintWindow} ActivateHint(CursorPos, True);
DebugLn('TApplication.DoOnMouseMove Info.ControlHasHint=',dbgs(Info.ControlHasHint),' Type=',dbgs(ord(FHintTimerType)),' FHintControl=',DbgSName(FHintControl),' Info.Control=',DbgSName(Info.Control));
{$endif}
HintControlChanged := FHintControl <> Info.Control;
if Info.ControlHasHint then
begin
if HintControlChanged then
begin
StopHintTimer;
HideHint;
FHintControl := Info.Control;
FHintRect := FHintControl.BoundsRect;
end;
case FHintTimerType of
ahttNone, ahttHideHint:
//react only if the hint control changed or if the mouse leave the previously set hint rect
if HintControlChanged or (not PtInRect(FHintRect, FHintControl.ScreenToClient(Info.MousePos))) then
begin
//if a hint is visible immediately query the app to show a new hint...
if FHintTimerType = ahttHideHint then
ShowHintWindow(Info);
//...if there's no hint window visible at this point than schedule a new query
if (FHintTimerType = ahttNone) or (FHintWindow = nil) or not FHintWindow.Visible then
StartHintTimer(HintPause, ahttShowHint);
end;
ahttShowHint:
StartHintTimer(HintPause, ahttShowHint);
end;
end
else
CancelHint;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -882,6 +882,7 @@ end;
procedure TApplication.OnHintTimer(Sender: TObject); procedure TApplication.OnHintTimer(Sender: TObject);
var var
Info: THintInfoAtMouse; Info: THintInfoAtMouse;
CursorPos: TPoint;
begin begin
{$ifdef DebugHintWindow} {$ifdef DebugHintWindow}
DebugLn('TApplication.OnHintTimer Type=', IntToStr(ord(FHintTimerType))); DebugLn('TApplication.OnHintTimer Type=', IntToStr(ord(FHintTimerType)));
@ -890,11 +891,16 @@ begin
case FHintTimerType of case FHintTimerType of
ahttShowHint: ahttShowHint:
begin begin
Info := GetHintInfoAtMouse; if not GetCursorPos(CursorPos) then
if Info.ControlHasHint then HideHint
ShowHintWindow(Info)
else else
HideHint; begin
Info := GetHintInfoAt(CursorPos);
if Info.ControlHasHint then
ShowHintWindow(Info)
else
HideHint;
end;
end; end;
ahttHideHint: ahttHideHint:
begin begin