Changeset 68


Ignore:
Timestamp:
Jul 4, 2009, 12:21:28 PM (11 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: OS/2: Initial port of QCoreApplication (#8).

Location:
trunk/src/corelib/kernel
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/kernel/kernel.pri

    r2 r68  
    6868}
    6969
     70os2 {
     71        SOURCES += \
     72                kernel/qeventdispatcher_pm.cpp \
     73                kernel/qcoreapplication_pm.cpp
     74        HEADERS += \
     75                kernel/qeventdispatcher_pm_p.h \
     76}
    7077
    7178wince*: {
  • trunk/src/corelib/kernel/qcoreapplication.cpp

    r2 r68  
    7474#endif
    7575
     76#ifdef Q_OS_OS2
     77#  include "qeventdispatcher_pm_p.h"
     78#endif
     79
    7680#ifdef Q_OS_MAC
    7781#  include "qcore_mac_p.h"
     
    8690QT_BEGIN_NAMESPACE
    8791
    88 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
     92#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_MAC)
    8993extern QString qAppFileName();
    9094#endif
    9195
    92 #if !defined(Q_OS_WIN)
     96#if !defined(Q_OS_WIN) && !defined(Q_WS_PM)
    9397#ifdef Q_OS_MAC
    9498QString QCoreApplicationPrivate::macMenuBarName()
     
    278282#elif defined(Q_OS_WIN)
    279283    eventDispatcher = new QEventDispatcherWin32(q);
     284#elif defined(Q_OS_OS2)
     285    eventDispatcher = new QEventDispatcherPM(q);
    280286#else
    281287#  error "QEventDispatcher not yet ported to this platform"
     
    378384    setLibraryPaths(), addLibraryPath(), and removeLibraryPath().
    379385
    380         On Unix/Linux Qt is configured to use the system local settings by 
    381         default. This can cause a conflict when using POSIX functions, for 
    382         instance, when converting between data types such as floats and 
    383         strings, since the notation may differ between locales. To get 
    384         around this problem call the POSIX function setlocale(LC_NUMERIC,"C") 
    385         right after initializing QApplication or QCoreApplication to reset 
     386        On Unix/Linux Qt is configured to use the system local settings by
     387        default. This can cause a conflict when using POSIX functions, for
     388        instance, when converting between data types such as floats and
     389        strings, since the notation may differ between locales. To get
     390        around this problem call the POSIX function setlocale(LC_NUMERIC,"C")
     391        right after initializing QApplication or QCoreApplication to reset
    386392        the locale that is used for number formatting to "C"-locale.
    387393
     
    17431749
    17441750    d->cachedApplicationFilePath = filePath.filePath();
     1751    return d->cachedApplicationFilePath;
     1752#elif defined(Q_WS_PM)
     1753    QString appFileName = qAppFileName();
     1754    if(!appFileName.isEmpty()) {
     1755        QFileInfo fi(appFileName);
     1756        d->cachedApplicationFilePath = fi.canonicalFilePath();
     1757    }
    17451758    return d->cachedApplicationFilePath;
    17461759#elif defined(Q_WS_MAC)
     
    18151828#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
    18161829    return GetCurrentProcessId();
     1830#elif defined(Q_OS_OS2)
     1831    PPIB ppib;
     1832    DosGetInfoBlocks(NULL, &ppib);
     1833    return ppib->pib_ulpid;
    18171834#else
    18181835    // UNIX
     
    20682085        const QByteArray libPathEnv = qgetenv("QT_PLUGIN_PATH");
    20692086        if (!libPathEnv.isEmpty()) {
    2070 #ifdef Q_OS_WIN
     2087#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
    20712088            QLatin1Char pathSep(';');
    20722089#else
     
    22182235    if (d->eventFilter)
    22192236        return d->eventFilter(message, result);
    2220 #ifdef Q_OS_WIN
     2237#if defined(Q_WS_WIN)
    22212238    return winEventFilter(reinterpret_cast<MSG *>(message), result);
     2239#elif defined(Q_WS_PM)
     2240    return pmEventFilter(reinterpret_cast<QMSG *>(message), reinterpret_cast<MRESULT *>(result));
    22222241#else
    22232242    return false;
  • trunk/src/corelib/kernel/qcoreapplication.h

    r2 r68  
    5353#if defined(Q_WS_WIN) && !defined(tagMSG)
    5454typedef struct tagMSG MSG;
     55#endif
     56
     57#if defined(Q_WS_PM)
     58typedef struct _QMSG QMSG;
     59typedef void *MRESULT;
    5560#endif
    5661
     
    164169#if defined(Q_WS_WIN)
    165170    virtual bool winEventFilter(MSG *message, long *result);
     171#endif
     172
     173#if defined(Q_WS_PM)
     174    virtual bool pmEventFilter(QMSG *message, MRESULT *result);
    166175#endif
    167176
  • trunk/src/corelib/kernel/qcoreapplication_pm.cpp

    r63 r68  
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    44** Contact: Qt Software Information (qt-info@nokia.com)
     5**
     6** Copyright (C) 2009 netlabs.org. OS/2 parts.
    57**
    68** This file is part of the QtCore module of the Qt Toolkit.
     
    4345#include "qcoreapplication_p.h"
    4446#include "qstringlist.h"
    45 #include "qt_windows.h"
     47#include "qt_os2.h"
    4648#include "qvector.h"
    4749#include "qmutex.h"
     
    5254QT_BEGIN_NAMESPACE
    5355
    54 // ############### DON'T EXPORT HERE!!!
    55 Q_CORE_EXPORT char         appFileName[MAX_PATH+1];                // application file name
    56 Q_CORE_EXPORT char         theAppName[MAX_PATH+1];                        // application name
    57 Q_CORE_EXPORT HINSTANCE appInst        = 0;                // handle to app instance
    58 Q_CORE_EXPORT HINSTANCE appPrevInst        = 0;                // handle to prev app instance
    59 Q_CORE_EXPORT int appCmdShow = 0;
    60 bool usingWinMain = false;  // whether the qWinMain() is used or not
    61 
    62 Q_CORE_EXPORT HINSTANCE qWinAppInst()                // get Windows app handle
    63 {
    64     return appInst;
    65 }
    66 
    67 Q_CORE_EXPORT HINSTANCE qWinAppPrevInst()                // get Windows prev app handle
    68 {
    69     return appPrevInst;
    70 }
    71 
    72 void set_winapp_name()
     56static char appFileName[CCHMAXPATH];     // application file name
     57static char theAppName[CCHMAXPATH];      // application name
     58
     59static void set_app_name()
    7360{
    7461    static bool already_set = false;
    7562    if (!already_set) {
    7663        already_set = true;
    77 #ifndef Q_OS_WINCE
    78         GetModuleFileNameA(0, appFileName, sizeof(appFileName));
    79         appFileName[sizeof(appFileName)-1] = 0;
    80 #else
    81         QString afm;
    82         afm.resize(sizeof(appFileName));
    83         afm.resize(GetModuleFileName(0, (wchar_t *) (afm.unicode()), sizeof(appFileName)));
    84         memcpy(appFileName, afm.toLatin1(), sizeof(appFileName));
    85 #endif
     64        PPIB ppib;
     65        DosGetInfoBlocks(NULL, &ppib);
     66        DosQueryModuleName(ppib->pib_hmte, sizeof(appFileName), appFileName);
     67
    8668        const char *p = strrchr(appFileName, '\\');        // skip path
    8769        if (p)
     
    9577Q_CORE_EXPORT QString qAppFileName()                // get application file name
    9678{
    97     return QString::fromLatin1(appFileName);
     79    set_app_name();
     80    return QString::fromLocal8Bit(appFileName);
    9881}
    9982
    10083QString QCoreApplicationPrivate::appName() const
    10184{
    102     if (!theAppName[0])
    103         set_winapp_name();
    104     return QString::fromLatin1(theAppName);
    105 }
    106 
    107 class QWinMsgHandlerCriticalSection
    108 {
    109     CRITICAL_SECTION cs;
    110 public:
    111     QWinMsgHandlerCriticalSection()
    112     { InitializeCriticalSection(&cs); }
    113     ~QWinMsgHandlerCriticalSection()
    114     { DeleteCriticalSection(&cs); }
    115 
    116     void lock()
    117     { EnterCriticalSection(&cs); }
    118     void unlock()
    119     { LeaveCriticalSection(&cs); }
    120 };
    121 
    122 Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char* str)
    123 {
    124     Q_UNUSED(t);
    125     // OutputDebugString is not threadsafe.
    126 
    127     // cannot use QMutex here, because qWarning()s in the QMutex
    128     // implementation may cause this function to recurse
    129     static QWinMsgHandlerCriticalSection staticCriticalSection;
    130 
    131     if (!str)
    132         str = "(null)";
    133 
    134     staticCriticalSection.lock();
    135     QT_WA({
    136         QString s(QString::fromLocal8Bit(str));
    137         s += QLatin1String("\n");
    138         OutputDebugStringW((TCHAR*)s.utf16());
    139     }, {
    140         QByteArray s(str);
    141         s += "\n";
    142         OutputDebugStringA(s.data());
    143     })
    144     staticCriticalSection.unlock();
    145 }
    146 
    147 
    148 /*****************************************************************************
    149   qWinMain() - Initializes Windows. Called from WinMain() in qtmain_win.cpp
    150  *****************************************************************************/
    151 
    152 #if defined(Q_OS_WINCE)
    153 Q_CORE_EXPORT void __cdecl qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam,
    154                int cmdShow, int &argc, QVector<char *> &argv)
    155 #else
    156 Q_CORE_EXPORT
    157 void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam,
    158                int cmdShow, int &argc, QVector<char *> &argv)
    159 #endif
    160 {
    161     static bool already_called = false;
    162 
    163     if (already_called) {
    164         qWarning("Qt: Internal error: qWinMain should be called only once");
    165         return;
    166     }
    167     already_called = true;
    168     usingWinMain = true;
    169 
    170   // Install default debug handler
    171 
    172     qInstallMsgHandler(qWinMsgHandler);
    173 
    174   // Create command line
    175 
    176     set_winapp_name();
    177 
    178     argv = qWinCmdLine<char>(cmdParam, int(strlen(cmdParam)), argc);
    179     // Get Windows parameters
    180 
    181     appInst = instance;
    182     appPrevInst = prevInstance;
    183     appCmdShow = cmdShow;
     85    set_app_name();
     86    return QString::fromLocal8Bit(theAppName);
    18487}
    18588
     
    198101    QAbstractEventDispatcher::instance().
    199102*/
    200 bool QCoreApplication::winEventFilter(MSG *msg, long *result)        // Windows event filter
    201 {
    202     Q_UNUSED(msg);
    203     Q_UNUSED(result);
     103bool QCoreApplication::pmEventFilter(QMSG * /*msg*/, MRESULT * /*rc*/)
     104{
    204105    return false;
    205106}
    206107
     108// @todo check if we really need this when doing timers in QEventDispatcherPM
     109#if 0
    207110void QCoreApplicationPrivate::removePostedTimerEvent(QObject *object, int timerId)
    208111{
     
    226129    }
    227130}
    228 
    229 #if defined(Q_WS_WIN) && !defined(QT_NO_DEBUG_STREAM)
     131#endif
     132
     133// @todo later
     134#if 0 && !defined(QT_NO_DEBUG_STREAM)
    230135/*****************************************************************************
    231136  Convenience functions for convert WM_* messages into human readable strings,
     
    233138 *****************************************************************************/
    234139QT_BEGIN_INCLUDE_NAMESPACE
    235 #include <windowsx.h>
    236140#include "qdebug.h"
    237141QT_END_INCLUDE_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.