Implements a custom-drawn check box control drawn using theme services.

checkboxthemed.pas contains classes used to implements a custom-drawn check box control drawn using theme services.

This file is part of the LazControls package.

Provides a link between a themed check box control and its action.

TCheckBoxThemedActionLink is a TWinControlActionLink descendant which maintains a link between a TCustomCheckBoxThemed class instance and its Action. It provides overridden methods that use TCustomCheckBoxThemed as the internal client for the link, and maintains the checked state for the client control when the Action is linked and executed.

TCustomAction TWinControlActionLink TControlActionLink
Sets the control used as the client in the action link.

Calls the inherited method, and stores the control as a TCustomCheckBoxThemed instance in the member variable used in the class instance.

The themed check box object that is the client for the action link.
Sets the value in the Checked property for the client control when linked to the action.
New value for the Checked property.
Determines if an Action is linked to the client control and if the Checked values are in sync.
True when an Action exists for the client control and they share the same Checked value.
Class type used to create new instances of TCheckBoxThemedActionLink.

TCheckBoxThemedActionLinkClass is a TCheckBoxThemedActionLink class type.

Implements the base class for a custom-drawn check box control.

TCustomCheckBoxThemed is a TCustomControl descendant which implements the base class for a custom-drawn check box control.

Do not create instances of TCustomCheckBoxThemed; use the TCheckBoxThemed descendant.

TCustomControl
Gets the value for the Check property.
Value for the property.
Sets the value for the Alignment property.
New value for the property.
Sets an internal flag used to track mouse hover, and redraws the control.
New value for the internal flag.
Sets the value for the Checked property.
New value for the property.
Sets the value for the State property.
New value for the property.
Gets the dimensions for the check box in the control scaled to the given display density.
TSize instance with the dimensions for the check box.
Design-time PPI setting used to scale to the PPI setting for the screen.
Member used to track key or mouse state in the control.
Not used in the current implementation.
Not used in the current implementation.
Not used in the current implementation.
Calculates the preferred height and width for the control.
Preferred width calculated in the method.
Preferred height calculated in the method.
True if additional space is reserved for theming element / details.
Handles the CM_BIDIMODECHANGED control message.
Control message examined in the method.
Handles the CM_ENABLEDCHANGED control message.
Control message examined in the method.
Gets the size needed for the check box when drawn using ThemeServices.

InitCheckBoxSize is a class method used to initialize the member used to store the check box size when drawn using theme element details. Calls the GetDetailSize method in ThemeServices to store the value for the TPoint member.

Handles a message with an accelerator key for the control.
True when the key is handled in the method.
Message with the key event examined in the method.
Performs actions needed when the control is clicked.

DoClick ensures that the State or Checked property is updated when the control is clicked. When AllowGrayed is enabled, the value in State is updated to the next value for the tri-state check box control. Otherwise, the current value in Checked is toggled.

DoClick is called from DialogChar when an accelerator key is handled for the control. It is called from KeyUp when the VK_RETURN or VK_SPACE key code is handled for the control. It is also called from MouseUp when a Left mouse button event occurs on the hovered control.

Performs actions needed when the control is entered (receives input focus).

DoEnter is an overridden method in TCustomCheckBoxThemed. It calls the inherited method on entry to signal the OnEnter event handler (when assigned). It calls Invalidate to force the control to be redrawn.

TWinControl.DoEnter TWinControl.OnEnter TWinControl.Invalidate
Performs actions needed when the control is exited (loses input focus).

DoExit is an overridden method in TCustomCheckBoxThemed. It calls the inherited method on entry to signal the OnExit event handler (when assigned). It calls Invalidate to force the control to be redrawn.

TWinControl.DoExit TWinControl.OnExit TWinControl.Invalidate
Gets the class reference used to create the action link for the control.

GetActionLinkClass is an overridden method in TCustomCheckBoxThemed used to get the class reference needed to create a new action link for the control. The return value is the TCheckBoxThemedActionLink type.

It re-implements the method introduced in the ancestor class. It does not call the inherited method.

Always returns the TCheckBoxThemedActionLink type.
Handles key down events for the control.
Key code examined in method.
Shift, Alt, or Ctrl modifier for the key.
Handles key up events for the control.
Key code examined in method.
Shift, Alt, or Ctrl modifier for the key.
Handles mouse down events for the control.
Mouse button for the event.
Shift, Alt, or Ctrl modifier for the mouse event.
Horizontal coordinate for the mouse pointer.
Vertical coordinate for the mouse pointer.
Updates the hover state when the mouse pointer enters the control.
Updates the hover state when the mouse pointer leaves the control.
Handles a mouse up event for the control.

MouseUp is an overridden method in TCustomCheckBoxThemed. It calls the inherited method on entry to signal the OnMouseUp event handler (when assigned). It ensures that a Left mouse button click anywhere within the client rectangle for the control causes the DoClick method to be called to update values in the State and/or Checked property.

Mouse button for the event.
Shift, Ctrl, Alt modifier for the mouse event.
Horizontal coordinate for the mouse pointer.
Vertical coordinate for the mouse pointer.
Draws the themed check box control.

Paint is an overridden method in TCustomCheckBoxThemed. It calls the inherited method to signal the OnPaint event handler (when assigned). It calls PaintSelf which implements the custom drawing method used for the themed check box control.

TCustomControl.Paint
Redraws the control when the caption text has been changed.

Calls the inherited method on entry. Calls Invalidate to force the control to be redrawn.

TWinControl.Invalidate
Handles the WM_SIZE message for the control and redraws the control.

Calls the inherited method on entry to apply the message to the control. Calls Invalidate to force the control to be redrawn.

TWinControl.WMSize
Window message examined in the method.
Indicates if the mouse pointer is hovered over the control.
Protected property used to track the Checked state in the ActionLink/Action for the control.
Internal constant with the space reserved for the focus border in the control.
Internal constant with the space reserved for padding in the control.
Renders a check box control using the specified parameters.

PaintSelf is a class method used to render a custom-drawn check box control using the parameters passed to the method.

PaintSelf calculates the size and position for both the caption and the check box in the control using the theme element details in theme services. This includes use of the ARightToLeft parameter in DrawText flags. ThemeServices.DrawText is called to render the caption for the control. ThemeServices.DrawElement is called to draw the check box using the hovered, pressed, and checked state values for the control.

Canvas is the TCanvas instance where the control is drawn.

PaintSelf is called from the Paint method, and occurs after the inherited OnPaint event handler been signalled (when assigned).

TThemeServices.DrawText TThemeServices.DrawElement
Canvas for a check box control.
Caption text for a check box control.
Rectangle with the coordinates for a check box control.
Checked state for a check box control.
Alignment for caption in the check box control.
True if the mouse is hovered over the check box control.
True if the check box control is in the pressed state (mouse down).
True if the check box control has input focus.
Left-to-Right alignment for the content in the check box control.
True if the control is drawn in the enabled state.
Constructor for the class instance.

Create is the overridden constructor for the class instance, and calls the inherited constructor on entry. Create sets the accessibility role and control style flags needed for the control. Create also sets the default values for properties, including:

Alignment
  Set to taRightJustify.
AllowGrayed
  Set to False.
AutoSize
  Set to True.
TabStop
  Set to True.

Horizontal alignment for the caption text in the control.

Alignment is a TLeftRight property which contains the horizontal alignment used for the control.

The value in Alignment is used in the Paint and PaintSelf methods. It determines the alignment for Caption displayed for the control is drawn. taLeftJustify aligns the caption to the left of the check box, while taRightJustify aligns the caption to the right side of the check box.

The default value for the property is taRightJustify.

Setting a new value for the property calls the Invalidate method which forces the control to be redrawn.

TWinControl.Invalidate
Indicates if the control can use the "grayed" state.

AllowGrayed is a Boolean property which indicates if the control can be displayed using its "grayed" state. This indicates that the control is disabled or has an undetermined state value. The default value for the property is False.

AllowGrayed is used to determine the new value for the State property when the control is clicked, or when handling key events in the control. When AllowGrayed is True, a click event changes State from cbUnchecked, to cbGrayed, to cbChecked and then back to cbUnchecked. When AllowGrayed is False, the State value is toggled between cbUnchecked and cbChecked using the Checked property.

Provides access to the checked state for the control as a Boolean value.

Checked is a Boolean property used to read or write the checked or unchecked state for the control as a Boolean value.

Checked is True when the value in the State property is cbChecked. Any other value in State causes Checked to contain False (including cbGrayed). Setting a new value for the property causes State to change to either cbChecked (for True) or cbUnchecked (for False).

Use State to set the checked state for the control using the 3-state values in the TCheckBoxState enumeration.

The default value for the property is False.

Indicates the checked, unchecked, or grayed state for the check box control.

State is a TCheckBoxState property which indicates the checked, unchecked, or grayed state for the check box control. The default value for the property is cbUnchecked.

At run-time, setting a new value for State causes additional actions to be performed:

- Signals the OnEditingDone event handler (when assigned).
- Signals the OnChange event handler (when assigned).
- Signals the OnClick event handler (when assigned) if an Action has not been assigned for the control, or the Check value in Action has not been changed.
- Executes the Action (via the ActionLink) when the new property value is different than the Checked state for the Action.
- Calls Invalidate to force the control to be redrawn.

No actions are performed at design-time, during LCL streaming, when the control is freed, or when the new value for State is the same as the existing property value.

State is related to the Checked property. Checked is True when State contains cbChecked, or False for any other value in State. Setting the value in Checked causes the value in State to be toggled between cbChecked and cbUnchecked.

The value in State is updated when the accelerator character or a click event is handled for the control. Its value is used in the Paint and PaintSelf methods to determine how the themed check box is drawn for the control.

TWinControl.Invalidate TControl.OnEditingDone TControl.OnClick TControl.Action TControl.ActionLink
Event handler signalled when the value for the control is changed.

OnChange is a TNotifyEvent property with the event handler signalled when the value for the control is changed.

OnChange is signalled when the value in State or Checked is modified. It occurs after the OnEditingDone event handler and before the OnClick event handler (or execution of the Action) for the control.

Applications must implement and assign an object procedure to the property to respond to the event notification.

TControl.OnEditingDone TControl.OnClick TControl.Action TControl.ActionLink TNotifyEvent
Implements a custom-drawn check box control.

TCheckBoxThemed is a TCustomCheckBoxThemed descendant which implements a custom-drawn check box control. It implements a custom paint method to render the control using theme services. TCheckBoxThemed is the type used to implement check box controls used in both the Object Inspector and Property editors in the Lazarus IDE.

TCheckBoxThemed sets the visibility and default values for properties defined in an ancestor class.

The default value for the property is True in TCheckBoxThemed.

The default value for the property is True in TCheckBoxThemed.