mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 17:19:19 +02:00
implement autosizing for win32 checkbox and radiobutton
git-svn-id: trunk@7735 -
This commit is contained in:
parent
1eb012c515
commit
6a2d38bc49
@ -227,6 +227,8 @@ type
|
||||
public
|
||||
class function CreateHandle(const AWinControl: TWinControl;
|
||||
const AParams: TCreateParams): HWND; override;
|
||||
class procedure GetPreferredSize(const AWinControl: TWinControl;
|
||||
var PreferredWidth, PreferredHeight: integer); override;
|
||||
class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override;
|
||||
class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox;
|
||||
const OldShortCut, NewShortCut: TShortCut); override;
|
||||
@ -1011,6 +1013,31 @@ begin
|
||||
Result := Params.Window;
|
||||
end;
|
||||
|
||||
procedure TWin32WSCustomCheckBox.GetPreferredSize(const AWinControl: TWinControl;
|
||||
var PreferredWidth, PreferredHeight: integer);
|
||||
var
|
||||
textSize: Windows.SIZE;
|
||||
winHandle: HWND;
|
||||
canvasHandle: HDC;
|
||||
oldFontHandle: HFONT;
|
||||
text: string;
|
||||
begin
|
||||
winHandle := AWinControl.Handle;
|
||||
canvasHandle := GetDC(winHandle);
|
||||
oldFontHandle := SelectObject(canvasHandle, AWinControl.Font.Handle);
|
||||
text := AWinControl.Caption;
|
||||
if GetTextExtentPoint32(canvasHandle, PChar(text), Length(text), textSize) then
|
||||
begin
|
||||
// ~5 pixels spacing between checkbox and text, and 2 pixels margin for rounding error
|
||||
PreferredWidth := GetSystemMetrics(SM_CXMENUCHECK) - GetSystemMetrics(SM_CXBORDER) + textSize.cx + 7;
|
||||
PreferredHeight := GetSystemMetrics(SM_CYMENUCHECK) - GetSystemMetrics(SM_CYBORDER);
|
||||
if textSize.cy > PreferredHeight then
|
||||
PreferredHeight := textSize.cy;
|
||||
end;
|
||||
SelectObject(canvasHandle, oldFontHandle);
|
||||
ReleaseDC(winHandle, canvasHandle);
|
||||
end;
|
||||
|
||||
function TWin32WSCustomCheckBox.RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState;
|
||||
begin
|
||||
case SendMessage(ACustomCheckBox.Handle, BM_GETCHECK, 0, 0) of
|
||||
|
Loading…
Reference in New Issue
Block a user