summaryrefslogtreecommitdiff
path: root/src/gui/fpg_popupcalendar.pas
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-06-29 15:08:19 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-06-29 15:08:19 +0200
commitc7feadee67f8cf803e2736470ecc416686be7130 (patch)
tree4fee5118d159478a99de2a76e324962cf5746c62 /src/gui/fpg_popupcalendar.pas
parent371c968f98929960e36d98df5ec41621ff6eb4b1 (diff)
downloadfpGUI-c7feadee67f8cf803e2736470ecc416686be7130.tar.xz
Calendar Combo: Correctly position Month popup menu.
If there isn't space at the bottom of the Month Edit, then place the Month popup menu above the Month Edit. We had to introduce a friend class, to get access to the protected PrepareToShow method.
Diffstat (limited to 'src/gui/fpg_popupcalendar.pas')
-rw-r--r--src/gui/fpg_popupcalendar.pas17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/gui/fpg_popupcalendar.pas b/src/gui/fpg_popupcalendar.pas
index 736c41ae..af27568b 100644
--- a/src/gui/fpg_popupcalendar.pas
+++ b/src/gui/fpg_popupcalendar.pas
@@ -282,6 +282,10 @@ uses
fpg_scrollbar,
fpg_constants;
+type
+ // friend class to get access to Protected methods
+ TPopupMenuFriend = class(TfpgPopupMenu);
+
{@VFD_NEWFORM_IMPL}
@@ -643,9 +647,9 @@ begin
begin
FYearPopupWindow := TYearSelectForm.CreateCustom(nil, YearOf(MinDate), YearOf(MaxDate));
FYearPopupWindow.OnClose := @YearPopupWindowClose;
-// FYearPopupWindow.DontCloseWidget := self; // now we can control when the popup window closes
FYearPopupWindow.Year := Year;
end;
+
FYearPopupWindow.ShowAt(self, edtYear.Left, edtYear.Bottom);
end;
@@ -1067,11 +1071,11 @@ end;
procedure TfpgPopupCalendar.ShowDefaultPopupMenu;
var
itm: TfpgMenuItem;
+ pt: TPoint;
begin
if not Assigned(FMonthsPopupMenu) then
begin
FMonthsPopupMenu := TfpgPopupMenu.Create(nil);
-// FMonthsPopupMenu.DontCloseWidget := self; // now we can control when the popup window closes
itm := FMonthsPopupMenu.AddMenuItem(rslongjan, '', @miMonthClicked);
itm.Tag := 1;
itm := FMonthsPopupMenu.AddMenuItem(rslongfeb, '', @miMonthClicked);
@@ -1098,8 +1102,15 @@ begin
itm.Tag := 12;
end;
+ // translate Edit coordinates
+ pt := WindowToScreen(self, Point(edtMonth.Left, edtMonth.Bottom));
+ TPopupMenuFriend(FMonthsPopupMenu).PrepareToShow; // forces height calculation
+ // If dropdown will not fit below Edit, then we place it above
+ if (pt.y + FMonthsPopupMenu.Height) > fpgApplication.ScreenHeight then
+ pt.y := pt.y - edtMonth.Height - FMonthsPopupMenu.Height;
+
// SetDefaultPopupMenuItemsState;
- FMonthsPopupMenu.ShowAt(self, edtMonth.Left, edtMonth.Bottom);
+ FMonthsPopupMenu.ShowAt(nil, pt.x, pt.y);
end;
constructor TfpgPopupCalendar.Create(AOwner: TComponent; AOrigFocusWin: TfpgWidget);