mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 20:21:12 +02:00
win32: fix MeasureText for use with custom drawn controls (bug #0012934)
git-svn-id: trunk@18189 -
This commit is contained in:
parent
469e8d7e1a
commit
ae9d552d60
@ -111,7 +111,7 @@ procedure RestoreStayOnTopFlags(Window: HWND);
|
||||
|
||||
procedure AddToChangedMenus(Window: HWnd);
|
||||
procedure RedrawMenus;
|
||||
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
|
||||
function MeasureText(const AWinControl: TWinControl; Text: string; UseFont: HFont; var Width, Height: integer): boolean;
|
||||
function GetControlText(AHandle: HWND): string;
|
||||
procedure SetMenuFlag(const Menu:HMenu; Flag: Cardinal; Value: boolean);
|
||||
|
||||
@ -1246,7 +1246,7 @@ begin
|
||||
SetMenuItemInfo(Menu, 0, True, @MenuInfo);
|
||||
end;
|
||||
|
||||
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
|
||||
function MeasureText(const AWinControl: TWinControl; Text: string; UseFont: HFont; var Width, Height: integer): boolean;
|
||||
var
|
||||
textSize: Windows.SIZE;
|
||||
winHandle: HWND;
|
||||
@ -1255,7 +1255,10 @@ var
|
||||
begin
|
||||
winHandle := AWinControl.Handle;
|
||||
canvasHandle := Windows.GetDC(winHandle);
|
||||
newFontHandle := HFONT(SendMessage(winHandle, WM_GETFONT, 0, 0));
|
||||
if UseFont = 0 then
|
||||
newFontHandle := HFONT(SendMessage(winHandle, WM_GETFONT, 0, 0))
|
||||
else
|
||||
newFontHandle := UseFont;
|
||||
oldFontHandle := SelectObject(canvasHandle, newFontHandle);
|
||||
DeleteAmpersands(Text);
|
||||
|
||||
|
@ -247,7 +247,7 @@ begin
|
||||
BitBtnDC := GetDC(BitBtnHandle);
|
||||
hdcNewBitmap := CreateCompatibleDC(BitBtnDC);
|
||||
OldFontHandle := SelectObject(hdcNewBitmap, BitBtn.Font.Reference.Handle);
|
||||
MeasureText(BitBtn, ButtonCaption, TextSize.cx, TextSize.cy);
|
||||
MeasureText(BitBtn, ButtonCaption, BitBtn.Font.Reference.Handle, TextSize.cx, TextSize.cy);
|
||||
// calculate size of new bitmap
|
||||
case BitBtnLayout of
|
||||
blGlyphLeft, blGlyphRight:
|
||||
@ -401,7 +401,7 @@ var
|
||||
Glyph: TBitmap;
|
||||
spacing, srcWidth: integer;
|
||||
begin
|
||||
if MeasureText(AWinControl, AWinControl.Caption, PreferredWidth, PreferredHeight) then
|
||||
if MeasureText(AWinControl, AWinControl.Caption, 0, PreferredWidth, PreferredHeight) then
|
||||
begin
|
||||
Glyph := BitBtn.Glyph;
|
||||
if not Glyph.Empty then
|
||||
|
@ -1353,7 +1353,7 @@ end;
|
||||
class procedure TWin32WSButtonControl.GetPreferredSize(const AWinControl: TWinControl;
|
||||
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
|
||||
begin
|
||||
if MeasureText(AWinControl, AWinControl.Caption, PreferredWidth, PreferredHeight) then
|
||||
if MeasureText(AWinControl, AWinControl.Caption, 0, PreferredWidth, PreferredHeight) then
|
||||
begin
|
||||
Inc(PreferredWidth, 20);
|
||||
Inc(PreferredHeight, 4);
|
||||
@ -1437,7 +1437,7 @@ class procedure TWin32WSCustomCheckBox.GetPreferredSize(const AWinControl: TWinC
|
||||
var
|
||||
iconHeight: integer;
|
||||
begin
|
||||
if MeasureText(AWinControl, AWinControl.Caption, PreferredWidth, PreferredHeight) then
|
||||
if MeasureText(AWinControl, AWinControl.Caption, 0, PreferredWidth, PreferredHeight) then
|
||||
begin
|
||||
Inc(PreferredWidth, GetSystemMetrics(SM_CXMENUCHECK));
|
||||
// pixels spacing between checkbox and text
|
||||
|
Loading…
Reference in New Issue
Block a user