Sign in Join
Wiki copytemporary

LCL Internals - Resizing, Moving: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: LCL Internals - Resizing, Moving

OldNewLine
1+## Overview
2+
3+The LCL has a lot of resizing properties (Left, Width, Anchors, Align, AnchorSide, AutoSize, Constraints, ChildSizing, ...) and hooks where applications can alter the behavior (OnResize, OnChangeBounds, ...). All these things can not be calculated in one step, so controls can move quite a lot before the final coordinates come out. To reduce flickering the LCL does not send every move/resize to the LCL interface. For example during Begin/EndAlign and csLoading no move/resize is sent to the interface. The widgetset will try to follow the advices of the LCL, but there are some cases, where it does not follow. For example forms (top level windows) are limited by the window manager policies. And TPage completely depends on the size and theme of the TNotebook.
4+
5+## How the LCL tells the interface to resize/move a handle
6+
7+In TWinControl.DoSendBoundsToInterface the widget function SetBounds is called
8+
9+``` pascal
10+TWSWinControlClass(WidgetSetClass).SetBounds(Self, Left, Top, Width, Height);
11+```
12+
13+## How the Interface tells the LCL to resize/move a handle
14+
15+### When the client area of a Handle was resized
16+
17+*Note*: If the theme changes the frame of a TGroupBox can change. This leaves the Size and Position of the TGroupBox unchanged, but the client area can change. The interface calls
18+
19+` LCLControl.InvalidateClientRectCache(false);`
20+
21+and sends a LM_SIZE message as below.
22+
23+### When a Handle of a TWinControl was resized/moved
24+
25+#### First the LCL interface send a LM_WINDOWPOSCHANGED message
26+
27+- x := Left (relative to 0,0 of client area of parent)
28+- y := Top
29+- cx := Width
30+- cy := Height
31+
32+#### Then a LM_SIZE message is sent
33+
34+- Width
35+- Height
36+- SizeType is a bit flag containing Size_SourceIsInterface plus one of the values SIZENORMAL, SIZEICONIC, SIZEFULLSCREEN.
37+
38+#### Then a LM_MOVE message is sent
39+
40+- MoveType := Move_SourceIsInterface;
41+- XPos := Left (relative to 0,0 of client area of parent)
42+- YPos := Top
43+
44+### When a form is maximized, minimized or restored the interface sends a LM_SIZE message
45+
46+- Width
47+- Height
48+- SizeType is a bit flag containing Size_SourceIsInterface plus one of the values SIZENORMAL, SIZEICONIC, SIZEFULLSCREEN.
49+
50+## How the LCL gets the current size / position of a LCL interface handle
51+
52+### LCLIntf.GetWindowSize(Handle, InterfaceWidth, InterfaceHeight)
53+
54+Returns the current width and height of a Handle.
55+
56+### LCLIntf.GetClientRect(Handle, Result)
57+
58+Returns the current width and height (left and top are always 0) of the client area of a Handle (= inner area inside the border/frame of a control).
59+
60+### TWSWinControlClass(WidgetSetClass).GetDefaultClientRect(Self, Left, Top, Width, Height, Result)
61+
62+This function is called first by the LCL to get the ClientRect. If it returns false, the LCL will use GetClientRect if it has already created a handle, otherwise the values loaded from the .lfm. If all this fails, the default is Rect(0,0,Width,Height). GetDefaultClientRect can be used by the LCL interface to reduce flickering by providing good values before the handle is created.
63+
64+### GetWindowRelativePosition(Handle,NewLeft,NewTop)
65+
66+Returns the current Left, Top of a Handle relative to the client area (0,0) of its parent.
67+
68+## Constraints
69+
70+The LCL asks the interface for constraints (min, max for width and height) with the function
71+
72+``` pascal
73+GetControlConstraints
74+```
75+
76+For example: Under gtk a horizontal scrollbar has a fixed height.
77+
78+## Preferred Size
79+
80+To autosize a control (e.g. a TButton or a TLabel) the LCL asks the interface about the minimum size to render a control nicely:
81+
82+``` pascal
83+TWSWinControlClass(WidgetSetClass).GetPreferredSize(Self, PreferredWidth, PreferredHeight, WithThemeSpace);
84+```
85+
86+## Scrolling
87+
88+The LCL scrolls child controls only virtually. That means, their Left,Top properties do not change. To scroll it uses the LCL interface function
89+
90+``` pascal
91+TWSScrollingWinControlClass(WidgetSetClass).ScrollBy(Self, DeltaX, DeltaY);
92+```
93+
94+## Rectangles
95+
96+- BoundsRect - the rectangle containing coordinates of the control within parents coordinates
97+
98+
99+for TForm (not embedded into another control) coordinates are given in Screen position. The form non-client area (aka header, aka title) section is also NOT PART of the BoundsRect.
100+
101+- ClientsRect - the rectangle containing coordinates of the client area.
102+
103+## Miscellaneous
104+
105+### LCLIntf.GetClientBounds(Handle,Result);
106+
107+Returns the unscrolled client rectangle relative to the top, left of the Handle. In other words it is equivalent to:
108+
109+``` pascal
110+CurClientBounds := GetClientRect(Handle)
111+OffsetRect(CurClientBounds,FrameBorderLeft,FrameBorderTop);
112+```
113+
114+---
115+*From the Free Pascal wiki, page "LCL Internals - Resizing, Moving", as it stood on 2020-02-19 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history