diff options
Diffstat (limited to 'vcl/qt5/Qt5Instance.cxx')
-rw-r--r-- | vcl/qt5/Qt5Instance.cxx | 179 |
1 files changed, 89 insertions, 90 deletions
diff --git a/vcl/qt5/Qt5Instance.cxx b/vcl/qt5/Qt5Instance.cxx index c1e82aa6a0d9..d93b25f5bb89 100644 --- a/vcl/qt5/Qt5Instance.cxx +++ b/vcl/qt5/Qt5Instance.cxx @@ -61,9 +61,9 @@ Q_IMPORT_PLUGIN(QWasmIntegrationPlugin) namespace { -/// TODO: not much Qt5 specific here? could be generalised, esp. for OSX... +/// TODO: not much Qt specific here? could be generalised, esp. for OSX... /// this subclass allows for the transfer of a closure for running on the main -/// thread, to handle all the thread affine stuff in Qt5; the SolarMutex is +/// thread, to handle all the thread affine stuff in Qt; the SolarMutex is /// "loaned" to the main thread for the execution of the closure. /// @note it doesn't work to just use "emit" and signals/slots to move calls to /// the main thread, because the other thread has the SolarMutex; the other @@ -71,7 +71,7 @@ namespace /// will handle all sorts of events and whatnot; this design ensures that the /// main thread only runs the passed closure (unless the closure releases /// SolarMutex itself, which should probably be avoided). -class Qt5YieldMutex : public SalYieldMutex +class QtYieldMutex : public SalYieldMutex { public: /// flag only accessed on main thread: @@ -92,9 +92,9 @@ public: }; } -bool Qt5YieldMutex::IsCurrentThread() const +bool QtYieldMutex::IsCurrentThread() const { - auto const* pSalInst(static_cast<Qt5Instance const*>(GetSalData()->m_pInstance)); + auto const* pSalInst(static_cast<QtInstance const*>(GetSalData()->m_pInstance)); assert(pSalInst); if (pSalInst->IsMainThread() && m_bNoYieldLock) { @@ -103,9 +103,9 @@ bool Qt5YieldMutex::IsCurrentThread() const return SalYieldMutex::IsCurrentThread(); } -void Qt5YieldMutex::doAcquire(sal_uInt32 nLockCount) +void QtYieldMutex::doAcquire(sal_uInt32 nLockCount) { - auto const* pSalInst(static_cast<Qt5Instance const*>(GetSalData()->m_pInstance)); + auto const* pSalInst(static_cast<QtInstance const*>(GetSalData()->m_pInstance)); assert(pSalInst); if (!pSalInst->IsMainThread()) { @@ -149,9 +149,9 @@ void Qt5YieldMutex::doAcquire(sal_uInt32 nLockCount) SalYieldMutex::doAcquire(nLockCount); } -sal_uInt32 Qt5YieldMutex::doRelease(bool const bUnlockAll) +sal_uInt32 QtYieldMutex::doRelease(bool const bUnlockAll) { - auto const* pSalInst(static_cast<Qt5Instance const*>(GetSalData()->m_pInstance)); + auto const* pSalInst(static_cast<QtInstance const*>(GetSalData()->m_pInstance)); assert(pSalInst); if (pSalInst->IsMainThread() && m_bNoYieldLock) { @@ -170,11 +170,11 @@ sal_uInt32 Qt5YieldMutex::doRelease(bool const bUnlockAll) return nCount; } -// this could be abstracted to be independent of Qt5 by passing in the +// this could be abstracted to be independent of Qt by passing in the // event-trigger as another function parameter... // it could also be a template of the return type, then it could return the // result of func... but then how to handle the result in doAcquire? -void Qt5Instance::RunInMainThread(std::function<void()> func) +void QtInstance::RunInMainThread(std::function<void()> func) { DBG_TESTSOLARMUTEX(); if (IsMainThread()) @@ -183,7 +183,7 @@ void Qt5Instance::RunInMainThread(std::function<void()> func) return; } - Qt5YieldMutex* const pMutex(static_cast<Qt5YieldMutex*>(GetYieldMutex())); + QtYieldMutex* const pMutex(static_cast<QtYieldMutex*>(GetYieldMutex())); { std::scoped_lock<std::mutex> g(pMutex->m_RunInMainMutex); assert(!pMutex->m_Closure); @@ -201,7 +201,7 @@ void Qt5Instance::RunInMainThread(std::function<void()> func) } } -OUString Qt5Instance::constructToolkitID(std::u16string_view sTKname) +OUString QtInstance::constructToolkitID(std::u16string_view sTKname) { OUString sID(sTKname + OUString::Concat(u" (")); if (m_bUseCairo) @@ -212,8 +212,8 @@ OUString Qt5Instance::constructToolkitID(std::u16string_view sTKname) return sID; } -Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo) - : SalGenericInstance(std::make_unique<Qt5YieldMutex>()) +QtInstance::QtInstance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo) + : SalGenericInstance(std::make_unique<QtYieldMutex>()) , m_bUseCairo(bUseCairo) , m_pTimer(nullptr) , m_bSleeping(false) @@ -231,12 +231,11 @@ Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo) // this one needs to be queued non-blocking // in order to have this event arriving to correct event processing loop - connect(this, &Qt5Instance::deleteObjectLaterSignal, this, - [](QObject* pObject) { Qt5Instance::deleteObjectLater(pObject); }, - Qt::QueuedConnection); + connect(this, &QtInstance::deleteObjectLaterSignal, this, + [](QObject* pObject) { QtInstance::deleteObjectLater(pObject); }, Qt::QueuedConnection); m_aUpdateStyleTimer.SetTimeout(50); - m_aUpdateStyleTimer.SetInvokeHandler(LINK(this, Qt5Instance, updateStyleHdl)); + m_aUpdateStyleTimer.SetInvokeHandler(LINK(this, QtInstance, updateStyleHdl)); QAbstractEventDispatcher* dispatcher = QAbstractEventDispatcher::instance(qApp->thread()); connect(dispatcher, &QAbstractEventDispatcher::awake, this, [this]() { m_bSleeping = false; }); @@ -244,21 +243,21 @@ Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo) [this]() { m_bSleeping = true; }); connect(QGuiApplication::inputMethod(), &QInputMethod::localeChanged, this, - &Qt5Instance::localeChanged); + &QtInstance::localeChanged); #ifndef EMSCRIPTEN m_bSupportsOpenGL = true; #endif } -Qt5Instance::~Qt5Instance() +QtInstance::~QtInstance() { // force freeing the QApplication before freeing the arguments, // as it uses references to the provided arguments! m_pQApplication.reset(); } -void Qt5Instance::AfterAppInit() +void QtInstance::AfterAppInit() { // set the default application icon via desktop file just on Wayland, // as this otherwise overrides the individual desktop icons on X11. @@ -268,7 +267,7 @@ void Qt5Instance::AfterAppInit() : Qt::LeftToRight); } -void Qt5Instance::localeChanged() +void QtInstance::localeChanged() { SolarMutexGuard aGuard; const vcl::Window* pFocusWindow = Application::GetFocusWindow(); @@ -278,87 +277,87 @@ void Qt5Instance::localeChanged() const LanguageTag aTag( toOUString(QGuiApplication::inputMethod()->locale().name().replace("_", "-"))); - static_cast<Qt5Frame*>(pFocusFrame)->setInputLanguage(aTag.getLanguageType()); + static_cast<QtFrame*>(pFocusFrame)->setInputLanguage(aTag.getLanguageType()); } -void Qt5Instance::deleteObjectLater(QObject* pObject) { pObject->deleteLater(); } +void QtInstance::deleteObjectLater(QObject* pObject) { pObject->deleteLater(); } -SalFrame* Qt5Instance::CreateChildFrame(SystemParentData* /*pParent*/, SalFrameStyleFlags nStyle) +SalFrame* QtInstance::CreateChildFrame(SystemParentData* /*pParent*/, SalFrameStyleFlags nStyle) { SalFrame* pRet(nullptr); - RunInMainThread([&, this]() { pRet = new Qt5Frame(nullptr, nStyle, useCairo()); }); + RunInMainThread([&, this]() { pRet = new QtFrame(nullptr, nStyle, useCairo()); }); assert(pRet); return pRet; } -SalFrame* Qt5Instance::CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) +SalFrame* QtInstance::CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) { - assert(!pParent || dynamic_cast<Qt5Frame*>(pParent)); + assert(!pParent || dynamic_cast<QtFrame*>(pParent)); SalFrame* pRet(nullptr); RunInMainThread( - [&, this]() { pRet = new Qt5Frame(static_cast<Qt5Frame*>(pParent), nStyle, useCairo()); }); + [&, this]() { pRet = new QtFrame(static_cast<QtFrame*>(pParent), nStyle, useCairo()); }); assert(pRet); return pRet; } -void Qt5Instance::DestroyFrame(SalFrame* pFrame) +void QtInstance::DestroyFrame(SalFrame* pFrame) { if (pFrame) { - assert(dynamic_cast<Qt5Frame*>(pFrame)); - Q_EMIT deleteObjectLaterSignal(static_cast<Qt5Frame*>(pFrame)); + assert(dynamic_cast<QtFrame*>(pFrame)); + Q_EMIT deleteObjectLaterSignal(static_cast<QtFrame*>(pFrame)); } } -SalObject* Qt5Instance::CreateObject(SalFrame* pParent, SystemWindowData*, bool bShow) +SalObject* QtInstance::CreateObject(SalFrame* pParent, SystemWindowData*, bool bShow) { - assert(!pParent || dynamic_cast<Qt5Frame*>(pParent)); + assert(!pParent || dynamic_cast<QtFrame*>(pParent)); SalObject* pRet(nullptr); - RunInMainThread([&]() { pRet = new Qt5Object(static_cast<Qt5Frame*>(pParent), bShow); }); + RunInMainThread([&]() { pRet = new QtObject(static_cast<QtFrame*>(pParent), bShow); }); assert(pRet); return pRet; } -void Qt5Instance::DestroyObject(SalObject* pObject) +void QtInstance::DestroyObject(SalObject* pObject) { if (pObject) { - assert(dynamic_cast<Qt5Object*>(pObject)); - Q_EMIT deleteObjectLaterSignal(static_cast<Qt5Object*>(pObject)); + assert(dynamic_cast<QtObject*>(pObject)); + Q_EMIT deleteObjectLaterSignal(static_cast<QtObject*>(pObject)); } } std::unique_ptr<SalVirtualDevice> -Qt5Instance::CreateVirtualDevice(SalGraphics& rGraphics, tools::Long& nDX, tools::Long& nDY, - DeviceFormat /*eFormat*/, const SystemGraphicsData* pGd) +QtInstance::CreateVirtualDevice(SalGraphics& rGraphics, tools::Long& nDX, tools::Long& nDY, + DeviceFormat /*eFormat*/, const SystemGraphicsData* pGd) { if (m_bUseCairo) { - SvpSalGraphics* pSvpSalGraphics = dynamic_cast<Qt5SvpGraphics*>(&rGraphics); + SvpSalGraphics* pSvpSalGraphics = dynamic_cast<QtSvpGraphics*>(&rGraphics); assert(pSvpSalGraphics); // tdf#127529 see SvpSalInstance::CreateVirtualDevice for the rare case of a non-null pPreExistingTarget cairo_surface_t* pPreExistingTarget = pGd ? static_cast<cairo_surface_t*>(pGd->pSurface) : nullptr; std::unique_ptr<SalVirtualDevice> pVD( - new Qt5SvpVirtualDevice(pSvpSalGraphics->getSurface(), pPreExistingTarget)); + new QtSvpVirtualDevice(pSvpSalGraphics->getSurface(), pPreExistingTarget)); pVD->SetSize(nDX, nDY); return pVD; } else { - std::unique_ptr<SalVirtualDevice> pVD(new Qt5VirtualDevice(/*scale*/ 1)); + std::unique_ptr<SalVirtualDevice> pVD(new QtVirtualDevice(/*scale*/ 1)); pVD->SetSize(nDX, nDY); return pVD; } } -std::unique_ptr<SalMenu> Qt5Instance::CreateMenu(bool bMenuBar, Menu* pVCLMenu) +std::unique_ptr<SalMenu> QtInstance::CreateMenu(bool bMenuBar, Menu* pVCLMenu) { std::unique_ptr<SalMenu> pRet; RunInMainThread([&pRet, bMenuBar, pVCLMenu]() { - Qt5Menu* pSalMenu = new Qt5Menu(bMenuBar); + QtMenu* pSalMenu = new QtMenu(bMenuBar); pRet.reset(pSalMenu); pSalMenu->SetMenu(pVCLMenu); }); @@ -366,28 +365,28 @@ std::unique_ptr<SalMenu> Qt5Instance::CreateMenu(bool bMenuBar, Menu* pVCLMenu) return pRet; } -std::unique_ptr<SalMenuItem> Qt5Instance::CreateMenuItem(const SalItemParams& rItemData) +std::unique_ptr<SalMenuItem> QtInstance::CreateMenuItem(const SalItemParams& rItemData) { - return std::unique_ptr<SalMenuItem>(new Qt5MenuItem(&rItemData)); + return std::unique_ptr<SalMenuItem>(new QtMenuItem(&rItemData)); } -SalTimer* Qt5Instance::CreateSalTimer() +SalTimer* QtInstance::CreateSalTimer() { - m_pTimer = new Qt5Timer(); + m_pTimer = new QtTimer(); return m_pTimer; } -SalSystem* Qt5Instance::CreateSalSystem() { return new Qt5System; } +SalSystem* QtInstance::CreateSalSystem() { return new QtSystem; } -std::shared_ptr<SalBitmap> Qt5Instance::CreateSalBitmap() +std::shared_ptr<SalBitmap> QtInstance::CreateSalBitmap() { if (m_bUseCairo) return std::make_shared<SvpSalBitmap>(); else - return std::make_shared<Qt5Bitmap>(); + return std::make_shared<QtBitmap>(); } -bool Qt5Instance::ImplYield(bool bWait, bool bHandleAllCurrentEvents) +bool QtInstance::ImplYield(bool bWait, bool bHandleAllCurrentEvents) { // Re-acquire the guard for user events when called via Q_EMIT ImplYieldSignal SolarMutexGuard aGuard; @@ -408,7 +407,7 @@ bool Qt5Instance::ImplYield(bool bWait, bool bHandleAllCurrentEvents) return wasEvent; } -bool Qt5Instance::DoYield(bool bWait, bool bHandleAllCurrentEvents) +bool QtInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents) { bool bWasEvent = false; if (qApp->thread() == QThread::currentThread()) @@ -434,7 +433,7 @@ bool Qt5Instance::DoYield(bool bWait, bool bHandleAllCurrentEvents) return bWasEvent; } -bool Qt5Instance::AnyInput(VclInputFlags nType) +bool QtInstance::AnyInput(VclInputFlags nType) { bool bResult = false; if (nType & VclInputFlags::TIMER) @@ -444,62 +443,62 @@ bool Qt5Instance::AnyInput(VclInputFlags nType) return bResult; } -OUString Qt5Instance::GetConnectionIdentifier() { return OUString(); } +OUString QtInstance::GetConnectionIdentifier() { return OUString(); } -void Qt5Instance::AddToRecentDocumentList(const OUString&, const OUString&, const OUString&) {} +void QtInstance::AddToRecentDocumentList(const OUString&, const OUString&, const OUString&) {} #ifndef EMSCRIPTEN -OpenGLContext* Qt5Instance::CreateOpenGLContext() { return new Qt5OpenGLContext; } +OpenGLContext* QtInstance::CreateOpenGLContext() { return new QtOpenGLContext; } #endif -bool Qt5Instance::IsMainThread() const +bool QtInstance::IsMainThread() const { return !qApp || (qApp->thread() == QThread::currentThread()); } -void Qt5Instance::TriggerUserEventProcessing() +void QtInstance::TriggerUserEventProcessing() { QAbstractEventDispatcher* dispatcher = QAbstractEventDispatcher::instance(qApp->thread()); dispatcher->wakeUp(); } -void Qt5Instance::ProcessEvent(SalUserEvent aEvent) +void QtInstance::ProcessEvent(SalUserEvent aEvent) { aEvent.m_pFrame->CallCallback(aEvent.m_nEvent, aEvent.m_pData); } -rtl::Reference<Qt5FilePicker> -Qt5Instance::createPicker(css::uno::Reference<css::uno::XComponentContext> const& context, - QFileDialog::FileMode eMode) +rtl::Reference<QtFilePicker> +QtInstance::createPicker(css::uno::Reference<css::uno::XComponentContext> const& context, + QFileDialog::FileMode eMode) { if (!IsMainThread()) { SolarMutexGuard g; - rtl::Reference<Qt5FilePicker> pPicker; + rtl::Reference<QtFilePicker> pPicker; RunInMainThread([&, this]() { pPicker = createPicker(context, eMode); }); assert(pPicker); return pPicker; } - return new Qt5FilePicker(context, eMode); + return new QtFilePicker(context, eMode); } css::uno::Reference<css::ui::dialogs::XFilePicker2> -Qt5Instance::createFilePicker(const css::uno::Reference<css::uno::XComponentContext>& context) +QtInstance::createFilePicker(const css::uno::Reference<css::uno::XComponentContext>& context) { return css::uno::Reference<css::ui::dialogs::XFilePicker2>( createPicker(context, QFileDialog::ExistingFile)); } css::uno::Reference<css::ui::dialogs::XFolderPicker2> -Qt5Instance::createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>& context) +QtInstance::createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>& context) { return css::uno::Reference<css::ui::dialogs::XFolderPicker2>( createPicker(context, QFileDialog::Directory)); } css::uno::Reference<css::uno::XInterface> -Qt5Instance::CreateClipboard(const css::uno::Sequence<css::uno::Any>& arguments) +QtInstance::CreateClipboard(const css::uno::Sequence<css::uno::Any>& arguments) { OUString sel; if (arguments.getLength() == 0) @@ -508,7 +507,7 @@ Qt5Instance::CreateClipboard(const css::uno::Sequence<css::uno::Any>& arguments) } else if (arguments.getLength() != 1 || !(arguments[0] >>= sel)) { - throw css::lang::IllegalArgumentException("bad Qt5Instance::CreateClipboard arguments", + throw css::lang::IllegalArgumentException("bad QtInstance::CreateClipboard arguments", css::uno::Reference<css::uno::XInterface>(), -1); } @@ -521,26 +520,26 @@ Qt5Instance::CreateClipboard(const css::uno::Sequence<css::uno::Any>& arguments) if (it != m_aClipboards.end()) return it->second; - css::uno::Reference<css::uno::XInterface> xClipboard = Qt5Clipboard::create(sel); + css::uno::Reference<css::uno::XInterface> xClipboard = QtClipboard::create(sel); if (xClipboard.is()) m_aClipboards[sel] = xClipboard; return xClipboard; } -css::uno::Reference<css::uno::XInterface> Qt5Instance::CreateDragSource() +css::uno::Reference<css::uno::XInterface> QtInstance::CreateDragSource() { return css::uno::Reference<css::uno::XInterface>( - static_cast<cppu::OWeakObject*>(new Qt5DragSource())); + static_cast<cppu::OWeakObject*>(new QtDragSource())); } -css::uno::Reference<css::uno::XInterface> Qt5Instance::CreateDropTarget() +css::uno::Reference<css::uno::XInterface> QtInstance::CreateDropTarget() { return css::uno::Reference<css::uno::XInterface>( - static_cast<cppu::OWeakObject*>(new Qt5DropTarget())); + static_cast<cppu::OWeakObject*>(new QtDropTarget())); } -IMPL_LINK_NOARG(Qt5Instance, updateStyleHdl, Timer*, void) +IMPL_LINK_NOARG(QtInstance, updateStyleHdl, Timer*, void) { SolarMutexGuard aGuard; SalFrame* pFrame = anyFrame(); @@ -555,7 +554,7 @@ IMPL_LINK_NOARG(Qt5Instance, updateStyleHdl, Timer*, void) } } -void Qt5Instance::UpdateStyle(bool bFontsChanged) +void QtInstance::UpdateStyle(bool bFontsChanged) { if (bFontsChanged) m_bUpdateFonts = true; @@ -563,7 +562,7 @@ void Qt5Instance::UpdateStyle(bool bFontsChanged) m_aUpdateStyleTimer.Start(); } -void* Qt5Instance::CreateGStreamerSink(const SystemChildWindow* pWindow) +void* QtInstance::CreateGStreamerSink(const SystemChildWindow* pWindow) { #if ENABLE_GSTREAMER_1_0 && QT5_HAVE_GOBJECT auto pSymbol = gstElementFactoryNameSymbol(); @@ -598,9 +597,9 @@ void* Qt5Instance::CreateGStreamerSink(const SystemChildWindow* pWindow) #endif } -void Qt5Instance::AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, - std::unique_ptr<int>& rFakeArgc, - std::vector<FreeableCStr>& rFakeArgvFreeable) +void QtInstance::AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, + std::unique_ptr<int>& rFakeArgc, + std::vector<FreeableCStr>& rFakeArgvFreeable) { OString aVersion(qVersion()); SAL_INFO("vcl.qt5", "qt version string is " << aVersion); @@ -644,16 +643,16 @@ void Qt5Instance::AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, *rFakeArgc = nFakeArgc; } -void Qt5Instance::MoveFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, - std::unique_ptr<int>& rFakeArgc, - std::vector<FreeableCStr>& rFakeArgvFreeable) +void QtInstance::MoveFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, + std::unique_ptr<int>& rFakeArgc, + std::vector<FreeableCStr>& rFakeArgvFreeable) { m_pFakeArgv = std::move(rFakeArgv); m_pFakeArgc = std::move(rFakeArgc); m_pFakeArgvFreeable.swap(rFakeArgvFreeable); } -std::unique_ptr<QApplication> Qt5Instance::CreateQApplication(int& nArgc, char** pArgv) +std::unique_ptr<QApplication> QtInstance::CreateQApplication(int& nArgc, char** pArgv) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // for scaled icons in the native menus @@ -686,15 +685,15 @@ VCLPLUG_QT5_PUBLIC SalInstance* create_SalInstance() std::unique_ptr<char* []> pFakeArgv; std::unique_ptr<int> pFakeArgc; std::vector<FreeableCStr> aFakeArgvFreeable; - Qt5Instance::AllocFakeCmdlineArgs(pFakeArgv, pFakeArgc, aFakeArgvFreeable); + QtInstance::AllocFakeCmdlineArgs(pFakeArgv, pFakeArgc, aFakeArgvFreeable); std::unique_ptr<QApplication> pQApp - = Qt5Instance::CreateQApplication(*pFakeArgc, pFakeArgv.get()); + = QtInstance::CreateQApplication(*pFakeArgc, pFakeArgv.get()); - Qt5Instance* pInstance = new Qt5Instance(pQApp, bUseCairo); + QtInstance* pInstance = new QtInstance(pQApp, bUseCairo); pInstance->MoveFakeCmdlineArgs(pFakeArgv, pFakeArgc, aFakeArgvFreeable); - new Qt5Data(pInstance); + new QtData(pInstance); return pInstance; } |