| [2] | 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| [651] | 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| [561] | 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| [2] | 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| [561] | 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.
|
|---|
| [2] | 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| [561] | 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| [2] | 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qsystemtrayicon_p.h"
|
|---|
| 43 | #ifndef QT_NO_SYSTEMTRAYICON
|
|---|
| [561] | 44 | #define _WIN32_IE 0x0600 //required for NOTIFYICONDATA_V2_SIZE
|
|---|
| [2] | 45 |
|
|---|
| 46 | //missing defines for MINGW :
|
|---|
| 47 | #ifndef NIN_BALLOONTIMEOUT
|
|---|
| 48 | #define NIN_BALLOONTIMEOUT (WM_USER + 4)
|
|---|
| 49 | #endif
|
|---|
| 50 | #ifndef NIN_BALLOONUSERCLICK
|
|---|
| 51 | #define NIN_BALLOONUSERCLICK (WM_USER + 5)
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
| 54 | #include <qt_windows.h>
|
|---|
| 55 | #include <commctrl.h>
|
|---|
| 56 | #include <shlwapi.h>
|
|---|
| 57 | #include <QBitmap>
|
|---|
| 58 | #include <QLibrary>
|
|---|
| 59 | #include <QApplication>
|
|---|
| 60 | #include <QToolTip>
|
|---|
| 61 | #include <QDesktopWidget>
|
|---|
| 62 | #include <QSettings>
|
|---|
| 63 |
|
|---|
| [561] | 64 | #if defined(Q_WS_WINCE) && !defined(STANDARDSHELL_UI_MODEL)
|
|---|
| [2] | 65 | # include <streams.h>
|
|---|
| 66 | #endif
|
|---|
| 67 |
|
|---|
| 68 | QT_BEGIN_NAMESPACE
|
|---|
| 69 |
|
|---|
| [561] | 70 | #if defined(Q_WS_WINCE)
|
|---|
| [2] | 71 | static const UINT q_uNOTIFYICONID = 13; // IDs from 0 to 12 are reserved on WinCE.
|
|---|
| 72 | #else
|
|---|
| 73 | static const UINT q_uNOTIFYICONID = 0;
|
|---|
| 74 | #endif
|
|---|
| 75 |
|
|---|
| 76 | static uint MYWM_TASKBARCREATED = 0;
|
|---|
| 77 | #define MYWM_NOTIFYICON (WM_APP+101)
|
|---|
| 78 |
|
|---|
| [561] | 79 | struct Q_NOTIFYICONIDENTIFIER {
|
|---|
| 80 | DWORD cbSize;
|
|---|
| 81 | HWND hWnd;
|
|---|
| 82 | UINT uID;
|
|---|
| 83 | GUID guidItem;
|
|---|
| 84 | };
|
|---|
| [2] | 85 |
|
|---|
| [561] | 86 | #define Q_MSGFLT_ALLOW 1
|
|---|
| [2] | 87 |
|
|---|
| [561] | 88 | typedef HRESULT (WINAPI *PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER* identifier, RECT* iconLocation);
|
|---|
| 89 | typedef BOOL (WINAPI *PtrChangeWindowMessageFilter)(UINT message, DWORD dwFlag);
|
|---|
| 90 | typedef BOOL (WINAPI *PtrChangeWindowMessageFilterEx)(HWND hWnd, UINT message, DWORD action, void* pChangeFilterStruct);
|
|---|
| 91 |
|
|---|
| [2] | 92 | class QSystemTrayIconSys : QWidget
|
|---|
| 93 | {
|
|---|
| 94 | public:
|
|---|
| 95 | QSystemTrayIconSys(QSystemTrayIcon *object);
|
|---|
| 96 | ~QSystemTrayIconSys();
|
|---|
| 97 | bool winEvent( MSG *m, long *result );
|
|---|
| 98 | bool trayMessage(DWORD msg);
|
|---|
| 99 | bool iconDrawItem(LPDRAWITEMSTRUCT lpdi);
|
|---|
| [561] | 100 | void setIconContents(NOTIFYICONDATA &data);
|
|---|
| 101 | bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs);
|
|---|
| [2] | 102 | bool allowsMessages();
|
|---|
| 103 | bool supportsMessages();
|
|---|
| 104 | QRect findIconGeometry(const int a_iButtonID);
|
|---|
| 105 | void createIcon();
|
|---|
| 106 | HICON hIcon;
|
|---|
| 107 | QPoint globalPos;
|
|---|
| 108 | QSystemTrayIcon *q;
|
|---|
| 109 | private:
|
|---|
| [561] | 110 | uint notifyIconSize;
|
|---|
| [2] | 111 | int maxTipLength;
|
|---|
| [561] | 112 | bool ignoreNextMouseRelease;
|
|---|
| [2] | 113 | };
|
|---|
| 114 |
|
|---|
| 115 | bool QSystemTrayIconSys::allowsMessages()
|
|---|
| 116 | {
|
|---|
| 117 | #ifndef QT_NO_SETTINGS
|
|---|
| 118 | QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Software\\Microsoft"
|
|---|
| 119 | "\\Windows\\CurrentVersion\\Explorer\\Advanced"), QSettings::NativeFormat);
|
|---|
| 120 | return settings.value(QLatin1String("EnableBalloonTips"), true).toBool();
|
|---|
| 121 | #else
|
|---|
| 122 | return false;
|
|---|
| 123 | #endif
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | bool QSystemTrayIconSys::supportsMessages()
|
|---|
| 127 | {
|
|---|
| 128 | #ifndef Q_OS_WINCE
|
|---|
| [561] | 129 | return allowsMessages();
|
|---|
| [2] | 130 | #endif
|
|---|
| [561] | 131 | return false;
|
|---|
| [2] | 132 | }
|
|---|
| 133 |
|
|---|
| 134 | QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object)
|
|---|
| [561] | 135 | : hIcon(0), q(object), ignoreNextMouseRelease(false)
|
|---|
| 136 |
|
|---|
|
|---|