linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04172
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2532: allow icons to be added to balloons (convoluted code to support XP)
------------------------------------------------------------
revno: 2532
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2011-05-27 13:00:40 +0200
message:
allow icons to be added to balloons (convoluted code to support XP)
modified:
dwt/include/dwt/widgets/Notification.h
dwt/src/widgets/Notification.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dwt/include/dwt/widgets/Notification.h'
--- dwt/include/dwt/widgets/Notification.h 2011-04-23 10:33:55 +0000
+++ dwt/include/dwt/widgets/Notification.h 2011-05-27 11:00:40 +0000
@@ -58,7 +58,9 @@
void setTooltip(const tstring& tip);
- void addMessage(const tstring& title, const tstring& message);
+ /** show a balloon popup.
+ @param balloonIcon icon shown next to the title, only available on >= Vista. */
+ void addMessage(const tstring& title, const tstring& message, const IconPtr& balloonIcon = 0);
// TODO Fix callback parameters
typedef std::function<void ()> Callback;
@@ -90,6 +92,8 @@
Callback balloonClicked;
Callback updateTip;
+ NOTIFYICONDATA makeNID() const;
+
/// Last tick that tip was updated
DWORD lastTick;
bool trayHandler(const MSG& msg);
=== modified file 'dwt/src/widgets/Notification.cpp'
--- dwt/src/widgets/Notification.cpp 2011-04-23 10:33:55 +0000
+++ dwt/src/widgets/Notification.cpp 2011-05-27 11:00:40 +0000
@@ -30,7 +30,9 @@
*/
#include <dwt/widgets/Notification.h>
+
#include <dwt/Application.h>
+#include <dwt/util/win32/Version.h>
namespace dwt {
@@ -38,6 +40,26 @@
static const UINT taskbarMsg = ::RegisterWindowMessage(_T("TaskbarCreated"));
+/* the following dance adds the hBalloonIcon member to NOTIFYICONDATA without requiring a global
+switch of WINVER / _WIN32_WINNT / etc to Vista values. */
+typedef NOTIFYICONDATA legacyNOTIFYICONDATA;
+#if(_WIN32_WINNT < 0x600)
+struct NOTIFYICONDATA_ : NOTIFYICONDATA {
+ HICON hBalloonIcon;
+ NOTIFYICONDATA_(const NOTIFYICONDATA& nid) : NOTIFYICONDATA(nid), hBalloonIcon(0) { }
+};
+#define NOTIFYICONDATA NOTIFYICONDATA_
+#define NIF_SHOWTIP 0x80
+#endif
+
+legacyNOTIFYICONDATA Notification::makeNID() const {
+ bool vista = util::win32::ensureVersion(util::win32::VISTA);
+ legacyNOTIFYICONDATA nid = { vista ? sizeof(NOTIFYICONDATA) : sizeof(legacyNOTIFYICONDATA), parent->handle() };
+ if(vista)
+ nid.uFlags |= NIF_SHOWTIP;
+ return nid;
+}
+
Notification::Notification(WindowPtr parent_) :
parent(parent_),
visible(false),
@@ -73,10 +95,10 @@
visible = visible_;
- NOTIFYICONDATA nid = { sizeof(NOTIFYICONDATA), parent->handle() };
+ NOTIFYICONDATA nid = makeNID();
if(visible) {
- nid.uFlags = NIF_MESSAGE;
+ nid.uFlags |= NIF_MESSAGE;
nid.uCallbackMessage = message;
if(!tip.empty()) {
@@ -90,6 +112,7 @@
}
::Shell_NotifyIcon(NIM_ADD, &nid);
+
} else {
::Shell_NotifyIcon(NIM_DELETE, &nid);
}
@@ -100,24 +123,33 @@
lastTick = ::GetTickCount();
if(visible) {
- NOTIFYICONDATA nid = { sizeof(NOTIFYICONDATA), parent->handle() };
- nid.uFlags = NIF_TIP;
+ NOTIFYICONDATA nid = makeNID();
+ nid.uFlags |= NIF_TIP;
tip.copy(nid.szTip, sizeof(nid.szTip) / sizeof(nid.szTip[0]) - 1);
::Shell_NotifyIcon(NIM_MODIFY, &nid);
}
}
-void Notification::addMessage(const tstring& title, const tstring& message) {
+void Notification::addMessage(const tstring& title, const tstring& message, const IconPtr& balloonIcon) {
if(!visible || balloons)
++balloons;
if(!visible)
setVisible(true);
- NOTIFYICONDATA nid = { sizeof(NOTIFYICONDATA), parent->handle() };
- nid.uFlags = NIF_INFO;
+ NOTIFYICONDATA nid = makeNID();
+ nid.uFlags |= NIF_INFO;
+
message.copy(nid.szInfo, sizeof(nid.szInfo) / sizeof(nid.szInfo[0]) - 1);
+
title.copy(nid.szInfoTitle, sizeof(nid.szInfoTitle) / sizeof(nid.szInfoTitle[0]) - 1);
- nid.dwInfoFlags = NIIF_INFO;
+
+ if(balloonIcon && util::win32::ensureVersion(util::win32::VISTA)) {
+ nid.dwInfoFlags = NIIF_USER;
+ nid.hBalloonIcon = balloonIcon->handle();
+ } else {
+ nid.dwInfoFlags = NIIF_INFO;
+ }
+
::Shell_NotifyIcon(NIM_MODIFY, &nid);
}