Ocean
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
protected
:
39
40
/**
41
* Definition of a vector holding a string.
42
*/
43
typedef
std::vector<std::string>
Strings
;
44
45
public
:
46
47
/**
48
* Creates a new context menu object.
49
*/
50
ContextMenu
();
51
52
/**
53
* Disabled copy constructor preventing to copy a ContextMenu object.
54
* @param contextMenu The context menu to be copied
55
*/
56
ContextMenu
(
const
ContextMenu
& contextMenu) =
delete
;
57
58
/**
59
* Creates a new context menu object.
60
* @param contextMenu The context menu to be moved
61
*/
62
inline
ContextMenu
(
ContextMenu
&& contextMenu) noexcept;
63
64
/**
65
* Adds a new item to the context menu.
66
* @param text The text of the item to be added, "-" for a separator item
67
* @param enabled True, to enabled the item; False, to disable the item
68
* @return The index of the new item, with range [0, infinity)
69
*/
70
int
addItem
(
const
std::string& text,
const
bool
enabled =
true
);
71
72
/**
73
* Popups the context menu, blocks the main event queue, and does not return unti the user has made a decision.
74
* @return The index of the item the user selected, -1 if the user did not select any item
75
* @see addItem().
76
*/
77
int
popup
();
78
79
/**
80
* Internal event functions for a selected menu item, should never be called from outside.
81
* @param item The item that has been selected
82
*/
83
void
onItemSelected
(NSMenuItem* item);
84
85
/**
86
* Disabled assign operator preventing to assign a context menu.
87
* @param contextMenu The context menu to be assigned
88
* @return Reference to this object
89
*/
90
ContextMenu
&
operator=
(
const
ContextMenu
& contextMenu) =
delete
;
91
92
/**
93
* Move operator.
94
* @param contextMenu The context menu to be moved
95
* @return Reference to this object
96
*/
97
ContextMenu
&
operator=
(
ContextMenu
&& contextMenu) noexcept;
98
99
protected
:
100
101
/// The actual MacOS context menu wrapped by this class.
102
NSMenu*
contextMenuNSMenu
;
103
104
/// The items of the context menus.
105
Strings
contextMenuItemTexts
;
106
107
/// The index of the item that has been selected by the user, -1 if no item has been selected.
108
int
contextSelectedIndex
;
109
};
110
111
ContextMenu::ContextMenu
(
ContextMenu
&& contextMenu) noexcept :
112
ContextMenu
()
113
{
114
*
this
= std::move(contextMenu);
115
}
116
117
}
118
119
}
120
121
}
122
123
}
124
125
#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::contextSelectedIndex
int contextSelectedIndex
The index of the item that has been selected by the user, -1 if no item has been selected.
Definition:
ContextMenu.h:108
Ocean::Platform::Apple::MacOS::ContextMenu::contextMenuItemTexts
Strings contextMenuItemTexts
The items of the context menus.
Definition:
ContextMenu.h:105
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::Strings
std::vector< std::string > Strings
Definition of a vector holding a string.
Definition:
ContextMenu.h:43
Ocean::Platform::Apple::MacOS::ContextMenu::contextMenuNSMenu
NSMenu * contextMenuNSMenu
The actual MacOS context menu wrapped by this class.
Definition:
ContextMenu.h:102
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::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=(const ContextMenu &contextMenu)=delete
Disabled assign operator preventing to assign a context menu.
Ocean::Platform::Apple::MacOS::ContextMenu::ContextMenu
ContextMenu()
Creates a new context menu object.
Ocean::Platform::Apple::MacOS::ContextMenu::operator=
ContextMenu & operator=(ContextMenu &&contextMenu) noexcept
Move operator.
Ocean
The namespace covering the entire Ocean framework.
Definition:
Accessor.h:15
impl
ocean
platform
apple
macos
ContextMenu.h
Generated on Wed Nov 13 2024 18:48:16 for Ocean by
1.9.1