From 9a2fe76443e814c221f308f8fe37ef6fcccbcf74 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 1 Oct 2009 14:12:30 +0200 Subject: fix minimizing for Windows CE and Windows mobile Task-number: QT-2243 Reviewed-by: thartman --- src/gui/kernel/qapplication_win.cpp | 19 ++++++++++++++----- src/gui/kernel/qguifunctions_wince.cpp | 13 +++++-------- src/gui/kernel/qwidget_wince.cpp | 26 +++++++++++--------------- tests/auto/qwidget/tst_qwidget.cpp | 10 ---------- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index eb9e276..44f82b6 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -1967,13 +1967,22 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam // where it got it from; it would simply get a 0 value as the old focus widget. #ifdef Q_WS_WINCE { - if (widget->windowState() & Qt::WindowMinimized) { - if (widget->windowState() & Qt::WindowMaximized) - widget->showMaximized(); - else - widget->show(); +#ifdef Q_WS_WINCE_WM + // On Windows mobile we do not receive WM_SYSCOMMAND / SC_MINIMIZE messages. + // Thus we have to unset the minimized state explicitly. We must do this for all + // top-level widgets, because we get the HWND of a random widget here. + foreach (QWidget* tlw, QApplication::topLevelWidgets()) { + if (tlw->isMinimized()) + tlw->setWindowState(tlw->windowState() & ~Qt::WindowMinimized); } #else + // On Windows CE we do not receive WM_SYSCOMMAND / SC_MINIMIZE messages. + // Thus we have to unset the minimized state explicitly. + if (widget->windowState() & Qt::WindowMinimized) + widget->setWindowState(widget->windowState() & ~Qt::WindowMinimized); +#endif // Q_WS_WINCE_WM + +#else if (!(widget->windowState() & Qt::WindowMinimized)) { #endif // Ignore the activate message send by WindowsXP to a minimized window diff --git a/src/gui/kernel/qguifunctions_wince.cpp b/src/gui/kernel/qguifunctions_wince.cpp index 048780e..58e12ee 100644 --- a/src/gui/kernel/qguifunctions_wince.cpp +++ b/src/gui/kernel/qguifunctions_wince.cpp @@ -329,17 +329,14 @@ void qt_wince_maximize(QWidget *widget) void qt_wince_minimize(HWND hwnd) { - uint exstyle = GetWindowLongW(hwnd, GWL_EXSTYLE); - uint style = GetWindowLongW(hwnd, GWL_STYLE); - RECT rect; - RECT crect = {0,0,0,0}; - GetWindowRect(hwnd, &rect); - AdjustWindowRectEx(&crect, style & ~WS_OVERLAPPED, FALSE, exstyle); - MoveWindow(hwnd, rect.left - crect.left, rect.top - crect.top, 0, 0, true); - SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong (hwnd, GWL_EXSTYLE) | WS_EX_NODRAG); #ifdef Q_OS_WINCE_WM ShowWindow(hwnd, SW_HIDE); #else + if (!IsWindowVisible(hwnd)) { + // Hack for an initial showMinimized. + // Without it, our widget doesn't appear in the task bar. + ShowWindow(hwnd, SW_SHOW); + } ShowWindow(hwnd, SW_MINIMIZE); #endif } diff --git a/src/gui/kernel/qwidget_wince.cpp b/src/gui/kernel/qwidget_wince.cpp index 32e8e7f..c0664f4 100644 --- a/src/gui/kernel/qwidget_wince.cpp +++ b/src/gui/kernel/qwidget_wince.cpp @@ -416,6 +416,10 @@ void QWidgetPrivate::show_sys() { SetWindowLong(q->internalWinId(), GWL_STYLE, style | WS_MAXIMIZEBOX); } } else +#else + // Imitate minimizing on Windows mobile by hiding the widget. + if (q->isMinimized()) + sm = SW_HIDE; #endif if (q->isHidden()) { sm = SW_HIDE; @@ -428,8 +432,7 @@ void QWidgetPrivate::show_sys() { sm = SW_SHOWNOACTIVATE; } - if (!(data.window_state & Qt::WindowMinimized)) - ShowWindow(q->internalWinId(), sm); + ShowWindow(q->internalWinId(), sm); if (q->isMaximized() && q->isWindow()) qt_wince_maximize(q); @@ -438,7 +441,7 @@ void QWidgetPrivate::show_sys() { if (!qt_wince_is_mobile() && q->isFullScreen()) { HWND handle = FindWindow(L"HHTaskBar", L""); if (handle) { - ShowWindow(handle, 0); + ShowWindow(handle, SW_HIDE); EnableWindow(handle, false); } } @@ -468,17 +471,12 @@ void QWidget::setWindowState(Qt::WindowStates newstate) return; int max = SW_SHOWNORMAL; - int min = SW_SHOWNOACTIVATE; - int normal = SW_SHOWNOACTIVATE; if ((oldstate & Qt::WindowMinimized) && !(newstate & Qt::WindowMinimized)) newstate |= Qt::WindowActive; - if (newstate & Qt::WindowActive) { - max = SW_SHOWNORMAL; - min = SW_SHOWNORMAL; + if (newstate & Qt::WindowActive) normal = SW_SHOWNORMAL; - } if (isWindow()) { createWinId(); Q_ASSERT(testAttribute(Qt::WA_WState_Created)); @@ -556,13 +554,11 @@ void QWidget::setWindowState(Qt::WindowStates newstate) } } if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) { - if (isVisible()) { - ShowWindow(internalWinId(), (newstate & Qt::WindowMinimized) ? min : - (newstate & Qt::WindowMaximized) ? max : normal); - if (newstate & Qt::WindowMaximized) - qt_wince_maximize(this); if (newstate & Qt::WindowMinimized) qt_wince_minimize(internalWinId()); + else if (newstate & Qt::WindowMaximized) { + ShowWindow(internalWinId(), max); + qt_wince_maximize(this); } } if ((newstate & Qt::WindowMaximized) && !(newstate & Qt::WindowFullScreen)) { @@ -588,7 +584,7 @@ void QWidgetPrivate::deleteSysExtra() if (!qt_wince_is_mobile() && q->isFullScreen()) { HWND handle = FindWindow(L"HHTaskBar", L""); if (handle) { - ShowWindow(handle, 1); + ShowWindow(handle, SW_SHOWNORMAL); EnableWindow(handle, true); } } diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index c4e62ef..e4608b2 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -8046,13 +8046,8 @@ void tst_QWidget::doubleRepaint() QTRY_COMPARE(widget.numPaintEvents, expectedRepaints); widget.numPaintEvents = 0; -#ifndef Q_OS_WINCE //still no proper minimizing // Minmize: Should not trigger a repaint. widget.showMinimized(); -#else - // Hide: Should not trigger a repaint. - widget.hide(); -#endif QTest::qWait(10); QCOMPARE(widget.numPaintEvents, 0); widget.numPaintEvents = 0; @@ -8061,12 +8056,7 @@ void tst_QWidget::doubleRepaint() widget.showNormal(); QTest::qWaitForWindowShown(&widget); QTest::qWait(10); -#ifndef Q_OS_WINCE QCOMPARE(widget.numPaintEvents, 0); -#else - // We called hide(), and then it'll get repainted once it's shown again. - QCOMPARE(widget.numPaintEvents, 1); -#endif } #ifndef Q_WS_MAC -- cgit v0.12