1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
use objc::{class, msg_send, sel, sel_impl};
use crate::{
core_graphics::CGRectEdge,
foundation::{NSCoder, NSRect, NSSize},
object,
objective_c_runtime::{id, traits::FromId},
utils::to_bool,
};
use super::{
interface_impl, ns_appearance::NSAppearance, INSResponder, INSView, INSViewController,
NSPopoverBehavior, NSViewController,
};
object! {
/// A means to display additional content related to existing content on the screen.
unsafe pub struct NSPopover;
}
impl NSPopover {
/// Creates a new popover.
pub fn new() -> Self {
unsafe { Self::from_id(msg_send![class!(NSPopover), new]) }
}
}
impl Default for NSPopover {
fn default() -> Self {
Self::new()
}
}
impl INSResponder for NSPopover {}
#[interface_impl(NSResponder)]
impl NSPopover {
/* Accessing a Popover’s Content View Controller
*/
/// The view controller that manages the content of the popover.
#[property]
pub fn content_view_controller(&self) -> NSViewController {
unsafe { NSViewController::from_id(msg_send![self.m_self(), contentViewController]) }
}
/// Sets the view controller that manages the content of the popover.
///
/// # Arguments
///
/// * `view_controller` - The view controller that manages the content of the popover.
#[property]
pub fn set_content_view_controller<Controller>(&self, view_controller: Controller)
where
Controller: INSViewController,
{
unsafe { msg_send![self.m_self(), setContentViewController: view_controller] }
}
/* Managing a Popover's Position and Size */
/// Specifies the behavior of the popover.
#[property]
pub fn behavior(&self) -> NSPopoverBehavior {
unsafe { msg_send![self.m_self(), behavior] }
}
/// Sets the behavior of the popover.
///
/// # Arguments
///
/// * `behavior` - The behavior of the popover.
#[property]
pub fn set_behavior(&self, behavior: NSPopoverBehavior) {
unsafe { msg_send![self.m_self(), setBehavior: behavior] }
}
/// Shows the popover anchored to the specified view.
#[method]
pub fn show_relative_to_rect_of_view_preferred_edge<V>(
&self,
rect: NSRect,
view: V,
edge: CGRectEdge,
) where
V: INSView,
{
unsafe {
msg_send![self.m_self(), showRelativeToRect: rect ofView: view preferredEdge: edge]
}
}
/// The rectangle within the positioning view relative to which the popover should be positioned.
#[property]
pub fn positioning_rect(&self) -> NSRect {
unsafe { msg_send![self.m_self(), positioningRect] }
}
/* Managing a Popover's Appearance
*/
/// The appearance of the popover.
#[property]
pub fn appearance(&self) -> NSAppearance {
unsafe { NSAppearance::from_id(msg_send![self.m_self(), appearance]) }
}
/// Sets the appearance of the popover.
///
/// # Arguments
///
/// * `appearance` - The appearance to use.
#[method]
pub fn set_appearance(&self, appearance: NSAppearance) {
unsafe { msg_send![self.m_self(), setAppearance: appearance] }
}
/// The appearance that will be used when the popover is displayed onscreen.
#[property]
pub fn effective_appearance(&self) -> NSAppearance {
unsafe { NSAppearance::from_id(msg_send![self.m_self(), effectiveAppearance]) }
}
/// Specifies if the popover is to be animated.
#[property]
pub fn animates(&self) -> bool {
unsafe { to_bool(msg_send![self.m_self(), animates]) }
}
/// The content size of the popover.
#[property]
pub fn content_size(&self) -> NSSize {
unsafe { msg_send![self.m_self(), contentSize] }
}
/// Sets the content size of the popover.
///
/// # Arguments
///
/// * `size` - The size to use.
#[property]
pub fn set_content_size(&self, size: NSSize) {
unsafe { msg_send![self.m_self(), setContentSize: size] }
}
/// The display state of the popover.
#[property]
pub fn shown(&self) -> bool {
unsafe { to_bool(msg_send![self.m_self(), isShown]) }
}
/// A Boolean value that indicates whether the window created by a popover's detachment is automatically created.
#[property]
pub fn detached(&self) -> bool {
unsafe { to_bool(msg_send![self.m_self(), isDetached]) }
}
/* Closing a Popover
*/
/// Attempts to close the popover.
#[method]
pub fn perform_close(&self, sender: id) {
unsafe { msg_send![self.m_self(), performClose: sender] }
}
/// Forces the popover to close without consulting its delegate.
#[method]
pub fn close(&self) {
unsafe { msg_send![self.m_self(), close] }
}
/// The delegate of the popover.
#[property]
pub fn delegate(&self) -> id {
unsafe { msg_send![self.m_self(), delegate] }
}
/// Sets the delegate of the popover.
///
/// # Arguments
///
/// * `delegate` - The delegate to use.
#[method]
pub fn set_delegate(&self, delegate: id) {
unsafe { msg_send![self.m_self(), setDelegate: delegate] }
}
/* Initializers
*/
/// Creates a new popover.
#[method]
pub fn init(&self) -> NSPopover {
unsafe { msg_send![self.m_self(), init] }
}
/// Creates a new popover with `NSCoder`
#[method]
pub fn init_with_coder(&self, coder: NSCoder) -> NSPopover {
unsafe { msg_send![self.m_self(), initWithCoder: coder] }
}
}