Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/kernel/qapplication_win.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
    4040****************************************************************************/
    4141
    42 #ifdef Q_OS_WINCE
     42#ifdef Q_WS_WINCE
    4343#include "qguifunctions_wince.h"
    4444#include "qmenubar.h"
     
    4949extern void qt_wince_hide_taskbar(HWND hwnd); //defined in qguifunctions_wince.cpp
    5050#endif
    51 #ifdef Q_OS_WINCE_WM
     51#ifdef Q_WS_WINCE_WM
    5252#include <windowsm.h>
    5353#include <tpcshell.h>
     54#ifdef QT_WINCE_GESTURES
     55#include <gesture.h>
     56#endif
    5457#endif
    5558
     
    8992#include <private/qkeymapper_p.h>
    9093#include <private/qlocale_p.h>
     94#include "qevent_p.h"
    9195
    9296//#define ALIEN_DEBUG
     
    105109#endif // QT_NO_ACCESSIBILITY
    106110
    107 #include <winuser.h>
    108111#if !defined(WINABLEAPI)
    109 #  if defined(Q_OS_WINCE)
     112#  if defined(Q_WS_WINCE)
    110113#    include <bldver.h>
    111114#  endif
     
    113116#endif
    114117
    115 
    116 #ifndef FLASHW_STOP
    117 typedef struct {
    118     UINT  cbSize;
    119     HWND  hwnd;
     118#ifndef WM_TOUCH
     119#  define WM_TOUCH 0x0240
     120
     121#  define TOUCHEVENTF_MOVE       0x0001
     122#  define TOUCHEVENTF_DOWN       0x0002
     123#  define TOUCHEVENTF_UP         0x0004
     124#  define TOUCHEVENTF_INRANGE    0x0008
     125#  define TOUCHEVENTF_PRIMARY    0x0010
     126#  define TOUCHEVENTF_NOCOALESCE 0x0020
     127#  define TOUCHEVENTF_PEN        0x0040
     128#  define TOUCHEVENTF_PALM       0x0080
     129
     130#  define TOUCHINPUTMASKF_TIMEFROMSYSTEM 0x0001
     131#  define TOUCHINPUTMASKF_EXTRAINFO      0x0002
     132#  define TOUCHINPUTMASKF_CONTACTAREA    0x0004
     133
     134typedef struct tagTOUCHINPUT
     135{
     136    LONG x;
     137    LONG y;
     138    HANDLE hSource;
     139    DWORD dwID;
    120140    DWORD dwFlags;
    121     UINT  uCount;
    122     DWORD dwTimeout;
    123 } FLASHWINFO, *PFLASHWINFO;
    124 #define FLASHW_STOP         0
    125 #define FLASHW_CAPTION      0x00000001
    126 #define FLASHW_TRAY         0x00000002
    127 #define FLASHW_ALL          (FLASHW_CAPTION | FLASHW_TRAY)
    128 #define FLASHW_TIMER        0x00000004
    129 #define FLASHW_TIMERNOFG    0x0000000C
    130 #endif /* FLASHW_STOP */
    131 typedef BOOL (WINAPI *PtrFlashWindowEx)(PFLASHWINFO pfwi);
    132 static PtrFlashWindowEx pFlashWindowEx = 0;
     141    DWORD dwMask;
     142    DWORD dwTime;
     143    ULONG_PTR dwExtraInfo;
     144    DWORD cxContact;
     145    DWORD cyContact;
     146} TOUCHINPUT, *PTOUCHINPUT;
     147
     148#endif
    133149
    134150#include <windowsx.h>
     
    154170#endif
    155171
     172#ifndef IMR_RECONVERTSTRING
     173#define IMR_RECONVERTSTRING 4
     174#endif
     175
     176#ifndef IMR_CONFIRMRECONVERTSTRING
     177#define IMR_CONFIRMRECONVERTSTRING 0x0005
     178#endif
    156179QT_BEGIN_NAMESPACE
    157180
    158 #ifdef Q_OS_WINCE
     181#ifdef Q_WS_WINCE
    159182#ifndef SHRG_RETURNCMD
    160183struct SHRGINFO {
     
    199222#endif
    200223
    201 bool qt_cleartype_enabled;
     224Q_GUI_EXPORT bool qt_cleartype_enabled;
    202225Q_GUI_EXPORT bool qt_win_owndc_required; // CS_OWNDC is required if we use the GL graphicssystem as default
    203226
     
    221244HCTX qt_tablet_context;  // the hardware context for the tablet (like a window handle)
    222245bool qt_tablet_tilt_support;
    223 static void tabletInit(UINT wActiveCsr, HCTX hTab);
     246
     247#ifndef QT_NO_TABLETEVENT
     248static void tabletInit(const quint64 uniqueId, const UINT csr_type, HCTX hTab);
     249static void tabletUpdateCursor(QTabletDeviceData &tdd, const UINT currentCursor);
    224250static void initWinTabFunctions();        // resolve the WINTAB api functions
     251#endif // QT_NO_TABLETEVENT
    225252
    226253
     
    234261extern QRegion qt_dirtyRegion(QWidget *);
    235262
    236 typedef QHash<UINT, QTabletDeviceData> QTabletCursorInfo;
     263typedef QHash<quint64, QTabletDeviceData> QTabletCursorInfo;
    237264Q_GLOBAL_STATIC(QTabletCursorInfo, tCursorInfo)
    238265QTabletDeviceData currentTabletPointer;
     
    240267// from qregion_win.cpp
    241268extern HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int right, int bottom);
    242 
    243 Q_CORE_EXPORT bool winPeekMessage(MSG* msg, HWND hWnd, UINT wMsgFilterMin,
    244                             UINT wMsgFilterMax, UINT wRemoveMsg);
    245 Q_CORE_EXPORT bool winPostMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
    246269
    247270// support for on-the-fly changes of the XP theme engine
     
    259282#define WM_XBUTTONUP                    0x020C
    260283#define WM_XBUTTONDBLCLK                0x020D
     284#endif
     285#ifndef GET_KEYSTATE_WPARAM
    261286#define GET_KEYSTATE_WPARAM(wParam)     (LOWORD(wParam))
    262287#define GET_XBUTTON_WPARAM(wParam)      (HIWORD(wParam))
    263288#define XBUTTON1      0x0001
    264289#define XBUTTON2      0x0002
     290#endif
     291#ifndef MK_XBUTTON1
    265292#define MK_XBUTTON1         0x0020
    266293#define MK_XBUTTON2         0x0040
    267294#endif
    268295
    269 #ifdef Q_OS_WINCE
    270 #define GET_KEYSTATE_WPARAM(wParam)     (LOWORD(wParam))
    271 #endif
    272 
    273 // support for multi-media-keys on ME/2000/XP
     296// support for multi-media-keys
    274297#ifndef WM_APPCOMMAND
    275298#define WM_APPCOMMAND                   0x0319
    276 
     299#endif
     300
     301#ifndef FAPPCOMMAND_MOUSE
    277302#define FAPPCOMMAND_MOUSE 0x8000
    278303#define FAPPCOMMAND_KEY   0
     
    308333#define APPCOMMAND_TREBLE_DOWN            22
    309334#define APPCOMMAND_TREBLE_UP              23
     335#endif // FAPPCOMMAND_MOUSE
    310336
    311337// New commands from Windows XP (some even Sp1)
     
    342368#endif // APPCOMMAND_MICROPHONE_VOLUME_MUTE
    343369
    344 #endif // WM_APPCOMMAND
    345 
    346 static UINT WM95_MOUSEWHEEL = 0;
    347 
    348370#if (_WIN32_WINNT < 0x0400)
    349371// This struct is defined in winuser.h if the _WIN32_WINNT >= 0x0400 -- in the
     
    377399 *****************************************************************************/
    378400
    379 extern Q_CORE_EXPORT char      theAppName[];
    380 extern Q_CORE_EXPORT char      appFileName[];
    381 extern Q_CORE_EXPORT HINSTANCE appInst;                        // handle to app instance
    382 extern Q_CORE_EXPORT HINSTANCE appPrevInst;                        // handle to prev app instance
    383 extern Q_CORE_EXPORT int appCmdShow;                                // main window show command
    384401static HWND         curWin                = 0;                // current window
    385402static HDC         displayDC        = 0;                // display device context
     
    422439#define __export
    423440#endif
    424 
    425 QApplicationPrivate* getQApplicationPrivateInternal()
    426 {
    427     return qApp->d_func();
    428 }
    429441
    430442extern "C" LRESULT CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM);
     
    449461    bool        translateCloseEvent(const MSG &msg);
    450462    bool        translateTabletEvent(const MSG &msg, PACKET *localPacketBuf, int numPackets);
     463    bool        translateGestureEvent(const MSG &msg, const GESTUREINFO &gi);
    451464    void        repolishStyle(QStyle &style);
    452465    inline void showChildren(bool spontaneous) { d_func()->showChildren(spontaneous); }
     
    498511                 QColor(qt_colorref2qrgb(GetSysColor(COLOR_HIGHLIGHTTEXT))));
    499512
    500 #if defined(Q_OS_WINCE)
     513#if defined(Q_WS_WINCE)
    501514    // ### hardcoded until I find out how to get it from the system settings.
    502515    pal.setColor(QPalette::LinkVisited, pal.highlight().color().dark(150));
     
    517530    pal.setColor(QPalette::Inactive, QPalette::Dark, pal.dark().color());
    518531
    519     if (QSysInfo::WindowsVersion != QSysInfo::WV_NT && QSysInfo::WindowsVersion != QSysInfo::WV_95) {
    520         if (pal.midlight() == pal.button())
    521             pal.setColor(QPalette::Midlight, pal.button().color().lighter(110));
    522         if (pal.background() != pal.base()) {
    523             pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Inactive, QPalette::Window));
    524             pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Inactive, QPalette::Text));
    525         }
    526     }
     532    if (pal.midlight() == pal.button())
     533        pal.setColor(QPalette::Midlight, pal.button().color().lighter(110));
     534    if (pal.background() != pal.base()) {
     535        pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Inactive, QPalette::Window));
     536        pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Inactive, QPalette::Text));
     537    }
     538
    527539    const QColor bg = pal.background().color();
    528540    const QColor fg = pal.foreground().color(), btn = pal.button().color();
     
    574586static void qt_set_windows_font_resources()
    575587{
    576 #ifndef Q_OS_WINCE
    577     QFont menuFont;
    578     QFont messageFont;
    579     QFont statusFont;
    580     QFont titleFont;
    581     QFont iconTitleFont;
    582     QT_WA({
    583         NONCLIENTMETRICS ncm;
    584         ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONTW);
    585         SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize , &ncm, 0);
    586         menuFont = qt_LOGFONTtoQFont(ncm.lfMenuFont,true);
    587         messageFont = qt_LOGFONTtoQFont(ncm.lfMessageFont,true);
    588         statusFont = qt_LOGFONTtoQFont(ncm.lfStatusFont,true);
    589         titleFont = qt_LOGFONTtoQFont(ncm.lfCaptionFont,true);
    590         LOGFONTW lfIconTitleFont;
    591         SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lfIconTitleFont), &lfIconTitleFont, 0);
    592         iconTitleFont = qt_LOGFONTtoQFont(lfIconTitleFont,true);
    593     } , {
    594         // A version
    595         NONCLIENTMETRICSA ncm;
    596         ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICSA, lfMessageFont) + sizeof(LOGFONTA);
    597         SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
    598         menuFont = qt_LOGFONTtoQFont((LOGFONT&)ncm.lfMenuFont,true);
    599         messageFont = qt_LOGFONTtoQFont((LOGFONT&)ncm.lfMessageFont,true);
    600         statusFont = qt_LOGFONTtoQFont((LOGFONT&)ncm.lfStatusFont,true);
    601         titleFont = qt_LOGFONTtoQFont((LOGFONT&)ncm.lfCaptionFont,true);
    602         LOGFONTA lfIconTitleFont;
    603         SystemParametersInfoA(SPI_GETICONTITLELOGFONT, sizeof(lfIconTitleFont), &lfIconTitleFont, 0);
    604         iconTitleFont = qt_LOGFONTtoQFont((LOGFONT&)lfIconTitleFont,true);
    605     });
     588#ifndef Q_WS_WINCE
     589    NONCLIENTMETRICS ncm;
     590    ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT);
     591    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize , &ncm, 0);
     592
     593    QFont menuFont = qt_LOGFONTtoQFont(ncm.lfMenuFont, true);
     594    QFont messageFont = qt_LOGFONTtoQFont(ncm.lfMessageFont, true);
     595    QFont statusFont = qt_LOGFONTtoQFont(ncm.lfStatusFont, true);
     596    QFont titleFont = qt_LOGFONTtoQFont(ncm.lfCaptionFont, true);
     597
     598    LOGFONT lfIconTitleFont;
     599    SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIconTitleFont), &lfIconTitleFont, 0);
     600    QFont iconTitleFont = qt_LOGFONTtoQFont(lfIconTitleFont, true);
    606601
    607602    QApplication::setFont(menuFont, "QMenu");
     
    625620        smallerFont.setPointSize(systemFont.pointSize()-1);
    626621        QApplication::setFont(smallerFont, "QTabBar");
    627     }
    628 #endif// Q_OS_WINCE
     622        smallerFont.setBold(true);
     623        QApplication::setFont(smallerFont, "QAbstractButton");
     624    }
     625#endif// Q_WS_WINCE
    629626}
    630627
    631628static void qt_win_read_cleartype_settings()
    632629{
    633     QT_WA({
    634         UINT result;
    635         BOOL ok;
    636         ok = SystemParametersInfoW(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0);
    637         if (ok)
    638             qt_cleartype_enabled = (result == FE_FONTSMOOTHINGCLEARTYPE);
    639     }, {
    640         UINT result;
    641         BOOL ok;
    642         ok = SystemParametersInfoA(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0);
    643         if (ok)
    644             qt_cleartype_enabled = (result == FE_FONTSMOOTHINGCLEARTYPE);
    645     });
     630    UINT result = 0;
     631#ifdef Q_OS_WINCE
     632    if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &result, 0))
     633        qt_cleartype_enabled = result;
     634#else
     635    if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0))
     636        qt_cleartype_enabled = (result == FE_FONTSMOOTHINGCLEARTYPE);
     637#endif
    646638}
    647639
     
    660652    QColor menuCol(qt_colorref2qrgb(GetSysColor(COLOR_MENU)));
    661653    QColor menuText(qt_colorref2qrgb(GetSysColor(COLOR_MENUTEXT)));
    662     BOOL isFlat = 0;
     654    BOOL isFlat = false;
    663655    if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
    664656        && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
    665         SystemParametersInfo(0x1022 /*SPI_GETFLATMENU*/, 0, &isFlat, 0);
     657        SystemParametersInfo(SPI_GETFLATMENU, 0, &isFlat, 0);
    666658    QPalette menu(pal);
    667659    // we might need a special color group for the menu.
     
    678670                                            (QSysInfo::WindowsVersion >= QSysInfo::WV_XP
    679671                                            && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)
    680                                             && isFlat ? COLOR_MENUHILIGHT
    681                                                         : COLOR_HIGHLIGHT))));
     672                                            && isFlat ? COLOR_MENUHILIGHT : COLOR_HIGHLIGHT))));
    682673    menu.setColor(QPalette::Disabled, QPalette::HighlightedText, disabled);
    683674    menu.setColor(QPalette::Disabled, QPalette::Button,
     
    695686    menu.setColor(QPalette::Inactive, QPalette::HighlightedText,
    696687                    menu.color(QPalette::Active, QPalette::HighlightedText));
    697 
    698     if (QSysInfo::WindowsVersion != QSysInfo::WV_NT && QSysInfo::WindowsVersion != QSysInfo::WV_95)
    699         menu.setColor(QPalette::Inactive, QPalette::ButtonText,
    700                         pal.color(QPalette::Inactive, QPalette::Dark));
     688    menu.setColor(QPalette::Inactive, QPalette::ButtonText,
     689                    pal.color(QPalette::Inactive, QPalette::Dark));
    701690    QApplication::setPalette(menu, "QMenu");
    702691
     
    715704 *****************************************************************************/
    716705
    717 typedef BOOL (WINAPI *PtrUpdateLayeredWindow)(HWND hwnd, HDC hdcDst, const POINT *pptDst,
    718     const SIZE *psize, HDC hdcSrc, const POINT *pptSrc, COLORREF crKey,
    719     const Q_BLENDFUNCTION *pblend, DWORD dwflags);
    720 static PtrUpdateLayeredWindow ptrUpdateLayeredWindow = 0;
    721 
     706typedef BOOL (WINAPI *PtrSetProcessDPIAware) (VOID);
     707static PtrSetProcessDPIAware ptrSetProcessDPIAware = 0;
     708PtrUpdateLayeredWindow ptrUpdateLayeredWindow = 0;
     709PtrUpdateLayeredWindowIndirect ptrUpdateLayeredWindowIndirect = 0;
    722710static BOOL WINAPI qt_updateLayeredWindowIndirect(HWND hwnd, const Q_UPDATELAYEREDWINDOWINFO *info)
    723711{
     
    746734        else
    747735#endif // QT_DEBUG
    748         if (qstrcmp(argv[i], "-direct3d") == 0)
    749             QApplication::setAttribute(Qt::AA_MSWindowsUseDirect3DByDefault);
    750         else
    751736            argv[j++] = argv[i];
    752737    }
     
    756741    }
    757742
    758     // Get the application name/instance if qWinMain() was not invoked
    759 #ifndef Q_OS_WINCE
     743#ifndef Q_WS_WINCE
    760744    // No message boxes but important ones
    761745    SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
    762746#endif
    763747
    764     if (appInst == 0) {
    765         QT_WA({
    766             appInst = GetModuleHandle(0);
    767         }, {
    768             appInst = GetModuleHandleA(0);
    769         });
    770     }
    771 
    772 #ifndef Q_OS_WINCE
     748#ifndef Q_WS_WINCE
    773749    // Initialize OLE/COM
    774750    //         S_OK means success and S_FALSE means that it has already
     
    782758
    783759    // Misc. initialization
    784 #if defined(QT_DEBUG) && !defined(Q_OS_WINCE)
     760#if defined(QT_DEBUG) && !defined(Q_WS_WINCE)
    785761    GdiSetBatchLimit(1);
    786762#endif
     
    794770    QCursorData::initialize();
    795771#endif
    796     qApp->setObjectName(QLatin1String(theAppName));
    797 
    798 #if !defined(Q_OS_WINCE)
     772    qApp->setObjectName(priv->appName());
     773
    799774    // default font
    800     HFONT hfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
    801     QFont f(QLatin1String("MS Sans Serif"),8);
    802     int result = 0;
    803     QT_WA({
    804             LOGFONT lf;
    805             if (result = GetObject(hfont, sizeof(lf), &lf))
    806                 f = qt_LOGFONTtoQFont((LOGFONT&)lf,true);
    807         } , {
    808               LOGFONTA lf;
    809               if (result = GetObjectA(hfont, sizeof(lf), &lf))
    810                   f = qt_LOGFONTtoQFont((LOGFONT&)lf,true);
    811           });
    812     if (result
    813         && QSysInfo::WindowsVersion >= QSysInfo::WV_2000
    814         && QSysInfo::WindowsVersion <= QSysInfo::WV_NT_based
    815         && f.family() == QLatin1String("MS Shell Dlg"))
    816         f.setFamily(QLatin1String("MS Shell Dlg 2"));
    817     QApplicationPrivate::setSystemFont(f);
    818 #else //Q_OS_WINCE
    819         LOGFONT lf;
    820         HGDIOBJ stockFont = GetStockObject(SYSTEM_FONT);
    821         int result = 0;
    822         result = GetObject(stockFont, sizeof(lf), &lf);
    823         QFont font = qt_LOGFONTtoQFont(lf, true);
    824         if (result)
    825           QApplicationPrivate::setSystemFont(font);
    826 #endif //Q_OS_WINCE
     775#ifndef Q_WS_WINCE
     776    HGDIOBJ stockFont = GetStockObject(DEFAULT_GUI_FONT);
     777#else
     778    HGDIOBJ stockFont = GetStockObject(SYSTEM_FONT);
     779#endif
     780
     781    LOGFONT lf;
     782    GetObject(stockFont, sizeof(lf), &lf);
     783    QFont systemFont = qt_LOGFONTtoQFont(lf, true);
     784
     785#ifndef Q_WS_WINCE
     786    if (systemFont.family() == QLatin1String("MS Shell Dlg")) {
     787        systemFont.setFamily(QLatin1String("MS Shell Dlg 2"));
     788    }
     789#endif
     790
     791    QApplicationPrivate::setSystemFont(systemFont);
    827792
    828793    // QFont::locale_init();  ### Uncomment when it does something on Windows
     
    831796        qt_set_windows_resources();
    832797
    833     QT_WA({
    834         WM95_MOUSEWHEEL = RegisterWindowMessage(L"MSWHEEL_ROLLMSG");
    835     } , {
    836         WM95_MOUSEWHEEL = RegisterWindowMessageA("MSWHEEL_ROLLMSG");
    837     });
     798#ifndef QT_NO_TABLETEVENT
    838799    initWinTabFunctions();
     800#endif // QT_NO_TABLETEVENT
    839801    QApplicationPrivate::inputContext = new QWinInputContext(0);
    840802
     
    856818    if (ptrUpdateLayeredWindow && !ptrUpdateLayeredWindowIndirect)
    857819        ptrUpdateLayeredWindowIndirect = qt_updateLayeredWindowIndirect;
     820
     821    // Notify Vista and Windows 7 that we support highter DPI settings
     822    ptrSetProcessDPIAware = (PtrSetProcessDPIAware)
     823        QLibrary::resolve(QLatin1String("user32"), "SetProcessDPIAware");
     824    if (ptrSetProcessDPIAware)
     825        ptrSetProcessDPIAware();
     826#endif
     827
     828    priv->GetGestureInfo = 0;
     829    priv->GetGestureExtraArgs = 0;
     830    priv->CloseGestureInfoHandle = 0;
     831    priv->SetGestureConfig = 0;
     832    priv->GetGestureConfig = 0;
     833    priv->BeginPanningFeedback = 0;
     834    priv->UpdatePanningFeedback = 0;
     835    priv->EndPanningFeedback = 0;
     836
     837#if defined(Q_WS_WINCE_WM) && defined(QT_WINCE_GESTURES)
     838    priv->GetGestureInfo = (PtrGetGestureInfo) &TKGetGestureInfo;
     839    priv->GetGestureExtraArgs = (PtrGetGestureExtraArgs) &TKGetGestureExtraArguments;
     840#elif !defined(Q_WS_WINCE)
     841  #if !defined(QT_NO_NATIVE_GESTURES)
     842    priv->GetGestureInfo =
     843            (PtrGetGestureInfo)QLibrary::resolve(QLatin1String("user32"),
     844                                                 "GetGestureInfo");
     845    priv->GetGestureExtraArgs =
     846            (PtrGetGestureExtraArgs)QLibrary::resolve(QLatin1String("user32"),
     847                                                      "GetGestureExtraArgs");
     848    priv->CloseGestureInfoHandle =
     849            (PtrCloseGestureInfoHandle)QLibrary::resolve(QLatin1String("user32"),
     850                                                         "CloseGestureInfoHandle");
     851    priv->SetGestureConfig =
     852            (PtrSetGestureConfig)QLibrary::resolve(QLatin1String("user32"),
     853                                                   "SetGestureConfig");
     854    priv->GetGestureConfig =
     855            (PtrGetGestureConfig)QLibrary::resolve(QLatin1String("user32"),
     856                                                   "GetGestureConfig");
     857  #endif // QT_NO_NATIVE_GESTURES
     858    priv->BeginPanningFeedback =
     859            (PtrBeginPanningFeedback)QLibrary::resolve(QLatin1String("uxtheme"),
     860                                                       "BeginPanningFeedback");
     861    priv->UpdatePanningFeedback =
     862            (PtrUpdatePanningFeedback)QLibrary::resolve(QLatin1String("uxtheme"),
     863                                                        "UpdatePanningFeedback");
     864    priv->EndPanningFeedback =
     865        (PtrEndPanningFeedback)QLibrary::resolve(QLatin1String("uxtheme"),
     866                                                   "EndPanningFeedback");
    858867#endif
    859868}
     
    881890    QApplicationPrivate::inputContext = 0;
    882891
    883 #ifndef Q_OS_WINCE
     892#ifndef Q_WS_WINCE
    884893  // Deinitialize OLE/COM
    885894    OleUninitialize();
     
    891900  Platform specific global and internal functions
    892901 *****************************************************************************/
    893 
    894 Q_GUI_EXPORT int qWinAppCmdShow()                        // get main window show command
    895 {
    896     return appCmdShow;
    897 }
    898 
    899902
    900903Q_GUI_EXPORT HDC qt_win_display_dc()                        // get display DC
     
    929932        cname = QLatin1String("QWidgetOwnDC");
    930933        style = CS_DBLCLKS;
    931 #ifndef Q_OS_WINCE
     934#ifndef Q_WS_WINCE
    932935        style |= CS_OWNDC;
    933936#endif
     
    938941            if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
    939942                && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) {
    940                 style |= 0x00020000;                // CS_DROPSHADOW
     943                style |= CS_DROPSHADOW;
    941944            }
    942945            cname = QLatin1String("QToolTip");
     
    944947            cname = QLatin1String("QTool");
    945948        }
    946 #ifndef Q_OS_WINCE
     949#ifndef Q_WS_WINCE
    947950        style |= CS_SAVEBITS;
    948951#endif
     
    951954        cname = QLatin1String("QPopup");
    952955        style = CS_DBLCLKS;
    953 #ifndef Q_OS_WINCE
     956#ifndef Q_WS_WINCE
    954957        style |= CS_SAVEBITS;
    955958#endif
    956959        if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
    957960            && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
    958             style |= 0x00020000;                // CS_DROPSHADOW
     961            style |= CS_DROPSHADOW;
    959962        icon = false;
    960963    } else {
     
    964967    }
    965968
    966 #ifndef Q_OS_WINCE
     969#ifndef Q_WS_WINCE
    967970    // force CS_OWNDC when the GL graphics system is
    968971    // used as the default renderer
     
    976979    // move the windows to the front when starting
    977980    // a second instance.
    978     wchar_t uniqueAppID[256];
    979     GetModuleFileNameW(0, uniqueAppID, 255);
    980     cname = QString::number(RegisterWindowMessageW(
    981               (const wchar_t *) QString::fromUtf16((const ushort *)uniqueAppID).toLower().replace(QString(QString::fromLatin1("\\")),
    982               QString(QString::fromLatin1("_"))).utf16()));
     981    wchar_t uniqueAppID[MAX_PATH];
     982    GetModuleFileName(0, uniqueAppID, MAX_PATH);
     983    cname = QString::number(RegisterWindowMessage(
     984              (const wchar_t *) QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1Char('\\'),
     985              QLatin1Char('_')).utf16()));
    983986#endif
    984987
     
    991994
    992995    if (classExists == -1) {
    993         QT_WA({
    994             WNDCLASS wcinfo;
    995             classExists = GetClassInfo((HINSTANCE)qWinAppInst(), (TCHAR*)cname.utf16(), &wcinfo);
    996             classExists = classExists && wcinfo.lpfnWndProc != QtWndProc;
    997         }, {
    998             WNDCLASSA wcinfo;
    999             classExists = GetClassInfoA((HINSTANCE)qWinAppInst(), cname.toLatin1(), &wcinfo);
    1000             classExists = classExists && wcinfo.lpfnWndProc != QtWndProc;
    1001         });
     996        WNDCLASS wcinfo;
     997        classExists = GetClassInfo((HINSTANCE)qWinAppInst(), (wchar_t*)cname.utf16(), &wcinfo);
     998        classExists = classExists && wcinfo.lpfnWndProc != QtWndProc;
    1002999    }
    10031000
     
    10081005        return cname;
    10091006
    1010     ATOM atom;
    1011 #ifndef Q_OS_WINCE
    1012     HBRUSH bgBrush = (HBRUSH)GetSysColorBrush(COLOR_WINDOW);
    1013     QT_WA({
    1014         WNDCLASS wc;
    1015         wc.style        = style;
    1016         wc.lpfnWndProc        = (WNDPROC)QtWndProc;
    1017         wc.cbClsExtra        = 0;
    1018         wc.cbWndExtra        = 0;
    1019         wc.hInstance        = (HINSTANCE)qWinAppInst();
    1020         if (icon) {
    1021             wc.hIcon = LoadIcon(appInst, L"IDI_ICON1");
    1022             if (!wc.hIcon)
    1023                 wc.hIcon = LoadIcon(0, IDI_APPLICATION);
    1024         } else {
    1025             wc.hIcon = 0;
    1026         }
    1027         wc.hCursor        = 0;
    1028         wc.hbrBackground= bgBrush;
    1029         wc.lpszMenuName        = 0;
    1030         wc.lpszClassName= (TCHAR*)cname.utf16();
    1031         atom = RegisterClass(&wc);
    1032     } , {
    1033         WNDCLASSA wc;
    1034         wc.style        = style;
    1035         wc.lpfnWndProc        = (WNDPROC)QtWndProc;
    1036         wc.cbClsExtra        = 0;
    1037         wc.cbWndExtra        = 0;
    1038         wc.hInstance        = (HINSTANCE)qWinAppInst();
    1039         if (icon) {
    1040             wc.hIcon = LoadIconA(appInst, (char*)"IDI_ICON1");
    1041             if (!wc.hIcon)
    1042                 wc.hIcon = LoadIconA(0, (char*)IDI_APPLICATION);
    1043         } else {
    1044             wc.hIcon = 0;
    1045         }
    1046         wc.hCursor        = 0;
    1047         wc.hbrBackground= bgBrush;
    1048         wc.lpszMenuName        = 0;
    1049           QByteArray tempArray = cname.toLatin1();
    1050         wc.lpszClassName= tempArray;
    1051         atom = RegisterClassA(&wc);
    1052     });
     1007    WNDCLASS wc;
     1008    wc.style        = style;
     1009    wc.lpfnWndProc  = (WNDPROC)QtWndProc;
     1010    wc.cbClsExtra   = 0;
     1011    wc.cbWndExtra   = 0;
     1012    wc.hInstance    = qWinAppInst();
     1013    if (icon) {
     1014        wc.hIcon = (HICON)LoadImage(qWinAppInst(), L"IDI_ICON1", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
     1015#ifndef Q_WS_WINCE
     1016        if (!wc.hIcon)
     1017            wc.hIcon = (HICON)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
     1018#endif
     1019    } else {
     1020        wc.hIcon    = 0;
     1021    }
     1022    wc.hCursor      = 0;
     1023#ifndef Q_WS_WINCE
     1024    wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_WINDOW);
    10531025#else
    1054         WNDCLASS wc;
    1055         wc.style        = style;
    1056         wc.lpfnWndProc        = (WNDPROC)QtWndProc;
    1057         wc.cbClsExtra        = 0;
    1058         wc.cbWndExtra        = 0;
    1059         wc.hInstance        = (HINSTANCE)qWinAppInst();
    1060         if (icon) {
    1061             wc.hIcon = LoadIcon(appInst, L"IDI_ICON1");
    1062 //            if (!wc.hIcon)
    1063 //                wc.hIcon = LoadIcon(0, IDI_APPLICATION);
    1064         } else {
    1065             wc.hIcon = 0;
    1066         }
    1067         wc.hCursor        = 0;
    1068         wc.hbrBackground= 0;
    1069         wc.lpszMenuName        = 0;
    1070         wc.lpszClassName= (TCHAR*)cname.utf16();
    1071         atom = RegisterClass(&wc);
    1072 #endif
     1026    wc.hbrBackground = 0;
     1027#endif
     1028    wc.lpszMenuName  = 0;
     1029    wc.lpszClassName = (wchar_t*)cname.utf16();
     1030
     1031    ATOM atom = RegisterClass(&wc);
    10731032
    10741033#ifndef QT_NO_DEBUG
    10751034    if (!atom)
    10761035        qErrnoWarning("QApplication::regClass: Registering window class failed.");
     1036#else
     1037    Q_UNUSED(atom);
    10771038#endif
    10781039
     
    10921053    QHash<QString, int>::ConstIterator it = hash->constBegin();
    10931054    while (it != hash->constEnd()) {
    1094         QT_WA({
    1095             UnregisterClass((TCHAR*)it.key().utf16(), (HINSTANCE)qWinAppInst());
    1096         } , {
    1097             UnregisterClassA(it.key().toLatin1(), (HINSTANCE)qWinAppInst());
    1098         });
     1055        UnregisterClass((wchar_t*)it.key().utf16(), qWinAppInst());
    10991056        ++it;
    11001057    }
     
    11301087}
    11311088
    1132 Q_GUI_EXPORT void qWinProcessConfigRequests()                // perform requests in queue
     1089static void qWinProcessConfigRequests()                // perform requests in queue
    11331090{
    11341091    if (!configRequests)
     
    13131270static void alert_widget(QWidget *widget, int duration)
    13141271{
     1272#ifdef Q_OS_WINCE
     1273    Q_UNUSED(widget);
     1274    Q_UNUSED(duration);
     1275#else
    13151276    bool stopFlash = duration < 0;
    13161277
    1317     if (!pFlashWindowEx) {
    1318 #ifndef Q_OS_WINCE
    1319         QLibrary themeLib(QLatin1String("user32"));
    1320         pFlashWindowEx  = (PtrFlashWindowEx)themeLib.resolve("FlashWindowEx");
    1321 #endif
    1322     }
    1323 
    1324     if (pFlashWindowEx && widget && (!widget->isActiveWindow() || stopFlash)) {
     1278    if (widget && (!widget->isActiveWindow() || stopFlash)) {
    13251279        DWORD timeOut = GetCaretBlinkTime();
    13261280        if (timeOut <= 0)
     
    13401294        info.uCount = stopFlash ? 0 : flashCount;
    13411295
    1342         pFlashWindowEx(&info);
    1343     }
     1296        FlashWindowEx(&info);
     1297    }
     1298#endif
    13441299}
    13451300
     
    13721327extern uint qGlobalPostedEventsCount();
    13731328
    1374 /*!
    1375     \internal
    1376     \since 4.1
    1377 
    1378     If \a gotFocus is true, \a widget will become the active window.
    1379     Otherwise the active window is reset to 0.
    1380 */
    13811329void QApplication::winFocus(QWidget *widget, bool gotFocus)
    13821330{
     
    13891337            // raise the entire application, not just the dialog
    13901338            QWidget* mw = QApplicationPrivate::active_window;
    1391 #ifndef Q_OS_WINCE
     1339#ifndef Q_WS_WINCE
    13921340            while(mw->parentWidget() && (mw->windowType() == Qt::Dialog))
    13931341                mw = mw->parentWidget()->window();
     
    14361384static bool qt_is_translatable_mouse_event(UINT message)
    14371385{
    1438     return (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST ||
    1439                 message >= WM_XBUTTONDOWN && message <= WM_XBUTTONDBLCLK)
     1386    return (((message >= WM_MOUSEFIRST && message <= WM_MOUSELAST) ||
     1387                (message >= WM_XBUTTONDOWN && message <= WM_XBUTTONDBLCLK))
    14401388            && message != WM_MOUSEWHEEL
    1441 
    1442 #ifndef Q_OS_WINCE
    1443             || message >= WM_NCMOUSEMOVE && message <= WM_NCMBUTTONDBLCLK
     1389            && message != WM_MOUSEHWHEEL)
     1390
     1391#ifndef Q_WS_WINCE
     1392            || (message >= WM_NCMOUSEMOVE && message <= WM_NCMBUTTONDBLCLK)
    14441393#endif
    14451394            ;
     
    14801429    // If it's a non-client-area message the coords are screen coords, otherwise they are
    14811430    // client coords.
    1482 #ifndef Q_OS_WINCE
     1431#ifndef Q_WS_WINCE
    14831432    if (message < WM_NCMOUSEMOVE || message > WM_NCMBUTTONDBLCLK)
    14841433#endif
     
    15101459        && (message == WM_MBUTTONDOWN || message == WM_XBUTTONDOWN
    15111460        || message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN
    1512 #ifndef Q_OS_WINCE
     1461#ifndef Q_WS_WINCE
    15131462        || message == WM_NCMBUTTONDOWN || message == WM_NCLBUTTONDOWN
    15141463        || message == WM_NCRBUTTONDOWN)) {
     
    15201469
    15211470    switch (message) {
    1522 #ifndef Q_OS_WINCE
     1471#ifndef Q_WS_WINCE
    15231472    case WM_QUERYENDSESSION: {
    15241473        if (sm_smActive) // bogus message from windows
     
    15421491        // we receive the message for each toplevel window included internal hidden ones,
    15431492        // but the aboutToQuit signal should be emitted only once.
    1544         QApplicationPrivate *qAppPriv = getQApplicationPrivateInternal();
     1493        QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
    15451494        if (endsession && !qAppPriv->aboutToQuitEmitted) {
    15461495            qAppPriv->aboutToQuitEmitted = true;
     
    15481497            qApp->qt_metacall(QMetaObject::InvokeMetaMethod, index,0);
    15491498            // since the process will be killed immediately quit() has no real effect
    1550             qApp->quit();
     1499            QApplication::quit();
    15511500        }
    15521501
     
    15541503    }
    15551504    case WM_DISPLAYCHANGE:
    1556         if (qApp->type() == QApplication::Tty)
     1505        if (QApplication::type() == QApplication::Tty)
    15571506            break;
    15581507        if (qt_desktopWidget) {
     
    15711520
    15721521    case WM_SETTINGCHANGE:
    1573 #ifdef Q_OS_WINCE
     1522#ifdef Q_WS_WINCE
    15741523        // CE SIP hide/show
    15751524        if (wParam == SPI_SETSIPINFO) {
     
    15801529#endif
    15811530        // ignore spurious XP message when user logs in again after locking
    1582         if (qApp->type() == QApplication::Tty)
     1531        if (QApplication::type() == QApplication::Tty)
    15831532            break;
    15841533        if (QApplication::desktopSettingsAware() && wParam != SPI_SETWORKAREA) {
     
    16031552        if (wParam == SPI_SETFONTSMOOTHINGTYPE) {
    16041553            qt_win_read_cleartype_settings();
    1605             foreach (QWidget *w, qApp->topLevelWidgets()) {
     1554            foreach (QWidget *w, QApplication::topLevelWidgets()) {
    16061555                if (!w->isVisible())
    16071556                    continue;
     
    16121561        break;
    16131562    case WM_SYSCOLORCHANGE:
    1614         if (qApp->type() == QApplication::Tty)
     1563        if (QApplication::type() == QApplication::Tty)
    16151564            break;
    16161565        if (QApplication::desktopSettingsAware()) {
     
    16641613
    16651614    if (qt_is_translatable_mouse_event(message)) {
    1666         if (qApp->activePopupWidget() != 0) { // in popup mode
     1615        if (QApplication::activePopupWidget() != 0) { // in popup mode
    16671616            POINT curPos = msg.pt;
    16681617            QWidget* w = QApplication::widgetAt(curPos.x, curPos.y);
     
    16731622        if (!qt_tabletChokeMouse) {
    16741623            result = widget->translateMouseEvent(msg);        // mouse event
    1675 #if defined(Q_OS_WINCE) && !defined(QT_NO_CONTEXTMENU)
    1676             if (message == WM_LBUTTONDOWN && widget != qApp->activePopupWidget()) {
     1624#if defined(Q_WS_WINCE) && !defined(QT_NO_CONTEXTMENU)
     1625            if (message == WM_LBUTTONDOWN && widget != QApplication::activePopupWidget()) {
    16771626                QWidget* alienWidget = widget;
    1678                 if ((alienWidget != qApp->activePopupWidget()) && (alienWidget->contextMenuPolicy() != Qt::PreventContextMenu)) {
     1627                if ((alienWidget != QApplication::activePopupWidget()) && (alienWidget->contextMenuPolicy() != Qt::PreventContextMenu)) {
    16791628                    QPoint pos(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
    16801629                    QPoint globalPos(msg.pt.x, msg.pt.y);
     
    16831632                    if (!alienWidget->testAttribute(Qt::WA_NativeWindow) && !alienWidget->testAttribute(Qt::WA_PaintOnScreen)) {
    16841633                        alienWidget = QApplication::widgetAt(globalPos);
    1685                         pos = alienWidget->mapFromGlobal(globalPos);
     1634                        if (alienWidget)
     1635                            pos = alienWidget->mapFromGlobal(globalPos);
    16861636                    }
    1687                     SHRGINFO shrg;
    1688                     shrg.cbSize = sizeof(shrg);
    1689                     shrg.hwndClient = hwnd;
    1690                     shrg.ptDown.x = GET_X_LPARAM(lParam);
    1691                     shrg.ptDown.y = GET_Y_LPARAM(lParam);
    1692                     shrg.dwFlags = SHRG_RETURNCMD | SHRG_NOANIMATION;
    1693                     resolveAygLibs();
    1694                     if (ptrRecognizeGesture && (ptrRecognizeGesture(&shrg) == GN_CONTEXTMENU)) {
    1695                         if (qApp->activePopupWidget())
    1696                             qApp->activePopupWidget()->close();
    1697                         QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos);
    1698                         result = qt_sendSpontaneousEvent(alienWidget, &e);
     1637                    if (alienWidget) {
     1638                        SHRGINFO shrg;
     1639                        shrg.cbSize = sizeof(shrg);
     1640                        shrg.hwndClient = hwnd;
     1641                        shrg.ptDown.x = GET_X_LPARAM(lParam);
     1642                        shrg.ptDown.y = GET_Y_LPARAM(lParam);
     1643                        shrg.dwFlags = SHRG_RETURNCMD | SHRG_NOANIMATION;
     1644                        resolveAygLibs();
     1645                        if (ptrRecognizeGesture && (ptrRecognizeGesture(&shrg) == GN_CONTEXTMENU)) {
     1646                            if (QApplication::activePopupWidget())
     1647                                QApplication::activePopupWidget()->close();
     1648                            QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos);
     1649                            result = qt_sendSpontaneousEvent(alienWidget, &e);
     1650                        }
    16991651                    }
    17001652                }
     
    17051657            // and sometimes we get both a WM_MOUSEMOVE and
    17061658            // a WM_LBUTTONDOWN/UP, this creates a spurious mouse
    1707             // press/release event, using the winPeekMessage
     1659            // press/release event, using the PeekMessage
    17081660            // will help us fix this.  This leaves us with a
    17091661            // question:
     
    17151667            if (is_mouse_move) {
    17161668                MSG msg1;
    1717                 if (winPeekMessage(&msg1, msg.hwnd, WM_MOUSEFIRST,
    1718                                     WM_MOUSELAST, PM_NOREMOVE))
     1669                if (PeekMessage(&msg1, msg.hwnd, WM_MOUSEFIRST,
     1670                                WM_MOUSELAST, PM_NOREMOVE))
    17191671                    next_is_button = (msg1.message == WM_LBUTTONUP
    17201672                                       || msg1.message == WM_LBUTTONDOWN);
     
    17231675                qt_tabletChokeMouse = false;
    17241676        }
    1725     } else if (message == WM95_MOUSEWHEEL) {
    1726         result = widget->translateWheelEvent(msg);
    17271677    } else {
    17281678        switch (message) {
     1679        case WM_TOUCH:
     1680            result = QApplicationPrivate::instance()->translateTouchEvent(msg);
     1681            break;
    17291682        case WM_KEYDOWN:                        // keyboard event
    17301683        case WM_SYSKEYDOWN:
     
    17331686        case WM_KEYUP:
    17341687        case WM_SYSKEYUP:
     1688#if Q_OS_WINCE_WM
     1689        case WM_HOTKEY:
     1690            if(HIWORD(msg.lParam) == VK_TBACK) {
     1691                const bool hotKeyDown = !(LOWORD(msg.lParam) & MOD_KEYUP);
     1692                msg.lParam = 0x69 << 16;
     1693                msg.wParam = VK_BACK;
     1694                if (hotKeyDown) {
     1695                    msg.message = WM_KEYDOWN;
     1696                    qt_keymapper_private()->updateKeyMap(msg);
     1697                } else {
     1698                    msg.message = WM_KEYUP;
     1699                }
     1700            }
     1701            // fall-through intended
     1702#endif
    17351703        case WM_IME_CHAR:
    17361704        case WM_IME_KEYDOWN:
    17371705        case WM_CHAR: {
    17381706            MSG msg1;
    1739             bool anyMsg = winPeekMessage(&msg1, msg.hwnd, 0, 0, PM_NOREMOVE);
     1707            bool anyMsg = PeekMessage(&msg1, msg.hwnd, 0, 0, PM_NOREMOVE);
    17401708            if (anyMsg && msg1.message == WM_DEADCHAR) {
    17411709                result = true; // consume event since there is a dead char next
     
    17561724                       ? (QETWidget*)QApplication::activePopupWidget()->focusWidget()
    17571725                       : (QETWidget*)QApplication::activePopupWidget();
    1758             else if (qApp->focusWidget())
     1726            else if (QApplication::focusWidget())
    17591727                widget = (QETWidget*)QApplication::focusWidget();
    17601728            else if (!widget || widget->internalWinId() == GetFocus()) // We faked the message to go to exactly that widget.
     
    17711739
    17721740        case WM_MOUSEWHEEL:
     1741        case WM_MOUSEHWHEEL:
    17731742            result = widget->translateWheelEvent(msg);
    17741743            break;
     
    17971766                            key = Qt::Key_BassUp;
    17981767                            break;
    1799                         case APPCOMMAND_BROWSER_BACKWARD:
    1800                             key = Qt::Key_Back;
    1801                             break;
    1802                         case APPCOMMAND_BROWSER_FAVORITES:
    1803                             key = Qt::Key_Favorites;
    1804                             break;
    1805                         case APPCOMMAND_BROWSER_FORWARD:
    1806                             key = Qt::Key_Forward;
    1807                             break;
    1808                         case APPCOMMAND_BROWSER_HOME:
    1809                             key = Qt::Key_HomePage;
    1810                             break;
    1811                         case APPCOMMAND_BROWSER_REFRESH:
    1812                             key = Qt::Key_Refresh;
    1813                             break;
    1814                         case APPCOMMAND_BROWSER_SEARCH:
    1815                             key = Qt::Key_Search;
    1816                             break;
    1817                         case APPCOMMAND_BROWSER_STOP:
    1818                             key = Qt::Key_Stop;
    1819                             break;
    1820                         case APPCOMMAND_LAUNCH_APP1:
    1821                             key = Qt::Key_Launch0;
    1822                             break;
    1823                         case APPCOMMAND_LAUNCH_APP2:
    1824                             key = Qt::Key_Launch1;
    1825                             break;
    1826                         case APPCOMMAND_LAUNCH_MAIL:
    1827                             key = Qt::Key_LaunchMail;
    1828                             break;
    1829                         case APPCOMMAND_LAUNCH_MEDIA_SELECT:
    1830                             key = Qt::Key_LaunchMedia;
    1831                             break;
    1832                         case APPCOMMAND_MEDIA_NEXTTRACK:
    1833                             key = Qt::Key_MediaNext;
    1834                             break;
    1835                         case APPCOMMAND_MEDIA_PLAY_PAUSE:
    1836                             key = Qt::Key_MediaPlay;
    1837                             break;
    1838                         case APPCOMMAND_MEDIA_PREVIOUSTRACK:
    1839                             key = Qt::Key_MediaPrevious;
    1840                             break;
    1841                         case APPCOMMAND_MEDIA_STOP:
    1842                             key = Qt::Key_MediaStop;
    1843                             break;
    18441768                        case APPCOMMAND_TREBLE_DOWN:
    18451769                            key = Qt::Key_TrebleDown;
     
    18481772                            key = Qt::Key_TrebleUp;
    18491773                            break;
    1850                         case APPCOMMAND_VOLUME_DOWN:
    1851                             key = Qt::Key_VolumeDown;
    1852                             break;
    1853                         case APPCOMMAND_VOLUME_MUTE:
    1854                             key = Qt::Key_VolumeMute;
    1855                             break;
    1856                         case APPCOMMAND_VOLUME_UP:
    1857                             key = Qt::Key_VolumeUp;
    1858                             break;
    1859                         // Commands new in Windows XP
    18601774                        case APPCOMMAND_HELP:
    18611775                            key = Qt::Key_Help;
     
    18631777                        case APPCOMMAND_FIND:
    18641778                            key = Qt::Key_Search;
    1865                             break;
    1866                         case APPCOMMAND_PRINT:
    1867                             key = Qt::Key_Print;
    1868                             break;
    1869                         case APPCOMMAND_MEDIA_PLAY:
    1870                             key = Qt::Key_MediaPlay;
    18711779                            break;
    18721780                        default:
     
    18781786                            if (g)
    18791787                                widget = (QETWidget*)g;
    1880                             else if (qApp->focusWidget())
    1881                                 widget = (QETWidget*)qApp->focusWidget();
     1788                            else if (QApplication::focusWidget())
     1789                                widget = (QETWidget*)QApplication::focusWidget();
    18821790                            else
    18831791                                widget = (QETWidget*)widget->window();
     
    19011809            break;
    19021810
    1903 #ifndef Q_OS_WINCE
     1811#ifndef Q_WS_WINCE
    19041812        case WM_NCHITTEST:
    19051813            if (widget->isWindow()) {
     
    19081816                QRect fs = widget->frameStrut();
    19091817                if (!widget->isMinimized()) {
     1818                    if (widget->minimumHeight() == widget->maximumHeight()) {
     1819                        if (pos.y() < -(fs.top() - fs.left()))
     1820                            return HTCAPTION;
     1821                        if (pos.y() >= widget->height())
     1822                            return HTBORDER;
     1823                    }
    19101824                    if (widget->minimumWidth() == widget->maximumWidth() && (pos.x() < 0 || pos.x() >= widget->width()))
    1911                         break;
    1912                     if (widget->minimumHeight() == widget->maximumHeight() && (pos.y() < -(fs.top() - fs.left()) || pos.y() >= widget->height()))
    1913                         break;
     1825                        return HTBORDER;
    19141826                }
    19151827            }
     
    19201832
    19211833        case WM_SYSCOMMAND: {
    1922 #ifndef Q_OS_WINCE
     1834#ifndef Q_WS_WINCE
    19231835            bool window_state_change = false;
    19241836            Qt::WindowStates oldstate = Qt::WindowStates(widget->dataPtr()->window_state);
     
    19321844                QWhatsThis::enterWhatsThisMode();
    19331845#endif
    1934                 QT_WA({
    1935                     DefWindowProc(hwnd, WM_NCPAINT, 1, 0);
    1936                 } , {
    1937                     DefWindowProcA(hwnd, WM_NCPAINT, 1, 0);
    1938                 });
     1846                DefWindowProc(hwnd, WM_NCPAINT, 1, 0);
    19391847                break;
    19401848#if defined(QT_NON_COMMERCIAL)
     
    19481856                    qt_sendSpontaneousEvent(widget, &e);
    19491857                    widget->hideChildren(true);
    1950 #ifndef Q_OS_WINCE
    19511858                    const QString title = widget->windowIconText();
    19521859                    if (!title.isEmpty())
    19531860                        widget->setWindowTitle_helper(title);
    1954 #endif
    19551861                }
    19561862                result = false;
     
    19711877                    QShowEvent e;
    19721878                    qt_sendSpontaneousEvent(widget, &e);
    1973 #ifndef Q_OS_WINCE
    19741879                    const QString title = widget->windowTitle();
    19751880                    if (!title.isEmpty())
    19761881                        widget->setWindowTitle_helper(title);
    1977 #endif
    19781882                }
    19791883                result = false;
     
    19881892                qt_sendSpontaneousEvent(widget, &e);
    19891893            }
    1990 #endif
     1894#endif // #ifndef Q_OS_WINCE
    19911895
    19921896            break;
     
    19941898
    19951899        case WM_SETTINGCHANGE:
    1996             if ( qApp->type() == QApplication::Tty )
     1900            if ( QApplication::type() == QApplication::Tty )
    19971901                break;
    19981902
    19991903            if (!msg.wParam) {
    2000                 QString area = QT_WA_INLINE(QString::fromUtf16((unsigned short *)msg.lParam),
    2001                                              QString::fromLocal8Bit((char*)msg.lParam));
     1904                QString area = QString::fromWCharArray((wchar_t*)msg.lParam);
    20021905                if (area == QLatin1String("intl")) {
    20031906                    QLocalePrivate::updateSystemPrivate();
     
    20071910            }
    20081911            else if (msg.wParam == SPI_SETICONTITLELOGFONT) {
    2009                 if (qApp->desktopSettingsAware()) {
     1912                if (QApplication::desktopSettingsAware()) {
    20101913                    widget = (QETWidget*)QWidget::find(hwnd);
    20111914                    if (widget && !widget->parentWidget()) {
     
    20211924            break;
    20221925
    2023 #ifndef Q_OS_WINCE
     1926#ifndef Q_WS_WINCE
    20241927        case WM_ENTERSIZEMOVE:
    20251928            autoCaptureWnd = hwnd;
    2026             QApplicationPrivate::inSizeMove = true;
    20271929            break;
    20281930        case WM_EXITSIZEMOVE:
    20291931            autoCaptureWnd = 0;
    2030             QApplicationPrivate::inSizeMove = false;
    20311932            break;
    20321933#endif
     
    20501951
    20511952        case WM_ACTIVATE:
    2052             if ( qApp->type() == QApplication::Tty )
     1953            if ( QApplication::type() == QApplication::Tty )
    20531954                break;
    20541955
     
    20761977                // loses focus. Doing it here would result in the widget getting focus to not know
    20771978                // where it got it from; it would simply get a 0 value as the old focus widget.
     1979#ifdef Q_WS_WINCE
     1980                {
     1981#ifdef Q_WS_WINCE_WM
     1982                    // On Windows mobile we do not receive WM_SYSCOMMAND / SC_MINIMIZE messages.
     1983                    // Thus we have to unset the minimized state explicitly. We must do this for all
     1984                    // top-level widgets, because we get the HWND of a random widget here.
     1985                    foreach (QWidget* tlw, QApplication::topLevelWidgets()) {
     1986                        if (tlw->isMinimized())
     1987                            tlw->setWindowState(tlw->windowState() & ~Qt::WindowMinimized);
     1988                    }
     1989#else
     1990                    // On Windows CE we do not receive WM_SYSCOMMAND / SC_MINIMIZE messages.
     1991                    // Thus we have to unset the minimized state explicitly.
     1992                    if (widget->windowState() & Qt::WindowMinimized)
     1993                        widget->setWindowState(widget->windowState() & ~Qt::WindowMinimized);
     1994#endif  // Q_WS_WINCE_WM
     1995
     1996#else
    20781997                if (!(widget->windowState() & Qt::WindowMinimized)) {
     1998#endif
    20791999                    // Ignore the activate message send by WindowsXP to a minimized window
    2080 #ifdef Q_OS_WINCE_WM
     2000#ifdef Q_WS_WINCE_WM
    20812001                    if  (widget->windowState() & Qt::WindowFullScreen)
    20822002                        qt_wince_hide_taskbar(widget->winId());
     
    21052025            break;
    21062026
    2107 #ifndef Q_OS_WINCE
     2027#ifndef Q_WS_WINCE
    21082028            case WM_MOUSEACTIVATE:
    21092029                if (widget->window()->windowType() == Qt::Tool) {
     
    21942114            break;
    21952115
    2196 #ifndef Q_OS_WINCE
     2116#ifndef Q_WS_WINCE
    21972117        case WM_WINDOWPOSCHANGING:
    21982118            {
     
    22752195                QWidget *fw = QWidget::keyboardGrabber();
    22762196                if (!fw) {
    2277                     if (qApp->activePopupWidget())
    2278                         fw = (qApp->activePopupWidget()->focusWidget()
    2279                                                   ? qApp->activePopupWidget()->focusWidget()
    2280                                                   : qApp->activePopupWidget());
    2281                     else if (qApp->focusWidget())
    2282                         fw = qApp->focusWidget();
     2197                    if (QApplication::activePopupWidget())
     2198                        fw = (QApplication::activePopupWidget()->focusWidget()
     2199                                                  ? QApplication::activePopupWidget()->focusWidget()
     2200                                                  : QApplication::activePopupWidget());
     2201                    else if (QApplication::focusWidget())
     2202                        fw = QApplication::focusWidget();
    22832203                    else if (widget)
    22842204                        fw = widget->window();
     
    22972217        case WM_IME_ENDCOMPOSITION:
    22982218        case WM_IME_COMPOSITION: {
    2299             QWidget *fw = qApp->focusWidget();
     2219            QWidget *fw = QApplication::focusWidget();
    23002220            QWinInputContext *im = fw ? qobject_cast<QWinInputContext *>(fw->inputContext()) : 0;
    23012221            if (fw && im) {
     
    23092229            break;
    23102230        }
    2311 
    2312 #ifndef Q_OS_WINCE
     2231        case WM_IME_REQUEST: {
     2232            QWidget *fw = QApplication::focusWidget();
     2233            QWinInputContext *im = fw ? qobject_cast<QWinInputContext *>(fw->inputContext()) : 0;
     2234            if (fw && im) {
     2235                if(wParam == IMR_RECONVERTSTRING) {
     2236                    int ret = im->reconvertString((RECONVERTSTRING *)lParam);
     2237                    if (ret == -1) {
     2238                        result = false;
     2239                    } else {
     2240                        return ret;
     2241                    }
     2242                } else if (wParam == IMR_CONFIRMRECONVERTSTRING) {
     2243                    RETURN(TRUE);
     2244                } else {
     2245                    // in all other cases, call DefWindowProc()
     2246                    result = false;
     2247                }
     2248            }
     2249            break;
     2250        }
     2251#ifndef Q_WS_WINCE
    23132252        case WM_CHANGECBCHAIN:
    23142253        case WM_DRAWCLIPBOARD:
     
    23302269            {
    23312270                // Ignoring all requests while starting up
    2332                 if (qApp->startingUp() || qApp->closingDown() || (DWORD)lParam != OBJID_CLIENT) {
     2271                if (QApplication::startingUp() || QApplication::closingDown() || (DWORD)lParam != OBJID_CLIENT) {
    23332272                    result = false;
    23342273                    break;
     
    23732312                    ret = qMin<int>(wParam - 1, text.size());
    23742313                    text.resize(ret);
    2375                     QT_WA({
    2376                         memcpy((void *)lParam, text.utf16(), (text.size() + 1) * 2);
    2377                     }, {
    2378                         memcpy((void *)lParam, text.toLocal8Bit().data(), text.size() + 1);
    2379                     });
     2314                    memcpy((void *)lParam, text.utf16(), (text.size() + 1) * sizeof(ushort));
    23802315                    delete acc;
    23812316                }
     
    23972332            break;
    23982333        case WT_PROXIMITY:
    2399             if (ptrWTPacketsGet) {
    2400                 bool enteredProximity = LOWORD(lParam) != 0;
    2401                 PACKET proximityBuffer[QT_TABLET_NPACKETQSIZE];
    2402                 int totalPacks = ptrWTPacketsGet(qt_tablet_context, QT_TABLET_NPACKETQSIZE, proximityBuffer);
    2403                 if (totalPacks > 0 && enteredProximity) {
    2404                     uint currentCursor = proximityBuffer[0].pkCursor;
    2405                     if (!tCursorInfo()->contains(currentCursor))
    2406                         tabletInit(currentCursor, qt_tablet_context);
    2407                     currentTabletPointer = tCursorInfo()->value(currentCursor);
     2334
     2335            #ifndef QT_NO_TABLETEVENT
     2336            if (ptrWTPacketsGet && ptrWTInfo) {
     2337                const bool enteredProximity = LOWORD(lParam) != 0;
     2338                PACKET proximityBuffer[1]; // we are only interested in the first packet in this case
     2339                const int totalPacks = ptrWTPacketsGet(qt_tablet_context, 1, proximityBuffer);
     2340                if (totalPacks > 0) {
     2341                    const UINT currentCursor = proximityBuffer[0].pkCursor;
     2342
     2343                    UINT csr_physid;
     2344                    ptrWTInfo(WTI_CURSORS + currentCursor, CSR_PHYSID, &csr_physid);
     2345                    UINT csr_type;
     2346                    ptrWTInfo(WTI_CURSORS + currentCursor, CSR_TYPE, &csr_type);
     2347                    const UINT deviceIdMask = 0xFF6; // device type mask && device color mask
     2348                    quint64 uniqueId = (csr_type & deviceIdMask);
     2349                    uniqueId = (uniqueId << 32) | csr_physid;
     2350
     2351                    // initialising and updating the cursor should be done in response to
     2352                    // WT_CSRCHANGE. We do it in WT_PROXIMITY because some wintab never send
     2353                    // the event WT_CSRCHANGE even if asked with CXO_CSRMESSAGES
     2354                    const QTabletCursorInfo *const globalCursorInfo = tCursorInfo();
     2355                    if (!globalCursorInfo->contains(uniqueId))
     2356                        tabletInit(uniqueId, csr_type, qt_tablet_context);
     2357
     2358                    currentTabletPointer = globalCursorInfo->value(uniqueId);
     2359                    tabletUpdateCursor(currentTabletPointer, currentCursor);
    24082360                }
    24092361                qt_tabletChokeMouse = false;
    2410 #ifndef QT_NO_TABLETEVENT
     2362
    24112363                QTabletEvent tabletProximity(enteredProximity ? QEvent::TabletEnterProximity
    24122364                                                              : QEvent::TabletLeaveProximity,
     
    24142366                                             0, 0, 0, 0, 0, currentTabletPointer.llId);
    24152367                QApplication::sendEvent(qApp, &tabletProximity);
    2416 #endif // QT_NO_TABLETEVENT
    2417             }
    2418             break;
    2419 #ifdef Q_OS_WINCE_WM
     2368            }
     2369            #endif // QT_NO_TABLETEVENT
     2370
     2371            break;
     2372#ifdef Q_WS_WINCE_WM
    24202373        case WM_SETFOCUS: {
    24212374            HIMC hC;
     
    24302383            if (!QWidget::find((HWND)wParam)) { // we don't get focus, so unset it now
    24312384                if (!widget->hasFocus()) // work around Windows bug after minimizing/restoring
    2432                     widget = (QETWidget*)qApp->focusWidget();
     2385                    widget = (QETWidget*)QApplication::focusWidget();
    24332386                HWND focus = ::GetFocus();
    24342387                //if there is a current widget and the new widget belongs to the same toplevel window
     2388                //or if the current widget was embedded into non-qt window (i.e. we won't get WM_ACTIVATEAPP)
    24352389                //then we clear the focus on the widget
    24362390                //in case the new widget belongs to a different widget hierarchy, clearing the focus
    24372391                //will be handled because the active window will change
    2438                 if (widget && ::IsChild(widget->window()->internalWinId(), focus)) {
     2392                const bool embedded = widget && ((QETWidget*)widget->window())->topData()->embedded;
     2393                if (widget && (embedded || ::IsChild(widget->window()->internalWinId(), focus))) {
    24392394                    widget->clearFocus();
    24402395                    result = true;
     
    24472402            break;
    24482403        case WM_THEMECHANGED:
    2449             if ((widget->windowType() == Qt::Desktop) || !qApp || qApp->closingDown()
    2450                                                          || qApp->type() == QApplication::Tty)
     2404            if ((widget->windowType() == Qt::Desktop) || !qApp || QApplication::closingDown()
     2405                                                         || QApplication::type() == QApplication::Tty)
    24512406                break;
    24522407
    24532408            if (widget->testAttribute(Qt::WA_WState_Polished))
    2454                 qApp->style()->unpolish(widget);
     2409                QApplication::style()->unpolish(widget);
    24552410
    24562411            if (widget->testAttribute(Qt::WA_WState_Polished))
    2457                 qApp->style()->polish(widget);
    2458             widget->repolishStyle(*qApp->style());
     2412                QApplication::style()->polish(widget);
     2413            widget->repolishStyle(*QApplication::style());
    24592414            if (widget->isVisible())
    24602415                widget->update();
    24612416            break;
    24622417
    2463 #ifndef Q_OS_WINCE
     2418#ifndef Q_WS_WINCE
    24642419        case WM_INPUTLANGCHANGE: {
    2465             char info[7];
    2466             if (!GetLocaleInfoA(MAKELCID(lParam, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, info, 6)) {
     2420            wchar_t info[7];
     2421            if (!GetLocaleInfo(MAKELCID(lParam, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, info, 6)) {
    24672422                inputcharset = CP_ACP;
    24682423            } else {
    2469                 inputcharset = QString::fromLatin1(info).toInt();
     2424                inputcharset = QString::fromWCharArray(info).toInt();
    24702425            }
    24712426            QKeyMapper::changeKeyboard();
     
    25612516            result = false;
    25622517            break;
     2518        case WM_GESTURE: {
     2519            GESTUREINFO gi;
     2520            memset(&gi, 0, sizeof(GESTUREINFO));
     2521            gi.cbSize = sizeof(GESTUREINFO);
     2522
     2523            QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
     2524            BOOL bResult = false;
     2525            if (qAppPriv->GetGestureInfo)
     2526                bResult = qAppPriv->GetGestureInfo((HANDLE)msg.lParam, &gi);
     2527            if (bResult) {
     2528                if (gi.dwID == GID_BEGIN) {
     2529                    // find the alien widget for the gesture position.
     2530                    // This might not be accurate as the position is the center
     2531                    // point of two fingers for multi-finger gestures.
     2532                    QPoint pt(gi.ptsLocation.x, gi.ptsLocation.y);
     2533                    QWidget *w = widget->childAt(widget->mapFromGlobal(pt));
     2534                    qAppPriv->gestureWidget = w ? w : widget;
     2535                }
     2536                if (qAppPriv->gestureWidget)
     2537                    static_cast<QETWidget*>(qAppPriv->gestureWidget)->translateGestureEvent(msg, gi);
     2538                if (qAppPriv->CloseGestureInfoHandle)
     2539                    qAppPriv->CloseGestureInfoHandle((HANDLE)msg.lParam);
     2540                if (gi.dwID == GID_END)
     2541                    qAppPriv->gestureWidget = 0;
     2542            } else {
     2543                DWORD dwErr = GetLastError();
     2544                if (dwErr > 0)
     2545                    qWarning() << "translateGestureEvent: error = " << dwErr;
     2546            }
     2547            result = true;
     2548            break;
     2549        }
    25632550        default:
    25642551            result = false;                        // event was not processed
     
    26592646
    26602647    bool block_event = false;
    2661 #ifndef Q_OS_WINCE
    2662     if (type != WM_NCHITTEST)
     2648#ifndef Q_WS_WINCE
     2649    if (type != WM_NCHITTEST) {
    26632650#endif
    26642651        if ((type >= WM_MOUSEFIRST && type <= WM_MOUSELAST) ||
    2665              type == WM_MOUSEWHEEL || type == (int)WM95_MOUSEWHEEL ||
     2652             type == WM_MOUSEWHEEL || type == WM_MOUSEHWHEEL ||
    26662653             type == WM_MOUSELEAVE ||
    26672654             (type >= WM_KEYFIRST && type <= WM_KEYLAST)
    2668 #ifndef Q_OS_WINCE
     2655#ifndef Q_WS_WINCE
    26692656            || type == WM_NCMOUSEMOVE
    26702657#endif
    26712658         ) {
    26722659            if (type == WM_MOUSEMOVE
    2673 #ifndef Q_OS_WINCE
     2660#ifndef Q_WS_WINCE
    26742661                 || type == WM_NCMOUSEMOVE
    26752662#endif
     
    26892676            block_event = true;
    26902677        }
    2691 #ifndef Q_OS_WINCE
    2692     else if (type == WM_MOUSEACTIVATE || type == WM_NCLBUTTONDOWN){
    2693         if (!top->isActiveWindow()) {
    2694             top->activateWindow();
    2695         } else {
    2696             QApplication::beep();
    2697         }
    2698         block_event = true;
    2699         ret = MA_NOACTIVATEANDEAT;
    2700     } else if (type == WM_SYSCOMMAND) {
    2701         if (!(msg->wParam == SC_RESTORE && widget->isMinimized()))
     2678#ifndef Q_WS_WINCE
     2679        else if (type == WM_MOUSEACTIVATE || type == WM_NCLBUTTONDOWN){
     2680            if (!top->isActiveWindow()) {
     2681                top->activateWindow();
     2682            } else {
     2683                QApplication::beep();
     2684            }
    27022685            block_event = true;
     2686            ret = MA_NOACTIVATEANDEAT;
     2687        } else if (type == WM_SYSCOMMAND) {
     2688            if (!(msg->wParam == SC_RESTORE && widget->isMinimized()))
     2689                block_event = true;
     2690        }
    27032691    }
    27042692#endif
     
    27442732        popup->focusWidget()->setFocus(Qt::PopupFocusReason);
    27452733    } else if (QApplicationPrivate::popupWidgets->count() == 1) { // this was the first popup
    2746         if (QWidget *fw = q_func()->focusWidget()) {
     2734        if (QWidget *fw = QApplication::focusWidget()) {
    27472735            QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason);
    2748             q_func()->sendEvent(fw, &e);
     2736            QApplication::sendEvent(fw, &e);
    27492737        }
    27502738    }
     
    27732761            releaseAutoCapture();
    27742762        QWidget *fw = QApplicationPrivate::active_window ? QApplicationPrivate::active_window->focusWidget()
    2775             : q_func()->focusWidget();
     2763            : QApplication::focusWidget();
    27762764        if (fw) {
    2777             if (fw != q_func()->focusWidget()) {
     2765            if (fw != QApplication::focusWidget()) {
    27782766                fw->setFocus(Qt::PopupFocusReason);
    27792767            } else {
    27802768                QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason);
    2781                 q_func()->sendEvent(fw, &e);
     2769                QApplication::sendEvent(fw, &e);
    27822770            }
    27832771        }
     
    28472835    WM_XBUTTONDBLCLK,    QEvent::MouseButtonDblClick,     Qt::XButton1,
    28482836
    2849 #ifndef Q_OS_WINCE
     2837#ifndef Q_WS_WINCE
    28502838    WM_NCMOUSEMOVE,      QEvent::NonClientAreaMouseMove,           0,
    28512839    WM_NCLBUTTONDOWN,    QEvent::NonClientAreaMouseButtonPress,    Qt::LeftButton,
     
    29022890    // reset button state
    29032891
    2904     MSG msg = {0, 0, 0, 0, 0, 0, 0};
    2905     QT_WA( {
    2906         while (PeekMessage(&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
    2907             ;
    2908         if (msg.message == WM_MOUSEMOVE)
    2909             PostMessage(msg.hwnd, msg.message, 0, msg.lParam);
    2910     }, {
    2911         MSG msg;
    2912         msg.message = 0;
    2913         while (PeekMessageA(&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
    2914             ;
    2915         if (msg.message == WM_MOUSEMOVE)
    2916             PostMessageA(msg.hwnd, msg.message, 0, msg.lParam);
    2917     } );
     2892    MSG msg = {0, 0, 0, 0, 0, {0, 0} };
     2893    while (PeekMessage(&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
     2894        ;
     2895    if (msg.message == WM_MOUSEMOVE)
     2896        PostMessage(msg.hwnd, msg.message, 0, msg.lParam);
    29182897}
    29192898
    29202899// In DnD, the mouse release event never appears, so the
    29212900// mouse button state machine must be manually reset
    2922 /*! \internal */
    29232901void QApplication::winMouseButtonUp()
    29242902{
     
    29512929    if (msg.message == WM_MOUSEMOVE) {
    29522930        MSG mouseMsg;
    2953         while (winPeekMessage(&mouseMsg, msg.hwnd, WM_MOUSEFIRST,
    2954                 WM_MOUSELAST, PM_NOREMOVE)) {
     2931        while (PeekMessage(&mouseMsg, msg.hwnd, WM_MOUSEFIRST,
     2932               WM_MOUSELAST, PM_NOREMOVE)) {
    29552933            if (mouseMsg.message == WM_MOUSEMOVE) {
    29562934#define PEEKMESSAGE_IS_BROKEN 1
     
    29632941                MSG keyMsg;
    29642942                bool done = false;
    2965                 while (winPeekMessage(&keyMsg, 0, WM_KEYFIRST, WM_KEYLAST,
    2966                         PM_NOREMOVE)) {
     2943                while (PeekMessage(&keyMsg, 0, WM_KEYFIRST, WM_KEYLAST,
     2944                       PM_NOREMOVE)) {
    29672945                    if (keyMsg.time < mouseMsg.time) {
    29682946                        if ((keyMsg.lParam & 0xC0000000) == 0x40000000) {
    2969                             winPeekMessage(&keyMsg, 0, keyMsg.message,
    2970                                             keyMsg.message, PM_REMOVE);
     2947                            PeekMessage(&keyMsg, 0, keyMsg.message,
     2948                                        keyMsg.message, PM_REMOVE);
    29712949                        } else {
    29722950                            done = true;
     
    29942972                msgPtr->pt = mouseMsg.pt;
    29952973                // Remove the mouse move message
    2996                 winPeekMessage(&mouseMsg, msg.hwnd, WM_MOUSEMOVE,
    2997                                 WM_MOUSEMOVE, PM_REMOVE);
     2974                PeekMessage(&mouseMsg, msg.hwnd, WM_MOUSEMOVE,
     2975                            WM_MOUSEMOVE, PM_REMOVE);
    29982976            } else {
    29992977                break; // there was no more WM_MOUSEMOVE event
     
    30243002        alienWidget = 0;
    30253003
    3026     if (type == QEvent::MouseMove || type == QEvent::NonClientAreaMouseMove) {
     3004    if (type == QEvent::MouseMove || type == QEvent::NonClientAreaMouseMove
     3005            || type == QEvent::TabletMove) {
     3006
    30273007        if (!(state & Qt::MouseButtonMask))
    30283008            qt_button_down = 0;
     
    30443024        HWND id = effectiveWinId();
    30453025        QWidget *mouseGrabber = QWidget::mouseGrabber();
    3046         QWidget *activePopupWidget = qApp->activePopupWidget();
     3026        QWidget *activePopupWidget = QApplication::activePopupWidget();
    30473027        if (mouseGrabber) {
    30483028            if (!activePopupWidget || (activePopupWidget == this && !rect().contains(widgetPos)))
     
    31373117
    31383118        replayPopupMouseEvent = false;
    3139         QWidget* activePopupWidget = qApp->activePopupWidget();
     3119        QWidget* activePopupWidget = QApplication::activePopupWidget();
    31403120        QWidget *target = activePopupWidget;
    31413121        const QPoint globalPos(gpos.x, gpos.y);
     
    31553135                break;
    31563136            case QEvent::MouseButtonRelease:
     3137            case QEvent::TabletRelease:
     3138
    31573139                releaseAfter = true;
    31583140                break;
     
    31653147                target = popupButtonFocus;
    31663148            } else if (popupChild) {
    3167                 // forward mouse events to the popup child. mouse move events
    3168                 // are only forwarded to popup children that enable mouse tracking.
    3169                 if (type != QEvent::MouseMove || popupChild->hasMouseTracking())
    3170                     target = popupChild;
     3149                target = popupChild;
    31713150            }
    31723151
     
    31983177
    31993178        if (type == QEvent::MouseButtonPress
    3200             && qApp->activePopupWidget() != activePopupWidget
     3179            && QApplication::activePopupWidget() != activePopupWidget
    32013180            && replayPopupMouseEvent) {
    32023181            // the popup dissappeared. Replay the event
     
    32123191                ScreenToClient(hwndTarget, &widgetpt);
    32133192                LPARAM lParam = MAKELPARAM(widgetpt.x, widgetpt.y);
    3214                 winPostMessage(hwndTarget, msg.message, msg.wParam, lParam);
     3193                PostMessage(hwndTarget, msg.message, msg.wParam, lParam);
    32153194            }
    32163195        } else if (type == QEvent::MouseButtonRelease && button == Qt::RightButton
    3217                 && qApp->activePopupWidget() == activePopupWidget) {
     3196                && QApplication::activePopupWidget() == activePopupWidget) {
    32183197            // popup still alive and received right-button-release
    32193198#if !defined(QT_NO_CONTEXTMENU)
     
    32793258
    32803259    int delta;
    3281     if (msg.message == WM_MOUSEWHEEL)
     3260    if (msg.message == WM_MOUSEWHEEL || msg.message == WM_MOUSEHWHEEL)
    32823261        delta = (short) HIWORD (msg.wParam);
    32833262    else
    32843263        delta = (int) msg.wParam;
    32853264
    3286     Qt::Orientation orient = (state&Qt::AltModifier
     3265    Qt::Orientation orient = (msg.message == WM_MOUSEHWHEEL || state&Qt::AltModifier
    32873266#if 0
    32883267    // disabled for now - Trenton's one-wheel mouse makes trouble...
     
    32973276#endif
    32983277       ) ? Qt::Horizontal : Qt::Vertical;
     3278
     3279    // according to the MSDN documentation on WM_MOUSEHWHEEL:
     3280    // a positive value indicates that the wheel was rotated to the right;
     3281    // a negative value indicates that the wheel was rotated to the left.
     3282    // Qt defines this value as the exact opposite, so we have to flip the value!
     3283    if (msg.message == WM_MOUSEHWHEEL)
     3284        delta = -delta;
    32993285
    33003286    QPoint globalPos;
     
    33183304    // send the event to the widget or its ancestors
    33193305    {
    3320         QWidget* popup = qApp->activePopupWidget();
     3306        QWidget* popup = QApplication::activePopupWidget();
    33213307        if (popup && w->window() != popup)
    33223308            popup->close();
     
    33343320
    33353321    // send the event to the widget that has the focus or its ancestors, if different
    3336     if (w != qApp->focusWidget() && (w = qApp->focusWidget())) {
    3337         QWidget* popup = qApp->activePopupWidget();
     3322    if (w != QApplication::focusWidget() && (w = QApplication::focusWidget())) {
     3323        QWidget* popup = QApplication::activePopupWidget();
    33383324        if (popup && w->window() != popup)
    33393325            popup->close();
     
    33563342// the following is adapted from the wintab syspress example (public domain)
    33573343/* -------------------------------------------------------------------------- */
    3358 static void tabletInit(UINT wActiveCsr, HCTX hTab)
    3359 {
     3344// Initialize the "static" information of a cursor device (pen, airbrush, etc).
     3345// The QTabletDeviceData is initialized with the data that do not change in time
     3346// (number of button, type of device, etc) but do not initialize the variable data
     3347// (e.g.: pen or eraser)
     3348#ifndef QT_NO_TABLETEVENT
     3349
     3350static void tabletInit(const quint64 uniqueId, const UINT csr_type, HCTX hTab)
     3351{
     3352    Q_ASSERT(ptrWTInfo);
     3353    Q_ASSERT(ptrWTGet);
     3354
     3355    Q_ASSERT(!tCursorInfo()->contains(uniqueId));
     3356
    33603357    /* browse WinTab's many info items to discover pressure handling. */
    3361     if (ptrWTInfo && ptrWTGet) {
    3362         AXIS np;
    3363         LOGCONTEXT lc;
    3364         BYTE wPrsBtn;
    3365         BYTE logBtns[32];
    3366         UINT size;
    3367 
    3368         /* discover the LOGICAL button generated by the pressure channel. */
    3369         /* get the PHYSICAL button from the cursor category and run it */
    3370         /* through that cursor's button map (usually the identity map). */
    3371         wPrsBtn = (BYTE)-1;
    3372         ptrWTInfo(WTI_CURSORS + wActiveCsr, CSR_NPBUTTON, &wPrsBtn);
    3373         size = ptrWTInfo(WTI_CURSORS + wActiveCsr, CSR_BUTTONMAP, &logBtns);
    3374         if ((UINT)wPrsBtn < size)
    3375             wPrsBtn = logBtns[wPrsBtn];
    3376 
    3377         /* get the current context for its device variable. */
    3378         ptrWTGet(hTab, &lc);
    3379 
    3380         /* get the size of the pressure axis. */
    3381         QTabletDeviceData tdd;
    3382         ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_NPRESSURE, &np);
    3383         tdd.minPressure = int(np.axMin);
    3384         tdd.maxPressure = int(np.axMax);
    3385 
    3386         ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_TPRESSURE, &np);
    3387         tdd.minTanPressure = int(np.axMin);
    3388         tdd.maxTanPressure = int(np.axMax);
    3389 
    3390         ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_X, &np);
    3391         tdd.minX = int(np.axMin);
    3392         tdd.maxX = int(np.axMax);
    3393 
    3394         ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_Y, &np);
    3395         tdd.minY = int(np.axMin);
    3396         tdd.maxY = int(np.axMax);
    3397 
    3398         ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_Z, &np);
    3399         tdd.minZ = int(np.axMin);
    3400         tdd.maxZ = int(np.axMax);
    3401 
    3402         int csr_type,
    3403             csr_physid;
    3404         ptrWTInfo(WTI_CURSORS + wActiveCsr, CSR_TYPE, &csr_type);
    3405         ptrWTInfo(WTI_CURSORS + wActiveCsr, CSR_PHYSID, &csr_physid);
    3406         tdd.llId = csr_type & 0x0F06;
    3407         tdd.llId = (tdd.llId << 24) | csr_physid;
    3408 #ifndef QT_NO_TABLETEVENT
    3409         if (((csr_type & 0x0006) == 0x0002) && ((csr_type & 0x0F06) != 0x0902)) {
    3410             tdd.currentDevice = QTabletEvent::Stylus;
    3411         } else {
    3412             switch (csr_type & 0x0F06) {
     3358    AXIS np;
     3359    LOGCONTEXT lc;
     3360
     3361    /* get the current context for its device variable. */
     3362    ptrWTGet(hTab, &lc);
     3363
     3364    /* get the size of the pressure axis. */
     3365    QTabletDeviceData tdd;
     3366    tdd.llId = uniqueId;
     3367
     3368    ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_NPRESSURE, &np);
     3369    tdd.minPressure = int(np.axMin);
     3370    tdd.maxPressure = int(np.axMax);
     3371
     3372    ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_TPRESSURE, &np);
     3373    tdd.minTanPressure = int(np.axMin);
     3374    tdd.maxTanPressure = int(np.axMax);
     3375
     3376    LOGCONTEXT lcMine;
     3377
     3378    /* get default region */
     3379    ptrWTInfo(WTI_DEFCONTEXT, 0, &lcMine);
     3380
     3381    tdd.minX = 0;
     3382    tdd.maxX = int(lcMine.lcInExtX) - int(lcMine.lcInOrgX);
     3383
     3384    tdd.minY = 0;
     3385    tdd.maxY = int(lcMine.lcInExtY) - int(lcMine.lcInOrgY);
     3386
     3387    tdd.minZ = 0;
     3388    tdd.maxZ = int(lcMine.lcInExtZ) - int(lcMine.lcInOrgZ);
     3389
     3390    const uint cursorTypeBitMask = 0x0F06; // bitmask to find the specific cursor type (see Wacom FAQ)
     3391    if (((csr_type & 0x0006) == 0x0002) && ((csr_type & cursorTypeBitMask) != 0x0902)) {
     3392        tdd.currentDevice = QTabletEvent::Stylus;
     3393    } else {
     3394        switch (csr_type & cursorTypeBitMask) {
    34133395            case 0x0802:
    34143396                tdd.currentDevice = QTabletEvent::Stylus;
     
    34283410            default:
    34293411                tdd.currentDevice = QTabletEvent::NoDevice;
    3430             }
    3431         }
    3432 
    3433         switch (wActiveCsr % 3) {
    3434         case 2:
    3435             tdd.currentPointerType = QTabletEvent::Eraser;
    3436             break;
    3437         case 1:
    3438             tdd.currentPointerType = QTabletEvent::Pen;
    3439             break;
    3440         case 0:
    3441             tdd.currentPointerType = QTabletEvent::Cursor;
    3442             break;
    3443         default:
    3444             tdd.currentPointerType = QTabletEvent::UnknownPointer;
    3445         }
     3412        }
     3413    }
     3414    tCursorInfo()->insert(uniqueId, tdd);
     3415}
    34463416#endif // QT_NO_TABLETEVENT
    3447         tCursorInfo()->insert(wActiveCsr, tdd);
    3448     }
    3449 }
     3417
     3418// Update the "dynamic" informations of a cursor device (pen, airbrush, etc).
     3419// The dynamic information is the information of QTabletDeviceData that can change
     3420// in time (eraser or pen if a device is turned around).
     3421#ifndef QT_NO_TABLETEVENT
     3422
     3423static void tabletUpdateCursor(QTabletDeviceData &tdd, const UINT currentCursor)
     3424{
     3425    switch (currentCursor % 3) { // %3 for dual track
     3426    case 0:
     3427        tdd.currentPointerType = QTabletEvent::Cursor;
     3428        break;
     3429    case 1:
     3430        tdd.currentPointerType = QTabletEvent::Pen;
     3431        break;
     3432    case 2:
     3433        tdd.currentPointerType = QTabletEvent::Eraser;
     3434        break;
     3435    default:
     3436        tdd.currentPointerType = QTabletEvent::UnknownPointer;
     3437    }
     3438}
     3439#endif // QT_NO_TABLETEVENT
    34503440
    34513441bool QETWidget::translateTabletEvent(const MSG &msg, PACKET *localPacketBuf,
     
    35083498        QPoint globalPos(qRound(hiResGlobal.x()), qRound(hiResGlobal.y()));
    35093499
     3500        if (t == QEvent::TabletPress)
     3501        {
     3502            qt_button_down = QApplication::widgetAt(globalPos);
     3503        }
     3504
    35103505        // make sure the tablet event get's sent to the proper widget...
    3511         QWidget *w = QApplication::widgetAt(globalPos);
     3506        QWidget *w = 0;
     3507
    35123508        if (qt_button_down)
    35133509            w = qt_button_down; // Pass it to the thing that's grabbed it.
     3510        else
     3511            w = QApplication::widgetAt(globalPos);
    35143512
    35153513        if (!w)
    35163514            w = this;
     3515
     3516        if (t == QEvent::TabletRelease)
     3517        {
     3518            if (qt_win_ignoreNextMouseReleaseEvent) {
     3519                qt_win_ignoreNextMouseReleaseEvent = false;
     3520                if (qt_button_down && qt_button_down->internalWinId() == autoCaptureWnd) {
     3521                    releaseAutoCapture();
     3522                    qt_button_down = 0;
     3523                }
     3524            }
     3525
     3526        }
     3527
    35173528        QPoint localPos = w->mapFromGlobal(globalPos);
    35183529#ifndef QT_NO_TABLETEVENT
     
    35623573
    35633574extern bool qt_is_gui_used;
     3575
     3576
     3577#ifndef QT_NO_TABLETEVENT
     3578
    35643579static void initWinTabFunctions()
    35653580{
     
    35723587    QLibrary library(QLatin1String("wintab32"));
    35733588    if (library.load()) {
    3574         QT_WA({
    3575             ptrWTInfo = (PtrWTInfo)library.resolve("WTInfoW");
    3576             ptrWTGet = (PtrWTGet)library.resolve("WTGetW");
    3577         } , {
    3578             ptrWTInfo = (PtrWTInfo)library.resolve("WTInfoA");
    3579             ptrWTGet = (PtrWTGet)library.resolve("WTGetA");
    3580         });
    3581 
     3589        ptrWTInfo = (PtrWTInfo)library.resolve("WTInfoW");
     3590        ptrWTGet = (PtrWTGet)library.resolve("WTGetW");
    35823591        ptrWTEnable = (PtrWTEnable)library.resolve("WTEnable");
    35833592        ptrWTOverlap = (PtrWTEnable)library.resolve("WTOverlap");
     
    35863595#endif // Q_OS_WINCE
    35873596}
     3597#endif // QT_NO_TABLETEVENT
    35883598
    35893599
     
    36503660        QSize oldSize = size();
    36513661        QSize newSize(a, b);
    3652 #ifdef Q_OS_WINCE_WM
     3662#ifdef Q_WS_WINCE_WM
    36533663        if (isFullScreen() && (oldSize.width() == newSize.height()) && (oldSize.height() == newSize.width()))
    36543664            qt_wince_hide_taskbar(internalWinId());
     
    36623672            // (like Windows+M)
    36633673            if (msg.wParam == SIZE_MINIMIZED && !isMinimized()) {
    3664 #ifndef Q_OS_WINCE
     3674#ifndef Q_WS_WINCE
    36653675                const QString title = windowIconText();
    36663676                if (!title.isEmpty())
     
    36743684                }
    36753685            } else if (msg.wParam != SIZE_MINIMIZED && isMinimized()) {
    3676 #ifndef Q_OS_WINCE
     3686#ifndef Q_WS_WINCE
    36773687                const QString title = windowTitle();
    36783688                if (!title.isEmpty())
     
    37203730        QPoint newCPos(a, b);
    37213731        // Ignore silly Windows move event to wild pos after iconify.
    3722 #if !defined(Q_OS_WINCE)
     3732#if !defined(Q_WS_WINCE)
    37233733        if (!IsIconic(internalWinId()) && newCPos != oldPos) {
    37243734#endif
     
    37323742                QApplication::postEvent(this, e);
    37333743            }
    3734 #if !defined(Q_OS_WINCE)
     3744#if !defined(Q_WS_WINCE)
    37353745        }
    37363746#endif
     
    37533763}
    37543764
     3765bool QETWidget::translateGestureEvent(const MSG &, const GESTUREINFO &gi)
     3766{
     3767    const QPoint widgetPos = QPoint(gi.ptsLocation.x, gi.ptsLocation.y);
     3768    QWidget *alienWidget = !internalWinId() ? this : childAt(widgetPos);
     3769    if (alienWidget && alienWidget->internalWinId())
     3770        alienWidget = 0;
     3771    QWidget *widget = alienWidget ? alienWidget : this;
     3772
     3773    QNativeGestureEvent event;
     3774    event.sequenceId = gi.dwSequenceID;
     3775    event.position = QPoint(gi.ptsLocation.x, gi.ptsLocation.y);
     3776    event.argument = gi.ullArguments;
     3777
     3778    switch (gi.dwID) {
     3779    case GID_BEGIN:
     3780        event.gestureType = QNativeGestureEvent::GestureBegin;
     3781        break;
     3782    case GID_END:
     3783        event.gestureType = QNativeGestureEvent::GestureEnd;
     3784        break;
     3785    case GID_ZOOM:
     3786        event.gestureType = QNativeGestureEvent::Zoom;
     3787        break;
     3788    case GID_PAN:
     3789        event.gestureType = QNativeGestureEvent::Pan;
     3790        break;
     3791    case GID_ROTATE:
     3792        event.gestureType = QNativeGestureEvent::Rotate;
     3793        break;
     3794    case GID_TWOFINGERTAP:
     3795    case GID_ROLLOVER:
     3796    default:
     3797        break;
     3798    }
     3799    if (event.gestureType != QNativeGestureEvent::None)
     3800        qt_sendSpontaneousEvent(widget, &event);
     3801    return true;
     3802}
     3803
    37553804
    37563805void  QApplication::setCursorFlashTime(int msecs)
     
    37743823void QApplication::setDoubleClickInterval(int ms)
    37753824{
    3776 #ifndef Q_OS_WINCE
     3825#ifndef Q_WS_WINCE
    37773826    SetDoubleClickTime(ms);
    37783827#endif
     
    38063855    if (n < 0)
    38073856        n = 0;
    3808     QT_WA({
    3809         SystemParametersInfo(SPI_SETWHEELSCROLLLINES, (uint)n, 0, 0);
    3810     } , {
    3811         SystemParametersInfoA(SPI_SETWHEELSCROLLLINES, (uint)n, 0, 0);
    3812     });
     3857    SystemParametersInfo(SPI_SETWHEELSCROLLLINES, (uint)n, 0, 0);
    38133858#else
    38143859    QApplicationPrivate::wheel_scroll_lines = n;
     
    38203865#ifdef SPI_GETWHEELSCROLLLINES
    38213866    uint i = 3;
    3822     QT_WA({
    3823         SystemParametersInfo(SPI_GETWHEELSCROLLLINES, sizeof(uint), &i, 0);
    3824     } , {
    3825         SystemParametersInfoA(SPI_GETWHEELSCROLLLINES, sizeof(uint), &i, 0);
    3826     });
     3867    SystemParametersInfo(SPI_GETWHEELSCROLLLINES, sizeof(uint), &i, 0);
    38273868    if (i > INT_MAX)
    38283869        i = INT_MAX;
     
    38693910        return false;
    38703911
    3871     if (!effect_override && desktopSettingsAware()
    3872         && !(QSysInfo::WindowsVersion == QSysInfo::WV_95 || QSysInfo::WindowsVersion == QSysInfo::WV_NT)) {
     3912    if (!effect_override && desktopSettingsAware()) {
    38733913        // we know that they can be used when we are here
    38743914        BOOL enabled = false;
     
    38793919            break;
    38803920        case Qt::UI_FadeMenu:
    3881             if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)
    3882                 return false;
    38833921            api = SPI_GETMENUFADE;
    38843922            break;
     
    38873925            break;
    38883926        case Qt::UI_AnimateTooltip:
    3889             if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)
    3890                 api = SPI_GETMENUANIMATION;
    3891             else
    3892                 api = SPI_GETTOOLTIPANIMATION;
     3927            api = SPI_GETTOOLTIPANIMATION;
    38933928            break;
    38943929        case Qt::UI_FadeTooltip:
    3895             if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)
    3896                 return false;
    38973930            api = SPI_GETTOOLTIPFADE;
    38983931            break;
     
    39013934            break;
    39023935        }
    3903         QT_WA({
    3904             SystemParametersInfo(api, 0, &enabled, 0);
    3905         } , {
    3906             SystemParametersInfoA(api, 0, &enabled, 0);
    3907         });
     3936        SystemParametersInfo(api, 0, &enabled, 0);
    39083937        return enabled;
    39093938    }
     
    39543983#endif //QT_NO_SESSIONMANAGER
    39553984
     3985
     3986PtrRegisterTouchWindow QApplicationPrivate::RegisterTouchWindow = 0;
     3987PtrGetTouchInputInfo QApplicationPrivate::GetTouchInputInfo = 0;
     3988PtrCloseTouchInputHandle QApplicationPrivate::CloseTouchInputHandle = 0;
     3989
     3990void QApplicationPrivate::initializeMultitouch_sys()
     3991{
     3992    QLibrary library(QLatin1String("user32"));
     3993    // MinGW (g++ 3.4.5) accepts only C casts.
     3994    RegisterTouchWindow = (PtrRegisterTouchWindow)(library.resolve("RegisterTouchWindow"));
     3995    GetTouchInputInfo = (PtrGetTouchInputInfo)(library.resolve("GetTouchInputInfo"));
     3996    CloseTouchInputHandle = (PtrCloseTouchInputHandle)(library.resolve("CloseTouchInputHandle"));
     3997
     3998    touchInputIDToTouchPointID.clear();
     3999}
     4000
     4001void QApplicationPrivate::cleanupMultitouch_sys()
     4002{
     4003    touchInputIDToTouchPointID.clear();
     4004}
     4005
     4006bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
     4007{
     4008    QWidget *widgetForHwnd = QWidget::find(msg.hwnd);
     4009    if (!widgetForHwnd)
     4010        return false;
     4011
     4012    QRect screenGeometry = QApplication::desktop()->screenGeometry(widgetForHwnd);
     4013
     4014    QList<QTouchEvent::TouchPoint> touchPoints;
     4015
     4016    QVector<TOUCHINPUT> winTouchInputs(msg.wParam);
     4017    memset(winTouchInputs.data(), 0, sizeof(TOUCHINPUT) * winTouchInputs.count());
     4018    Qt::TouchPointStates allStates = 0;
     4019    QApplicationPrivate::GetTouchInputInfo((HANDLE) msg.lParam, msg.wParam, winTouchInputs.data(), sizeof(TOUCHINPUT));
     4020    for (int i = 0; i < winTouchInputs.count(); ++i) {
     4021        const TOUCHINPUT &touchInput = winTouchInputs.at(i);
     4022
     4023        int touchPointID = touchInputIDToTouchPointID.value(touchInput.dwID, -1);
     4024        if (touchPointID == -1) {
     4025            touchPointID = touchInputIDToTouchPointID.count();
     4026            touchInputIDToTouchPointID.insert(touchInput.dwID, touchPointID);
     4027        }
     4028
     4029        QTouchEvent::TouchPoint touchPoint(touchPointID);
     4030
     4031        // update state
     4032        QPointF screenPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.));
     4033        QRectF screenRect;
     4034        if (touchInput.dwMask & TOUCHINPUTMASKF_CONTACTAREA)
     4035            screenRect.setSize(QSizeF(qreal(touchInput.cxContact) / qreal(100.),
     4036                                      qreal(touchInput.cyContact) / qreal(100.)));
     4037        screenRect.moveCenter(screenPos);
     4038
     4039        Qt::TouchPointStates state;
     4040        if (touchInput.dwFlags & TOUCHEVENTF_DOWN) {
     4041            state = Qt::TouchPointPressed;
     4042        } else if (touchInput.dwFlags & TOUCHEVENTF_UP) {
     4043            state = Qt::TouchPointReleased;
     4044        } else {
     4045            state = (screenPos == touchPoint.screenPos()
     4046                     ? Qt::TouchPointStationary
     4047                     : Qt::TouchPointMoved);
     4048        }
     4049        if (touchInput.dwFlags & TOUCHEVENTF_PRIMARY)
     4050            state |= Qt::TouchPointPrimary;
     4051        touchPoint.setState(state);
     4052        touchPoint.setScreenRect(screenRect);
     4053        touchPoint.setNormalizedPos(QPointF(screenPos.x() / screenGeometry.width(),
     4054                                            screenPos.y() / screenGeometry.height()));
     4055
     4056        allStates |= state;
     4057
     4058        touchPoints.append(touchPoint);
     4059    }
     4060    QApplicationPrivate::CloseTouchInputHandle((HANDLE) msg.lParam);
     4061
     4062    if ((allStates & Qt::TouchPointStateMask) == Qt::TouchPointReleased) {
     4063        // all touch points released, forget the ids we've seen, they may not be reused
     4064        touchInputIDToTouchPointID.clear();
     4065    }
     4066
     4067    translateRawTouchEvent(widgetForHwnd, QTouchEvent::TouchScreen, touchPoints);
     4068    return true;
     4069}
     4070
    39564071QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.