diff options
author | Liang Qi <liang.qi@qt.io> | 2018-06-30 22:59:21 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-07-02 11:23:45 +0200 |
commit | e3ed2281c0c891cf3b15c95f9f7cdae42e9f233a (patch) | |
tree | aae8da6ce616eae02b69fb1fcdcb4383c8fe6811 /src/plugins/platforms/windows | |
parent | 3be141d5bc199080b524d8f6f5ce514e8f74d23a (diff) | |
parent | e75e4b39b78ba05ea2cd45dc96acf99fc89c5915 (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
Conflicts:
src/plugins/platforms/cocoa/qnsview.mm
src/plugins/platforms/cocoa/qnsview_dragging.mm
src/plugins/platforms/ios/qiosinputcontext.mm
src/plugins/platforms/xcb/qxcbconnection.cpp
src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
src/plugins/platforms/xcb/qxcbwindow.cpp
src/tools/androiddeployqt/main.cpp
Was moved from qttools into qtbase in 5.11.
So re-apply 32398e4d here.
tests/auto/corelib/global/qlogging/test/test.pro
tests/auto/corelib/global/qlogging/tst_qlogging.cpp
tests/auto/corelib/io/qfile/tst_qfile.cpp
tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
tests/auto/corelib/thread/qthreadstorage/test/test.pro
tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
tests/auto/widgets/kernel/qapplication/test/test.pro
Done-with: Gatis Paeglis <gatis.paeglis@qt.io>
Done-with: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Done-with: Oliver Wolff <oliver.wolff@qt.io>
Change-Id: Id970486c5315a1718c540f00deb2633533e8fc7b
Diffstat (limited to 'src/plugins/platforms/windows')
7 files changed, 124 insertions, 64 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 80f3203289..980a9fe9ab 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1430,7 +1430,7 @@ bool QWindowsContext::filterNativeEvent(MSG *msg, LRESULT *result) bool QWindowsContext::filterNativeEvent(QWindow *window, MSG *msg, LRESULT *result) { long filterResult = 0; - if (QWindowSystemInterface::handleNativeEvent(window, nativeEventType(), &msg, &filterResult)) { + if (QWindowSystemInterface::handleNativeEvent(window, nativeEventType(), msg, &filterResult)) { *result = LRESULT(filterResult); return true; } diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index 6358778914..2409d70ec9 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -153,9 +153,11 @@ QT_BEGIN_NAMESPACE QWindowsOpengl32DLL QOpenGLStaticContext::opengl32; -FARPROC QWindowsOpengl32DLL::resolve(const char *name) +QFunctionPointer QWindowsOpengl32DLL::resolve(const char *name) { - return m_lib ? ::GetProcAddress(m_lib, name) : nullptr; + return m_lib + ? reinterpret_cast<QFunctionPointer>(::GetProcAddress(m_lib, name)) + : nullptr; } bool QWindowsOpengl32DLL::init(bool softwareRendering) @@ -977,12 +979,18 @@ QOpenGLStaticContext::QOpenGLStaticContext() : extensionNames(QOpenGLStaticContext::getGlString(GL_EXTENSIONS)), extensions(0), defaultFormat(QWindowsOpenGLContextFormat::current()), - wglGetPixelFormatAttribIVARB((WglGetPixelFormatAttribIVARB)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetPixelFormatAttribivARB")), - wglChoosePixelFormatARB((WglChoosePixelFormatARB)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglChoosePixelFormatARB")), - wglCreateContextAttribsARB((WglCreateContextAttribsARB)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglCreateContextAttribsARB")), - wglSwapInternalExt((WglSwapInternalExt)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglSwapIntervalEXT")), - wglGetSwapInternalExt((WglGetSwapInternalExt)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetSwapIntervalEXT")), - wglGetExtensionsStringARB((WglGetExtensionsStringARB)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetExtensionsStringARB")) + wglGetPixelFormatAttribIVARB(reinterpret_cast<WglGetPixelFormatAttribIVARB>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetPixelFormatAttribivARB")))), + wglChoosePixelFormatARB(reinterpret_cast<WglChoosePixelFormatARB>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglChoosePixelFormatARB")))), + wglCreateContextAttribsARB(reinterpret_cast<WglCreateContextAttribsARB>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglCreateContextAttribsARB")))), + wglSwapInternalExt(reinterpret_cast<WglSwapInternalExt>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglSwapIntervalEXT")))), + wglGetSwapInternalExt(reinterpret_cast<WglGetSwapInternalExt>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetSwapIntervalEXT")))), + wglGetExtensionsStringARB(reinterpret_cast<WglGetExtensionsStringARB>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetExtensionsStringARB")))) { if (extensionNames.startsWith(SAMPLE_BUFFER_EXTENSION " ") || extensionNames.indexOf(" " SAMPLE_BUFFER_EXTENSION " ") != -1) @@ -1231,7 +1239,8 @@ bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval) hasRobustness = exts && strstr(exts, "GL_ARB_robustness"); } else { typedef const GLubyte * (APIENTRY *glGetStringi_t)(GLenum, GLuint); - glGetStringi_t glGetStringi = (glGetStringi_t) QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetStringi"); + glGetStringi_t glGetStringi = reinterpret_cast<glGetStringi_t>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetStringi"))); if (glGetStringi) { GLint n = 0; QOpenGLStaticContext::opengl32.glGetIntegerv(GL_NUM_EXTENSIONS, &n); @@ -1244,8 +1253,10 @@ bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval) } } } - if (hasRobustness) - m_getGraphicsResetStatus = (GLenum (APIENTRY *)()) QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetGraphicsResetStatusARB"); + if (hasRobustness) { + m_getGraphicsResetStatus = reinterpret_cast<GlGetGraphicsResetStatusArbType>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetGraphicsResetStatusARB"))); + } QOpenGLStaticContext::opengl32.wglMakeCurrent(prevSurface, prevContext); return true; @@ -1369,16 +1380,17 @@ QFunctionPointer QWindowsGLContext::getProcAddress(const char *procName) // Even though we use QFunctionPointer, it does not mean the function can be called. // It will need to be cast to the proper function type with the correct calling // convention. QFunctionPointer is nothing more than a glorified void* here. - PROC procAddress = QOpenGLStaticContext::opengl32.wglGetProcAddress(procName); + QFunctionPointer procAddress = reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress(procName)); // We support AllGLFunctionsQueryable, which means this function must be able to // return a function pointer even for functions that are in GL.h and exported // normally from opengl32.dll. wglGetProcAddress() is not guaranteed to work for such // functions, however in QT_OPENGL_DYNAMIC builds QOpenGLFunctions will just blindly // call into here for _any_ OpenGL function. - if (!procAddress || procAddress == reinterpret_cast<PROC>(0x1) || procAddress == reinterpret_cast<PROC>(0x2) - || procAddress == reinterpret_cast<PROC>(0x3) || procAddress == reinterpret_cast<PROC>(-1)) + if (procAddress == nullptr || reinterpret_cast<quintptr>(procAddress) < 4u + || procAddress == reinterpret_cast<QFunctionPointer>(-1)) { procAddress = QOpenGLStaticContext::opengl32.resolve(procName); + } if (QWindowsContext::verbose > 1) qCDebug(lcQpaGl) << __FUNCTION__ << procName << QOpenGLStaticContext::opengl32.wglGetCurrentContext() << "returns" << procAddress; diff --git a/src/plugins/platforms/windows/qwindowsglcontext.h b/src/plugins/platforms/windows/qwindowsglcontext.h index 2e89711740..8c96a8dd0c 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.h +++ b/src/plugins/platforms/windows/qwindowsglcontext.h @@ -122,7 +122,7 @@ struct QWindowsOpengl32DLL void (APIENTRY * glGetIntegerv)(GLenum pname, GLint* params); const GLubyte * (APIENTRY * glGetString)(GLenum name); - FARPROC resolve(const char *name); + QFunctionPointer resolve(const char *name); private: HMODULE m_lib; bool m_nonOpengl32; @@ -217,6 +217,8 @@ public: void *nativeContext() const override { return m_renderingContext; } private: + typedef GLenum (APIENTRY *GlGetGraphicsResetStatusArbType)(); + inline void releaseDCs(); bool updateObtainedParams(HDC hdc, int *obtainedSwapInterval = 0); @@ -230,7 +232,7 @@ private: bool m_extensionsUsed; int m_swapInterval; bool m_ownsContext; - GLenum (APIENTRY * m_getGraphicsResetStatus)(); + GlGetGraphicsResetStatusArbType m_getGraphicsResetStatus; bool m_lost; }; #endif diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.cpp b/src/plugins/platforms/windows/qwindowsinputcontext.cpp index 9f4dea915e..30da0da1de 100644 --- a/src/plugins/platforms/windows/qwindowsinputcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsinputcontext.cpp @@ -163,19 +163,22 @@ Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id); // from qlocale_win.cpp */ -HIMC QWindowsInputContext::m_defaultContext = 0; - QWindowsInputContext::QWindowsInputContext() : m_WM_MSIME_MOUSE(RegisterWindowMessage(L"MSIMEMouseOperation")), m_languageId(currentInputLanguageId()), m_locale(qt_localeFromLCID(m_languageId)) { + const quint32 bmpData = 0; + m_transparentBitmap = CreateBitmap(2, 2, 1, 1, &bmpData); + connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged, this, &QWindowsInputContext::cursorRectChanged); } QWindowsInputContext::~QWindowsInputContext() { + if (m_transparentBitmap) + DeleteObject(m_transparentBitmap); } bool QWindowsInputContext::hasCapability(Capability capability) const @@ -242,6 +245,43 @@ bool QWindowsInputContext::isInputPanelVisible() const return hwnd && ::IsWindowEnabled(hwnd) && ::IsWindowVisible(hwnd); } +void QWindowsInputContext::showInputPanel() +{ + if (!inputMethodAccepted()) + return; + + QWindow *window = QGuiApplication::focusWindow(); + if (!window) + return; + + QWindowsWindow *platformWindow = QWindowsWindow::windowsWindowOf(window); + if (!platformWindow) + return; + + // Create an invisible 2x2 caret, which will be kept at the microfocus position. + // It is important for triggering the on-screen keyboard in touch-screen devices, + // for some Chinese input methods, and for Magnifier's "follow keyboard" feature. + if (!m_caretCreated && m_transparentBitmap) + m_caretCreated = CreateCaret(platformWindow->handle(), m_transparentBitmap, 0, 0); + + // For some reason, the on-screen keyboard is only triggered on the Surface + // with Windows 10 if the Windows IME is (re)enabled _after_ the caret is shown. + if (m_caretCreated) { + cursorRectChanged(); + ShowCaret(platformWindow->handle()); + setWindowsImeEnabled(platformWindow, false); + setWindowsImeEnabled(platformWindow, true); + } +} + +void QWindowsInputContext::hideInputPanel() +{ + if (m_caretCreated) { + DestroyCaret(); + m_caretCreated = false; + } +} + void QWindowsInputContext::updateEnabled() { if (!QGuiApplication::focusObject()) @@ -256,18 +296,14 @@ void QWindowsInputContext::updateEnabled() void QWindowsInputContext::setWindowsImeEnabled(QWindowsWindow *platformWindow, bool enabled) { - if (!platformWindow || platformWindow->testFlag(QWindowsWindow::InputMethodDisabled) == !enabled) + if (!platformWindow) return; if (enabled) { - // Re-enable Windows IME by associating default context saved on first disabling. - ImmAssociateContext(platformWindow->handle(), QWindowsInputContext::m_defaultContext); - platformWindow->clearFlag(QWindowsWindow::InputMethodDisabled); + // Re-enable Windows IME by associating default context. + ImmAssociateContextEx(platformWindow->handle(), 0, IACE_DEFAULT); } else { - // Disable Windows IME by associating 0 context. Store context first time. - const HIMC oldImC = ImmAssociateContext(platformWindow->handle(), 0); - platformWindow->setFlag(QWindowsWindow::InputMethodDisabled); - if (!QWindowsInputContext::m_defaultContext && oldImC) - QWindowsInputContext::m_defaultContext = oldImC; + // Disable Windows IME by associating 0 context. + ImmAssociateContext(platformWindow->handle(), 0); } } @@ -284,15 +320,25 @@ void QWindowsInputContext::update(Qt::InputMethodQueries queries) void QWindowsInputContext::cursorRectChanged() { - if (!m_compositionContext.hwnd) + QWindow *window = QGuiApplication::focusWindow(); + if (!window) return; + + qreal factor = QHighDpiScaling::factor(window); + const QInputMethod *inputMethod = QGuiApplication::inputMethod(); const QRectF cursorRectangleF = inputMethod->cursorRectangle(); if (!cursorRectangleF.isValid()) return; + const QRect cursorRectangle = - QRectF(cursorRectangleF.topLeft() * m_compositionContext.factor, - cursorRectangleF.size() * m_compositionContext.factor).toRect(); + QRectF(cursorRectangleF.topLeft() * factor, cursorRectangleF.size() * factor).toRect(); + + if (m_caretCreated) + SetCaretPos(cursorRectangle.x(), cursorRectangle.y()); + + if (!m_compositionContext.hwnd) + return; qCDebug(lcQpaInputMethods) << __FUNCTION__<< cursorRectangle; @@ -316,9 +362,6 @@ void QWindowsInputContext::cursorRectChanged() candf.rcArea.right = cursorRectangle.x() + cursorRectangle.width(); candf.rcArea.bottom = cursorRectangle.y() + cursorRectangle.height(); - if (m_compositionContext.haveCaret) - SetCaretPos(cursorRectangle.x(), cursorRectangle.y()); - ImmSetCompositionWindow(himc, &cf); ImmSetCandidateWindow(himc, &candf); ImmReleaseContext(m_compositionContext.hwnd, himc); @@ -410,7 +453,7 @@ bool QWindowsInputContext::startComposition(HWND hwnd) qCDebug(lcQpaInputMethods) << __FUNCTION__ << fo << window << "language=" << m_languageId; if (!fo || QWindowsWindow::handleOf(window) != hwnd) return false; - initContext(hwnd, QHighDpiScaling::factor(window), fo); + initContext(hwnd, fo); startContextComposition(); return true; } @@ -550,18 +593,13 @@ bool QWindowsInputContext::endComposition(HWND hwnd) return true; } -void QWindowsInputContext::initContext(HWND hwnd, qreal factor, QObject *focusObject) +void QWindowsInputContext::initContext(HWND hwnd, QObject *focusObject) { if (m_compositionContext.hwnd) doneContext(); m_compositionContext.hwnd = hwnd; m_compositionContext.focusObject = focusObject; - m_compositionContext.factor = factor; - // Create a hidden caret which is kept at the microfocus - // position in update(). This is important for some - // Chinese input methods. - m_compositionContext.haveCaret = CreateCaret(hwnd, 0, 1, 1); - HideCaret(hwnd); + update(Qt::ImQueryAll); m_compositionContext.isComposing = false; m_compositionContext.position = 0; @@ -571,12 +609,10 @@ void QWindowsInputContext::doneContext() { if (!m_compositionContext.hwnd) return; - if (m_compositionContext.haveCaret) - DestroyCaret(); m_compositionContext.hwnd = 0; m_compositionContext.composition.clear(); m_compositionContext.position = 0; - m_compositionContext.isComposing = m_compositionContext.haveCaret = false; + m_compositionContext.isComposing = false; m_compositionContext.focusObject = 0; } diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.h b/src/plugins/platforms/windows/qwindowsinputcontext.h index 35105d15ff..8668efbb15 100644 --- a/src/plugins/platforms/windows/qwindowsinputcontext.h +++ b/src/plugins/platforms/windows/qwindowsinputcontext.h @@ -58,12 +58,10 @@ class QWindowsInputContext : public QPlatformInputContext struct CompositionContext { HWND hwnd = 0; - bool haveCaret = false; QString composition; int position = 0; bool isComposing = false; QPointer<QObject> focusObject; - qreal factor = 1; }; public: explicit QWindowsInputContext(); @@ -81,6 +79,8 @@ public: QRectF keyboardRect() const override; bool isInputPanelVisible() const override; + void showInputPanel() override; + void hideInputPanel() override; bool startComposition(HWND hwnd); bool composition(HWND hwnd, LPARAM lParam); @@ -96,7 +96,7 @@ private slots: void cursorRectChanged(); private: - void initContext(HWND hwnd, qreal factor, QObject *focusObject); + void initContext(HWND hwnd, QObject *focusObject); void doneContext(); void startContextComposition(); void endContextComposition(); @@ -104,7 +104,8 @@ private: HWND getVirtualKeyboardWindowHandle() const; const DWORD m_WM_MSIME_MOUSE; - static HIMC m_defaultContext; + bool m_caretCreated = false; + HBITMAP m_transparentBitmap; CompositionContext m_compositionContext; bool m_endCompositionRecursionGuard = false; LCID m_languageId; diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp index a90a44c4e1..c4ee820211 100644 --- a/src/plugins/platforms/windows/qwindowsopengltester.cpp +++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp @@ -283,16 +283,21 @@ QWindowsOpenGLTester::Renderers QWindowsOpenGLTester::supportedRenderers() bool QWindowsOpenGLTester::testDesktopGL() { #if !defined(QT_NO_OPENGL) + typedef HGLRC (WINAPI *CreateContextType)(HDC); + typedef BOOL (WINAPI *DeleteContextType)(HGLRC); + typedef BOOL (WINAPI *MakeCurrentType)(HDC, HGLRC); + typedef PROC (WINAPI *WglGetProcAddressType)(LPCSTR); + HMODULE lib = 0; HWND wnd = 0; HDC dc = 0; HGLRC context = 0; LPCTSTR className = L"qtopengltest"; - HGLRC (WINAPI * CreateContext)(HDC dc) = 0; - BOOL (WINAPI * DeleteContext)(HGLRC context) = 0; - BOOL (WINAPI * MakeCurrent)(HDC dc, HGLRC context) = 0; - PROC (WINAPI * WGL_GetProcAddress)(LPCSTR name) = 0; + CreateContextType CreateContext = nullptr; + DeleteContextType DeleteContext = nullptr; + MakeCurrentType MakeCurrent = nullptr; + WglGetProcAddressType WGL_GetProcAddress = nullptr; bool result = false; @@ -300,16 +305,20 @@ bool QWindowsOpenGLTester::testDesktopGL() // This will typically fail on systems that do not have a real OpenGL driver. lib = LoadLibraryA("opengl32.dll"); if (lib) { - CreateContext = reinterpret_cast<HGLRC (WINAPI *)(HDC)>(::GetProcAddress(lib, "wglCreateContext")); + CreateContext = reinterpret_cast<CreateContextType>( + reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "wglCreateContext"))); if (!CreateContext) goto cleanup; - DeleteContext = reinterpret_cast<BOOL (WINAPI *)(HGLRC)>(::GetProcAddress(lib, "wglDeleteContext")); + DeleteContext = reinterpret_cast<DeleteContextType>( + reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "wglDeleteContext"))); if (!DeleteContext) goto cleanup; - MakeCurrent = reinterpret_cast<BOOL (WINAPI *)(HDC, HGLRC)>(::GetProcAddress(lib, "wglMakeCurrent")); + MakeCurrent = reinterpret_cast<MakeCurrentType>( + reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "wglMakeCurrent"))); if (!MakeCurrent) goto cleanup; - WGL_GetProcAddress = reinterpret_cast<PROC (WINAPI *)(LPCSTR)>(::GetProcAddress(lib, "wglGetProcAddress")); + WGL_GetProcAddress = reinterpret_cast<WglGetProcAddressType>( + reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "wglGetProcAddress"))); if (!WGL_GetProcAddress) goto cleanup; @@ -356,7 +365,8 @@ bool QWindowsOpenGLTester::testDesktopGL() // Check the version. If we got 1.x then it's all hopeless and we can stop right here. typedef const GLubyte * (APIENTRY * GetString_t)(GLenum name); - GetString_t GetString = reinterpret_cast<GetString_t>(::GetProcAddress(lib, "glGetString")); + GetString_t GetString = reinterpret_cast<GetString_t>( + reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "glGetString"))); if (GetString) { if (const char *versionStr = reinterpret_cast<const char *>(GetString(GL_VERSION))) { const QByteArray version(versionStr); diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 02e986fd90..5ff25eb474 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -215,12 +215,11 @@ public: WithinCreate = 0x20000, WithinMaximize = 0x40000, MaximizeToFullScreen = 0x80000, - InputMethodDisabled = 0x100000, - Compositing = 0x200000, - HasBorderInFullScreen = 0x400000, - WithinDpiChanged = 0x800000, - VulkanSurface = 0x1000000, - ResizeMoveActive = 0x2000000 + Compositing = 0x100000, + HasBorderInFullScreen = 0x200000, + WithinDpiChanged = 0x400000, + VulkanSurface = 0x800000, + ResizeMoveActive = 0x1000000 }; QWindowsWindow(QWindow *window, const QWindowsWindowData &data); |