notify_icon.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_UI_WIN_NOTIFY_ICON_H_
  5. #define ATOM_BROWSER_UI_WIN_NOTIFY_ICON_H_
  6. #include <windows.h> // windows.h must be included first
  7. #include <shellapi.h>
  8. #include <string>
  9. #include "atom/browser/ui/tray_icon.h"
  10. #include "base/compiler_specific.h"
  11. #include "base/macros.h"
  12. #include "base/win/scoped_gdi_object.h"
  13. namespace gfx {
  14. class Point;
  15. }
  16. namespace views {
  17. class MenuRunner;
  18. }
  19. namespace atom {
  20. class NotifyIconHost;
  21. class NotifyIcon : public TrayIcon {
  22. public:
  23. // Constructor which provides this icon's unique ID and messaging window.
  24. NotifyIcon(NotifyIconHost* host, UINT id, HWND window, UINT message);
  25. virtual ~NotifyIcon();
  26. // Handles a click event from the user - if |left_button_click| is true and
  27. // there is a registered observer, passes the click event to the observer,
  28. // otherwise displays the context menu if there is one.
  29. void HandleClickEvent(int modifiers,
  30. bool left_button_click,
  31. bool double_button_click);
  32. // Re-creates the status tray icon now after the taskbar has been created.
  33. void ResetIcon();
  34. UINT icon_id() const { return icon_id_; }
  35. HWND window() const { return window_; }
  36. UINT message_id() const { return message_id_; }
  37. // Overridden from TrayIcon:
  38. void SetImage(HICON image) override;
  39. void SetPressedImage(HICON image) override;
  40. void SetToolTip(const std::string& tool_tip) override;
  41. void DisplayBalloon(HICON icon,
  42. const base::string16& title,
  43. const base::string16& contents) override;
  44. void PopUpContextMenu(const gfx::Point& pos,
  45. AtomMenuModel* menu_model) override;
  46. void SetContextMenu(AtomMenuModel* menu_model) override;
  47. gfx::Rect GetBounds() override;
  48. private:
  49. void InitIconData(NOTIFYICONDATA* icon_data);
  50. // The tray that owns us. Weak.
  51. NotifyIconHost* host_;
  52. // The unique ID corresponding to this icon.
  53. UINT icon_id_;
  54. // Window used for processing messages from this icon.
  55. HWND window_;
  56. // The message identifier used for status icon messages.
  57. UINT message_id_;
  58. // The currently-displayed icon for the window.
  59. base::win::ScopedHICON icon_;
  60. // The context menu.
  61. AtomMenuModel* menu_model_ = nullptr;
  62. // Context menu associated with this icon (if any).
  63. std::unique_ptr<views::MenuRunner> menu_runner_;
  64. DISALLOW_COPY_AND_ASSIGN(NotifyIcon);
  65. };
  66. } // namespace atom
  67. #endif // ATOM_BROWSER_UI_WIN_NOTIFY_ICON_H_