Index: /trunk/src/gui/kernel/qapplication_pm.cpp
===================================================================
--- /trunk/src/gui/kernel/qapplication_pm.cpp	(revision 120)
+++ /trunk/src/gui/kernel/qapplication_pm.cpp	(revision 121)
@@ -600,5 +600,4 @@
             }
 
-            case WM_MOVE:   // move window
             case WM_SIZE: { // resize window
                 if (widget->translateConfigEvent(qmsg))
@@ -698,84 +697,30 @@
             }
 
-            default:
-                break;
-            }
-        }
-
-    } while(0);
-
-    return WinDefWindowProc(hwnd, msg, mp1, mp2);
-}
-
-PFNWP QtOldFrameProc = 0;
-
-MRESULT EXPENTRY QtFrameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
-{
-    do {
-        if (!qApp) // unstable app state
-            break;
-#if 0
-        // make sure we show widgets (e.g. scrollbars) when the user resizes
-        if (qApp->loopLevel())
-            qApp->sendPostedEvents(0, QEvent::ShowWindowRequest);
-#endif
-
-        MRESULT rc = (MRESULT) FALSE;
-
-        HWND hwndC = WinWindowFromID(hwnd, FID_CLIENT);
-        QETWidget *widget = (QETWidget*)QWidget::find(hwndC);
-        if (!widget) // don't know this widget
-            break;
-
-        Q_ASSERT(widget->isWindow());
-
-#if defined(QT_DEBUGMSGFLOW)
-        {
-            QMSG qmsg; // create QMSG structure
-            qmsg.hwnd = hwnd;
-            qmsg.msg = msg;
-            qmsg.mp1 = mp1;
-            qmsg.mp2 = mp2;
-            QString str = qStrQMSG(qmsg);
-            if (!str.isEmpty())
-                qDebug() << "*** [F]" << str.toUtf8().constData();
-        }
-#endif
-
-        switch(msg) {
-
-        case WM_WINDOWPOSCHANGED: {
-            // We detect spontaneous min/max/restore events here instead of
-            // WM_MINMAXFRAME, because WM_MINMAXFRAME is a pre-process message
-            // (i.e. no actual changes have been made). We need actual changes
-            // in order to update the frame strut and send WindowStateChange.
-            rc = QtOldFrameProc(hwnd, msg, mp1, mp2);
-
-            ULONG awp = LONGFROMMP(mp2);
-
-            bool window_state_change = false;
-            Qt::WindowStates oldstate = Qt::WindowStates(widget->dataPtr()->window_state);
-
-            if (awp & AWP_MINIMIZED) {
-                window_state_change = true;
-                widget->dataPtr()->window_state |= Qt::WindowMinimized;
-                if (widget->isVisible()) {
-                    QHideEvent e;
-                    qt_sendSpontaneousEvent(widget, &e);
-                    widget->dptr()->hideChildren(true);
-                    const QString title = widget->windowIconText();
-                    if (!title.isEmpty())
-                        widget->dptr()->setWindowTitle_helper(title);
-                }
-            } else {
-                if (awp & AWP_MAXIMIZED) {
-                    widget->topData()->normalGeometry = widget->geometry();
-                }
-                if (awp & AWP_RESTORED) {
+            case WM_MINMAXFRAME: {
+                PSWP pswp = (PSWP)mp1;
+
+                bool window_state_change = false;
+                Qt::WindowStates oldstate = Qt::WindowStates(widget->dataPtr()->window_state);
+
+                if (pswp->fl & SWP_MINIMIZE) {
                     window_state_change = true;
-                    if (awp & AWP_MAXIMIZED)
+                    widget->dataPtr()->window_state |= Qt::WindowMinimized;
+                    if (widget->isVisible()) {
+                        QHideEvent e;
+                        qt_sendSpontaneousEvent(widget, &e);
+                        widget->dptr()->hideChildren(true);
+                        const QString title = widget->windowIconText();
+                        if (!title.isEmpty())
+                            widget->dptr()->setWindowTitle_helper(title);
+                    }
+                } else if (pswp->fl & (SWP_MAXIMIZE | SWP_RESTORE)) {
+                    window_state_change = true;
+                    if (pswp->fl & SWP_MAXIMIZE) {
+                        widget->topData()->normalGeometry = widget->geometry();
                         widget->dataPtr()->window_state |= Qt::WindowMaximized;
-                    else if (!widget->isMinimized())
+                    }
+                    else if (!widget->isMinimized()) {
                         widget->dataPtr()->window_state &= ~Qt::WindowMaximized;
+                    }
 
                     if (widget->isMinimized()) {
@@ -789,17 +734,67 @@
                     }
                 }
-            }
-
-            if (window_state_change) {
-                widget->dptr()->updateFrameStrut();
-                if (!widget->topData()->inSetWindowState) {
-                    // send WindowStateChange event if this message is NOT
-                    // originated from QWidget::setWindowState().
+
+                if (window_state_change) {
                     QWindowStateChangeEvent e(oldstate);
                     qt_sendSpontaneousEvent(widget, &e);
                 }
-            }
-
-            return rc;
+
+                break;
+            }
+
+            default:
+                break;
+            }
+        }
+
+    } while(0);
+
+    return WinDefWindowProc(hwnd, msg, mp1, mp2);
+}
+
+PFNWP QtOldFrameProc = 0;
+
+MRESULT EXPENTRY QtFrameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+{
+    do {
+        if (!qApp) // unstable app state
+            break;
+#if 0
+        // make sure we show widgets (e.g. scrollbars) when the user resizes
+        if (qApp->loopLevel())
+            qApp->sendPostedEvents(0, QEvent::ShowWindowRequest);
+#endif
+
+        HWND hwndC = WinWindowFromID(hwnd, FID_CLIENT);
+        QETWidget *widget = (QETWidget*)QWidget::find(hwndC);
+        if (!widget) // don't know this widget
+            break;
+
+        Q_ASSERT(widget->isWindow());
+
+        QMSG qmsg; // create QMSG structure
+        qmsg.hwnd = hwnd;
+        qmsg.msg = msg;
+        qmsg.mp1 = mp1;
+        qmsg.mp2 = mp2;
+
+#if defined(QT_DEBUGMSGFLOW)
+        {
+            QString str = qStrQMSG(qmsg);
+            if (!str.isEmpty())
+                qDebug() << "*** [F]" << str.toUtf8().constData();
+        }
+#endif
+
+        switch(msg) {
+
+        case WM_MOVE: { // move window
+            // note that we handle it nere instead of having CS_MOVENOTIFY
+            // on the client and handling in QtWndProc because we don't want
+            // client inside frame window move messages that would appear during
+            // minimize/maximize otherwise
+            if (widget->translateConfigEvent(qmsg))
+                return (MRESULT)TRUE;
+            break;
         }
 
@@ -1640,10 +1635,15 @@
     }
 
-    QRect cr = geometry();
     if (qmsg.msg == WM_SIZE) { // resize event
-        QSize oldSize = size();
-        QSize newSize(SHORT1FROMMP(qmsg.mp2), SHORT2FROMMP(qmsg.mp2));
-        cr.setSize(newSize);
-        data->crect = cr;
+        QSize oldSize = data->crect.size();
+        QSize newSize;
+        if (isWindow()) {
+            // the frame strut may have changed (e.g. after minimize)
+            d_func()->updateFrameStrut();
+            newSize = data->crect.size();
+        } else {
+            newSize = QSize(SHORT1FROMMP(qmsg.mp2), SHORT2FROMMP(qmsg.mp2));
+            data->crect.setSize(newSize);
+        }
         if (isWindow()) {                        // update title/icon text
             d_func()->createTLExtra();
@@ -1702,5 +1702,5 @@
         }
     } else if (qmsg.msg == WM_MOVE) { // move event
-        QPoint oldPos = geometry().topLeft();
+        QPoint oldPos = data->crect.topLeft();
         SWP swp;
         if (isWindow()) {
@@ -1718,6 +1718,5 @@
         QPoint newCPos(swp.x, swp.y);
         if (newCPos != oldPos) {
-            cr.moveTopLeft(newCPos);
-            data->crect = cr;
+            data->crect.moveTopLeft(newCPos);
             if (isVisible()) {
                 QMoveEvent e(newCPos, oldPos); // cpos (client position)
@@ -1778,4 +1777,17 @@
 }
 
+/*****************************************************************************
+  PM struct/message debug helpers
+ *****************************************************************************/
+
+typedef QLatin1String QCStr;
+
+#define myDefFlagEx(var,fl,varstr,flstr) if (var & fl) { \
+    if (!varstr.isEmpty()) varstr += QCStr("|"); varstr += QCStr(flstr); \
+} else do {} while(0)
+
+#define myDefFlag(var,fl,varstr) myDefFlagEx(var,fl,varstr,#fl)
+#define myDefFlagCut(var,fl,varstr,pos) myDefFlagEx(var,fl,varstr,#fl + pos)
+
 QDbgStr qStrHWND(HWND hwnd)
 {
@@ -1816,14 +1828,48 @@
     myCaseBegin(WM_SIZE)
         str += QString().
-            sprintf(" old (%hd,%ld) new (%hd,%hd)",
+            sprintf(" old (%hd,%hd) new (%hd,%hd)",
                     SHORT1FROMMP(qmsg.mp1), SHORT2FROMMP(qmsg.mp1),
                     SHORT1FROMMP(qmsg.mp2), SHORT2FROMMP(qmsg.mp2));
+        SWP swp;
+        WinQueryWindowPos(qmsg.hwnd, &swp);
+        str += QCStr(" ") + qStrSWP(swp);
+        HWND p = WinQueryWindow(qmsg.hwnd, QW_PARENT);
+        if (p != NULLHANDLE && p != WinQueryDesktopWindow(0, 0)) {
+            WinQueryWindowPos(p, &swp);
+            str += QCStr(" p ") + qStrSWP(swp);
+        }
         break;
     myCaseEnd()
 
     myCaseBegin(WM_MOVE)
+        SWP swp;
+        WinQueryWindowPos(qmsg.hwnd, &swp);
+        str += QCStr(" ") + qStrSWP(swp);
+        HWND p = WinQueryWindow(qmsg.hwnd, QW_PARENT);
+        if (p != NULLHANDLE && p != WinQueryDesktopWindow(0, 0)) {
+            WinQueryWindowPos(p, &swp);
+            str += QCStr(" p ") + qStrSWP(swp);
+        }
         break;
     myCaseEnd()
 
+    myCaseBegin(WM_WINDOWPOSCHANGED)
+        str += QCStr(" ") + qStrSWP(*((PSWP) qmsg.mp1));
+        ULONG awp = LONGFROMMP(qmsg.mp2);
+        QString awpstr;
+        myDefFlagEx(awp, AWP_MINIMIZED, awpstr, "MIN");
+        myDefFlagEx(awp, AWP_MAXIMIZED, awpstr, "MAX");
+        myDefFlagEx(awp, AWP_RESTORED, awpstr, "REST");
+        myDefFlagEx(awp, AWP_ACTIVATE, awpstr, "ACT");
+        myDefFlagEx(awp, AWP_DEACTIVATE, awpstr, "DEACT");
+        str += QCStr(" AWP(") + awpstr + QCStr(")");
+        break;
+    myCaseEnd()
+
+    myCaseBegin(WM_MINMAXFRAME)
+        str += QCStr(" ") + qStrSWP(*((PSWP) qmsg.mp1));
+        break;
+    myCaseEnd()
+
     default:
         break;
@@ -1842,3 +1888,26 @@
 }
 
+QDbgStr qStrSWP(const SWP &swp)
+{
+    QString fl;
+    myDefFlagEx(swp.fl, SWP_SHOW, fl, "SHOW");
+    myDefFlagEx(swp.fl, SWP_HIDE, fl, "HIDE");
+    myDefFlagEx(swp.fl, SWP_ACTIVATE, fl, "ACT");
+    myDefFlagEx(swp.fl, SWP_DEACTIVATE, fl, "DEACT");
+    myDefFlagEx(swp.fl, SWP_MAXIMIZE, fl, "MAX");
+    myDefFlagEx(swp.fl, SWP_MINIMIZE, fl, "MIN");
+    myDefFlagEx(swp.fl, SWP_RESTORE, fl, "REST");
+    myDefFlagEx(swp.fl, SWP_MOVE, fl, "MOVE");
+    myDefFlagEx(swp.fl, SWP_SIZE, fl, "SIZE");
+    myDefFlagEx(swp.fl, SWP_ZORDER, fl, "ZORD");
+
+    return QString().sprintf("SWP(%ld,%ld %ldx%ld %08lX ",
+                             swp.x, swp.y, swp.cx, swp.cy, swp.hwndInsertBehind) +
+        fl + QLatin1String(")");
+}
+
+#undef myDefFlagCut
+#undef myDefFlag
+#undef myDefFlagEx
+
 QT_END_NAMESPACE
Index: /trunk/src/gui/kernel/qwidget_p.h
===================================================================
--- /trunk/src/gui/kernel/qwidget_p.h	(revision 120)
+++ /trunk/src/gui/kernel/qwidget_p.h	(revision 121)
@@ -157,5 +157,4 @@
     HWND fId;
     HSWITCH swEntry;
-    uint inSetWindowState : 1;
 #endif
     QRect normalGeometry; // used by showMin/maximized/FullScreen
Index: /trunk/src/gui/kernel/qwidget_pm.cpp
===================================================================
--- /trunk/src/gui/kernel/qwidget_pm.cpp	(revision 120)
+++ /trunk/src/gui/kernel/qwidget_pm.cpp	(revision 121)
@@ -90,5 +90,4 @@
         // WC_FRAME parent HWND internally maintaned for them
         cname = QLatin1String("QWindow");
-        style |= CS_MOVENOTIFY;
     } else {
         cname = QLatin1String("QWidget");
@@ -1393,7 +1392,4 @@
         Q_ASSERT(fId != NULLHANDLE);
 
-        // set flag for the WM_WINDOWPOSCHANGED handler in QtFrameProc
-        d->topData()->inSetWindowState = true;
-
         // Ensure the initial size is valid, since we store it as normalGeometry below.
         if (!testAttribute(Qt::WA_Resized) && !isVisible())
@@ -1458,11 +1454,8 @@
             }
         }
-
-        // set flag for the WM_WINDOWPOSCHANGED handler in QtFrameProc
-        d->topData()->inSetWindowState = false;
-    }
+    }
+
     data->window_state = newstate;
-    QWindowStateChangeEvent e(oldstate);
-    QApplication::sendEvent(this, &e);
+    // Note: QWindowStateChangeEvent is sent from QtWndProc(WM_MINMAXFRAME)
 }
 
@@ -1940,5 +1933,4 @@
     extra->topextra->fId = NULLHANDLE;
     extra->topextra->swEntry = NULLHANDLE;
-    extra->topextra->inSetWindowState = false;
 }
 
@@ -1989,6 +1981,5 @@
     fs.setCoords(cswp.x, cswp.y, swp.cx - cswp.x - cswp.cx,
                                  swp.cy - cswp.y - cswp.cy);
-    // @todo do we really need to update crect here??
-    //data.crect.setRect(swp.x + cswp.x, swp.y + cswp.y, cswp.cx, cswp.cy);
+    data.crect.setRect(swp.x + cswp.x, swp.y + cswp.y, cswp.cx, cswp.cy);
 
     data.fstrut_dirty = false;
Index: /trunk/src/gui/kernel/qwindowdefs_pm.h
===================================================================
--- /trunk/src/gui/kernel/qwindowdefs_pm.h	(revision 120)
+++ /trunk/src/gui/kernel/qwindowdefs_pm.h	(revision 121)
@@ -103,4 +103,5 @@
 
 Q_CORE_EXPORT QDbgStr qStrRECTL(const RECTL &rcl);
+Q_CORE_EXPORT QDbgStr qStrSWP(const SWP &swp);
 
 #endif // defined(QT_OS2_H)
@@ -111,8 +112,15 @@
 // Prints a non-quoted QString
 inline QDebug operator<<(QDebug dbg, const QDbgStr &str)
-{ dbg << str.utf8().constData(); return dbg; }
+{ dbg << str.toUtf8().constData(); return dbg; }
+
+#if defined(QT_OS2_H)
 
 inline QDebug operator<<(QDebug dbg, const RECTL &rcl)
 { dbg << qStrRECTL(rcl); return dbg; }
+
+inline QDebug operator<<(QDebug dbg, const SWP &swp)
+{ dbg << qStrSWP(swp); return dbg; }
+
+#endif // defined(QT_OS2_H)
 
 #endif // defined(QDEBUG_H) && !defined(QT_NO_DEBUG_STREAM)
