objc2_app_kit/generated/
NSMenu.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::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// When set as a value on `NSMenu.presentationStyle`, determines how
13/// the given menu is presented.
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenupresentationstyle?language=objc)
16// NS_ENUM
17#[repr(transparent)]
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
19pub struct NSMenuPresentationStyle(pub NSInteger);
20impl NSMenuPresentationStyle {
21    /// The default presentation style. Typically means the menu will
22    /// be presented as either a popup or pulldown menu, based on the
23    /// context.
24    #[doc(alias = "NSMenuPresentationStyleRegular")]
25    pub const Regular: Self = Self(0);
26    /// The menu marked as palette is to be displayed in place of the
27    /// menu item presenting it, with its items aligned horizontally.
28    #[doc(alias = "NSMenuPresentationStylePalette")]
29    pub const Palette: Self = Self(1);
30}
31
32unsafe impl Encode for NSMenuPresentationStyle {
33    const ENCODING: Encoding = NSInteger::ENCODING;
34}
35
36unsafe impl RefEncode for NSMenuPresentationStyle {
37    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40/// When set as a value on `NSMenu.selectionMode`, determines how the
41/// menu manages selection states of the menu items that belong to
42/// the same selection group.
43///
44/// This does not apply to menu items that have distinct
45/// target/action values.
46///
47/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenuselectionmode?language=objc)
48// NS_ENUM
49#[repr(transparent)]
50#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
51pub struct NSMenuSelectionMode(pub NSInteger);
52impl NSMenuSelectionMode {
53    /// The menu will determine the appropriate selection mode based
54    /// on the context and its contents.
55    #[doc(alias = "NSMenuSelectionModeAutomatic")]
56    pub const Automatic: Self = Self(0);
57    /// The user will be allowed to select at most one menu item in
58    /// the same selection group at a time. A change in selection
59    /// will deselect any previously selected item.
60    #[doc(alias = "NSMenuSelectionModeSelectOne")]
61    pub const SelectOne: Self = Self(1);
62    /// The user can select multiple items in the menu. A change in
63    /// selection will not automatically deselect any previously
64    /// selected item in the same selection group.
65    #[doc(alias = "NSMenuSelectionModeSelectAny")]
66    pub const SelectAny: Self = Self(2);
67}
68
69unsafe impl Encode for NSMenuSelectionMode {
70    const ENCODING: Encoding = NSInteger::ENCODING;
71}
72
73unsafe impl RefEncode for NSMenuSelectionMode {
74    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
75}
76
77extern_class!(
78    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenu?language=objc)
79    #[unsafe(super(NSObject))]
80    #[thread_kind = MainThreadOnly]
81    #[derive(Debug, PartialEq, Eq, Hash)]
82    pub struct NSMenu;
83);
84
85#[cfg(feature = "NSAccessibilityProtocols")]
86extern_conformance!(
87    unsafe impl NSAccessibility for NSMenu {}
88);
89
90#[cfg(feature = "NSAccessibilityProtocols")]
91extern_conformance!(
92    unsafe impl NSAccessibilityElementProtocol for NSMenu {}
93);
94
95#[cfg(feature = "NSAppearance")]
96extern_conformance!(
97    unsafe impl NSAppearanceCustomization for NSMenu {}
98);
99
100extern_conformance!(
101    unsafe impl NSCoding for NSMenu {}
102);
103
104extern_conformance!(
105    unsafe impl NSCopying for NSMenu {}
106);
107
108unsafe impl CopyingHelper for NSMenu {
109    type Result = Self;
110}
111
112extern_conformance!(
113    unsafe impl NSObjectProtocol for NSMenu {}
114);
115
116#[cfg(feature = "NSUserInterfaceItemIdentification")]
117extern_conformance!(
118    unsafe impl NSUserInterfaceItemIdentification for NSMenu {}
119);
120
121impl NSMenu {
122    extern_methods!(
123        #[unsafe(method(initWithTitle:))]
124        #[unsafe(method_family = init)]
125        pub fn initWithTitle(this: Allocated<Self>, title: &NSString) -> Retained<Self>;
126
127        /// # Safety
128        ///
129        /// `coder` possibly has further requirements.
130        #[unsafe(method(initWithCoder:))]
131        #[unsafe(method_family = init)]
132        pub unsafe fn initWithCoder(this: Allocated<Self>, coder: &NSCoder) -> Retained<Self>;
133
134        #[unsafe(method(title))]
135        #[unsafe(method_family = none)]
136        pub fn title(&self) -> Retained<NSString>;
137
138        /// Setter for [`title`][Self::title].
139        ///
140        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
141        #[unsafe(method(setTitle:))]
142        #[unsafe(method_family = none)]
143        pub fn setTitle(&self, title: &NSString);
144
145        #[cfg(all(feature = "NSEvent", feature = "NSResponder", feature = "NSView"))]
146        #[unsafe(method(popUpContextMenu:withEvent:forView:))]
147        #[unsafe(method_family = none)]
148        pub fn popUpContextMenu_withEvent_forView(menu: &NSMenu, event: &NSEvent, view: &NSView);
149
150        #[cfg(all(
151            feature = "NSEvent",
152            feature = "NSFont",
153            feature = "NSResponder",
154            feature = "NSView"
155        ))]
156        #[unsafe(method(popUpContextMenu:withEvent:forView:withFont:))]
157        #[unsafe(method_family = none)]
158        pub fn popUpContextMenu_withEvent_forView_withFont(
159            menu: &NSMenu,
160            event: &NSEvent,
161            view: &NSView,
162            font: Option<&NSFont>,
163        );
164
165        #[cfg(all(feature = "NSMenuItem", feature = "NSResponder", feature = "NSView"))]
166        #[unsafe(method(popUpMenuPositioningItem:atLocation:inView:))]
167        #[unsafe(method_family = none)]
168        pub fn popUpMenuPositioningItem_atLocation_inView(
169            &self,
170            item: Option<&NSMenuItem>,
171            location: NSPoint,
172            view: Option<&NSView>,
173        ) -> bool;
174
175        #[unsafe(method(setMenuBarVisible:))]
176        #[unsafe(method_family = none)]
177        pub fn setMenuBarVisible(visible: bool, mtm: MainThreadMarker);
178
179        #[unsafe(method(menuBarVisible))]
180        #[unsafe(method_family = none)]
181        pub fn menuBarVisible(mtm: MainThreadMarker) -> bool;
182
183        /// # Safety
184        ///
185        /// This is not retained internally, you must ensure the object is still alive.
186        #[unsafe(method(supermenu))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn supermenu(&self) -> Option<Retained<NSMenu>>;
189
190        /// Setter for [`supermenu`][Self::supermenu].
191        ///
192        /// # Safety
193        ///
194        /// This is unretained, you must ensure the object is kept alive while in use.
195        #[unsafe(method(setSupermenu:))]
196        #[unsafe(method_family = none)]
197        pub unsafe fn setSupermenu(&self, supermenu: Option<&NSMenu>);
198
199        #[cfg(feature = "NSMenuItem")]
200        #[unsafe(method(insertItem:atIndex:))]
201        #[unsafe(method_family = none)]
202        pub fn insertItem_atIndex(&self, new_item: &NSMenuItem, index: NSInteger);
203
204        #[cfg(feature = "NSMenuItem")]
205        #[unsafe(method(addItem:))]
206        #[unsafe(method_family = none)]
207        pub fn addItem(&self, new_item: &NSMenuItem);
208
209        #[cfg(feature = "NSMenuItem")]
210        /// # Safety
211        ///
212        /// `selector` must be a valid selector.
213        #[unsafe(method(insertItemWithTitle:action:keyEquivalent:atIndex:))]
214        #[unsafe(method_family = none)]
215        pub unsafe fn insertItemWithTitle_action_keyEquivalent_atIndex(
216            &self,
217            string: &NSString,
218            selector: Option<Sel>,
219            char_code: &NSString,
220            index: NSInteger,
221        ) -> Retained<NSMenuItem>;
222
223        #[cfg(feature = "NSMenuItem")]
224        /// # Safety
225        ///
226        /// `selector` must be a valid selector.
227        #[unsafe(method(addItemWithTitle:action:keyEquivalent:))]
228        #[unsafe(method_family = none)]
229        pub unsafe fn addItemWithTitle_action_keyEquivalent(
230            &self,
231            string: &NSString,
232            selector: Option<Sel>,
233            char_code: &NSString,
234        ) -> Retained<NSMenuItem>;
235
236        #[unsafe(method(removeItemAtIndex:))]
237        #[unsafe(method_family = none)]
238        pub fn removeItemAtIndex(&self, index: NSInteger);
239
240        #[cfg(feature = "NSMenuItem")]
241        #[unsafe(method(removeItem:))]
242        #[unsafe(method_family = none)]
243        pub fn removeItem(&self, item: &NSMenuItem);
244
245        #[cfg(feature = "NSMenuItem")]
246        #[unsafe(method(setSubmenu:forItem:))]
247        #[unsafe(method_family = none)]
248        pub fn setSubmenu_forItem(&self, menu: Option<&NSMenu>, item: &NSMenuItem);
249
250        #[unsafe(method(removeAllItems))]
251        #[unsafe(method_family = none)]
252        pub fn removeAllItems(&self);
253
254        #[cfg(feature = "NSMenuItem")]
255        #[unsafe(method(itemArray))]
256        #[unsafe(method_family = none)]
257        pub fn itemArray(&self) -> Retained<NSArray<NSMenuItem>>;
258
259        #[cfg(feature = "NSMenuItem")]
260        /// Setter for [`itemArray`][Self::itemArray].
261        ///
262        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
263        #[unsafe(method(setItemArray:))]
264        #[unsafe(method_family = none)]
265        pub fn setItemArray(&self, item_array: &NSArray<NSMenuItem>);
266
267        #[unsafe(method(numberOfItems))]
268        #[unsafe(method_family = none)]
269        pub fn numberOfItems(&self) -> NSInteger;
270
271        #[cfg(feature = "NSMenuItem")]
272        #[unsafe(method(itemAtIndex:))]
273        #[unsafe(method_family = none)]
274        pub fn itemAtIndex(&self, index: NSInteger) -> Option<Retained<NSMenuItem>>;
275
276        #[cfg(feature = "NSMenuItem")]
277        #[unsafe(method(indexOfItem:))]
278        #[unsafe(method_family = none)]
279        pub fn indexOfItem(&self, item: &NSMenuItem) -> NSInteger;
280
281        #[unsafe(method(indexOfItemWithTitle:))]
282        #[unsafe(method_family = none)]
283        pub fn indexOfItemWithTitle(&self, title: &NSString) -> NSInteger;
284
285        #[unsafe(method(indexOfItemWithTag:))]
286        #[unsafe(method_family = none)]
287        pub fn indexOfItemWithTag(&self, tag: NSInteger) -> NSInteger;
288
289        /// # Safety
290        ///
291        /// `object` should be of the correct type.
292        #[unsafe(method(indexOfItemWithRepresentedObject:))]
293        #[unsafe(method_family = none)]
294        pub unsafe fn indexOfItemWithRepresentedObject(
295            &self,
296            object: Option<&AnyObject>,
297        ) -> NSInteger;
298
299        #[unsafe(method(indexOfItemWithSubmenu:))]
300        #[unsafe(method_family = none)]
301        pub fn indexOfItemWithSubmenu(&self, submenu: Option<&NSMenu>) -> NSInteger;
302
303        /// # Safety
304        ///
305        /// - `target` should be of the correct type.
306        /// - `action_selector` must be a valid selector.
307        #[unsafe(method(indexOfItemWithTarget:andAction:))]
308        #[unsafe(method_family = none)]
309        pub unsafe fn indexOfItemWithTarget_andAction(
310            &self,
311            target: Option<&AnyObject>,
312            action_selector: Option<Sel>,
313        ) -> NSInteger;
314
315        #[cfg(feature = "NSMenuItem")]
316        #[unsafe(method(itemWithTitle:))]
317        #[unsafe(method_family = none)]
318        pub fn itemWithTitle(&self, title: &NSString) -> Option<Retained<NSMenuItem>>;
319
320        #[cfg(feature = "NSMenuItem")]
321        #[unsafe(method(itemWithTag:))]
322        #[unsafe(method_family = none)]
323        pub fn itemWithTag(&self, tag: NSInteger) -> Option<Retained<NSMenuItem>>;
324
325        #[unsafe(method(autoenablesItems))]
326        #[unsafe(method_family = none)]
327        pub fn autoenablesItems(&self) -> bool;
328
329        /// Setter for [`autoenablesItems`][Self::autoenablesItems].
330        #[unsafe(method(setAutoenablesItems:))]
331        #[unsafe(method_family = none)]
332        pub fn setAutoenablesItems(&self, autoenables_items: bool);
333
334        #[unsafe(method(update))]
335        #[unsafe(method_family = none)]
336        pub fn update(&self);
337
338        #[cfg(feature = "NSEvent")]
339        #[unsafe(method(performKeyEquivalent:))]
340        #[unsafe(method_family = none)]
341        pub fn performKeyEquivalent(&self, event: &NSEvent) -> bool;
342
343        #[cfg(feature = "NSMenuItem")]
344        #[unsafe(method(itemChanged:))]
345        #[unsafe(method_family = none)]
346        pub fn itemChanged(&self, item: &NSMenuItem);
347
348        #[unsafe(method(performActionForItemAtIndex:))]
349        #[unsafe(method_family = none)]
350        pub fn performActionForItemAtIndex(&self, index: NSInteger);
351
352        #[unsafe(method(delegate))]
353        #[unsafe(method_family = none)]
354        pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSMenuDelegate>>>;
355
356        /// Setter for [`delegate`][Self::delegate].
357        ///
358        /// This is a [weak property][objc2::topics::weak_property].
359        #[unsafe(method(setDelegate:))]
360        #[unsafe(method_family = none)]
361        pub fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSMenuDelegate>>);
362
363        #[cfg(feature = "objc2-core-foundation")]
364        #[unsafe(method(menuBarHeight))]
365        #[unsafe(method_family = none)]
366        pub fn menuBarHeight(&self) -> CGFloat;
367
368        #[unsafe(method(cancelTracking))]
369        #[unsafe(method_family = none)]
370        pub fn cancelTracking(&self);
371
372        #[unsafe(method(cancelTrackingWithoutAnimation))]
373        #[unsafe(method_family = none)]
374        pub fn cancelTrackingWithoutAnimation(&self);
375
376        #[cfg(feature = "NSMenuItem")]
377        #[unsafe(method(highlightedItem))]
378        #[unsafe(method_family = none)]
379        pub fn highlightedItem(&self) -> Option<Retained<NSMenuItem>>;
380
381        #[cfg(feature = "objc2-core-foundation")]
382        #[unsafe(method(minimumWidth))]
383        #[unsafe(method_family = none)]
384        pub fn minimumWidth(&self) -> CGFloat;
385
386        #[cfg(feature = "objc2-core-foundation")]
387        /// Setter for [`minimumWidth`][Self::minimumWidth].
388        #[unsafe(method(setMinimumWidth:))]
389        #[unsafe(method_family = none)]
390        pub fn setMinimumWidth(&self, minimum_width: CGFloat);
391
392        #[unsafe(method(size))]
393        #[unsafe(method_family = none)]
394        pub fn size(&self) -> NSSize;
395
396        #[cfg(feature = "NSFont")]
397        #[unsafe(method(font))]
398        #[unsafe(method_family = none)]
399        pub fn font(&self) -> Option<Retained<NSFont>>;
400
401        #[cfg(feature = "NSFont")]
402        /// Setter for [`font`][Self::font].
403        ///
404        /// # Safety
405        ///
406        /// `font` might not allow `None`.
407        #[unsafe(method(setFont:))]
408        #[unsafe(method_family = none)]
409        pub unsafe fn setFont(&self, font: Option<&NSFont>);
410
411        #[unsafe(method(allowsContextMenuPlugIns))]
412        #[unsafe(method_family = none)]
413        pub fn allowsContextMenuPlugIns(&self) -> bool;
414
415        /// Setter for [`allowsContextMenuPlugIns`][Self::allowsContextMenuPlugIns].
416        #[unsafe(method(setAllowsContextMenuPlugIns:))]
417        #[unsafe(method_family = none)]
418        pub fn setAllowsContextMenuPlugIns(&self, allows_context_menu_plug_ins: bool);
419
420        #[unsafe(method(automaticallyInsertsWritingToolsItems))]
421        #[unsafe(method_family = none)]
422        pub fn automaticallyInsertsWritingToolsItems(&self) -> bool;
423
424        /// Setter for [`automaticallyInsertsWritingToolsItems`][Self::automaticallyInsertsWritingToolsItems].
425        #[unsafe(method(setAutomaticallyInsertsWritingToolsItems:))]
426        #[unsafe(method_family = none)]
427        pub fn setAutomaticallyInsertsWritingToolsItems(
428            &self,
429            automatically_inserts_writing_tools_items: bool,
430        );
431
432        #[unsafe(method(showsStateColumn))]
433        #[unsafe(method_family = none)]
434        pub fn showsStateColumn(&self) -> bool;
435
436        /// Setter for [`showsStateColumn`][Self::showsStateColumn].
437        #[unsafe(method(setShowsStateColumn:))]
438        #[unsafe(method_family = none)]
439        pub fn setShowsStateColumn(&self, shows_state_column: bool);
440
441        #[cfg(feature = "NSUserInterfaceLayout")]
442        #[unsafe(method(userInterfaceLayoutDirection))]
443        #[unsafe(method_family = none)]
444        pub fn userInterfaceLayoutDirection(&self) -> NSUserInterfaceLayoutDirection;
445
446        #[cfg(feature = "NSUserInterfaceLayout")]
447        /// Setter for [`userInterfaceLayoutDirection`][Self::userInterfaceLayoutDirection].
448        #[unsafe(method(setUserInterfaceLayoutDirection:))]
449        #[unsafe(method_family = none)]
450        pub fn setUserInterfaceLayoutDirection(
451            &self,
452            user_interface_layout_direction: NSUserInterfaceLayoutDirection,
453        );
454    );
455}
456
457/// Methods declared on superclass `NSObject`.
458impl NSMenu {
459    extern_methods!(
460        #[unsafe(method(init))]
461        #[unsafe(method_family = init)]
462        pub fn init(this: Allocated<Self>) -> Retained<Self>;
463
464        #[unsafe(method(new))]
465        #[unsafe(method_family = new)]
466        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
467    );
468}
469
470/// NSPaletteMenus.
471impl NSMenu {
472    extern_methods!(
473        #[cfg(all(feature = "NSColor", feature = "block2"))]
474        /// Creates a palette menu displaying user-selectable color
475        /// tags using the provided array of colors and optional titles.
476        ///
477        /// Note that the palette menu is configured for display as an inline menu; you must set it as the submenu of another menu item, contained in a standard menu.
478        /// The palette menu cannot be used to invoke the `popUpMenuPositioningItem` method, or attached directly to a popup button or toolbar item.
479        ///
480        ///
481        /// Returns: An autoconfigured palette menu.
482        #[unsafe(method(paletteMenuWithColors:titles:selectionHandler:))]
483        #[unsafe(method_family = none)]
484        pub fn paletteMenuWithColors_titles_selectionHandler(
485            colors: &NSArray<NSColor>,
486            item_titles: &NSArray<NSString>,
487            on_selection_change: Option<&block2::DynBlock<dyn Fn(NonNull<NSMenu>)>>,
488            mtm: MainThreadMarker,
489        ) -> Retained<Self>;
490
491        #[cfg(all(feature = "NSColor", feature = "NSImage", feature = "block2"))]
492        /// Creates a palette menu displaying user-selectable color tags
493        /// using the provided template image, tinted using the specified
494        /// array of colors.
495        ///
496        /// Optionally allows observing changes to the selection state in
497        /// the compact menu. The block is invoked after the selection
498        /// has been updated. Currently selected items can be retrieved
499        /// from the `selectedItems` property.
500        ///
501        /// Note that the palette menu is configured for display as an inline menu; you must set it as the submenu of another menu item, contained in a standard menu.
502        /// The palette menu cannot be used to invoke the `popUpMenuPositioningItem` method, or attached directly to a popup button or toolbar item.
503        ///
504        ///
505        /// Returns: An autoconfigured palette menu.
506        #[unsafe(method(paletteMenuWithColors:titles:templateImage:selectionHandler:))]
507        #[unsafe(method_family = none)]
508        pub fn paletteMenuWithColors_titles_templateImage_selectionHandler(
509            colors: &NSArray<NSColor>,
510            item_titles: &NSArray<NSString>,
511            image: &NSImage,
512            on_selection_change: Option<&block2::DynBlock<dyn Fn(NonNull<NSMenu>)>>,
513            mtm: MainThreadMarker,
514        ) -> Retained<Self>;
515
516        /// The presentation style of the menu.
517        ///
518        ///
519        /// Note: This property is not respected if the menu is the main
520        /// menu of the app.
521        #[unsafe(method(presentationStyle))]
522        #[unsafe(method_family = none)]
523        pub fn presentationStyle(&self) -> NSMenuPresentationStyle;
524
525        /// Setter for [`presentationStyle`][Self::presentationStyle].
526        #[unsafe(method(setPresentationStyle:))]
527        #[unsafe(method_family = none)]
528        pub fn setPresentationStyle(&self, presentation_style: NSMenuPresentationStyle);
529
530        /// The selection mode of the menu.
531        ///
532        /// Note the selection mode only has effect on menu items that
533        /// belong to the same selection group. A selection group consists
534        /// of the items with the same target/action.
535        #[unsafe(method(selectionMode))]
536        #[unsafe(method_family = none)]
537        pub fn selectionMode(&self) -> NSMenuSelectionMode;
538
539        /// Setter for [`selectionMode`][Self::selectionMode].
540        #[unsafe(method(setSelectionMode:))]
541        #[unsafe(method_family = none)]
542        pub fn setSelectionMode(&self, selection_mode: NSMenuSelectionMode);
543
544        #[cfg(feature = "NSMenuItem")]
545        /// The menu items that are selected.
546        ///
547        /// An item is selected when its state is `NSControl.StateValue.on`.
548        ///
549        ///
550        /// Note: This property is settable. Setting `selectedItems` will
551        /// select any items that are contained in the provided array, and
552        /// deselect any previously selected items that are not in the array.
553        #[unsafe(method(selectedItems))]
554        #[unsafe(method_family = none)]
555        pub fn selectedItems(&self) -> Retained<NSArray<NSMenuItem>>;
556
557        #[cfg(feature = "NSMenuItem")]
558        /// Setter for [`selectedItems`][Self::selectedItems].
559        ///
560        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
561        #[unsafe(method(setSelectedItems:))]
562        #[unsafe(method_family = none)]
563        pub fn setSelectedItems(&self, selected_items: &NSArray<NSMenuItem>);
564    );
565}
566
567/// NSSubmenuAction.
568impl NSMenu {
569    extern_methods!(
570        /// # Safety
571        ///
572        /// `sender` should be of the correct type.
573        #[unsafe(method(submenuAction:))]
574        #[unsafe(method_family = none)]
575        pub unsafe fn submenuAction(&self, sender: Option<&AnyObject>);
576    );
577}
578
579extern_protocol!(
580    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenuitemvalidation?language=objc)
581    pub unsafe trait NSMenuItemValidation: NSObjectProtocol + MainThreadOnly {
582        #[cfg(feature = "NSMenuItem")]
583        #[unsafe(method(validateMenuItem:))]
584        #[unsafe(method_family = none)]
585        fn validateMenuItem(&self, menu_item: &NSMenuItem) -> bool;
586    }
587);
588
589extern_protocol!(
590    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenudelegate?language=objc)
591    pub unsafe trait NSMenuDelegate: NSObjectProtocol + MainThreadOnly {
592        #[optional]
593        #[unsafe(method(menuNeedsUpdate:))]
594        #[unsafe(method_family = none)]
595        fn menuNeedsUpdate(&self, menu: &NSMenu);
596
597        #[optional]
598        #[unsafe(method(numberOfItemsInMenu:))]
599        #[unsafe(method_family = none)]
600        fn numberOfItemsInMenu(&self, menu: &NSMenu) -> NSInteger;
601
602        #[cfg(feature = "NSMenuItem")]
603        #[optional]
604        #[unsafe(method(menu:updateItem:atIndex:shouldCancel:))]
605        #[unsafe(method_family = none)]
606        fn menu_updateItem_atIndex_shouldCancel(
607            &self,
608            menu: &NSMenu,
609            item: &NSMenuItem,
610            index: NSInteger,
611            should_cancel: bool,
612        ) -> bool;
613
614        #[optional]
615        #[unsafe(method(menuWillOpen:))]
616        #[unsafe(method_family = none)]
617        fn menuWillOpen(&self, menu: &NSMenu);
618
619        #[optional]
620        #[unsafe(method(menuDidClose:))]
621        #[unsafe(method_family = none)]
622        fn menuDidClose(&self, menu: &NSMenu);
623
624        #[cfg(feature = "NSMenuItem")]
625        #[optional]
626        #[unsafe(method(menu:willHighlightItem:))]
627        #[unsafe(method_family = none)]
628        fn menu_willHighlightItem(&self, menu: &NSMenu, item: Option<&NSMenuItem>);
629
630        #[cfg(feature = "NSScreen")]
631        #[optional]
632        #[unsafe(method(confinementRectForMenu:onScreen:))]
633        #[unsafe(method_family = none)]
634        fn confinementRectForMenu_onScreen(
635            &self,
636            menu: &NSMenu,
637            screen: Option<&NSScreen>,
638        ) -> NSRect;
639    }
640);
641
642/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenuproperties?language=objc)
643// NS_OPTIONS
644#[repr(transparent)]
645#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
646pub struct NSMenuProperties(pub NSUInteger);
647bitflags::bitflags! {
648    impl NSMenuProperties: NSUInteger {
649        #[doc(alias = "NSMenuPropertyItemTitle")]
650        const ItemTitle = 1<<0;
651        #[doc(alias = "NSMenuPropertyItemAttributedTitle")]
652        const ItemAttributedTitle = 1<<1;
653        #[doc(alias = "NSMenuPropertyItemKeyEquivalent")]
654        const ItemKeyEquivalent = 1<<2;
655        #[doc(alias = "NSMenuPropertyItemImage")]
656        const ItemImage = 1<<3;
657        #[doc(alias = "NSMenuPropertyItemEnabled")]
658        const ItemEnabled = 1<<4;
659        #[doc(alias = "NSMenuPropertyItemAccessibilityDescription")]
660        const ItemAccessibilityDescription = 1<<5;
661    }
662}
663
664unsafe impl Encode for NSMenuProperties {
665    const ENCODING: Encoding = NSUInteger::ENCODING;
666}
667
668unsafe impl RefEncode for NSMenuProperties {
669    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
670}
671
672/// NSMenuPropertiesToUpdate.
673impl NSMenu {
674    extern_methods!(
675        #[unsafe(method(propertiesToUpdate))]
676        #[unsafe(method_family = none)]
677        pub fn propertiesToUpdate(&self) -> NSMenuProperties;
678    );
679}
680
681extern "C" {
682    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenuwillsendactionnotification?language=objc)
683    pub static NSMenuWillSendActionNotification: &'static NSNotificationName;
684}
685
686extern "C" {
687    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenudidsendactionnotification?language=objc)
688    pub static NSMenuDidSendActionNotification: &'static NSNotificationName;
689}
690
691extern "C" {
692    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenudidadditemnotification?language=objc)
693    pub static NSMenuDidAddItemNotification: &'static NSNotificationName;
694}
695
696extern "C" {
697    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenudidremoveitemnotification?language=objc)
698    pub static NSMenuDidRemoveItemNotification: &'static NSNotificationName;
699}
700
701extern "C" {
702    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenudidchangeitemnotification?language=objc)
703    pub static NSMenuDidChangeItemNotification: &'static NSNotificationName;
704}
705
706extern "C" {
707    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenudidbegintrackingnotification?language=objc)
708    pub static NSMenuDidBeginTrackingNotification: &'static NSNotificationName;
709}
710
711extern "C" {
712    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmenudidendtrackingnotification?language=objc)
713    pub static NSMenuDidEndTrackingNotification: &'static NSNotificationName;
714}
715
716/// NSDeprecated.
717impl NSMenu {
718    extern_methods!(
719        /// # Safety
720        ///
721        /// - `menu_rep` should be of the correct type.
722        /// - `menu_rep` might not allow `None`.
723        #[deprecated]
724        #[unsafe(method(setMenuRepresentation:))]
725        #[unsafe(method_family = none)]
726        pub unsafe fn setMenuRepresentation(&self, menu_rep: Option<&AnyObject>);
727
728        #[deprecated]
729        #[unsafe(method(menuRepresentation))]
730        #[unsafe(method_family = none)]
731        pub fn menuRepresentation(&self) -> Option<Retained<AnyObject>>;
732
733        /// # Safety
734        ///
735        /// - `menu_rep` should be of the correct type.
736        /// - `menu_rep` might not allow `None`.
737        #[deprecated]
738        #[unsafe(method(setContextMenuRepresentation:))]
739        #[unsafe(method_family = none)]
740        pub unsafe fn setContextMenuRepresentation(&self, menu_rep: Option<&AnyObject>);
741
742        #[deprecated]
743        #[unsafe(method(contextMenuRepresentation))]
744        #[unsafe(method_family = none)]
745        pub fn contextMenuRepresentation(&self) -> Option<Retained<AnyObject>>;
746
747        /// # Safety
748        ///
749        /// - `menu_rep` should be of the correct type.
750        /// - `menu_rep` might not allow `None`.
751        #[deprecated]
752        #[unsafe(method(setTearOffMenuRepresentation:))]
753        #[unsafe(method_family = none)]
754        pub unsafe fn setTearOffMenuRepresentation(&self, menu_rep: Option<&AnyObject>);
755
756        #[deprecated]
757        #[unsafe(method(tearOffMenuRepresentation))]
758        #[unsafe(method_family = none)]
759        pub fn tearOffMenuRepresentation(&self) -> Option<Retained<AnyObject>>;
760
761        #[deprecated]
762        #[unsafe(method(menuZone))]
763        #[unsafe(method_family = none)]
764        pub fn menuZone(mtm: MainThreadMarker) -> *mut NSZone;
765
766        /// # Safety
767        ///
768        /// `zone` must be a valid pointer.
769        #[deprecated]
770        #[unsafe(method(setMenuZone:))]
771        #[unsafe(method_family = none)]
772        pub unsafe fn setMenuZone(zone: *mut NSZone, mtm: MainThreadMarker);
773
774        #[deprecated]
775        #[unsafe(method(attachedMenu))]
776        #[unsafe(method_family = none)]
777        pub fn attachedMenu(&self) -> Option<Retained<NSMenu>>;
778
779        #[deprecated]
780        #[unsafe(method(isAttached))]
781        #[unsafe(method_family = none)]
782        pub fn isAttached(&self) -> bool;
783
784        #[deprecated]
785        #[unsafe(method(sizeToFit))]
786        #[unsafe(method_family = none)]
787        pub fn sizeToFit(&self);
788
789        /// # Safety
790        ///
791        /// `submenu` might not allow `None`.
792        #[deprecated]
793        #[unsafe(method(locationForSubmenu:))]
794        #[unsafe(method_family = none)]
795        pub unsafe fn locationForSubmenu(&self, submenu: Option<&NSMenu>) -> NSPoint;
796
797        #[deprecated]
798        #[unsafe(method(menuChangedMessagesEnabled))]
799        #[unsafe(method_family = none)]
800        pub fn menuChangedMessagesEnabled(&self) -> bool;
801
802        /// Setter for [`menuChangedMessagesEnabled`][Self::menuChangedMessagesEnabled].
803        #[deprecated]
804        #[unsafe(method(setMenuChangedMessagesEnabled:))]
805        #[unsafe(method_family = none)]
806        pub fn setMenuChangedMessagesEnabled(&self, menu_changed_messages_enabled: bool);
807
808        #[cfg(feature = "NSEvent")]
809        #[deprecated]
810        #[unsafe(method(helpRequested:))]
811        #[unsafe(method_family = none)]
812        pub fn helpRequested(&self, event_ptr: &NSEvent);
813
814        #[deprecated]
815        #[unsafe(method(isTornOff))]
816        #[unsafe(method_family = none)]
817        pub fn isTornOff(&self) -> bool;
818    );
819}