internal override Rect GetVisibleBoundingRectCore() { PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner); // If there's no source, the element is not visible, return empty rect if (presentationSource == null) { return(Rect.Empty); } HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwnSource, there's not much we can do, return empty rect if (hwndSource == null) { return(Rect.Empty); } Rect rectElement = CalculateVisibleBoundingRect(_owner); Rect rectRoot = PointUtil.ElementToRoot(rectElement, _owner, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); Rect rectScreen = PointUtil.ClientToScreen(rectClient, hwndSource); return(rectScreen); }
private bool ComputeBoundingRectangle(out Rect rect) { rect = Rect.Empty; PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner); // If there's no source, the element is not visible, return empty rect if (presentationSource == null) { return(false); } HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwndSource, there's not much we can do, return empty rect if (hwndSource == null) { return(false); } Rect rectElement = _owner.Visual2DContentBounds; // we use VisualTreeHelper.GetContainingVisual2D to transform from the containing Viewport3DVisual Rect rectRoot = PointUtil.ElementToRoot(rectElement, VisualTreeHelper.GetContainingVisual2D(_owner), presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); rect = PointUtil.ClientToScreen(rectClient, hwndSource); return(true); }
override protected Point GetClickablePointCore() { Point pt = new Point(double.NaN, double.NaN); PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner); // If there's no source, the element is not visible, return (double.NaN, double.NaN) point if (presentationSource == null) { return(pt); } HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwnSource, there's not much we can do, return (double.NaN, double.NaN) point if (hwndSource == null) { return(pt); } Rect rectElement = new Rect(new Point(0, 0), _owner.RenderSize); Rect rectRoot = PointUtil.ElementToRoot(rectElement, _owner, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); Rect rectScreen = PointUtil.ClientToScreen(rectClient, hwndSource); pt = new Point(rectScreen.Left + rectScreen.Width * 0.5, rectScreen.Top + rectScreen.Height * 0.5); return(pt); }
protected override Rect GetBoundingRectangleCore() { TextElement textElement = (TextElement)base.Owner; ITextView textView = textElement.TextContainer.TextView; if (textView == null || !textView.IsValid) { return(Rect.Empty); } Geometry tightBoundingGeometryFromTextPositions = textView.GetTightBoundingGeometryFromTextPositions(textElement.ContentStart, textElement.ContentEnd); if (tightBoundingGeometryFromTextPositions == null) { return(Rect.Empty); } PresentationSource presentationSource = PresentationSource.CriticalFromVisual(textView.RenderScope); if (presentationSource == null) { return(Rect.Empty); } HwndSource hwndSource = presentationSource as HwndSource; if (hwndSource == null) { return(Rect.Empty); } Rect bounds = tightBoundingGeometryFromTextPositions.Bounds; Rect rectRoot = PointUtil.ElementToRoot(bounds, textView.RenderScope, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); return(PointUtil.ClientToScreen(rectClient, hwndSource)); }
override protected Rect GetBoundingRectangleCore() { PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner); // If there's no source, the element is not visible, return empty rect if (presentationSource == null) { return(Rect.Empty); } HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwnSource, there's not much we can do, return empty rect if (hwndSource == null) { return(Rect.Empty); } Rect rectElement = new Rect(new Point(0, 0), _owner.RenderSize); Rect rectRoot = PointUtil.ElementToRoot(rectElement, _owner, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); Rect rectScreen = PointUtil.ClientToScreen(rectClient, hwndSource); return(rectScreen); }
private NativeMethods.RECT CalculateAssignedRC(PresentationSource source) { Rect rectElement = new Rect(base.RenderSize); Rect rectRoot = PointUtil.ElementToRoot(rectElement, this, source); Rect rect = PointUtil.RootToClient(rectRoot, source); IntPtr parent = UnsafeNativeMethods.GetParent(this._hwnd); NativeMethods.RECT rc = PointUtil.FromRect(rect); NativeMethods.RECT rect2 = PointUtil.AdjustForRightToLeft(rc, new HandleRef(null, parent)); if (!CoreAppContextSwitches.DoNotUsePresentationDpiCapabilityTier2OrGreater) { rect2 = this.AdjustRectForDpi(rect2); } return(rect2); }
protected override Rect GetBoundingRectangleCore() { UIElement uielement; Rect rect = this.CalculateBoundingRect(false, out uielement); if (rect != Rect.Empty && uielement != null) { HwndSource hwndSource = PresentationSource.CriticalFromVisual(uielement) as HwndSource; if (hwndSource != null) { rect = PointUtil.ElementToRoot(rect, uielement, hwndSource); rect = PointUtil.RootToClient(rect, hwndSource); rect = PointUtil.ClientToScreen(rect, hwndSource); } } return(rect); }
protected override Point GetClickablePointCore() { Point result = default(Point); UIElement uielement; Rect rect = this.CalculateBoundingRect(true, out uielement); if (rect != Rect.Empty && uielement != null) { HwndSource hwndSource = PresentationSource.CriticalFromVisual(uielement) as HwndSource; if (hwndSource != null) { rect = PointUtil.ElementToRoot(rect, uielement, hwndSource); rect = PointUtil.RootToClient(rect, hwndSource); rect = PointUtil.ClientToScreen(rect, hwndSource); result = new Point(rect.Left + rect.Width * 0.1, rect.Top + rect.Height * 0.1); } } return(result); }
/// <summary> /// <see cref="AutomationPeer.GetClickablePointCore"/> /// </summary> protected override Point GetClickablePointCore() { Point point = new Point(); UIElement uiScope; Rect boundingRect = CalculateBoundingRect(true, out uiScope); if (boundingRect != Rect.Empty && uiScope != null) { HwndSource hwndSource = PresentationSource.CriticalFromVisual(uiScope) as HwndSource; if (hwndSource != null) { boundingRect = PointUtil.ElementToRoot(boundingRect, uiScope, hwndSource); boundingRect = PointUtil.RootToClient(boundingRect, hwndSource); boundingRect = PointUtil.ClientToScreen(boundingRect, hwndSource); point = new Point(boundingRect.Left + boundingRect.Width * 0.1, boundingRect.Top + boundingRect.Height * 0.1); } } return(point); }
protected override Point GetClickablePointCore() { Point pt = new Point(); TextElement textElement = (TextElement)Owner; ITextView textView = textElement.TextContainer.TextView; if (textView == null || !textView.IsValid || (!textView.Contains(textElement.ContentStart) && !textView.Contains(textElement.ContentEnd))) { return(pt); } PresentationSource presentationSource = PresentationSource.CriticalFromVisual(textView.RenderScope); if (presentationSource == null) { return(pt); } HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwnSource, there's not much we can do, return empty rect if (hwndSource == null) { return(pt); } TextPointer endPosition = textElement.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward); if (endPosition == null || endPosition.CompareTo(textElement.ContentEnd) > 0) { endPosition = textElement.ContentEnd; } Rect rectElement = CalculateVisibleRect(textView, textElement, textElement.ContentStart, endPosition); Rect rectRoot = PointUtil.ElementToRoot(rectElement, textView.RenderScope, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); Rect rectScreen = PointUtil.ClientToScreen(rectClient, hwndSource); pt = new Point(rectScreen.Left + rectScreen.Width * 0.5, rectScreen.Top + rectScreen.Height * 0.5); return(pt); }
// Translate the layout information assigned to us from the co-ordinate // space of this element, through the root visual, to the Win32 client // co-ordinate space private NativeMethods.RECT CalculateAssignedRC(PresentationSource source) { Rect rectElement = new Rect(RenderSize); Rect rectRoot = PointUtil.ElementToRoot(rectElement, this, source); Rect rectClient = PointUtil.RootToClient(rectRoot, source); // Adjust for Right-To-Left oriented windows IntPtr hwndParent = UnsafeNativeMethods.GetParent(_hwnd); NativeMethods.RECT rcClient = PointUtil.FromRect(rectClient); NativeMethods.RECT rcClientRTLAdjusted = PointUtil.AdjustForRightToLeft(rcClient, new HandleRef(null, hwndParent)); if (!CoreAppContextSwitches.DoNotUsePresentationDpiCapabilityTier2OrGreater) { //Adjust for differences in DPI between _hwnd and hwndParent rcClientRTLAdjusted = AdjustRectForDpi(rcClientRTLAdjusted); } return(rcClientRTLAdjusted); }
protected override Rect GetBoundingRectangleCore() { TextElement textElement = (TextElement)Owner; ITextView textView = textElement.TextContainer.TextView; if (textView == null || !textView.IsValid) { return(Rect.Empty); } Geometry geometry = textView.GetTightBoundingGeometryFromTextPositions(textElement.ContentStart, textElement.ContentEnd); if (geometry != null) { PresentationSource presentationSource = PresentationSource.CriticalFromVisual(textView.RenderScope); if (presentationSource == null) { return(Rect.Empty); } HwndSource hwndSource = presentationSource as HwndSource; // If the source isn't an HwnSource, there's not much we can do, return empty rect if (hwndSource == null) { return(Rect.Empty); } Rect rectElement = geometry.Bounds; Rect rectRoot = PointUtil.ElementToRoot(rectElement, textView.RenderScope, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); Rect rectScreen = PointUtil.ClientToScreen(rectClient, hwndSource); return(rectScreen); } else { return(Rect.Empty); } }
protected override Point GetClickablePointCore() { Point result = default(Point); TextElement textElement = (TextElement)base.Owner; ITextView textView = textElement.TextContainer.TextView; if (textView == null || !textView.IsValid || (!textView.Contains(textElement.ContentStart) && !textView.Contains(textElement.ContentEnd))) { return(result); } PresentationSource presentationSource = PresentationSource.CriticalFromVisual(textView.RenderScope); if (presentationSource == null) { return(result); } HwndSource hwndSource = presentationSource as HwndSource; if (hwndSource == null) { return(result); } TextPointer textPointer = textElement.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward); if (textPointer == null || textPointer.CompareTo(textElement.ContentEnd) > 0) { textPointer = textElement.ContentEnd; } Rect rectElement = this.CalculateVisibleRect(textView, textElement, textElement.ContentStart, textPointer); Rect rectRoot = PointUtil.ElementToRoot(rectElement, textView.RenderScope, presentationSource); Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource); Rect rect = PointUtil.ClientToScreen(rectClient, hwndSource); result = new Point(rect.Left + rect.Width * 0.5, rect.Top + rect.Height * 0.5); return(result); }