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();
		}
Exemplo n.º 2
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);
		}
		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,
			};
		}
Exemplo n.º 4
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);
Exemplo n.º 5
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);
		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 == 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);
		}
		public override void UpdatePopupAgent(HexSpaceReservationAgent agent, HexLineSpan lineSpan, VSTA.PopupStyles styles) {
			if (wpfHexView.IsClosed)
				throw new InvalidOperationException();
			if (agent == 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 == null)
				throw new ArgumentException();
			popupAgent.Update(lineSpan, styles);
			UpdateAggregateFocus();
			wpfHexView.QueueSpaceReservationStackRefresh();
		}
		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);
		}
		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;
		}
		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;
				}
			}
		}
		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;
		}