public override void DrawWithFrame (CGRect cellFrame, NSView inView) { if (IdeApp.Preferences.UserInterfaceTheme == Theme.Dark) { var inset = cellFrame.Inset (0.25f, 0.25f); inset = new CGRect (inset.X, inset.Y + 2, inset.Width, inset.Height - 2); var path = NSBezierPath.FromRoundedRect (inset, 3, 3); path.LineWidth = 0.5f; Styles.DarkBorderColor.ToNSColor ().SetStroke (); path.Stroke (); inset = new CGRect (inset.X + 3, inset.Y, inset.Width, inset.Height); DrawInteriorWithFrame (inset, inView); path = new NSBezierPath (); // Draw the separators for (int segment = 1; segment < SegmentCount; segment++) { nfloat x = inset.X + (33 * segment); path.MoveTo (new CGPoint (x, 0)); path.LineTo (new CGPoint (x, inset.Y + inset.Height)); } path.LineWidth = 0.5f; path.Stroke (); } else { base.DrawWithFrame (cellFrame, inView); } }
public override void DrawSegment (nint segment, CGRect frame, NSView controlView) { var img = base.GetImageForSegment (segment); var rect = new CGRect (Math.Round (frame.X + ((frame.Width / 2) - (img.Size.Width / 2))), Math.Round (frame.Y + ((frame.Height / 2) - (img.Size.Height / 2))), img.Size.Width, img.Size.Height); img.Draw (rect); }
protected override void OnRealized () { base.OnRealized (); nsview = GtkMacInterop.GetNSView (this); containers [nsview] = this; ConnectSubviews (nsview); }
public NSMyVideoView(CoreGraphics.CGRect rect, NSView view, AVPlayerLayer layer) : base(rect) { AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; _view = view; _layer = layer; }
AppResult GenerateChildrenForNSView (NSView view, List<AppResult> resultSet) { AppResult firstChild = null, lastChild = null; foreach (var child in view.Subviews) { AppResult node = new NSObjectResult (child) { SourceQuery = ToString () }; resultSet.Add (node); if (firstChild == null) { firstChild = node; lastChild = node; } else { lastChild.NextSibling = node; node.PreviousSibling = lastChild; lastChild = node; } if (child.Subviews != null) { AppResult children = GenerateChildrenForNSView (child, resultSet); node.FirstChild = children; } } return firstChild; }
public static void BringSubviewToFront(this NSView superView, NSView theView) { if(theView == null || !superView.Subviews.Contains(theView)) return; theView.RemoveFromSuperview(); superView.AddSubview(theView); }
public CropMarker(NSView view) { this.target = view; this.setColor(NSColor.BlueColor); this.selectedPath = NSBezierPath.BezierPath; this.selectedPath.Retain(); this.selectedRect = NSRect.NSZeroRect; }
void ConnectSubviews (NSView v) { if (v is GtkEmbed) { ((GtkEmbed)v).Connect (this); } else { foreach (var sv in v.Subviews) ConnectSubviews (v); } }
internal static NSViewContainer GetContainer (NSView v) { while (v != null) { NSViewContainer c; if (containers.TryGetValue (v, out c)) return c; v = v.Superview; } return null; }
public override void DrawWithFrame (CGRect cellFrame, NSView inView) { if (IdeApp.Preferences.UserInterfaceSkin == Skin.Dark) { var inset = cellFrame.Inset (0.25f, 0.25f); if (!ShowsFirstResponder) { var path = NSBezierPath.FromRoundedRect (inset, 3, 3); path.LineWidth = 0.5f; Styles.DarkBorderColor.ToNSColor ().SetStroke (); path.Stroke (); } // Can't just call base.DrawInteriorWithFrame because it draws the placeholder text // with a strange emboss effect when it the view is not first responder. // Again, probably because the NSSearchField handles the not first responder state itself // rather than using NSSearchFieldCell //base.DrawInteriorWithFrame (inset, inView); // So instead, draw the various extra cells and text in the correct places SearchButtonCell.DrawWithFrame (SearchButtonRectForBounds (inset), inView); if (!ShowsFirstResponder) { PlaceholderAttributedString.DrawInRect (SearchTextRectForBounds (inset)); } if (!string.IsNullOrEmpty (StringValue)) { CancelButtonCell.DrawWithFrame (CancelButtonRectForBounds (inset), inView); } } else { if (inView.Window.Screen.BackingScaleFactor == 2) { nfloat yOffset = 0f; nfloat hOffset = 0f; if (MacSystemInformation.OsVersion >= MacSystemInformation.ElCapitan) { if (inView.Window.IsKeyWindow) { yOffset = 0.5f; hOffset = -0.5f; } else { yOffset = 0f; hOffset = 1.0f; } } else { yOffset = 1f; hOffset = -1f; } cellFrame = new CGRect (cellFrame.X, cellFrame.Y + yOffset, cellFrame.Width, cellFrame.Height + hOffset); } else { nfloat yOffset = 0f; nfloat hOffset = 0f; cellFrame = new CGRect (cellFrame.X, cellFrame.Y + yOffset, cellFrame.Width, cellFrame.Height + hOffset); } base.DrawWithFrame (cellFrame, inView); } }
public override void DrawImage(NSImage image, CGRect frame, NSView controlView) { NSGraphicsContext.GlobalSaveGraphicsState (); { this.shadow.Set (); CGRect imgRect = frame.Inset ((frame.Size.Width - image.Size.Width) / 2.0f, (frame.Size.Height - image.Size.Height) / 2.0f); image.Flipped = true; image.DrawInRect (imgRect, CGRect.Empty, NSCompositingOperation.SourceOver, 1.0f); } NSGraphicsContext.GlobalRestoreGraphicsState (); }
void StyleViews(NSView view) { var textField = view as NSTextField; if (textField != null) textField.TextColor = textColor; var subviews = view.Subviews; if (subviews != null) { foreach (var subview in subviews) StyleViews (subview); } }
// // Static Methods // internal static NSViewContainer2 GetContainer(NSView v) { while (v != null) { NSViewContainer2 result; if (containers.TryGetValue(v, out result)) { return result; } v = v.Superview; } return null; }
/// <summary> /// NOTE: One key to having the contained view resize correctly is to have its autoresizing set correctly in IB. /// Based on the new content view frame, calculate the window's new frame /// </summary> public NSRect NewFrameForNewContentView(NSView view) { NSWindow window = this.Window; NSRect newFrameRect = window.FrameRectForContentRect(view.Frame); NSRect oldFrameRect = window.Frame; NSSize newSize = newFrameRect.size; NSSize oldSize = oldFrameRect.size; NSRect frame = window.Frame; frame.size = newSize; frame.origin.y -= (newSize.height - oldSize.height); return frame; }
public override void DrawWithFrame (CGRect cellFrame, NSView inView) { borderColor.SetFill (); NSGraphics.RectFill ( new CGRect ( cellFrame.X + padding / 2, cellFrame.Y + padding / 2, cellFrame.Width - padding, cellFrame.Height - padding ) ); base.DrawWithFrame (cellFrame, inView); }
// // Methods // void ConnectSubviews(NSView v) { if (v is GtkEmbed2) { ((GtkEmbed2)v).Connect(this); } else { NSView[] subviews = v.Subviews; for (int i = 0; i < subviews.Length; i++) { NSView nSView = subviews[i]; this.ConnectSubviews(nSView); } } }
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> (); }
private void DisplaySubview(NSViewController controller, SubviewType type) { // Is this view already displayed? if (ViewType == type) return; // Is there a view already being displayed? if (Subview != null) { // Yes, remove it from the view Subview.RemoveFromSuperview (); // Release memory Subview = null; SubviewController = null; } // Save values ViewType = type; SubviewController = controller; Subview = controller.View; // Define frame and display Subview.Frame = new CGRect (0, 0, ViewContainer.Frame.Width, ViewContainer.Frame.Height); ViewContainer.AddSubview (Subview); // Take action on type switch (type) { case SubviewType.TableBinding: AddButton.Active = true; EditButton.Active = true; DeleteButton.Active = true; Search.Enabled = true; break; case SubviewType.CollectionView: AddButton.Active = true; EditButton.Active = true; DeleteButton.Active = true; Search.Enabled = true; break; default: AddButton.Active = false; EditButton.Active = false; DeleteButton.Active = false; Search.Enabled = false; break; } }
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(); }
// partial void OkClicked (NSObject sender) // { // (WindowController as PreferencesWindowController).OkPressed(); // Close(); // } private void ShowPanel(NSViewController controller) { // Is there a view already being displayed? if (_subview != null) { // Yes, remove it from the view _subview.RemoveFromSuperview (); // Release memory _subview = null; _subviewController = null; } // Save values _subviewController = controller; _subview = controller.View; // Define frame and display _subview.Frame = new CGRect (0, 0, _preferencesView.Frame.Width, _preferencesView.Frame.Height); _preferencesView.AddSubview (_subview); }
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); }
private void DisplaySubview(NSViewController controller, SubviewType type) { // Is this view already displayed? if (ViewType == type) return; // Is there a view already being displayed? if (Subview != null) { // Yes, remove it from the view Subview.RemoveFromSuperview (); // Release memory Subview = null; SubviewController = null; } // Save values ViewType = type; SubviewController = controller; Subview = controller.View; // Define frame and display Subview.Frame = new CGRect (0, 0, ViewContainer.Frame.Width, ViewContainer.Frame.Height); ViewContainer.AddSubview (Subview); }
public override void SetBackgroundColor(NSView view, Color color) { ((CellView)view).BetterBackgroundColor = color.ToNSUI(); }
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; }
public override Color GetBackgroundColor(NSView view) { return(((EtoImageView)view).BackgroundColor.ToEto()); }
public override void DrawInteriorWithFrame(System.Drawing.RectangleF cellFrame, NSView inView) { var nscontext = NSGraphicsContext.CurrentContext; if (DrawsBackground) { var context = nscontext.GraphicsPort; context.SetFillColor(BackgroundColor.ToCGColor()); context.FillRect(cellFrame); } var drawableCellHandler = Handler as DrawableCellHandler; var handler = new GraphicsHandler(null, nscontext, cellFrame.Height, flipped: false); var graphics = new Graphics(drawableCellHandler.Widget.Generator, handler); if (drawableCellHandler.Widget.PaintHandler != null) { var b = graphics.ClipBounds; //graphics.SetClip(clipBounds); drawableCellHandler.Widget.PaintHandler(new DrawableCellPaintArgs { Graphics = graphics, // cachedGraphics, CellBounds = cellFrame.ToEto(), Item = drawableCellHandler.dataItem, CellState = DrawableCellState.Normal, // cellState.ToEto(), }); graphics.SetClip(b); // restore } //base.DrawInteriorWithFrame (cellFrame, inView); }
public static Gtk.Widget NSViewToGtkWidget(NSView view) { return(new Gtk.Widget(NativeMethods.gtk_ns_view_new((IntPtr)view.Handle))); }
public CustomAlignedContainer(NSView child) { Child = child; AddSubview(child); UpdateTextFieldFrame(); }
public static Rectangle WidgetBounds(this NSView v) { return(new Rectangle(v.WidgetX(), v.WidgetY(), v.WidgetWidth(), v.WidgetHeight())); }
public override void SetFont(NSView view, Font font) { ((CellView)view).TextField.Font = font.ToNS(); }
public GtkNSViewHost(NSView view) : this(view, disposeViewOnGtkDestroy : false) { }
public override Font GetFont(NSView view) { return(((CellView)view).TextField.Font.ToEto()); }
public override void SetForegroundColor(NSView view, Color color) { ((CellView)view).TextField.TextColor = color.ToNSUI(); }
public override Color GetForegroundColor(NSView view) { return(((CellView)view).TextField.TextColor.ToEto()); }
public static double WidgetWidth(this NSView v) { return((double)(v.Frame.Width)); }
public MacOSViewHandle(NSView view) { _view = view; }
public static double WidgetHeight(this NSView v) { return((double)(v.Frame.Height)); }
public void Destroy() { _view.Dispose(); _view = null; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Set the view to use the default device device = MTLDevice.SystemDefault; if (device == null) { Console.WriteLine("Metal is not supported on this device"); View = new NSView(View.Frame); } // Create a new command queue commandQueue = device.CreateCommandQueue(); // Load all the shader files with a metal file extension in the project defaultLibrary = device.CreateDefaultLibrary(); // Setup view view = (MTKView)View; view.Delegate = this; view.Device = device; view.SampleCount = 1; view.DepthStencilPixelFormat = MTLPixelFormat.Depth32Float_Stencil8; view.ColorPixelFormat = MTLPixelFormat.BGRA8Unorm; view.PreferredFramesPerSecond = 60; view.ClearColor = new MTLClearColor(0.5f, 0.5f, 0.5f, 1.0f); // Load the vertex program into the library IMTLFunction vertexProgram = defaultLibrary.CreateFunction("triangle_vertex"); // Load the fragment program into the library IMTLFunction fragmentProgram = defaultLibrary.CreateFunction("triangle_fragment"); // Create a vertex descriptor from the MTKMesh MTLVertexDescriptor vertexDescriptor = new MTLVertexDescriptor(); vertexDescriptor.Attributes[0].Format = MTLVertexFormat.Float4; vertexDescriptor.Attributes[0].BufferIndex = 0; vertexDescriptor.Attributes[0].Offset = 0; vertexDescriptor.Attributes[1].Format = MTLVertexFormat.Float4; vertexDescriptor.Attributes[1].BufferIndex = 0; vertexDescriptor.Attributes[1].Offset = 4 * sizeof(float); vertexDescriptor.Layouts[0].Stride = 8 * sizeof(float); vertexDescriptor.Layouts[0].StepRate = 1; vertexDescriptor.Layouts[0].StepFunction = MTLVertexStepFunction.PerVertex; vertexBuffer = device.CreateBuffer(vertexData, MTLResourceOptions.CpuCacheModeDefault);// (MTLResourceOptions)0); // Create a reusable pipeline state var pipelineStateDescriptor = new MTLRenderPipelineDescriptor { SampleCount = view.SampleCount, VertexFunction = vertexProgram, FragmentFunction = fragmentProgram, VertexDescriptor = vertexDescriptor, DepthAttachmentPixelFormat = view.DepthStencilPixelFormat, StencilAttachmentPixelFormat = view.DepthStencilPixelFormat }; pipelineStateDescriptor.ColorAttachments[0].PixelFormat = view.ColorPixelFormat; NSError error; pipelineState = device.CreateRenderPipelineState(pipelineStateDescriptor, out error); if (pipelineState == null) { Console.WriteLine("Failed to created pipeline state, error {0}", error); } var depthStateDesc = new MTLDepthStencilDescriptor { DepthCompareFunction = MTLCompareFunction.Less, DepthWriteEnabled = true }; depthState = device.CreateDepthStencilState(depthStateDesc); this.rectangle = new MTLScissorRect(125, 166, 250, 444); }
/// <summary> /// Creates the Sciter window and returns the native handle /// </summary> /// <param name="frame">Rectangle of the window</param> /// <param name="creationFlags">Flags for the window creation, defaults to SW_MAIN | SW_TITLEBAR | SW_RESIZEABLE | SW_CONTROLS | SW_ENABLE_DEBUG</param> public void CreateWindow(PInvokeUtils.RECT frame = new PInvokeUtils.RECT(), SciterXDef.SCITER_CREATE_WINDOW_FLAGS creationFlags = DefaultCreateFlags, IntPtr parent = new IntPtr()) { Debug.Assert(_hwnd == IntPtr.Zero); _hwnd = _api.SciterCreateWindow( creationFlags, ref frame, _proc, IntPtr.Zero, parent ); Debug.Assert(_hwnd != IntPtr.Zero); if(_hwnd == IntPtr.Zero) throw new Exception("CreateWindow() failed"); #if GTKMONO _gtkwindow = PInvokeGTK.gtk_widget_get_toplevel(_hwnd); Debug.Assert(_gtkwindow != IntPtr.Zero); #elif OSX _nsview = new OSXView(_hwnd); #endif }
public override CGRect DrawTitle(NSAttributedString title, CGRect frame, NSView controlView) { if (controlView is FormsNSButton button) { var paddedFrame = new CGRect(frame.X + button._leftPadding, frame.Y + button._topPadding, frame.Width - button._leftPadding - button._rightPadding, frame.Height - button._topPadding - button._bottomPadding); return(base.DrawTitle(title, paddedFrame, controlView)); } return(base.DrawTitle(title, frame, controlView)); }
CGRect GetRelativeAllocation (NSView ancestor, NSView child) { if (child == null) return CGRect.Empty; if (child.Superview == ancestor) return child.Frame; var f = GetRelativeAllocation (ancestor, child.Superview); var cframe = child.Frame; return new CGRect (cframe.X + f.X, cframe.Y + f.Y, cframe.Width, cframe.Height); }
// // Constructors // public NSViewContainer2(NSView child = null) { WidgetFlags |= WidgetFlags.NoWindow; this.child = child; }
public override void LoadView() { var view = new NSView(); var lblTitle = new NSTextField { Editable = false, Hidden = string.IsNullOrEmpty(this.Title), Alignment = NSTextAlignment.Center, StringValue = this.Title ?? string.Empty }; var datePicker = new NSDatePicker { DatePickerStyle = NSDatePickerStyle.ClockAndCalendar, DatePickerElements = this.ElementFlags, DateValue = this.SelectedDateTime.ToNSDate(), TimeInterval = this.MinuteInterval }; if (this.Use24HourClock) { datePicker.Locale = NSLocale.FromLocaleIdentifier("NL"); } if (this.MaximumDateTime != null) { datePicker.MinDate = this.MaximumDateTime.Value.ToNSDate(); } if (this.MaximumDateTime != null) { datePicker.MaxDate = this.MaximumDateTime.Value.ToNSDate(); } var okButton = new NSButton { Title = this.OkText }; okButton.Activated += (sender, e) => { this.SelectedDateTime = datePicker.DateValue.ToDateTime(); this.Presentor.DismissViewController(this); this.Ok?.Invoke(this); }; var cancelButton = new NSButton { Title = this.CancelText }; cancelButton.Activated += (sender, e) => { this.Presentor.DismissViewController(this); this.Cancel?.Invoke(this); }; view.AggregateSubviews(lblTitle, datePicker, okButton, cancelButton); // Constraints Extensions.ActivateConstraints( lblTitle.TopAnchor.ConstraintEqualToAnchor(view.TopAnchor), lblTitle.LeadingAnchor.ConstraintEqualToAnchor(view.LeadingAnchor), lblTitle.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor), datePicker.TopAnchor.ConstraintEqualToAnchor(lblTitle.BottomAnchor, 2), datePicker.LeadingAnchor.ConstraintEqualToAnchor(view.LeadingAnchor), datePicker.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor), okButton.TopAnchor.ConstraintEqualToAnchor(datePicker.BottomAnchor, 2), okButton.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor), okButton.BottomAnchor.ConstraintEqualToAnchor(view.BottomAnchor), cancelButton.TrailingAnchor.ConstraintEqualToAnchor(okButton.LeadingAnchor, 2), cancelButton.LeadingAnchor.ConstraintGreaterThanOrEqualToAnchor(view.LeadingAnchor), cancelButton.BottomAnchor.ConstraintEqualToAnchor(okButton.BottomAnchor) ); this.View = view; }
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) => ((IMenuItemController)element).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) => ((IMenuItemController)element).Activate(); button.BezelStyle = NSBezelStyle.TexturedRounded; _ = element.ApplyNativeImageAsync(ToolbarItem.IconImageSourceProperty, image => { if (image != null) { button.Image = image; } button.SizeToFit(); }); button.Enabled = item.Enabled = element.IsEnabled; element.PropertyChanged -= ToolBarItemPropertyChanged; element.PropertyChanged += ToolBarItemPropertyChanged; view.AddSubview(button); //item.Label = item.PaletteLabel = item.ToolTip = element.Text ?? ""; subItems[i] = item; SetAccessibility(button, element); group.Items.Add(new NativeToolbarGroup.Item { ToolbarItem = item, Button = button, Element = element }); } 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(); } }
public PageRenderer() { View = new NSView { WantsLayer = true }; }
public override void SetBackgroundColor(NSView view, Color color) { var field = ((EtoImageView)view); field.BackgroundColor = color.ToNSUI(); }
void Popup(NSView view, CGPoint point) { this.PopUpMenu(null, point, view); }
public static NSEvent RetargetMouseEvent(this NSEvent e, NSView target) { var p = target.Window.ConvertScreenToBase(e.Window.ConvertBaseToScreen(e.LocationInWindow)); return(NSEvent.MouseEvent(e.Type, p, e.ModifierFlags, e.Timestamp, target.Window.WindowNumber, null, 0, e.ClickCount, e.Pressure)); }
public override Color GetBackgroundColor(NSView view) { return(((CellView)view).BetterBackgroundColor.ToEto()); }
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; }
static ICredentials GetCredentialsFromUser(Uri uri, IWebProxy proxy, CredentialType credentialType) { NetworkCredential result = null; Runtime.RunInMainThread(() => { 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 = new NSAlert { MessageText = GettextCatalog.GetString("Credentials Required"), InformativeText = message }; var okButton = alert.AddButton(GettextCatalog.GetString("OK")); var cancelButton = alert.AddButton(GettextCatalog.GetString("Cancel")); 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; alert.Window.WeakDelegate = new PasswordAlertWindowDelegate(usernameInput, passwordInput, cancelButton, okButton); alert.Window.InitialFirstResponder = usernameInput; if (alert.RunModal() != NSAlertFirstButtonReturn) { return; } var username = usernameInput.StringValue; var password = passwordInput.StringValue; result = new NetworkCredential(username, password); } }).Wait(); // 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 SetSubView (NSView view) { this.ContainerView.AddSubview (view); }
public void SetContent(NSView view) { ContentView = view; UpdateContentSize(false); }
bool IsCorrectNotification (NSView view, NSObject notifObject) { var window = selector.Window; // Skip updates with a null Window. Only crashes on Mavericks. // The View gets updated once again when the window resize finishes. // We're getting notified about all windows in the application (for example, NSPopovers) that change size when really we only care about // the window the bar is in. return window != null && notifObject == window; }
public static Point WidgetLocation(this NSView v) { return(new Point(v.WidgetX(), v.WidgetY())); }
/// <summary> /// Given a view, retrieve its window state. /// </summary> /// <param name="view">The view whose owning window's state is desired.</param> /// <returns>The owning window's state.</returns> public static OSWindowState WindowState(this NSView view) { return(view.Window.WindowState()); }
public static double WidgetY(this NSView v) { return((double)v.Frame.Y); }