Ejemplo n.º 1
0
 public HexPopupSpaceReservationAgent(HexSpaceReservationManager spaceReservationManager, WpfHexView wpfHexView, HexLineSpan lineSpan, VSTA.PopupStyles style, UIElement content)
 {
     if (lineSpan.IsDefault)
     {
         throw new ArgumentException();
     }
     if ((style & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent))
     {
         throw new ArgumentOutOfRangeException(nameof(style));
     }
     this.spaceReservationManager = spaceReservationManager ?? throw new ArgumentNullException(nameof(spaceReservationManager));
     this.wpfHexView = wpfHexView;
     this.lineSpan   = lineSpan;
     this.style      = style;
     this.content    = content ?? throw new ArgumentNullException(nameof(content));
     popup           = new Popup {
         PlacementTarget     = wpfHexView.VisualElement,
         Placement           = PlacementMode.Relative,
         Visibility          = Visibility.Collapsed,
         IsOpen              = false,
         AllowsTransparency  = true,
         UseLayoutRounding   = true,
         SnapsToDevicePixels = true,
     };
 }
		internal void Update(HexLineSpan lineSpan, VSTA.PopupStyles style) {
			if (lineSpan.IsDefault)
				throw new ArgumentException();
			if ((style & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent))
				throw new ArgumentOutOfRangeException(nameof(style));
			this.lineSpan = lineSpan;
			this.style = style;
			wpfHexView.QueueSpaceReservationStackRefresh();
		}
Ejemplo n.º 3
0
 internal void Update(HexLineSpan lineSpan, VSTA.PopupStyles style)
 {
     if (lineSpan.IsDefault)
     {
         throw new ArgumentException();
     }
     if ((style & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent))
     {
         throw new ArgumentOutOfRangeException(nameof(style));
     }
     this.lineSpan = lineSpan;
     this.style    = style;
     wpfHexView.QueueSpaceReservationStackRefresh();
 }
Ejemplo n.º 4
0
        Rect GetClosest(Rect spanBounds, Rect?rect, Rect candidate, VSTA.PopupStyles style)
        {
            if (rect == null)
            {
                return(candidate);
            }
            double rectDist, candidateDist;

            if ((style & VSTA.PopupStyles.PositionLeftOrRight) != 0)
            {
                rectDist      = GetHorizontalDistance(spanBounds, rect.Value);
                candidateDist = GetHorizontalDistance(spanBounds, candidate);
            }
            else
            {
                rectDist      = GetVerticalDistance(spanBounds, rect.Value);
                candidateDist = GetVerticalDistance(spanBounds, candidate);
            }
            return(rectDist <= candidateDist ? rect.Value : candidate);
        }
		public HexPopupSpaceReservationAgent(HexSpaceReservationManager spaceReservationManager, WpfHexView wpfHexView, HexLineSpan lineSpan, VSTA.PopupStyles style, UIElement content) {
			if (spaceReservationManager == null)
				throw new ArgumentNullException(nameof(spaceReservationManager));
			if (lineSpan.IsDefault)
				throw new ArgumentException();
			if (content == null)
				throw new ArgumentNullException(nameof(content));
			if ((style & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent))
				throw new ArgumentOutOfRangeException(nameof(style));
			this.spaceReservationManager = spaceReservationManager;
			this.wpfHexView = wpfHexView;
			this.lineSpan = lineSpan;
			this.style = style;
			this.content = content;
			popup = new Popup {
				PlacementTarget = wpfHexView.VisualElement,
				Placement = PlacementMode.Relative,
				Visibility = Visibility.Collapsed,
				IsOpen = false,
				AllowsTransparency = true,
				UseLayoutRounding = true,
				SnapsToDevicePixels = true,
			};
		}
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a popup agent
 /// </summary>
 /// <param name="span">Span and selection flags</param>
 /// <param name="style">Popup style</param>
 /// <param name="content">Popup content</param>
 /// <returns></returns>
 public HexSpaceReservationAgent CreatePopupAgent(HexBufferSpanSelection span, VSTA.PopupStyles style, UIElement content) =>
 CreatePopupAgent(span.BufferSpan, span.SelectionFlags, style, content);
Ejemplo n.º 7
0
        IEnumerable <Rect> GetPositions(Rect screenRect, Geometry reservedSpace, Size desiredSize, Rect spanBounds, VSTA.PopupStyles style)
        {
            var rect1 = GetPosition(screenRect, desiredSize, spanBounds, spanBounds, style);

            if (!OverlapsReservedSpace(reservedSpace, rect1))
            {
                yield return(rect1);
            }

            var unionBounds = Rect.Union(reservedSpace.Bounds, spanBounds);

            if ((style & VSTA.PopupStyles.PositionLeftOrRight) != 0)
            {
                bool preferLeft = (style & VSTA.PopupStyles.PreferLeftOrTopPosition) != 0;
                var  rect2      = preferLeft ?
                                  new Rect(unionBounds.Left - desiredSize.Width, spanBounds.Y, desiredSize.Width, desiredSize.Height) :
                                  new Rect(unionBounds.Right, spanBounds.Y, desiredSize.Width, desiredSize.Height);
                if (!OverlapsReservedSpace(reservedSpace, rect2))
                {
                    yield return(rect2);
                }
            }
            else
            {
                bool preferTop = (style & VSTA.PopupStyles.PreferLeftOrTopPosition) != 0;
                var  rect2     = preferTop ?
                                 new Rect(spanBounds.X, unionBounds.Top - desiredSize.Height, desiredSize.Width, desiredSize.Height) :
                                 new Rect(spanBounds.X, unionBounds.Bottom, desiredSize.Width, desiredSize.Height);
                if (!OverlapsReservedSpace(reservedSpace, rect2))
                {
                    yield return(rect2);
                }
            }

            var rect3 = GetPosition(screenRect, desiredSize, spanBounds, unionBounds, style);

            if (!OverlapsReservedSpace(reservedSpace, rect3))
            {
                yield return(rect3);
            }
        }
Ejemplo n.º 8
0
        Rect GetPosition(Rect screenRect, Size desiredSize, Rect spanBounds, Rect reservedBounds, VSTA.PopupStyles style)
        {
            Debug.Assert(Rect.Union(reservedBounds, spanBounds) == reservedBounds);
            double left, top;

            if ((style & VSTA.PopupStyles.PositionLeftOrRight) != 0)
            {
                bool preferLeft    = (style & VSTA.PopupStyles.PreferLeftOrTopPosition) != 0;
                bool bottomJustify = (style & VSTA.PopupStyles.RightOrBottomJustify) != 0;
                top  = bottomJustify ? spanBounds.Bottom - desiredSize.Height : reservedBounds.Top;
                left = preferLeft ? reservedBounds.Left - desiredSize.Width : reservedBounds.Right;
                if (top < screenRect.Top)
                {
                    top = screenRect.Top;
                }
                else if (top + desiredSize.Height > screenRect.Bottom)
                {
                    top = screenRect.Bottom - desiredSize.Height;
                }
            }
            else
            {
                bool preferTop    = (style & VSTA.PopupStyles.PreferLeftOrTopPosition) != 0;
                bool rightJustify = (style & VSTA.PopupStyles.RightOrBottomJustify) != 0;
                top  = preferTop ? reservedBounds.Top - desiredSize.Height : reservedBounds.Bottom;
                left = rightJustify ? spanBounds.Right - desiredSize.Width : reservedBounds.Left;
                if (left < screenRect.Left)
                {
                    left = screenRect.Left;
                }
                else if (left + desiredSize.Width > screenRect.Right)
                {
                    left = screenRect.Right - desiredSize.Width;
                }
            }
            return(new Rect(left, top, desiredSize.Width, desiredSize.Height));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a popup agent
 /// </summary>
 /// <param name="line">Line</param>
 /// <param name="span">Line span</param>
 /// <param name="style">Popup style</param>
 /// <param name="content">Popup content</param>
 /// <returns></returns>
 public HexSpaceReservationAgent CreatePopupAgent(HexBufferLine line, VST.Span span, VSTA.PopupStyles style, UIElement content) =>
 CreatePopupAgent(new HexLineSpan(line, span), style, content);
Ejemplo n.º 10
0
        IEnumerable <Rect> GetValidPositions(Rect screenRect, Geometry reservedSpace, Size desiredSize, Rect spanBounds, VSTA.PopupStyles style)
        {
            var possiblePositions = new List <Rect>();

            possiblePositions.AddRange(GetPositions(screenRect, reservedSpace, desiredSize, spanBounds, style));
            possiblePositions.AddRange(GetPositions(screenRect, reservedSpace, desiredSize, spanBounds, style ^ VSTA.PopupStyles.PreferLeftOrTopPosition));
            bool isLeftRight = (style & VSTA.PopupStyles.PositionLeftOrRight) != 0;

            foreach (var pos in possiblePositions)
            {
                if (isLeftRight)
                {
                    if (pos.Left >= screenRect.Left && pos.Right <= screenRect.Right)
                    {
                        yield return(pos);
                    }
                }
                else
                {
                    if (pos.Top >= screenRect.Top && pos.Bottom <= screenRect.Bottom)
                    {
                        yield return(pos);
                    }
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates a popup agent
 /// </summary>
 /// <param name="lineSpan">Line span</param>
 /// <param name="style">Popup style</param>
 /// <param name="content">Popup content</param>
 /// <returns></returns>
 public abstract HexSpaceReservationAgent CreatePopupAgent(HexLineSpan lineSpan, VSTA.PopupStyles style, UIElement content);
Ejemplo n.º 12
0
		/// <summary>
		/// Shows a tooltip
		/// </summary>
		/// <param name="bufferSpan">Buffer span</param>
		/// <param name="flags">Selection flags</param>
		/// <param name="toolTipContent">Tooltip content</param>
		/// <param name="style">Popup style</param>
		public abstract void ShowToolTip(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, object toolTipContent, VSTA.PopupStyles style);
Ejemplo n.º 13
0
 public override HexSpaceReservationAgent CreatePopupAgent(HexLineSpan lineSpan, VSTA.PopupStyles style, UIElement content)
 {
     if (wpfHexView.IsClosed)
     {
         throw new InvalidOperationException();
     }
     if (lineSpan.IsDefault)
     {
         throw new ArgumentException();
     }
     if (content is null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     if ((style & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent))
     {
         throw new ArgumentOutOfRangeException(nameof(style));
     }
     return(new HexPopupSpaceReservationAgent(this, wpfHexView, lineSpan, style, content));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Updates a popup agent
 /// </summary>
 /// <param name="agent">Popup agent created by <see cref="CreatePopupAgent(HexLineSpan, VSTA.PopupStyles, UIElement)"/></param>
 /// <param name="span">Span and selection flags</param>
 /// <param name="styles">New popup style</param>
 public void UpdatePopupAgent(HexSpaceReservationAgent agent, HexBufferSpanSelection span, VSTA.PopupStyles styles) =>
 UpdatePopupAgent(agent, span.BufferSpan, span.SelectionFlags, styles);
Ejemplo n.º 15
0
 /// <summary>
 /// Updates a popup agent
 /// </summary>
 /// <param name="agent">Popup agent created by <see cref="CreatePopupAgent(HexLineSpan, VSTA.PopupStyles, UIElement)"/></param>
 /// <param name="lineSpan">New line span</param>
 /// <param name="styles">New popup style</param>
 public abstract void UpdatePopupAgent(HexSpaceReservationAgent agent, HexLineSpan lineSpan, VSTA.PopupStyles styles);
Ejemplo n.º 16
0
 /// <summary>
 /// Updates a popup agent
 /// </summary>
 /// <param name="agent">Popup agent created by <see cref="CreatePopupAgent(HexLineSpan, VSTA.PopupStyles, UIElement)"/></param>
 /// <param name="line">Line</param>
 /// <param name="span">Line span</param>
 /// <param name="styles">New popup style</param>
 public void UpdatePopupAgent(HexSpaceReservationAgent agent, HexBufferLine line, VST.Span span, VSTA.PopupStyles styles) =>
 UpdatePopupAgent(agent, new HexLineSpan(line, span), styles);
Ejemplo n.º 17
0
 /// <summary>
 /// Updates a popup agent
 /// </summary>
 /// <param name="agent">Popup agent created by <see cref="CreatePopupAgent(HexLineSpan, VSTA.PopupStyles, UIElement)"/></param>
 /// <param name="bufferSpan">New buffer span</param>
 /// <param name="flags">New selection flags</param>
 /// <param name="styles">New popup style</param>
 public void UpdatePopupAgent(HexSpaceReservationAgent agent, HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, VSTA.PopupStyles styles) =>
 UpdatePopupAgent(agent, new HexLineSpan(bufferSpan, flags), styles);
Ejemplo n.º 18
0
        public override void ShowToolTip(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, object toolTipContent, VSTA.PopupStyles style)
        {
            if (bufferSpan.IsDefault)
            {
                throw new ArgumentException();
            }
            if (toolTipContent == null)
            {
                throw new ArgumentNullException(nameof(toolTipContent));
            }
            if ((style & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent))
            {
                throw new ArgumentOutOfRangeException(nameof(style));
            }

            ClearToolTip();

            var uiElement = GetUIElement(toolTipContent);

            if (uiElement == null)
            {
                throw new ArgumentException();
            }

            spaceReservationManager.AgentChanged += SpaceReservationManager_AgentChanged;
            toolTipAgent = spaceReservationManager.CreatePopupAgent(bufferSpan, flags, style, uiElement);
            spaceReservationManager.AddAgent(toolTipAgent);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Creates a popup agent
 /// </summary>
 /// <param name="bufferSpan">Buffer span</param>
 /// <param name="flags">Selection flags</param>
 /// <param name="style">Popup style</param>
 /// <param name="content">Popup content</param>
 /// <returns></returns>
 public HexSpaceReservationAgent CreatePopupAgent(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, VSTA.PopupStyles style, UIElement content) =>
 CreatePopupAgent(new HexLineSpan(bufferSpan, flags), style, content);
Ejemplo n.º 20
0
        public override void UpdatePopupAgent(HexSpaceReservationAgent agent, HexLineSpan lineSpan, VSTA.PopupStyles styles)
        {
            if (wpfHexView.IsClosed)
            {
                throw new InvalidOperationException();
            }
            if (agent is null)
            {
                throw new ArgumentNullException(nameof(agent));
            }
            if (lineSpan.IsDefault)
            {
                throw new ArgumentException();
            }
            if ((styles & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent))
            {
                throw new ArgumentOutOfRangeException(nameof(styles));
            }
            if (!spaceReservationAgents.Contains(agent))
            {
                throw new ArgumentOutOfRangeException(nameof(agent));
            }
            var popupAgent = agent as HexPopupSpaceReservationAgent;

            if (popupAgent is null)
            {
                throw new ArgumentException();
            }
            popupAgent.Update(lineSpan, styles);
            UpdateAggregateFocus();
            wpfHexView.QueueSpaceReservationStackRefresh();
        }
Ejemplo n.º 21
0
		/// <summary>
		/// Shows a tooltip
		/// </summary>
		/// <param name="span">Span and selection flags</param>
		/// <param name="toolTipContent">Tooltip content</param>
		/// <param name="style">Popup style</param>
		public void ShowToolTip(HexBufferSpanSelection span, object toolTipContent, VSTA.PopupStyles style) =>
			ShowToolTip(span.BufferSpan, span.SelectionFlags, toolTipContent, style);