vcl/inc/salvtables.hxx |    2 +-
 vcl/qt5/QtInstance.cxx |   12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

New commits:
commit 1e2836665a1839f61cd8bfa46c54687f010e7e9d
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Aug 30 18:17:53 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Aug 31 18:28:36 2024 +0200

    tdf#162696 tdf#130857 qt weld: Get parent via SalInstanceWidget
    
    Since only welding for simple message dialogs has been
    implemented for the Qt based VCL plugins so far, the
    `weld::Widget*` parent passed to `QtInstance::CreateMessageDialog`
    is usually not a `QtInstanceWidget`.
    
    The initial implementation to get a parent from
    
        commit 9e40fc8c9458b937200ea56c96b89113c74b67f5
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Wed Feb 14 10:54:59 2024 +0100
    
            tdf#130857 qt weld: Set msg dialog parent
    
    implemented a fallback to use of the currently active
    window if no native Qt parent is set.
    
    That is however not sufficient to reliably set the
    correct parent for the QMessageBox for the tdf#162696
    scenario, where the "Extension" dialog that is the
    parent and the message box and the message box itself
    are created shortly after each other, and the extension
    dialog does not reliably have focus yet when the message
    box is created, so the start center window would sometimes
    be set as the parent of the message dialog instead.
    
    Adjust the logic to make use of the implementation detail
    that non-Qt parents are `SalInstanceWidget`s.
    Retrieve a `QWidget` to use as the parent via
    the `SalFrame`/`QtFrame` in that case.
    
    This makes setting the correct parent work for both,
    the case described in the commit message of the
    above-mentioned commit and for the tdf#162696
    case, fixing the issue mentioned in tdf#162696#c13:
    
    > One small thing I noticed is that after clicking OK on the warning
    > dialog, the Extensions dialog has to be manually brought into focus. So
    > it's not layered below the warning dialog during the first installation
    > action in a session.
    
    Change-Id: I4de403a8ed78a649a17f6cabc0e0f5fdecae09c3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172686
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index 200e0ef36bf5..ba7653a0fc40 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -183,7 +183,7 @@ public:
 
 class SalFlashAttention;
 
-class SalInstanceWidget : public virtual weld::Widget
+class VCL_DLLPUBLIC SalInstanceWidget : public virtual weld::Widget
 {
 protected:
     VclPtr<vcl::Window> m_xWidget;
diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx
index 4587ef6c7933..f650699bacdd 100644
--- a/vcl/qt5/QtInstance.cxx
+++ b/vcl/qt5/QtInstance.cxx
@@ -39,6 +39,7 @@
 #include <QtInstanceMessageDialog.hxx>
 
 #include <headless/svpvd.hxx>
+#include <salvtables.hxx>
 
 #include <QtCore/QAbstractEventDispatcher>
 #include <QtCore/QLibraryInfo>
@@ -827,8 +828,15 @@ weld::MessageDialog* 
QtInstance::CreateMessageDialog(weld::Widget* pParent,
             }
             else
             {
-                // the parent is not welded/not a native Qt widget; fall back 
to currently active window
-                pQtParent = QApplication::activeWindow();
+                // the parent is not welded/not a native Qt widget; get 
QWidget via frame
+                if (SalInstanceWidget* pSalWidget = 
dynamic_cast<SalInstanceWidget*>(pParent))
+                {
+                    if (vcl::Window* pWindow = pSalWidget->getWidget())
+                    {
+                        if (QtFrame* pFrame = 
static_cast<QtFrame*>(pWindow->ImplGetFrame()))
+                            pQtParent = pFrame->GetQWidget();
+                    }
+                }
             }
         }
 

Reply via email to