vcl/inc/qt5/QtFrame.hxx             |    2 
 vcl/inc/qt5/QtInstance.hxx          |    7 ++
 vcl/inc/salframe.hxx                |    8 ++
 vcl/qt5/QtClipboard.cxx             |    4 -
 vcl/qt5/QtFilePicker.cxx            |  100 +++++++++++++----------------------
 vcl/qt5/QtFrame.cxx                 |   99 ++++++++++++----------------------
 vcl/qt5/QtGraphics_Controls.cxx     |    7 +-
 vcl/qt5/QtInstance.cxx              |   17 ++----
 vcl/qt5/QtInstanceButton.cxx        |   12 ++--
 vcl/qt5/QtInstanceDialog.cxx        |   21 +++----
 vcl/qt5/QtInstanceMessageDialog.cxx |   78 +++++++++++++--------------
 vcl/qt5/QtInstanceWidget.cxx        |  102 ++++++++++++++++++------------------
 vcl/qt5/QtInstanceWindow.cxx        |   12 ++--
 vcl/qt5/QtMenu.cxx                  |    9 +--
 vcl/qt5/QtTransferable.cxx          |    9 +--
 vcl/qt5/QtWidget.cxx                |   12 +---
 vcl/unx/kf5/KFFilePicker.cxx        |    7 +-
 17 files changed, 225 insertions(+), 281 deletions(-)

New commits:
commit 25e5f050756bb25d67b6a90433c0a50a149d5dc0
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Sep 27 09:08:43 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Sep 28 09:32:44 2024 +0200

    qt: Let GetQtInstance return ref instead of pointer
    
    The return value was dereferenced in all callers
    anyway.
    
    Change-Id: Ib91eddd23222d086f9a4edac980a05cd96c75ad7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174026
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtInstance.hxx b/vcl/inc/qt5/QtInstance.hxx
index f82def9c830c..4eb88e26d3f2 100644
--- a/vcl/inc/qt5/QtInstance.hxx
+++ b/vcl/inc/qt5/QtInstance.hxx
@@ -197,6 +197,11 @@ public:
     void setActivePopup(QtFrame*);
 };
 
-inline QtInstance* GetQtInstance() { return 
static_cast<QtInstance*>(GetSalInstance()); }
+inline QtInstance& GetQtInstance()
+{
+    QtInstance* pInstance = static_cast<QtInstance*>(GetSalInstance());
+    assert(pInstance);
+    return *pInstance;
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtClipboard.cxx b/vcl/qt5/QtClipboard.cxx
index 2181079a1988..430af1f96efa 100644
--- a/vcl/qt5/QtClipboard.cxx
+++ b/vcl/qt5/QtClipboard.cxx
@@ -59,9 +59,9 @@ css::uno::Reference<css::uno::XInterface> 
QtClipboard::create(const OUString& aM
 
 void QtClipboard::flushClipboard()
 {
-    auto* pSalInst(GetQtInstance());
     SolarMutexGuard g;
-    pSalInst->RunInMainThread([this]() {
+    QtInstance& rQtInstance = GetQtInstance();
+    rQtInstance.RunInMainThread([this]() {
         if (!isOwner(m_aClipboardMode))
             return;
 
diff --git a/vcl/qt5/QtFilePicker.cxx b/vcl/qt5/QtFilePicker.cxx
index 70fa7ef96483..93b16057e5dd 100644
--- a/vcl/qt5/QtFilePicker.cxx
+++ b/vcl/qt5/QtFilePicker.cxx
@@ -126,9 +126,7 @@ 
QtFilePicker::QtFilePicker(css::uno::Reference<css::uno::XComponentContext> cont
 QtFilePicker::~QtFilePicker()
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this]() {
+    GetQtInstance().RunInMainThread([this]() {
         // must delete it in main thread, otherwise
         // QSocketNotifier::setEnabled() will crash us
         m_pFileDialog.reset();
@@ -151,9 +149,7 @@ void SAL_CALL QtFilePicker::removeFilePickerListener(const 
uno::Reference<XFileP
 void SAL_CALL QtFilePicker::setTitle(const OUString& title)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread(
+    GetQtInstance().RunInMainThread(
         [this, &title]() { m_pFileDialog->setWindowTitle(toQString(title)); });
 }
 
@@ -209,12 +205,11 @@ void QtFilePicker::finished(int nResult)
 sal_Int16 SAL_CALL QtFilePicker::execute()
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         sal_uInt16 ret;
-        pSalInst->RunInMainThread([&ret, this]() { ret = execute(); });
+        rQtInstance.RunInMainThread([&ret, this]() { ret = execute(); });
         return ret;
     }
 
@@ -240,9 +235,7 @@ QtFilePicker::startExecuteModal(const 
Reference<css::ui::dialogs::XDialogClosedL
 void SAL_CALL QtFilePicker::setMultiSelectionMode(sal_Bool multiSelect)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this, multiSelect]() {
+    GetQtInstance().RunInMainThread([this, multiSelect]() {
         if (m_bIsFolderPicker || m_pFileDialog->acceptMode() == 
QFileDialog::AcceptSave)
             return;
 
@@ -254,17 +247,14 @@ void SAL_CALL 
QtFilePicker::setMultiSelectionMode(sal_Bool multiSelect)
 void SAL_CALL QtFilePicker::setDefaultName(const OUString& name)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this, &name]() { 
m_pFileDialog->selectFile(toQString(name)); });
+    GetQtInstance().RunInMainThread(
+        [this, &name]() { m_pFileDialog->selectFile(toQString(name)); });
 }
 
 void SAL_CALL QtFilePicker::setDisplayDirectory(const OUString& dir)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this, &dir]() {
+    GetQtInstance().RunInMainThread([this, &dir]() {
         QString qDir(toQString(dir));
         m_pFileDialog->setDirectoryUrl(QUrl(qDir));
     });
@@ -274,9 +264,7 @@ OUString SAL_CALL QtFilePicker::getDisplayDirectory()
 {
     SolarMutexGuard g;
     OUString ret;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread(
+    GetQtInstance().RunInMainThread(
         [&ret, this]() { ret = 
toOUString(m_pFileDialog->directoryUrl().toString()); });
     return ret;
 }
@@ -293,9 +281,7 @@ uno::Sequence<OUString> SAL_CALL 
QtFilePicker::getSelectedFiles()
 {
     SolarMutexGuard g;
     QList<QUrl> urls;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([&urls, this]() { urls = 
m_pFileDialog->selectedUrls(); });
+    GetQtInstance().RunInMainThread([&urls, this]() { urls = 
m_pFileDialog->selectedUrls(); });
 
     uno::Sequence<OUString> seq(urls.size());
     auto seqRange = asNonConstRange(seq);
@@ -330,11 +316,10 @@ uno::Sequence<OUString> SAL_CALL 
QtFilePicker::getSelectedFiles()
 void SAL_CALL QtFilePicker::appendFilter(const OUString& title, const 
OUString& filter)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pSalInst->RunInMainThread([this, &title, &filter]() { 
appendFilter(title, filter); });
+        rQtInstance.RunInMainThread([this, &title, &filter]() { 
appendFilter(title, filter); });
         return;
     }
 
@@ -366,9 +351,7 @@ void SAL_CALL QtFilePicker::appendFilter(const OUString& 
title, const OUString&
 void SAL_CALL QtFilePicker::setCurrentFilter(const OUString& title)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this, &title]() {
+    GetQtInstance().RunInMainThread([this, &title]() {
         m_aCurrentFilter = 
m_aTitleToFilterMap.value(toQString(title).replace("/", "\/"));
     });
 }
@@ -377,9 +360,8 @@ OUString SAL_CALL QtFilePicker::getCurrentFilter()
 {
     SolarMutexGuard g;
     QString filter;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([&filter, this]() {
+    QtInstance& rQtInstance = GetQtInstance();
+    rQtInstance.RunInMainThread([&filter, this]() {
         filter = m_aTitleToFilterMap.key(m_pFileDialog->selectedNameFilter());
     });
 
@@ -392,11 +374,10 @@ void SAL_CALL QtFilePicker::appendFilterGroup(const 
OUString& rGroupTitle,
                                               const 
uno::Sequence<beans::StringPair>& filters)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pSalInst->RunInMainThread(
+        rQtInstance.RunInMainThread(
             [this, &rGroupTitle, &filters]() { appendFilterGroup(rGroupTitle, 
filters); });
         return;
     }
@@ -495,11 +476,10 @@ void SAL_CALL QtFilePicker::setValue(sal_Int16 controlId, 
sal_Int16 nControlActi
                                      const uno::Any& value)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pSalInst->RunInMainThread([this, controlId, nControlAction, &value]() {
+        rQtInstance.RunInMainThread([this, controlId, nControlAction, 
&value]() {
             setValue(controlId, nControlAction, value);
         });
         return;
@@ -525,12 +505,11 @@ void SAL_CALL QtFilePicker::setValue(sal_Int16 controlId, 
sal_Int16 nControlActi
 uno::Any SAL_CALL QtFilePicker::getValue(sal_Int16 controlId, sal_Int16 
nControlAction)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         uno::Any ret;
-        pSalInst->RunInMainThread([&ret, this, controlId, nControlAction]() {
+        rQtInstance.RunInMainThread([&ret, this, controlId, nControlAction]() {
             ret = getValue(controlId, nControlAction);
         });
         return ret;
@@ -559,9 +538,7 @@ uno::Any SAL_CALL QtFilePicker::getValue(sal_Int16 
controlId, sal_Int16 nControl
 void SAL_CALL QtFilePicker::enableControl(sal_Int16 controlId, sal_Bool enable)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this, controlId, enable]() {
+    GetQtInstance().RunInMainThread([this, controlId, enable]() {
         if (m_aCustomWidgetsMap.contains(controlId))
             m_aCustomWidgetsMap.value(controlId)->setEnabled(enable);
         else
@@ -572,11 +549,10 @@ void SAL_CALL QtFilePicker::enableControl(sal_Int16 
controlId, sal_Bool enable)
 void SAL_CALL QtFilePicker::setLabel(sal_Int16 controlId, const OUString& 
label)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pSalInst->RunInMainThread([this, controlId, label]() { 
setLabel(controlId, label); });
+        rQtInstance.RunInMainThread([this, controlId, label]() { 
setLabel(controlId, label); });
         return;
     }
 
@@ -593,12 +569,11 @@ void SAL_CALL QtFilePicker::setLabel(sal_Int16 controlId, 
const OUString& label)
 OUString SAL_CALL QtFilePicker::getLabel(sal_Int16 controlId)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         OUString ret;
-        pSalInst->RunInMainThread([&ret, this, controlId]() { ret = 
getLabel(controlId); });
+        rQtInstance.RunInMainThread([&ret, this, controlId]() { ret = 
getLabel(controlId); });
         return ret;
     }
 
@@ -756,11 +731,10 @@ void SAL_CALL QtFilePicker::initialize(const 
uno::Sequence<uno::Any>& args)
     }
 
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pSalInst->RunInMainThread([this, args]() { initialize(args); });
+        rQtInstance.RunInMainThread([this, args]() { initialize(args); });
         return;
     }
 
@@ -894,7 +868,7 @@ void SAL_CALL QtFilePicker::initialize(const 
uno::Sequence<uno::Any>& args)
     css::awt::SystemDependentXWindow xSysWin;
     aAny >>= xSysWin;
 
-    const auto& pFrames = pSalInst->getFrames();
+    const auto& pFrames = rQtInstance.getFrames();
     const tools::Long aWindowHandle = xSysWin.WindowHandle;
     const auto it
         = std::find_if(pFrames.begin(), pFrames.end(), [&aWindowHandle](auto 
pFrame) -> bool {
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 4d985c41296a..3308ccccea2e 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -114,8 +114,7 @@ QtFrame::QtFrame(QtFrame* pParent, SalFrameStyleFlags 
nStyle, bool bUseCairo)
 #endif
     , m_nInputLanguage(LANGUAGE_DONTKNOW)
 {
-    QtInstance* pInst = GetQtInstance();
-    pInst->insertFrame(this);
+    GetQtInstance().insertFrame(this);
 
     m_aDamageHandler.handle = this;
     m_aDamageHandler.damaged = ::SvpDamageHandler;
@@ -208,8 +207,7 @@ void QtFrame::FillSystemEnvData(SystemEnvData& rData, 
sal_IntPtr pWindow, QWidge
 
 QtFrame::~QtFrame()
 {
-    QtInstance* pInst = GetQtInstance();
-    pInst->eraseFrame(this);
+    GetQtInstance().eraseFrame(this);
     delete asChild();
     m_aSystemData.aShellWindow = 0;
 }
@@ -269,8 +267,7 @@ void QtFrame::ReleaseGraphics(SalGraphics* pSalGraph)
 
 bool QtFrame::PostEvent(std::unique_ptr<ImplSVEvent> pData)
 {
-    QtInstance* pInst = GetQtInstance();
-    pInst->PostEvent(this, pData.release(), SalEvent::UserEvent);
+    GetQtInstance().PostEvent(this, pData.release(), SalEvent::UserEvent);
     return true;
 }
 
@@ -336,19 +333,16 @@ void QtFrame::SetWindowStateImpl(Qt::WindowStates eState)
 
 void QtFrame::SetTitle(const OUString& rTitle)
 {
-    QtInstance* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread(
+    GetQtInstance().RunInMainThread(
         [this, rTitle]() { 
m_pQWidget->window()->setWindowTitle(toQString(rTitle)); });
 }
 
 void QtFrame::SetIcon(sal_uInt16 nIcon)
 {
-    QtInstance* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pSalInst->RunInMainThread([this, nIcon]() { SetIcon(nIcon); });
+        rQtInstance.RunInMainThread([this, nIcon]() { SetIcon(nIcon); });
         return;
     }
 
@@ -401,11 +395,10 @@ void QtFrame::SetExtendedFrameStyle(SalExtStyle 
/*nExtStyle*/) { /* not needed *
 void QtFrame::Show(bool bVisible, bool bNoActivate)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    assert(pQtInstance);
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { Show(bVisible, bNoActivate); });
+        rQtInstance.RunInMainThread([&] { Show(bVisible, bNoActivate); });
         return;
     }
 
@@ -523,10 +516,10 @@ void QtFrame::SetPosSize(tools::Long nX, tools::Long nY, 
tools::Long nWidth, too
                          sal_uInt16 nFlags)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { SetPosSize(nX, nY, nWidth, nHeight, 
nFlags); });
+        rQtInstance.RunInMainThread([&] { SetPosSize(nX, nY, nWidth, nHeight, 
nFlags); });
     }
 
     if (!isWindow() || isChild(true, false))
@@ -619,9 +612,7 @@ void QtFrame::SetModal(bool bModal)
     if (!isWindow() || asChild()->isModal() == bModal)
         return;
 
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this, bModal]() {
+    GetQtInstance().RunInMainThread([this, bModal]() {
 
         QWidget* const pChild = asChild();
         const bool bWasVisible = pChild->isVisible();
@@ -650,11 +641,10 @@ bool QtFrame::GetModal() const { return isWindow() && 
windowHandle()->isModal();
 
 void QtFrame::SetWindowState(const vcl::WindowData* pState)
 {
-    QtInstance* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pSalInst->RunInMainThread([this, pState]() { SetWindowState(pState); 
});
+        rQtInstance.RunInMainThread([this, pState]() { SetWindowState(pState); 
});
         return;
     }
 
@@ -787,9 +777,7 @@ void QtFrame::SetAlwaysOnTop(bool bOnTop)
 
 void QtFrame::ToTop(SalFrameToTop nFlags)
 {
-    QtInstance* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this, nFlags]() {
+    GetQtInstance().RunInMainThread([this, nFlags]() {
         QWidget* const pWidget = asChild();
         if (isWindow() && !(nFlags & SalFrameToTop::GrabFocusOnly))
             pWidget->raise();
@@ -1382,7 +1370,7 @@ void QtFrame::ResolveWindowHandle(SystemEnvData& rData) 
const
     }
 }
 
-bool QtFrame::GetUseReducedAnimation() const { return 
GetQtInstance()->GetUseReducedAnimation(); }
+bool QtFrame::GetUseReducedAnimation() const { return 
GetQtInstance().GetUseReducedAnimation(); }
 
 // Drag'n'drop foo
 
@@ -1404,9 +1392,7 @@ void QtFrame::registerDropTarget(QtDropTarget* 
pDropTarget)
     assert(!m_pDropTarget);
     m_pDropTarget = pDropTarget;
 
-    QtInstance* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    pSalInst->RunInMainThread([this]() { m_pQWidget->setAcceptDrops(true); });
+    GetQtInstance().RunInMainThread([this]() { 
m_pQWidget->setAcceptDrops(true); });
 }
 
 void QtFrame::deregisterDropTarget(QtDropTarget const* pDropTarget)
diff --git a/vcl/qt5/QtGraphics_Controls.cxx b/vcl/qt5/QtGraphics_Controls.cxx
index 9dd0b3a4f61e..ab905b687432 100644
--- a/vcl/qt5/QtGraphics_Controls.cxx
+++ b/vcl/qt5/QtGraphics_Controls.cxx
@@ -741,12 +741,11 @@ bool QtGraphics_Controls::getNativeControlRegion(
     ControlState controlState, const ImplControlValue& val, const OUString& 
rCaption,
     tools::Rectangle& nativeBoundingRegion, tools::Rectangle& 
nativeContentRegion)
 {
-    QtInstance* pQtInstance(GetQtInstance());
-    assert(pQtInstance);
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bRet;
-        pQtInstance->RunInMainThread([&]() {
+        rQtInstance.RunInMainThread([&]() {
             bRet = getNativeControlRegion(type, part, controlRegion, 
controlState, val, rCaption,
                                           nativeBoundingRegion, 
nativeContentRegion);
         });
diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx
index 2243b3dec590..b8ce2a796c81 100644
--- a/vcl/qt5/QtInstance.cxx
+++ b/vcl/qt5/QtInstance.cxx
@@ -135,9 +135,8 @@ void lcl_setStandardButtons(QtInstanceMessageDialog& 
rMessageDialog, VclButtonsT
 
 bool QtYieldMutex::IsCurrentThread() const
 {
-    auto const* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (pSalInst->IsMainThread() && m_bNoYieldLock)
+    QtInstance& rQtInstance = GetQtInstance();
+    if (rQtInstance.IsMainThread() && m_bNoYieldLock)
     {
         return true; // main thread has borrowed SolarMutex
     }
@@ -146,9 +145,8 @@ bool QtYieldMutex::IsCurrentThread() const
 
 void QtYieldMutex::doAcquire(sal_uInt32 nLockCount)
 {
-    auto const* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         SalYieldMutex::doAcquire(nLockCount);
         return;
@@ -192,9 +190,8 @@ void QtYieldMutex::doAcquire(sal_uInt32 nLockCount)
 
 sal_uInt32 QtYieldMutex::doRelease(bool const bUnlockAll)
 {
-    auto const* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (pSalInst->IsMainThread() && m_bNoYieldLock)
+    QtInstance& rQtInstance = GetQtInstance();
+    if (rQtInstance.IsMainThread() && m_bNoYieldLock)
     {
         return 1; // dummy value
     }
@@ -203,7 +200,7 @@ sal_uInt32 QtYieldMutex::doRelease(bool const bUnlockAll)
     // read m_nCount before doRelease (it's guarded by m_aMutex)
     bool const isReleased(bUnlockAll || m_nCount == 1);
     sal_uInt32 nCount = SalYieldMutex::doRelease(bUnlockAll);
-    if (isReleased && !pSalInst->IsMainThread())
+    if (isReleased && !rQtInstance.IsMainThread())
     {
         m_isWakeUpMain = true;
         m_InMainCondition.notify_all(); // unblock main thread
diff --git a/vcl/qt5/QtInstanceButton.cxx b/vcl/qt5/QtInstanceButton.cxx
index 0bc79fd2478f..1d68f9bcdb0e 100644
--- a/vcl/qt5/QtInstanceButton.cxx
+++ b/vcl/qt5/QtInstanceButton.cxx
@@ -21,10 +21,10 @@ QtInstanceButton::QtInstanceButton(QPushButton* pButton)
 void QtInstanceButton::set_label(const OUString& rText)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_label(rText); });
+        rQtInstance.RunInMainThread([&] { set_label(rText); });
         return;
     }
 
@@ -50,11 +50,11 @@ void QtInstanceButton::set_from_icon_name(const OUString& 
/*rIconName*/)
 OUString QtInstanceButton::get_label() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         OUString sLabel;
-        pQtInstance->RunInMainThread([&] { sLabel = get_label(); });
+        rQtInstance.RunInMainThread([&] { sLabel = get_label(); });
         return sLabel;
     }
 
diff --git a/vcl/qt5/QtInstanceDialog.cxx b/vcl/qt5/QtInstanceDialog.cxx
index 36f7e75c4fc8..3f1df87f2741 100644
--- a/vcl/qt5/QtInstanceDialog.cxx
+++ b/vcl/qt5/QtInstanceDialog.cxx
@@ -18,8 +18,7 @@ QtInstanceDialog::QtInstanceDialog(QDialog* pDialog)
 QtInstanceDialog::~QtInstanceDialog()
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    pQtInstance->RunInMainThread([&] { m_pDialog.reset(); });
+    GetQtInstance().RunInMainThread([&] { m_pDialog.reset(); });
 }
 
 bool QtInstanceDialog::runAsync(std::shared_ptr<Dialog> const&,
@@ -45,11 +44,11 @@ void QtInstanceDialog::SetInstallLOKNotifierHdl(const 
Link<void*, vcl::ILibreOff
 int QtInstanceDialog::run()
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         int nResult = 0;
-        pQtInstance->RunInMainThread([&] { nResult = run(); });
+        rQtInstance.RunInMainThread([&] { nResult = run(); });
         return nResult;
     }
 
@@ -63,10 +62,10 @@ void QtInstanceDialog::add_button(const OUString&, int, 
const OUString&) {}
 void QtInstanceDialog::set_modal(bool bModal)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_modal(bModal); });
+        rQtInstance.RunInMainThread([&] { set_modal(bModal); });
         return;
     }
 
@@ -76,11 +75,11 @@ void QtInstanceDialog::set_modal(bool bModal)
 bool QtInstanceDialog::get_modal() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bModal = false;
-        pQtInstance->RunInMainThread([&] { bModal = get_modal(); });
+        rQtInstance.RunInMainThread([&] { bModal = get_modal(); });
         return bModal;
     }
 
diff --git a/vcl/qt5/QtInstanceMessageDialog.cxx 
b/vcl/qt5/QtInstanceMessageDialog.cxx
index a0aa35958140..76e370ea10d7 100644
--- a/vcl/qt5/QtInstanceMessageDialog.cxx
+++ b/vcl/qt5/QtInstanceMessageDialog.cxx
@@ -25,10 +25,10 @@ 
QtInstanceMessageDialog::QtInstanceMessageDialog(QMessageBox* pMessageDialog)
 void QtInstanceMessageDialog::set_primary_text(const rtl::OUString& rText)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_primary_text(rText); });
+        rQtInstance.RunInMainThread([&] { set_primary_text(rText); });
         return;
     }
 
@@ -38,10 +38,10 @@ void QtInstanceMessageDialog::set_primary_text(const 
rtl::OUString& rText)
 void QtInstanceMessageDialog::set_secondary_text(const rtl::OUString& rText)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_secondary_text(rText); });
+        rQtInstance.RunInMainThread([&] { set_secondary_text(rText); });
         return;
     }
 
@@ -53,11 +53,11 @@ weld::Container* 
QtInstanceMessageDialog::weld_message_area() { return nullptr;
 OUString QtInstanceMessageDialog::get_primary_text() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
+    QtInstance& rQtInstance = GetQtInstance();
     OUString sText;
-    if (!pQtInstance->IsMainThread())
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { sText = get_primary_text(); });
+        rQtInstance.RunInMainThread([&] { sText = get_primary_text(); });
         return sText;
     }
 
@@ -68,11 +68,11 @@ OUString QtInstanceMessageDialog::get_primary_text() const
 OUString QtInstanceMessageDialog::get_secondary_text() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
+    QtInstance& rQtInstance = GetQtInstance();
     OUString sText;
-    if (!pQtInstance->IsMainThread())
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { sText = get_secondary_text(); });
+        rQtInstance.RunInMainThread([&] { sText = get_secondary_text(); });
         return sText;
     }
 
@@ -83,10 +83,10 @@ OUString QtInstanceMessageDialog::get_secondary_text() const
 void QtInstanceMessageDialog::add_button(const OUString& rText, int nResponse, 
const OUString&)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { add_button(rText, nResponse); });
+        rQtInstance.RunInMainThread([&] { add_button(rText, nResponse); });
         return;
     }
 
@@ -99,10 +99,10 @@ void QtInstanceMessageDialog::add_button(const OUString& 
rText, int nResponse, c
 void QtInstanceMessageDialog::set_default_response(int nResponse)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_default_response(nResponse); });
+        rQtInstance.RunInMainThread([&] { set_default_response(nResponse); });
         return;
     }
 
@@ -116,11 +116,11 @@ void QtInstanceMessageDialog::set_default_response(int 
nResponse)
 QtInstanceButton* QtInstanceMessageDialog::weld_widget_for_response(int 
nResponse)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         QtInstanceButton* pButton;
-        pQtInstance->RunInMainThread([&] { pButton = 
weld_widget_for_response(nResponse); });
+        rQtInstance.RunInMainThread([&] { pButton = 
weld_widget_for_response(nResponse); });
         return pButton;
     }
 
@@ -133,11 +133,11 @@ QtInstanceButton* 
QtInstanceMessageDialog::weld_widget_for_response(int nRespons
 int QtInstanceMessageDialog::run()
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         int nRet = 0;
-        pQtInstance->RunInMainThread([&] { nRet = run(); });
+        rQtInstance.RunInMainThread([&] { nRet = run(); });
         return nRet;
     }
 
@@ -152,11 +152,11 @@ bool QtInstanceMessageDialog::runAsync(const 
std::shared_ptr<weld::DialogControl
                                        const std::function<void(sal_Int32)>& 
func)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bRet = false;
-        pQtInstance->RunInMainThread([&] { bRet = runAsync(rxOwner, func); });
+        rQtInstance.RunInMainThread([&] { bRet = runAsync(rxOwner, func); });
         return bRet;
     }
 
@@ -174,11 +174,11 @@ bool 
QtInstanceMessageDialog::runAsync(std::shared_ptr<Dialog> const& rxSelf,
                                        const std::function<void(sal_Int32)>& 
func)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bRet;
-        pQtInstance->RunInMainThread([&] { bRet = runAsync(rxSelf, func); });
+        rQtInstance.RunInMainThread([&] { bRet = runAsync(rxSelf, func); });
         return bRet;
     }
 
@@ -196,10 +196,10 @@ bool 
QtInstanceMessageDialog::runAsync(std::shared_ptr<Dialog> const& rxSelf,
 void QtInstanceMessageDialog::response(int nResponse)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { response(nResponse); });
+        rQtInstance.RunInMainThread([&] { response(nResponse); });
         return;
     }
 
@@ -210,10 +210,10 @@ void QtInstanceMessageDialog::response(int nResponse)
 void QtInstanceMessageDialog::dialogFinished(int nResult)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { dialogFinished(nResult); });
+        rQtInstance.RunInMainThread([&] { dialogFinished(nResult); });
         return;
     }
 
@@ -244,11 +244,11 @@ void QtInstanceMessageDialog::dialogFinished(int nResult)
 QPushButton* QtInstanceMessageDialog::buttonForResponseCode(int nResponse)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         QPushButton* pButton;
-        pQtInstance->RunInMainThread([&] { pButton = 
buttonForResponseCode(nResponse); });
+        rQtInstance.RunInMainThread([&] { pButton = 
buttonForResponseCode(nResponse); });
         return pButton;
     }
 
diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx
index 2f74e2eff829..e0060ebc4905 100644
--- a/vcl/qt5/QtInstanceWidget.cxx
+++ b/vcl/qt5/QtInstanceWidget.cxx
@@ -20,10 +20,10 @@ QtInstanceWidget::QtInstanceWidget(QWidget* pWidget)
 void QtInstanceWidget::set_sensitive(bool bSensitive)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_sensitive(bSensitive); });
+        rQtInstance.RunInMainThread([&] { set_sensitive(bSensitive); });
         return;
     }
 
@@ -34,11 +34,11 @@ void QtInstanceWidget::set_sensitive(bool bSensitive)
 bool QtInstanceWidget::get_sensitive() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bSensitive = false;
-        pQtInstance->RunInMainThread([&] { bSensitive = get_sensitive(); });
+        rQtInstance.RunInMainThread([&] { bSensitive = get_sensitive(); });
         return bSensitive;
     }
 
@@ -49,11 +49,11 @@ bool QtInstanceWidget::get_sensitive() const
 bool QtInstanceWidget::get_visible() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bVisible = false;
-        pQtInstance->RunInMainThread([&] { bVisible = get_visible(); });
+        rQtInstance.RunInMainThread([&] { bVisible = get_visible(); });
         return bVisible;
     }
 
@@ -64,11 +64,11 @@ bool QtInstanceWidget::get_visible() const
 bool QtInstanceWidget::is_visible() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bVisible = false;
-        pQtInstance->RunInMainThread([&] { bVisible = is_visible(); });
+        rQtInstance.RunInMainThread([&] { bVisible = is_visible(); });
         return bVisible;
     }
 
@@ -82,10 +82,10 @@ bool QtInstanceWidget::is_visible() const
 void QtInstanceWidget::set_can_focus(bool bCanFocus)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_can_focus(bCanFocus); });
+        rQtInstance.RunInMainThread([&] { set_can_focus(bCanFocus); });
         return;
     }
 
@@ -99,10 +99,10 @@ void QtInstanceWidget::set_can_focus(bool bCanFocus)
 void QtInstanceWidget::grab_focus()
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { grab_focus(); });
+        rQtInstance.RunInMainThread([&] { grab_focus(); });
         return;
     }
 
@@ -113,11 +113,11 @@ void QtInstanceWidget::grab_focus()
 bool QtInstanceWidget::has_focus() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bFocus = false;
-        pQtInstance->RunInMainThread([&] { bFocus = has_focus(); });
+        rQtInstance.RunInMainThread([&] { bFocus = has_focus(); });
         return bFocus;
     }
 
@@ -130,11 +130,11 @@ bool QtInstanceWidget::is_active() const { return 
has_focus(); }
 bool QtInstanceWidget::has_child_focus() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         bool bChildFocus = false;
-        pQtInstance->RunInMainThread([&] { bChildFocus = has_child_focus(); });
+        rQtInstance.RunInMainThread([&] { bChildFocus = has_child_focus(); });
         return bChildFocus;
     }
 
@@ -154,10 +154,10 @@ bool QtInstanceWidget::has_child_focus() const
 void QtInstanceWidget::show()
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { show(); });
+        rQtInstance.RunInMainThread([&] { show(); });
         return;
     }
 
@@ -168,10 +168,10 @@ void QtInstanceWidget::show()
 void QtInstanceWidget::hide()
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { hide(); });
+        rQtInstance.RunInMainThread([&] { hide(); });
         return;
     }
 
@@ -238,10 +238,10 @@ int QtInstanceWidget::get_margin_end() const { return 1; }
 void QtInstanceWidget::set_accessible_name(const OUString& rName)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_accessible_name(rName); });
+        rQtInstance.RunInMainThread([&] { set_accessible_name(rName); });
         return;
     }
 
@@ -252,10 +252,10 @@ void QtInstanceWidget::set_accessible_name(const 
OUString& rName)
 void QtInstanceWidget::set_accessible_description(const OUString& rDescription)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { 
set_accessible_description(rDescription); });
+        rQtInstance.RunInMainThread([&] { 
set_accessible_description(rDescription); });
         return;
     }
 
@@ -266,11 +266,11 @@ void QtInstanceWidget::set_accessible_description(const 
OUString& rDescription)
 OUString QtInstanceWidget::get_accessible_name() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         OUString sName;
-        pQtInstance->RunInMainThread([&] { sName = get_accessible_name(); });
+        rQtInstance.RunInMainThread([&] { sName = get_accessible_name(); });
         return sName;
     }
 
@@ -281,11 +281,11 @@ OUString QtInstanceWidget::get_accessible_name() const
 OUString QtInstanceWidget::get_accessible_description() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         OUString sDescription;
-        pQtInstance->RunInMainThread([&] { sDescription = 
get_accessible_description(); });
+        rQtInstance.RunInMainThread([&] { sDescription = 
get_accessible_description(); });
         return sDescription;
     }
 
@@ -296,11 +296,11 @@ OUString QtInstanceWidget::get_accessible_description() 
const
 OUString QtInstanceWidget::get_accessible_id() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         OUString sId;
-        pQtInstance->RunInMainThread([&] { sId = get_accessible_id(); });
+        rQtInstance.RunInMainThread([&] { sId = get_accessible_id(); });
         return sId;
     }
 
@@ -317,10 +317,10 @@ void 
QtInstanceWidget::set_accessible_relation_labeled_by(weld::Widget*) {}
 void QtInstanceWidget::set_tooltip_text(const OUString& rTip)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_tooltip_text(rTip); });
+        rQtInstance.RunInMainThread([&] { set_tooltip_text(rTip); });
         return;
     }
 
@@ -331,11 +331,11 @@ void QtInstanceWidget::set_tooltip_text(const OUString& 
rTip)
 OUString QtInstanceWidget::get_tooltip_text() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         OUString sToolTipText;
-        pQtInstance->RunInMainThread([&] { sToolTipText = get_tooltip_text(); 
});
+        rQtInstance.RunInMainThread([&] { sToolTipText = get_tooltip_text(); 
});
         return sToolTipText;
     }
 
diff --git a/vcl/qt5/QtInstanceWindow.cxx b/vcl/qt5/QtInstanceWindow.cxx
index bf2d713e1482..63f27bad055c 100644
--- a/vcl/qt5/QtInstanceWindow.cxx
+++ b/vcl/qt5/QtInstanceWindow.cxx
@@ -17,10 +17,10 @@ QtInstanceWindow::QtInstanceWindow(QWidget* pWidget)
 void QtInstanceWindow::set_title(const OUString& rTitle)
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pQtInstance->RunInMainThread([&] { set_title(rTitle); });
+        rQtInstance.RunInMainThread([&] { set_title(rTitle); });
         return;
     }
 
@@ -30,11 +30,11 @@ void QtInstanceWindow::set_title(const OUString& rTitle)
 OUString QtInstanceWindow::get_title() const
 {
     SolarMutexGuard g;
-    QtInstance* pQtInstance = GetQtInstance();
-    if (!pQtInstance->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         OUString sTitle;
-        pQtInstance->RunInMainThread([&] { sTitle = get_title(); });
+        rQtInstance.RunInMainThread([&] { sTitle = get_title(); });
         return sTitle;
     }
 
diff --git a/vcl/qt5/QtMenu.cxx b/vcl/qt5/QtMenu.cxx
index 284c45f8eee7..b0d4ca9841af 100644
--- a/vcl/qt5/QtMenu.cxx
+++ b/vcl/qt5/QtMenu.cxx
@@ -436,11 +436,10 @@ void QtMenu::SetSubMenu(SalMenuItem* pSalMenuItem, 
SalMenu* pSubMenu, unsigned n
 
 void QtMenu::SetFrame(const SalFrame* pFrame)
 {
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
-        pSalInst->RunInMainThread([this, pFrame]() { SetFrame(pFrame); });
+        rQtInstance.RunInMainThread([this, pFrame]() { SetFrame(pFrame); });
         return;
     }
 
diff --git a/vcl/qt5/QtTransferable.cxx b/vcl/qt5/QtTransferable.cxx
index ce989da2aa5a..095ba9ec6836 100644
--- a/vcl/qt5/QtTransferable.cxx
+++ b/vcl/qt5/QtTransferable.cxx
@@ -190,9 +190,8 @@ css::uno::Any SAL_CALL
 QtClipboardTransferable::getTransferData(const css::datatransfer::DataFlavor& 
rFlavor)
 {
     css::uno::Any aAny;
-    auto* pSalInst(GetQtInstance());
     SolarMutexGuard g;
-    pSalInst->RunInMainThread([&, this]() {
+    GetQtInstance().RunInMainThread([&, this]() {
         ensureConsistencyWithSystemClipboard();
         aAny = QtTransferable::getTransferData(rFlavor);
     });
@@ -203,9 +202,8 @@ css::uno::Sequence<css::datatransfer::DataFlavor>
     SAL_CALL QtClipboardTransferable::getTransferDataFlavors()
 {
     css::uno::Sequence<css::datatransfer::DataFlavor> aSeq;
-    auto* pSalInst(GetQtInstance());
     SolarMutexGuard g;
-    pSalInst->RunInMainThread([&, this]() {
+    GetQtInstance().RunInMainThread([&, this]() {
         ensureConsistencyWithSystemClipboard();
         aSeq = QtTransferable::getTransferDataFlavors();
     });
@@ -216,9 +214,8 @@ sal_Bool SAL_CALL
 QtClipboardTransferable::isDataFlavorSupported(const 
css::datatransfer::DataFlavor& rFlavor)
 {
     bool bIsSupported = false;
-    auto* pSalInst(GetQtInstance());
     SolarMutexGuard g;
-    pSalInst->RunInMainThread([&, this]() {
+    GetQtInstance().RunInMainThread([&, this]() {
         ensureConsistencyWithSystemClipboard();
         bIsSupported = QtTransferable::isDataFlavorSupported(rFlavor);
     });
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 5bd44267c860..77dda53eb6da 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -240,7 +240,7 @@ void QtWidget::showEvent(QShowEvent*)
     // resulting in a hidden / unmapped window
     SalPaintEvent aPaintEvt(0, 0, aSize.width(), aSize.height());
     if (m_rFrame.isPopup())
-        GetQtInstance()->setActivePopup(&m_rFrame);
+        GetQtInstance().setActivePopup(&m_rFrame);
     m_rFrame.CallCallback(SalEvent::Paint, &aPaintEvt);
 }
 
@@ -248,8 +248,8 @@ void QtWidget::hideEvent(QHideEvent* pEvent)
 {
     if (m_rFrame.isPopup())
     {
-        if (GetQtInstance()->activePopup() == &m_rFrame)
-            GetQtInstance()->setActivePopup(nullptr);
+        if (GetQtInstance().activePopup() == &m_rFrame)
+            GetQtInstance().setActivePopup(nullptr);
 
         // destroy the QWindow as the popup would otherwise still show up
         // as a top-level child of the app on the a11y level
@@ -664,7 +664,7 @@ bool QtWidget::handleEvent(QtFrame& rFrame, QWidget& 
rWidget, QEvent* pEvent)
     {
         // Qt's POV on the active popup is wrong due to our fake popup, so 
check LO's state.
         // Otherwise Qt will continue handling ToolTip events from the 
"parent" window.
-        const QtFrame* pPopupFrame = GetQtInstance()->activePopup();
+        const QtFrame* pPopupFrame = GetQtInstance().activePopup();
         if (!rFrame.m_aTooltipText.isEmpty() && (!pPopupFrame || pPopupFrame 
== &rFrame))
         {
             // tdf#162297 Use a dummy style to ensure the tooltip is wrapped
@@ -963,9 +963,7 @@ void QtWidget::changeEvent(QEvent* pEvent)
             [[fallthrough]];
         case QEvent::StyleChange:
         {
-            auto* pSalInst(GetQtInstance());
-            assert(pSalInst);
-            pSalInst->UpdateStyle(QEvent::FontChange == pEvent->type());
+            GetQtInstance().UpdateStyle(QEvent::FontChange == pEvent->type());
             break;
         }
         default:
diff --git a/vcl/unx/kf5/KFFilePicker.cxx b/vcl/unx/kf5/KFFilePicker.cxx
index 4122ef47108c..cb744f54038a 100644
--- a/vcl/unx/kf5/KFFilePicker.cxx
+++ b/vcl/unx/kf5/KFFilePicker.cxx
@@ -85,12 +85,11 @@ void SAL_CALL KFFilePicker::setValue(sal_Int16 controlId, 
sal_Int16 nControlActi
 uno::Any SAL_CALL KFFilePicker::getValue(sal_Int16 controlId, sal_Int16 
nControlAction)
 {
     SolarMutexGuard g;
-    auto* pSalInst(GetQtInstance());
-    assert(pSalInst);
-    if (!pSalInst->IsMainThread())
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
     {
         uno::Any ret;
-        pSalInst->RunInMainThread([&ret, this, controlId, nControlAction]() {
+        rQtInstance.RunInMainThread([&ret, this, controlId, nControlAction]() {
             ret = getValue(controlId, nControlAction);
         });
         return ret;
commit a499874d9c0685d79b629b4bb246394b6b15691a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Sep 26 18:22:12 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Sep 28 09:32:33 2024 +0200

    tdf#160837 qt: Rely on toolkit for frame positions, drop menubar hack
    
    Make `SalFrame::GetUnmirroredGeometry` overridable
    (and let it return a copy of the SalFrameGeometry
    instead of a const reference) and document that
    subclasses can either make sure to keep the
    `SalFrame::maGeometry` member (which is returned by
    the default implementation of
    `SalFrame::GetUnmirroredGeometry`) up to date or override
    the latter in order to always return the current
    geometry.
    
    Override the method in `QtFrame` and fully rely on Qt
    to report and set the position of the frame, via
    the corresponding QWidget: Set the position, width
    and height in the returned `SalFrameGeometry`
    to the ones of the widget (factoring in the
    scale factor).
    
    Stop updating `maGeometry` size/position whenever
    the widget position or size changes, as that is no
    longer used anymore now that `GetUnmirroredGeometry`
    is overriden.
    
    This also allows to drop earlier hacks where
    position calculation in some places had to be adjusted
    by the height of the native menu bar, as that one
    doesn't have a corresponding vcl::Window, but results
    in everything else being shifted down a bit.
    
    Using Qt directly to set other members of the
    returned `SalFrameGeometry` (like the screen number)
    would probably be possible, but is not included
    in this change. (It can still be done separately
    later.)
    
    This makes Accerciser highlight the correct area
    when using the qt6 VCL plugin and using Writer
    with the standard interface (where the y position
    reported via AT-SPI2 would previously always be
    too small, missing the menu bar height) and thus
    e.g. also allows to make use of it's "select object
    under mouse" feature (s. tdf#160837).
    The position via AT-SPI is however currently only
    correct on X11/XWayland where global/screen coordinates
    are reported via AT-SPI2.
    Wayland, where window-relative coordinates are used,
    still suffers from another issue that will be addressed
    in a separate commit.
    
    The highlighting in Accerciser is also still wrong
    when a screen scaling factor other than 100% is set,
    but that's broken for other applications (e.g. gtk3-demo)
    just the same, so might be an issue in Accerciser instead.
    
    I successfully tested that these behave as expected
    when using the qt6 VCL plugin with this change in place:
    
    * Combobox popup positions, with either 100% screen scaling
      or a scaling factor of 150% or 200% on both, X11 and
      Wayland.
    * When enabling RTL mode via env var `SAL_RTL_ENABLED=1`,
      RTL layout is used and things look OK at a quick glance.
    * The following bugs (somewhat related to positioning and/or
      the now dropped menu bar hacks) are still fixed, i.e. don't
      reappear:
    
        * tdf#149805 "kf5: Gap when expanding comboboxes in toolbar"
        * tdf#151677 "tip on "formula bar" for "formula making" is
          displaying over the formula itself."
        * tdf#152217 "Black box in Basic IDE where the status bar
          should be (kf5 only)"
        * tdf#153458 "Connecting to database: wrong cursor position
          for dropping data to Calc sheet"
        * tdf#153800 "Calc sheet tab drag-and-drop target area has
          shifted vertically (kf5-only)"
        * tdf#154043 "Change object layer via drag and drop has target
          shifted down (KF5-only)"
        * tdf#154447 "Clicking a dropdown tool button shouldn't
          place the context menu on top of the button (kf5)"
    
    Unrelated to this commit, popup positioning and rendering in
    in a multi-screen setup on Wayland with different scaling
    factors set for the single screens is still broken (see
    tdf#141578).
    
    Change-Id: Ifa0eff271c7d3fa2b6db9bdc1669e62333bd3094
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173996
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx
index 044a4a68b7a3..a54af3547c52 100644
--- a/vcl/inc/qt5/QtFrame.hxx
+++ b/vcl/inc/qt5/QtFrame.hxx
@@ -147,7 +147,6 @@ public:
     QtMainWindow* GetTopLevelWindow() const { return m_pTopLevel; }
     QWidget* asChild() const;
     qreal devicePixelRatioF() const;
-    int menuBarOffset() const;
 
     void Damage(sal_Int32 nExtentsX, sal_Int32 nExtentsY, sal_Int32 
nExtentsWidth,
                 sal_Int32 nExtentsHeight) const;
@@ -180,6 +179,7 @@ public:
     virtual void SetPosSize(tools::Long nX, tools::Long nY, tools::Long 
nWidth, tools::Long nHeight,
                             sal_uInt16 nFlags) override;
     virtual void GetClientSize(tools::Long& rWidth, tools::Long& rHeight) 
override;
+    SalFrameGeometry GetUnmirroredGeometry() const override;
     virtual void GetWorkArea(AbsoluteScreenPixelRectangle& rRect) override;
     virtual SalFrame* GetParent() const override;
     virtual void SetModal(bool bModal) override;
diff --git a/vcl/inc/salframe.hxx b/vcl/inc/salframe.hxx
index e5e833c68796..c0300b4083cd 100644
--- a/vcl/inc/salframe.hxx
+++ b/vcl/inc/salframe.hxx
@@ -119,7 +119,10 @@ private:
     SALFRAMEPROC            m_pProc;
     Link<bool, void>        m_aModalHierarchyHdl;
 protected:
+    // subclasses need to either keep this up to date
+    // or override GetUnmirroredGeometry()
     SalFrameGeometry maGeometry; ///< absolute, unmirrored values
+
     mutable std::unique_ptr<weld::Window> m_xFrameWeld;
 public:
                             SalFrame();
@@ -161,7 +164,10 @@ public:
     virtual SalFrame*       GetParent() const = 0;
     // Note: x will be mirrored at parent if UI mirroring is active
     SalFrameGeometry        GetGeometry() const;
-    const SalFrameGeometry& GetUnmirroredGeometry() const { return maGeometry; 
}
+
+    // subclasses either have to keep maGeometry up to date or override this
+    // method to return an up-to-date SalFrameGeometry
+    virtual SalFrameGeometry GetUnmirroredGeometry() const { return 
maGeometry; }
 
     virtual void SetWindowState(const vcl::WindowData*) = 0;
     // return the absolute, unmirrored system frame state
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 99375eb72a7f..4d985c41296a 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -461,14 +461,6 @@ void QtFrame::SetMaxClientSize(tools::Long nWidth, 
tools::Long nHeight)
     }
 }
 
-int QtFrame::menuBarOffset() const
-{
-    QtMainWindow* pTopLevel = m_pParent->GetTopLevelWindow();
-    if (pTopLevel && pTopLevel->menuBar() && pTopLevel->menuBar()->isVisible())
-        return round(pTopLevel->menuBar()->geometry().height() * 
devicePixelRatioF());
-    return 0;
-}
-
 void QtFrame::SetDefaultPos()
 {
     if (!m_bDefaultPos)
@@ -481,7 +473,6 @@ void QtFrame::SetDefaultPos()
         QWidget* const pParentWin = m_pParent->asChild()->window();
         QWidget* const pChildWin = asChild()->window();
         QPoint aPos = (pParentWin->rect().center() - 
pChildWin->rect().center()) * fRatio;
-        aPos.ry() -= menuBarOffset();
         SetPosSize(aPos.x(), aPos.y(), 0, 0, SAL_FRAME_POSSIZE_X | 
SAL_FRAME_POSSIZE_Y);
         assert(!m_bDefaultPos);
     }
@@ -560,13 +551,6 @@ void QtFrame::SetPosSize(tools::Long nX, tools::Long nY, 
tools::Long nWidth, too
                 else
                     asChild()->setFixedSize(nNewWidth, nNewHeight);
             }
-
-            // assume the resize happened
-            // needed for calculations and will eventually be corrected by 
events
-            if (nWidth > 0)
-                maGeometry.setWidth(nWidth);
-            if (nHeight > 0)
-                maGeometry.setHeight(nHeight);
         }
     }
 
@@ -584,7 +568,7 @@ void QtFrame::SetPosSize(tools::Long nX, tools::Long nY, 
tools::Long nWidth, too
             nX = aParentGeometry.x() + aParentGeometry.width() - nX - 
GetWidth() - 1;
         else
             nX += aParentGeometry.x();
-        nY += aParentGeometry.y() + menuBarOffset();
+        nY += aParentGeometry.y();
     }
 
     if (!(nFlags & SAL_FRAME_POSSIZE_X))
@@ -592,10 +576,6 @@ void QtFrame::SetPosSize(tools::Long nX, tools::Long nY, 
tools::Long nWidth, too
     else if (!(nFlags & SAL_FRAME_POSSIZE_Y))
         nY = GetUnmirroredGeometry().y();
 
-    // assume the reposition happened
-    // needed for calculations and will eventually be corrected by events later
-    maGeometry.setPos({ nX, nY });
-
     m_bDefaultPos = false;
     asChild()->move(round(nX / devicePixelRatioF()), round(nY / 
devicePixelRatioF()));
 }
@@ -606,6 +586,20 @@ void QtFrame::GetClientSize(tools::Long& rWidth, 
tools::Long& rHeight)
     rHeight = round(m_pQWidget->height() * devicePixelRatioF());
 }
 
+SalFrameGeometry QtFrame::GetUnmirroredGeometry() const
+{
+    SalFrameGeometry aGeometry = maGeometry;
+
+    const qreal fRatio = devicePixelRatioF();
+    const QPoint aScreenPos = m_pQWidget->mapToGlobal(QPoint(0, 0));
+    aGeometry.setX(aScreenPos.x() * fRatio);
+    aGeometry.setY(aScreenPos.y() * fRatio);
+    aGeometry.setWidth(m_pQWidget->width() * fRatio);
+    aGeometry.setHeight(m_pQWidget->height() * fRatio);
+
+    return aGeometry;
+}
+
 void QtFrame::GetWorkArea(AbsoluteScreenPixelRectangle& rRect)
 {
     if (!isWindow())
@@ -1576,12 +1570,7 @@ void QtFrame::handleDragLeave()
     m_bInDrag = false;
 }
 
-void QtFrame::handleMoveEvent(QMoveEvent* pEvent)
-{
-    const qreal fRatio = devicePixelRatioF();
-    maGeometry.setPos(toPoint(pEvent->pos() * fRatio));
-    CallCallback(SalEvent::Move, nullptr);
-}
+void QtFrame::handleMoveEvent(QMoveEvent*) { CallCallback(SalEvent::Move, 
nullptr); }
 
 void QtFrame::handlePaintEvent(QPaintEvent* pEvent, QWidget* pWidget)
 {
@@ -1614,8 +1603,6 @@ void QtFrame::handleResizeEvent(QResizeEvent* pEvent)
     const int nWidth = ceil(pEvent->size().width() * fRatio);
     const int nHeight = ceil(pEvent->size().height() * fRatio);
 
-    maGeometry.setSize({ nWidth, nHeight });
-
     if (m_bUseCairo)
     {
         if (m_pSurface)
diff --git a/vcl/qt5/QtMenu.cxx b/vcl/qt5/QtMenu.cxx
index 5b76706f22b3..284c45f8eee7 100644
--- a/vcl/qt5/QtMenu.cxx
+++ b/vcl/qt5/QtMenu.cxx
@@ -881,10 +881,8 @@ bool QtMenu::ShowNativePopupMenu(FloatingWindow* pWin, 
const tools::Rectangle& r
     const VclPtr<vcl::Window> xParent = 
pWin->ImplGetWindowImpl()->mpRealParent;
     AbsoluteScreenPixelRectangle aFloatRect = 
FloatingWindow::ImplConvertToAbsPos(xParent, rRect);
 
-    // tdf#154447 Menu bar height has to be added
     QtFrame* pFrame = static_cast<QtFrame*>(pWin->ImplGetFrame());
     assert(pFrame);
-    aFloatRect.SetPosY(aFloatRect.getY() + pFrame->menuBarOffset());
 
     const QRect aRect = toQRect(aFloatRect, 1 / pFrame->devicePixelRatioF());
     mpQMenu->exec(aRect.bottomLeft());

Reply via email to