vcl/inc/qt5/Qt5Frame.hxx       |    3 ---
 vcl/inc/qt5/Qt5Object.hxx      |    2 ++
 vcl/inc/salobj.hxx             |    7 ++++---
 vcl/qt5/Qt5Frame.cxx           |   24 ++++++++++--------------
 vcl/qt5/Qt5Object.cxx          |   12 ++++++++++++
 vcl/source/window/syschild.cxx |    6 ++++--
 6 files changed, 32 insertions(+), 22 deletions(-)

New commits:
commit a7ab534afee3d92d92c51759dcb733da6545d7a2
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Sun Jun 2 21:01:33 2019 +0000
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Thu Jun 13 07:00:03 2019 +0200

    tdf#125692 SalObject always holds a SystemChildWindow
    
    Let's just face reality and store it as a VclPtr.
    
    And this is needed, because Qt, like VCL, uses deferred deletion,
    and has no way to filter events to QObjects out of its event queue
    easily. This way the qt5 plugin can report focus changes for
    SalObjects without a crash, which happens when you close a
    presentation with a video by click.
    
    And in addition it reverts the workaround introduced in commit
    e770bacc85a0 ("Qt5 workaround modal change after show bug"), as it
    seems this bug is a use-after-free error, introduced by LO.
    Thanks Michael Weghorn for catching that!
    
    Maybe someone should also rename SalObject...
    
    Change-Id: I0bc64ea64f95dfc7a838799c4a04de183adfefcf
    Reviewed-on: https://gerrit.libreoffice.org/73567
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>
    (cherry picked from commit 2dc6bdd1d5789ace0500cad90f5d2eb930888bb9)
    Reviewed-on: https://gerrit.libreoffice.org/73921

diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx
index 3b590bd8e28c..c70171869aa8 100644
--- a/vcl/inc/qt5/Qt5Frame.hxx
+++ b/vcl/inc/qt5/Qt5Frame.hxx
@@ -111,9 +111,6 @@ class VCLPLUG_QT5_PUBLIC Qt5Frame : public QObject, public 
SalFrame
     void TriggerPaintEvent();
     void TriggerPaintEvent(QRect aRect);
 
-private:
-    void setVisible(bool);
-
 Q_SIGNALS:
     void tooltipRequest(const OUString& rTooltip);
 
diff --git a/vcl/inc/qt5/Qt5Object.hxx b/vcl/inc/qt5/Qt5Object.hxx
index e27d549ca51d..6bfdd81b0327 100644
--- a/vcl/inc/qt5/Qt5Object.hxx
+++ b/vcl/inc/qt5/Qt5Object.hxx
@@ -66,6 +66,8 @@ class Qt5ObjectWindow : public QWindow
     Qt5Object& m_rParent;
 
     bool event(QEvent*) override;
+    void focusInEvent(QFocusEvent*) override;
+    void focusOutEvent(QFocusEvent*) override;
     void mousePressEvent(QMouseEvent*) override;
     void mouseReleaseEvent(QMouseEvent*) override;
     // keyPressEvent(QKeyEvent*) is handled via event(QEvent*); see comment in 
Qt5Widget::event
diff --git a/vcl/inc/salobj.hxx b/vcl/inc/salobj.hxx
index 56ca04985a7d..83024fec339d 100644
--- a/vcl/inc/salobj.hxx
+++ b/vcl/inc/salobj.hxx
@@ -21,16 +21,17 @@
 #define INCLUDED_VCL_INC_SALOBJ_HXX
 
 #include <vcl/dllapi.h>
+#include <vcl/syschild.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
 #include "salwtype.hxx"
 
 struct SystemEnvData;
 
-typedef void (*SALOBJECTPROC)( void* pInst, SalObjEvent nEvent );
+typedef void (*SALOBJECTPROC)(SystemChildWindow* pInst, SalObjEvent nEvent);
 
 class VCL_PLUGIN_PUBLIC SalObject
 {
-    void*               m_pInst;
+    VclPtr<SystemChildWindow> m_pInst;
     SALOBJECTPROC       m_pCallback;
     bool                m_bMouseTransparent:1,
                         m_bEraseBackground:1;
@@ -54,7 +55,7 @@ public:
 
     virtual const SystemEnvData*    GetSystemData() const = 0;
 
-    void                            SetCallback( void* pInst, SALOBJECTPROC 
pProc )
+    void                            SetCallback( SystemChildWindow* pInst, 
SALOBJECTPROC pProc )
                                         { m_pInst = pInst; m_pCallback = 
pProc; }
     void                            CallCallback( SalObjEvent nEvent )
                                         { if (m_pCallback) m_pCallback( 
m_pInst, nEvent ); }
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index 541bb4b2e7ce..7a2c67b809d5 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -33,6 +33,7 @@
 #include <QtCore/QMimeData>
 #include <QtCore/QPoint>
 #include <QtCore/QSize>
+#include <QtCore/QThread>
 #include <QtGui/QIcon>
 #include <QtGui/QWindow>
 #include <QtGui/QScreen>
@@ -360,8 +361,6 @@ void Qt5Frame::DrawMenuBar() { /* not needed */}
 
 void Qt5Frame::SetExtendedFrameStyle(SalExtStyle /*nExtStyle*/) { /* not 
needed */}
 
-void Qt5Frame::setVisible(bool bVisible) { asChild()->setVisible(bVisible); }
-
 void Qt5Frame::Show(bool bVisible, bool /*bNoActivate*/)
 {
     assert(m_pQWidget);
@@ -371,7 +370,7 @@ void Qt5Frame::Show(bool bVisible, bool /*bNoActivate*/)
 
     auto* pSalInst(static_cast<Qt5Instance*>(GetSalData()->m_pInstance));
     assert(pSalInst);
-    pSalInst->RunInMainThread([this, bVisible]() { setVisible(bVisible); });
+    pSalInst->RunInMainThread([this, bVisible]() { 
asChild()->setVisible(bVisible); });
 }
 
 void Qt5Frame::SetMinClientSize(long nWidth, long nHeight)
@@ -506,21 +505,18 @@ void Qt5Frame::SetModal(bool bModal)
         auto* pSalInst(static_cast<Qt5Instance*>(GetSalData()->m_pInstance));
         assert(pSalInst);
         pSalInst->RunInMainThread([this, bModal]() {
-            bool wasVisible = windowHandle()->isVisible();
+
+            QWidget* const pChild = asChild();
+            const bool bWasVisible = pChild->isVisible();
 
             // modality change is only effective if the window is hidden
-            if (wasVisible)
-            {
-                windowHandle()->hide();
-            }
+            if (bWasVisible)
+                pChild->hide();
 
-            windowHandle()->setModality(bModal ? Qt::WindowModal : 
Qt::NonModal);
+            pChild->setWindowModality(bModal ? Qt::WindowModal : Qt::NonModal);
 
-            // and shown again if it was visible
-            if (wasVisible)
-            {
-                windowHandle()->show();
-            }
+            if (bWasVisible)
+                pChild->show();
         });
     }
 }
diff --git a/vcl/qt5/Qt5Object.cxx b/vcl/qt5/Qt5Object.cxx
index 205c8b918535..cf0bd05b89cf 100644
--- a/vcl/qt5/Qt5Object.cxx
+++ b/vcl/qt5/Qt5Object.cxx
@@ -109,6 +109,18 @@ Qt5ObjectWindow::Qt5ObjectWindow(Qt5Object& rParent)
     assert(m_rParent.frame() && m_rParent.frame()->GetQWidget());
 }
 
+void Qt5ObjectWindow::focusInEvent(QFocusEvent* pEvent)
+{
+    m_rParent.CallCallback(SalObjEvent::GetFocus);
+    QWindow::focusInEvent(pEvent);
+}
+
+void Qt5ObjectWindow::focusOutEvent(QFocusEvent* pEvent)
+{
+    m_rParent.CallCallback(SalObjEvent::LoseFocus);
+    QWindow::focusOutEvent(pEvent);
+}
+
 void Qt5ObjectWindow::mousePressEvent(QMouseEvent* pEvent)
 {
     m_rParent.CallCallback(SalObjEvent::ToTop);
diff --git a/vcl/source/window/syschild.cxx b/vcl/source/window/syschild.cxx
index 28063ce19c63..e6f3e6013400 100644
--- a/vcl/source/window/syschild.cxx
+++ b/vcl/source/window/syschild.cxx
@@ -42,9 +42,9 @@
 
 using namespace ::com::sun::star;
 
-static void ImplSysChildProc( void* pInst, SalObjEvent nEvent )
+static void ImplSysChildProc( SystemChildWindow* pInst, SalObjEvent nEvent )
 {
-    VclPtr<SystemChildWindow> pWindow = static_cast<SystemChildWindow*>(pInst);
+    VclPtr<SystemChildWindow> pWindow = pInst;
 
     switch ( nEvent )
     {
@@ -68,6 +68,8 @@ static void ImplSysChildProc( void* pInst, SalObjEvent nEvent 
)
         case SalObjEvent::LoseFocus:
             // trigger a LoseFocus which matches the status
             // of the window with matching Activate-Status
+            if (pWindow->IsDisposed())
+                break;
             pWindow->ImplGetFrameData()->mbSysObjFocus = false;
             if ( !pWindow->ImplGetFrameData()->mnFocusId )
             {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to