Ocean
Loading...
Searching...
No Matches
ContextMenu.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_APPLE_MACOS_CONTEXT_MENU_H
9#define META_OCEAN_PLATFORM_APPLE_MACOS_CONTEXT_MENU_H
10
12
13#ifndef __OBJC__
14 #error Platform::Apple::MacOS::ContextMenu.h needs to be included from an ObjectiveC++ file
15#endif
16
17#include <AppKit/AppKit.h>
18
19namespace Ocean
20{
21
22namespace Platform
23{
24
25namespace Apple
26{
27
28namespace MacOS
29{
30
31/**
32 * This class implements a context menu for MacOS platforms.
33 * Mainly, this class wraps a NSMenu object.
34 * @ingroup platformapplemacos
35 */
37{
38 public:
39
40 /**
41 * Creates a new context menu object.
42 */
44
45 /**
46 * Disabled copy constructor preventing to copy a ContextMenu object.
47 * @param contextMenu The context menu to be copied
48 */
49 ContextMenu(const ContextMenu& contextMenu) = delete;
50
51 /**
52 * Creates a new context menu object.
53 * @param contextMenu The context menu to be moved
54 */
55 inline ContextMenu(ContextMenu&& contextMenu) noexcept;
56
57 /**
58 * Adds a new item to the context menu.
59 * @param text The text of the item to be added, "-" for a separator item
60 * @param enabled True, to enabled the item; False, to disable the item
61 * @return The index of the new item, with range [0, infinity)
62 */
63 int addItem(const std::string& text, const bool enabled = true);
64
65 /**
66 * Popups the context menu, blocks the main event queue, and does not return unti the user has made a decision.
67 * @return The index of the item the user selected, -1 if the user did not select any item
68 * @see addItem().
69 */
70 int popup();
71
72 /**
73 * Internal event functions for a selected menu item, should never be called from outside.
74 * @param item The item that has been selected
75 */
76 void onItemSelected(NSMenuItem* item);
77
78 /**
79 * Disabled assign operator preventing to assign a context menu.
80 * @param contextMenu The context menu to be assigned
81 * @return Reference to this object
82 */
83 ContextMenu& operator=(const ContextMenu& contextMenu) = delete;
84
85 /**
86 * Move operator.
87 * @param contextMenu The context menu to be moved
88 * @return Reference to this object
89 */
90 ContextMenu& operator=(ContextMenu&& contextMenu) noexcept;
91
92 protected:
93
94 /// The actual MacOS context menu wrapped by this class.
95 NSMenu* nsMenu_ = nullptr;
96
97 /// The items of the context menus.
99
100 /// The index of the item that has been selected by the user, -1 if no item has been selected.
102};
103
105{
106 *this = std::move(contextMenu);
107}
108
109}
110
111}
112
113}
114
115}
116
117#endif // META_OCEAN_PLATFORM_APPLE_MACOS_CONTEXT_MENU_H
This class implements a context menu for MacOS platforms.
Definition ContextMenu.h:37
int selectedIndex_
The index of the item that has been selected by the user, -1 if no item has been selected.
Definition ContextMenu.h:101
Strings itemTexts_
The items of the context menus.
Definition ContextMenu.h:98
void onItemSelected(NSMenuItem *item)
Internal event functions for a selected menu item, should never be called from outside.
ContextMenu & operator=(const ContextMenu &contextMenu)=delete
Disabled assign operator preventing to assign a context menu.
int popup()
Popups the context menu, blocks the main event queue, and does not return unti the user has made a de...
NSMenu * nsMenu_
The actual MacOS context menu wrapped by this class.
Definition ContextMenu.h:95
ContextMenu(const ContextMenu &contextMenu)=delete
Disabled copy constructor preventing to copy a ContextMenu object.
int addItem(const std::string &text, const bool enabled=true)
Adds a new item to the context menu.
ContextMenu & operator=(ContextMenu &&contextMenu) noexcept
Move operator.
ContextMenu()
Creates a new context menu object.
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition Base.h:162
The namespace covering the entire Ocean framework.
Definition Accessor.h:15