vcl/win/window/salframe.cxx |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

New commits:
commit a49245e04d45735aa76ad7720657c83530ba9ed8
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Mon Aug 29 13:57:10 2022 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Mon Aug 29 15:34:17 2022 +0200

    Don't position dialogs relative to other dialogs
    
    When calling setPosSize on a dialog, and there are other dialogs on top of 
it,
    the dialog was positioned relative to its parent dialog.
    
    Fix this, so that dialogs are always positioned relative to the main window 
(if there is one).
    
    Revert of/Follow up to 8750c812c9b808ee980f7e0ce0e6ce91e75e1424
    
    Change-Id: I69f189865b118f9bc20077d48591fbd9e83b014f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138994
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index da8a12bf81a9..0f2d18547bc4 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -1263,23 +1263,30 @@ void WinSalFrame::SetPosSize( tools::Long nX, 
tools::Long nY, tools::Long nWidth
     nWidth  = aWinRect.right - aWinRect.left + 1;
     nHeight = aWinRect.bottom - aWinRect.top + 1;
 
-    if ( !(nPosSize & SWP_NOMOVE) && ::GetParent( mhWnd ) )
+    // For dialogs (WS_POPUP && WS_DLGFRAME), we need to find the "real" 
parent,
+    // in case multiple dialogs are stacked on each other
+    // (wo don't want to position the second dialog relative to the first one, 
but relative to the main window)
+    HWND hWndParent = ImplGetParentHwnd(mhWnd);
+    while ( hWndParent && (GetWindowStyle( hWndParent ) & WS_POPUP) &&  
(GetWindowStyle( hWndParent ) & WS_DLGFRAME) )
+    {
+        hWndParent = ::ImplGetParentHwnd( hWndParent );
+    }
+
+    if ( !(nPosSize & SWP_NOMOVE) && hWndParent )
     {
             RECT aParentRect;
-            GetClientRect( ImplGetParentHwnd( mhWnd ), &aParentRect );
+            GetClientRect( hWndParent, &aParentRect );
             if( AllSettings::GetLayoutRTL() )
                 nX = (aParentRect.right - aParentRect.left) - nWidth-1 - nX;
 
-            //#110386#, do not transform coordinates for system child windows 
and dialogs
-            if( !(GetWindowStyle( mhWnd ) & WS_CHILD) &&
-                !(GetWindowStyle( mhWnd ) & WS_DLGFRAME) )
+            //#110386#, do not transform coordinates for system child windows
+            if( !(GetWindowStyle( mhWnd ) & WS_CHILD) )
             {
                 POINT aPt;
                 aPt.x = nX;
                 aPt.y = nY;
 
-                HWND parentHwnd = ImplGetParentHwnd( mhWnd );
-                WinSalFrame* pParentFrame = GetWindowPtr( parentHwnd );
+                WinSalFrame* pParentFrame = GetWindowPtr( hWndParent );
                 if ( pParentFrame && pParentFrame->mnShowState == 
SW_SHOWMAXIMIZED )
                 {
                     // #i42485#: parent will be shown maximized in which case
@@ -1289,7 +1296,7 @@ void WinSalFrame::SetPosSize( tools::Long nX, tools::Long 
nY, tools::Long nWidth
                     aPt.y +=  pParentFrame->maGeometry.y();
                 }
                 else
-                    ClientToScreen( parentHwnd, &aPt );
+                    ClientToScreen( hWndParent, &aPt );
 
                 nX = aPt.x;
                 nY = aPt.y;

Reply via email to