#[cfg(feature = "block2")]
use block2::*;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSMenuPresentationStyle(pub NSInteger);
impl NSMenuPresentationStyle {
#[doc(alias = "NSMenuPresentationStyleRegular")]
pub const Regular: Self = Self(0);
#[doc(alias = "NSMenuPresentationStylePalette")]
pub const Palette: Self = Self(1);
}
unsafe impl Encode for NSMenuPresentationStyle {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for NSMenuPresentationStyle {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSMenuSelectionMode(pub NSInteger);
impl NSMenuSelectionMode {
#[doc(alias = "NSMenuSelectionModeAutomatic")]
pub const Automatic: Self = Self(0);
#[doc(alias = "NSMenuSelectionModeSelectOne")]
pub const SelectOne: Self = Self(1);
#[doc(alias = "NSMenuSelectionModeSelectAny")]
pub const SelectAny: Self = Self(2);
}
unsafe impl Encode for NSMenuSelectionMode {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for NSMenuSelectionMode {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct NSMenu;
unsafe impl ClassType for NSMenu {
type Super = NSObject;
type Mutability = MainThreadOnly;
}
);
#[cfg(feature = "NSAccessibilityProtocols")]
unsafe impl NSAccessibility for NSMenu {}
#[cfg(feature = "NSAccessibilityProtocols")]
unsafe impl NSAccessibilityElementProtocol for NSMenu {}
#[cfg(feature = "NSAppearance")]
unsafe impl NSAppearanceCustomization for NSMenu {}
unsafe impl NSCoding for NSMenu {}
unsafe impl NSCopying for NSMenu {}
unsafe impl NSObjectProtocol for NSMenu {}
#[cfg(feature = "NSUserInterfaceItemIdentification")]
unsafe impl NSUserInterfaceItemIdentification for NSMenu {}
extern_methods!(
unsafe impl NSMenu {
#[method_id(@__retain_semantics Init initWithTitle:)]
pub unsafe fn initWithTitle(this: Allocated<Self>, title: &NSString) -> Id<Self>;
#[method_id(@__retain_semantics Init initWithCoder:)]
pub unsafe fn initWithCoder(this: Allocated<Self>, coder: &NSCoder) -> Id<Self>;
#[method_id(@__retain_semantics Other title)]
pub unsafe fn title(&self) -> Id<NSString>;
#[method(setTitle:)]
pub unsafe fn setTitle(&self, title: &NSString);
#[cfg(all(feature = "NSEvent", feature = "NSResponder", feature = "NSView"))]
#[method(popUpContextMenu:withEvent:forView:)]
pub unsafe fn popUpContextMenu_withEvent_forView(
menu: &NSMenu,
event: &NSEvent,
view: &NSView,
);
#[cfg(all(
feature = "NSEvent",
feature = "NSFont",
feature = "NSResponder",
feature = "NSView"
))]
#[method(popUpContextMenu:withEvent:forView:withFont:)]
pub unsafe fn popUpContextMenu_withEvent_forView_withFont(
menu: &NSMenu,
event: &NSEvent,
view: &NSView,
font: Option<&NSFont>,
);
#[cfg(all(feature = "NSMenuItem", feature = "NSResponder", feature = "NSView"))]
#[method(popUpMenuPositioningItem:atLocation:inView:)]
pub unsafe fn popUpMenuPositioningItem_atLocation_inView(
&self,
item: Option<&NSMenuItem>,
location: NSPoint,
view: Option<&NSView>,
) -> bool;
#[method(setMenuBarVisible:)]
pub unsafe fn setMenuBarVisible(visible: bool, mtm: MainThreadMarker);
#[method(menuBarVisible)]
pub unsafe fn menuBarVisible(mtm: MainThreadMarker) -> bool;
#[method_id(@__retain_semantics Other supermenu)]
pub unsafe fn supermenu(&self) -> Option<Id<NSMenu>>;
#[method(setSupermenu:)]
pub unsafe fn setSupermenu(&self, supermenu: Option<&NSMenu>);
#[cfg(feature = "NSMenuItem")]
#[method(insertItem:atIndex:)]
pub unsafe fn insertItem_atIndex(&self, new_item: &NSMenuItem, index: NSInteger);
#[cfg(feature = "NSMenuItem")]
#[method(addItem:)]
pub fn addItem(&self, new_item: &NSMenuItem);
#[cfg(feature = "NSMenuItem")]
#[method_id(@__retain_semantics Other insertItemWithTitle:action:keyEquivalent:atIndex:)]
pub unsafe fn insertItemWithTitle_action_keyEquivalent_atIndex(
&self,
string: &NSString,
selector: Option<Sel>,
char_code: &NSString,
index: NSInteger,
) -> Id<NSMenuItem>;
#[cfg(feature = "NSMenuItem")]
#[method_id(@__retain_semantics Other addItemWithTitle:action:keyEquivalent:)]
pub unsafe fn addItemWithTitle_action_keyEquivalent(
&self,
string: &NSString,
selector: Option<Sel>,
char_code: &NSString,
) -> Id<NSMenuItem>;
#[method(removeItemAtIndex:)]
pub unsafe fn removeItemAtIndex(&self, index: NSInteger);
#[cfg(feature = "NSMenuItem")]
#[method(removeItem:)]
pub unsafe fn removeItem(&self, item: &NSMenuItem);
#[cfg(feature = "NSMenuItem")]
#[method(setSubmenu:forItem:)]
pub unsafe fn setSubmenu_forItem(&self, menu: Option<&NSMenu>, item: &NSMenuItem);
#[method(removeAllItems)]
pub unsafe fn removeAllItems(&self);
#[cfg(feature = "NSMenuItem")]
#[method_id(@__retain_semantics Other itemArray)]
pub unsafe fn itemArray(&self) -> Id<NSArray<NSMenuItem>>;
#[cfg(feature = "NSMenuItem")]
#[method(setItemArray:)]
pub unsafe fn setItemArray(&self, item_array: &NSArray<NSMenuItem>);
#[method(numberOfItems)]
pub unsafe fn numberOfItems(&self) -> NSInteger;
#[cfg(feature = "NSMenuItem")]
#[method_id(@__retain_semantics Other itemAtIndex:)]
pub unsafe fn itemAtIndex(&self, index: NSInteger) -> Option<Id<NSMenuItem>>;
#[cfg(feature = "NSMenuItem")]
#[method(indexOfItem:)]
pub unsafe fn indexOfItem(&self, item: &NSMenuItem) -> NSInteger;
#[method(indexOfItemWithTitle:)]
pub unsafe fn indexOfItemWithTitle(&self, title: &NSString) -> NSInteger;
#[method(indexOfItemWithTag:)]
pub unsafe fn indexOfItemWithTag(&self, tag: NSInteger) -> NSInteger;
#[method(indexOfItemWithRepresentedObject:)]
pub unsafe fn indexOfItemWithRepresentedObject(
&self,
object: Option<&AnyObject>,
) -> NSInteger;
#[method(indexOfItemWithSubmenu:)]
pub unsafe fn indexOfItemWithSubmenu(&self, submenu: Option<&NSMenu>) -> NSInteger;
#[method(indexOfItemWithTarget:andAction:)]
pub unsafe fn indexOfItemWithTarget_andAction(
&self,
target: Option<&AnyObject>,
action_selector: Option<Sel>,
) -> NSInteger;
#[cfg(feature = "NSMenuItem")]
#[method_id(@__retain_semantics Other itemWithTitle:)]
pub unsafe fn itemWithTitle(&self, title: &NSString) -> Option<Id<NSMenuItem>>;
#[cfg(feature = "NSMenuItem")]
#[method_id(@__retain_semantics Other itemWithTag:)]
pub unsafe fn itemWithTag(&self, tag: NSInteger) -> Option<Id<NSMenuItem>>;
#[method(autoenablesItems)]
pub unsafe fn autoenablesItems(&self) -> bool;
#[method(setAutoenablesItems:)]
pub unsafe fn setAutoenablesItems(&self, autoenables_items: bool);
#[method(update)]
pub unsafe fn update(&self);
#[cfg(feature = "NSEvent")]
#[method(performKeyEquivalent:)]
pub unsafe fn performKeyEquivalent(&self, event: &NSEvent) -> bool;
#[cfg(feature = "NSMenuItem")]
#[method(itemChanged:)]
pub unsafe fn itemChanged(&self, item: &NSMenuItem);
#[method(performActionForItemAtIndex:)]
pub unsafe fn performActionForItemAtIndex(&self, index: NSInteger);
#[method_id(@__retain_semantics Other delegate)]
pub unsafe fn delegate(&self) -> Option<Id<ProtocolObject<dyn NSMenuDelegate>>>;
#[method(setDelegate:)]
pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSMenuDelegate>>);
#[method(menuBarHeight)]
pub unsafe fn menuBarHeight(&self) -> CGFloat;
#[method(cancelTracking)]
pub unsafe fn cancelTracking(&self);
#[method(cancelTrackingWithoutAnimation)]
pub unsafe fn cancelTrackingWithoutAnimation(&self);
#[cfg(feature = "NSMenuItem")]
#[method_id(@__retain_semantics Other highlightedItem)]
pub unsafe fn highlightedItem(&self) -> Option<Id<NSMenuItem>>;
#[method(minimumWidth)]
pub unsafe fn minimumWidth(&self) -> CGFloat;
#[method(setMinimumWidth:)]
pub unsafe fn setMinimumWidth(&self, minimum_width: CGFloat);
#[method(size)]
pub unsafe fn size(&self) -> NSSize;
#[cfg(feature = "NSFont")]
#[method_id(@__retain_semantics Other font)]
pub unsafe fn font(&self) -> Option<Id<NSFont>>;
#[cfg(feature = "NSFont")]
#[method(setFont:)]
pub unsafe fn setFont(&self, font: Option<&NSFont>);
#[method(allowsContextMenuPlugIns)]
pub unsafe fn allowsContextMenuPlugIns(&self) -> bool;
#[method(setAllowsContextMenuPlugIns:)]
pub unsafe fn setAllowsContextMenuPlugIns(&self, allows_context_menu_plug_ins: bool);
#[method(showsStateColumn)]
pub unsafe fn showsStateColumn(&self) -> bool;
#[method(setShowsStateColumn:)]
pub unsafe fn setShowsStateColumn(&self, shows_state_column: bool);
#[cfg(feature = "NSUserInterfaceLayout")]
#[method(userInterfaceLayoutDirection)]
pub unsafe fn userInterfaceLayoutDirection(&self) -> NSUserInterfaceLayoutDirection;
#[cfg(feature = "NSUserInterfaceLayout")]
#[method(setUserInterfaceLayoutDirection:)]
pub unsafe fn setUserInterfaceLayoutDirection(
&self,
user_interface_layout_direction: NSUserInterfaceLayoutDirection,
);
}
);
extern_methods!(
unsafe impl NSMenu {
#[method_id(@__retain_semantics Init init)]
pub fn init(this: Allocated<Self>) -> Id<Self>;
#[method_id(@__retain_semantics New new)]
pub fn new(mtm: MainThreadMarker) -> Id<Self>;
}
);
extern_methods!(
unsafe impl NSMenu {
#[cfg(all(feature = "NSColor", feature = "block2"))]
#[method_id(@__retain_semantics Other paletteMenuWithColors:titles:selectionHandler:)]
pub unsafe fn paletteMenuWithColors_titles_selectionHandler(
colors: &NSArray<NSColor>,
item_titles: &NSArray<NSString>,
on_selection_change: Option<&Block<dyn Fn(NonNull<NSMenu>)>>,
mtm: MainThreadMarker,
) -> Id<Self>;
#[cfg(all(feature = "NSColor", feature = "NSImage", feature = "block2"))]
#[method_id(@__retain_semantics Other paletteMenuWithColors:titles:templateImage:selectionHandler:)]
pub unsafe fn paletteMenuWithColors_titles_templateImage_selectionHandler(
colors: &NSArray<NSColor>,
item_titles: &NSArray<NSString>,
image: &NSImage,
on_selection_change: Option<&Block<dyn Fn(NonNull<NSMenu>)>>,
mtm: MainThreadMarker,
) -> Id<Self>;
#[method(presentationStyle)]
pub unsafe fn presentationStyle(&self) -> NSMenuPresentationStyle;
#[method(setPresentationStyle:)]
pub unsafe fn setPresentationStyle(&self, presentation_style: NSMenuPresentationStyle);
#[method(selectionMode)]
pub unsafe fn selectionMode(&self) -> NSMenuSelectionMode;
#[method(setSelectionMode:)]
pub unsafe fn setSelectionMode(&self, selection_mode: NSMenuSelectionMode);
#[cfg(feature = "NSMenuItem")]
#[method_id(@__retain_semantics Other selectedItems)]
pub unsafe fn selectedItems(&self) -> Id<NSArray<NSMenuItem>>;
#[cfg(feature = "NSMenuItem")]
#[method(setSelectedItems:)]
pub unsafe fn setSelectedItems(&self, selected_items: &NSArray<NSMenuItem>);
}
);
extern_methods!(
unsafe impl NSMenu {
#[method(submenuAction:)]
pub unsafe fn submenuAction(&self, sender: Option<&AnyObject>);
}
);
extern_protocol!(
pub unsafe trait NSMenuItemValidation: NSObjectProtocol + IsMainThreadOnly {
#[cfg(feature = "NSMenuItem")]
#[method(validateMenuItem:)]
unsafe fn validateMenuItem(&self, menu_item: &NSMenuItem) -> bool;
}
unsafe impl ProtocolType for dyn NSMenuItemValidation {}
);
extern_protocol!(
pub unsafe trait NSMenuDelegate: NSObjectProtocol + IsMainThreadOnly {
#[optional]
#[method(menuNeedsUpdate:)]
unsafe fn menuNeedsUpdate(&self, menu: &NSMenu);
#[optional]
#[method(numberOfItemsInMenu:)]
unsafe fn numberOfItemsInMenu(&self, menu: &NSMenu) -> NSInteger;
#[cfg(feature = "NSMenuItem")]
#[optional]
#[method(menu:updateItem:atIndex:shouldCancel:)]
unsafe fn menu_updateItem_atIndex_shouldCancel(
&self,
menu: &NSMenu,
item: &NSMenuItem,
index: NSInteger,
should_cancel: bool,
) -> bool;
#[optional]
#[method(menuWillOpen:)]
unsafe fn menuWillOpen(&self, menu: &NSMenu);
#[optional]
#[method(menuDidClose:)]
unsafe fn menuDidClose(&self, menu: &NSMenu);
#[cfg(feature = "NSMenuItem")]
#[optional]
#[method(menu:willHighlightItem:)]
unsafe fn menu_willHighlightItem(&self, menu: &NSMenu, item: Option<&NSMenuItem>);
#[cfg(feature = "NSScreen")]
#[optional]
#[method(confinementRectForMenu:onScreen:)]
unsafe fn confinementRectForMenu_onScreen(
&self,
menu: &NSMenu,
screen: Option<&NSScreen>,
) -> NSRect;
}
unsafe impl ProtocolType for dyn NSMenuDelegate {}
);
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSMenuProperties(pub NSUInteger);
impl NSMenuProperties {
pub const NSMenuPropertyItemTitle: Self = Self(1 << 0);
pub const NSMenuPropertyItemAttributedTitle: Self = Self(1 << 1);
pub const NSMenuPropertyItemKeyEquivalent: Self = Self(1 << 2);
pub const NSMenuPropertyItemImage: Self = Self(1 << 3);
pub const NSMenuPropertyItemEnabled: Self = Self(1 << 4);
pub const NSMenuPropertyItemAccessibilityDescription: Self = Self(1 << 5);
}
unsafe impl Encode for NSMenuProperties {
const ENCODING: Encoding = NSUInteger::ENCODING;
}
unsafe impl RefEncode for NSMenuProperties {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_methods!(
unsafe impl NSMenu {
#[method(propertiesToUpdate)]
pub unsafe fn propertiesToUpdate(&self) -> NSMenuProperties;
}
);
extern "C" {
pub static NSMenuWillSendActionNotification: &'static NSNotificationName;
}
extern "C" {
pub static NSMenuDidSendActionNotification: &'static NSNotificationName;
}
extern "C" {
pub static NSMenuDidAddItemNotification: &'static NSNotificationName;
}
extern "C" {
pub static NSMenuDidRemoveItemNotification: &'static NSNotificationName;
}
extern "C" {
pub static NSMenuDidChangeItemNotification: &'static NSNotificationName;
}
extern "C" {
pub static NSMenuDidBeginTrackingNotification: &'static NSNotificationName;
}
extern "C" {
pub static NSMenuDidEndTrackingNotification: &'static NSNotificationName;
}
extern_methods!(
unsafe impl NSMenu {
#[deprecated]
#[method(setMenuRepresentation:)]
pub unsafe fn setMenuRepresentation(&self, menu_rep: Option<&AnyObject>);
#[deprecated]
#[method_id(@__retain_semantics Other menuRepresentation)]
pub unsafe fn menuRepresentation(&self) -> Option<Id<AnyObject>>;
#[deprecated]
#[method(setContextMenuRepresentation:)]
pub unsafe fn setContextMenuRepresentation(&self, menu_rep: Option<&AnyObject>);
#[deprecated]
#[method_id(@__retain_semantics Other contextMenuRepresentation)]
pub unsafe fn contextMenuRepresentation(&self) -> Option<Id<AnyObject>>;
#[deprecated]
#[method(setTearOffMenuRepresentation:)]
pub unsafe fn setTearOffMenuRepresentation(&self, menu_rep: Option<&AnyObject>);
#[deprecated]
#[method_id(@__retain_semantics Other tearOffMenuRepresentation)]
pub unsafe fn tearOffMenuRepresentation(&self) -> Option<Id<AnyObject>>;
#[deprecated]
#[method(menuZone)]
pub unsafe fn menuZone(mtm: MainThreadMarker) -> *mut NSZone;
#[deprecated]
#[method(setMenuZone:)]
pub unsafe fn setMenuZone(zone: *mut NSZone, mtm: MainThreadMarker);
#[deprecated]
#[method_id(@__retain_semantics Other attachedMenu)]
pub unsafe fn attachedMenu(&self) -> Option<Id<NSMenu>>;
#[deprecated]
#[method(isAttached)]
pub unsafe fn isAttached(&self) -> bool;
#[deprecated]
#[method(sizeToFit)]
pub unsafe fn sizeToFit(&self);
#[deprecated]
#[method(locationForSubmenu:)]
pub unsafe fn locationForSubmenu(&self, submenu: Option<&NSMenu>) -> NSPoint;
#[deprecated]
#[method(menuChangedMessagesEnabled)]
pub unsafe fn menuChangedMessagesEnabled(&self) -> bool;
#[deprecated]
#[method(setMenuChangedMessagesEnabled:)]
pub unsafe fn setMenuChangedMessagesEnabled(&self, menu_changed_messages_enabled: bool);
#[cfg(feature = "NSEvent")]
#[deprecated]
#[method(helpRequested:)]
pub unsafe fn helpRequested(&self, event_ptr: &NSEvent);
#[deprecated]
#[method(isTornOff)]
pub unsafe fn isTornOff(&self) -> bool;
}
);