using CPF.Mac.Foundation; using CPF.Mac.ObjCRuntime; using System; using System.ComponentModel; namespace CPF.Mac.AppKit { [Register("NSTextFieldCell", true)] public class NSTextFieldCell : NSActionCell { private static readonly IntPtr selBackgroundColorHandle = Selector.GetHandle("backgroundColor"); private static readonly IntPtr selSetBackgroundColor_Handle = Selector.GetHandle("setBackgroundColor:"); private static readonly IntPtr selDrawsBackgroundHandle = Selector.GetHandle("drawsBackground"); private static readonly IntPtr selSetDrawsBackground_Handle = Selector.GetHandle("setDrawsBackground:"); private static readonly IntPtr selTextColorHandle = Selector.GetHandle("textColor"); private static readonly IntPtr selSetTextColor_Handle = Selector.GetHandle("setTextColor:"); private static readonly IntPtr selBezelStyleHandle = Selector.GetHandle("bezelStyle"); private static readonly IntPtr selSetBezelStyle_Handle = Selector.GetHandle("setBezelStyle:"); private static readonly IntPtr selPlaceholderStringHandle = Selector.GetHandle("placeholderString"); private static readonly IntPtr selSetPlaceholderString_Handle = Selector.GetHandle("setPlaceholderString:"); private static readonly IntPtr selPlaceholderAttributedStringHandle = Selector.GetHandle("placeholderAttributedString"); private static readonly IntPtr selSetPlaceholderAttributedString_Handle = Selector.GetHandle("setPlaceholderAttributedString:"); private static readonly IntPtr selAllowedInputSourceLocalesHandle = Selector.GetHandle("allowedInputSourceLocales"); private static readonly IntPtr selSetAllowedInputSourceLocales_Handle = Selector.GetHandle("setAllowedInputSourceLocales:"); private static readonly IntPtr selWantsNotificationForMarkedTextHandle = Selector.GetHandle("wantsNotificationForMarkedText"); private static readonly IntPtr selSetWantsNotificationForMarkedText_Handle = Selector.GetHandle("setWantsNotificationForMarkedText:"); private static readonly IntPtr selInitTextCell_Handle = Selector.GetHandle("initTextCell:"); private static readonly IntPtr selInitImageCell_Handle = Selector.GetHandle("initImageCell:"); private static readonly IntPtr selSetUpFieldEditorAttributes_Handle = Selector.GetHandle("setUpFieldEditorAttributes:"); private static readonly IntPtr class_ptr = Class.GetHandle("NSTextFieldCell"); private object __mt_BackgroundColor_var; private object __mt_TextColor_var; private object __mt_PlaceholderAttributedString_var; public override IntPtr ClassHandle => class_ptr; public virtual NSColor BackgroundColor { [Export("backgroundColor")] get { NSApplication.EnsureUIThread(); return (NSColor)(__mt_BackgroundColor_var = ((!IsDirectBinding) ? ((NSColor)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selBackgroundColorHandle))) : ((NSColor)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(base.Handle, selBackgroundColorHandle))))); } [Export("setBackgroundColor:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetBackgroundColor_Handle, value.Handle); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetBackgroundColor_Handle, value.Handle); } __mt_BackgroundColor_var = value; } } public virtual bool DrawsBackground { [Export("drawsBackground")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return Messaging.bool_objc_msgSend(base.Handle, selDrawsBackgroundHandle); } return Messaging.bool_objc_msgSendSuper(base.SuperHandle, selDrawsBackgroundHandle); } [Export("setDrawsBackground:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_bool(base.Handle, selSetDrawsBackground_Handle, value); } else { Messaging.void_objc_msgSendSuper_bool(base.SuperHandle, selSetDrawsBackground_Handle, value); } } } public virtual NSColor TextColor { [Export("textColor")] get { NSApplication.EnsureUIThread(); return (NSColor)(__mt_TextColor_var = ((!IsDirectBinding) ? ((NSColor)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selTextColorHandle))) : ((NSColor)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(base.Handle, selTextColorHandle))))); } [Export("setTextColor:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetTextColor_Handle, value.Handle); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetTextColor_Handle, value.Handle); } __mt_TextColor_var = value; } } public virtual NSTextFieldBezelStyle BezelStyle { [Export("bezelStyle")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return (NSTextFieldBezelStyle)Messaging.int_objc_msgSend(base.Handle, selBezelStyleHandle); } return (NSTextFieldBezelStyle)Messaging.int_objc_msgSendSuper(base.SuperHandle, selBezelStyleHandle); } [Export("setBezelStyle:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_int(base.Handle, selSetBezelStyle_Handle, (int)value); } else { Messaging.void_objc_msgSendSuper_int(base.SuperHandle, selSetBezelStyle_Handle, (int)value); } } } public virtual string PlaceholderString { [Export("placeholderString")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return NSString.FromHandle(Messaging.IntPtr_objc_msgSend(base.Handle, selPlaceholderStringHandle)); } return NSString.FromHandle(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selPlaceholderStringHandle)); } [Export("setPlaceholderString:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } IntPtr intPtr = NSString.CreateNative(value); if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetPlaceholderString_Handle, intPtr); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetPlaceholderString_Handle, intPtr); } NSString.ReleaseNative(intPtr); } } public virtual NSAttributedString PlaceholderAttributedString { [Export("placeholderAttributedString")] get { NSApplication.EnsureUIThread(); return (NSAttributedString)(__mt_PlaceholderAttributedString_var = ((!IsDirectBinding) ? ((NSAttributedString)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selPlaceholderAttributedStringHandle))) : ((NSAttributedString)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(base.Handle, selPlaceholderAttributedStringHandle))))); } [Export("setPlaceholderAttributedString:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetPlaceholderAttributedString_Handle, value.Handle); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetPlaceholderAttributedString_Handle, value.Handle); } __mt_PlaceholderAttributedString_var = value; } } public virtual string[] AllowedInputSourceLocales { [Export("allowedInputSourceLocales")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return NSArray.StringArrayFromHandle(Messaging.IntPtr_objc_msgSend(base.Handle, selAllowedInputSourceLocalesHandle)); } return NSArray.StringArrayFromHandle(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, selAllowedInputSourceLocalesHandle)); } [Export("setAllowedInputSourceLocales:")] set { NSApplication.EnsureUIThread(); if (value == null) { throw new ArgumentNullException("value"); } NSArray nSArray = NSArray.FromStrings(value); if (IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr(base.Handle, selSetAllowedInputSourceLocales_Handle, nSArray.Handle); } else { Messaging.void_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetAllowedInputSourceLocales_Handle, nSArray.Handle); } nSArray.Dispose(); } } public override bool WantsNotificationForMarkedText { [Export("wantsNotificationForMarkedText")] get { NSApplication.EnsureUIThread(); if (IsDirectBinding) { return Messaging.bool_objc_msgSend(base.Handle, selWantsNotificationForMarkedTextHandle); } return Messaging.bool_objc_msgSendSuper(base.SuperHandle, selWantsNotificationForMarkedTextHandle); } [Export("setWantsNotificationForMarkedText:")] set { NSApplication.EnsureUIThread(); if (IsDirectBinding) { Messaging.void_objc_msgSend_bool(base.Handle, selSetWantsNotificationForMarkedText_Handle, value); } else { Messaging.void_objc_msgSendSuper_bool(base.SuperHandle, selSetWantsNotificationForMarkedText_Handle, value); } } } [EditorBrowsable(EditorBrowsableState.Advanced)] [Export("init")] public NSTextFieldCell() : 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 NSTextFieldCell(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 NSTextFieldCell(NSObjectFlag t) : base(t) { } [EditorBrowsable(EditorBrowsableState.Advanced)] public NSTextFieldCell(IntPtr handle) : base(handle) { } [Export("initTextCell:")] public NSTextFieldCell(string aString) : base(NSObjectFlag.Empty) { NSApplication.EnsureUIThread(); if (aString == null) { throw new ArgumentNullException("aString"); } IntPtr intPtr = NSString.CreateNative(aString); if (IsDirectBinding) { base.Handle = Messaging.IntPtr_objc_msgSend_IntPtr(base.Handle, selInitTextCell_Handle, intPtr); } else { base.Handle = Messaging.IntPtr_objc_msgSendSuper_IntPtr(base.SuperHandle, selInitTextCell_Handle, intPtr); } NSString.ReleaseNative(intPtr); } [Export("initImageCell:")] public NSTextFieldCell(NSImage image) : base(NSObjectFlag.Empty) { NSApplication.EnsureUIThread(); if (image == null) { throw new ArgumentNullException("image"); } if (IsDirectBinding) { base.Handle = Messaging.IntPtr_objc_msgSend_IntPtr(base.Handle, selInitImageCell_Handle, image.Handle); } else { base.Handle = Messaging.IntPtr_objc_msgSendSuper_IntPtr(base.SuperHandle, selInitImageCell_Handle, image.Handle); } } [Export("setUpFieldEditorAttributes:")] public new virtual NSText SetUpFieldEditorAttributes(NSText textObj) { NSApplication.EnsureUIThread(); if (textObj == null) { throw new ArgumentNullException("textObj"); } if (IsDirectBinding) { return (NSText)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend_IntPtr(base.Handle, selSetUpFieldEditorAttributes_Handle, textObj.Handle)); } return (NSText)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper_IntPtr(base.SuperHandle, selSetUpFieldEditorAttributes_Handle, textObj.Handle)); } protected override void Dispose(bool disposing) { base.Dispose(disposing); if (base.Handle == IntPtr.Zero) { __mt_BackgroundColor_var = null; __mt_TextColor_var = null; __mt_PlaceholderAttributedString_var = null; } } } }