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