public CocoaWindow(WindowConfiguration config, WebviewBridge bridge) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (bridge == null) { throw new ArgumentNullException(nameof(bridge)); } Handle = AppKit.Call("NSWindow", "alloc"); canResizeField = config.CanResize; var style = GetWantedStyleMask(); ObjC.SendMessage( Handle, ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"), new CGRect(0, 0, config.Size.Width, config.Size.Height), new UIntPtr((uint)style), new UIntPtr(2), false); webview = new CocoaWebview(bridge); ObjC.Call(Handle, "setContentView:", webview.Handle); webview.TitleChanged += Webview_TitleChanged; windowDelegate = WindowDelegateDefinition.CreateInstance(this); ObjC.Call(Handle, "setDelegate:", windowDelegate.Handle); }
public CocoaStatusIcon() { var statusBar = AppKit.Call("NSStatusBar", "systemStatusBar"); statusItem = ObjC.Call(statusBar, "statusItemWithLength:", -2.0); // -1 = variable size; -2 = square size ObjC.Call(statusItem, "setHighlightMode:", true); statusBarButton = ObjC.Call(statusItem, "button"); ObjC.Call(statusBarButton, "setImageScaling:", 3); // 3 = scale proportionally up or down }
public CocoaWindow(WindowConfiguration config, IUiFactory windowFactory) { if (windowFactory == null) { throw new ArgumentNullException(nameof(windowFactory)); } this.config = config ?? throw new ArgumentNullException(nameof(config)); Interlocked.Increment(ref count); // need to keep the delegates around or they will get garbage collected windowShouldCloseDelegate = WindowShouldCloseCallback; windowWillCloseDelegate = WindowWillCloseCallback; Handle = AppKit.Call("NSWindow", "alloc"); var style = NSWindowStyleMask.Titled | NSWindowStyleMask.Closable | NSWindowStyleMask.Miniaturizable; if (config.CanResize) { style |= NSWindowStyleMask.Resizable; } ObjC.SendMessage( Handle, ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"), new CGRect(0, 0, config.Width, config.Height), (int)style, 2, 0); Title = config.Title; IntPtr bgColor = NSColor.FromHex(config.BackgroundColor); ObjC.Call(Handle, "setBackgroundColor:", bgColor); var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder); bridge = new WebviewBridge(); webview = new CocoaWebview(config, contentProvider, bridge); ObjC.Call(Handle, "setContentView:", webview.Handle); if (config.EnableScriptInterface) { bridge.Init(this, webview, windowFactory); } if (config.UseBrowserTitle) { webview.TitleChanged += Webview_TitleChanged; bridge.TitleChanged += Webview_TitleChanged; } SetWindowDelegate(Handle); }
public CocoaStatusIcon(string title) { var statusBar = AppKit.Call("NSStatusBar", "systemStatusBar"); statusItem = ObjC.Call(statusBar, "statusItemWithLength:", -2.0); // -1 = variable size; -2 = square size ObjC.Call(statusItem, "setHighlightMode:", true); statusBarButton = ObjC.Call(statusItem, "button"); ObjC.Call(statusBarButton, "setImageScaling:", new UIntPtr((uint)NSImageScaling.ProportionallyUpOrDown)); Title = title; }
private CocoaLabelMenuItem(string label, string action) : base(AppKit.Call("NSMenuItem", "alloc")) { ObjC.Call( Handle, "initWithTitle:action:keyEquivalent:", NSString.Create(label), ObjC.RegisterName(action), NSString.Create(string.Empty)); }
public CocoaApplication() { Factory = new CocoaUiFactory(); SynchronizationContext = new CocoaSynchronizationContext(); Handle = AppKit.Call("NSApplication", "sharedApplication"); appDelegate = AppDelegateDefinition.CreateInstance(this); ObjC.Call(Handle, "setActivationPolicy:", IntPtr.Zero); ObjC.Call(Handle, "setDelegate:", appDelegate.Handle); }
public CocoaMenu(string title) { if (title != null) { Handle = AppKit.Call("NSMenu", "alloc"); ObjC.Call(Handle, "initWithTitle:", NSString.Create(title)); } else { Handle = AppKit.Call("NSMenu", "new"); } }
public CocoaApplication() { Factory = new CocoaUiFactory(); SynchronizationContext = new CocoaSynchronizationContext(); Handle = AppKit.Call("NSApplication", "sharedApplication"); appDelegate = AppDelegateDefinition.CreateInstance(this); ObjC.Call(Handle, "setActivationPolicy:", IntPtr.Zero); ObjC.Call(Handle, "setDelegate:", appDelegate.Handle); ObjC.SetProperty(AppKit.GetClass("NSWindow"), "allowsAutomaticWindowTabbing", false); }
public CocoaLabelMenuItem(string label) : base(AppKit.Call("NSMenuItem", "alloc")) { // need to keep the delegate around or it will get garbage collected menuDelegate = MenuCallback; ObjC.Call( Handle, "initWithTitle:action:keyEquivalent:", NSString.Create(label), ObjC.RegisterName("menuCallback:"), NSString.Create(string.Empty)); SetCallbackClass(); }
private unsafe void UpdateIcon(AppIcon?icon) { var image = IntPtr.Zero; if (icon != null && icon.Icons.Length > 0) { byte[] data = icon.GetIconData(icon.DefaultIcon); fixed(byte *dataPtr = data) { IntPtr nsData = Foundation.Call( "NSData", "dataWithBytesNoCopy:length:freeWhenDone:", (IntPtr)dataPtr, new IntPtr(data.Length), IntPtr.Zero); image = AppKit.Call("NSImage", "alloc"); ObjC.Call(image, "initWithData:", nsData); ObjC.Call(statusBarButton, "setImage:", image); } } ObjC.Call(statusBarButton, "setImage:", image); }
public static NSDialog CreateAlert() { var alert = AppKit.Call("NSAlert", "new"); return(new NSDialog(alert, ObjC.Call(alert, "window"), true)); }
internal static IntPtr GetApp() { return(AppKit.Call("NSApplication", "sharedApplication")); }
public CocoaSeparatorMenuItem() : base(AppKit.Call("NSMenuItem", "separatorItem")) { }
public static NSDialog CreateOpenPanel() { var panel = AppKit.Call("NSOpenPanel", "openPanel"); return(new NSDialog(panel, panel, false)); }
public static NSDialog CreateSavePanel() { var panel = AppKit.Call("NSSavePanel", "savePanel"); return(new NSDialog(panel, panel, false)); }
public static IntPtr FromHex(string?hex) { ColorTools.ParseHex(hex, out byte r, out byte g, out byte b); return(AppKit.Call("NSColor", "colorWithRed:green:blue:alpha:", r / 255d, g / 255d, b / 255d, 1d)); }
public CocoaMenu() : base(AppKit.Call("NSMenu", "new")) { ObjC.Call(Handle, "setAutoenablesItems:", false); }
public void AddSeparatorMenuItem() { var item = AppKit.Call("NSMenuItem", "separatorItem"); AddItem(item); }