diff --git a/lcl/controls.pp b/lcl/controls.pp index c9aef94078..15d09fc552 100644 --- a/lcl/controls.pp +++ b/lcl/controls.pp @@ -127,7 +127,7 @@ type TCaption = TTranslateString; TCursor = -32768..32767; - TFormStyle = (fsNormal, fsMDIChild, fsMDIForm, fsStayOnTop, fsSplash); + TFormStyle = (fsNormal, fsMDIChild, fsMDIForm, fsStayOnTop, fsSplash, fsSystemStayOnTop); TFormBorderStyle = (bsNone, bsSingle, bsSizeable, bsDialog, bsToolWindow, bsSizeToolWin); TBorderStyle = bsNone..bsSingle; @@ -144,7 +144,8 @@ type TMouseButton = (mbLeft, mbRight, mbMiddle, mbExtra1, mbExtra2); const - fsAllStayOnTop = [fsStayOnTop, fsSplash]; + fsAllStayOnTop = [fsStayOnTop, fsSplash, fsSystemStayOnTop]; + fsAllNonSystemStayOnTop = [fsStayOnTop, fsSplash]; // Cursor constants crHigh = TCursor(0); diff --git a/lcl/include/application.inc b/lcl/include/application.inc index 3bc68d30e2..7f3d22b7df 100644 --- a/lcl/include/application.inc +++ b/lcl/include/application.inc @@ -1271,7 +1271,7 @@ begin AForm := Screen.CustomForms[i]; if (AForm.Parent <> nil) or not AForm.Visible then Continue; - if (AForm.FormStyle in fsAllStayOnTop) then + if (AForm.FormStyle in fsAllNonSystemStayOnTop) then begin AForm.FormStyle := fsNormal; if FRestoreStayOnTop = nil then diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index 0541a979ea..5e5861abe7 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -1793,7 +1793,7 @@ Begin if OldFormStyle = fsSplash then BorderStyle := bsSizeable; if HandleAllocated then - TWSCustomFormClass(WidgetSetClass).SetFormStyle(Self, Value); + TWSCustomFormClass(WidgetSetClass).SetFormStyle(Self, Value, OldFormStyle); end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/qt/qtwsforms.pp b/lcl/interfaces/qt/qtwsforms.pp index 7f22131d47..0bf9bc2ed6 100644 --- a/lcl/interfaces/qt/qtwsforms.pp +++ b/lcl/interfaces/qt/qtwsforms.pp @@ -83,7 +83,7 @@ type class procedure DestroyHandle(const AWinControl: TWinControl); override; class procedure SetAllowDropFiles(const AForm: TCustomForm; AValue: Boolean); override; class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); override; - class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle: TFormStyle); override; + class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle, AOldFormStyle: TFormStyle); override; class procedure SetIcon(const AForm: TCustomForm; const Small, Big: HICON); override; class procedure SetPopupParent(const ACustomForm: TCustomForm; const APopupMode: TPopupMode; const APopupParent: TCustomForm); override; @@ -258,7 +258,7 @@ begin end; class procedure TQtWSCustomForm.SetFormStyle(const AForm: TCustomform; - const AFormStyle: TFormStyle); + const AFormStyle, AOldFormStyle: TFormStyle); var QtWin: TQtMainWindow; begin diff --git a/lcl/interfaces/win32/win32callback.inc b/lcl/interfaces/win32/win32callback.inc index cef792514c..75c158dad1 100644 --- a/lcl/interfaces/win32/win32callback.inc +++ b/lcl/interfaces/win32/win32callback.inc @@ -1437,12 +1437,12 @@ begin if Window = TWin32WidgetSet(WidgetSet).FAppHandle then if WParam = 0 then begin -// RemoveStayOnTopFlags(Window); + RemoveStayOnTopFlags(Window); DisabledForms := Screen.DisableForms(nil, DisabledForms); end else begin -// RestoreStayOnTopFlags(Window); + RestoreStayOnTopFlags(Window); Screen.EnableForms(DisabledForms); end; @@ -1509,6 +1509,13 @@ begin WM_HELP: if Window = Win32WidgetSet.AppHandle then Application.HelpCommand(0, LParam); + WM_HOTKEY: + begin + LMessage.Msg := WM_HOTKEY; + LMessage.WParam := WParam; + LMessage.LParam := LParam; + WinProcess := false; + end; WM_HSCROLL, WM_VSCROLL: begin @@ -2178,14 +2185,14 @@ begin if WParam <> 0 then // activated begin //WriteLn('Restore'); -// RestoreStayOnTopFlags(Window); + RestoreStayOnTopFlags(Window); if assigned(Application) then Application.IntfAppActivate; end else begin // deactivated //WriteLn('Remove'); -// RemoveStayOnTopFlags(Window); + RemoveStayOnTopFlags(Window); if assigned(Application) then Application.IntfAppDeactivate; end; diff --git a/lcl/interfaces/win32/win32proc.pp b/lcl/interfaces/win32/win32proc.pp index 9d2975a189..2792c5908f 100644 --- a/lcl/interfaces/win32/win32proc.pp +++ b/lcl/interfaces/win32/win32proc.pp @@ -1072,11 +1072,23 @@ function EnumStayOnTopRemove(Handle: HWND; Param: LPARAM): WINBOOL; stdcall; var AStyle: DWord; StayOnTopWindowsInfo: PStayOnTopWindowsInfo absolute Param; + lWindowInfo: PWin32WindowInfo; + lWinControl: TWinControl; begin Result := True; AStyle := GetWindowLong(Handle, GWL_EXSTYLE); if (AStyle and WS_EX_TOPMOST) <> 0 then // if stay on top then begin + // Don't remove system-wide stay on top + lWindowInfo := GetWin32WindowInfo(Handle); + if (lWindowInfo <> nil) then + begin + lWinControl := lWindowInfo^.WinControl; + if (lWinControl <> nil) and (lWinControl is TCustomForm) + and (TCustomForm(lWinControl).FormStyle = fsSystemStayOnTop) then + Exit; + end; + StayOnTopWindowsInfo^.StayOnTopList.Add(Pointer(Handle)); SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_NOOWNERZORDER or SWP_NOSENDCHANGING); diff --git a/lcl/interfaces/win32/win32wsforms.pp b/lcl/interfaces/win32/win32wsforms.pp index be80f60ba5..455cc405e4 100644 --- a/lcl/interfaces/win32/win32wsforms.pp +++ b/lcl/interfaces/win32/win32wsforms.pp @@ -83,7 +83,7 @@ type AWidth, AHeight: Integer); override; class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); override; - class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle: TFormStyle); override; + class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle, AOldFormStyle: TFormStyle); override; class procedure SetIcon(const AForm: TCustomForm; const Small, Big: HICON); override; class procedure ShowModal(const ACustomForm: TCustomForm); override; class procedure SetPopupParent(const ACustomForm: TCustomForm; @@ -440,9 +440,18 @@ begin end; class procedure TWin32WSCustomForm.SetFormStyle(const AForm: TCustomform; - const AFormStyle: TFormStyle); + const AFormStyle, AOldFormStyle: TFormStyle); begin - RecreateWnd(AForm); + // Some changes don't require RecreateWnd + + // From normal to StayOnTop + if (AOldFormStyle = fsNormal) and (AFormStyle in fsAllStayOnTop) then + SetWindowPos(AForm.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE) + // From StayOnTop to normal + else if (AOldFormStyle in fsAllStayOnTop) and (AFormStyle = fsNormal) then + SetWindowPos(AForm.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE) + else + RecreateWnd(AForm); end; class procedure TWin32WSCustomForm.SetBounds(const AWinControl: TWinControl; diff --git a/lcl/widgetset/wsforms.pp b/lcl/widgetset/wsforms.pp index cd322ecc55..f5d31b5d1b 100644 --- a/lcl/widgetset/wsforms.pp +++ b/lcl/widgetset/wsforms.pp @@ -88,7 +88,7 @@ type const ABorderIcons: TBorderIcons); virtual; class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); virtual; - class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle: TFormStyle); virtual; + class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle, AOldFormStyle: TFormStyle); virtual; class procedure SetIcon(const AForm: TCustomForm; const Small, Big: HICON); virtual; class procedure ShowModal(const ACustomForm: TCustomForm); virtual; class procedure SetPopupParent(const ACustomForm: TCustomForm; @@ -162,7 +162,7 @@ begin end; class procedure TWSCustomForm.SetFormStyle(const AForm: TCustomform; - const AFormStyle: TFormStyle); + const AFormStyle, AOldFormStyle: TFormStyle); begin end;