public static void ShowContextMenu(NSView parent, int x, int y, NSMenu menu, bool selectFirstItem = false) { if (parent == null) { throw new ArgumentNullException("parent"); } if (menu == null) { throw new ArgumentNullException("menu"); } var pt = parent.ConvertPointToView(new CoreGraphics.CGPoint(x, y), null); if (selectFirstItem) { menu.PopUpMenu(menu.ItemAt(0), pt, parent); } else { var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown, pt, 0, 0, parent.Window.WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu(menu, tmp_event, parent); } }
public static CGPoint PointToScreen(this NSView view, CGPoint point) { var p = view.ConvertPointToView(point, null); if (view.Window == null) { return(p); } p = view.Window.ConvertPointToScreen(p); return(p); }
public static Point PointToScreen(this NSView view, Point point) { var p = view.ConvertPointToView(new CGPoint(point.X, point.Y), null); if (view.Window == null) { return(new Point(p.X, p.Y)); } p = view.Window.ConvertPointToScreen(p); return(new Point(p.X, p.Y)); }
static Task <Rectangle <Points> > RelativeFrame(NSView from, NSView to) { return(Fusion.Application.MainThread.InvokeAsync( () => { var translation = from.ConvertPointToView(new CGPoint(from.Bounds.Left, from.Bounds.Height), to).ToFusion(); return Rectangle.FromPositionSize( left: translation.X, top: new Points(to.Frame.Height) - translation.Y, width: new Points(from.Frame.Width), height: new Points(from.Frame.Height)); })); }
void SetViewClip() { Control.ClipToRect(view.ConvertRectToView(view.VisibleRect(), null)); var pos = view.ConvertPointToView(SD.PointF.Empty, null); if (!Flipped) { currentTransform = new CGAffineTransform(1, 0, 0, -1, pos.X, pos.Y + view.Frame.Height); } else { currentTransform = new CGAffineTransform(1, 0, 0, -1, pos.X, pos.Y); } Control.ConcatCTM(currentTransform); }
public static void ShowContextMenu(NSView parent, int x, int y, NSMenu menu, bool selectFirstItem = false) { if (parent == null) { throw new ArgumentNullException("parent"); } if (menu == null) { throw new ArgumentNullException("menu"); } var pt = parent.ConvertPointToView(new CoreGraphics.CGPoint(x, y), null); if (selectFirstItem) { menu.PopUpMenu(menu.ItemAt(0), pt, parent); } else { var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown, pt, 0, 0, parent.Window.WindowNumber, null, 0, 0, 0); // the following lines are here to dianose & fix VSTS 1026106 - we were getting // a SigSegv from here and it is likely caused by NSEvent being null, however // it's worth leaving Debug checks in just to be on the safe side if (tmp_event == null) { // since this is often called outside of a try/catch loop, we'll just // log an error and not throw the exception LoggingService.LogInternalError(new ArgumentNullException(nameof(tmp_event))); return; } System.Diagnostics.Debug.Assert(parent != null, "Parent was modified (set to null) during execution."); System.Diagnostics.Debug.Assert(menu != null, "Menu was modified (set to null) during execution."); NSMenu.PopUpContextMenu(menu, tmp_event, parent); } }
public SD.PointF TranslateView(SD.PointF point, bool halfers = false) { if (halfers) { point.X += 0.5F; point.Y += 0.5F; } if (view != null) { if (!Flipped) { point.Y = view.Bounds.Height - point.Y; } point = view.ConvertPointToView(point, null); } else if (!Flipped) { point.Y = this.height - point.Y; } return(point); }
void InitializeContext(bool viewFlipped) { Control.SaveState(); #if OSX // os x has different flipped states (depending on layers, etc), so compensate to make 0,0 at the top-left if (view != null) { // we have a view (drawing directly to the screen), so adjust to where it is Control.ClipToRect(view.ConvertRectToView(view.VisibleRect(), null)); var pos = view.ConvertPointToView(CGPoint.Empty, null); if (!viewFlipped) { pos.Y += view.Frame.Height; } currentTransform = new CGAffineTransform(1, 0, 0, -1, (float)pos.X, (float)pos.Y); Control.ConcatCTM(currentTransform); } else { // drawing to a bitmap or during a drawRect operation currentTransform = new CGAffineTransform(1, 0, 0, -1, 0, viewFlipped ? ViewHeight : 0); if (viewFlipped) { Control.ConcatCTM(currentTransform); } } phase = null; #elif IOS if (viewFlipped) { // on ios, we flip the context if we're drawing on a bitmap otherwise we don't need to currentTransform = new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight); Control.ConcatCTM(currentTransform); } #endif }
internal void UpdateInsets() { if (this.lastKeyboardRect.IsEmpty || this.fetchWindow() == null) { return; } NSView firstResponder = UIViewExtensions.FindFirstResponder(this.targetView); CGRect frame = this.targetView.Frame; CGSize size = frame.Size; // ISSUE: reference to a compiler-generated method CGRect cgRect = CGRect.Intersect(this.targetView.Superview.ConvertRectFromView(this.lastKeyboardRect, (NSView)null), this.targetView.Frame); this.setInsetAction(new UIEdgeInsets((nfloat)0, (nfloat)0, cgRect.Height, (nfloat)0)); if (!(firstResponder is UITextView) || this.setContentOffset == null) { return; } nfloat nfloat = size.Height - cgRect.Height; NSView uiView = firstResponder; frame = uiView.Frame; CGPoint location = frame.Location; NSView superview = this.targetView.Superview; // ISSUE: reference to a compiler-generated method nfloat y1 = uiView.ConvertPointToView(location, superview).Y; frame = firstResponder.Frame; nfloat height = frame.Height; nfloat y2 = y1 + height - nfloat; if (!(y2 > (nfloat)0)) { return; } this.setContentOffset(new CGPoint((nfloat)0, y2)); }