win32: fix autosize for TSpinEdit

git-svn-id: trunk@19709 -
This commit is contained in:
paul 2009-04-30 15:33:36 +00:00
parent 2ee9eb22cb
commit b5d76c7a76
2 changed files with 25 additions and 7 deletions

View File

@ -105,6 +105,7 @@ procedure RestoreStayOnTopFlags(Window: HWND);
procedure AddToChangedMenus(Window: HWnd);
procedure RedrawMenus;
function MeasureTextForWnd(const AWindow: HWND; Text: string; var Width, Height: integer): boolean;
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
function GetControlText(AHandle: HWND): string;
procedure SetMenuFlag(const Menu:HMenu; Flag: Cardinal; Value: boolean);
@ -1149,16 +1150,15 @@ begin
SetMenuItemInfo(Menu, 0, True, @MenuInfo);
end;
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
function MeasureTextForWnd(const AWindow: HWND; Text: string; var Width,
Height: integer): boolean;
var
textSize: Windows.SIZE;
winHandle: HWND;
canvasHandle: HDC;
oldFontHandle, newFontHandle: HFONT;
begin
winHandle := AWinControl.Handle;
canvasHandle := Windows.GetDC(winHandle);
newFontHandle := HFONT(SendMessage(winHandle, WM_GETFONT, 0, 0));
canvasHandle := Windows.GetDC(AWindow);
newFontHandle := HFONT(SendMessage(AWindow, WM_GETFONT, 0, 0));
oldFontHandle := SelectObject(canvasHandle, newFontHandle);
DeleteAmpersands(Text);
@ -1170,7 +1170,12 @@ begin
Height := textSize.cy;
end;
SelectObject(canvasHandle, oldFontHandle);
Windows.ReleaseDC(winHandle, canvasHandle);
Windows.ReleaseDC(AWindow, canvasHandle);
end;
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
begin
Result := MeasureTextForWnd(AWinControl.Handle, Text, Width, Height);
end;
function GetControlText(AHandle: HWND): string;

View File

@ -50,6 +50,9 @@ type
var Left, Top, Width, Height: integer; var SuppressMove: boolean); override;
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
@ -180,6 +183,17 @@ begin
Result := Params.Window;
end;
class procedure TWin32WSCustomFloatSpinEdit.GetPreferredSize(
const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean);
begin
if MeasureTextForWnd(GetBuddyWindow(AWinControl.Handle), 'Fj', PreferredWidth, PreferredHeight) then
begin
PreferredWidth := 0;
Inc(PreferredHeight, 10);
end;
end;
class procedure TWin32WSCustomFloatSpinEdit.AdaptBounds(const AWinControl: TWinControl;
var Left, Top, Width, Height: integer; var SuppressMove: boolean);
var
@ -187,7 +201,6 @@ var
R: TRect;
WindowWidth: Integer;
begin
WinHandle := AWinControl.Handle;
{
// detach from buddy first