Contains forms, types, and routines used to display a pop-up for TTimeEdit.

timepopup.pas contains the TTimePopupForm form and the ShowTimePopup routine used to create, configure, and display the pop-up form.

Author: Michael Fuchs

Specifies an event handler signalled to get a time return value.

TReturnTimeEvent specifies an event handler signalled to validate or assign a time value. It is an object procedure which must be implemented in an application to respond to the event notification.

Sender is the object generating the event notification.

ATime is a TDateTime value which contains the time value used in the event handler. Only the time portion of the type is significant.

TReturnTimeEvent is the type passed as an argument to the ShowTimePopup routine, and implemented as a private member in TTimePopupForm.

Object for the event notification.
Time value examined or updated in the event handler.
Implements a form displayed to capture a time value.

TTimePopupForm implements a form displayed to capture and return a time value.

The form contains grids with Hour and Minute values which can be selected to form the time value. The Minutes displayed in the grid are in either 5 minute or 30 minute intervals, depending on the layout selected using the SetLayout method; Simple layout uses a 5 minute interval and is the default layout for the form.

It uses an internal TReturnTimeEvent handler to validate or update the time value. There are also internal members used to track the control associated with the form, and the coordinates where the form is displayed. These internals are assigned using values passed as arguments to the ShowTimePopup routine.

TTimeEdit
Implements the OnDblClick event handler for grids controls on the form.

Calls ReturnTime to signal the OnReturnTime event handler (when assigned) and close the form.

Object for the event notification.
Implements the OnKeyDown event handler for grid controls on the form.

GridsKeyDown ensures that the virtual key in Key and Shift is applied, when required. GridsKeyDown calls for form methods for the following:

VK_ESC
  Calls the close method to close the Form.
VK_RETURN, VK_SPACE
  Call ReturnTime to validate/update the time value, and close the Form.

When Key is handled in the method, it is set to zero (0). Otherwise, it is retained for use in Form or Application key events.

Object for the event notification.
Virtual key code examined in the method.
Key Modifier examined in the method.
Sets the canvas text style for a grid on the form.

GridPrepareCanvas ensures that the Canvas used to draw grid controls (TStringGrid) on the form has been initialized. GridPrepareCanvas sets the text layout and alignment needed for the Canvas property in the control.

Sender contains the grid control updated in the method. All other parameters are ignored in the current implementation.

Control updated in the method.
Ignored.
Ignored.
Ignored.
Implements the OnClick event handler for the MoreLessBtn button on the form.
Object for the event notification.
Ensures that the DoubleBuffered property is updated with the current value from the widget set class.
Calculates the total height for the Hours and Minutes grids on the form.
Gets a TDateTime value for the selected cells in Hours and Minutes grids.
Calls EncodeTime to get the return value for the selected cells.
TDateTime value for the selected cells; only the time portion of the value is relevant.
Initializes the form using the origin and time values specified.
Calls KeepInView to ensure that the form origin remains visible on the current monitor. Called from the ShowTimePopup routine.
Upper left coordinates for the form.
Initial time value displayed on the form.
Ensures that form remains visible on the current monitor.

KeepInView ensures that form remains visible on the current monitor. KeepInView tries to put the form on a "nice" place on the screen and make sure the entire form is visible. TheCaller typically will be a TTimeEdit control, and uses the following logic:

- Places the form right under Caller control. If it does not fit...
- Place the form above the Caller control. If it does not fit...
- Sets the top coordinate to 0 and allows covering the Caller control.

Upper left coordinates where the form is displayed.
Validates the current time value for the form.

ReturnTime is a procedure used to validate and possibly update the current time value for the form. GetTime is called to get the time value using the selected cells in the Hour and Minute grids.

ReturnTime signals the internal TReturnTimeEvent event handler (when assigned) to validate/update the time value. The TReturnTimeEvent event handler is passed as an argument to the ShowTimePopup routine.

The Close method is called to close the form if it has not already been hidden.

TCustomForm.Close
Sets the layout used in Minute grid for the form.

SimpleLayout indicates whether the Minutes grid on the form use the simple layout. Simple layout uses a 30 minute interval between cells in the grid, and offers a more compact appearance. When SimpleLayout is False, a 5 minute interval is used between cells in the Minute grid.

Uses the compact 30 minute interval when True.
Sets the time value displayed on the form.
Time value applied to the Hour and Minute grid.
Performs actions needed when the form is closed.

FormClose reimplements the FormClose event handler for the form to ensure that the FormDeactivate method is removed from the registered deactivate handlers in the global Application instance. FormClose sets the value in CloseAction to caFree to free the form instance.

Application TApplication.RemoveOnDeactivateHandler
Object for the event notification.
Close action to perform on exit form the method.
Performs actions needed when the form instance is created.

FormCreate reimplements the FormCreate method to initialize the form instance, and register its deactivation handler. FormCreate sets the form to us the Simple layout, calls SetLayout, and registers the FormDeactivate method as a deactivation handler in the global Application instance.

Application TApplication.AddOnDeactivateHandler
Object for the event notification.
Performs action needed when the form is deactivated.

FormDeactivate reimplements the FormDeactivate event handler for the form. FormDeactivate call the Hide method to immediately hide the form. Otherwise, it would remain visible while in a Drag operation, for example. If not already active, the Close method is called prior to exiting from the method.

Object for the event notification.
Creates, initializes, and displays a TTimePopupForm instance.

ShowTimePopup is a routine used to create, initialize, and display a TTimePopupForm instance. Arguments passed to the routine identify the time value and the control associated with the pop-up, event handlers assigned to the form instance, and the layout and position for the form.

Coordinates where the form is displayed.
Initial time value for the form.
Indicates if DoubleBuffered is enabled in the form instance.
Event handler signalled when the time value is changed.
Event handler signalled when the form is show or hidden.
True indicates the simple (compact) layout is used for the Minute grid on the form.
Control with the time value updated using the pop-up form.