Implements a bevel with additional drawing features used as a separator on forms, frames, and panels.

DividerBevel.pas contains the TDividerBevel control, a bevel with additional drawing features. This file is part of the LazControls package.

Line with text in the middle, used as a divider or header.

TDividerBevel is a TGraphicControl descendant which implements a component represented as a beveled line with a caption. It is used as a separator or header on forms, frames, and panels. It is similar to TBevel, but provides additional drawing styles as well layout options for the control caption.

TDividerBevel can be oriented either horizontally or vertically. The bevel can be drawn using a raised or lowered drawing style. The bevel can be rendered using a line drawing shape or a pattern defined in the Style property. The height of the bevel can be specified, or it can resize to the Text on the control. The caption can be drawn at a specific position (LeftIndent) and surrounded by an unused space using the CaptionSpacing property. Transparency is also supported in the control.

The BevelWidth property indicates the thickness for the bevel. It is set to -1 by default, and indicates that the size is Max(3, TextHeight div 5). A positive value means that pixel measurements are used in the property.

The LeftIndent is set by default to 60. Any negative value in LeftIndent causes the text in Caption to be centered along the bevel orientation.

Sets the value in the BevelStyle property. TControl.AutoSize New value for the BevelStyle property. Sets the value in the BevelWidth property. New value for the BevelWidth property. Sets the value for the CaptionSpacing property. New value for the CaptionSpacing property. Sets the value for the LeftIndent property. New value for the LeftIndent property. Sets the value for the Orientation property. New value for the Orientation property. Sets the value for the Style property. New value for the Style property. Sets the value for the Transparent property. New value for the Transparent property. Member with the height for the bevel. Member with the top for the bevel. Member with the flag set when the Font, Text, Bevel or the preferred size has been changed. Member with the text extent for the Caption property. The default size for a new instance of the class.

GetControlClassDefaultSize is an overridden TSize function used to get the default size for new instances of the TDividerBevel class. The width (CX) in the TSize instance is set to 240. The height (CY) in the TSize instance is set to 17.

Used by the GetDefaultWidth and GetDefaultHeight methods.

TControl.GetControlClassDefaultSize
TSize instance with the width and height for the new class instance. Calculates the height for the Caption text and the bevel on the control.

CalcSize is a method used to calculate the height for the Caption text and the bevel drawn on the control. An internal flag, set when the Text or Font for the control is changed, is used to determine when the calculation is needed. No actions are performed in the method if the flag has not been set.

CalcSize calls the TextExtent method in the control Canvas to get the text extent for Caption.

BevelWidth is used to set the height for the bevel in pixels when it has a positive or zero value. When BevelWidth has a negative value, the height for the bevel is set to the larger of 20% of the text height or 3 pixels. The bevel is centered in the text height.

CalcSize is called from the CalculatePreferredSize and Paint methods.

Draws the control on its Canvas.

Paint is an overridden method used to draw the control on its Canvas. It re-implements the method from the ancestor class, and does not call the inherited method.

Paint calls CalcSize to ensure that the height for the Caption text and the bevel are updated before the control is drawn.

If Transparent is set to False, the background for the control is filled using the value in Color.

Values in BevelStyle, Style, Orientation, and Caption are used to determine the drawing area for the bevel on the control. The PaintBevel method is called to render the bevel to the control Canvas.

When Caption has been assigned, it is positioned using the values in LeftIndent and CaptionSpacing. The TextOut method in Canvas is called to draw the Caption text using the Orientation for the control.

Use the Font property to configure the font face, style, and size used for the Caption text.

Performs actions when the Font for the control has been changed.

FontChanged is an overridden method used to update the control when the value in Font has been changed. It calls the inherited method on entry to apply the new font to the control Canvas, and post a CM_FONTCHANGED control message to the widgetset class. The internal flag used to force text and bevel sizes to be recalculated is set. Invalidate is called to force the control to be redrawn.

FontChanged is assigned as the OnChange event handler in the Font property.

TGraphicControl.FontChanged
Object instance for the event notification. Sets the value for the AutoSize property.

SetAutoSize is an overridden method in TDividerBevel. It calls the inherited method on entry to update the member for AutoSize and to call the AdjustSize method when needed. It extends InvalidatePreferredSize method (in the ancestor) to clear any cached preferred size value for the control or any of its parents when Value is set to True.

TControl.AutoSize TControl.InvalidatePreferredSize
New value for the AutoSize property. Performs actions when the CM_TEXTCHANGED message is handled for the control.

TextChanged is an overridden method used to perform action needed when the value in the text property has been changed for the control. It re-implements the method from the ancestor class to set in the internal flag to recalculate text and bevel sizes in the control, and calls the Invalidate method to force the control to be redrawn.

TextChanged is called from the CMTextChanged method.

TControl.CMTextChanged
Calculates the preferred size for the control.

CalculatePreferredSize is an overridden method used to calculate the preferred width and height for the control. It re-implements the method from the ancestor class, and does not call the inherited method.

CalculatePreferredSize sets the internal flag to recalculate the text and bevel height, and calls CalcSize to update the values.

The value in Orientation is used to determine the value calculated in the method. When set to trHorizontal, PreferredHeight is set to the maximum of the text height or the bevel height (Caption is empty). When set to trVertical, the PreferredWidth is set to the maximum of the text height or the bevel height (Caption is empty).

The preferred width for the control. The preferred height for the control. True if additional space is reserved for theme elements. Not used in the method. Constructor for the class instance.

Create is the overridden constructor for the class instance, and calls the inherited method on entry. It sets the default values for properties, including:

  • BevelStyle (bsLowered)
  • BevelWidth (-1 for relative bevel size)
  • CaptionSpacing (10 pixels)
  • LeftIndex (60 pixels)
  • Orientation (trHorizontal)
  • Transparent (True)
  • AutoSize (True)

An internal flag used to force the text and bevel height to be calculated is set. The GetControlClassDefaultSize method is called get and set the initial bounds for the class instance.

Owner of the class instance. Determine if the width and/or height can be adjusted by a layout policy.

Re-implements the method from the ancestor class, and does not call the inherited method. In TDividerBevel, a dimension can be auto-adjusted when AutoSize is not enabled, and the dimension is not the Orientation for the control. Called when an auto-adjust layout policy is applied to the control.

TControl.ShouldAutoAdjust
True if the width can be auto-adjusted by a layout policy. True if the height can be auto-adjusted by a layout policy. Indicates whether the bevel is drawn using a raised or lowered drawing style.

BevelStyle is a TBevelStyle property which indicates if the bevel is drawn using a raised or lowered style. The default value for the property is bsLowered. Changing the value for the property causes the control to be redrawn.

Use BevelWidth to set the bevel height in pixels, or relative to the text height for the control. Use Style to set the shape or pattern used to draw the bevel.

BevelStyle is used in the Paint method.

TBevelStyle
Height for the bevel on its Orientation.

The default value for the property is -1. Negative values in the property indicate that the bevel is drawn using 20% of the Text height for the control, with a minimum height of 3 pixels.

Changing the value in BevelWidth causes the control to be updated. When AutoSize is True, the preferred size is reset and the AdjustSize method is called. When AutoSize is False, an internal flag is set to indicate that the size needs to be recalculated in the CalcSize method. The Invalidate method is called to force the control to be redrawn.

TControl.InvalidatePreferredSize TControl.AdjustSize TControl.Invalidate
Number of pixels reserved as spacing in front of and following the Caption for the control.

The default value for the property is 10. Use LeftIndent to set the position (in pixels) where the Caption text is drawn. A negative value in LeftIndent causes the caption to be centered along the bevel, and the value in CaptionSpacing is ignored.

Position relative to Left where the CaptionSpacing and Caption are drawn.

LeftIndent is an Integer property which indicates the position relative to the Left property where the CaptionSpacing and Caption text are displayed on the control. The default value for the property is 60 pixels.

Use CaptionSpacing to set the number of pixels reserved as undecorated blank space on each side of the Caption text.

For example: If CaptionSpacing is set to 10, and LeftIndent is set to 60, the CaptionSpacing starts at 60 pixels and the text at 70 pixels relative to Left.

LeftIndent, when set to a negative value, causes the CaptionSpacing and Caption text to be centered along the Orientation for the divider bevel. When set to 0, neither left indent nor caption spacing are applied before the Caption text.

Changing the value for the property causes the control to be redrawn.

LeftIndent is used in the Paint method.

TControl.Caption TControl.Left
Direction that the bevel and caption are drawn.

Orientation is a TTrackBarOrientation property which indicates the direction that the bevel and caption are drawn on the control. The default value for the property is trHorizontal, and causes the bevel and caption to be draw from left to right horizontally. When set to trVertical, the Font on the control Canvas is rotated 90 degrees and the bevel and caption are drawn from top to bottom vertically.

Changing the value for the property causes the size to be adjusted when AutoSize is set to True. The control is redrawn when the new property value is applied.

Orientation is used in the Paint method.

TGraphicControl.Canvas TControl.AutoSize TTrackBarOrientation
Drawing style for the bevel on the control.

Style is a TGrabStyle property with the shape or pattern used to draw the bevel on the control.

The default value for the property is gsSimple, and causes a simple rectangle to be drawn with the appearance in the BevelStyle property. Contrasting colors on the borders are used to achieve the raised or lowered appearance. Other values include:

gsDouble
Draws double lines using the appearance in BevelStyle.
gsHorLines
Draws a single line using the appearance in BevelStyle.
gsVerLines
Draws a vertical line using the appearance in BevelStyle.
gsGripper
Draws a row of raised dots on the bevel. BevelStyle is not used. Drawn using the trGripper theme element details in ThemeServices.
gsButton
Draws the bevel using a pseudo-button style. BevelStyle is not used. Drawn using the tbPushButtonNormal theme element details in ThemeServices.
Indicates if the parent control is visible beneath the drawing area for the divider bevel.

Transparent is a Boolean property which indicates if the control is drawn with transparency. When set to True, the parent control is visible beneath the undecorated areas on the control. When set to False, the client area for the control is filled using the value in Color. The default value for the property is True.

TControl.Color