diff --git a/docs/xml/lcl/forms.xml b/docs/xml/lcl/forms.xml index 01ab6248f8..35270068c3 100644 --- a/docs/xml/lcl/forms.xml +++ b/docs/xml/lcl/forms.xml @@ -1500,13 +1500,13 @@ - default behavior - popup to mainform/taskbar window + modal: popup to mainform/taskbar window; non-modal: no window parent - popup to active form, and same as pmNone if no active form + modal & non-modal: popup to active form or if not available, to main form - popup to PopupParent, and same as pmNone if not exists + modal & non-modal: popup to PopupParent or if not available, to main form diff --git a/lcl/forms.pp b/lcl/forms.pp index e0685c3608..93b2bc2cd4 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -388,9 +388,9 @@ type ); TPopupMode = ( - pmNone, // default behavior - popup to mainform/taskbar window - pmAuto, // popup to active form and same as pmNone if no active form - pmExplicit // popup to PopupParent and same as pmNone if not exists + pmNone, // modal: popup to mainform/taskbar window; non-modal: no window parent + pmAuto, // modal & non-modal: popup to active form or if not available, to main form + pmExplicit // modal & non-modal: popup to PopupParent or if not available, to main form ); TCloseEvent = procedure(Sender: TObject; var CloseAction: TCloseAction) of object; @@ -594,6 +594,7 @@ type function FormIsUpdating: boolean; override; function GetFormImage: TBitmap; function GetRolesForControl(AControl: TControl): TControlRolesForForm; + function GetRealPopupParent: TCustomForm; procedure Hide; procedure IntfDropFiles(const FileNames: array of String); procedure IntfHelp(AComponent: TComponent); diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index ff6d698805..483e295f8c 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -360,10 +360,11 @@ begin if FPopupMode <> AValue then begin FPopupMode := AValue; - if FPopupMode = pmAuto then - PopupParent := nil; + if (FPopupMode in [pmAuto, pmNone]) and (PopupParent <> nil) then + PopupParent := nil + else if not (csDesigning in ComponentState) and HandleAllocated then - TWSCustomFormClass(WidgetSetClass).SetPopupParent(Self, PopupMode, PopupParent); + TWSCustomFormClass(WidgetSetClass).SetRealPopupParent(Self, GetRealPopupParent); end; end; @@ -380,7 +381,7 @@ begin FPopupMode := pmExplicit; end; if not (csDesigning in ComponentState) and HandleAllocated then - TWSCustomFormClass(WidgetSetClass).SetPopupParent(Self, PopupMode, PopupParent); + TWSCustomFormClass(WidgetSetClass).SetRealPopupParent(Self, GetRealPopupParent); end; end; @@ -1475,6 +1476,31 @@ begin end; end; +function TCustomForm.GetRealPopupParent: TCustomForm; +begin + Result := nil; + if (fsModal in FormState) or // always set WndParent of modal windows + (PopupMode in [pmAuto, pmExplicit]) // set WndParent of non-modal windows only for pmAuto, pmExplicit + then + begin + case PopupMode of + pmAuto: + begin + Result := Screen.ActiveForm; + if (Result<>nil) and (Result.FormStyle = fsSplash) then // ignore fsSplash + Result := nil; + end; + pmExplicit: Result := PopupParent; + end; + if (Result = nil) or not Result.HandleAllocated then + Result := Application.MainForm; + end; + if (Result <> nil) and not Result.HandleAllocated then + Result := nil; + if (Result = Self) then + Result := nil; +end; + procedure TCustomForm.DoAutoSize; begin //DebugLn(['TCustomForm.DoAutoSize ',DbgSName(Self),' ',WindowState=wsNormal,' ',fsDisableAutoSize in FFormState,' ',dbgs(BoundsRect),' ',dbgs(ClientRect)]); @@ -2039,6 +2065,8 @@ end; TCustomForm CreateParams ------------------------------------------------------------------------------} procedure TCustomForm.CreateParams(var Params : TCreateParams); +var + APopupParent: TCustomForm; begin inherited CreateParams(Params); with Params do @@ -2050,15 +2078,9 @@ begin begin if (Application.MainForm <> Self) then begin - case PopupMode of - pmNone:; - pmAuto: - if (Screen.ActiveForm <> nil) then - WndParent := Screen.ActiveForm.Handle; - pmExplicit: - if (PopupParent <> nil) then - WndParent := PopupParent.Handle; - end; + APopupParent := GetRealPopupParent; + if APopupParent <> nil then + WndParent := APopupParent.Handle; end; if (WndParent = 0) and (((Self = Application.MainForm) and Application.MainFormOnTaskBar) or (GetEffectiveShowInTaskBar = stAlways)) then diff --git a/lcl/interfaces/carbon/carbonwsforms.pp b/lcl/interfaces/carbon/carbonwsforms.pp index 08eb113d82..cb5142b287 100644 --- a/lcl/interfaces/carbon/carbonwsforms.pp +++ b/lcl/interfaces/carbon/carbonwsforms.pp @@ -76,8 +76,8 @@ type class procedure SetAlphaBlend(const ACustomForm: TCustomForm; const AlphaBlend: Boolean; const Alpha: Byte); override; class procedure SetFormStyle(const ACustomForm: TCustomForm; const ANewFormStyle, {%H-}AOldFormStyle: TFormStyle); override; - class procedure SetPopupParent(const ACustomForm: TCustomForm; - const {%H-}APopupMode: TPopupMode; const APopupParent: TCustomForm); override; + class procedure SetRealPopupParent(const ACustomForm: TCustomForm; + const APopupParent: TCustomForm); override; end; { TCarbonWSForm } @@ -338,10 +338,9 @@ begin Self, 'SetFormStyle', 'SetWindowGroup'); end; -class procedure TCarbonWSCustomForm.SetPopupParent(const ACustomForm:TCustomForm; - const APopupMode:TPopupMode;const APopupParent:TCustomForm); +class procedure TCarbonWSCustomForm.SetRealPopupParent( + const ACustomForm: TCustomForm; const APopupParent: TCustomForm); begin - //todo: better "popup-parent" hanlding if Assigned(APopupParent) and (APopupParent.Handle<>0) then begin SetWindowGroup( TCarbonWindow(ACustomForm.Handle).Window, GetWindowGroupOfClass(kHelpWindowClass)); diff --git a/lcl/interfaces/cocoa/cocoawsforms.pp b/lcl/interfaces/cocoa/cocoawsforms.pp index 118512d449..0eb98b2538 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pp +++ b/lcl/interfaces/cocoa/cocoawsforms.pp @@ -112,8 +112,8 @@ type class procedure SetBorderIcons(const AForm: TCustomForm; const ABorderIcons: TBorderIcons); override; class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); override; class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle, AOldFormStyle: TFormStyle); override; - class procedure SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); override; + class procedure SetRealPopupParent(const ACustomForm: TCustomForm; + const APopupParent: TCustomForm); override; {need to override these } class function GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean; override; @@ -660,30 +660,17 @@ begin end; end; -class procedure TCocoaWSCustomForm.SetPopupParent( - const ACustomForm: TCustomForm; const APopupMode: TPopupMode; - const APopupParent: TCustomForm); -var - PopupParent: TCustomForm; +class procedure TCocoaWSCustomForm.SetRealPopupParent( + const ACustomForm: TCustomForm; const APopupParent: TCustomForm); begin - if not ACustomForm.HandleAllocated then Exit; - case APopupMode of - pmNone: - PopupParent := nil; - pmAuto: - PopupParent := Screen.ActiveForm; - pmExplicit: - PopupParent := APopupParent; - end; - - if Assigned(PopupParent) then - NSWindow(PopupParent.Handle).addChildWindow_ordered(NSWindow(ACustomForm.Handle), NSWindowAbove) - else if Assigned(NSWindow(ACustomForm.Handle).parentWindow) then NSWindow(ACustomForm.Handle).parentWindow.removeChildWindow(NSWindow(ACustomForm.Handle)); + if Assigned(APopupParent) then + NSWindow(APopupParent.Handle).addChildWindow_ordered(NSWindow(ACustomForm.Handle), NSWindowAbove); end; -class function TCocoaWSCustomForm.GetClientBounds(const AWinControl: TWinControl; var ARect: TRect): Boolean; +class function TCocoaWSCustomForm.GetClientBounds( + const AWincontrol: TWinControl; var ARect: TRect): Boolean; begin Result := False; if not AWinControl.HandleAllocated then Exit; @@ -691,7 +678,8 @@ begin Result := True; end; -class function TCocoaWSCustomForm.GetClientRect(const AWinControl: TWinControl; var ARect: TRect): Boolean; +class function TCocoaWSCustomForm.GetClientRect(const AWincontrol: TWinControl; + var ARect: TRect): Boolean; var x, y: Integer; begin diff --git a/lcl/interfaces/customdrawn/customdrawnwsforms.pp b/lcl/interfaces/customdrawn/customdrawnwsforms.pp index 75ccd82aa4..f73ccede80 100644 --- a/lcl/interfaces/customdrawn/customdrawnwsforms.pp +++ b/lcl/interfaces/customdrawn/customdrawnwsforms.pp @@ -141,8 +141,8 @@ type class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); override; // class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle, AOldFormStyle: TFormStyle); override; -// class procedure SetPopupParent(const ACustomForm: TCustomForm; -// const APopupMode: TPopupMode; const APopupParent: TCustomForm); override; +// class procedure SetRealPopupParent(const ACustomForm: TCustomForm; +// const APopupParent: TCustomForm); override; class procedure SetIcon(const AForm: TCustomForm; const Small, Big: HICON); override; class procedure SetShowInTaskbar(const AForm: TCustomForm; const AValue: TShowInTaskbar); override; class procedure ShowModal(const ACustomForm: TCustomForm); override; diff --git a/lcl/interfaces/gtk/gtkwsforms.pp b/lcl/interfaces/gtk/gtkwsforms.pp index f4bab52e1b..17d0de0af5 100644 --- a/lcl/interfaces/gtk/gtkwsforms.pp +++ b/lcl/interfaces/gtk/gtkwsforms.pp @@ -79,8 +79,8 @@ type class procedure SetBorderIcons(const AForm: TCustomForm; const ABorderIcons: TBorderIcons); override; class procedure SetColor(const AWinControl: TWinControl); override; - class procedure SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); override; + class procedure SetRealPopupParent(const ACustomForm: TCustomForm; + const APopupParent: TCustomForm); override; end; { TGtkWSForm } @@ -526,23 +526,13 @@ begin TGtkWSWinControl.SetColor(AWinControl); end; -class procedure TGtkWSCustomForm.SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); -var - PopupParent: TCustomForm; +class procedure TGtkWSCustomForm.SetRealPopupParent( + const ACustomForm: TCustomForm; const APopupParent: TCustomForm); begin - if not WSCheckHandleAllocated(ACustomForm, 'SetPopupParent') then Exit; + if not WSCheckHandleAllocated(ACustomForm, 'SetRealPopupParent') then Exit; - case APopupMode of - pmNone: - PopupParent := nil; - pmAuto: - PopupParent := Screen.ActiveForm; - pmExplicit: - PopupParent := APopupParent; - end; - if PopupParent <> nil then - gtk_window_set_transient_for(PGtkWindow(ACustomForm.Handle), PGtkWindow(PopupParent.Handle)) + if APopupParent <> nil then + gtk_window_set_transient_for(PGtkWindow(ACustomForm.Handle), PGtkWindow(APopupParent.Handle)) else gtk_window_set_transient_for(PGtkWindow(ACustomForm.Handle), nil); end; diff --git a/lcl/interfaces/gtk2/gtk2wsforms.pp b/lcl/interfaces/gtk2/gtk2wsforms.pp index b1f95cfaa4..19d2b2acf9 100644 --- a/lcl/interfaces/gtk2/gtk2wsforms.pp +++ b/lcl/interfaces/gtk2/gtk2wsforms.pp @@ -84,8 +84,8 @@ type class procedure SetBorderIcons(const AForm: TCustomForm; const ABorderIcons: TBorderIcons); override; class procedure SetColor(const AWinControl: TWinControl); override; - class procedure SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); override; + class procedure SetRealPopupParent(const ACustomForm: TCustomForm; + const APopupParent: TCustomForm); override; end; { TGtk2WSForm } @@ -680,7 +680,7 @@ var {$IFDEF HASX} TempGdkWindow: PGdkWindow; {$ENDIF} - AForm: TCustomForm; + AForm, APopupParent: TCustomForm; GtkWindow: PGtkWindow; Geometry: TGdkGeometry; @@ -778,11 +778,11 @@ begin if AWinControl.HandleObjectShouldBeVisible and not (csDesigning in AForm.ComponentState) and not (AForm.FormStyle in fsAllStayOnTop) and - not (fsModal in AForm.FormState) and - (AForm.PopupMode = pmExplicit) and - (AForm.PopupParent = nil) then + not (fsModal in AForm.FormState) then begin - SetPopupParent(AForm, AForm.PopupMode, AForm.PopupParent); + APopupParent := AForm.GetRealPopupParent; + if (APopupParent <> nil) then + SetRealPopupParent(AForm, APopupParent); end; {$ENDIF} @@ -842,27 +842,13 @@ begin TGtk2WSWinControl.SetColor(AWinControl); end; -class procedure TGtk2WSCustomForm.SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); -var - PopupParent: TCustomForm; +class procedure TGtk2WSCustomForm.SetRealPopupParent( + const ACustomForm: TCustomForm; const APopupParent: TCustomForm); begin - if not WSCheckHandleAllocated(ACustomForm, 'SetPopupParent') then Exit; + if not WSCheckHandleAllocated(ACustomForm, 'SetRealPopupParent') then Exit; - case APopupMode of - pmNone: - PopupParent := nil; - pmAuto: - PopupParent := Screen.ActiveForm; - pmExplicit: - begin - PopupParent := APopupParent; - if PopupParent = nil then - PopupParent := Application.MainForm; - end; - end; - if PopupParent <> nil then - gtk_window_set_transient_for({%H-}PGtkWindow(ACustomForm.Handle), {%H-}PGtkWindow(PopupParent.Handle)) + if APopupParent <> nil then + gtk_window_set_transient_for({%H-}PGtkWindow(ACustomForm.Handle), {%H-}PGtkWindow(APopupParent.Handle)) else gtk_window_set_transient_for({%H-}PGtkWindow(ACustomForm.Handle), nil); end; diff --git a/lcl/interfaces/gtk3/gtk3wsforms.pp b/lcl/interfaces/gtk3/gtk3wsforms.pp index 43043f1e7e..e061486fa4 100644 --- a/lcl/interfaces/gtk3/gtk3wsforms.pp +++ b/lcl/interfaces/gtk3/gtk3wsforms.pp @@ -95,8 +95,8 @@ type 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; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); override; + class procedure SetRealPopupParent(const ACustomForm: TCustomForm; + const APopupParent: TCustomForm); override; class procedure SetShowInTaskbar(const AForm: TCustomForm; const AValue: TShowInTaskbar); override; class procedure SetZPosition(const AWinControl: TWinControl; const APosition: TWSZPosition); override; class function GetDefaultColor(const AControl: TControl; const ADefaultColorType: TDefaultColorType): TColor; override; @@ -387,20 +387,20 @@ begin {$ENDIF} end; -class procedure TGtk3WSCustomForm.SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); +class procedure TGtk3WSCustomForm.SetRealPopupParent( + const ACustomForm: TCustomForm; const APopupParent: TCustomForm); begin - if not WSCheckHandleAllocated(ACustomForm, 'ShowPopupParent') then + if not WSCheckHandleAllocated(ACustomForm, 'SetRealPopupParent') then Exit; {$IFDEF GTK3DEBUGCORE} - DebugLn('TGtk3WSCustomForm.SetPopupParent'); + DebugLn('TGtk3WSCustomForm.SetRealPopupParent'); {$ENDIF} end; class procedure TGtk3WSCustomForm.SetAlphaBlend(const ACustomForm: TCustomForm; const AlphaBlend: Boolean; const Alpha: Byte); begin - if not WSCheckHandleAllocated(ACustomForm, 'ShowAlphaBlend') then + if not WSCheckHandleAllocated(ACustomForm, 'SetAlphaBlend') then Exit; {$IFDEF GTK3DEBUGCORE} DebugLn('TGtk3WSCustomForm.SetAlphaBlend'); diff --git a/lcl/interfaces/qt/qtint.pp b/lcl/interfaces/qt/qtint.pp index 369491d3a8..c71e9b989f 100644 --- a/lcl/interfaces/qt/qtint.pp +++ b/lcl/interfaces/qt/qtint.pp @@ -246,6 +246,7 @@ type function X11Raise(AHandle: HWND): boolean; function X11GetActiveWindow: QWidgetH; function GetWindowManager: String; + function SetTransientForHint(Widget: QWidgetH; ATransientWin: QWidgetH): boolean; procedure SetSkipX11Taskbar(Widget: QWidgetH; const ASkipTaskBar: Boolean); {check if XWindow have _NET_WM_STATE_ABOVE and our form doesn''t know anything about it} function GetAlwaysOnTopX11(Widget: QWidgetH): boolean; diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index e580693642..38071355b1 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -622,7 +622,6 @@ type LayoutWidget: QBoxLayoutH; FCWEventHook: QObject_hookH; FShowOnTaskBar: Boolean; - FPopupMode: TPopupMode; FPopupParent: QWidgetH; FMDIStateHook: QMdiSubWindow_hookH; protected @@ -669,7 +668,7 @@ type procedure SlotActivateWindow(vActivate: Boolean); cdecl; procedure slotWindowStateChange; cdecl; procedure setShowInTaskBar(AValue: Boolean); - procedure setPopupParent(APopupMode: TPopupMode; NewParent: QWidgetH); + procedure setRealPopupParent(NewParent: QWidgetH); property Blocked: Boolean read FBlocked write FBlocked; property ShowOnTaskBar: Boolean read FShowOnTaskBar; public @@ -6569,7 +6568,6 @@ begin QtFormBorderStyle := Ord(bsSizeable); QtFormStyle := Ord(fsNormal); FHasPaint := True; - FPopupMode := pmNone; FPopupParent := nil; MDIAreaHandle := nil; MDIChildArea := nil; @@ -6711,42 +6709,8 @@ begin end; procedure TQtMainWindow.UpdateParent; -var - NewParent: QWidgetH; begin - NewParent := nil; - case FPopupMode of - pmNone: ;// no popup parent - pmAuto: - // active form is parent - if Screen.ActiveForm <> nil then - NewParent := TQtWidget(Screen.ActiveForm.Handle).Widget; - pmExplicit: - begin - // parent is FPopupParent - if FPopupParent <> nil then - NewParent := FPopupParent - {$IFDEF HASX11} - else - begin - if not IsMainForm then - begin - NewParent := TQtMainWindow(Application.MainForm.Handle).Widget; - setWindowFlags(windowFlags or QtSheet); - end; - end; - {$ENDIF} - end; - end; - if (NewParent = nil) and (FPopupMode <> pmNone) and - not FShowOnTaskBar and not IsMainForm then - NewParent := TQtMainWindow(Application.MainForm.Handle).Widget; - {$IFDEF MSWINDOWS} - if (NewParent = nil) and (FPopupMode = pmNone) and - not FShowOnTaskBar and not IsMainForm then - NewParent := TQtMainWindow(Application.MainForm.Handle).Widget; - {$ENDIF} - ChangeParent(NewParent); + ChangeParent(FPopupParent); end; {------------------------------------------------------------------------------ @@ -7367,9 +7331,8 @@ begin {$ENDIF} end; -procedure TQtMainWindow.setPopupParent(APopupMode: TPopupMode; NewParent: QWidgetH); +procedure TQtMainWindow.setRealPopupParent(NewParent: QWidgetH); begin - FPopupMode := APopupMode; FPopupParent := NewParent; UpdateParent; end; diff --git a/lcl/interfaces/qt/qtwsforms.pp b/lcl/interfaces/qt/qtwsforms.pp index 5d6baba571..fc49b95937 100644 --- a/lcl/interfaces/qt/qtwsforms.pp +++ b/lcl/interfaces/qt/qtwsforms.pp @@ -80,8 +80,8 @@ type class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); 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; + class procedure SetRealPopupParent(const ACustomForm: TCustomForm; + const APopupParent: TCustomForm); override; class procedure SetShowInTaskbar(const AForm: TCustomForm; const AValue: TShowInTaskbar); override; class procedure ShowHide(const AWinControl: TWinControl); override; //TODO: rename to SetVisible(control, visible) class procedure ShowModal(const ACustomForm: TCustomForm); override; @@ -145,7 +145,7 @@ class function TQtWSCustomForm.CreateHandle(const AWinControl: TWinControl; var QtMainWindow: TQtMainWindow; Str: WideString; - PopupParent: QWidgetH; + APopupParent: TCustomForm; AForm: TCustomForm; begin {$ifdef VerboseQt} @@ -191,11 +191,9 @@ begin not (csDesigning in AForm.ComponentState)) {$endif} then QtMainWindow.setShowInTaskBar(False); - if Assigned(AForm.PopupParent) and AForm.PopupParent.HandleAllocated then - PopupParent := TQtWidget(AForm.PopupParent.Handle).Widget - else - PopupParent := nil; - QtMainWindow.setPopupParent(AForm.PopupMode, PopupParent); + APopupParent := AForm.GetRealPopupParent; + if APopupParent<>nil then + QtMainWindow.setRealPopupParent(TQtWidget(APopupParent.Handle).Widget); end; {$IFDEF HASX11} @@ -329,18 +327,18 @@ begin TQtWidget(AForm.Handle).setWindowIcon(nil); end; -class procedure TQtWSCustomForm.SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); +class procedure TQtWSCustomForm.SetRealPopupParent( + const ACustomForm: TCustomForm; const APopupParent: TCustomForm); var PopupParent: QWidgetH; begin if not ACustomForm.HandleAllocated or (csDestroying in ACustomForm.ComponentState) then exit; - if Assigned(APopupParent) and APopupParent.HandleAllocated then + if Assigned(APopupParent) then PopupParent := TQtWidget(APopupParent.Handle).Widget else PopupParent := nil; - TQtMainWindow(ACustomForm.Handle).setPopupParent(APopupMode, PopupParent); + TQtMainWindow(ACustomForm.Handle).setRealPopupParent(PopupParent); end; {------------------------------------------------------------------------------ @@ -382,6 +380,7 @@ var Widget: TQtMainWindow; R: TRect; {$IFDEF HASX11} + APopupParent: TCustomForm; ActiveWin: HWND; W: QWidgetH; {$ENDIF} @@ -524,7 +523,7 @@ begin not (fsModal in TForm(AWinControl).FormState) and (TForm(AWinControl).FormStyle <> fsMDIChild) and (QApplication_activeModalWidget() <> nil) then - TQtMainWindow(Widget).setPopupParent(pmExplicit, + TQtMainWindow(Widget).setRealPopupParent( QApplication_activeModalWidget()); end else begin @@ -542,18 +541,15 @@ begin if AWinControl.HandleObjectShouldBeVisible and not (TCustomForm(AWinControl).FormStyle in fsAllStayOnTop) and not (fsModal in TCustomForm(AWinControl).FormState) and - (TCustomForm(AWinControl).FormStyle <> fsMDIChild) and - (TCustomForm(AWinControl).PopupMode = pmAuto) and - (TCustomForm(AWinControl).BorderStyle = bsNone) and - (TCustomForm(AWinControl).PopupParent = nil) then + (TCustomForm(AWinControl).FormStyle <> fsMDIChild) then begin - W := QApplication_activeWindow; - Flags := Widget.windowFlags; - if W <> nil then - Widget.setParent(W) - else - Widget.setParent(QApplication_desktop); - Widget.setWindowFlags(Flags or QtTool); + APopupParent := TCustomForm(AWinControl).GetRealPopupParent; + if (APopupParent <> nil) then + begin + Widget.setParent(TQtWidget(APopupParent.Handle).Widget); + {use direct X11 call instead of QtTool flag.issue #29253} + SetTransientForHint(Widget.Widget, TQtWidget(APopupParent.Handle).Widget); + end; end; {$ENDIF} end; diff --git a/lcl/interfaces/qt/qtx11.inc b/lcl/interfaces/qt/qtx11.inc index 26a0111c22..09ea598bc9 100644 --- a/lcl/interfaces/qt/qtx11.inc +++ b/lcl/interfaces/qt/qtx11.inc @@ -214,6 +214,25 @@ begin end; end; +function SetTransientForHint(Widget: QWidgetH; ATransientWin: QWidgetH): boolean; +var + Display: PDisplay; + AWin: LongWord; +begin + Result := False; + if Widget = nil then + exit; + Display := QX11Info_display(); + + if Display = nil then + exit; + if ATransientWin <> nil then + AWin := QWidget_winID(ATransientWin) + else + AWin := 0; + Result := XSetTransientForHint(Display, QWidget_winId(Widget), AWin) = 1; +end; + procedure SetSkipX11Taskbar(Widget: QWidgetH; const ASkipTaskBar: Boolean); const _NET_WM_STATE_REMOVE = 0; diff --git a/lcl/interfaces/win32/win32wsforms.pp b/lcl/interfaces/win32/win32wsforms.pp index 69f2ba5c85..f4b2088c2f 100644 --- a/lcl/interfaces/win32/win32wsforms.pp +++ b/lcl/interfaces/win32/win32wsforms.pp @@ -78,8 +78,8 @@ type 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; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); override; + class procedure SetRealPopupParent(const ACustomForm: TCustomForm; + const APopupParent: TCustomForm); override; class procedure SetShowInTaskbar(const AForm: TCustomForm; const AValue: TShowInTaskbar); override; class procedure ShowHide(const AWinControl: TWinControl); override; end; @@ -637,8 +637,8 @@ begin RDW_INVALIDATE or RDW_FRAME or RDW_NOCHILDREN or RDW_ERASE); end; -class procedure TWin32WSCustomForm.SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); +class procedure TWin32WSCustomForm.SetRealPopupParent( + const ACustomForm: TCustomForm; const APopupParent: TCustomForm); begin // changing parent is not possible without handle recreation RecreateWnd(ACustomForm); diff --git a/lcl/widgetset/wsforms.pp b/lcl/widgetset/wsforms.pp index 3c85bab64d..85430dff75 100644 --- a/lcl/widgetset/wsforms.pp +++ b/lcl/widgetset/wsforms.pp @@ -86,8 +86,8 @@ type class procedure SetIcon(const AForm: TCustomForm; const Small, Big: HICON); virtual; class procedure ShowModal(const ACustomForm: TCustomForm); virtual; class procedure SetModalResult(const ACustomForm: TCustomForm; ANewValue: TModalResult); virtual; - class procedure SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); virtual; + class procedure SetRealPopupParent(const ACustomForm: TCustomForm; + const APopupParent: TCustomForm); virtual; class procedure SetShowInTaskbar(const AForm: TCustomForm; const AValue: TShowInTaskbar); virtual; class procedure SetZPosition(const AWinControl: TWinControl; const APosition: TWSZPosition); virtual; class function GetDefaultColor(const AControl: TControl; const ADefaultColorType: TDefaultColorType): TColor; override; @@ -199,8 +199,8 @@ class procedure TWSCustomForm.SetModalResult(const ACustomForm: TCustomForm; begin end; -class procedure TWSCustomForm.SetPopupParent(const ACustomForm: TCustomForm; - const APopupMode: TPopupMode; const APopupParent: TCustomForm); +class procedure TWSCustomForm.SetRealPopupParent( + const ACustomForm: TCustomForm; const APopupParent: TCustomForm); begin end;