public void Popup(IWidgetBackend widget, double x, double y) { var refView = (widget as EmbedNativeWidgetBackend)?.EmbeddedView; if (refView == null) { refView = (widget as ViewBackend)?.Widget; } if (refView == null) { try { refView = GtkQuartz.GetView(widget.NativeWidget); // GtkNSView is not necessarily exclusive, translate coords to the ContentView of the window refView = refView.Window.ContentView; var location = widget.ConvertToWindowCoordinates(new Point(x, y)).ToCGPoint(); location = refView.ConvertPointToView(location, null); if (refView.IsFlipped) { location.Y = refView.Frame.Height - location.Y; } Popup(refView, location); } catch (Exception ex) { throw new ArgumentException("Widget belongs to an unsupported Toolkit", nameof(widget), ex); } } else { Popup(refView, new CGPoint(x, y)); } }
public void Show(Popover.Position orientation, Widget referenceWidget, Rectangle positionRect, Widget child) { var refBackend = Toolkit.GetBackend(referenceWidget) as IWidgetBackend; NSView refView = (refBackend as EmbedNativeWidgetBackend)?.EmbeddedView; if (refView == null) { refView = (refBackend as ViewBackend)?.Widget; } if (refView == null) { if (referenceWidget.Surface.ToolkitEngine.Type == ToolkitType.Gtk) { try { refView = GtkQuartz.GetView(refBackend.NativeWidget); var rLocation = refView.ConvertRectToView(refView.Frame, null).Location.ToXwtPoint(); if (referenceWidget.WindowBounds.Location != rLocation) { positionRect.X += referenceWidget.WindowBounds.Location.X - rLocation.X; positionRect.Y += referenceWidget.WindowBounds.Location.Y - rLocation.Y; } } catch (Exception ex) { throw new ArgumentException("Widget belongs to an unsupported Toolkit", nameof(referenceWidget), ex); } } else if (referenceWidget.Surface.ToolkitEngine != ApplicationContext.Toolkit) { throw new ArgumentException("Widget belongs to an unsupported Toolkit", nameof(referenceWidget)); } } // If the rect is empty, the coordinates of the rect will be ignored. // Set the width and height, for the positioning to function correctly. if (Math.Abs(positionRect.Width) < double.Epsilon) { positionRect.Width = referenceWidget.Size.Width; } if (Math.Abs(positionRect.Height) < double.Epsilon) { positionRect.Height = referenceWidget.Size.Height; } DestroyPopover(); popover = new NSAppearanceCustomizationPopover { Behavior = NSPopoverBehavior.Transient }; controller = new FactoryViewController(this, child, popover) { BackgroundColor = backgroundColor }; popover.ContentViewController = controller; popover.Delegate = controller; // if the reference has a custom appearance, use it for the popover if (refView.EffectiveAppearance.Name != NSAppearance.NameAqua) { controller.EffectiveAppearanceName = refView.EffectiveAppearance.Name; if (popover is INSAppearanceCustomization) { ((INSAppearanceCustomization)popover).SetAppearance(refView.EffectiveAppearance); } } popover.Show(positionRect.ToCGRect(), refView, ToRectEdge(orientation)); }