using CPF.Mac.CoreGraphics; using CPF.Mac.Foundation; using CPF.Mac.ObjCRuntime; using System; using System.ComponentModel; namespace CPF.Mac.AppKit { [Register("NSButton", true)] public class NSButton : NSControl { private static readonly IntPtr selTitleHandle = Selector.GetHandle("title"); private static readonly IntPtr selSetTitle_Handle = Selector.GetHandle("setTitle:"); private static readonly IntPtr selAlternateTitleHandle = Selector.GetHandle("alternateTitle"); private static readonly IntPtr selSetAlternateTitle_Handle = Selector.GetHandle("setAlternateTitle:"); private static readonly IntPtr selImageHandle = Selector.GetHandle("image"); private static readonly IntPtr selSetImage_Handle = Selector.GetHandle("setImage:"); private static readonly IntPtr selAlternateImageHandle = Selector.GetHandle("alternateImage"); private static readonly IntPtr selSetAlternateImage_Handle = Selector.GetHandle("setAlternateImage:"); private static readonly IntPtr selImagePositionHandle = Selector.GetHandle("imagePosition"); private static readonly IntPtr selSetImagePosition_Handle = Selector.GetHandle("setImagePosition:"); private static readonly IntPtr selStateHandle = Selector.GetHandle("state"); private static readonly IntPtr selSetState_Handle = Selector.GetHandle("setState:"); private static readonly IntPtr selIsBorderedHandle = Selector.GetHandle("isBordered"); private static readonly IntPtr selSetBordered_Handle = Selector.GetHandle("setBordered:"); private static readonly IntPtr selIsTransparentHandle = Selector.GetHandle("isTransparent"); private static readonly IntPtr selSetTransparent_Handle = Selector.GetHandle("setTransparent:"); private static readonly IntPtr selKeyEquivalentHandle = Selector.GetHandle("keyEquivalent"); private static readonly IntPtr selSetKeyEquivalent_Handle = Selector.GetHandle("setKeyEquivalent:"); private static readonly IntPtr selKeyEquivalentModifierMaskHandle = Selector.GetHandle("keyEquivalentModifierMask"); private static readonly IntPtr selSetKeyEquivalentModifierMask_Handle = Selector.GetHandle("setKeyEquivalentModifierMask:"); private static readonly IntPtr selAttributedTitleHandle = Selector.GetHandle("attributedTitle"); private static readonly IntPtr selSetAttributedTitle_Handle = Selector.GetHandle("setAttributedTitle:"); private static readonly IntPtr selAttributedAlternateTitleHandle = Selector.GetHandle("attributedAlternateTitle"); private static readonly IntPtr selSetAttributedAlternateTitle_Handle = Selector.GetHandle("setAttributedAlternateTitle:"); private static readonly IntPtr selBezelStyleHandle = Selector.GetHandle("bezelStyle"); private static readonly IntPtr selSetBezelStyle_Handle = Selector.GetHandle("setBezelStyle:"); private static readonly IntPtr selAllowsMixedStateHandle = Selector.GetHandle("allowsMixedState"); private static readonly IntPtr selSetAllowsMixedState_Handle = Selector.GetHandle("setAllowsMixedState:"); private static readonly IntPtr selSoundHandle = Selector.GetHandle("sound"); private static readonly IntPtr selSetSound_Handle = Selector.GetHandle("setSound:"); private static readonly IntPtr selInitWithFrame_Handle = Selector.GetHandle("initWithFrame:"); private static readonly IntPtr selSetButtonType_Handle = Selector.GetHandle("setButtonType:"); private static readonly IntPtr selSetPeriodicDelayInterval_Handle = Selector.GetHandle("setPeriodicDelay:interval:"); private static readonly IntPtr selGetPeriodicDelayInterval_Handle = Selector.GetHandle("getPeriodicDelay:interval:"); private static readonly IntPtr selHighlight_Handle = Selector.GetHandle("highlight:"); private static readonly IntPtr selPerformKeyEquivalent_Handle = Selector.GetHandle("performKeyEquivalent:"); private static readonly IntPtr selSetTitleWithMnemonic_Handle = Selector.GetHandle("setTitleWithMnemonic:"); private static readonly IntPtr selSetNextStateHandle = Selector.GetHandle("setNextState"); private static readonly IntPtr selShowsBorderOnlyWhileMouseInsideHandle = Selector.GetHandle("showsBorderOnlyWhileMouseInside"); private static readonly IntPtr class_ptr = Class.GetHandle("NSButton"); private object __mt_Image_var; private object __mt_AlternateImage_var; private object __mt_AttributedTitle_var; private object __mt_AttributedAlternateTitle_var; private object __mt_Sound_var; public new NSButtonCell Cell { get { return (NSButtonCell)base.Cell; } set { base.Cell = value; } } public override IntPtr ClassHandle => class_ptr; public virtual string Title { [Export("title")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return NSString.FromHandle(Messaging.IntPtr_objc_msgSend(base.Handle, selTitleHandle)); } return NSString.FromHandle(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selTitleHandle)); } [Export("setTitle:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } IntPtr intPtr = NSString.CreateNative(value); if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetTitle_Handle, intPtr); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetTitle_Handle, intPtr); } NSString.ReleaseNative(intPtr); } } public virtual string AlternateTitle { [Export("alternateTitle")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return NSString.FromHandle(Messaging.IntPtr_objc_msgSend(base.Handle, selAlternateTitleHandle)); } return NSString.FromHandle(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selAlternateTitleHandle)); } [Export("setAlternateTitle:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } IntPtr intPtr = NSString.CreateNative(value); if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetAlternateTitle_Handle, intPtr); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetAlternateTitle_Handle, intPtr); } NSString.ReleaseNative(intPtr); } } public virtual NSImage Image { [Export("image")] get { NSApplication.EnsureUIThread(); return (NSImage)(__mt_Image_var = ((!IsDirectBinding) ? ((NSImage)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selImageHandle))) : ((NSImage)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(base.Handle, selImageHandle))))); } [Export("setImage:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetImage_Handle, value?.Handle ?? IntPtr.Zero); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetImage_Handle, value?.Handle ?? IntPtr.Zero); } __mt_Image_var = value; } } public virtual NSImage AlternateImage { [Export("alternateImage")] get { NSApplication.EnsureUIThread(); return (NSImage)(__mt_AlternateImage_var = ((!IsDirectBinding) ? ((NSImage)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selAlternateImageHandle))) : ((NSImage)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(base.Handle, selAlternateImageHandle))))); } [Export("setAlternateImage:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetAlternateImage_Handle, value?.Handle ?? IntPtr.Zero); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetAlternateImage_Handle, value?.Handle ?? IntPtr.Zero); } __mt_AlternateImage_var = value; } } public virtual NSCellImagePosition ImagePosition { [Export("imagePosition")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return (NSCellImagePosition)Messaging.UInt64_objc_msgSend(base.Handle, selImagePositionHandle); } return (NSCellImagePosition)Messaging.UInt64_objc_msgSendSuper(base.SuperHandle, selImagePositionHandle); } [Export("setImagePosition:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_UInt64(base.Handle, selSetImagePosition_Handle, (ulong)value); } else { Messaging.void_objc_msgSendSuper_UInt64(base.SuperHandle, selSetImagePosition_Handle, (ulong)value); } } } public virtual NSCellStateValue State { [Export("state")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return (NSCellStateValue)Messaging.Int64_objc_msgSend(base.Handle, selStateHandle); } return (NSCellStateValue)Messaging.Int64_objc_msgSendSuper(base.SuperHandle, selStateHandle); } [Export("setState:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_Int64(base.Handle, selSetState_Handle, (long)value); } else { Messaging.void_objc_msgSendSuper_Int64(base.SuperHandle, selSetState_Handle, (long)value); } } } public virtual bool Bordered { [Export("isBordered")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return Messaging.bool_objc_msgSend(base.Handle, selIsBorderedHandle); } return Messaging.bool_objc_msgSendSuper(base.SuperHandle, selIsBorderedHandle); } [Export("setBordered:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_bool(base.Handle, selSetBordered_Handle, value); } else { Messaging.void_objc_msgSendSuper_bool(base.SuperHandle, selSetBordered_Handle, value); } } } public virtual bool Transparent { [Export("isTransparent")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return Messaging.bool_objc_msgSend(base.Handle, selIsTransparentHandle); } return Messaging.bool_objc_msgSendSuper(base.SuperHandle, selIsTransparentHandle); } [Export("setTransparent:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_bool(base.Handle, selSetTransparent_Handle, value); } else { Messaging.void_objc_msgSendSuper_bool(base.SuperHandle, selSetTransparent_Handle, value); } } } public virtual string KeyEquivalent { [Export("keyEquivalent")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return NSString.FromHandle(Messaging.IntPtr_objc_msgSend(base.Handle, selKeyEquivalentHandle)); } return NSString.FromHandle(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selKeyEquivalentHandle)); } [Export("setKeyEquivalent:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } IntPtr intPtr = NSString.CreateNative(value); if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetKeyEquivalent_Handle, intPtr); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetKeyEquivalent_Handle, intPtr); } NSString.ReleaseNative(intPtr); } } public virtual NSEventModifierMask KeyEquivalentModifierMask { [Export("keyEquivalentModifierMask")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return (NSEventModifierMask)Messaging.UInt64_objc_msgSend(base.Handle, selKeyEquivalentModifierMaskHandle); } return (NSEventModifierMask)Messaging.UInt64_objc_msgSendSuper(base.SuperHandle, selKeyEquivalentModifierMaskHandle); } [Export("setKeyEquivalentModifierMask:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_UInt64(base.Handle, selSetKeyEquivalentModifierMask_Handle, (ulong)value); } else { Messaging.void_objc_msgSendSuper_UInt64(base.SuperHandle, selSetKeyEquivalentModifierMask_Handle, (ulong)value); } } } public virtual NSAttributedString AttributedTitle { [Export("attributedTitle")] get { NSApplication.EnsureUIThread(); return (NSAttributedString)(__mt_AttributedTitle_var = ((!IsDirectBinding) ? ((NSAttributedString)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selAttributedTitleHandle))) : ((NSAttributedString)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(base.Handle, selAttributedTitleHandle))))); } [Export("setAttributedTitle:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetAttributedTitle_Handle, value.Handle); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetAttributedTitle_Handle, value.Handle); } __mt_AttributedTitle_var = value; } } public virtual NSAttributedString AttributedAlternateTitle { [Export("attributedAlternateTitle")] get { NSApplication.EnsureUIThread(); return (NSAttributedString)(__mt_AttributedAlternateTitle_var = ((!IsDirectBinding) ? ((NSAttributedString)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selAttributedAlternateTitleHandle))) : ((NSAttributedString)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(base.Handle, selAttributedAlternateTitleHandle))))); } [Export("setAttributedAlternateTitle:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetAttributedAlternateTitle_Handle, value.Handle); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetAttributedAlternateTitle_Handle, value.Handle); } __mt_AttributedAlternateTitle_var = value; } } public virtual NSBezelStyle BezelStyle { [Export("bezelStyle")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return (NSBezelStyle)Messaging.UInt64_objc_msgSend(base.Handle, selBezelStyleHandle); } return (NSBezelStyle)Messaging.UInt64_objc_msgSendSuper(base.SuperHandle, selBezelStyleHandle); } [Export("setBezelStyle:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_UInt64(base.Handle, selSetBezelStyle_Handle, (ulong)value); } else { Messaging.void_objc_msgSendSuper_UInt64(base.SuperHandle, selSetBezelStyle_Handle, (ulong)value); } } } public virtual bool AllowsMixedState { [Export("allowsMixedState")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return Messaging.bool_objc_msgSend(base.Handle, selAllowsMixedStateHandle); } return Messaging.bool_objc_msgSendSuper(base.SuperHandle, selAllowsMixedStateHandle); } [Export("setAllowsMixedState:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_bool(base.Handle, selSetAllowsMixedState_Handle, value); } else { Messaging.void_objc_msgSendSuper_bool(base.SuperHandle, selSetAllowsMixedState_Handle, value); } } } public virtual NSSound Sound { [Export("sound")] get { NSApplication.EnsureUIThread(); return (NSSound)(__mt_Sound_var = ((!IsDirectBinding) ? ((NSSound)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selSoundHandle))) : ((NSSound)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(base.Handle, selSoundHandle))))); } [Export("setSound:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetSound_Handle, value.Handle); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetSound_Handle, value.Handle); } __mt_Sound_var = value; } } [EditorBrowsable(EditorBrowsableState.Advanced)] [Export("init")] public NSButton() : base(NSObjectFlag.Empty) { if (IsDirectBinding) { base.Handle = Messaging.IntPtr_objc_msgSend(base.Handle, Selector.Init); } else { base.Handle = Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, Selector.Init); } } [EditorBrowsable(EditorBrowsableState.Advanced)] [Export("initWithCoder:")] public NSButton(NSCoder coder) : base(NSObjectFlag.Empty) { if (IsDirectBinding) { base.Handle = Messaging.IntPtr_objc_msgSend_IntPtr(base.Handle, Selector.InitWithCoder, coder.Handle); } else { base.Handle = Messaging.IntPtr_objc_msgSendSuper_IntPtr(base.SuperHandle, Selector.InitWithCoder, coder.Handle); } } [EditorBrowsable(EditorBrowsableState.Advanced)] public NSButton(NSObjectFlag t) : base(t) { } [EditorBrowsable(EditorBrowsableState.Advanced)] public NSButton(IntPtr handle) : base(handle) { } [Export("initWithFrame:")] public NSButton(CGRect frameRect) : base(NSObjectFlag.Empty) { NSApplication.EnsureUIThread(); if (IsDirectBinding) { base.Handle = Messaging.IntPtr_objc_msgSend_CGRect(base.Handle, selInitWithFrame_Handle, frameRect); } else { base.Handle = Messaging.IntPtr_objc_msgSendSuper_CGRect(base.SuperHandle, selInitWithFrame_Handle, frameRect); } } [Export("setButtonType:")] public virtual void SetButtonType(NSButtonType aType) { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_UInt64(base.Handle, selSetButtonType_Handle, (ulong)aType); } else { Messaging.void_objc_msgSendSuper_UInt64(base.SuperHandle, selSetButtonType_Handle, (ulong)aType); } } [Export("setPeriodicDelay:interval:")] public virtual void SetPeriodicDelay(float delay, float interval) { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_float_float(base.Handle, selSetPeriodicDelayInterval_Handle, delay, interval); } else { Messaging.void_objc_msgSendSuper_float_float(base.SuperHandle, selSetPeriodicDelayInterval_Handle, delay, interval); } } [Export("getPeriodicDelay:interval:")] public virtual void GetPeriodicDelay(ref float delay, ref float interval) { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_out_Single_out_Single(base.Handle, selGetPeriodicDelayInterval_Handle, out delay, out interval); } else { Messaging.void_objc_msgSendSuper_out_Single_out_Single(base.SuperHandle, selGetPeriodicDelayInterval_Handle, out delay, out interval); } } [Export("highlight:")] public virtual void Highlight(bool flag) { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_bool(base.Handle, selHighlight_Handle, flag); } else { Messaging.void_objc_msgSendSuper_bool(base.SuperHandle, selHighlight_Handle, flag); } } [Export("performKeyEquivalent:")] public new virtual bool PerformKeyEquivalent(NSEvent key) { NSApplication.EnsureUIThread(); if (key == null) { throw new ArgumentNullException("key"); } if (IsDirectBinding) { return Messaging.bool_objc_msgSend_IntPtr(base.Handle, selPerformKeyEquivalent_Handle, key.Handle); } return Messaging.bool_objc_msgSendSuper_IntPtr(base.SuperHandle, selPerformKeyEquivalent_Handle, key.Handle); } [Export("setTitleWithMnemonic:")] public virtual void SetTitleWithMnemonic(string mnemonic) { NSApplication.EnsureUIThread(); if (mnemonic == null) { throw new ArgumentNullException("mnemonic"); } IntPtr intPtr = NSString.CreateNative(mnemonic); if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetTitleWithMnemonic_Handle, intPtr); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetTitleWithMnemonic_Handle, intPtr); } NSString.ReleaseNative(intPtr); } [Export("setNextState")] public virtual void SetNextState() { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend(base.Handle, selSetNextStateHandle); } else { Messaging.void_objc_msgSendSuper(base.SuperHandle, selSetNextStateHandle); } } [Export("showsBorderOnlyWhileMouseInside")] public virtual bool ShowsBorderOnlyWhileMouseInside() { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return Messaging.bool_objc_msgSend(base.Handle, selShowsBorderOnlyWhileMouseInsideHandle); } return Messaging.bool_objc_msgSendSuper(base.SuperHandle, selShowsBorderOnlyWhileMouseInsideHandle); } protected override void Dispose(bool disposing) { base.Dispose(disposing); if (base.Handle == IntPtr.Zero) { __mt_Image_var = null; __mt_AlternateImage_var = null; __mt_AttributedTitle_var = null; __mt_AttributedAlternateTitle_var = null; __mt_Sound_var = null; } } } }