/// <summary>Centers a window relative to its parent.</summary> static void CenterWindow(Window childControl, Window parentControl) { #if MAC NSWindow nsChild = childControl, nsParent = parentControl; if (nsParent == null || !nsParent.IsVisible) { nsChild.Center(); } else { int x = (int)(Math.Max(0, (nsParent.Frame.Width - nsChild.Frame.Width) / 2) + nsParent.Frame.X); int y = (int)(Math.Max(0, (nsParent.Frame.Height - nsChild.Frame.Height) / 2) + nsParent.Frame.Y); nsChild.SetFrame(new CoreGraphics.CGRect(x, y, nsChild.Frame.Width, nsChild.Frame.Height), true); } #else if (childControl.nativeWidget is Gtk.Window gtkChild) { gtkChild.Child.Show(); int x, y; gtkChild.GetSize(out var w, out var h); if (parentControl?.nativeWidget is Gtk.Window gtkParent) { gtkParent.GetSize(out var winw, out var winh); gtkParent.GetPosition(out var winx, out var winy); x = Math.Max(0, (winw - w) / 2) + winx; y = Math.Max(0, (winh - h) / 2) + winy; gtkChild.Move(x, y); } else { gtkChild.SetPosition(Gtk.WindowPosition.Center); } } #endif }
public override void DidFinishLaunching (NSNotification notification) { var menu = new NSMenu (); var menuItem = new NSMenuItem (); menu.AddItem (menuItem); var appMenu = new NSMenu (); var quitItem = new NSMenuItem ("Quit", "q", (s, e) => NSApplication.SharedApplication.Terminate (menu)); appMenu.AddItem (quitItem); menuItem.Submenu = appMenu; NSApplication.SharedApplication.MainMenu = menu; m_window = new NSWindow ( new CGRect (0, 0, 1024, 720), NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.TexturedBackground, NSBackingStore.Buffered, false) { Title = "Bluebird WkBrowser", ReleasedWhenClosed = false, ContentMinSize = new CGSize (1024, 600), CollectionBehavior = NSWindowCollectionBehavior.FullScreenPrimary }; m_window.Center (); m_window.MakeKeyAndOrderFront (null); var viewController = new ViewController (); m_window.ContentView = viewController.View; m_window.ContentViewController = viewController; viewController.View.Frame = m_window.ContentView.Bounds; }
public AppDelegate() { var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled; var rect = new CoreGraphics.CGRect(0, 0, 800, 600); window = new NSWindow(rect, style, NSBackingStore.Buffered, false); window.Title = "SkiaSharp"; window.TitleVisibility = NSWindowTitleVisibility.Hidden; window.Center(); }
public AppDelegate() { var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled; var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768); window = new NSWindow(rect, style, NSBackingStore.Buffered, false); window.Title = "WebView Example"; // choose your own Title here window.TitleVisibility = NSWindowTitleVisibility.Hidden; window.Center(); }
public static void Main(string[] args) { NSApplication.Init(); Gtk.Application.Init(); var gtkWindow = new Gtk.Window(Gtk.WindowType.Toplevel) { Title = "GTK Window", Gravity = Gdk.Gravity.Center, DefaultSize = new Gdk.Size(WindowWidth, WindowHeight), BorderWidth = Padding }; gtkWindow.Add(new Gtk.Widget(gtk_ns_view_new(new NativeViewHost().Handle))); gtkWindow.ShowAll(); var nativeWindow = new NSWindow( new CGRect(0, 0, WindowWidth, WindowHeight), NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, false) { Title = "Native Window", ContentView = new NativeViewHost() }; nativeWindow.Center(); nativeWindow.MakeKeyAndOrderFront(null); var menuBar = new NSMenu(); var appMenuItem = new NSMenuItem(); menuBar.AddItem(appMenuItem); var appMenu = new NSMenu(); appMenu.AddItem(new NSMenuItem("Quit", new ObjCRuntime.Selector("terminate:"), "q")); appMenuItem.Submenu = appMenu; NSApplication.SharedApplication.Delegate = new NSApplicationDelegate(); NSApplication.SharedApplication.MainMenu = menuBar; NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular; // Allow the native run loop to drive the app, and the GTK window // embedding a native view with a local event monitor will deliver // events as expected. // NSApplication.SharedApplication.Run(); // Let GTK drive the app, dispatching to the native run loop as // necessary, and the native view with a local event monitor will // only deliver events when the mouse is within the view's frame. Gtk.Application.Run(); }
public override void DidFinishLaunching(NSNotification notification) { var window = new NSWindow(new CGRect(0, 0, 500, 500), NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable, NSBackingStore.Buffered, false); var scrollView = new NSScrollView(); scrollView.BackgroundColor = NSColor.Blue; window.ContentView = scrollView; window.Center(); window.MakeKeyAndOrderFront(this); var liteHtmlWindow = new LiteHtmlSharp.Mac.LiteHtmlWindowHelper(window, window.Frame, LiteHtmlSharp.IncludedMasterCss.CssString); liteHtmlWindow.LiteHtmlView.LoadHtml(SampleHtml); }
public AppDelegate() { const NSWindowStyle style = NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable; var rect = new CoreGraphics.CGRect(200, 200, 1024, 768); MainWindow = new NSWindow(rect, style, NSBackingStore.Buffered, false) { Title = "Demo", TitleVisibility = NSWindowTitleVisibility.Hidden }; MainWindow.Center(); NSApplication.SharedApplication.MainMenu = new NSMenu(); }
public override void DidFinishLaunching(NSNotification notification) { var flags = NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable | NSWindowStyle.FullSizeContentView; var window = new NSWindow(new CGRect(x: 0, y: 0, width: 480, height: 300), flags, NSBackingStore.Buffered, deferCreation: false); window.WillClose += delegate { window.ContentView = NSTextField.CreateLabel("CLOSING"); GC.Collect(); }; window.Center(); window.ContentView = new NSHostingView(new ClickButton()); window.MakeKeyAndOrderFront(this); }
public override void DidFinishLaunching(NSNotification notification) { // Init segues and forms Segue.Init(); Xamarin.Forms.Forms.Init(); // Start the app window = new NSWindow( new CGRect(0, 0, 400, 600), NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable | NSWindowStyle.Titled, NSBackingStore.Buffered, deferCreation: false); LoadApplication(new App()); base.DidFinishLaunching(notification); window.Center(); }
public override void DidFinishLaunching(NSNotification notification) { // Handle CMD-Q NSMenu mainMenu = NSApplication.SharedApplication.MainMenu = new NSMenu("Exception marshaling"); mainMenu.AddItem("Sub", new ObjCRuntime.Selector("sub"), "S"); var subMenu = new NSMenu("Sub"); var quit = new NSMenuItem("Quit", (sender, e) => { NSApplication.SharedApplication.Terminate(this); }); quit.Enabled = true; quit.KeyEquivalent = "q"; quit.KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask; subMenu.AddItem(quit); mainMenu.AutoEnablesItems = false; mainMenu.SetSubmenu(subMenu, mainMenu.ItemAt(0)); // Create main window and its UI window = new NSWindow(new CGRect(0, 0, 500, 500), NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable, NSBackingStore.Buffered, true); window.Title = "Exception marshaling"; var protoCell = new NSButtonCell(); protoCell.SetButtonType(NSButtonType.Radio); var cellSize = new CGSize(300, 25); var boxSize = new CGSize(300, 400); var managedBox = new NSBox(new CGRect(new CGPoint(0, 0), boxSize)); var objectiveCBox = new NSBox(new CGRect(new CGPoint(managedBox.Frame.Right, managedBox.Frame.Y), boxSize)); var throwManagedException = new NSButton(new CGRect((boxSize.Width - 200) / 2, 0, 200, cellSize.Height)); throwManagedException.Title = "Throw managed exception"; var marshalManagedModeMatrix = new NSMatrix(new CGRect(0, 0, managedBox.Frame.Width, cellSize.Height * 6 + 10), NSMatrixMode.Radio, protoCell, 6, 1); marshalManagedModeMatrix.Cells [0].Title = "None"; marshalManagedModeMatrix.Cells [1].Title = "Default"; marshalManagedModeMatrix.Cells [2].Title = "Unwind native code"; marshalManagedModeMatrix.Cells [3].Title = "Throw Objective-C exception"; marshalManagedModeMatrix.Cells [4].Title = "Abort"; marshalManagedModeMatrix.Cells [5].Title = "Disable"; marshalManagedModeMatrix.CellSize = cellSize; var marshalManagedMode = new NSBox(new CGRect(0, throwManagedException.Frame.Bottom + 20, marshalManagedModeMatrix.Frame.Width, marshalManagedModeMatrix.Frame.Height + cellSize.Height)); marshalManagedMode.Title = "Marshaling mode"; marshalManagedMode.AddSubview(marshalManagedModeMatrix); var threadManagedMatrix = new NSMatrix(new CGRect(0, 0, managedBox.Frame.Width, cellSize.Height * 3 + 10), NSMatrixMode.Radio, protoCell, 3, 1); threadManagedMatrix.Cells [0].Title = "Main thread"; threadManagedMatrix.Cells [1].Title = "Background thread"; threadManagedMatrix.Cells [2].Title = "Threadpool thread"; threadManagedMatrix.CellSize = cellSize; var threadManaged = new NSBox(new CGRect(new CGPoint(0, marshalManagedMode.Frame.Bottom + 20), new CGSize(threadManagedMatrix.Frame.Width, threadManagedMatrix.Frame.Height + cellSize.Height))); threadManaged.Title = "Thread"; threadManaged.AddSubview(threadManagedMatrix); var marshalObjectiveCModeMatrix = new NSMatrix(marshalManagedModeMatrix.Frame, NSMatrixMode.Radio, protoCell, 6, 1); marshalObjectiveCModeMatrix.Cells [0].Title = "None"; marshalObjectiveCModeMatrix.Cells [1].Title = "Default"; marshalObjectiveCModeMatrix.Cells [2].Title = "Unwind managed code"; marshalObjectiveCModeMatrix.Cells [3].Title = "Throw managed exception"; marshalObjectiveCModeMatrix.Cells [4].Title = "Abort"; marshalObjectiveCModeMatrix.Cells [5].Title = "Disable"; marshalObjectiveCModeMatrix.CellSize = cellSize; var marshalObjectiveCMode = new NSBox(marshalManagedMode.Frame); marshalObjectiveCMode.Title = "Marshaling mode"; marshalObjectiveCMode.AddSubview(marshalObjectiveCModeMatrix); var threadObjectiveCMatrix = new NSMatrix(threadManagedMatrix.Frame, threadManagedMatrix.Mode, threadManagedMatrix.Prototype, threadManagedMatrix.Rows, threadManagedMatrix.Columns); threadObjectiveCMatrix.Cells [0].Title = "Main thread"; threadObjectiveCMatrix.Cells [1].Title = "Background thread"; threadObjectiveCMatrix.Cells [2].Title = "Threadpool thread"; threadObjectiveCMatrix.CellSize = cellSize; var threadObjectiveC = new NSBox(threadManaged.Frame); threadObjectiveC.Title = "Thread"; threadObjectiveC.AddSubview(threadObjectiveCMatrix); var throwObjectiveCException = new NSButton(throwManagedException.Frame); throwObjectiveCException.Title = "Throw Objective-C exception"; managedBox.Title = "Managed exception"; managedBox.AddSubview(throwManagedException); managedBox.AddSubview(threadManaged); managedBox.AddSubview(marshalManagedMode); managedBox.Frame = new CGRect(managedBox.Frame.X, managedBox.Frame.Y, managedBox.Frame.Width, threadManaged.Frame.Bottom + cellSize.Height); //managedBox.SetBoundsSize (new CGSize (managedBox.Bounds.Width, threadManaged.Frame.Bottom)); window.ContentView.AddSubview(managedBox); objectiveCBox.Title = "Objective-C exception"; objectiveCBox.AddSubview(throwObjectiveCException); objectiveCBox.AddSubview(threadObjectiveC); objectiveCBox.AddSubview(marshalObjectiveCMode); objectiveCBox.Frame = new CGRect(objectiveCBox.Frame.Location, managedBox.Frame.Size); window.ContentView.AddSubview(objectiveCBox); var windowContentSize = new CGSize(managedBox.Frame.Width + objectiveCBox.Frame.Width, Math.Max(managedBox.Frame.Height, objectiveCBox.Frame.Height)); window.SetContentSize(windowContentSize); window.ContentMinSize = windowContentSize; window.Center(); window.MakeKeyAndOrderFront(window); Action setModes = () => { if (marshalManagedModeMatrix.SelectedRow == 0) { Exceptions.ManagedExceptionMode = null; } else { Exceptions.ManagedExceptionMode = (MarshalManagedExceptionMode)(int)marshalManagedModeMatrix.SelectedRow - 1; } if (marshalObjectiveCModeMatrix.SelectedRow == 0) { Exceptions.ObjectiveCExceptionMode = null; } else { Exceptions.ObjectiveCExceptionMode = (MarshalObjectiveCExceptionMode)(int)marshalObjectiveCModeMatrix.SelectedRow - 1; } }; throwObjectiveCException.Activated += (sender, e) => { setModes(); Exceptions.ThrowObjectiveCException((ThreadMode)(int)threadObjectiveCMatrix.SelectedRow); }; throwManagedException.Activated += (sender, e) => { setModes(); Exceptions.ThrowManagedException((ThreadMode)(int)threadManagedMatrix.SelectedRow); }; }