diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2010-06-16 15:23:34 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2010-06-16 15:23:34 (GMT) |
commit | 0b9638476c1a8bad4e33cbd20be1f6ff33935766 (patch) | |
tree | 968c6927ef9cda975f1065c41d93882231383588 /src/gui | |
parent | 8cb10f381af7fd6f1fa0ffc946f6a4e6ba106d5d (diff) | |
parent | c9a89b253176547901e11d27c042983a65f43b1f (diff) | |
download | Qt-0b9638476c1a8bad4e33cbd20be1f6ff33935766.zip Qt-0b9638476c1a8bad4e33cbd20be1f6ff33935766.tar.gz Qt-0b9638476c1a8bad4e33cbd20be1f6ff33935766.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt into qt-4.7-from-4.6
Diffstat (limited to 'src/gui')
23 files changed, 164 insertions, 181 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 7b0722e..6c5623e 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -6100,8 +6100,15 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) if (ev.isAccepted() || ev.isAccepted(g)) { conflictedGestures.remove(g); // mark the item as a gesture target - if (item) + if (item) { gestureTargets.insert(g, item.data()); + QHash<QGraphicsObject *, QSet<QGesture *> >::iterator it, e; + it = cachedItemGestures.begin(); + e = cachedItemGestures.end(); + for(; it != e; ++it) + it.value().remove(g); + cachedItemGestures[item.data()].insert(g); + } DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" << "override was accepted:" << g << item.data(); diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri index 8d75fdd..c4eac95 100644 --- a/src/gui/image/image.pri +++ b/src/gui/image/image.pri @@ -93,12 +93,12 @@ SOURCES += \ SOURCES += image/qpnghandler.cpp contains(QT_CONFIG, system-png) { - unix:LIBS_PRIVATE += -lpng - win32:LIBS += libpng.lib + unix|win32-g++*:LIBS_PRIVATE += -lpng + win32:!win32-g++*:LIBS += libpng.lib } else { DEFINES *= QT_USE_BUNDLED_LIBPNG !isEqual(QT_ARCH, i386):!isEqual(QT_ARCH, x86_64):DEFINES += PNG_NO_ASSEMBLER_CODE - INCLUDEPATH += ../3rdparty/libpng ../3rdparty/zlib + INCLUDEPATH += ../3rdparty/libpng SOURCES += ../3rdparty/libpng/png.c \ ../3rdparty/libpng/pngerror.c \ ../3rdparty/libpng/pngget.c \ @@ -114,6 +114,14 @@ SOURCES += \ ../3rdparty/libpng/pngwrite.c \ ../3rdparty/libpng/pngwtran.c \ ../3rdparty/libpng/pngwutil.c + + contains(QT_CONFIG, system-zlib) { + symbian:LIBS_PRIVATE += -llibz + else:if(unix|win32-g++*):LIBS_PRIVATE += -lz + else:LIBS += zdll.lib + } else { + INCLUDEPATH += ../3rdparty/zlib + } } } else { DEFINES *= QT_NO_IMAGEFORMAT_PNG diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 20e4b50..fd2c139 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -1766,6 +1766,9 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) function returns the actual matrix used for transforming the pixmap. + \note When using the native X11 graphics system, the pixmap + becomes invalid when the QApplication instance is destroyed. + \sa QBitmap, QImage, QImageReader, QImageWriter */ diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index 6bebefc..e8dc5ae 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -1250,10 +1250,8 @@ void QX11PixmapData::release() pengine = 0; if (!X11) { -#ifndef QT_NO_DEBUG - qWarning("~QX11PixmapData(): QPixmap objects must be destroyed before the QApplication" - " object, otherwise the native pixmap object will be leaked."); -#endif + // At this point, the X server will already have freed our resources, + // so there is nothing to do. return; } diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 52767b8..1680ef4 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -5313,6 +5313,7 @@ void QApplication::setInputContext(QInputContext *inputContext) } delete QApplicationPrivate::inputContext; QApplicationPrivate::inputContext = inputContext; + QApplicationPrivate::inputContext->setParent(this); } /*! diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 09535fa..0edb8fb 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -118,8 +118,6 @@ extern void qt_wince_hide_taskbar(HWND hwnd); //defined in qguifunctions_wince.c # include <winable.h> #endif -#include "private/qwinnativepangesturerecognizer_win_p.h" - #ifndef WM_TOUCH # define WM_TOUCH 0x0240 @@ -4066,36 +4064,9 @@ PtrCloseTouchInputHandle QApplicationPrivate::CloseTouchInputHandle = 0; void QApplicationPrivate::initializeMultitouch_sys() { - static const IID QT_IID_IInkTablets = {0x112086D9, 0x7779, 0x4535, {0xA6, 0x99, 0x86, 0x2B, 0x43, 0xAC, 0x18, 0x63} }; - static const IID QT_IID_IInkTablet2 = {0x90c91ad2, 0xfa36, 0x49d6, {0x95, 0x16, 0xce, 0x8d, 0x57, 0x0f, 0x6f, 0x85} }; - static const CLSID QT_CLSID_InkTablets = {0x6E4FCB12, 0x510A, 0x4d40, {0x93, 0x04, 0x1D, 0xA1, 0x0A, 0xE9, 0x14, 0x7C} }; - - IInkTablets *iInkTablets = 0; - HRESULT hr = CoCreateInstance(QT_CLSID_InkTablets, NULL, CLSCTX_ALL, QT_IID_IInkTablets, (void**)&iInkTablets); - if (SUCCEEDED(hr)) { - long count = 0; - iInkTablets->get_Count(&count); - for (long i = 0; i < count; ++i) { - IInkTablet *iInkTablet = 0; - hr = iInkTablets->Item(i, &iInkTablet); - if (FAILED(hr)) - continue; - IInkTablet2 *iInkTablet2 = 0; - hr = iInkTablet->QueryInterface(QT_IID_IInkTablet2, (void**)&iInkTablet2); - iInkTablet->Release(); - if (FAILED(hr)) - continue; - TabletDeviceKind kind; - hr = iInkTablet2->get_DeviceKind(&kind); - iInkTablet2->Release(); - if (FAILED(hr)) - continue; - if (kind == TDK_Touch) { - QApplicationPrivate::HasTouchSupport = true; - break; - } - } - iInkTablets->Release(); + if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) { + static const int QT_SM_DIGITIZER = 94; + QApplicationPrivate::HasTouchSupport = GetSystemMetrics(QT_SM_DIGITIZER); } QLibrary library(QLatin1String("user32")); diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 2af031b..e43a560 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -286,6 +286,9 @@ bool QGestureManager::filterEventThroughContexts(const QMultiMap<QObject *, // check if a running gesture switched back to maybe state QSet<QGesture *> activeToMaybeGestures = m_activeGestures & newMaybeGestures; + // check if a maybe gesture switched to canceled - reset it but don't send an event + QSet<QGesture *> maybeToCanceledGestures = m_maybeGestures & notGestures; + // check if a running gesture switched back to not gesture state, // i.e. were canceled QSet<QGesture *> canceledGestures = m_activeGestures & notGestures; @@ -345,7 +348,8 @@ bool QGestureManager::filterEventThroughContexts(const QMultiMap<QObject *, << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures - << "\n\tcanceled:" << canceledGestures; + << "\n\tcanceled:" << canceledGestures + << "\n\tmaybe-canceled:" << maybeToCanceledGestures; } QSet<QGesture *> undeliveredGestures; @@ -366,7 +370,7 @@ bool QGestureManager::filterEventThroughContexts(const QMultiMap<QObject *, // reset gestures that ended QSet<QGesture *> endedGestures = - finishedGestures + canceledGestures + undeliveredGestures; + finishedGestures + canceledGestures + undeliveredGestures + maybeToCanceledGestures; foreach (QGesture *gesture, endedGestures) { recycle(gesture); m_gestureTargets.remove(gesture); diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 6960838..8a3e89e 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -112,6 +112,7 @@ QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2; if (d->offset.x() > 10 || d->offset.y() > 10 || d->offset.x() < -10 || d->offset.y() < -10) { + q->setHotSpot(p1.startScreenPos()); result = QGestureRecognizer::TriggerGesture; } else { result = QGestureRecognizer::MayBeGesture; @@ -441,6 +442,7 @@ QGestureRecognizer::Result QTapGestureRecognizer::recognize(QGesture *state, switch (event->type()) { case QEvent::TouchBegin: { d->position = ev->touchPoints().at(0).pos(); + q->setHotSpot(ev->touchPoints().at(0).screenPos()); result = QGestureRecognizer::TriggerGesture; break; } @@ -523,6 +525,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, if (d->timerId) q->killTimer(d->timerId); d->timerId = q->startTimer(TimerInterval); + q->setHotSpot(ev->touchPoints().at(0).startScreenPos()); result = QGestureRecognizer::TriggerGesture; break; case QEvent::TouchEnd: diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 492954a..dd568cd 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -380,6 +380,8 @@ void QWidget::setInputContext(QInputContext *context) if (d->ic) delete d->ic; d->ic = context; + if (d->ic) + d->ic->setParent(this); #endif } @@ -1067,7 +1069,6 @@ struct QWidgetExceptionCleaner \sa windowFlags */ - QWidget::QWidget(QWidget *parent, Qt::WindowFlags f) : QObject(*new QWidgetPrivate, 0), QPaintDevice() { diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h index 64addeb..9d0e6f7 100644 --- a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h +++ b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h @@ -55,39 +55,6 @@ #include <QGestureRecognizer> -#include <objbase.h> - -class IInkRectangle; -class TabletHardwareCapabilities; -class TabletPropertyMetricUnit; -DECLARE_INTERFACE_(IInkTablet, IDispatch) -{ - STDMETHOD(get_Name)(THIS_ BSTR *Name) PURE; - STDMETHOD(get_PlugAndPlayId)(THIS_ BSTR *Id) PURE; - STDMETHOD(get_MaximumInputRectangle)(THIS_ IInkRectangle **Rectangle) PURE; - STDMETHOD(get_HardwareCapabilities)(THIS_ TabletHardwareCapabilities *Capabilities) PURE; - STDMETHOD(IsPacketPropertySupported)(THIS_ BSTR packetPropertyName) PURE; - STDMETHOD(GetPropertyMetrics)(THIS_ BSTR propertyName, long *Minimum, long *Maximum, TabletPropertyMetricUnit *Units, float *Resolution) PURE; -}; -enum TabletDeviceKind -{ - TDK_Mouse = 0, - TDK_Pen = 1, - TDK_Touch = 2 -}; -DECLARE_INTERFACE_(IInkTablet2, IDispatch) -{ - STDMETHOD(get_DeviceKind)(THIS_ TabletDeviceKind *Kind) PURE; -}; -DECLARE_INTERFACE_(IInkTablets, IDispatch) -{ - STDMETHOD(get_Count)(THIS_ long *Count) PURE; - STDMETHOD(get__NewEnum)(THIS_ IUnknown **_NewEnum) PURE; - STDMETHOD(get_DefaultTablet)(THIS_ IInkTablet **DefaultTablet) PURE; - STDMETHOD(Item)(THIS_ long Index, IInkTablet **Tablet) PURE; - STDMETHOD(IsPacketPropertySupported)(THIS_ BSTR packetPropertyName, VARIANT_BOOL *Supported) PURE; -}; - #ifndef QT_NO_GESTURES QT_BEGIN_NAMESPACE diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri index 123af1c..a5cfb84 100644 --- a/src/gui/painting/painting.pri +++ b/src/gui/painting/painting.pri @@ -234,7 +234,7 @@ contains(QMAKE_MAC_XARCH, no) { IWMMXT_SOURCES += painting/qdrawhelper_iwmmxt.cpp } - win32-g++|!win32:!*-icc* { + win32-g++*|!win32:!*-icc* { mmx { mmx_compiler.commands = $$QMAKE_CXX -c -Winline @@ -403,9 +403,10 @@ neon:*-g++* { } contains(QT_CONFIG, zlib) { - INCLUDEPATH += ../3rdparty/zlib + INCLUDEPATH += ../3rdparty/zlib } else:!contains(QT_CONFIG, no-zlib) { - unix:LIBS_PRIVATE += -lz -# win32:LIBS += libz.lib + symbian:LIBS_PRIVATE += -llibz + else:if(unix|win32-g++*):LIBS_PRIVATE += -lz + else:LIBS += zdll.lib } diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 4978565..039a6da 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -762,7 +762,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q #ifndef QT_NO_ITEMVIEWS case PE_PanelItemViewRow: if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { - QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled + QPalette::ColorGroup cg = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled)) ? QPalette::Normal : QPalette::Disabled; if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active)) cg = QPalette::Inactive; @@ -775,7 +775,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q break; case PE_PanelItemViewItem: if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { - QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled + QPalette::ColorGroup cg = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled)) ? QPalette::Normal : QPalette::Disabled; if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active)) cg = QPalette::Inactive; diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp index b59a033..c989bd3 100644 --- a/src/gui/styles/qgtkstyle.cpp +++ b/src/gui/styles/qgtkstyle.cpp @@ -855,9 +855,10 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, key = QLS("a"); GTK_WIDGET_SET_FLAGS(gtkTreeView, GTK_HAS_FOCUS); } + bool isEnabled = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled)); gtkPainter.paintFlatBox(gtkTreeView, detail, option->rect, option->state & State_Selected ? GTK_STATE_SELECTED : - option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, + isEnabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_OUT, gtkTreeView->style, key); if (isActive ) GTK_WIDGET_UNSET_FLAGS(gtkTreeView, GTK_HAS_FOCUS); diff --git a/src/gui/text/qtextoption.cpp b/src/gui/text/qtextoption.cpp index 3b02ebe..8f31e46 100644 --- a/src/gui/text/qtextoption.cpp +++ b/src/gui/text/qtextoption.cpp @@ -145,7 +145,7 @@ QTextOption &QTextOption::operator=(const QTextOption &o) \sa tabArray(), setTabStop(), setTabs() */ -void QTextOption::setTabArray(QList<qreal> tabStops) +void QTextOption::setTabArray(QList<qreal> tabStops) // Qt5: const ref { if (!d) d = new QTextOptionPrivate; @@ -165,7 +165,7 @@ void QTextOption::setTabArray(QList<qreal> tabStops) \sa tabStops() */ -void QTextOption::setTabs(QList<QTextOption::Tab> tabStops) +void QTextOption::setTabs(QList<QTextOption::Tab> tabStops) // Qt5: const ref { if (!d) d = new QTextOptionPrivate; @@ -391,6 +391,12 @@ QList<QTextOption::Tab> QTextOption::tabs() const */ /*! + \fn Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar()) + Creates a tab with the given position, tab type, and (for DelimiterTab) delimiter + \since 4.7 +*/ + +/*! \fn bool Tab::operator==(const Tab &other) const Returns true if tab \a other is equal to this tab; diff --git a/src/gui/text/qtextoption.h b/src/gui/text/qtextoption.h index fa8c6f2..a48efc1 100644 --- a/src/gui/text/qtextoption.h +++ b/src/gui/text/qtextoption.h @@ -68,6 +68,8 @@ public: struct Q_GUI_EXPORT Tab { inline Tab() : position(80), type(QTextOption::LeftTab) { } + inline Tab(qreal pos, TabType tabType, QChar delim = QChar()) + : position(pos), type(tabType), delimiter(delim) {} inline bool operator==(const Tab &other) const { return type == other.type diff --git a/src/gui/text/text.pri b/src/gui/text/text.pri index d5a9c74..34311a9 100644 --- a/src/gui/text/text.pri +++ b/src/gui/text/text.pri @@ -139,7 +139,7 @@ contains(QT_CONFIG, freetype) { ../3rdparty/freetype/src/base/ftmm.c \ ../3rdparty/freetype/src/base/fttype1.c \ ../3rdparty/freetype/src/base/ftsynth.c \ - ../3rdparty/freetype/src/base/ftbitmap.c\ + ../3rdparty/freetype/src/base/ftbitmap.c \ ../3rdparty/freetype/src/bdf/bdf.c \ ../3rdparty/freetype/src/cache/ftcache.c \ ../3rdparty/freetype/src/cff/cff.c \ diff --git a/src/gui/util/qsystemtrayicon.cpp b/src/gui/util/qsystemtrayicon.cpp index d7dde87..941961b 100644 --- a/src/gui/util/qsystemtrayicon.cpp +++ b/src/gui/util/qsystemtrayicon.cpp @@ -356,10 +356,7 @@ bool QSystemTrayIcon::isSystemTrayAvailable() */ bool QSystemTrayIcon::supportsMessages() { -#if defined(Q_WS_QWS) - return false; -#endif - return true; + return QSystemTrayIconPrivate::supportsMessages_sys(); } /*! diff --git a/src/gui/util/qsystemtrayicon_mac.mm b/src/gui/util/qsystemtrayicon_mac.mm index 8aaaa0f..22134cb 100644 --- a/src/gui/util/qsystemtrayicon_mac.mm +++ b/src/gui/util/qsystemtrayicon_mac.mm @@ -226,6 +226,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return true; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return true; +} + void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon, int) { diff --git a/src/gui/util/qsystemtrayicon_p.h b/src/gui/util/qsystemtrayicon_p.h index e8bf197..4592e43 100644 --- a/src/gui/util/qsystemtrayicon_p.h +++ b/src/gui/util/qsystemtrayicon_p.h @@ -83,7 +83,9 @@ public: void updateMenu_sys(); QRect geometry_sys() const; void showMessage_sys(const QString &msg, const QString &title, QSystemTrayIcon::MessageIcon icon, int secs); + static bool isSystemTrayAvailable_sys(); + static bool supportsMessages_sys(); QPointer<QMenu> menu; QIcon icon; diff --git a/src/gui/util/qsystemtrayicon_qws.cpp b/src/gui/util/qsystemtrayicon_qws.cpp index b1b895b..cda47aa 100644 --- a/src/gui/util/qsystemtrayicon_qws.cpp +++ b/src/gui/util/qsystemtrayicon_qws.cpp @@ -75,6 +75,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return false; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return false; +} + void QSystemTrayIconPrivate::showMessage_sys(const QString &message, const QString &title, QSystemTrayIcon::MessageIcon icon, diff --git a/src/gui/util/qsystemtrayicon_win.cpp b/src/gui/util/qsystemtrayicon_win.cpp index c89fbae..a9585b9 100644 --- a/src/gui/util/qsystemtrayicon_win.cpp +++ b/src/gui/util/qsystemtrayicon_win.cpp @@ -41,23 +41,21 @@ #include "qsystemtrayicon_p.h" #ifndef QT_NO_SYSTEMTRAYICON -#define _WIN32_IE 0x0600 //required for NOTIFYICONDATA_V2_SIZE -//missing defines for MINGW : -#ifndef NIN_BALLOONTIMEOUT -#define NIN_BALLOONTIMEOUT (WM_USER + 4) +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 #endif -#ifndef NIN_BALLOONUSERCLICK -#define NIN_BALLOONUSERCLICK (WM_USER + 5) + +#ifndef _WIN32_IE +#define _WIN32_IE 0x600 #endif #include <qt_windows.h> +#include <windowsx.h> #include <commctrl.h> -#include <QBitmap> + #include <QLibrary> #include <QApplication> -#include <QToolTip> -#include <QDesktopWidget> #include <QSettings> QT_BEGIN_NAMESPACE @@ -74,6 +72,30 @@ struct Q_NOTIFYICONIDENTIFIER { GUID guidItem; }; +#ifndef NOTIFYICON_VERSION_4 +#define NOTIFYICON_VERSION_4 4 +#endif + +#ifndef NIN_SELECT +#define NIN_SELECT (WM_USER + 0) +#endif + +#ifndef NIN_KEYSELECT +#define NIN_KEYSELECT (WM_USER + 1) +#endif + +#ifndef NIN_BALLOONTIMEOUT +#define NIN_BALLOONTIMEOUT (WM_USER + 4) +#endif + +#ifndef NIN_BALLOONUSERCLICK +#define NIN_BALLOONUSERCLICK (WM_USER + 5) +#endif + +#ifndef NIF_SHOWTIP +#define NIF_SHOWTIP 0x00000080 +#endif + #define Q_MSGFLT_ALLOW 1 typedef HRESULT (WINAPI *PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER* identifier, RECT* iconLocation); @@ -87,11 +109,8 @@ public: ~QSystemTrayIconSys(); bool winEvent( MSG *m, long *result ); bool trayMessage(DWORD msg); - bool iconDrawItem(LPDRAWITEMSTRUCT lpdi); void setIconContents(NOTIFYICONDATA &data); bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs); - bool allowsMessages(); - bool supportsMessages(); QRect findIconGeometry(const int a_iButtonID); void createIcon(); HICON hIcon; @@ -100,10 +119,11 @@ public: private: uint notifyIconSize; int maxTipLength; + int version; bool ignoreNextMouseRelease; }; -bool QSystemTrayIconSys::allowsMessages() +static bool allowsMessages() { #ifndef QT_NO_SETTINGS QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Software\\Microsoft" @@ -114,16 +134,18 @@ bool QSystemTrayIconSys::allowsMessages() #endif } -bool QSystemTrayIconSys::supportsMessages() -{ - return allowsMessages(); -} - QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object) : hIcon(0), q(object), ignoreNextMouseRelease(false) { - notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, guidItem); // NOTIFYICONDATAW_V2_SIZE; + if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) { + notifyIconSize = sizeof(NOTIFYICONDATA); + version = NOTIFYICON_VERSION_4; + } else { + notifyIconSize = NOTIFYICONDATA_V2_SIZE; + version = NOTIFYICON_VERSION; + } + maxTipLength = 128; // For restoring the tray icon after explorer crashes @@ -157,7 +179,7 @@ QSystemTrayIconSys::~QSystemTrayIconSys() void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) { - tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; + tnd.uFlags |= NIF_MESSAGE | NIF_ICON | NIF_TIP; tnd.uCallbackMessage = MYWM_NOTIFYICON; tnd.hIcon = hIcon; QString tip = q->toolTip(); @@ -170,7 +192,6 @@ void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) static int iconFlag( QSystemTrayIcon::MessageIcon icon ) { -#if NOTIFYICON_VERSION >= 3 switch (icon) { case QSystemTrayIcon::Information: return NIIF_INFO; @@ -184,20 +205,13 @@ static int iconFlag( QSystemTrayIcon::MessageIcon icon ) Q_ASSERT_X(false, "QSystemTrayIconSys::showMessage", "Invalid QSystemTrayIcon::MessageIcon value"); return NIIF_NONE; } -#else - Q_UNUSED(icon); - return 0; -#endif } bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs) { -#if NOTIFYICON_VERSION >= 3 NOTIFYICONDATA tnd; memset(&tnd, 0, notifyIconSize); - Q_ASSERT(testAttribute(Qt::WA_WState_Created)); - setIconContents(tnd); memcpy(tnd.szInfo, message.utf16(), qMin(message.length() + 1, 256) * sizeof(wchar_t)); memcpy(tnd.szInfoTitle, title.utf16(), qMin(title.length() + 1, 64) * sizeof(wchar_t)); @@ -206,42 +220,36 @@ bool QSystemTrayIconSys::showMessage(const QString &title, const QString &messag tnd.cbSize = notifyIconSize; tnd.hWnd = winId(); tnd.uTimeout = uSecs; - tnd.uFlags = NIF_INFO; + tnd.uFlags = NIF_INFO | NIF_SHOWTIP; + + Q_ASSERT(testAttribute(Qt::WA_WState_Created)); return Shell_NotifyIcon(NIM_MODIFY, &tnd); -#else - Q_UNUSED(title); - Q_UNUSED(message); - Q_UNUSED(type); - Q_UNUSED(uSecs); - return false; -#endif } bool QSystemTrayIconSys::trayMessage(DWORD msg) { NOTIFYICONDATA tnd; memset(&tnd, 0, notifyIconSize); + tnd.uID = q_uNOTIFYICONID; tnd.cbSize = notifyIconSize; tnd.hWnd = winId(); + tnd.uFlags = NIF_SHOWTIP; + tnd.uVersion = version; Q_ASSERT(testAttribute(Qt::WA_WState_Created)); - if (msg != NIM_DELETE) { + if (msg == NIM_ADD || msg == NIM_MODIFY) { setIconContents(tnd); } - return Shell_NotifyIcon(msg, &tnd); -} + bool success = Shell_NotifyIcon(msg, &tnd); -bool QSystemTrayIconSys::iconDrawItem(LPDRAWITEMSTRUCT lpdi) -{ - if (!hIcon) - return false; - - DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon, 0, 0, 0, 0, DI_NORMAL); - return true; + if (msg == NIM_ADD) + return success && Shell_NotifyIcon(NIM_SETVERSION, &tnd); + else + return success; } void QSystemTrayIconSys::createIcon() @@ -264,27 +272,24 @@ void QSystemTrayIconSys::createIcon() bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) { switch(m->message) { - case WM_CREATE: -#ifdef GWLP_USERDATA - SetWindowLongPtr(winId(), GWLP_USERDATA, (LONG_PTR)((CREATESTRUCTW*)m->lParam)->lpCreateParams); -#else - SetWindowLong(winId(), GWL_USERDATA, (LONG)((CREATESTRUCTW*)m->lParam)->lpCreateParams); -#endif - break; - - case WM_DRAWITEM: - return iconDrawItem((LPDRAWITEMSTRUCT)m->lParam); - case MYWM_NOTIFYICON: { - RECT r; - GetWindowRect(winId(), &r); - QEvent *e = 0; - Qt::KeyboardModifiers keys = QApplication::keyboardModifiers(); - QPoint gpos = QCursor::pos(); - - switch (m->lParam) { - case WM_LBUTTONUP: + int message = 0; + QPoint gpos; + + if (version == NOTIFYICON_VERSION_4) { + Q_ASSERT(q_uNOTIFYICONID == HIWORD(m->lParam)); + message = LOWORD(m->lParam); + gpos = QPoint(GET_X_LPARAM(m->wParam), GET_Y_LPARAM(m->wParam)); + } else { + Q_ASSERT(q_uNOTIFYICONID == m->wParam); + message = m->lParam; + gpos = QCursor::pos(); + } + + switch (message) { + case NIN_SELECT: + case NIN_KEYSELECT: if (ignoreNextMouseRelease) ignoreNextMouseRelease = false; else @@ -297,7 +302,7 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) emit q->activated(QSystemTrayIcon::DoubleClick); break; - case WM_RBUTTONUP: + case WM_CONTEXTMENU: if (q->contextMenu()) { q->contextMenu()->popup(gpos); } @@ -311,13 +316,9 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) case WM_MBUTTONUP: emit q->activated(QSystemTrayIcon::MiddleClick); break; + default: - break; - } - if (e) { - bool res = QApplication::sendEvent(q, e); - delete e; - return res; + break; } break; } @@ -441,7 +442,7 @@ QRect QSystemTrayIconSys::findIconGeometry(const int iconId) void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut) { - if (!sys || !sys->allowsMessages()) + if (!sys || !allowsMessages()) return; uint uSecs = 0; @@ -459,21 +460,14 @@ void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString //title is limited to 63 chars + NULL QString titleString = title.left(63) + QChar(); - if (sys->supportsMessages()) { - sys->showMessage(titleString, messageString, type, (unsigned int)uSecs); - } else { - //use fallback - QRect iconPos = sys->findIconGeometry(q_uNOTIFYICONID); - if (iconPos.isValid()) { - QBalloonTip::showBalloon(type, title, message, sys->q, iconPos.center(), uSecs, true); - } - } + sys->showMessage(titleString, messageString, type, uSecs); } QRect QSystemTrayIconPrivate::geometry_sys() const { if (!sys) return QRect(); + return sys->findIconGeometry(q_uNOTIFYICONID); } @@ -519,6 +513,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return true; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return allowsMessages(); +} + QT_END_NAMESPACE #endif diff --git a/src/gui/util/qsystemtrayicon_wince.cpp b/src/gui/util/qsystemtrayicon_wince.cpp index 0a0d340..e5cf0fd 100644 --- a/src/gui/util/qsystemtrayicon_wince.cpp +++ b/src/gui/util/qsystemtrayicon_wince.cpp @@ -155,10 +155,6 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) case MYWM_NOTIFYICON: { - RECT r; - GetWindowRect(winId(), &r); - QEvent *e = 0; - Qt::KeyboardModifiers keys = QApplication::keyboardModifiers(); QPoint gpos = QCursor::pos(); switch (m->lParam) { @@ -193,14 +189,10 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) case WM_MBUTTONUP: emit q->activated(QSystemTrayIcon::MiddleClick); break; + default: break; } - if (e) { - bool res = QApplication::sendEvent(q, e); - delete e; - return res; - } break; } default: @@ -291,6 +283,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return true; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return true; +} + QT_END_NAMESPACE #endif diff --git a/src/gui/util/qsystemtrayicon_x11.cpp b/src/gui/util/qsystemtrayicon_x11.cpp index 82b4325..59fdc07 100644 --- a/src/gui/util/qsystemtrayicon_x11.cpp +++ b/src/gui/util/qsystemtrayicon_x11.cpp @@ -381,6 +381,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return QSystemTrayIconSys::locateSystemTray() != XNone; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return true; +} + void QSystemTrayIconPrivate::showMessage_sys(const QString &message, const QString &title, QSystemTrayIcon::MessageIcon icon, int msecs) { |