From 4642421795a66f43ffa8d56aaa71136212e86045 Mon Sep 17 00:00:00 2001 From: ondrej Date: Thu, 17 Mar 2016 10:26:20 +0000 Subject: [PATCH] win32: better spin edit (spin placed inside edit) git-svn-id: trunk@51971 - --- lcl/interfaces/win32/win32winapi.inc | 2 +- lcl/interfaces/win32/win32wsspin.pp | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lcl/interfaces/win32/win32winapi.inc b/lcl/interfaces/win32/win32winapi.inc index 33046898a6..7b5f755b13 100644 --- a/lcl/interfaces/win32/win32winapi.inc +++ b/lcl/interfaces/win32/win32winapi.inc @@ -2221,7 +2221,7 @@ var begin UpDownWP.length := SizeOf(UpDownWP); if Windows.GetWindowPlacement(WindowInfo^.UpDown, UpDownWP) then - Width := UpDownWP.rcNormalPosition.Right - WP.rcNormalPosition.Left; + Width := Max(Width, UpDownWP.rcNormalPosition.Right - WP.rcNormalPosition.Left); end; procedure ExcludeCaption; inline; diff --git a/lcl/interfaces/win32/win32wsspin.pp b/lcl/interfaces/win32/win32wsspin.pp index 0c54c351e8..0e9c93b311 100644 --- a/lcl/interfaces/win32/win32wsspin.pp +++ b/lcl/interfaces/win32/win32wsspin.pp @@ -29,7 +29,7 @@ uses // uncomment only when needed for registration //////////////////////////////////////////////////// CommCtrl, Windows, Win32Extra, - Spin, Controls, StdCtrls, LCLType, LMessages, LazUTF8, + Spin, Controls, StdCtrls, LCLType, LMessages, Themes, LazUTF8, //////////////////////////////////////////////////// WSSpin, WSLCLClasses, WSProc, Win32Int, Win32Proc, Win32WSStdCtrls, Win32WSControls; @@ -163,8 +163,11 @@ begin Flags := Flags or ES_AUTOHSCROLL; HotTracking := False; SystemParametersInfo(SPI_GETHOTTRACKING, 0, @HotTracking, 0); - UpDownFlags := WS_CHILD or WS_CLIPSIBLINGS or UDS_ALIGNRIGHT or UDS_ARROWKEYS or - UpDownHotStyle[HotTracking] or ((WS_VISIBLE or WS_DISABLED) and Flags); + + UpDownFlags := WS_CHILD or WS_CLIPSIBLINGS or UDS_ARROWKEYS + or UpDownHotStyle[HotTracking] + or ((WS_VISIBLE or WS_DISABLED) and Flags); + Window := CreateWindowExW(FlagsEx, PWideChar(WideString(EditClsName)), PWideChar(UTF8ToUTF16(StrCaption)), Flags, Left, Top, Width, Height, Parent, HMENU(nil), HInstance, nil); @@ -260,7 +263,7 @@ class procedure TWin32WSCustomFloatSpinEdit.AdaptBounds(const AWinControl: TWinC var WinHandle, UpDown: HWND; R: TRect; - UpDownWidth: Integer; + UpDownWidth, BorderWidth: Integer; DWP: HDWP; begin WinHandle := AWinControl.Handle; @@ -275,11 +278,16 @@ begin } GetWindowRect(UpDown, @R); UpDownWidth := R.Right - R.Left; + if (WindowsVersion >= wvXP) and ThemeServices.ThemesEnabled then + BorderWidth := GetSystemMetrics(SM_CXBORDER) + else + BorderWidth := GetSystemMetrics(SM_CXEDGE); DWP := BeginDeferWindowPos(2); - DeferWindowPos(DWP, WinHandle, UpDown, Left, Top, Width - UpDownWidth + 2, Height, SWP_NOACTIVATE); - DeferWindowPos(DWP, UpDown, 0, Left + Width - UpDownWidth, Top, UpDownWidth, Height, SWP_NOZORDER or SWP_NOACTIVATE); + DeferWindowPos(DWP, WinHandle, UpDown, Left, Top, Width, Height, SWP_NOACTIVATE); + DeferWindowPos(DWP, UpDown, 0, Left + Width - UpDownWidth-BorderWidth, Top+BorderWidth, UpDownWidth, Height-BorderWidth*2, SWP_NOZORDER or SWP_NOACTIVATE); EndDeferWindowPos(DWP); + SendMessage(WinHandle, EM_SETMARGINS, EC_RIGHTMARGIN, MAKELONG(0, UpDownWidth + BorderWidth + 1)); SuppressMove := True; end;