Index: /trunk/src/gui/gui.pro
===================================================================
--- /trunk/src/gui/gui.pro	(revision 568)
+++ /trunk/src/gui/gui.pro	(revision 569)
@@ -5,5 +5,5 @@
 win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x65000000
 
-!win32:!embedded:!mac:!symbian:!os2::CONFIG      += x11
+!win32:!embedded:!mac:!symbian:!os2:CONFIG += x11
 
 unix:QMAKE_PKGCONFIG_REQUIRES = QtCore
Index: /trunk/src/gui/image/qpixmap_pm.cpp
===================================================================
--- /trunk/src/gui/image/qpixmap_pm.cpp	(revision 568)
+++ /trunk/src/gui/image/qpixmap_pm.cpp	(revision 569)
@@ -128,5 +128,5 @@
     }
 
-    QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data);
+    QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data());
     int w = d->image.width();
     int h = d->image.height();
Index: /trunk/src/gui/kernel/qapplication_pm.cpp
===================================================================
--- /trunk/src/gui/kernel/qapplication_pm.cpp	(revision 568)
+++ /trunk/src/gui/kernel/qapplication_pm.cpp	(revision 569)
@@ -2425,4 +2425,12 @@
 }
 
+void QApplicationPrivate::initializeMultitouch_sys()
+{
+}
+
+void QApplicationPrivate::cleanupMultitouch_sys()
+{
+}
+
 /*****************************************************************************
   PM session management
Index: /trunk/src/gui/kernel/qguiplatformplugin.cpp
===================================================================
--- /trunk/src/gui/kernel/qguiplatformplugin.cpp	(revision 568)
+++ /trunk/src/gui/kernel/qguiplatformplugin.cpp	(revision 569)
@@ -151,4 +151,6 @@
 #elif defined(Q_OS_SYMBIAN)
     return QLatin1String("Windows");                    // default style for Symbian without S60
+#elif defined(Q_OS_OS2)
+    return QLatin1String("Windows");                    // default style for OS/2
 #elif defined(Q_WS_X11) && defined(Q_OS_IRIX)
     return QLatin1String("SGI");                        // default style for X11 on IRIX
Index: /trunk/src/gui/kernel/qwidget.cpp
===================================================================
--- /trunk/src/gui/kernel/qwidget.cpp	(revision 568)
+++ /trunk/src/gui/kernel/qwidget.cpp	(revision 569)
@@ -7272,5 +7272,5 @@
     // hidden.
     if (wasVisible) {
-#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_PM) 
+#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_PM)
         qApp->d_func()->sendSyntheticEnterLeave(q);
 #endif
@@ -9011,6 +9011,6 @@
 Qt::InputMethodHints QWidget::inputMethodHints() const
 {
+#ifndef QT_NO_IM
     Q_D(const QWidget);
-#ifndef QT_NO_IM
     return d->imHints;
 #else //QT_NO_IM
@@ -10409,4 +10409,5 @@
         if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created))
             d->createWinId();
+#ifndef QT_NO_IM
         if (ic && isEnabled())
             ic->setFocusWidget(focusWidget);
Index: /trunk/src/gui/kernel/qwidget_p.h
===================================================================
--- /trunk/src/gui/kernel/qwidget_p.h	(revision 568)
+++ /trunk/src/gui/kernel/qwidget_p.h	(revision 569)
@@ -712,4 +712,5 @@
     HWND effectiveFrameWinId() const;
     void validateObstacles();
+    void reparentChildren();
 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
     uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
Index: /trunk/src/gui/kernel/qwidget_pm.cpp
===================================================================
--- /trunk/src/gui/kernel/qwidget_pm.cpp	(revision 568)
+++ /trunk/src/gui/kernel/qwidget_pm.cpp	(revision 569)
@@ -1376,5 +1376,5 @@
     Q_D(QWidget);
     if (!isWindow() && parentWidget())
-        parentWidget()->d_func()->invalidateBuffer(geometry());
+        parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
     d->deactivateWidgetCleanup();
     if (testAttribute(Qt::WA_WState_Created)) {
@@ -1412,5 +1412,9 @@
             qt_WinDestroyWindow(id);
         }
-        d->setWinId(0);
+        QT_TRY {
+            d->setWinId(0);
+        } QT_CATCH (const std::bad_alloc &) {
+            // swallow - destructors must not throw
+        }
     }
 }
@@ -1458,5 +1462,5 @@
     bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
     if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
-        q->parentWidget()->d_func()->invalidateBuffer(q->geometry());
+        q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
 
     WId old_fid = frameWinId();
@@ -1641,4 +1645,5 @@
 }
 
+#ifndef QT_NO_CURSOR
 void QWidget::grabMouse(const QCursor &cursor)
 {
@@ -1654,4 +1659,5 @@
     }
 }
+#endif
 
 void QWidget::releaseMouse()
@@ -1929,5 +1935,5 @@
  */
 
-void QWidgetPrivate::setWSGeometry(bool dontShow)
+void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &)
 {
     Q_Q(QWidget);
Index: /trunk/src/gui/painting/painting.pri
===================================================================
--- /trunk/src/gui/painting/painting.pri	(revision 568)
+++ /trunk/src/gui/painting/painting.pri	(revision 569)
@@ -110,6 +110,5 @@
         SOURCES += \
                 painting/qcolormap_pm.cpp \
-                painting/qpaintdevice_pm.cpp \
-                painting/qregion_pm.cpp
+                painting/qpaintdevice_pm.cpp
 }
 
Index: /trunk/src/gui/painting/qpaintdevice_pm.cpp
===================================================================
--- /trunk/src/gui/painting/qpaintdevice_pm.cpp	(revision 568)
+++ /trunk/src/gui/painting/qpaintdevice_pm.cpp	(revision 569)
@@ -50,24 +50,5 @@
 QT_BEGIN_NAMESPACE
 
-QPaintDevice::QPaintDevice()
-{
-    painters = 0;
-}
-
-extern void qt_painter_removePaintDevice(QPaintDevice *); //qpainter.cpp
-
-QPaintDevice::~QPaintDevice()
-{
-    if (paintingActive())
-        qWarning("QPaintDevice: Cannot destroy paint device that is being "
-                  "painted.  Be sure to QPainter::end() painters!");
-    qt_painter_removePaintDevice(this);
-}
-
-int QPaintDevice::metric(PaintDeviceMetric) const
-{
-    qWarning("QPaintDevice::metrics: Device has no metric information");
-    return 0;
-}
+// Nothing to be done here so far
 
 QT_END_NAMESPACE
Index: /trunk/src/gui/painting/qregion.cpp
===================================================================
--- /trunk/src/gui/painting/qregion.cpp	(revision 568)
+++ /trunk/src/gui/painting/qregion.cpp	(revision 569)
@@ -281,4 +281,11 @@
     }
 #endif
+#if defined(Q_WS_PM)
+    else {
+        // cause a new HRGN to be created when necessary
+        disposeHandle(d->rgn);
+        d->height = 0;
+    }
+#endif
 }
 
@@ -546,5 +553,5 @@
     \sa intersected()
 */
-#if !defined (Q_OS_UNIX) && !defined (Q_WS_WIN)
+#if !defined (Q_OS_UNIX) && !defined (Q_WS_WIN) && !defined (Q_WS_PM)
 QRegion& QRegion::operator+=(const QRect &r)
 {
@@ -569,5 +576,5 @@
    \since 4.4
  */
-#if defined (Q_OS_UNIX) || defined (Q_WS_WIN)
+#if defined (Q_OS_UNIX) || defined (Q_WS_WIN) || defined (Q_WS_PM)
 QRegion& QRegion::operator&=(const QRect &r)
 {
@@ -728,5 +735,5 @@
 }
 
-#if !defined (Q_OS_UNIX) && !defined (Q_WS_WIN)
+#if !defined (Q_OS_UNIX) && !defined (Q_WS_WIN) && !defined (Q_WS_PM)
 /*!
     \overload
@@ -1091,5 +1098,5 @@
 }
 
-#if defined(Q_OS_UNIX) || defined(Q_WS_WIN)
+#if defined(Q_OS_UNIX) || defined(Q_WS_WIN) || defined(Q_WS_PM)
 
 //#define QT_REGION_DEBUG
@@ -1635,4 +1642,8 @@
 QT_BEGIN_INCLUDE_NAMESPACE
 # include "qregion_win.cpp"
+QT_END_INCLUDE_NAMESPACE
+#elif defined(Q_WS_PM)
+QT_BEGIN_INCLUDE_NAMESPACE
+# include "qregion_pm.cpp"
 QT_END_INCLUDE_NAMESPACE
 #elif defined(Q_WS_QWS)
@@ -3853,4 +3864,7 @@
 #elif defined(Q_WS_WIN)
         d->rgn = 0;
+#elif defined(Q_WS_PM)
+        d->rgn = 0;
+        d->height = 0;
 #endif
         if (t == Rectangle) {
@@ -3878,4 +3892,7 @@
 #elif defined(Q_WS_WIN)
             d->rgn = 0;
+#elif defined(Q_WS_PM)
+            d->rgn = 0;
+            d->height = 0;
 #endif
             d->qt_rgn = qt_rgn;
@@ -3910,4 +3927,7 @@
 #elif defined(Q_WS_WIN)
         d->rgn = 0;
+#elif defined(Q_WS_PM)
+        d->rgn = 0;
+        d->height = 0;
 #endif
         d->qt_rgn = qt_bitmapToRegion(bm);
@@ -3926,4 +3946,7 @@
     if (x->rgn)
         qt_win_dispose_rgn(x->rgn);
+#elif defined(Q_WS_PM)
+    if (x->rgn)
+        disposeHandle(x->rgn);
 #endif
     delete x;
@@ -3960,4 +3983,7 @@
 #elif defined(Q_WS_WIN)
     x->rgn = 0;
+#elif defined(Q_WS_PM)
+    x->rgn = 0;
+    x->height = 0;
 #endif
     if (d->qt_rgn)
Index: /trunk/src/gui/painting/qregion.h
===================================================================
--- /trunk/src/gui/painting/qregion.h	(revision 568)
+++ /trunk/src/gui/painting/qregion.h	(revision 569)
@@ -60,5 +60,5 @@
 class QVariant;
 
-#if defined(Q_WS_QWS) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
+#if defined(Q_WS_QWS) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) || defined(Q_WS_PM)
 struct QRegionPrivate;
 #endif
@@ -184,8 +184,7 @@
 #if defined(Q_WS_WIN)
     void ensureHandle() const;
-    QRegion winCombine(const QRegion &r, int num) const;
 #elif defined(Q_WS_PM)
-    QRegion pmCombine(const QRegion &r, int op) const;
     void updateHandle(int targetHeight) const;
+    static void disposeHandle(HRGN hrgn);
 #elif defined(Q_WS_X11)
     void updateX11Region() const;
@@ -216,5 +215,5 @@
         mutable RgnHandle unused; // Here for binary compatability reasons. ### Qt 5 remove.
 #endif
-#if defined(Q_WS_QWS) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
+#if defined(Q_WS_QWS) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) || defined(Q_WS_PM)
         QRegionPrivate *qt_rgn;
 #endif
Index: /trunk/src/gui/painting/qregion_pm.cpp
===================================================================
--- /trunk/src/gui/painting/qregion_pm.cpp	(revision 568)
+++ /trunk/src/gui/painting/qregion_pm.cpp	(revision 569)
@@ -68,484 +68,18 @@
 //  The handle() function, used for external access to the region, takes an
 //  argument that must be always set to the height of the target device to
-//  guarantee the correct coordinate space alignment.
-
-#if defined(__GNUC__) && defined(__INNOTEK_LIBC__)
-
-// Innotek GCC lacks some API functions in its version of OS/2 Toolkit headers
-
-extern "C" HRGN APIENTRY GpiCreateEllipticRegion(HPS hps,
-                                                 PRECTL prclRect);
-
-extern "C" HRGN APIENTRY GpiCreatePolygonRegion(HPS hps,
-                                                ULONG ulCount,
-                                                PPOLYGON paplgn,
-                                                ULONG flOptions);
-#endif
+//  guarantee the correct y axis alignment.
 
 QRegion::QRegionData QRegion::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1),
                                                NULLHANDLE, 0 };
 
-QRegion::QRegion()
-    : d(&shared_empty)
+/*!
+    \internal
+
+    Deletes the given region handle.
+ */
+void QRegion::disposeHandle(HRGN hrgn)
 {
-    d->ref.ref();
-}
-
-QRegion::QRegion(const QRect &r, RegionType t)
-{
-    if (r.isEmpty()) {
-        d = &shared_empty;
-        d->ref.ref();
-    } else {
-        d = new QRegionData;
-        d->ref = 1;
-        d->height = 0;
-        HPS hps = qt_display_ps();
-        if (t == Rectangle) {
-            RECTL rcl = { r.left(), -(r.bottom()+1), r.right()+1, -r.top() };
-            d->rgn = GpiCreateRegion(hps, 1, &rcl);
-        } else if (t == Ellipse) {
-            // if the width or height of the ellipse is odd, GPI always
-            // converts it to a nearest even value, which is obviously stupid
-            // So, we don't use GpiCreateEllipticRegion(), but create an array
-            // of points to call GpiCreatePolygonRegion() instead.
-            QPainterPath p(QPointF(r.x(), r.y()));
-            p.arcTo(r.x(), r.y(), r.width(), r.height(), 0, 360);
-            QPolygon a = p.toFillPolygon().toPolygon();
-            for (int i = 0; i < a.size(); ++ i)
-                a[i].ry() = -(a[i].y() + 1);
-            // GpiCreatePolygonRegion() is bogus and always starts a poligon from
-            // the current position. Make the last point the current one and reduce
-            // the number of points by one.
-            GpiMove(hps, reinterpret_cast<PPOINTL>(&a[a.size() - 1]));
-            POLYGON poly = { a.size() - 1, reinterpret_cast<PPOINTL>(a.data()) };
-            d->rgn = GpiCreatePolygonRegion(hps, 1, &poly, POLYGON_ALTERNATE);
-        }
-    }
-}
-
-QRegion::QRegion(const QPolygon &a, Qt::FillRule fillRule)
-{
-    if (a.size() < 3) {
-        d = &shared_empty;
-        d->ref.ref();
-    } else {
-        d = new QRegionData;
-        d->ref = 1;
-        d->height = 0;
-        HPS hps = qt_display_ps();
-        POINTL *pts = new POINTL[a.size()];
-        for (int i = 0; i < a.size(); ++ i) {
-            pts[i].x = a[i].x();
-            pts[i].y = - (a[i].y() + 1);
-        }
-        // GpiCreatePolygonRegion() is bogus and always starts a poligon from
-        // the current position. Make the last point the current one and reduce
-        // the number of points by one.
-        GpiMove(hps, &pts[a.size() - 1]);
-        POLYGON poly = { a.size() - 1, pts };
-        ULONG opts = Qt::OddEvenFill ? POLYGON_ALTERNATE : POLYGON_WINDING;
-        d->rgn = GpiCreatePolygonRegion(hps, 1, &poly, opts);
-        delete[] pts;
-    }
-}
-
-QRegion::QRegion(const QRegion &r)
-{
-    d = r.d;
-    d->ref.ref();
-}
-
-static HRGN bitmapToRegion(const QBitmap& bitmap)
-{
-    HRGN region = 0;
-    QImage image = bitmap.toImage();
-    const int maxrect = 256;
-    RECTL rects[maxrect];
-    HPS hps = qt_display_ps();
-
-#define FlushSpans \
-    { \
-        HRGN r = GpiCreateRegion(hps, n, rects); \
-	    if (region) { \
-	        GpiCombineRegion(hps, region, region, r, CRGN_OR); \
-	        GpiDestroyRegion(hps, r); \
-    	} else { \
-    	    region = r; \
-    	} \
-    }
-
-#define AddSpan \
-    { \
-        rects[n].xLeft = prev1; \
-        rects[n].yBottom = -(y+1); \
-        rects[n].xRight = x-1+1; \
-        rects[n].yTop = -y; \
-        n++; \
-        if (n == maxrect) { \
-            FlushSpans \
-            n = 0; \
-        } \
-    }
-
-    int n = 0;
-    int zero = 0x00;
-
-    int x, y;
-    for (y = 0; y < image.height(); y++) {
-    	uchar *line = image.scanLine(y);
-    	int w = image.width();
-    	uchar all = zero;
-    	int prev1 = -1;
-    	for (x = 0; x < w;) {
-    	    uchar byte = line[x/8];
-    	    if (x > w-8 || byte != all) {
-    		for (int b = 8; b > 0 && x < w; b--) {
-    		    if (!(byte & 0x80) == !all) {
-                    // More of the same
-    		    } else {
-        			// A change.
-        			if (all != zero) {
-        			    AddSpan;
-        			    all = zero;
-        			} else {
-        			    prev1 = x;
-        			    all = ~zero;
-        			}
-    		    }
-    		    byte <<= 1;
-    		    x++;
-    		}
-    	    } else {
-                x += 8;
-    	    }
-    	}
-    	if (all != zero) {
-    	    AddSpan;
-    	}
-    }
-    if (n) {
-        FlushSpans;
-    }
-
-    if (!region)
-        region = GpiCreateRegion(hps, 0, NULL);
-
-    return region;
-}
-
-QRegion::QRegion(const QBitmap &bm)
-{
-    if (bm.isNull()) {
-        d = &shared_empty;
-        d->ref.ref();
-    } else {
-        d = new QRegionData;
-        d->ref = 1;
-        d->height = 0;
-        d->rgn = bitmapToRegion(bm);
-    }
-}
-
-void QRegion::cleanUp(QRegion::QRegionData *x)
-{
-    if (x->rgn != NULLHANDLE)
-        GpiDestroyRegion(qt_display_ps(), x->rgn);
-    delete x;
-}
-
-QRegion::~QRegion()
-{
-    if (!d->ref.deref())
-        cleanUp(d);
-}
-
-QRegion &QRegion::operator=(const QRegion &r)
-{
-    r.d->ref.ref();
-    if (!d->ref.deref())
-        cleanUp(d);
-    d = r.d;
-    return *this;
-}
-
-
-QRegion QRegion::copy() const
-{
-    QRegion r;
-    QRegionData *x = new QRegionData;
-    x->ref = 1;
-    if (d->rgn != NULLHANDLE) {
-        x->height = d->height;
-        HPS hps = qt_display_ps();
-        x->rgn = GpiCreateRegion(hps, 0, NULL);
-        GpiCombineRegion(hps, x->rgn, d->rgn, NULL, CRGN_COPY);
-    } else {
-        x->height = 0;
-        x->rgn = NULLHANDLE;
-    }
-    if (!r.d->ref.deref())
-        cleanUp(r.d);
-    r.d = x;
-    return r;
-}
-
-bool QRegion::isEmpty() const
-{
-    return (d == &shared_empty || boundingRect().isEmpty());
-}
-
-bool QRegion::contains(const QPoint &p) const
-{
-    LONG rc = PRGN_OUTSIDE;
-    if (d->rgn != NULLHANDLE) {
-        POINTL ptl = { p.x(), d->height - (p.y() + 1) };
-        rc = GpiPtInRegion(qt_display_ps(), d->rgn, &ptl);
-    }
-    return rc == PRGN_INSIDE;
-}
-
-bool QRegion::contains(const QRect &r) const
-{
-    LONG rc = PRGN_OUTSIDE;
-    if (d->rgn != NULLHANDLE) {
-        RECTL rcl = { r.left(), d->height - (r.bottom() + 1),
-                      r.right() + 1, d->height - r.top() };
-        rc = GpiRectInRegion(qt_display_ps(), d->rgn, &rcl);
-    }
-    return rc == RRGN_INSIDE || rc == RRGN_PARTIAL;
-}
-
-void QRegion::translate(int dx, int dy)
-{
-    if (d->rgn == NULLHANDLE || (dx == 0 && dy == 0))
-        return;
-    detach();
-    POINTL ptl = { dx, -dy };
-    GpiOffsetRegion(qt_display_ps(), d->rgn, &ptl);
-}
-
-#define CRGN_NOP -1
-
-// Duplicates of those in qregion.cpp
-#define QRGN_OR               6
-#define QRGN_AND              7
-#define QRGN_SUB              8
-#define QRGN_XOR              9
-
-/*
-  Performs the actual OR, AND, SUB and XOR operation between regions.
-  Sets the resulting region handle to 0 to indicate an empty region.
-*/
-
-QRegion QRegion::pmCombine(const QRegion &r, int op) const
-{
-    LONG both = CRGN_NOP, left = CRGN_NOP, right = CRGN_NOP;
-    switch (op) {
-    case QRGN_OR:
-        both = CRGN_OR;
-        left = right = CRGN_COPY;
-        break;
-    case QRGN_AND:
-        both = CRGN_AND;
-        break;
-    case QRGN_SUB:
-        both = CRGN_DIFF;
-        left = CRGN_COPY;
-        break;
-    case QRGN_XOR:
-        both = CRGN_XOR;
-        left = right = CRGN_COPY;
-        break;
-    default:
-        qWarning( "QRegion: Internal error in pmCombine" );
-    }
-
-    QRegion result;
-    if (d->rgn == NULLHANDLE && r.d->rgn == NULLHANDLE)
-        return result;
-    HPS hps = qt_display_ps();
-    result.detach();
-    result.d->rgn = GpiCreateRegion(hps, 0, NULL);
-    LONG rc = RGN_NULL;
-    if (d->rgn != NULLHANDLE && r.d->rgn != NULLHANDLE) {
-        updateHandle(r.d->height); // bring to the same coordinate space
-        rc = GpiCombineRegion(hps, result.d->rgn, d->rgn, r.d->rgn, both);
-        result.d->height = r.d->height;
-    } else if (d->rgn && left != CRGN_NOP) {
-        rc = GpiCombineRegion(hps, result.d->rgn, d->rgn, 0, left);
-        result.d->height = d->height;
-    } else if (r.d->rgn != NULLHANDLE && right != CRGN_NOP) {
-        rc = GpiCombineRegion(hps, result.d->rgn, r.d->rgn, 0, right);
-        result.d->height = r.d->height;
-    }
-    if (rc == RGN_NULL || rc == RGN_ERROR) {
-        result = QRegion(); // shared_empty
-    }
-    return result;
-}
-
-QRegion QRegion::unite(const QRegion &r) const
-{
-    if (d->rgn == NULLHANDLE)
-        return r;
-    if (r.d->rgn == NULLHANDLE)
-        return *this;
-    return pmCombine(r, QRGN_OR);
-}
-
-QRegion QRegion::unite(const QRect &r) const
-{
-    return unite(QRegion(r));
-}
-
-QRegion QRegion::intersect(const QRegion &r) const
-{
-    if (r.d->rgn == NULLHANDLE || d->rgn == NULLHANDLE)
-        return QRegion();
-     return pmCombine(r, QRGN_AND);
-}
-
-QRegion QRegion::subtract(const QRegion &r) const
-{
-    if (r.d->rgn == NULLHANDLE || d->rgn == NULLHANDLE)
-        return *this;
-    return pmCombine(r, QRGN_SUB);
-}
-
-QRegion QRegion::eor(const QRegion &r) const
-{
-    if (d->rgn == NULLHANDLE)
-        return r;
-    if (r.d->rgn == NULLHANDLE)
-        return *this;
-    return pmCombine(r, QRGN_XOR);
-}
-
-QRect QRegion::boundingRect() const
-{
-    if (!d->rgn)
-        return QRect();
-
-    RECTL rcl;
-    LONG rc = RGN_NULL;
-    if (d->rgn != NULLHANDLE)
-        rc = GpiQueryRegionBox(qt_display_ps(), d->rgn, &rcl);
-    if (rc == RGN_NULL || rc == RGN_ERROR)
-        return QRect();
-    else
-        return QRect(rcl.xLeft, d->height - rcl.yTop,
-                     rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom);
-}
-
-QVector<QRect> QRegion::rects() const
-{
-    QVector<QRect> a;
-
-    if (d->rgn == NULLHANDLE)
-        return a;
-
-    HPS hps = qt_display_ps();
-    RGNRECT ctl = {1, 0, 0, RECTDIR_LFRT_TOPBOT};
-    if (!GpiQueryRegionRects(hps, d->rgn, NULL, &ctl, NULL))
-        return a;
-
-    ctl.crc = ctl.crcReturned;
-    PRECTL rcls = new RECTL[ctl.crcReturned];
-    if (rcls == 0)
-        return a;
-    if (!GpiQueryRegionRects(hps, d->rgn, NULL, &ctl, rcls)) {
-        delete [] rcls;
-        return a;
-    }
-
-    a = QVector<QRect>(ctl.crcReturned);
-    PRECTL r = rcls;
-    for (int i = 0; i < a.size(); ++i) {
-        a[i].setRect(r->xLeft, d->height - r->yTop,
-                     r->xRight - r->xLeft, r->yTop - r->yBottom);
-        ++r;
-    }
-
-    delete [] rcls;
-    return a;
- }
-
-void QRegion::setRects(const QRect *rects, int num)
-{
-    *this = QRegion();
-    if (!rects || num == 0 || (num == 1 && rects->isEmpty()))
-        return;
-    for (int i = 0; i < num; ++i)
-        *this |= rects[i];
-}
-
-int QRegion::numRects() const
-{
-    if (d->rgn == NULLHANDLE)
-        return 0;
-
-    RGNRECT ctl = {1, 0, 0, RECTDIR_LFRT_TOPBOT};
-    if (!GpiQueryRegionRects(qt_display_ps(), d->rgn, NULL, &ctl, NULL))
-        return 0;
-
-    return ctl.crcReturned;
-}
-
-bool QRegion::operator==(const QRegion &r) const
-{
-    if (d == r.d)
-        return true;
-    if ((d->rgn == NULLHANDLE) ^ (r.d->rgn == NULLHANDLE)) // one is empty, not both
-        return false;
-    if (d->rgn == NULLHANDLE) // both empty
-        return true;
-    updateHandle(r.d->height); // bring to the same coordinate space
-    return // both not empty
-        GpiEqualRegion(qt_display_ps(), d->rgn, r.d->rgn) == EQRGN_EQUAL;
-}
-
-QRegion& QRegion::operator+=(const QRegion &r)
-{
-    if (r.d->rgn == NULLHANDLE)
-        return *this;
-
-    if (d->rgn == NULLHANDLE) {
-        *this = r;
-        return *this;
-    }
-
-    *this = unite(r);
-    return *this;
-}
-
-QRegion& QRegion::operator-=(const QRegion &r)
-{
-    if (r.d->rgn == NULLHANDLE || d->rgn == NULLHANDLE)
-        return *this;
-
-    *this = subtract(r);
-    return *this;
-}
-
-QRegion& QRegion::operator&=(const QRegion &r)
-{
-    if (d->rgn == NULLHANDLE)
-        return *this;
-
-    if (r.d->rgn == NULLHANDLE) {
-        *this = QRegion();
-        return *this;
-    }
-
-    *this = intersect(r);
-    return *this;
-}
-
-bool qt_region_strictContains(const QRegion &region, const QRect &rect)
-{
-    Q_UNUSED(region);
-    Q_UNUSED(rect);
-    return false;
+    if (hrgn != 0)
+        GpiDestroyRegion(qt_display_ps(), hrgn);
 }
 
@@ -558,17 +92,41 @@
 void QRegion::updateHandle(int targetHeight) const
 {
-    QRegion *that = const_cast<QRegion*>(this); // we're const here
-    if (d->rgn == NULLHANDLE) {
-        // a handle of a null region is requested, allocate an empty region
-        that->detach();
-        that->d->rgn = GpiCreateRegion(qt_display_ps(), 0, NULL);
-        that->d->height = targetHeight;
-    } else if (d->height != targetHeight) {
-        // align region y axis to the top of the device
-        that->detach();
-        POINTL ptl = { 0, targetHeight - d->height };
-        GpiOffsetRegion(qt_display_ps(), d->rgn, &ptl);
-        that->d->height = targetHeight;
+    QRegion *self = const_cast<QRegion*>(this); // we're const here
+
+    if (d->rgn != 0) {
+        if (self->d->ref == 1) {
+            // align region y axis to the top of the device
+            POINTL ptl = { 0, targetHeight - d->height };
+            GpiOffsetRegion(qt_display_ps(), d->rgn, &ptl);
+            self->d->height = targetHeight;
+            return;
+        }
+        // create a copy since the hande may be in use (this will reset d->rgn)
+        *self = copy();
     }
+
+    Q_ASSERT(d->rgn == 0);
+
+    // new/updated/copied Qt region data, create a new HRGN for it
+    self->d->height = targetHeight;
+    if (d->qt_rgn) {
+        if (d->qt_rgn->numRects) {
+            PRECTL rcls = new RECTL[d->qt_rgn->numRects];
+            for (int i = 0; i < d->qt_rgn->numRects; ++i) {
+                QRect r = d->qt_rgn->rects.at(i);
+                // note RECTL is inclusive-exclusive here
+                rcls[i].xLeft = r.left();
+                rcls[i].yBottom = d->height - (r.bottom() + 1);
+                rcls[i].xRight = r.right() + 1;
+                rcls[i].yTop = d->height - r.top();
+            }
+            self->d->rgn = GpiCreateRegion(qt_display_ps(),
+                                           d->qt_rgn->numRects, rcls);
+            return;
+        }
+    }
+
+    // create an empty region
+    self->d->rgn = GpiCreateRegion(qt_display_ps(), 0, NULL);
 }
 
Index: /trunk/src/gui/text/text.pri
===================================================================
--- /trunk/src/gui/text/text.pri	(revision 568)
+++ /trunk/src/gui/text/text.pri	(revision 569)
@@ -187,7 +187,7 @@
         DEFINES += FT_CONFIG_OPTION_SYSTEM_ZLIB
     } os2 {
-        SOURCES +=
+        SOURCES += \
             ../3rdparty/freetype/src/base/ftsystem.c
-        INCLUDEPATH +=
+        INCLUDEPATH += \
             ../3rdparty/freetype/builds/os2
     } else {
@@ -204,5 +204,5 @@
 
     DEFINES += FT2_BUILD_LIBRARY
-    
+
     embedded:CONFIG += opentype
 } else:contains(QT_CONFIG, system-freetype) {
