Index: /trunk/src/gui/gui.pro
===================================================================
--- /trunk/src/gui/gui.pro	(revision 91)
+++ /trunk/src/gui/gui.pro	(revision 92)
@@ -20,16 +20,21 @@
 
 #modules
-include(kernel/kernel.pri)
-include(image/image.pri)
-include(painting/painting.pri)
-include(text/text.pri)
-include(styles/styles.pri)
-include(widgets/widgets.pri)
-include(dialogs/dialogs.pri)
-include(accessible/accessible.pri)
-include(itemviews/itemviews.pri)
-include(inputmethod/inputmethod.pri)
-include(graphicsview/graphicsview.pri)
-include(util/util.pri)
+# @todo on OS/2, temporarily disable some modules until implemented
+os2 {
+    include(kernel/kernel.pri)
+} else {
+    include(kernel/kernel.pri)
+    include(image/image.pri)
+    include(painting/painting.pri)
+    include(text/text.pri)
+    include(styles/styles.pri)
+    include(widgets/widgets.pri)
+    include(dialogs/dialogs.pri)
+    include(accessible/accessible.pri)
+    include(itemviews/itemviews.pri)
+    include(inputmethod/inputmethod.pri)
+    include(graphicsview/graphicsview.pri)
+    include(util/util.pri)
+}
 
 embedded: QT += network
Index: /trunk/src/gui/kernel/kernel.pri
===================================================================
--- /trunk/src/gui/kernel/kernel.pri	(revision 91)
+++ /trunk/src/gui/kernel/kernel.pri	(revision 92)
@@ -91,4 +91,20 @@
 }
 
+os2 {
+	# @todo override everything since most things are not ready...
+	HEADERS = \
+		kernel/qapplication.h \
+		kernel/qapplication_p.h \
+		kernel/qwidget.h \
+		kernel/qwidget_p.h
+	SOURCES = \
+		kernel/qapplication.cpp \
+		kernel/qwidget.cpp
+
+	SOURCES += \
+		kernel/qapplication_pm.cpp \
+		kernel/qwidget_pm.cpp
+}
+
 unix:x11 {
 	INCLUDEPATH += ../3rdparty/xorg
@@ -190,8 +206,8 @@
                 kernel/qeventdispatcher_mac_p.h
 
-        MENU_NIB.files = mac/qt_menu.nib 
-        MENU_NIB.path = Resources 
+        MENU_NIB.files = mac/qt_menu.nib
+        MENU_NIB.path = Resources
         MENU_NIB.version = Versions
-        QMAKE_BUNDLE_DATA += MENU_NIB 
+        QMAKE_BUNDLE_DATA += MENU_NIB
         RESOURCES += mac/maccursors.qrc
 
Index: /trunk/src/gui/kernel/qapplication.cpp
===================================================================
--- /trunk/src/gui/kernel/qapplication.cpp	(revision 91)
+++ /trunk/src/gui/kernel/qapplication.cpp	(revision 92)
@@ -2579,5 +2579,5 @@
         w = leaveList.at(i);
         if (!qApp->activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
+#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
             if (leaveAfterRelease == w)
                 leaveAfterRelease = 0;
@@ -2952,5 +2952,5 @@
 }
 
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
+#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
 /*
     This function should only be called when the widget changes visibility, i.e.
@@ -3008,5 +3008,5 @@
 #endif // QT_NO_CURSOR
 }
-#endif // Q_WS_WIN || Q_WS_X11
+#endif // Q_WS_WIN || Q_WS_PM || Q_WS_X11
 
 /*!
@@ -3498,5 +3498,5 @@
     event loop receives events from the window system and dispatches these to
     the application widgets.
- 
+
     Generally, no user interaction can take place before calling exec(). As a
     special case, modal widgets like QMessageBox can be used before calling
Index: /trunk/src/gui/kernel/qapplication_p.h
===================================================================
--- /trunk/src/gui/kernel/qapplication_p.h	(revision 91)
+++ /trunk/src/gui/kernel/qapplication_p.h	(revision 92)
@@ -421,5 +421,5 @@
     static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
                                QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver);
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
+#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
     void sendSyntheticEnterLeave(QWidget *widget);
 #endif
Index: /trunk/src/gui/kernel/qapplication_pm.cpp
===================================================================
--- /trunk/src/gui/kernel/qapplication_pm.cpp	(revision 92)
+++ /trunk/src/gui/kernel/qapplication_pm.cpp	(revision 92)
@@ -0,0 +1,335 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** Copyright (C) 2009 netlabs.org. OS/2 parts.
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qt_os2.h"
+
+#include "qapplication.h"
+#include "qapplication_p.h"
+
+#include "qwidget.h"
+#include "qpointer.h"
+#include "qcolormap.h"
+#include "qpixmapcache.h"
+
+#include "qset.h"
+
+#include "qwidget_p.h"
+#include "qkeymapper_p.h"
+#include "qcursor_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*****************************************************************************
+  Internal variables and functions
+ *****************************************************************************/
+
+static HWND	 curWin		= 0;		// current window
+static HPS	 displayPS	= 0;		// display presentation space
+
+static bool replayPopupMouseEvent = false; // replay handling when popups close
+
+// ignore the next release event if return from a modal widget
+static bool ignoreNextMouseReleaseEvent = false;
+
+#if defined(QT_DEBUG)
+static bool appNoGrab = false; // mouse/keyboard grabbing
+#endif
+
+static bool app_do_modal = false; // modal mode
+extern QWidgetList *qt_modal_stack;
+extern QDesktopWidget *qt_desktopWidget;
+static QPointer<QWidget> popupButtonFocus;
+static bool	qt_try_modal(QWidget *, QMSG *, int& ret);
+
+static QWidget *qt_button_down = 0; // widget got last button-down
+
+static HWND autoCaptureWnd = NULLHANDLE;
+static void setAutoCapture(HWND); // automatic capture
+static void releaseAutoCapture();
+
+static void unregWinClasses();
+
+extern QCursor *qt_grab_cursor();
+
+extern "C" MRESULT EXPENTRY QtWndProc(HWND, ULONG, MPARAM, MPARAM);
+
+class QETWidget : public QWidget                // event translator widget
+{
+public:
+    QWExtra    *xtra() { return d_func()->extraData(); }
+    QTLWExtra  *topData() { return d_func()->topData(); }
+// @todo later
+//  QTLWExtra  *maybeTopData() { return d_func()->maybeTopData(); }
+//  void syncBackingStore(const QRegion &rgn) { d_func()->syncBackingStore(rgn); }
+//  void syncBackingStore() { d_func()->syncBackingStore(); }
+//  QWidgetData *dataPtr() { return data; }
+//  QWidgetPrivate *dptr() { return d_func(); }
+//  QRect frameStrut() const { return d_func()->frameStrut(); }
+//  bool        winEvent(QMSG *m, long *r) { return QWidget::winEvent(m, r); }
+//  void        markFrameStrutDirty() { data->fstrut_dirty = 1; }
+//  bool        translateMouseEvent(const MSG &msg);
+//  bool        translateWheelEvent(const MSG &msg);
+//  bool        translatePaintEvent(const MSG &msg);
+//  bool        translateConfigEvent(const MSG &msg);
+//  bool        translateCloseEvent(const MSG &msg);
+//  void        repolishStyle(QStyle &style);
+//  inline void showChildren(bool spontaneous) { d_func()->showChildren(spontaneous); }
+//  inline void hideChildren(bool spontaneous) { d_func()->hideChildren(spontaneous); }
+//  inline uint testWindowState(uint teststate){ return dataPtr()->window_state & teststate; }
+//  inline void forceUpdate() {
+//      QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
+//      if (tlwExtra && tlwExtra->backingStore)
+//          tlwExtra->backingStore->markDirty(rect(), this, true, true);
+//  }
+};
+
+static void qt_set_pm_resources()
+{
+    // @todo later: take colors, fonts, etc. from the system theme
+};
+
+/*****************************************************************************
+  qt_init() - initializes Qt for PM
+ *****************************************************************************/
+
+void qt_init(QApplicationPrivate *priv, int)
+{
+
+    int argc = priv->argc;
+    char **argv = priv->argv;
+    int i, j;
+
+    // Get command line params
+
+    j = argc ? 1 : 0;
+    for (i=1; i<argc; i++) {
+        if (argv[i] && *argv[i] != '-') {
+            argv[j++] = argv[i];
+            continue;
+        }
+#if defined(QT_DEBUG)
+        if (qstrcmp(argv[i], "-nograb") == 0)
+            appNoGrab = !appNoGrab;
+        else
+#endif // QT_DEBUG
+            argv[j++] = argv[i];
+    }
+    if(j < priv->argc) {
+        priv->argv[j] = 0;
+        priv->argc = j;
+    }
+
+    // initialize key mapper
+    QKeyMapper::changeKeyboard();
+
+    QColormap::initialize();
+    QFont::initialize();
+#ifndef QT_NO_CURSOR
+    QCursorData::initialize();
+#endif
+    qApp->setObjectName(priv->appName());
+
+    // default font
+    QApplicationPrivate::setSystemFont(
+        QFont(QLatin1String("System Proportional"), 10));
+
+    // QFont::locale_init();  ### Uncomment when it does something on OS/2
+
+    if (QApplication::desktopSettingsAware())
+        qt_set_pm_resources();
+}
+
+/*****************************************************************************
+  qt_cleanup() - cleans up when the application is finished
+ *****************************************************************************/
+
+void qt_cleanup()
+{
+    unregWinClasses();
+    QPixmapCache::clear();
+
+#ifndef QT_NO_CURSOR
+    QCursorData::cleanup();
+#endif
+    QFont::cleanup();
+    QColormap::cleanup();
+
+    if (displayPS) {
+        WinReleasePS(displayPS);
+        displayPS = 0;
+    }
+}
+
+/*****************************************************************************
+  Platform specific global and internal functions
+ *****************************************************************************/
+
+Q_GUI_EXPORT HPS qt_display_dc()
+{
+    Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());
+    if (!displayPS)
+        displayPS = WinGetScreenPS(HWND_DESKTOP);
+    return displayPS;
+}
+
+// application no-grab option
+bool qt_nograb()
+{
+#if defined(QT_DEBUG)
+    return appNoGrab;
+#else
+    return false;
+#endif
+}
+
+typedef QSet<QString> WinClassNameHash;
+Q_GLOBAL_STATIC(WinClassNameHash, winclassNames)
+
+// register window class
+const QString qt_reg_winclass(QWidget *w)
+{
+    int flags = w->windowFlags();
+    int type = flags & Qt::WindowType_Mask;
+
+    QString cname;
+    ULONG style = 0;
+
+    if (type == Qt::Window) {
+        // this class is for frame window clients when WC_FRAME is used.
+        cname = QLatin1String("QWindow");
+        style |= CS_MOVENOTIFY;
+    } else if (type == Qt::Popup || type == Qt::Tool || type == Qt::ToolTip) {
+        cname = QLatin1String("QPopup");
+        // @todo do we really want SAVEBITS here?
+        style |= CS_SAVEBITS;
+    } else {
+        cname = QLatin1String("QWidget");
+    }
+
+    if (winclassNames()->contains(cname)) // already registered in our list
+        return cname;
+
+    // QT_EXTRAWINDATASIZE is defined in qwindowdefs_pm.h
+    WinRegisterClass(0, cname.toLatin1(), QtWndProc, style, QT_EXTRAWINDATASIZE);
+
+    winclassNames()->insert(cname);
+    return cname;
+}
+
+static void unregWinClasses()
+{
+    // there is no need to unregister private window classes -- it is done
+    // automatically upon process termination.
+    winclassNames()->clear();
+}
+
+/*****************************************************************************
+  Safe configuration (move,resize,setGeometry) mechanism to avoid
+  recursion when processing messages.
+ *****************************************************************************/
+
+/*****************************************************************************
+    GUI event dispatcher
+ *****************************************************************************/
+
+/*****************************************************************************
+  Platform specific QApplication members
+ *****************************************************************************/
+
+void QApplicationPrivate::initializeWidgetPaletteHash()
+{
+}
+
+QString QApplicationPrivate::appName() const
+{
+    return QCoreApplicationPrivate::appName();
+}
+
+/*****************************************************************************
+  QApplication cursor stack
+ *****************************************************************************/
+
+/*****************************************************************************
+  Routines to find a Qt widget from a screen position
+ *****************************************************************************/
+
+/*****************************************************************************
+  Main event loop
+ *****************************************************************************/
+
+/*****************************************************************************
+  Modal widgets; We have implemented our own modal widget mechanism
+  to get total control.
+  A modal widget without a parent becomes application-modal.
+  A modal widget with a parent becomes modal to its parent and grandparents..
+
+  QApplicationPrivate::enterModal()
+        Enters modal state
+        Arguments:
+            QWidget *widget        A modal widget
+
+  QApplicationPrivate::leaveModal()
+        Leaves modal state for a widget
+        Arguments:
+            QWidget *widget        A modal widget
+ *****************************************************************************/
+
+/*****************************************************************************
+  Popup widget mechanism
+
+  openPopup()
+        Adds a widget to the list of popup widgets
+        Arguments:
+            QWidget *widget        The popup widget to be added
+
+  closePopup()
+        Removes a widget from the list of popup widgets
+        Arguments:
+            QWidget *widget        The popup widget to be removed
+ *****************************************************************************/
+
+/*****************************************************************************
+  Event translation; translates PM events to Qt events
+ *****************************************************************************/
+
+QT_END_NAMESPACE
Index: /trunk/src/gui/kernel/qwidget.cpp
===================================================================
--- /trunk/src/gui/kernel/qwidget.cpp	(revision 91)
+++ /trunk/src/gui/kernel/qwidget.cpp	(revision 92)
@@ -1346,5 +1346,5 @@
     if (isWindow() && isVisible() && internalWinId())
         hide();
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
+#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
     else if (!internalWinId() && isVisible())
         qApp->d_func()->sendSyntheticEnterLeave(this);
@@ -6818,5 +6818,5 @@
     // hidden.
     if (wasVisible) {
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
+#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
         qApp->d_func()->sendSyntheticEnterLeave(q);
 #endif
@@ -6947,5 +6947,5 @@
             d->show_helper();
 
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
+#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
             qApp->d_func()->sendSyntheticEnterLeave(this);
 #endif
@@ -7062,5 +7062,5 @@
             }
         }
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
+#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
         qApp->d_func()->sendSyntheticEnterLeave(widget);
 #endif
@@ -8645,4 +8645,29 @@
 */
 bool QWidget::winEvent(MSG *message, long *result)
+{
+    Q_UNUSED(message);
+    Q_UNUSED(result);
+    return false;
+}
+
+#endif
+#if defined(Q_WS_PM)
+
+/*!
+    This special event handler can be reimplemented in a subclass to
+    receive native OS/2 Presentation Manager events which are passed in
+    the \a message parameter.
+
+    In your reimplementation of this function, if you want to stop the
+    event being handled by Qt, return true and set \a result to the value
+    that the window procedure should return. If you return false, this
+    native event is passed back to Qt, which translates the event into
+    a Qt event and sends it to the widget.
+
+    \warning This function is not portable.
+
+    \sa QApplication::pmEventFilter()
+*/
+bool QWidget::pmEvent(QMSG *message, MRESULT *result)
 {
     Q_UNUSED(message);
Index: /trunk/src/gui/kernel/qwidget.h
===================================================================
--- /trunk/src/gui/kernel/qwidget.h	(revision 91)
+++ /trunk/src/gui/kernel/qwidget.h	(revision 92)
@@ -658,4 +658,7 @@
 #if defined(Q_WS_WIN)
     virtual bool winEvent(MSG *message, long *result);
+#endif
+#if defined(Q_WS_PM)
+    virtual bool pmEvent(QMSG *message, MRESULT *result);
 #endif
 #if defined(Q_WS_X11)
Index: /trunk/src/gui/kernel/qwidget_p.h
===================================================================
--- /trunk/src/gui/kernel/qwidget_p.h	(revision 91)
+++ /trunk/src/gui/kernel/qwidget_p.h	(revision 92)
@@ -594,5 +594,5 @@
 #endif
 
-#if defined(Q_WS_X11) || defined (Q_WS_WIN) || defined(Q_WS_MAC)
+#if defined(Q_WS_X11) || defined (Q_WS_WIN)  || defined (Q_WS_PM) || defined(Q_WS_MAC)
 #ifdef Q_WS_MAC
     void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
Index: /trunk/src/gui/kernel/qwidget_pm.cpp
===================================================================
--- /trunk/src/gui/kernel/qwidget_pm.cpp	(revision 92)
+++ /trunk/src/gui/kernel/qwidget_pm.cpp	(revision 92)
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** Copyright (C) 2009 netlabs.org. OS/2 parts.
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qt_os2.h"
+
+#include "qwidget.h"
+#include "qwidget_p.h"
+
+#include "qapplication.h"
+
+#include "private/qapplication_p.h"
+
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+// defined in qapplication_pm.cpp
+extern bool qt_nograb();
+extern const QString qt_reg_winclass(QWidget *w);
+extern "C" MRESULT EXPENTRY QtWndProc(HWND, ULONG, MPARAM, MPARAM);
+
+/*****************************************************************************
+  QWidget member functions
+ *****************************************************************************/
+
+QT_END_NAMESPACE
Index: /trunk/src/gui/kernel/qwindowdefs_pm.h
===================================================================
--- /trunk/src/gui/kernel/qwindowdefs_pm.h	(revision 91)
+++ /trunk/src/gui/kernel/qwindowdefs_pm.h	(revision 92)
@@ -58,6 +58,13 @@
 typedef unsigned long LHANDLE;
 typedef LHANDLE HWND;
+typedef struct _QMSG QMSG;
+typedef void *MRESULT;
 
 typedef HWND WId;
+
+// constants to address extra window data
+#define QWL_QTCLIPRGN       (QWL_USER)
+#define QWL_QTMODAL         (QWL_USER + sizeof(ULONG))
+#define QT_EXTRAWINDATASIZE (sizeof(LONG) * 2)
 
 QT_BEGIN_NAMESPACE
