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
11
#include "
ocean/platform/apple/macos/MacOS.h
"
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
19
namespace
Ocean
20
{
21
22
namespace
Platform
23
{
24
25
namespace
Apple
26
{
27
28
namespace
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
*/
36
class
ContextMenu
37
{
38
public
:
39
40
/**
41
* Creates a new context menu object.
42
*/
43
ContextMenu
();
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.
98
Strings
itemTexts_
;
99
100
/// The index of the item that has been selected by the user, -1 if no item has been selected.
101
int
selectedIndex_
= -1;
102
};
103
104
ContextMenu::ContextMenu
(
ContextMenu
&& contextMenu)
noexcept
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
MacOS.h
Ocean::Platform::Apple::MacOS::ContextMenu
This class implements a context menu for MacOS platforms.
Definition
ContextMenu.h:37
Ocean::Platform::Apple::MacOS::ContextMenu::selectedIndex_
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
Ocean::Platform::Apple::MacOS::ContextMenu::itemTexts_
Strings itemTexts_
The items of the context menus.
Definition
ContextMenu.h:98
Ocean::Platform::Apple::MacOS::ContextMenu::onItemSelected
void onItemSelected(NSMenuItem *item)
Internal event functions for a selected menu item, should never be called from outside.
Ocean::Platform::Apple::MacOS::ContextMenu::operator=
ContextMenu & operator=(const ContextMenu &contextMenu)=delete
Disabled assign operator preventing to assign a context menu.
Ocean::Platform::Apple::MacOS::ContextMenu::popup
int popup()
Popups the context menu, blocks the main event queue, and does not return unti the user has made a de...
Ocean::Platform::Apple::MacOS::ContextMenu::nsMenu_
NSMenu * nsMenu_
The actual MacOS context menu wrapped by this class.
Definition
ContextMenu.h:95
Ocean::Platform::Apple::MacOS::ContextMenu::ContextMenu
ContextMenu(const ContextMenu &contextMenu)=delete
Disabled copy constructor preventing to copy a ContextMenu object.
Ocean::Platform::Apple::MacOS::ContextMenu::addItem
int addItem(const std::string &text, const bool enabled=true)
Adds a new item to the context menu.
Ocean::Platform::Apple::MacOS::ContextMenu::operator=
ContextMenu & operator=(ContextMenu &&contextMenu) noexcept
Move operator.
Ocean::Platform::Apple::MacOS::ContextMenu::ContextMenu
ContextMenu()
Creates a new context menu object.
Ocean::Strings
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition
Base.h:162
Ocean
The namespace covering the entire Ocean framework.
Definition
Accessor.h:15
impl
ocean
platform
apple
macos
ContextMenu.h
Generated on Wed Aug 12 2026 06:32:24 for Ocean by
1.9.8