EditBtn: fix keeping TimePopup form in view (a.o. take Taskbar into account). Patch by wp (minor modification by me). Issue #0029949.

git-svn-id: trunk@52106 -
This commit is contained in:
bart 2016-04-05 15:22:14 +00:00
parent 2eb6e52660
commit b4316ad202
3 changed files with 36 additions and 10 deletions

View File

@ -2092,7 +2092,8 @@ begin
ATime := GetTime;
if ATime = NullDate then
ATime := SysUtils.Time;
ShowTimePopup(PopupOrigin, ATime, Self.DoubleBuffered, @TimePopupReturnTime, @TimePopupShowHide, FSimpleLayout);
ShowTimePopup(PopupOrigin, ATime, Self.DoubleBuffered,
@TimePopupReturnTime, @TimePopupShowHide, FSimpleLayout, self);
end;
function TTimeEdit.TryParseInput(AInput: String; out ParseResult: TDateTime): Boolean;

View File

@ -13,7 +13,7 @@ object TimePopupForm: TTimePopupForm
OnCreate = FormCreate
OnDeactivate = FormDeactivate
PopupMode = pmAuto
LCLVersion = '1.5'
LCLVersion = '1.7'
object MainPanel: TPanel
Left = 0
Height = 185

View File

@ -41,6 +41,7 @@ type
FOnReturnTime: TReturnTimeEvent;
FSimpleLayout: Boolean;
FPopupOrigin: TPoint;
FCaller: TControl;
procedure ActivateDoubleBuffered;
procedure CalcGridHeights;
function GetTime: TDateTime;
@ -56,18 +57,22 @@ type
end;
procedure ShowTimePopup(const Position: TPoint; ATime: TDateTime; const DoubleBufferedForm: Boolean;
const OnReturnTime: TReturnTimeEvent; const OnShowHide: TNotifyEvent = nil; SimpleLayout: Boolean = True);
const OnReturnTime: TReturnTimeEvent; const OnShowHide: TNotifyEvent = nil;
SimpleLayout: Boolean = True; ACaller: TControl = nil);
implementation
{$R *.lfm}
procedure ShowTimePopup(const Position: TPoint; ATime: TDateTime; const DoubleBufferedForm: Boolean; const OnReturnTime: TReturnTimeEvent;
const OnShowHide: TNotifyEvent; SimpleLayout: Boolean);
procedure ShowTimePopup(const Position: TPoint; ATime: TDateTime; const DoubleBufferedForm: Boolean;
const OnReturnTime: TReturnTimeEvent; const OnShowHide: TNotifyEvent;
SimpleLayout: Boolean; ACaller: TControl);
var
NewForm: TTimePopupForm;
P: TPoint;
begin
NewForm := TTimePopupForm.Create(nil);
NewForm.FCaller := ACaller;
NewForm.Initialize(Position, ATime);
NewForm.FOnReturnTime := OnReturnTime;
NewForm.OnShow := OnShowHide;
@ -78,7 +83,11 @@ begin
if not SimpleLayout then
NewForm.SetTime(ATime); //update the row and col in the grid;
NewForm.Show;
NewForm.KeepInView(Position);
if Assigned(ACaller) then
P := ACaller.ControlToScreen(Point(0, ACaller.Height))
else
P := Position;
NewForm.KeepInView(P);
end;
procedure TTimePopupForm.SetTime(ATime: TDateTime);
@ -89,6 +98,7 @@ begin
Minute := MinuteOf(ATime);
HoursGrid.Col := Hour mod 12;
HoursGrid.Row := Hour div 12;
HoursGrid.TopRow := 0; // Avoid morning hours scrolling out of view if time is > 12:00
if FSimpleLayout then
begin
Minute := Minute - (Minute mod 5);
@ -255,21 +265,36 @@ begin
SetTime(ATime);
end;
{
Try to put the form on a "nice" place on the screen and make sure the entire form is visible.
Caller typically wil be a TTimeEdit
- first try to place it right under Caller, if that does not fit
- try to fit it just above Caller, if that also does not fit (Top < 0) then
- simply set Top to zero (in which case it will partially cover Caller
}
procedure TTimePopupForm.KeepInView(const PopupOrigin: TPoint);
var
ABounds: TRect;
begin
ABounds := Screen.MonitorFromPoint(PopupOrigin).BoundsRect;
ABounds := Screen.MonitorFromPoint(PopupOrigin).WorkAreaRect; // take care of taskbar
if PopupOrigin.X + Width > ABounds.Right then
Left := ABounds.Right - Width
else if PopupOrigin.X < ABounds.Left then
Left := ABounds.Left
else
Left := PopupOrigin.X;
if PopupOrigin.Y + Height > ABounds.Bottom then
Top := ABounds.Bottom - Height
begin
if Assigned(FCaller) then
Top := PopupOrigin.Y - FCaller.Height - Height
else
Top := ABounds.Bottom - Height;
end else if PopupOrigin.Y < ABounds.Top then
Top := ABounds.Top
else
Top := PopupOrigin.Y;
//store the fitting point, so the form won't move if it layout is changed back to simple
FPopupOrigin := Point(Left, Top);
if Left < ABounds.Left then Left := 0;
if Top < ABounds.Top then Top := 0;
end;
procedure TTimePopupForm.ReturnTime;