protected OptionPathMonobjc(NSRect aRect, Option aOption) : base(aOption) { iView = new NSView(); iTextField = new NSTextField(); iTextField.SetTitleWithMnemonic(new NSString(iOption.Value)); iTextField.IsEditable = false; iTextField.IsSelectable = false; //textField.AutoresizingMask = NSResizingFlags.NSViewWidthSizable | NSResizingFlags.NSViewMaxXMargin | NSResizingFlags.NSViewMaxYMargin; iButtonChange = new NSButton(); iButtonChange.BezelStyle = NSBezelStyle.NSRoundedBezelStyle; iButtonChange.Title = new NSString("Change..."); iButtonChange.SizeToFit(); iButtonChange.ActionEvent += ActionEventChange; float height = 60 + iButtonChange.Frame.Height; iView.Frame = new NSRect(aRect.MinX, aRect.MinY - height, aRect.Width, height); iTextField.Frame = new NSRect(0, height - 60, aRect.Width, 60); iButtonChange.Frame = new NSRect(iView.Frame.Width - iButtonChange.Frame.Width, iTextField.Frame.MinY - iButtonChange.Frame.Height, iButtonChange.Frame.Width, iButtonChange.Frame.Height); iView.AddSubview(iTextField); iView.AddSubview(iButtonChange); }
public override void ViewDidLoad() { View = new NSView(new CGRect(0, 100, 320, 400)); base.ViewDidLoad(); var textEditFirst = new NSTextField(new CGRect(10, 0, 320, 40)); View.AddSubview(textEditFirst); var textEditSecond = new NSTextField(new CGRect(10, 50, 320, 40)); View.AddSubview(textEditSecond); var labelFull = new NSTextField(new CGRect(10, 100, 320, 40)); View.AddSubview(labelFull); var bu = new NSButton(new CGRect(0, 150, 320, 40)); bu.Title = "Hello"; View.AddSubview(bu); var set = this.CreateBindingSet <FirstViewController, FirstViewModel> (); set.Bind(textEditFirst).For(v => v.StringValue).To(vm => vm.FirstName); set.Bind(textEditSecond).For(v => v.StringValue).To(vm => vm.LastName); set.Bind(labelFull).For(v => v.StringValue).To(vm => vm.FullName); set.Bind(bu).For("Activated").To("GoCommand"); set.Apply(); }
protected override void OnRealized() { LogEnter(); try { GdkWindow = Parent?.GdkWindow; if (GdkWindow != null && GdkWindow.Handle != IntPtr.Zero) { var superviewHandle = gdk_quartz_window_get_nsview(GdkWindow.Handle); if (superviewHandle != IntPtr.Zero) { superview = Runtime.GetNSObject <NSView> (superviewHandle); } } if (superview != null && view != null) { if (zOrder.HasValue) { superview.AddSubview(view, zOrder.Value, null); } else { superview.AddSubview(view); } } base.OnRealized(); UpdateViewFrame(); CanFocus = GetAcceptsFirstResponderView() != null; } finally { LogExit(); } }
public void SubviewSort() { using (var containerView = new NSView()) using (var a = new NSTextView() { Value = "a" }) using (var b = new NSTextView() { Value = "b" }) using (var c = new NSTextView() { Value = "c" }) { containerView.AddSubview(b); containerView.AddSubview(c); containerView.AddSubview(a); Assert.Throws <ArgumentNullException> (() => containerView.SortSubviews(null), "ANE"); Assert.AreEqual(3, containerView.Subviews.Length, "Presort Length"); Assert.AreEqual("b", ((NSTextView)containerView.Subviews [0]).Value, "Presort Value 0"); Assert.AreEqual("c", ((NSTextView)containerView.Subviews [1]).Value, "Presort Value 1"); Assert.AreEqual("a", ((NSTextView)containerView.Subviews [2]).Value, "Presort Value 2"); containerView.SortSubviews((x, y) => { var viewX = (NSTextView)x; var viewY = (NSTextView)y; var rv = string.Compare(viewX.Value, viewY.Value); if (rv == 0) { return(NSComparisonResult.Same); } else if (rv < 0) { return(NSComparisonResult.Ascending); } else { return(NSComparisonResult.Descending); } }); Assert.AreEqual(3, containerView.Subviews.Length, "Postsort Length"); Assert.AreEqual("a", ((NSTextView)containerView.Subviews [0]).Value, "Postsort Value 0"); Assert.AreEqual("b", ((NSTextView)containerView.Subviews [1]).Value, "Postsort Value 1"); Assert.AreEqual("c", ((NSTextView)containerView.Subviews [2]).Value, "Postsort Value 2"); try { containerView.SortSubviews((x, y) => { throw new ApplicationException("Something went wrong"); }); Assert.Fail("No exception thrown"); } catch (Exception e) { Assert.AreEqual("An exception occurred during sorting.", e.Message, "Exception Message"); Assert.AreEqual("Something went wrong", e.InnerException.Message, "InnerException Message"); } } }
public override void AwakeFromNib() { base.AwakeFromNib(); container = new NSView(); btn1 = new NSButton(); btn1.Title = "First Button"; btn1.SizeToFit(); btn2 = new NSButton(); btn2.Title = "Second Button"; btn2.SizeToFit(); btn3 = new NSButton(); btn3.Title = "Third Button"; btn3.SizeToFit(); var rect = btn2.Frame; rect.X += btn1.Frame.Right + 10; btn2.Frame = rect; rect = btn3.Frame; rect.X += btn2.Frame.Right + 10; btn3.Frame = rect; container.AddSubview(btn1); container.AddSubview(btn2); container.AddSubview(btn3); container.Frame = new CoreGraphics.CGRect(0, 0, btn3.Frame.Right, btn3.Frame.Bottom); Scroll.DocumentView = container; Scroll.HasHorizontalScroller = true; }
public MainWindow(CGRect contentRect, NSWindowStyle aStyle, NSBackingStore bufferingType, bool deferCreation) : base(contentRect, aStyle, bufferingType, deferCreation) { // Define the User Interface of the Window here Title = "Window From Code"; // Create the content view for the window and make it fill the window ContentView = new NSView(Frame); // Add UI Elements to window ClickMeButton = new NSButton(new CGRect(10, Frame.Height - 70, 100, 30)) { AutoresizingMask = NSViewResizingMask.MinYMargin }; ContentView.AddSubview(ClickMeButton); ClickMeLabel = new NSTextField(new CGRect(120, Frame.Height - 65, Frame.Width - 130, 20)) { BackgroundColor = NSColor.Clear, TextColor = NSColor.Black, Editable = false, Bezeled = false, AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.MinYMargin, StringValue = "Button has not been clicked yet." }; ContentView.AddSubview(ClickMeLabel); }
public ICredentials GetCredentials(Uri uri, IWebProxy proxy, CredentialType credentialType, ICredentials existingCredentials, bool retrying) { bool result = false; DispatchService.GuiSyncDispatch(() => { using (var ns = new NSAutoreleasePool()) { var message = string.Format("{0} needs {1} credentials to access {2}.", BrandingService.ApplicationName, credentialType == CredentialType.ProxyCredentials ? "proxy" : "request", uri.Host); NSAlert alert = NSAlert.WithMessage("Credentials Required", "OK", "Cancel", null, message); alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; NSView view = new NSView(new RectangleF(0, 0, 313, 91)); var creds = Utility.GetCredentialsForUriFromICredentials(uri, existingCredentials); var usernameLabel = new NSTextField(new RectangleF(17, 55, 71, 17)) { Identifier = "usernameLabel", StringValue = "Username:"******"Password:", Alignment = NSTextAlignment.Right, Editable = false, Bordered = false, DrawsBackground = false, Bezeled = false, Selectable = false, }; view.AddSubview(passwordLabel); var passwordInput = new NSSecureTextField(new RectangleF(93, 20, 200, 22)); passwordInput.StringValue = creds != null ? creds.Password : string.Empty; view.AddSubview(passwordInput); alert.AccessoryView = view; result = alert.RunModal() == 1; username = usernameInput.StringValue; password = passwordInput.StringValue; } }); return(result ? new NetworkCredential(username, password) : null); }
public OptionListMonobjc(NSRect aRect, Option aOption) : base(aOption) { iList = new List <string>(StringListConverter.StringToList(iOption.Value)); iDataSource = new OptionListMonobjcDataSource(); iDataSource.SetList(iList); iView = new NSView(); iButtonAdd = new NSButton(); iButtonAdd.BezelStyle = NSBezelStyle.NSRoundedBezelStyle; iButtonAdd.Title = new NSString("Add"); iButtonAdd.SizeToFit(); iButtonAdd.ActionEvent += ActionEventAdd; iButtonRemove = new NSButton(); iButtonRemove.BezelStyle = NSBezelStyle.NSRoundedBezelStyle; iButtonRemove.SetTitleWithMnemonic(new NSString("Remove")); iButtonRemove.SizeToFit(); float height = 100 + iButtonAdd.Frame.Height; iButtonRemove.ActionEvent += ActionEventRemove; iView.Frame = new NSRect(aRect.MinX, aRect.MinY - height, aRect.Width, height); NSScrollView scrollView = new NSScrollView(); scrollView.HasVerticalScroller = true; scrollView.HasHorizontalScroller = true; scrollView.AutohidesScrollers = true; NSTableColumn tableColumn = new NSTableColumn(); tableColumn.ResizingMask = NSTableColumnResizingMasks.NSTableColumnAutoresizingMask | NSTableColumnResizingMasks.NSTableColumnUserResizingMask; tableColumn.IsEditable = false; iTableView = new NSTableView(); iTableView.DataSource = iDataSource; iTableView.HeaderView = null; iTableView.UsesAlternatingRowBackgroundColors = true; iTableView.AddTableColumn(tableColumn); scrollView.Frame = new NSRect(0, height - 100, aRect.Width, 100); iTableView.Frame = scrollView.ContentView.Bounds; tableColumn.Width = iTableView.Bounds.Width - 3; scrollView.DocumentView = iTableView; iButtonAdd.Frame = new NSRect(iView.Frame.Width - iButtonAdd.Frame.Width - iButtonRemove.Frame.Width, scrollView.Frame.MinY - iButtonAdd.Frame.Height, iButtonAdd.Frame.Width, iButtonAdd.Frame.Height); iButtonRemove.Frame = new NSRect(iView.Frame.Width - iButtonRemove.Frame.Width, scrollView.Frame.MinY - iButtonRemove.Frame.Height, iButtonRemove.Frame.Width, iButtonRemove.Frame.Height); iView.AddSubview(scrollView); iView.AddSubview(iButtonAdd); iView.AddSubview(iButtonRemove); iTableView.ReloadData(); }
public OptionPageMonobjc(IOptionPage aOptionsPage, NSRect aFrameRect) { iName = aOptionsPage.Name; iView = new NSView(aFrameRect); iControls = new List <IOptionMonobjc>(); float y = iView.Frame.Height - 10; float mid = iView.Frame.Width * 0.5f; foreach (Option option in aOptionsPage.Options) { NSTextField label = new NSTextField(); label.SetTitleWithMnemonic(new NSString(option.Name + ":")); label.IsSelectable = false; label.IsEditable = false; label.IsBordered = false; label.DrawsBackground = false; label.Alignment = NSTextAlignment.NSLeftTextAlignment; label.SizeToFit(); label.Frame = new NSRect(10, y - label.Frame.Height, mid - 20, label.Frame.Height); iView.AddSubview(label); IOptionMonobjc o = null; if (option is OptionEnum || option is OptionNetworkInterface) { o = new OptionNetworkInterfaceMonobjc(new NSRect(mid, y, mid - 10, 20), option); } else if (option is OptionFilePath) { o = new OptionFilePathMonobjc(new NSRect(mid, y, mid - 10, 20), option); } else if (option is OptionFolderPath) { o = new OptionFolderPathMonobjc(new NSRect(mid, y, mid - 10, 20), option); } else if (option is OptionBool) { o = new OptionBoolMonobjc(new NSRect(mid, y, mid - 10, 20), option); } else if (option is OptionListFolderPath) { o = new OptionListFolderPathMonobjc(new NSRect(mid, y, mid - 10, 20), option); } if (o != null) { iView.AddSubview(o.View); y -= o.Height; iControls.Add(o); } } }
public void Initialize(NSView contentView) { var roseImage = NSImage.ImageNamed("basketball.png"); var squareImage = NSImage.ImageNamed("football.png"); square = new PhysicObject(squareImage, 20, spc, false); ground = new PhysicObject(roseImage, 20, spc, false); square.SetPosition(300, 0); ground.SetPosition(330, 0); contentView.AddSubview(square); contentView.AddSubview(ground); }
void CreateFilters(FileFilter [] filters) { if (filters.Any()) { var label = new NSTextField(); var fileTypes = new NSPopUpButton(); fileTypes.AddItems(filters.Select(f => f.Label).ToArray()); var fileTypeView = new NSView(); fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; const int padding = 15; label.StringValue = "Show Files"; label.DrawsBackground = false; label.Bordered = false; label.Bezeled = false; label.Editable = false; label.Selectable = false; label.SizeToFit(); fileTypeView.AddSubview(label); fileTypes.SizeToFit(); fileTypes.Activated += (sender, e) => { var currentFilter = filters.FirstOrDefault(f => f.Label == fileTypes.TitleOfSelectedItem); SetCurrentItem(currentFilter); // THIS DOES NOT WORK ON MAC OS FROM MAVERICS TO YOSEMITE // There exists hacks, however they are dependent on OS X version // I have filed bug as many others, but I guess this will never be fixed _panel.ValidateVisibleColumns(); _panel.Update(); }; fileTypeView.AddSubview(fileTypes); fileTypes.SetFrameOrigin(new CGPoint(label.Frame.Width + 10, padding)); label.SetFrameOrigin(new CGPoint(0, padding + (fileTypes.Frame.Height - label.Frame.Height) / 2)); fileTypeView.Frame = new CGRect(0, 0, fileTypes.Frame.Width + label.Frame.Width + 10, fileTypes.Frame.Height + padding * 2); _panel.AccessoryView = fileTypeView; if (filters.Any()) { SetCurrentItem(filters.First()); } } else { _panel.AccessoryView = null; } }
public void Initialise(NSView aParent) { // create the background iBkgd = new ButtonHoverType2Bkgd(); iBkgd.InitWithFrame(aParent.Bounds); iBkgd.AutoresizingMask = NSResizingFlags.NSViewWidthSizable; aParent.AddSubview(iBkgd); // create the button iButton = new NSButton(); iButton.InitWithFrame(aParent.Bounds); iButton.Cell = new ButtonHoverType2Cell(); iButton.AutoresizingMask = NSResizingFlags.NSViewWidthSizable; iButton.SetButtonType(NSButtonType.NSMomentaryChangeButton); iButton.IsBordered = true; iButton.BezelStyle = NSBezelStyle.NSRegularSquareBezelStyle; iButton.AlphaValue = 0.0f; iButton.ImagePosition = NSCellImagePosition.NSImageOnly; iButton.Title = NSString.Empty; iButton.AlternateTitle = NSString.Empty; iButton.Image = null; iButton.AlternateImage = null; iBkgd.AddSubview(iButton); SetOn(false); }
private void InsertPage(ContentPage page, int index) { IVisualElementRenderer renderer = Platform.GetRenderer((VisualElement)page); if (renderer == null) { renderer = Platform.CreateRenderer((VisualElement)page); Platform.SetRenderer((VisualElement)page, renderer); } NSView view = (NSView) new CarouselPageRenderer.PageContainer((VisualElement)page); view.AddSubview(renderer.NativeView); this.containerMap [(Page)page] = view; this.AddChildViewController(renderer.ViewController); var otherView = index < scrollView.Subviews.Length ? scrollView.Subviews[index] : (NSView)null; this.scrollView.AddSubview(view, NSWindowOrderingMode.Below, otherView); if ((index != 0 || this.SelectedIndex != 0) && index >= this.SelectedIndex) { return; } this.ScrollToPage(this.SelectedIndex + 1, false); }
public MainWindowView(IntPtr handle) : base(handle) { bottomView = Subviews.First(x => x.Identifier == "PlaybackBar"); bottomView.AddSubview(new PlaybackBar(bottomView.Bounds)); topView = Subviews.OfType <NSSplitView> ().First(); LayoutSubviews(); }
// Shared initialization code private void Initialize() { Title = DefaultTitle; MinSize = MinimumSize; CollectionBehavior = NSWindowCollectionBehavior.FullScreenPrimary; AllowsToolTipsWhenApplicationIsInactive = false; AutorecalculatesKeyViewLoop = false; ReleasedWhenClosed = false; AnimationBehavior = NSWindowAnimationBehavior.Default; ContentView = new NSView(Frame); // Add a web view to the window WebView = new WebView(ContentView.Frame) { AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable }; WebView.TitleChanged += (_, title) => Title = title.Length > 0 ? $"{title} - {DefaultTitle}" : DefaultTitle; ContentView.AddSubview(WebView); }
static void UpdateGroup(NativeToolbarGroup group, IList <ToolbarItem> toolbarItems, double itemWidth, double itemSpacing) { int count = toolbarItems.Count; group.Items.Clear(); if (count > 0) { var subItems = new NSToolbarItem[count]; var view = new NSView(); nfloat totalWidth = 0; var currentX = 0.0; for (int i = 0; i < toolbarItems.Count; i++) { var element = toolbarItems[i]; var item = new NSToolbarItem(element.Text); item.Activated += (sender, e) => (element as IMenuItemController).Activate(); var button = new NSButton(); button.Title = element.Text; button.SizeToFit(); var buttonWidth = itemWidth; if (button.FittingSize.Width > itemWidth) { buttonWidth = button.FittingSize.Width + 10; } button.Frame = new CGRect(currentX + i * itemSpacing, 0, buttonWidth, ToolbarItemHeight); currentX += buttonWidth; totalWidth += button.Frame.Width; button.Activated += (sender, e) => (element as IMenuItemController).Activate(); button.BezelStyle = NSBezelStyle.TexturedRounded; if (!string.IsNullOrEmpty(element.Icon)) { button.Image = new NSImage(element.Icon); } button.SizeToFit(); view.AddSubview(button); item.Label = item.PaletteLabel = item.ToolTip = button.ToolTip = element.Text; subItems[i] = item; group.Items.Add(new NativeToolbarGroup.Item { ToolbarItem = item, Button = button }); } view.Frame = new CGRect(0, 0, totalWidth + (itemSpacing * (count - 1)), ToolbarItemHeight); group.Group.Subitems = subItems; group.Group.View = view; } else { group.Group.Subitems = new NSToolbarItem[] { }; group.Group.View = new NSView(); } }
void AddInfoUpdateState() { NSView superView = InfoButton.Superview; nint updateCount = PublicationsDataManager.SharedInstance.CurrentPubliction.UpdateCount; if (updateCount <= 0) { NSView [] views = superView.Subviews; nint count = views.Length; if (count > 2) { NSButton button = (NSButton)views [count - 1]; button.RemoveFromSuperview(); } return; } CGRect frame = InfoButton.Frame; CGRect newFrame = new CGRect(frame.Right - 13, frame.Bottom - 12, 15, 15); NSButton newButton = new NSButton(newFrame); newButton.Cell.BezelStyle = NSBezelStyle.Circular; newButton.Cell.Bordered = false; newButton.WantsLayer = true; newButton.Layer.BackgroundColor = NSColor.Red.CGColor; newButton.Layer.CornerRadius = 7.5f; newButton.Alignment = NSTextAlignment.Center; //button.Enabled = false; string infoTitle = updateCount.ToString(); newButton.AttributedTitle = Utility.AttributeTitle(infoTitle, NSColor.White, 8); superView.AddSubview(newButton); }
public static void LoadFigma(this NSView contentView, FigmaFrameEntityResponse frameEntityResponse, List <FigmaImageView> figmaImageViews = null) { //clean views from current container var views = contentView.Subviews; foreach (var item in views) { item.RemoveFromSuperview(); } contentView.RemoveConstraints(contentView.Constraints); //Figma doesn't calculate the bounds of our first level frameEntityResponse.FigmaMainNode.CalculateBounds(); contentView.WantsLayer = true; var backgroundColor = frameEntityResponse.FigmaMainNode.backgroundColor.ToNSColor(); contentView.Layer.BackgroundColor = backgroundColor.CGColor; var figmaView = frameEntityResponse.FigmaMainNode as FigmaNode; var mainView = figmaView.ToNSView(contentView, figmaView, figmaImageViews); if (mainView != null) { contentView.AddSubview(mainView); } }
public NSView CreateView(float minHeight = 0) { CGSize bounds = GetBounds(minHeight); NSView view = new NSView(new CGRect(new CGPoint(0, 0), bounds)); view.AutoresizingMask = NSViewResizingMask.NotSizable | NSViewResizingMask.MinYMargin; var yCoord = view.Frame.Bottom; foreach (var control in __Controls) { if (control.Hidden) { continue; } control.Frame = new CGRect(control.Frame.X, yCoord - control.Frame.Height, control.Frame.Width, control.Frame.Height); if (!(control is MarginControl)) { view.AddSubview(control); } yCoord -= control.Frame.Height; } return(view); }
static NSView GetExtraButton(ActionSheetArguments arguments) { var newView = new NSView(); int height = 50; int width = 300; int i = 0; foreach (var button in arguments.Buttons) { var btn = new NSButton { Title = button, Tag = i }; btn.SetButtonType(NSButtonType.MomentaryPushIn); btn.Activated += (s, e) => { NSApplication.SharedApplication.EndSheet(NSApplication.SharedApplication.MainWindow.AttachedSheet, ((NSButton)s).Tag + 2); }; btn.Frame = new RectangleF(0, height * i, width, height); newView.AddSubview(btn); i++; } newView.Frame = new RectangleF(0, 0, width, height * i); return(newView); }
public virtual void UpdateLayout() { if (frontend.Margin.HorizontalSpacing == 0 && frontend.Margin.VerticalSpacing == 0) { if (alignment != null) { Widget.RemoveFromSuperview(); NSView cont = alignment.Superview; if (cont != null) { MacEngine.ReplaceChild(cont, alignment, Widget); } alignment.Dispose(); alignment = null; } } else { if (alignment == null) { alignment = new NSView(); alignment.Frame = Widget.Frame; NSView cont = Widget.Superview; if (cont != null) { MacEngine.ReplaceChild(cont, Widget, alignment); } alignment.AddSubview(Widget); } Rectangle frame = new Rectangle((int)frontend.Margin.Left, (int)frontend.Margin.Top, (int)alignment.Frame.Width - frontend.Margin.HorizontalSpacing, (int)alignment.Frame.Height - frontend.Margin.VerticalSpacing); Widget.SetWidgetBounds(frame); } }
protected override void OnRealized() { LogEnter(); try { GdkWindow = Parent?.GdkWindow; if (GdkWindow != null && GdkWindow.Handle != IntPtr.Zero) { var superviewHandle = gdk_quartz_window_get_nsview(GdkWindow.Handle); if (superviewHandle != IntPtr.Zero) { superview = Runtime.GetNSObject <NSView> (superviewHandle); } //we don't want accessibility exploring this view superview.AccessibilityElement = false; } if (superview != null && view != null) { superview.AddSubview(view); superview.SortSubviews(CompareViews); //we don't want include gdk_quartz children in accessibility navigation hierarchy superview.AccessibilityChildren = Array.Empty <NSObject>(); } base.OnRealized(); UpdateViewFrame(); CanFocus = GetAcceptsFirstResponderView() != null; } finally { LogExit(); } }
private void CreateFilmFanCheckboxes(NSView view, CGPoint boxAnchor, List <DateTime> days, bool usePerDayDict = true) { // Initialize the model rectangle. var boxRect = new CGRect(boxAnchor.X, boxAnchor.Y, _controlWidth, _labelHeight); foreach (var fan in ScreeningInfo.FilmFans) { // Populate the checkbox. var box = ControlsFactory.NewCheckbox(boxRect); box.Title = string.Empty; box.Activated += (s, e) => SetAvailability(s, fan, days); box.AllowsMixedState = true; view.AddSubview(box); // Update the indicated controls dictionary. if (usePerDayDict) { UpdateControlByFanByDayDictionary(box, fan, days); } else { _checkboxByFan.Add(fan, box); } // Update the horizontal position. boxRect.X += _controlWidth + _xBetweenControls; } }
public SpinnerHandler() { view = new MacEventView { Handler = this }; view.AddSubview(Control); }
void Create() { if (Control.AccessoryView != null) { return; } var fileTypeView = new NSView(); fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; const int padding = 15; if (Widget.Filters.Count > 0) { var label = new NSTextField(); label.StringValue = "Format"; label.DrawsBackground = false; label.Bordered = false; label.Bezeled = false; label.Editable = false; label.Selectable = false; label.SizeToFit(); fileTypeView.AddSubview(label); fileTypes.SizeToFit(); fileTypes.Activated += (sender, e) => { SetCurrentItem(); Control.ValidateVisibleColumns(); Control.Update(); }; fileTypeView.AddSubview(fileTypes); fileTypes.SetFrameOrigin(new CGPoint((nfloat)label.Frame.Width + 10, padding)); label.SetFrameOrigin(new CGPoint(0, (nfloat)(padding + (fileTypes.Frame.Height - label.Frame.Height) / 2))); fileTypeView.Frame = new CGRect(0, 0, (nfloat)(fileTypes.Frame.Width + label.Frame.Width + 10), (nfloat)(fileTypes.Frame.Height + padding * 2)); Control.AccessoryView = fileTypeView; SetCurrentItem(); } else { Control.AccessoryView = null; } }
public static void DisplayScreeningControls( List <Screening> screenings, NSView screeningsView, GoToScreeningDelegate goToScreening, ref FilmScreeningControl currentScreeningControl) { // Initialize the dictionary to find labels by screening. _labelByfilmScreening = new Dictionary <Screening, NSTextField> { }; // Initialize dimensions. var xLabel = _buttonWidth + _xBetweenLabels; var yScreening = screeningsView.Frame.Height; var contentWidth = screeningsView.Frame.Width; var buttonRect = new CGRect(0, yScreening, _buttonWidth, _labelHeight); var labelRect = new CGRect(xLabel, yScreening, contentWidth - xLabel, _labelHeight); foreach (var screening in screenings) { // Update the vertical position. yScreening -= _labelHeight; // Create the screening info button. buttonRect.Y = yScreening; var infoButton = new FilmScreeningControl(buttonRect, screening); infoButton.ReDraw(); infoButton.ScreeningInfoAsked += (sender, e) => goToScreening(screening); if (screening == _app.Controller.CurrentScreening) { currentScreeningControl = infoButton; currentScreeningControl.Selected = true; } screeningsView.AddSubview(infoButton); // Create the screening label. labelRect.Y = yScreening; var screeningLabel = ControlsFactory.NewStandardLabel(labelRect); screeningLabel.StringValue = screening.ToFilmScreeningLabelString(); ColorView.SetScreeningColor(screening, screeningLabel); screeningsView.AddSubview(screeningLabel); // Link the label to the screening. _labelByfilmScreening.Add(screening, screeningLabel); yScreening -= _yBetweenLabels; } }
public MainWindow(CGRect contentRect, NSWindowStyle aStyle, NSBackingStore bufferingType, bool deferCreation) : base(contentRect, aStyle, bufferingType, deferCreation) { // Define the User Interface of the Window here Title = "Window From Code"; // Create the content view for the window and make it fill the window ContentView = new NSView(Frame); // Add UI Elements to window ClickMeButton = NSButton.CreateButton("Click Me!", ButtonClicked); ClickMeButton.TranslatesAutoresizingMaskIntoConstraints = false; ContentView.AddSubview(ClickMeButton); ClickMeLabel = NSTextField.CreateLabel("Button has not been clicked yet."); ClickMeLabel.TranslatesAutoresizingMaskIntoConstraints = false; ContentView.AddSubview(ClickMeLabel); // Add constraints to window ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "V:|-[button]-[label]", NSLayoutFormatOptions.AlignAllLeading, "button", ClickMeButton, "label", ClickMeLabel)); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "H:|-[button]", NSLayoutFormatOptions.AlignAllFirstBaseline, "button", ClickMeButton)); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "H:|-[label]", NSLayoutFormatOptions.AlignAllFirstBaseline, "label", ClickMeLabel)); var constraints = NSLayoutConstraint.FromVisualFormat( "H:[label]-|", NSLayoutFormatOptions.AlignAllFirstBaseline, "label", ClickMeLabel); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "H:[button]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline, "button", ClickMeButton, "std", constraints[0].Constant)); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "H:[label]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline, "label", ClickMeLabel, "std", constraints[0].Constant)); constraints = NSLayoutConstraint.FromVisualFormat( "V:[label]-|", NSLayoutFormatOptions.AlignAllLeft, "label", ClickMeLabel); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "V:[label]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline, "label", ClickMeLabel, "std", constraints[0].Constant)); }
public static void MoveToPlaceholder(this NSView customControlView, NSView placeholder) { placeholder.AddSubview(customControlView); var placeholderSize = placeholder.Frame.Size; customControlView.Frame = new CoreGraphics.CGRect(0, 0, placeholderSize.Width, placeholderSize.Height); customControlView.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable; }
private void CreateNewContentViewFromAllView(int publicationCategoryIndex) { int frameX = 0; int index = 0; var frame = new CGRect(0, 0, PUBLICATION_COVER_WIDTH, PUBLICATION_VIEW_HEIGHT); NSView conentView = new NSView(frame); var documentView = (NSView)bookScrollView.DocumentView; if (documentView != null) { NSView[] viewList = documentView.Subviews; foreach (PublicationView view in documentView.Subviews) { view.RemoveFromSuperview(); } documentView = null; } foreach (PublicationView view in allPublicationsView) { if (!view.BookInfo.IsLoan && publicationCategoryIndex == PUBLICATION_FILTER_LOAN) { continue; } if (view.BookInfo.IsLoan && publicationCategoryIndex == PUBLICATION_FILTER_SUBSCRIPTION) { continue; } view.Frame = BookFrameByIndex(index); conentView.AddSubview(view); index++; frameX += (PUBLICATION_COVER_WIDTH + PUBLICATION_COVER_HORIZONTAL_SPACING); } if (index > 0) { SetPublicationViewHidden(false); var scrollContentSize = new CGSize(); scrollContentSize.Width = (frameX - PUBLICATION_COVER_HORIZONTAL_SPACING); //PUBLICATION_COVER_WIDTH + PUBLICATION_COVER_HORIZONTAL_SPACING scrollContentSize.Height = bookScrollView.ContentSize.Height; frame.Size = scrollContentSize; conentView.SetFrameOrigin(new CGPoint(0, 0)); conentView.SetFrameSize(scrollContentSize); bookScrollView.DocumentView = conentView; bookScrollView.AutohidesScrollers = true; } else { if (allPublicationsView.Count == 0) { SetPublicationViewHidden(true); } } }
void Create() { if (Control.AccessoryView != null) { return; } var fileTypeView = new NSView(); fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; int padding = 15; if (macfilters != null && macfilters.Count > 0) { var label = new NSTextField(); label.StringValue = "Format"; label.DrawsBackground = false; label.Bordered = false; label.Bezeled = false; label.Editable = false; label.Selectable = false; label.SizeToFit(); fileTypeView.AddSubview(label); fileTypes.SizeToFit(); fileTypes.Activated += (sender, e) => { SetFilters(); Control.ValidateVisibleColumns(); // SetFilters (); Control.Update(); }; fileTypeView.AddSubview(fileTypes); fileTypes.SetFrameOrigin(new System.Drawing.PointF(label.Frame.Width + 10, padding)); label.SetFrameOrigin(new System.Drawing.PointF(0, padding + (fileTypes.Frame.Height - label.Frame.Height) / 2)); fileTypeView.Frame = new System.Drawing.RectangleF(0, 0, fileTypes.Frame.Width + label.Frame.Width + 10, fileTypes.Frame.Height + padding * 2); Control.AccessoryView = fileTypeView; } else { Control.AccessoryView = null; } }
public void TestStaticCreation() { NSArray constraints; NSDictionary views; NSView view = new NSView(new NSRect(0, 0, 512, 512)); NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48)); view.AddSubview(button1); button1.Release(); NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48)); view.AddSubview(button2); button2.Release(); views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"button2", null); constraints = NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views); Check(constraints); view.Release(); }
public void TestPriority() { NSLayoutConstraint constraint; NSArray constraints; NSDictionary views; NSLayoutPriority priority; NSView view = new NSView(new NSRect(0, 0, 512, 512)); NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48)); view.AddSubview(button1); button1.Release(); NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48)); view.AddSubview(button2); button2.Release(); views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"button2", null); constraints = NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views); Check(constraints); constraint = constraints.LastObject.CastTo<NSLayoutConstraint>(); Check(constraint); constraint.Priority = NSLayoutPriority.NSLayoutPriorityRequired; priority = constraint.Priority; Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityRequired, priority, "Priorities should be equal"); constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 1.5); priority = constraint.Priority; Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 1, priority, "Priorities should be equal"); constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 45.23); priority = constraint.Priority; Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 45, priority, "Priorities should be equal"); constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 45.75); priority = constraint.Priority; Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 45, priority, "Priorities should be equal"); view.Release(); }
public MainWindow(CGRect contentRect, NSWindowStyle aStyle, NSBackingStore bufferingType, bool deferCreation): base (contentRect, aStyle,bufferingType,deferCreation) { // Define the User Interface of the Window here Title = "Window From Code"; // Create the content view for the window and make it fill the window ContentView = new NSView (Frame); // Add UI Elements to window ClickMeButton = new NSButton (new CGRect (10, Frame.Height-70, 100, 30)){ AutoresizingMask = NSViewResizingMask.MinYMargin }; ContentView.AddSubview (ClickMeButton); ClickMeLabel = new NSTextField (new CGRect (120, Frame.Height - 65, Frame.Width - 130, 20)) { BackgroundColor = NSColor.Clear, TextColor = NSColor.Black, Editable = false, Bezeled = false, AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.MinYMargin, StringValue = "Button has not been clicked yet." }; ContentView.AddSubview (ClickMeLabel); }
public NSTextField AddTextFieldWithIdentifierSuperView(NSString identifier, NSView superview) { NSTextField textField = new NSTextField (); textField.Identifier = identifier; textField.Cell.ControlSize = NSControlSize.NSSmallControlSize; textField.IsBordered = true; textField.IsBezeled = true; textField.IsSelectable = true; textField.IsEditable = true; textField.Font = NSFont.SystemFontOfSize (11); textField.AutoresizingMask = NSAutoresizingMask.NSViewMaxXMargin | NSAutoresizingMask.NSViewMinYMargin; textField.TranslatesAutoresizingMaskIntoConstraints = false; superview.AddSubview (textField); return textField.Autorelease<NSTextField> (); }
public NSButton AddPushButtonWithTitleIdentifierSuperView(NSString title, NSString identifier, NSView superview) { NSButton pushButton = new NSButton (); pushButton.Identifier = identifier; pushButton.BezelStyle = NSBezelStyle.NSRoundRectBezelStyle; pushButton.Font = NSFont.SystemFontOfSize (12); pushButton.AutoresizingMask = NSAutoresizingMask.NSViewMaxXMargin | NSAutoresizingMask.NSViewMinYMargin; pushButton.TranslatesAutoresizingMaskIntoConstraints = false; superview.AddSubview (pushButton); if (title != null) { pushButton.Title = title; } pushButton.Target = this; pushButton.Action = ObjectiveCRuntime.Selector ("shuffleTitleOfSender:"); return pushButton.Autorelease<NSButton> (); }
protected override void OnRealized() { base.OnRealized(); this.nsview = GtkMacInterop.GetNSView(this); containers[this.nsview] = this; if (child != null) { child.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable; child.Frame = nsview.Bounds; nsview.AddSubview(child); } this.ConnectSubviews(this.nsview); }
public bool Run (ExceptionDialogData data) { using (var alert = new NSAlert { AlertStyle = NSAlertStyle.Critical }) { alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; alert.MessageText = data.Title ?? GettextCatalog.GetString ("Error"); if (!string.IsNullOrEmpty (data.Message)) { alert.InformativeText = data.Message; } List<AlertButton> buttons = null; if (data.Buttons != null && data.Buttons.Length > 0) buttons = data.Buttons.Reverse ().ToList (); if (buttons != null) { foreach (var button in buttons) { var label = button.Label; if (button.IsStockButton) label = Gtk.Stock.Lookup (label).Label; label = label.Replace ("_", ""); //this message seems to be a standard Mac message since alert handles it specially if (button == AlertButton.CloseWithoutSave) label = GettextCatalog.GetString ("Don't Save"); alert.AddButton (label); } } if (data.Exception != null) { var scrollSize = new CGSize (400, 130); const float spacing = 4; string title = GettextCatalog.GetString ("View details"); string altTitle = GettextCatalog.GetString ("Hide details"); var buttonFrame = new CGRect (0, 0, 0, 0); var button = new NSButton (buttonFrame) { BezelStyle = NSBezelStyle.Disclosure, Title = "", AlternateTitle = "", }; button.SetButtonType (NSButtonType.OnOff); button.SizeToFit (); var label = new MDClickableLabel (title) { Alignment = NSTextAlignment.Left, }; label.SizeToFit (); button.SetFrameSize (new CGSize (button.Frame.Width, NMath.Max (button.Frame.Height, label.Frame.Height))); label.SetFrameOrigin (new CGPoint (button.Frame.Width + 5, button.Frame.Y)); var text = new MyTextView (new CGRect (0, 0, float.MaxValue, float.MaxValue)) { HorizontallyResizable = true, }; text.TextContainer.ContainerSize = new CGSize (float.MaxValue, float.MaxValue); text.TextContainer.WidthTracksTextView = true; text.InsertText (new NSString (data.Exception.ToString ())); text.Editable = false; var scrollView = new NSScrollView (new CGRect (CGPoint.Empty, CGSize.Empty)) { HasHorizontalScroller = true, HasVerticalScroller = true, }; var accessory = new NSView (new CGRect (0, 0, scrollSize.Width, button.Frame.Height)); accessory.AddSubview (scrollView); accessory.AddSubview (button); accessory.AddSubview (label); alert.AccessoryView = accessory; button.Activated += delegate { nfloat change; if (button.State == NSCellStateValue.On) { change = scrollSize.Height + spacing; label.StringValue = altTitle; scrollView.Hidden = false; scrollView.Frame = new CGRect (CGPoint.Empty, scrollSize); scrollView.DocumentView = text; } else { change = -(scrollSize.Height + spacing); label.StringValue = title; scrollView.Hidden = true; scrollView.Frame = new CGRect (CGPoint.Empty, CGSize.Empty); } var f = accessory.Frame; f.Height += change; accessory.Frame = f; var lf = label.Frame; lf.Y += change; label.Frame = lf; var bf = button.Frame; bf.Y += change; button.Frame = bf; label.SizeToFit (); var panel = alert.Window; var pf = panel.Frame; pf.Height += change; pf.Y -= change; panel.SetFrame (pf, true, true); //unless we assign the icon again, it starts nesting old icon into the warning icon alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; alert.Layout (); }; label.OnMouseUp += (sender, e) => button.PerformClick (e.Event); } var result = (int)(nint)alert.RunModal () - (int)(long)NSAlertButtonReturn.First; data.ResultButton = buttons != null ? buttons [result] : null; GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } return true; }
public SelectEncodingPanel () : base () { var size = new CGSize (600, 400); const float padding = 12; this.SetContentSize (size); var view = new NSView (new CGRect (0, 0, size.Width, size.Height)); var okButton = new NSButton { Title = GettextCatalog.GetString ("OK"), Bordered = true, BezelStyle = NSBezelStyle.Rounded, }; okButton.SetButtonType (NSButtonType.MomentaryPushIn); okButton.Activated += delegate { Dismiss (1); }; this.DefaultButtonCell = okButton.Cell; var cancelButton = new NSButton { Title = GettextCatalog.GetString ("Cancel"), Bordered = true, BezelStyle = NSBezelStyle.Rounded, }; cancelButton.Activated += delegate { Dismiss (0); }; var buttonBox = new MDBox (LayoutDirection.Horizontal, padding, 0) { new MDAlignment (cancelButton, true) { MinWidth = 96, MinHeight = 32 }, new MDAlignment (okButton, true) { MinWidth = 96, MinHeight = 32 }, }; buttonBox.Layout (); var buttonView = buttonBox.View; var buttonRect = buttonView.Frame; buttonRect.Y = 12; buttonRect.X = size.Width - buttonRect.Width - padding; buttonView.Frame = buttonRect; view.AddSubview (buttonView); var buttonAreaTop = buttonRect.Height + padding * 2; var label = CreateLabel (GettextCatalog.GetString ("Available encodings:")); var labelSize = label.Frame.Size; var labelBottom = size.Height - 12 - labelSize.Height; label.Frame = new CGRect (12, labelBottom, labelSize.Width, labelSize.Height); view.AddSubview (label); var moveButtonWidth = 32; var tableHeight = labelBottom - buttonAreaTop - padding; var tableWidth = size.Width / 2 - padding * 3 - moveButtonWidth + padding / 2; allTable = new NSTableView (new CGRect (padding, buttonAreaTop, tableWidth, tableHeight)); allTable.HeaderView = null; var allScroll = new NSScrollView (allTable.Frame) { BorderType = NSBorderType.BezelBorder, AutohidesScrollers = true, HasVerticalScroller = true, DocumentView = allTable, }; view.AddSubview (allScroll); nfloat center = (size.Width + padding) / 2; var selectedLabel = CreateLabel (GettextCatalog.GetString ("Encodings shown in menu:")); var selectedLabelSize = selectedLabel.Frame.Size; selectedLabel.Frame = new CGRect (center, labelBottom, selectedLabelSize.Width, selectedLabelSize.Height); view.AddSubview (selectedLabel); selectedTable = new NSTableView (new CGRect (center, buttonAreaTop, tableWidth, tableHeight)); selectedTable.HeaderView = null; var selectedScroll = new NSScrollView (selectedTable.Frame) { BorderType = NSBorderType.BezelBorder, AutohidesScrollers = true, HasVerticalScroller = true, DocumentView = selectedTable, }; view.AddSubview (selectedScroll); var buttonLevel = tableHeight / 2 + buttonAreaTop; var goRightImage = NSImage.ImageNamed ("NSGoRightTemplate"); addButton = new NSButton ( new CGRect (tableWidth + padding * 2, buttonLevel + padding / 2, moveButtonWidth, moveButtonWidth)) { //Title = "\u2192", BezelStyle = NSBezelStyle.SmallSquare, Image = goRightImage }; addButton.Activated += Add; view.AddSubview (addButton); removeButton = new NSButton ( new CGRect (tableWidth + padding * 2, buttonLevel - padding / 2 - moveButtonWidth, moveButtonWidth, moveButtonWidth)) { //Title = "\u2190", BezelStyle = NSBezelStyle.SmallSquare, Image = NSImage.ImageNamed ("NSGoLeftTemplate"), }; removeButton.Activated += Remove; view.AddSubview (removeButton); upButton = new NSButton ( new CGRect (center + tableWidth + padding, buttonLevel + padding / 2, moveButtonWidth, moveButtonWidth)) { //Title = "\u2191", BezelStyle = NSBezelStyle.SmallSquare, Image = MakeRotatedCopy (goRightImage, 90), }; upButton.Activated += MoveUp; view.AddSubview (upButton); downButton = new NSButton ( new CGRect (center + tableWidth + padding, buttonLevel - padding / 2 - moveButtonWidth, moveButtonWidth, moveButtonWidth)) { //Title = "\u2193", BezelStyle = NSBezelStyle.SmallSquare, Image = MakeRotatedCopy (goRightImage, -90), }; downButton.Activated += MoveDown; view.AddSubview (downButton); var allColumn = new NSTableColumn { DataCell = new NSTextFieldCell { Wraps = true }, Width = tableWidth }; allTable.AddColumn (allColumn); allTable.DataSource = allSource = new EncodingSource (TextEncoding.SupportedEncodings); allTable.Delegate = new EncodingAllDelegate (this); var selectedColumn = new NSTableColumn { DataCell = new NSTextFieldCell { Wraps = true }, Width = tableWidth }; selectedTable.AddColumn (selectedColumn); selectedTable.DataSource = selectedSource = new EncodingSource (TextEncoding.ConversionEncodings); selectedTable.Delegate = new EncodingSelectedDelegate (this); UpdateButtons (); this.ContentView = view; }
internal static NSView LabelControl (string label, float controlWidth, NSControl control) { var view = new NSView (new CGRect (0, 0, controlWidth, 28)) { AutoresizesSubviews = true, AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.MaxXMargin, }; var text = new NSTextField (new CGRect (0, 6, 100, 20)) { StringValue = label, DrawsBackground = false, Bordered = false, Editable = false, Selectable = false }; text.SizeToFit (); var textWidth = text.Frame.Width; var textHeight = text.Frame.Height; control.SizeToFit (); var rect = control.Frame; var controlHeight = rect.Height; control.Frame = new CGRect (textWidth + 5, 0, controlWidth, rect.Height); rect = view.Frame; rect.Width = control.Frame.Width + textWidth + 5; rect.Height = NMath.Max (controlHeight, textHeight); view.Frame = rect; view.AddSubview (text); view.AddSubview (control); return view; }
static ICredentials GetCredentialsFromUser (Uri uri, IWebProxy proxy, CredentialType credentialType) { NetworkCredential result = null; DispatchService.GuiSyncDispatch (() => { using (var ns = new NSAutoreleasePool ()) { var message = credentialType == CredentialType.ProxyCredentials ? GettextCatalog.GetString ( "{0} needs credentials to access the proxy server {1}.", BrandingService.ApplicationName, uri.Host ) : GettextCatalog.GetString ( "{0} needs credentials to access {1}.", BrandingService.ApplicationName, uri.Host ); var alert = NSAlert.WithMessage ( GettextCatalog.GetString ("Credentials Required"), GettextCatalog.GetString ("OK"), GettextCatalog.GetString ("Cancel"), null, message ); alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; var view = new NSView (new CGRect (0, 0, 313, 91)); var usernameLabel = new NSTextField (new CGRect (17, 55, 71, 17)) { Identifier = "usernameLabel", StringValue = "Username:"******"Password:", Alignment = NSTextAlignment.Right, Editable = false, Bordered = false, DrawsBackground = false, Bezeled = false, Selectable = false, }; view.AddSubview (passwordLabel); var passwordInput = new NSSecureTextField (new CGRect (93, 20, 200, 22)); view.AddSubview (passwordInput); alert.AccessoryView = view; if (alert.RunModal () != 1) return; var username = usernameInput.StringValue; var password = passwordInput.StringValue; result = new NetworkCredential (username, password); } }); // store the obtained credentials in the keychain // but don't store for the root url since it may have other credentials if (result != null) Keychain.AddInternetPassword (uri, result.UserName, result.Password); return result; }
public void TestExceptions() { NSDictionary views; NSView view = new NSView(new NSRect(0, 0, 512, 512)); NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48)); view.AddSubview(button1); button1.Release(); NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48)); view.AddSubview(button2); button2.Release(); Assert.Throws<ObjectiveCMessagingException>(() => { NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, null); }); Assert.Throws<ObjectiveCMessagingException>(() => { views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", null); NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views); }); Assert.Throws<ObjectiveCMessagingException>(() => { views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"dummy", null); NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("V|[button1]-[button2]|", 0, null, views); }); Assert.Throws<ObjectiveCMessagingException>(() => { views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"dummy", null); NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("V:|[button1(>30)]|", 0, null, views); }); view.Release(); }