TCustomComboBoxEx.DrawItem procedure
Draws an item on the extended combo-box control.
Declaration
procedure DrawItem(Index: Integer; ARect: TRect; State: TOwnerDrawState)
; overrideArguments
Index | Ordinal position for the item drawn in the method. |
ARect | Display rectangle for the item drawn in the method. |
State | State used to draw the item in the control. |
Description
DrawItem is an overridden procedure used to draw an item on the
extended combo-box control.
Index contains the ordinal position for the TComboExItem instance in
ItemsEx that is drawn in the method.
ARect is the TRect instance with the coordinates for the item. The
values in ARect are set in the calling procedure (LMDrawListItem in
TCustomComboBox). When the left coordinate is greater than zero (0), the item
is a sub-item (or not a main item). Sub-items are drawn with the additional
spacing in Indent applied to the drawing rectangle.
State contains the owner draw state used to render the item on the
control. It is used along with the Focused, DroppedDown, and IsEnabled to
determine the brush color and style used to render the item on the Canvas.
DrawItem calculates the vertical space needed for the text on the item. It also ensures that the Indent for the item is used to position output horizontally on the control.
If Images have been assigned for the control, the image index
appropriate for the value in State is determined. The value
odSelected causes the SelectedImageIndex for the item
is be used. Otherwise, the ImageIndex for the item is used.
The image size is determined using the SizeForPPI method in Images
with the value in its ImagesWidth and the display density for the control Font.
DrawItem gets the location for the image and the indent spacing for the current
BiDiMode setting for the control. Right-to-Left rendering aligns the image and
indent to the right-hand edge of the drawing rectangle. The DrawForPPI method
in Images is called to scale the selected image to the current PixelsPerInch
setting in Font, and to render the image on the control Canvas.
An image is not drawn when Images is unassigned or contains zero (0) images, or when values have not been explicitly assigned to either ImageIndex or SelectedImageIndex for the extended item in Index.
DrawItem configures the Canvas to use the brush style and font color needed for the values in State, DroppedDown, and Focused. clHighlight is used as the Font color for an item where any one of these values is True. Otherwise, clWindowText is used. If the item is Focused and Enabled but not DroppedDown, the background color is set to clBtnFace and the focus rectangle is drawn.
Text drawing flags are derived for the item; text is on an single line and
ellipsified when too long. Text is aligned for the Bidi mode on the control,
and centered vertically in the output rectangle. The text is rendered on the
Canvas by calling the DrawText method in the LCL interface.
TCustomComboBox or trigger its OnDrawItem event handler.
The extended combo-box item is rendered entirely in this method.
See also
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
