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 unsafe fn usesUserKeyEquivalents(mtm: MainThreadMarker) -> bool;
59
60        /// Setter for [`usesUserKeyEquivalents`][Self::usesUserKeyEquivalents].
61        #[unsafe(method(setUsesUserKeyEquivalents:))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn setUsesUserKeyEquivalents(
64            uses_user_key_equivalents: bool,
65            mtm: MainThreadMarker,
66        );
67
68        #[unsafe(method(separatorItem))]
69        #[unsafe(method_family = none)]
70        pub fn separatorItem(mtm: MainThreadMarker) -> Retained<NSMenuItem>;
71
72        /// Creates a menu item representing a section header with the provided title.
73        /// Section header items are used to provide context to a grouping of menu items.
74        /// Items created using this method are non-interactive and do not perform an action.
75        #[unsafe(method(sectionHeaderWithTitle:))]
76        #[unsafe(method_family = none)]
77        pub unsafe fn sectionHeaderWithTitle(
78            title: &NSString,
79            mtm: MainThreadMarker,
80        ) -> Retained<Self>;
81
82        /// An array of standard menu items related to Writing Tools.
83        /// Each call to this method returns an array of newly allocated instances of NSMenuItem.
84        #[unsafe(method(writingToolsItems))]
85        #[unsafe(method_family = none)]
86        pub unsafe fn writingToolsItems(mtm: MainThreadMarker) -> Retained<NSArray<NSMenuItem>>;
87
88        #[unsafe(method(initWithTitle:action:keyEquivalent:))]
89        #[unsafe(method_family = init)]
90        pub unsafe fn initWithTitle_action_keyEquivalent(
91            this: Allocated<Self>,
92            string: &NSString,
93            selector: Option<Sel>,
94            char_code: &NSString,
95        ) -> Retained<Self>;
96
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        #[unsafe(method(menu))]
104        #[unsafe(method_family = none)]
105        pub unsafe fn menu(&self) -> Option<Retained<NSMenu>>;
106
107        #[cfg(feature = "NSMenu")]
108        /// Setter for [`menu`][Self::menu].
109        #[unsafe(method(setMenu:))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn setMenu(&self, menu: Option<&NSMenu>);
112
113        #[unsafe(method(hasSubmenu))]
114        #[unsafe(method_family = none)]
115        pub unsafe fn hasSubmenu(&self) -> bool;
116
117        #[cfg(feature = "NSMenu")]
118        #[unsafe(method(submenu))]
119        #[unsafe(method_family = none)]
120        pub unsafe fn submenu(&self) -> Option<Retained<NSMenu>>;
121
122        #[cfg(feature = "NSMenu")]
123        /// Setter for [`submenu`][Self::submenu].
124        #[unsafe(method(setSubmenu:))]
125        #[unsafe(method_family = none)]
126        pub fn setSubmenu(&self, submenu: Option<&NSMenu>);
127
128        /// Returns: The `NSMenuItem` whose submenu contains the receiver, or nil if the receiver does not have a parent item.
129        #[unsafe(method(parentItem))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn parentItem(&self) -> Option<Retained<NSMenuItem>>;
132
133        #[unsafe(method(title))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn title(&self) -> Retained<NSString>;
136
137        /// Setter for [`title`][Self::title].
138        #[unsafe(method(setTitle:))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn setTitle(&self, title: &NSString);
141
142        #[unsafe(method(attributedTitle))]
143        #[unsafe(method_family = none)]
144        pub unsafe fn attributedTitle(&self) -> Option<Retained<NSAttributedString>>;
145
146        /// Setter for [`attributedTitle`][Self::attributedTitle].
147        #[unsafe(method(setAttributedTitle:))]
148        #[unsafe(method_family = none)]
149        pub unsafe fn setAttributedTitle(&self, attributed_title: Option<&NSAttributedString>);
150
151        /// Used to specify a standard subtitle for the menu item.
152        ///
153        /// The subtitle is displayed below the standard title.
154        ///
155        /// 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.
156        #[unsafe(method(subtitle))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn subtitle(&self) -> Option<Retained<NSString>>;
159
160        /// Setter for [`subtitle`][Self::subtitle].
161        #[unsafe(method(setSubtitle:))]
162        #[unsafe(method_family = none)]
163        pub unsafe fn setSubtitle(&self, subtitle: Option<&NSString>);
164
165        #[unsafe(method(isSeparatorItem))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn isSeparatorItem(&self) -> bool;
168
169        /// Indicates whether the item is a section header.
170        /// Section header items are created using the `sectionHeader(title:)` class method.
171        #[unsafe(method(isSectionHeader))]
172        #[unsafe(method_family = none)]
173        pub unsafe fn isSectionHeader(&self) -> bool;
174
175        #[unsafe(method(keyEquivalent))]
176        #[unsafe(method_family = none)]
177        pub unsafe fn keyEquivalent(&self) -> Retained<NSString>;
178
179        /// Setter for [`keyEquivalent`][Self::keyEquivalent].
180        #[unsafe(method(setKeyEquivalent:))]
181        #[unsafe(method_family = none)]
182        pub unsafe fn setKeyEquivalent(&self, key_equivalent: &NSString);
183
184        #[cfg(feature = "NSEvent")]
185        #[unsafe(method(keyEquivalentModifierMask))]
186        #[unsafe(method_family = none)]
187        pub unsafe fn keyEquivalentModifierMask(&self) -> NSEventModifierFlags;
188
189        #[cfg(feature = "NSEvent")]
190        /// Setter for [`keyEquivalentModifierMask`][Self::keyEquivalentModifierMask].
191        #[unsafe(method(setKeyEquivalentModifierMask:))]
192        #[unsafe(method_family = none)]
193        pub fn setKeyEquivalentModifierMask(
194            &self,
195            key_equivalent_modifier_mask: NSEventModifierFlags,
196        );
197
198        #[unsafe(method(userKeyEquivalent))]
199        #[unsafe(method_family = none)]
200        pub unsafe fn userKeyEquivalent(&self) -> Retained<NSString>;
201
202        #[unsafe(method(allowsKeyEquivalentWhenHidden))]
203        #[unsafe(method_family = none)]
204        pub unsafe fn allowsKeyEquivalentWhenHidden(&self) -> bool;
205
206        /// Setter for [`allowsKeyEquivalentWhenHidden`][Self::allowsKeyEquivalentWhenHidden].
207        #[unsafe(method(setAllowsKeyEquivalentWhenHidden:))]
208        #[unsafe(method_family = none)]
209        pub unsafe fn setAllowsKeyEquivalentWhenHidden(
210            &self,
211            allows_key_equivalent_when_hidden: bool,
212        );
213
214        #[unsafe(method(allowsAutomaticKeyEquivalentLocalization))]
215        #[unsafe(method_family = none)]
216        pub unsafe fn allowsAutomaticKeyEquivalentLocalization(&self) -> bool;
217
218        /// Setter for [`allowsAutomaticKeyEquivalentLocalization`][Self::allowsAutomaticKeyEquivalentLocalization].
219        #[unsafe(method(setAllowsAutomaticKeyEquivalentLocalization:))]
220        #[unsafe(method_family = none)]
221        pub unsafe fn setAllowsAutomaticKeyEquivalentLocalization(
222            &self,
223            allows_automatic_key_equivalent_localization: bool,
224        );
225
226        #[unsafe(method(allowsAutomaticKeyEquivalentMirroring))]
227        #[unsafe(method_family = none)]
228        pub unsafe fn allowsAutomaticKeyEquivalentMirroring(&self) -> bool;
229
230        /// Setter for [`allowsAutomaticKeyEquivalentMirroring`][Self::allowsAutomaticKeyEquivalentMirroring].
231        #[unsafe(method(setAllowsAutomaticKeyEquivalentMirroring:))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn setAllowsAutomaticKeyEquivalentMirroring(
234            &self,
235            allows_automatic_key_equivalent_mirroring: bool,
236        );
237
238        #[cfg(feature = "NSImage")]
239        #[unsafe(method(image))]
240        #[unsafe(method_family = none)]
241        pub unsafe fn image(&self) -> Option<Retained<NSImage>>;
242
243        #[cfg(feature = "NSImage")]
244        /// Setter for [`image`][Self::image].
245        #[unsafe(method(setImage:))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn setImage(&self, image: Option<&NSImage>);
248
249        #[cfg(feature = "NSCell")]
250        #[unsafe(method(state))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn state(&self) -> NSControlStateValue;
253
254        #[cfg(feature = "NSCell")]
255        /// Setter for [`state`][Self::state].
256        #[unsafe(method(setState:))]
257        #[unsafe(method_family = none)]
258        pub unsafe fn setState(&self, state: NSControlStateValue);
259
260        #[cfg(feature = "NSImage")]
261        #[unsafe(method(onStateImage))]
262        #[unsafe(method_family = none)]
263        pub unsafe fn onStateImage(&self) -> Option<Retained<NSImage>>;
264
265        #[cfg(feature = "NSImage")]
266        /// Setter for [`onStateImage`][Self::onStateImage].
267        #[unsafe(method(setOnStateImage:))]
268        #[unsafe(method_family = none)]
269        pub unsafe fn setOnStateImage(&self, on_state_image: Option<&NSImage>);
270
271        #[cfg(feature = "NSImage")]
272        #[unsafe(method(offStateImage))]
273        #[unsafe(method_family = none)]
274        pub unsafe fn offStateImage(&self) -> Option<Retained<NSImage>>;
275
276        #[cfg(feature = "NSImage")]
277        /// Setter for [`offStateImage`][Self::offStateImage].
278        #[unsafe(method(setOffStateImage:))]
279        #[unsafe(method_family = none)]
280        pub unsafe fn setOffStateImage(&self, off_state_image: Option<&NSImage>);
281
282        #[cfg(feature = "NSImage")]
283        #[unsafe(method(mixedStateImage))]
284        #[unsafe(method_family = none)]
285        pub unsafe fn mixedStateImage(&self) -> Option<Retained<NSImage>>;
286
287        #[cfg(feature = "NSImage")]
288        /// Setter for [`mixedStateImage`][Self::mixedStateImage].
289        #[unsafe(method(setMixedStateImage:))]
290        #[unsafe(method_family = none)]
291        pub unsafe fn setMixedStateImage(&self, mixed_state_image: Option<&NSImage>);
292
293        #[unsafe(method(isEnabled))]
294        #[unsafe(method_family = none)]
295        pub unsafe fn isEnabled(&self) -> bool;
296
297        /// Setter for [`isEnabled`][Self::isEnabled].
298        #[unsafe(method(setEnabled:))]
299        #[unsafe(method_family = none)]
300        pub unsafe fn setEnabled(&self, enabled: bool);
301
302        #[unsafe(method(isAlternate))]
303        #[unsafe(method_family = none)]
304        pub unsafe fn isAlternate(&self) -> bool;
305
306        /// Setter for [`isAlternate`][Self::isAlternate].
307        #[unsafe(method(setAlternate:))]
308        #[unsafe(method_family = none)]
309        pub unsafe fn setAlternate(&self, alternate: bool);
310
311        #[unsafe(method(indentationLevel))]
312        #[unsafe(method_family = none)]
313        pub unsafe fn indentationLevel(&self) -> NSInteger;
314
315        /// Setter for [`indentationLevel`][Self::indentationLevel].
316        #[unsafe(method(setIndentationLevel:))]
317        #[unsafe(method_family = none)]
318        pub unsafe fn setIndentationLevel(&self, indentation_level: NSInteger);
319
320        #[unsafe(method(target))]
321        #[unsafe(method_family = none)]
322        pub unsafe fn target(&self) -> Option<Retained<AnyObject>>;
323
324        /// This is a [weak property][objc2::topics::weak_property].
325        /// Setter for [`target`][Self::target].
326        #[unsafe(method(setTarget:))]
327        #[unsafe(method_family = none)]
328        pub unsafe fn setTarget(&self, target: Option<&AnyObject>);
329
330        #[unsafe(method(action))]
331        #[unsafe(method_family = none)]
332        pub unsafe fn action(&self) -> Option<Sel>;
333
334        /// Setter for [`action`][Self::action].
335        #[unsafe(method(setAction:))]
336        #[unsafe(method_family = none)]
337        pub unsafe fn setAction(&self, action: Option<Sel>);
338
339        #[unsafe(method(tag))]
340        #[unsafe(method_family = none)]
341        pub unsafe fn tag(&self) -> NSInteger;
342
343        /// Setter for [`tag`][Self::tag].
344        #[unsafe(method(setTag:))]
345        #[unsafe(method_family = none)]
346        pub unsafe fn setTag(&self, tag: NSInteger);
347
348        #[unsafe(method(representedObject))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn representedObject(&self) -> Option<Retained<AnyObject>>;
351
352        /// Setter for [`representedObject`][Self::representedObject].
353        #[unsafe(method(setRepresentedObject:))]
354        #[unsafe(method_family = none)]
355        pub unsafe fn setRepresentedObject(&self, represented_object: Option<&AnyObject>);
356
357        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
358        #[unsafe(method(view))]
359        #[unsafe(method_family = none)]
360        pub unsafe fn view(&self) -> Option<Retained<NSView>>;
361
362        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
363        /// Setter for [`view`][Self::view].
364        #[unsafe(method(setView:))]
365        #[unsafe(method_family = none)]
366        pub unsafe fn setView(&self, view: Option<&NSView>);
367
368        #[unsafe(method(isHighlighted))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn isHighlighted(&self) -> bool;
371
372        #[unsafe(method(isHidden))]
373        #[unsafe(method_family = none)]
374        pub unsafe fn isHidden(&self) -> bool;
375
376        /// Setter for [`isHidden`][Self::isHidden].
377        #[unsafe(method(setHidden:))]
378        #[unsafe(method_family = none)]
379        pub unsafe fn setHidden(&self, hidden: bool);
380
381        #[unsafe(method(isHiddenOrHasHiddenAncestor))]
382        #[unsafe(method_family = none)]
383        pub unsafe fn isHiddenOrHasHiddenAncestor(&self) -> bool;
384
385        #[unsafe(method(toolTip))]
386        #[unsafe(method_family = none)]
387        pub unsafe fn toolTip(&self) -> Option<Retained<NSString>>;
388
389        /// Setter for [`toolTip`][Self::toolTip].
390        #[unsafe(method(setToolTip:))]
391        #[unsafe(method_family = none)]
392        pub unsafe fn setToolTip(&self, tool_tip: Option<&NSString>);
393
394        #[cfg(feature = "NSMenuItemBadge")]
395        /// A badge used to provide additional quantitative information specific to
396        /// the menu item, such as the number of available updates.
397        ///
398        ///
399        /// Note: The default value of this property is
400        /// `nil.`
401        #[unsafe(method(badge))]
402        #[unsafe(method_family = none)]
403        pub unsafe fn badge(&self) -> Option<Retained<NSMenuItemBadge>>;
404
405        #[cfg(feature = "NSMenuItemBadge")]
406        /// Setter for [`badge`][Self::badge].
407        #[unsafe(method(setBadge:))]
408        #[unsafe(method_family = none)]
409        pub unsafe fn setBadge(&self, badge: Option<&NSMenuItemBadge>);
410    );
411}
412
413/// Methods declared on superclass `NSObject`.
414impl NSMenuItem {
415    extern_methods!(
416        #[unsafe(method(init))]
417        #[unsafe(method_family = init)]
418        pub fn init(this: Allocated<Self>) -> Retained<Self>;
419
420        #[unsafe(method(new))]
421        #[unsafe(method_family = new)]
422        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
423    );
424}
425
426/// NSViewEnclosingMenuItem.
427#[cfg(all(feature = "NSResponder", feature = "NSView"))]
428impl NSView {
429    extern_methods!(
430        #[unsafe(method(enclosingMenuItem))]
431        #[unsafe(method_family = none)]
432        pub unsafe fn enclosingMenuItem(&self) -> Option<Retained<NSMenuItem>>;
433    );
434}
435
436extern "C" {
437    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenuitemimportfromdeviceidentifier?language=objc)
438    #[cfg(feature = "NSUserInterfaceItemIdentification")]
439    pub static NSMenuItemImportFromDeviceIdentifier: &'static NSUserInterfaceItemIdentifier;
440}
441
442/// NSDeprecated.
443impl NSMenuItem {
444    extern_methods!(
445        #[deprecated]
446        #[unsafe(method(setMnemonicLocation:))]
447        #[unsafe(method_family = none)]
448        pub unsafe fn setMnemonicLocation(&self, location: NSUInteger);
449
450        #[deprecated]
451        #[unsafe(method(mnemonicLocation))]
452        #[unsafe(method_family = none)]
453        pub unsafe fn mnemonicLocation(&self) -> NSUInteger;
454
455        #[deprecated]
456        #[unsafe(method(mnemonic))]
457        #[unsafe(method_family = none)]
458        pub unsafe fn mnemonic(&self) -> Option<Retained<NSString>>;
459
460        #[deprecated]
461        #[unsafe(method(setTitleWithMnemonic:))]
462        #[unsafe(method_family = none)]
463        pub unsafe fn setTitleWithMnemonic(&self, string_with_ampersand: &NSString);
464    );
465}