objc2_app_kit/generated/
NSMenuItem.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenuitem?language=objc)
12    #[unsafe(super(NSObject))]
13    #[thread_kind = MainThreadOnly]
14    #[derive(Debug, PartialEq, Eq, Hash)]
15    pub struct NSMenuItem;
16);
17
18#[cfg(feature = "NSAccessibilityProtocols")]
19extern_conformance!(
20    unsafe impl NSAccessibility for NSMenuItem {}
21);
22
23#[cfg(feature = "NSAccessibilityProtocols")]
24extern_conformance!(
25    unsafe impl NSAccessibilityElementProtocol for NSMenuItem {}
26);
27
28extern_conformance!(
29    unsafe impl NSCoding for NSMenuItem {}
30);
31
32extern_conformance!(
33    unsafe impl NSCopying for NSMenuItem {}
34);
35
36unsafe impl CopyingHelper for NSMenuItem {
37    type Result = Self;
38}
39
40extern_conformance!(
41    unsafe impl NSObjectProtocol for NSMenuItem {}
42);
43
44#[cfg(feature = "NSUserInterfaceItemIdentification")]
45extern_conformance!(
46    unsafe impl NSUserInterfaceItemIdentification for NSMenuItem {}
47);
48
49#[cfg(feature = "NSUserInterfaceValidation")]
50extern_conformance!(
51    unsafe impl NSValidatedUserInterfaceItem for NSMenuItem {}
52);
53
54impl NSMenuItem {
55    extern_methods!(
56        #[unsafe(method(usesUserKeyEquivalents))]
57        #[unsafe(method_family = none)]
58        pub fn usesUserKeyEquivalents(mtm: MainThreadMarker) -> bool;
59
60        /// Setter for [`usesUserKeyEquivalents`][Self::usesUserKeyEquivalents].
61        #[unsafe(method(setUsesUserKeyEquivalents:))]
62        #[unsafe(method_family = none)]
63        pub fn setUsesUserKeyEquivalents(uses_user_key_equivalents: bool, mtm: MainThreadMarker);
64
65        #[unsafe(method(separatorItem))]
66        #[unsafe(method_family = none)]
67        pub fn separatorItem(mtm: MainThreadMarker) -> Retained<NSMenuItem>;
68
69        /// Creates a menu item representing a section header with the provided title.
70        /// Section header items are used to provide context to a grouping of menu items.
71        /// Items created using this method are non-interactive and do not perform an action.
72        #[unsafe(method(sectionHeaderWithTitle:))]
73        #[unsafe(method_family = none)]
74        pub fn sectionHeaderWithTitle(title: &NSString, mtm: MainThreadMarker) -> Retained<Self>;
75
76        /// An array of standard menu items related to Writing Tools.
77        /// Each call to this method returns an array of newly allocated instances of NSMenuItem.
78        #[unsafe(method(writingToolsItems))]
79        #[unsafe(method_family = none)]
80        pub fn writingToolsItems(mtm: MainThreadMarker) -> Retained<NSArray<NSMenuItem>>;
81
82        /// # Safety
83        ///
84        /// `selector` must be a valid selector.
85        #[unsafe(method(initWithTitle:action:keyEquivalent:))]
86        #[unsafe(method_family = init)]
87        pub unsafe fn initWithTitle_action_keyEquivalent(
88            this: Allocated<Self>,
89            string: &NSString,
90            selector: Option<Sel>,
91            char_code: &NSString,
92        ) -> Retained<Self>;
93
94        /// # Safety
95        ///
96        /// `coder` possibly has further requirements.
97        #[unsafe(method(initWithCoder:))]
98        #[unsafe(method_family = init)]
99        pub unsafe fn initWithCoder(this: Allocated<Self>, coder: &NSCoder) -> Retained<Self>;
100
101        #[cfg(feature = "NSMenu")]
102        /// Note: Never call the setter method directly: it is there only for subclassers.
103        ///
104        /// # Safety
105        ///
106        /// This is not retained internally, you must ensure the object is still alive.
107        #[unsafe(method(menu))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn menu(&self) -> Option<Retained<NSMenu>>;
110
111        #[cfg(feature = "NSMenu")]
112        /// Setter for [`menu`][Self::menu].
113        ///
114        /// # Safety
115        ///
116        /// This is unretained, you must ensure the object is kept alive while in use.
117        #[unsafe(method(setMenu:))]
118        #[unsafe(method_family = none)]
119        pub unsafe fn setMenu(&self, menu: Option<&NSMenu>);
120
121        #[unsafe(method(hasSubmenu))]
122        #[unsafe(method_family = none)]
123        pub fn hasSubmenu(&self) -> bool;
124
125        #[cfg(feature = "NSMenu")]
126        #[unsafe(method(submenu))]
127        #[unsafe(method_family = none)]
128        pub fn submenu(&self) -> Option<Retained<NSMenu>>;
129
130        #[cfg(feature = "NSMenu")]
131        /// Setter for [`submenu`][Self::submenu].
132        #[unsafe(method(setSubmenu:))]
133        #[unsafe(method_family = none)]
134        pub fn setSubmenu(&self, submenu: Option<&NSMenu>);
135
136        /// Returns: The `NSMenuItem` whose submenu contains the receiver, or nil if the receiver does not have a parent item.
137        ///
138        /// # Safety
139        ///
140        /// This is not retained internally, you must ensure the object is still alive.
141        #[unsafe(method(parentItem))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn parentItem(&self) -> Option<Retained<NSMenuItem>>;
144
145        #[unsafe(method(title))]
146        #[unsafe(method_family = none)]
147        pub fn title(&self) -> Retained<NSString>;
148
149        /// Setter for [`title`][Self::title].
150        ///
151        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
152        #[unsafe(method(setTitle:))]
153        #[unsafe(method_family = none)]
154        pub fn setTitle(&self, title: &NSString);
155
156        #[unsafe(method(attributedTitle))]
157        #[unsafe(method_family = none)]
158        pub fn attributedTitle(&self) -> Option<Retained<NSAttributedString>>;
159
160        /// Setter for [`attributedTitle`][Self::attributedTitle].
161        ///
162        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
163        #[unsafe(method(setAttributedTitle:))]
164        #[unsafe(method_family = none)]
165        pub fn setAttributedTitle(&self, attributed_title: Option<&NSAttributedString>);
166
167        /// Used to specify a standard subtitle for the menu item.
168        ///
169        /// The subtitle is displayed below the standard title.
170        ///
171        /// Note: On macOS 14, a menu item with an attributed title does not show the subtitle. The subtitle is shown on macOS 15 and later.
172        #[unsafe(method(subtitle))]
173        #[unsafe(method_family = none)]
174        pub fn subtitle(&self) -> Option<Retained<NSString>>;
175
176        /// Setter for [`subtitle`][Self::subtitle].
177        ///
178        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
179        #[unsafe(method(setSubtitle:))]
180        #[unsafe(method_family = none)]
181        pub fn setSubtitle(&self, subtitle: Option<&NSString>);
182
183        #[unsafe(method(isSeparatorItem))]
184        #[unsafe(method_family = none)]
185        pub fn isSeparatorItem(&self) -> bool;
186
187        /// Indicates whether the item is a section header.
188        /// Section header items are created using the `sectionHeader(title:)` class method.
189        #[unsafe(method(isSectionHeader))]
190        #[unsafe(method_family = none)]
191        pub fn isSectionHeader(&self) -> bool;
192
193        #[unsafe(method(keyEquivalent))]
194        #[unsafe(method_family = none)]
195        pub fn keyEquivalent(&self) -> Retained<NSString>;
196
197        /// Setter for [`keyEquivalent`][Self::keyEquivalent].
198        ///
199        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
200        #[unsafe(method(setKeyEquivalent:))]
201        #[unsafe(method_family = none)]
202        pub fn setKeyEquivalent(&self, key_equivalent: &NSString);
203
204        #[cfg(feature = "NSEvent")]
205        #[unsafe(method(keyEquivalentModifierMask))]
206        #[unsafe(method_family = none)]
207        pub fn keyEquivalentModifierMask(&self) -> NSEventModifierFlags;
208
209        #[cfg(feature = "NSEvent")]
210        /// Setter for [`keyEquivalentModifierMask`][Self::keyEquivalentModifierMask].
211        #[unsafe(method(setKeyEquivalentModifierMask:))]
212        #[unsafe(method_family = none)]
213        pub fn setKeyEquivalentModifierMask(
214            &self,
215            key_equivalent_modifier_mask: NSEventModifierFlags,
216        );
217
218        #[unsafe(method(userKeyEquivalent))]
219        #[unsafe(method_family = none)]
220        pub fn userKeyEquivalent(&self) -> Retained<NSString>;
221
222        #[unsafe(method(allowsKeyEquivalentWhenHidden))]
223        #[unsafe(method_family = none)]
224        pub fn allowsKeyEquivalentWhenHidden(&self) -> bool;
225
226        /// Setter for [`allowsKeyEquivalentWhenHidden`][Self::allowsKeyEquivalentWhenHidden].
227        #[unsafe(method(setAllowsKeyEquivalentWhenHidden:))]
228        #[unsafe(method_family = none)]
229        pub fn setAllowsKeyEquivalentWhenHidden(&self, allows_key_equivalent_when_hidden: bool);
230
231        #[unsafe(method(allowsAutomaticKeyEquivalentLocalization))]
232        #[unsafe(method_family = none)]
233        pub fn allowsAutomaticKeyEquivalentLocalization(&self) -> bool;
234
235        /// Setter for [`allowsAutomaticKeyEquivalentLocalization`][Self::allowsAutomaticKeyEquivalentLocalization].
236        #[unsafe(method(setAllowsAutomaticKeyEquivalentLocalization:))]
237        #[unsafe(method_family = none)]
238        pub fn setAllowsAutomaticKeyEquivalentLocalization(
239            &self,
240            allows_automatic_key_equivalent_localization: bool,
241        );
242
243        #[unsafe(method(allowsAutomaticKeyEquivalentMirroring))]
244        #[unsafe(method_family = none)]
245        pub fn allowsAutomaticKeyEquivalentMirroring(&self) -> bool;
246
247        /// Setter for [`allowsAutomaticKeyEquivalentMirroring`][Self::allowsAutomaticKeyEquivalentMirroring].
248        #[unsafe(method(setAllowsAutomaticKeyEquivalentMirroring:))]
249        #[unsafe(method_family = none)]
250        pub fn setAllowsAutomaticKeyEquivalentMirroring(
251            &self,
252            allows_automatic_key_equivalent_mirroring: bool,
253        );
254
255        #[cfg(feature = "NSImage")]
256        #[unsafe(method(image))]
257        #[unsafe(method_family = none)]
258        pub fn image(&self) -> Option<Retained<NSImage>>;
259
260        #[cfg(feature = "NSImage")]
261        /// Setter for [`image`][Self::image].
262        #[unsafe(method(setImage:))]
263        #[unsafe(method_family = none)]
264        pub fn setImage(&self, image: Option<&NSImage>);
265
266        #[cfg(feature = "NSCell")]
267        #[unsafe(method(state))]
268        #[unsafe(method_family = none)]
269        pub fn state(&self) -> NSControlStateValue;
270
271        #[cfg(feature = "NSCell")]
272        /// Setter for [`state`][Self::state].
273        #[unsafe(method(setState:))]
274        #[unsafe(method_family = none)]
275        pub fn setState(&self, state: NSControlStateValue);
276
277        #[cfg(feature = "NSImage")]
278        #[unsafe(method(onStateImage))]
279        #[unsafe(method_family = none)]
280        pub fn onStateImage(&self) -> Option<Retained<NSImage>>;
281
282        #[cfg(feature = "NSImage")]
283        /// Setter for [`onStateImage`][Self::onStateImage].
284        ///
285        /// # Safety
286        ///
287        /// `on_state_image` might not allow `None`.
288        #[unsafe(method(setOnStateImage:))]
289        #[unsafe(method_family = none)]
290        pub unsafe fn setOnStateImage(&self, on_state_image: Option<&NSImage>);
291
292        #[cfg(feature = "NSImage")]
293        #[unsafe(method(offStateImage))]
294        #[unsafe(method_family = none)]
295        pub fn offStateImage(&self) -> Option<Retained<NSImage>>;
296
297        #[cfg(feature = "NSImage")]
298        /// Setter for [`offStateImage`][Self::offStateImage].
299        #[unsafe(method(setOffStateImage:))]
300        #[unsafe(method_family = none)]
301        pub fn setOffStateImage(&self, off_state_image: Option<&NSImage>);
302
303        #[cfg(feature = "NSImage")]
304        #[unsafe(method(mixedStateImage))]
305        #[unsafe(method_family = none)]
306        pub fn mixedStateImage(&self) -> Option<Retained<NSImage>>;
307
308        #[cfg(feature = "NSImage")]
309        /// Setter for [`mixedStateImage`][Self::mixedStateImage].
310        ///
311        /// # Safety
312        ///
313        /// `mixed_state_image` might not allow `None`.
314        #[unsafe(method(setMixedStateImage:))]
315        #[unsafe(method_family = none)]
316        pub unsafe fn setMixedStateImage(&self, mixed_state_image: Option<&NSImage>);
317
318        #[unsafe(method(isEnabled))]
319        #[unsafe(method_family = none)]
320        pub fn isEnabled(&self) -> bool;
321
322        /// Setter for [`isEnabled`][Self::isEnabled].
323        #[unsafe(method(setEnabled:))]
324        #[unsafe(method_family = none)]
325        pub fn setEnabled(&self, enabled: bool);
326
327        #[unsafe(method(isAlternate))]
328        #[unsafe(method_family = none)]
329        pub fn isAlternate(&self) -> bool;
330
331        /// Setter for [`isAlternate`][Self::isAlternate].
332        #[unsafe(method(setAlternate:))]
333        #[unsafe(method_family = none)]
334        pub fn setAlternate(&self, alternate: bool);
335
336        #[unsafe(method(indentationLevel))]
337        #[unsafe(method_family = none)]
338        pub fn indentationLevel(&self) -> NSInteger;
339
340        /// Setter for [`indentationLevel`][Self::indentationLevel].
341        #[unsafe(method(setIndentationLevel:))]
342        #[unsafe(method_family = none)]
343        pub fn setIndentationLevel(&self, indentation_level: NSInteger);
344
345        #[unsafe(method(target))]
346        #[unsafe(method_family = none)]
347        pub fn target(&self) -> Option<Retained<AnyObject>>;
348
349        /// Setter for [`target`][Self::target].
350        ///
351        /// This is a [weak property][objc2::topics::weak_property].
352        ///
353        /// # Safety
354        ///
355        /// `target` should be of the correct type.
356        #[unsafe(method(setTarget:))]
357        #[unsafe(method_family = none)]
358        pub unsafe fn setTarget(&self, target: Option<&AnyObject>);
359
360        #[unsafe(method(action))]
361        #[unsafe(method_family = none)]
362        pub fn action(&self) -> Option<Sel>;
363
364        /// Setter for [`action`][Self::action].
365        ///
366        /// # Safety
367        ///
368        /// `action` must be a valid selector.
369        #[unsafe(method(setAction:))]
370        #[unsafe(method_family = none)]
371        pub unsafe fn setAction(&self, action: Option<Sel>);
372
373        #[unsafe(method(tag))]
374        #[unsafe(method_family = none)]
375        pub fn tag(&self) -> NSInteger;
376
377        /// Setter for [`tag`][Self::tag].
378        #[unsafe(method(setTag:))]
379        #[unsafe(method_family = none)]
380        pub fn setTag(&self, tag: NSInteger);
381
382        #[unsafe(method(representedObject))]
383        #[unsafe(method_family = none)]
384        pub fn representedObject(&self) -> Option<Retained<AnyObject>>;
385
386        /// Setter for [`representedObject`][Self::representedObject].
387        ///
388        /// # Safety
389        ///
390        /// `represented_object` should be of the correct type.
391        #[unsafe(method(setRepresentedObject:))]
392        #[unsafe(method_family = none)]
393        pub unsafe fn setRepresentedObject(&self, represented_object: Option<&AnyObject>);
394
395        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
396        #[unsafe(method(view))]
397        #[unsafe(method_family = none)]
398        pub fn view(&self) -> Option<Retained<NSView>>;
399
400        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
401        /// Setter for [`view`][Self::view].
402        #[unsafe(method(setView:))]
403        #[unsafe(method_family = none)]
404        pub fn setView(&self, view: Option<&NSView>);
405
406        #[unsafe(method(isHighlighted))]
407        #[unsafe(method_family = none)]
408        pub fn isHighlighted(&self) -> bool;
409
410        #[unsafe(method(isHidden))]
411        #[unsafe(method_family = none)]
412        pub fn isHidden(&self) -> bool;
413
414        /// Setter for [`isHidden`][Self::isHidden].
415        #[unsafe(method(setHidden:))]
416        #[unsafe(method_family = none)]
417        pub fn setHidden(&self, hidden: bool);
418
419        #[unsafe(method(isHiddenOrHasHiddenAncestor))]
420        #[unsafe(method_family = none)]
421        pub fn isHiddenOrHasHiddenAncestor(&self) -> bool;
422
423        #[unsafe(method(toolTip))]
424        #[unsafe(method_family = none)]
425        pub fn toolTip(&self) -> Option<Retained<NSString>>;
426
427        /// Setter for [`toolTip`][Self::toolTip].
428        ///
429        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
430        #[unsafe(method(setToolTip:))]
431        #[unsafe(method_family = none)]
432        pub fn setToolTip(&self, tool_tip: Option<&NSString>);
433
434        #[cfg(feature = "NSMenuItemBadge")]
435        /// A badge used to provide additional quantitative information specific to
436        /// the menu item, such as the number of available updates.
437        ///
438        ///
439        /// Note: The default value of this property is
440        /// `nil.`
441        #[unsafe(method(badge))]
442        #[unsafe(method_family = none)]
443        pub fn badge(&self) -> Option<Retained<NSMenuItemBadge>>;
444
445        #[cfg(feature = "NSMenuItemBadge")]
446        /// Setter for [`badge`][Self::badge].
447        ///
448        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
449        #[unsafe(method(setBadge:))]
450        #[unsafe(method_family = none)]
451        pub fn setBadge(&self, badge: Option<&NSMenuItemBadge>);
452    );
453}
454
455/// Methods declared on superclass `NSObject`.
456impl NSMenuItem {
457    extern_methods!(
458        #[unsafe(method(init))]
459        #[unsafe(method_family = init)]
460        pub fn init(this: Allocated<Self>) -> Retained<Self>;
461
462        #[unsafe(method(new))]
463        #[unsafe(method_family = new)]
464        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
465    );
466}
467
468/// NSViewEnclosingMenuItem.
469#[cfg(all(feature = "NSResponder", feature = "NSView"))]
470impl NSView {
471    extern_methods!(
472        #[unsafe(method(enclosingMenuItem))]
473        #[unsafe(method_family = none)]
474        pub fn enclosingMenuItem(&self) -> Option<Retained<NSMenuItem>>;
475    );
476}
477
478extern "C" {
479    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenuitemimportfromdeviceidentifier?language=objc)
480    #[cfg(feature = "NSUserInterfaceItemIdentification")]
481    pub static NSMenuItemImportFromDeviceIdentifier: &'static NSUserInterfaceItemIdentifier;
482}
483
484/// NSDeprecated.
485impl NSMenuItem {
486    extern_methods!(
487        #[deprecated]
488        #[unsafe(method(setMnemonicLocation:))]
489        #[unsafe(method_family = none)]
490        pub fn setMnemonicLocation(&self, location: NSUInteger);
491
492        #[deprecated]
493        #[unsafe(method(mnemonicLocation))]
494        #[unsafe(method_family = none)]
495        pub fn mnemonicLocation(&self) -> NSUInteger;
496
497        #[deprecated]
498        #[unsafe(method(mnemonic))]
499        #[unsafe(method_family = none)]
500        pub fn mnemonic(&self) -> Option<Retained<NSString>>;
501
502        #[deprecated]
503        #[unsafe(method(setTitleWithMnemonic:))]
504        #[unsafe(method_family = none)]
505        pub fn setTitleWithMnemonic(&self, string_with_ampersand: &NSString);
506    );
507}