]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Add NotifyIcon::DisplayBalloon
authorCheng Zhao <zcbenz@gmail.com>
Fri, 28 Nov 2014 10:30:43 +0000 (18:30 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 28 Nov 2014 10:30:43 +0000 (18:30 +0800)
atom/browser/ui/tray_icon.cc
atom/browser/ui/tray_icon.h
atom/browser/ui/win/notify_icon.cc
atom/browser/ui/win/notify_icon.h

index de9a16143b4d32acfb1c955733299df580daef05..538f259dbb1dab6fce8c811d726bf6b5dcf08157 100644 (file)
@@ -18,6 +18,11 @@ void TrayIcon::SetTitle(const std::string& title) {
 void TrayIcon::SetHighlightMode(bool highlight) {
 }
 
+void TrayIcon::DisplayBalloon(const gfx::ImageSkia& icon,
+                              const base::string16& title,
+                              const base::string16& contents) {
+}
+
 void TrayIcon::NotifyClicked() {
   FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked());
 }
index 8fe3160ee939ee57222d72ce40977ceeb158b567..0aa28ad07646becc329af5b49edb50aa118461c2 100644 (file)
@@ -39,6 +39,12 @@ class TrayIcon {
   // works on OS X.
   virtual void SetHighlightMode(bool highlight);
 
+  // Displays a notification balloon with the specified contents.
+  // Depending on the platform it might not appear by the icon tray.
+  virtual void DisplayBalloon(const gfx::ImageSkia& icon,
+                              const base::string16& title,
+                              const base::string16& contents);
+
   // Set the context menu for this icon.
   virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
 
index 7be52db42cf41f996d9508fec1f750a55964588e..dc22773688be6dad47db5e983a66efdf670bdf0c 100644 (file)
@@ -118,6 +118,35 @@ void NotifyIcon::SetToolTip(const std::string& tool_tip) {
     LOG(WARNING) << "Unable to set tooltip for status tray icon";
 }
 
+void NotifyIcon::DisplayBalloon(const gfx::ImageSkia& icon,
+                                const base::string16& title,
+                                const base::string16& contents) {
+  NOTIFYICONDATA icon_data;
+  InitIconData(&icon_data);
+  icon_data.uFlags = NIF_INFO;
+  icon_data.dwInfoFlags = NIIF_INFO;
+  wcscpy_s(icon_data.szInfoTitle, title.c_str());
+  wcscpy_s(icon_data.szInfo, contents.c_str());
+  icon_data.uTimeout = 0;
+
+  base::win::Version win_version = base::win::GetVersion();
+  if (!icon.isNull() && win_version != base::win::VERSION_PRE_XP) {
+    balloon_icon_.Set(IconUtil::CreateHICONFromSkBitmap(*icon.bitmap()));
+    if (win_version >= base::win::VERSION_VISTA) {
+      icon_data.hBalloonIcon = balloon_icon_.Get();
+      icon_data.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON;
+    } else {
+      icon_data.hIcon = balloon_icon_.Get();
+      icon_data.uFlags |= NIF_ICON;
+      icon_data.dwInfoFlags = NIIF_USER;
+    }
+  }
+
+  BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
+  if (!result)
+    LOG(WARNING) << "Unable to create status tray balloon.";
+}
+
 void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
   menu_model_ = menu_model;
 }
index 5f55c57b5054491c809523468bdc098214b4a230..2ac309d5dbaf6e17b6c6ecfd5a8e84ff7532c819 100644 (file)
@@ -46,6 +46,9 @@ class NotifyIcon : public TrayIcon {
   void SetImage(const gfx::ImageSkia& image) override;
   void SetPressedImage(const gfx::ImageSkia& image) override;
   void SetToolTip(const std::string& tool_tip) override;
+  void DisplayBalloon(const gfx::ImageSkia& icon,
+                      const base::string16& title,
+                      const base::string16& contents) override;
   void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
 
  private:
@@ -66,6 +69,9 @@ class NotifyIcon : public TrayIcon {
   // The currently-displayed icon for the window.
   base::win::ScopedHICON icon_;
 
+  // The currently-displayed icon for the notification balloon.
+  base::win::ScopedHICON balloon_icon_;
+
   // The context menu.
   ui::SimpleMenuModel* menu_model_;