LCL: hintwindow: add parameter to shrink window size on OffsetRect.

git-svn-id: trunk@55141 -
This commit is contained in:
ondrej 2017-06-01 11:40:50 +00:00
parent db4c7d76eb
commit cd76f09f06
2 changed files with 18 additions and 10 deletions

View File

@ -880,7 +880,8 @@ type
FAutoHide: Boolean;
FAutoHideTimer: TCustomTimer;
FHideInterval: Integer;
procedure AdjustBoundsForMonitor;
procedure AdjustBoundsForMonitor(KeepWidth: Boolean = True;
KeepHeight: Boolean = True);
function GetDrawTextFlags: Cardinal;
procedure SetAutoHide(Value : Boolean);
procedure AutoHideHint(Sender : TObject);
@ -911,7 +912,8 @@ type
AData: pointer); virtual;
function CalcHintRect(MaxWidth: Integer; const AHint: String;
AData: pointer): TRect; virtual;
function OffsetHintRect(NewPos: TPoint; dy: Integer = 15): Boolean;
function OffsetHintRect(NewPos: TPoint; dy: Integer = 15;
KeepWidth: Boolean = True; KeepHeight: Boolean = True): Boolean;
procedure InitializeWnd; override;
function IsHintMsg(Msg: TMsg): Boolean; virtual;
procedure ReleaseHandle;

View File

@ -311,42 +311,48 @@ begin
//debugln('THintWindow.CalcHintRect Result=',dbgs(Result));
end;
procedure THintWindow.AdjustBoundsForMonitor;
procedure THintWindow.AdjustBoundsForMonitor(KeepWidth: Boolean;
KeepHeight: Boolean);
var
AMonitor: TMonitor;
ABounds: TRect;
begin
AMonitor := Screen.MonitorFromPoint(FHintRect.TopLeft);
ABounds := AMonitor.BoundsRect;
ABounds := AMonitor.WorkareaRect;
// offset hint to fit into monitor
if FHintRect.Bottom > ABounds.Bottom then
begin
FHintRect.Top := ABounds.Bottom - (FHintRect.Bottom - FHintRect.Top);
if KeepHeight then
FHintRect.Top := ABounds.Bottom - (FHintRect.Bottom - FHintRect.Top);
FHintRect.Bottom := ABounds.Bottom;
end;
if FHintRect.Top < ABounds.Top then
begin
FHintRect.Bottom := Min(ABounds.Top + (FHintRect.Bottom - FHintRect.Top), ABounds.Bottom);
if KeepHeight then
FHintRect.Bottom := Min(ABounds.Top + (FHintRect.Bottom - FHintRect.Top), ABounds.Bottom);
FHintRect.Top := ABounds.Top;
end;
if FHintRect.Right > ABounds.Right then
begin
FHintRect.Left := ABounds.Right - (FHintRect.Right - FHintRect.Left);
if KeepWidth then
FHintRect.Left := ABounds.Right - (FHintRect.Right - FHintRect.Left);
FHintRect.Right := ABounds.Right;
end;
if FHintRect.Left < ABounds.Left then
begin
FHintRect.Right:= Min(ABounds.Left + (FHintRect.Right - FHintRect.Left), ABounds.Right);
if KeepWidth then
FHintRect.Right:= Min(ABounds.Left + (FHintRect.Right - FHintRect.Left), ABounds.Right);
FHintRect.Left := ABounds.Left;
end;
end;
function THintWindow.OffsetHintRect(NewPos: TPoint; dy: Integer): Boolean;
function THintWindow.OffsetHintRect(NewPos: TPoint; dy: Integer;
KeepWidth: Boolean; KeepHeight: Boolean): Boolean;
begin
Result:=OffsetRect(FHintRect, NewPos.X, NewPos.Y + dy);
AdjustBoundsForMonitor;
AdjustBoundsForMonitor(KeepWidth, KeepHeight);
end;
procedure THintWindow.InitializeWnd;