Index: /trunk/src/gui/image/qnativeimage.cpp
===================================================================
--- /trunk/src/gui/image/qnativeimage.cpp	(revision 114)
+++ /trunk/src/gui/image/qnativeimage.cpp	(revision 115)
@@ -141,4 +141,23 @@
 }
 
+#elif defined(Q_WS_PM)
+
+QNativeImage::QNativeImage(int width, int height, QImage::Format format,
+                           bool isTextBuffer, QWidget *widget)
+{
+    image = QImage(width, height, format);
+}
+
+QNativeImage::~QNativeImage()
+{
+}
+
+QImage::Format QNativeImage::systemFormat()
+{
+    // @todo support 8-bit indexed colors?
+//  if (QColormap::instance().depth() == 16)
+//      return QImage::Format_RGB16;
+    return QImage::Format_RGB32;
+}
 
 #elif defined(Q_WS_X11) && !defined(QT_NO_MITSHM)
Index: /trunk/src/gui/image/qnativeimage_p.h
===================================================================
--- /trunk/src/gui/image/qnativeimage_p.h	(revision 114)
+++ /trunk/src/gui/image/qnativeimage_p.h	(revision 115)
@@ -56,5 +56,5 @@
 #include "qimage.h"
 
-#ifdef Q_WS_WIN
+#if defined(Q_WS_WIN)
 #include "qt_windows.h"
 
@@ -84,5 +84,5 @@
     static QImage::Format systemFormat();
 
-#ifdef Q_WS_WIN
+#if defined(Q_WS_WIN)
     HDC hdc;
     HBITMAP bitmap;
Index: /trunk/src/gui/kernel/qwidget.cpp
===================================================================
--- /trunk/src/gui/kernel/qwidget.cpp	(revision 114)
+++ /trunk/src/gui/kernel/qwidget.cpp	(revision 115)
@@ -10359,4 +10359,35 @@
         qErrnoWarning("QWidget::releaseDC(): failed to release HDC");
 }
+#elif defined (Q_WS_PM)
+/*!
+    Returns the window system handle of the widget, for low-level
+    access. Using this function is not portable.
+
+    An HPS acquired with getPS() has to be released with releasePS().
+
+    \warning Using this function is not portable.
+*/
+HPS QWidget::getPS() const
+{
+    Q_D(const QWidget);
+    if (d->hd != NULLHANDLE)
+        return (HPS) d->hd;
+    return WinGetPS(winId());
+}
+
+/*!
+    Releases the HPS \a hdc acquired by a previous call to getPS().
+
+    \warning Using this function is not portable.
+*/
+void QWidget::releasePS(HPS hps) const
+{
+    Q_D(const QWidget);
+    // If there is a widget's own ps, the release operation is ignored because
+    // it will be released elsewhere. Otherwise, we assume that the given hps
+    // was acquired by WinGetPS in the getPS() call and release it.
+    if (d->hd == NULLHANDLE)
+        WinReleasePS(hps);
+}
 #else
 /*!
Index: /trunk/src/gui/kernel/qwidget.h
===================================================================
--- /trunk/src/gui/kernel/qwidget.h	(revision 114)
+++ /trunk/src/gui/kernel/qwidget.h	(revision 115)
@@ -583,4 +583,7 @@
     HDC getDC() const;
     void releaseDC(HDC) const;
+#elif defined(Q_WS_PM)
+    HPS getPS() const;
+    void releasePS(HPS) const;
 #else
     Qt::HANDLE handle() const;
Index: /trunk/src/gui/painting/qwindowsurface_raster.cpp
===================================================================
--- /trunk/src/gui/painting/qwindowsurface_raster.cpp	(revision 114)
+++ /trunk/src/gui/painting/qwindowsurface_raster.cpp	(revision 115)
@@ -199,4 +199,52 @@
 #endif
 
+#endif
+
+#ifdef Q_WS_PM
+    QRect br = rgn.boundingRect();
+#if 1
+    qDebug("QRasterWindowSurface::flush: [%s] br=%d,%d/%d,%d",
+           QWidgetPrivate::name(widget).constData(),
+           br.x(), br.y(), br.width(), br.height());
+#endif
+
+    HPS wps = widget->getPS();
+
+    // use the reflection + transformation matrix to flip the y axis
+    // @todo check if it's really slower than flipping the image bits instead
+    // @todo I guess we can use DIVE here; check it too
+    MATRIXLF m;
+    m.fxM11 = MAKEFIXED(1, 0);
+    m.fxM12 = 0;
+    m.lM13 = 0;
+    m.fxM21 = 0;
+    m.fxM22 = MAKEFIXED(-1, 0);
+    m.lM23 = 0;
+    m.lM31 = 0;
+    m.lM32 = widget->height() - 1;
+    GpiSetDefaultViewMatrix(wps, 8, &m, TRANSFORM_REPLACE);
+
+    QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();
+    QRect wbr = br.translated(-wOffset);
+
+    br.translate(offset);
+
+    BITMAPINFOHEADER2 bmh;
+    memset(&bmh, 0, sizeof(BITMAPINFOHEADER2));
+    bmh.cbFix = sizeof(BITMAPINFOHEADER2);
+    bmh.cPlanes = 1;
+    bmh.cBitCount = 32; // @todo support 8-bit indexed colors?
+    bmh.cx = d->image->width();
+    bmh.cy = d->image->height();
+
+    // Note: target is inclusive-inclusive, source is inclusive-exclusive
+    POINTL ptls[] = { { wbr.left(), wbr.top() },
+                      { wbr.right(), wbr.bottom() },
+                      { br.left(), br.top() },
+                      { br.right() + 1, br.bottom() + 1 } };
+    GpiDrawBits(wps, (PVOID) d->image->image.bits(), (PBITMAPINFO2) &bmh, 4, ptls,
+                ROP_SRCCOPY, BBO_IGNORE);
+
+    widget->releasePS(wps);
 #endif
 
