From 475bc75d3e06ab676ba6226c6b993b0671a2795d Mon Sep 17 00:00:00 2001 From: juha Date: Sat, 29 Aug 2020 14:40:17 +0000 Subject: [PATCH] LCL: Improve TForm's bounds events. Issue #36127, patch from Joeny Ang. git-svn-id: trunk@63842 - --- lcl/forms.pp | 2 +- lcl/include/customform.inc | 37 ++++++++++++++++++-------- lcl/interfaces/gtk2/gtk2callback.inc | 2 ++ lcl/interfaces/win32/win32callback.inc | 3 +++ 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/lcl/forms.pp b/lcl/forms.pp index b7c1e19816..8a6f34429d 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -492,7 +492,7 @@ type FWindowState: TWindowState; FDelayedEventCtr: Integer; FDelayedOnChangeBounds, FDelayedOnResize: Boolean; - FIsFirstOnShow, FIsFirstOnActivate: Boolean; + FIsFirstOnShow, FIsFirstOnActivate, FIsFirstRestore: Boolean; function GetClientHandle: HWND; function GetEffectiveShowInTaskBar: TShowInTaskBar; function GetMonitor: TMonitor; diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index e8f16bd55c..801d567fd6 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -720,14 +720,17 @@ begin Activate; end; end; - { delayed onResize() } - if FDelayedOnResize then - inherited DoOnResize; - { delayed onChangeBounds() } - if FDelayedOnResize or FDelayedOnChangeBounds then - inherited DoOnChangeBounds; - FDelayedOnChangeBounds := False; - FDelayedOnResize := False; + if not (FIsFirstOnShow or FIsFirstOnActivate) then + begin + { delayed onResize() } + if FDelayedOnResize then + inherited DoOnResize; + { delayed onChangeBounds() } + if FDelayedOnResize or FDelayedOnChangeBounds then + inherited DoOnChangeBounds; + FDelayedOnChangeBounds := False; + FDelayedOnResize := False; + end; end; procedure TCustomForm.WMWindowPosChanged(var Message: TLMWindowPosChanged); @@ -1001,6 +1004,7 @@ begin if FIsFirstOnShow and (WindowState in [wsMaximized, wsFullScreen]) then Exit; FIsFirstOnShow := False; + FIsFirstRestore := WindowState in [wsMaximized, wsFullScreen]; if Assigned(FOnShow) then FOnShow(Self); end; @@ -1139,17 +1143,15 @@ begin if Showing and not (csDesigning in ComponentState) then begin OldState := FWindowState; - FWindowState := State; if OldState <> State then begin + WindowState := State; if (State = wsMinimized) and (Application.MainForm = Self) and (WidgetSet.GetLCLCapability(lcNeedMininimizeAppWithMainForm) <> LCL_CAPABILITY_NO) then Application.Minimize; if (OldState = wsMinimized) and (Application.MainForm = Self) and (WidgetSet.GetLCLCapability(lcNeedMininimizeAppWithMainForm) <> LCL_CAPABILITY_NO) then Application.Restore; - if Assigned(OnWindowStateChange) then - OnWindowStateChange(Self); end; end; end; @@ -1830,7 +1832,19 @@ begin FWindowState := Value; //DebugLn(['TCustomForm.SetWindowState ',DbgSName(Self),' ',ord(FWindowState),' csDesigning=',csDesigning in ComponentState,' Showing=',Showing]); if (not (csDesigning in ComponentState)) and Showing then + begin ShowWindow(Handle, ShowCommands[Value]); + if not (FIsFirstOnShow or FIsFirstOnActivate) then + begin + if FIsFirstRestore then + begin + MoveToDefaultPosition; + FIsFirstRestore := False; + end; + if Assigned(OnWindowStateChange) then + OnWindowStateChange(Self); + end; + end; end; end; @@ -2030,6 +2044,7 @@ begin FDelayedOnResize := False; FIsFirstOnShow := True; FIsFirstOnActivate := True; + FIsFirstRestore := False; GlobalNameSpace.BeginWrite; try CreateNew(AOwner, 1); // this calls BeginFormUpdate, which is ended in AfterConstruction diff --git a/lcl/interfaces/gtk2/gtk2callback.inc b/lcl/interfaces/gtk2/gtk2callback.inc index 0cb367c3ca..df7f8b2a42 100644 --- a/lcl/interfaces/gtk2/gtk2callback.inc +++ b/lcl/interfaces/gtk2/gtk2callback.inc @@ -1121,6 +1121,8 @@ begin {$ENDIF} SizeMsg.SizeType := SIZE_MINIMIZED; end + else if (GDK_WINDOW_STATE_FULLSCREEN and state^.new_window_state)>0 then + SizeMsg.SizeType := SIZE_FULLSCREEN else if (GDK_WINDOW_STATE_MAXIMIZED and state^.new_window_state)>0 then begin // it can be both maximized + iconified and just loose iconified state diff --git a/lcl/interfaces/win32/win32callback.inc b/lcl/interfaces/win32/win32callback.inc index 80fd869e65..7da3367d94 100644 --- a/lcl/interfaces/win32/win32callback.inc +++ b/lcl/interfaces/win32/win32callback.inc @@ -15,6 +15,7 @@ {$ENDIF} type TWinControlAccess = class(TWinControl); + TApplicationAccess = class(TApplication); {*************************************************************} { callback routines } {*************************************************************} @@ -2054,6 +2055,8 @@ begin begin CheckSynchronize; TWin32Widgetset(Widgetset).CheckPipeEvents; + if Assigned(Application) then + TApplicationAccess(Application).ProcessAsyncCallQueue; end; WM_ENTERIDLE: Application.Idle(False); WM_ACTIVATE: SetLMessageAndParams(LM_ACTIVATE);