libnick 2025.1.0
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
notifyiconmenu.h
Go to the documentation of this file.
1
23#ifdef _WIN32
24#ifndef NOTIFYICONMENU_H
25#define NOTIFYICONMENU_H
26
27#include <functional>
28#include <memory>
29#include <string>
30#include <vector>
31
33{
38 {
39 Action = 0,
40 Separator = 1
41 };
42
47 {
48 public:
57 virtual ~NotifyIconMenuItem() = default;
63
64 private:
66 };
67
79
84 {
85 public:
91 NotifyIconActionMenuItem(const std::string& label, const std::function<void()>& action);
96 const std::string& getLabel() const;
100 void invoke() const;
104 void operator()() const;
105
106 private:
107 std::string m_label;
108 std::function<void()> m_action;
109 };
110
115 {
116 public:
120 NotifyIconMenu() = default;
125 size_t size() const;
130 bool empty() const;
137 const std::shared_ptr<NotifyIconMenuItem>& get(size_t index) const;
142 size_t addSeparator();
148 bool insertSeparator(size_t index);
154 bool removeSeparator(size_t index);
161 size_t addAction(const std::string& label, const std::function<void()>& action);
169 bool insertAction(size_t index, const std::string& label, const std::function<void()>& action);
175 bool removeAction(size_t index);
182 const std::shared_ptr<NotifyIconMenuItem>& operator[](size_t index) const;
183
184 private:
185 std::vector<std::shared_ptr<NotifyIconMenuItem>> m_items;
186 };
187}
188
189#endif //NOTIFYICONMENU_H
190#endif
An actionable menu item for a NotifyIcon.
Definition notifyiconmenu.h:84
void operator()() const
Calls the callback function of the menu item.
NotifyIconActionMenuItem(const std::string &label, const std::function< void()> &action)
Constructs a NotifyIconActionMenuItem.
const std::string & getLabel() const
Gets the label for the menu item.
void invoke() const
Calls the callback function of the menu item.
A generic menu item for a NotifyIcon.
Definition notifyiconmenu.h:47
NotifyIconMenuItemType getType() const
Gets the type of the menu item.
virtual ~NotifyIconMenuItem()=default
Destructs a NotifyIconMenuItem.
NotifyIconMenuItem(NotifyIconMenuItemType type)
Constructs a NotifyIconMenuItem.
A menu for a NotifyIcon.
Definition notifyiconmenu.h:115
bool removeAction(size_t index)
Removes an action item at a given index in the menu.
bool empty() const
Gets whether or not the menu is empty.
bool removeSeparator(size_t index)
Removes a separator at a given index in the menu.
const std::shared_ptr< NotifyIconMenuItem > & operator[](size_t index) const
Gets the NotifyIconMenuItem at a given index in the menu.
bool insertSeparator(size_t index)
Inserts a separator at a given index in the menu.
size_t addSeparator()
Adds a separator to the bottom of the menu.
const std::shared_ptr< NotifyIconMenuItem > & get(size_t index) const
Gets the NotifyIconMenuItem at a given index in the menu.
size_t size() const
Gets the number of items in the menu.
size_t addAction(const std::string &label, const std::function< void()> &action)
Adds an action item to the bottom of the menu.
bool insertAction(size_t index, const std::string &label, const std::function< void()> &action)
Inserts an action item at a given index in the menu.
NotifyIconMenu()=default
Constructs a NotifyIconMenu.
A separator menu item for a NotifyIcon.
Definition notifyiconmenu.h:72
NotifyIconSeparatorMenuItem()
Constructs a NotifyIconSeparatorMenuItem.
Definition notificationsenteventargs.h:31
NotifyIconMenuItemType
Types of menu items for a NotifyIcon.
Definition notifyiconmenu.h:38
@ Action
A menu item that can be clicked.