예제 #1
0
        public override Geometry PositionAndDisplay(Geometry reservedSpace)
        {
            var spanBoundsTmp = GetVisualSpanBounds();

            if (spanBoundsTmp == null || spanBoundsTmp.Value.IsEmpty)
            {
                return(null);
            }
            var spanBounds  = WpfHexViewRectToScreenRect(spanBoundsTmp.Value);
            var desiredSize = ToScreenSize(PopupSize);

            var screen     = new Screen(wpfHexView.VisualElement);
            var screenRect = screen.IsValid ? screen.DisplayRect : SystemParameters.WorkArea;

            Rect?popupRect = null;

            if ((style & VSTA.PopupStyles.PositionClosest) != 0)
            {
                foreach (var pos in GetValidPositions(screenRect, reservedSpace, desiredSize, spanBounds, style))
                {
                    popupRect = GetClosest(spanBounds, popupRect, pos, style);
                }
            }
            else
            {
                foreach (var pos in GetValidPositions(screenRect, reservedSpace, desiredSize, spanBounds, style))
                {
                    popupRect = pos;
                    break;
                }
            }

            if (popupRect == null)
            {
                return(null);
            }
            var viewRelativeRect = HexPopupHelper.TransformFromDevice(wpfHexView, popupRect.Value);

            bool isOpen = popup.IsOpen;

            if (!isOpen)
            {
                AddEvents();
            }

            if (popupZoomLevel != wpfHexView.ZoomLevel)
            {
                // Must set IsOpen to false when setting a new scale transform
                popup.IsOpen = false;
                HexPopupHelper.SetScaleTransform(wpfHexView, popup);
                popupZoomLevel = wpfHexView.ZoomLevel;
            }
            if (!isOpen)
            {
                popup.Child      = content;
                popup.Visibility = Visibility.Visible;
            }
            popup.VerticalOffset   = viewRelativeRect.Top;
            popup.HorizontalOffset = viewRelativeRect.Left;
            popup.IsOpen           = true;

            return(new RectangleGeometry(popupRect.Value));
        }
예제 #2
0
 Size ToScreenSize(Size size) => HexPopupHelper.TransformToDevice(wpfHexView, size);