Implements a pop-up form with a TCalendar control for TDateEdit.

calendarpopup.pas implements a non-modal calendar popup for a TDateEdit control. It includes a ShowCalendarPopup routine to configure, display, and capture the return value for the pop-up form.

Original Author: Vincent Snijders.

calendarpopup.pas is part of the LCL (Lazarus Component Library).

Specifies an event handler signalled when a date is selected on a pop-up calendar form.

TReturnDateEvent specifies an event handler signalled when a date is selected on a pop-up calendar form. TReturnDateEvent is the type used to implement the OnReturnDate event handler in TCalendarPopupForm. Applications must implement an object procedure used to respond to the event notification. It is passed as an argument to the ShowCalendarPopup routine.

Object for the event notification; normally the pop-up calendar form. TDateTime value for the date selected on the calendar form. Implements a non-modal pop-up form used to select a date from a TCalendar control.

TCalendarPopupForm is a TForm descendant which implements a non-modal pop-up form used to select a date with a TCalendar control. It includes the OnReturnDate event handler to perform the actions needed when a date is selected using the Calendar control.

TCalendarPopupForm is used as the non-modal dialog executed when the Button for the TDateEdit control is clicked.

Use the ShowCalendarPopup routine to create, configure, and display a pop-up calendar form.

TDateEdit
TCalendar control used to select a date on the form.

Calendar is a TCalendar member which contains the calendar control displayed on the form. It allows selection of a date, and calls the ReturnDate method when the Month, Day, or Year in the control is changed using either the mouse or the keyboard. Calendar is configured in the private Initialize method using the TDateTime and TDisplaySettings provided as arguments.

Use the ShowCalendarPopup routine to provide the date/time value, display settings, and date range needed in the pop-up calendar form.

Performs actions needed when a double click mouse event occurs in the Calendar control.

CalendarDblClick ensures that the mouse event is within the bounds for the Calendar control by calling its HitTest method. When the mouse event occurs on the Month or Year calendar parts, the ReturnDate method is called to signal the OnReturnDate event handler and close the form.

TCustomCalendar.HitTest TCalendarPart
Object for the event notification. Implements the OnKeyDown event handler for the Calendar control.

CalendarKeyDown is a procedure which implements the OnKeyDown event handler for the Calendar control. The method ensures that the key down virtual key code represented by Key and Shift is applied to the Calendar control, and includes:

VK_RETURN, VK_SPACE
Calls ReturnDate to apply the selected date value in Month view, and signals the OnReturnDate event handler.
VK_ESCAPE
Calls Close to close the form.

If the virtual key code is handled in the method, the value in Key is set to zero (0). Otherwise, it is retained for use in event handlers at the Form or Application level.

TCustomForm.Close
Object for the event notification; the Calendar control in this case. Virtual key code examined in the method. Virtual key modifier examined in the method. Implements the OnClose event handler for the form.

Ensures that the FormDeactivate method is removed from the registered OnDeactivate handlers in Application. The value in CloseAction is set to caFree in the method.

Object for the event notification. Close action to perform on exit from the event handler. Implements the OnCreate event handler for the form. Object for the event notification. Implements the OnDeactivate event handler for the form.

Ensures that the FormDeactivate method is added to the OnDeactivate handlers in Application.

Object for the event notification. Configures the Calendar control in the pop-up form.

Initialize is a method which configures the calendar control displayed on the form using the values passed in the arguments to the method.

ADateTime contains the initial TDateTime value for the calendar, and is stored in the DateTime property in Calendar.

DisplaySettings contains the set of display options enabled for the calendar, and is stored in the DisplaySettings property in Calendar.

AMinDate and AMaxDate indicate the range of dates that can be displayed or selected using the calendar, and is stored in the corresponding properties in Calendar. The Calendar uses the values to limit its DateTime selection to a required range of values. The values also prevent an exception raised when a TDateTime value is not supported on the native Calendar control.

Initialize is called when the ShowCalendarPopup routine creates, configures, and executes the pop-up calendar dialog.

Modified in LCL version 3.0 to include minimum and maximum date arguments. TCalendar.DateTime TCalendar.DisplaySettings TCalendar.MinDate TCalendar.MaxDate
Date value assigned to the Calendar control. Display settings applied to the Calendar control. Minimum date value allowed on the calendar. Maximum date value allowed on the calendar. Ensures that the form and the calling control are visible on the current monitor. Coordinates where the pop-up form is displayed. Signals the OnReturnDate event handler using the DateTime value in the Calendar control.

The TReturnDateEvent routine signalled in the method is provided when the ShowCalendarPopup routine is called. It is implemented as an object procedure in the control which displays the calendar pop-up form. For example: TDateEdit; it includes private methods used for the OnReturnDate and OnShowHide arguments passed to ShowCalendarPopup.

Calls Close to close the form if it has not already been executed.

Creates, configures, and displays a TCalendarPopupForm instance.

ShowCalendarPopup is an overloaded procedure used to create, configure, and display a TCalendarPopupForm instance using the arguments passed to the routine. The argument values are stored to the TCalendar instance on the dialog form by calling the Initialize method.

ShowCalendarPopup calls the Show method in the form to make it visible. The KeepInView method in the form is called to ensure that the pop-up is fully visible on the current monitor.

ShowCalendarPopup is called from the ButtonClick method in TDateEdit. The caller sets the argument values, including the date range in AMinDate and AMaxDate, to the defaults needed for the control. AMinDate is set to the date value for September 14, 1752 (the start of the Gregorian calendar in England). AMaxDate is set to the date portion of the MaxDateTime constant in the RTL (December 31, 9999). When omitted, an empty TDateTime value (0.0) is used in the arguments and does not impose a date range for the calendar pop-up.

Modified in LCL version 3.0 to include an overloaded variant with minimum and maximum date arguments. TDisplaySettings TDateEdit.ButtonClick
Coordinates where the pop-up calendar form is displayed. Initial date displayed in the Calendar for the form. Display settings applied to the Calendar control. Minimum date value that can be displayed or selected using the Calendar on the dialog, or an empty value (0.0) when omitted. Minimum date value that can be displayed or selected using the Calendar on the dialog, or an empty value (0.0) when omitted. Event handler signalled when a new date value is selected. Event handler signalled when the pop-up form is shown or hidden. The control which creates the pop-up and captures its return value.