win32: fix MeasureText for use with custom drawn controls (bug #0012934)

git-svn-id: trunk@18189 -
This commit is contained in:
paul 2009-01-07 15:01:05 +00:00
parent 469e8d7e1a
commit ae9d552d60
3 changed files with 10 additions and 7 deletions

View File

@ -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);

View File

@ -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

View File

@ -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