private static void GetClippedPositionOffsets(TextEditor This, ITextPointer position, LogicalDirection direction, out double horizontalOffset, out double verticalOffset) { Rect characterRect = position.GetCharacterRect(direction); horizontalOffset = characterRect.X; verticalOffset = characterRect.Y + characterRect.Height; FrameworkElement frameworkElement = This.TextView.RenderScope as FrameworkElement; if (frameworkElement != null) { GeneralTransform generalTransform = frameworkElement.TransformToAncestor(This.UiScope); if (generalTransform != null) { TextEditorContextMenu.ClipToElement(frameworkElement, generalTransform, ref horizontalOffset, ref verticalOffset); } } for (Visual visual = This.UiScope; visual != null; visual = (VisualTreeHelper.GetParent(visual) as Visual)) { frameworkElement = (visual as FrameworkElement); if (frameworkElement != null) { GeneralTransform generalTransform2 = visual.TransformToDescendant(This.UiScope); if (generalTransform2 != null) { TextEditorContextMenu.ClipToElement(frameworkElement, generalTransform2, ref horizontalOffset, ref verticalOffset); } } } PresentationSource presentationSource = PresentationSource.CriticalFromVisual(This.UiScope); IWin32Window win32Window = presentationSource as IWin32Window; if (win32Window != null) { IntPtr handle = IntPtr.Zero; new UIPermission(UIPermissionWindow.AllWindows).Assert(); try { handle = win32Window.Handle; } finally { CodeAccessPermission.RevertAssert(); } NativeMethods.RECT rect = new NativeMethods.RECT(0, 0, 0, 0); SafeNativeMethods.GetClientRect(new HandleRef(null, handle), ref rect); Point point = new Point((double)rect.left, (double)rect.top); Point point2 = new Point((double)rect.right, (double)rect.bottom); CompositionTarget compositionTarget = presentationSource.CompositionTarget; point = compositionTarget.TransformFromDevice.Transform(point); point2 = compositionTarget.TransformFromDevice.Transform(point2); GeneralTransform generalTransform3 = compositionTarget.RootVisual.TransformToDescendant(This.UiScope); if (generalTransform3 != null) { generalTransform3.TryTransform(point, out point); generalTransform3.TryTransform(point2, out point2); horizontalOffset = TextEditorContextMenu.ClipToBounds(point.X, horizontalOffset, point2.X); verticalOffset = TextEditorContextMenu.ClipToBounds(point.Y, verticalOffset, point2.Y); } } }
/// <summary> /// Computes the bounds for a given text segment, provided that the entire segment /// is located on a single text line. /// </summary> private static Rect GetLineBounds(ITextPointer start, ITextPointer end) { // Get the line range. if (!start.HasValidLayout || !end.HasValidLayout) { return Rect.Empty; } // Get the left and the width of the range bounds. Rect lineBounds = start.GetCharacterRect(LogicalDirection.Forward); lineBounds.Union(end.GetCharacterRect(LogicalDirection.Backward)); // Scan the line range and compute the top and the height of the bounding rectangle. ITextPointer navigator = start.CreatePointer(LogicalDirection.Forward); while (navigator.MoveToNextContextPosition(LogicalDirection.Forward) == true && navigator.CompareTo(end) < 0) { TextPointerContext context = navigator.GetPointerContext(LogicalDirection.Backward); switch (context) { case TextPointerContext.ElementStart: lineBounds.Union(navigator.GetCharacterRect(LogicalDirection.Backward)); navigator.MoveToElementEdge(ElementEdge.AfterEnd); break; case TextPointerContext.ElementEnd: case TextPointerContext.EmbeddedElement: lineBounds.Union(navigator.GetCharacterRect(LogicalDirection.Backward)); break; case TextPointerContext.Text: break; default: // Unexpected Invariant.Assert(context != TextPointerContext.None); break; } } return lineBounds; }
private static void GetClippedPositionOffsets(TextEditor This, ITextPointer position, LogicalDirection direction, out double horizontalOffset, out double verticalOffset) { // GetCharacterRect will return the position that base on UiScope. Rect positionRect = position.GetCharacterRect(direction); // Get the base offsets for our ContextMenu. horizontalOffset = positionRect.X; verticalOffset = positionRect.Y + positionRect.Height; // Clip to the child render scope. FrameworkElement element = This.TextView.RenderScope as FrameworkElement; if (element != null) { GeneralTransform transform = element.TransformToAncestor(This.UiScope); if (transform != null) { ClipToElement(element, transform, ref horizontalOffset, ref verticalOffset); } } // Clip to parent visuals. // This is unintuitive -- you might expect parents to have increasingly // larger viewports. But any parent that behaves like a ScrollViewer // will have a smaller view port that we need to clip against. for (Visual visual = This.UiScope; visual != null; visual = VisualTreeHelper.GetParent(visual) as Visual) { element = visual as FrameworkElement; if (element != null) { GeneralTransform transform = visual.TransformToDescendant(This.UiScope); if (transform != null) { ClipToElement(element, transform, ref horizontalOffset, ref verticalOffset); } } } // Clip to the window client rect. PresentationSource source = PresentationSource.CriticalFromVisual(This.UiScope); IWin32Window window = source as IWin32Window; if (window != null) { IntPtr hwnd = IntPtr.Zero; new UIPermission(UIPermissionWindow.AllWindows).Assert(); // BlessedAssert try { hwnd = window.Handle; } finally { CodeAccessPermission.RevertAssert(); } NativeMethods.RECT rc = new NativeMethods.RECT(0, 0, 0, 0); SafeNativeMethods.GetClientRect(new HandleRef(null, hwnd), ref rc); // Convert to mil measure units. Point minPoint = new Point(rc.left, rc.top); Point maxPoint = new Point(rc.right, rc.bottom); CompositionTarget compositionTarget = source.CompositionTarget; minPoint = compositionTarget.TransformFromDevice.Transform(minPoint); maxPoint = compositionTarget.TransformFromDevice.Transform(maxPoint); // Convert to local coordinates. GeneralTransform transform = compositionTarget.RootVisual.TransformToDescendant(This.UiScope); if (transform != null) { transform.TryTransform(minPoint, out minPoint); transform.TryTransform(maxPoint, out maxPoint); // Finally, do the clip. horizontalOffset = ClipToBounds(minPoint.X, horizontalOffset, maxPoint.X); verticalOffset = ClipToBounds(minPoint.Y, verticalOffset, maxPoint.Y); } // ContextMenu code takes care of clipping to desktop. } }
// MouseMoveEvent handler. private static void OnMouseMoveWithFocus(TextEditor This, MouseEventArgs e) { // Ignore the event if it was caused by us capturing the mouse if (This._mouseCapturingInProgress) { return; } // Clear a flag indicating that Shift key was pressed without any following key // This flag is necessary for KeyUp(RightShift/LeftShift) processing. TextEditor._ThreadLocalStore.PureControlShift = false; // Get the mouse move point. Point mouseMovePoint = e.GetPosition(This.TextView.RenderScope); // Update mouse cursor shape TextEditorMouse.UpdateCursor(This, mouseMovePoint); // For Invariant.Assert(This.Selection != null); // We're only interested in moves when the left button is down. if (e.LeftButton != MouseButtonState.Pressed) { return; } // We didn't get the original mouse down event, perhaps a listener // handled it. if (!This.UiScope.IsMouseCaptured) { return; } // Scale back any background layout in progress. This.TextView.ThrottleBackgroundTasksForUserInput(); if (This._tableColResizeInfo != null) { This._tableColResizeInfo.UpdateAdorner(mouseMovePoint); } else { // Consider event handled e.Handled = true; // For Invariant.Assert(This.Selection != null); // Find a text position for this mouse point ITextPointer snappedCursorPosition = This.TextView.GetTextPositionFromPoint(mouseMovePoint, /*snapToText:*/ true); // For Invariant.Assert(This.Selection != null); if (snappedCursorPosition == null) { This.RequestExtendSelection(mouseMovePoint); } else { This.CancelExtendSelection(); // For Invariant.Assert(This.Selection != null); if (!This._dragDropProcess.SourceOnMouseMove(mouseMovePoint)) { // Auto-scrolling behavior during selection guesture - // works when the mouse is outside of scroller's viewport. // In such case we artificially increase coordinates to // get to farther text position - which would speed-up scrolling // in particular direction. FrameworkElement scroller = This._Scroller; if (scroller != null && This.UiScope is TextBoxBase) { ITextPointer acceleratedCursorPosition = null; // cursorPosition corrected to accelerate scrolling Point targetPoint = new Point(mouseMovePoint.X, mouseMovePoint.Y); Point pointScroller = e.GetPosition((IInputElement)scroller); double pageHeight = (double)((TextBoxBase)This.UiScope).ViewportHeight; double slowAreaDelta = ScrollViewer._scrollLineDelta; // Auto scrolling up/down page for the page height if the mouse Y // position is out of viewport. if (pointScroller.Y < 0 - slowAreaDelta) { Rect targetRect = This.TextView.GetRectangleFromTextPosition(snappedCursorPosition); targetPoint = new Point(targetPoint.X, targetRect.Bottom - pageHeight); acceleratedCursorPosition = This.TextView.GetTextPositionFromPoint(targetPoint, /*snapToText:*/ true); } else if (pointScroller.Y > pageHeight + slowAreaDelta) { Rect targetRect = This.TextView.GetRectangleFromTextPosition(snappedCursorPosition); targetPoint = new Point(targetPoint.X, targetRect.Top + pageHeight); acceleratedCursorPosition = This.TextView.GetTextPositionFromPoint(targetPoint, /*snapToText:*/ true); } double pageWidth = (double)((TextBoxBase)This.UiScope).ViewportWidth; // Auto scrolling to left/right scroll delta amount if the mouse X position // is out of viewport area. if (pointScroller.X < 0) { targetPoint = new Point(targetPoint.X - slowAreaDelta, targetPoint.Y); acceleratedCursorPosition = This.TextView.GetTextPositionFromPoint(targetPoint, /*snapToText:*/ true); } else if (pointScroller.X > pageWidth) { targetPoint = new Point(targetPoint.X + slowAreaDelta, targetPoint.Y); acceleratedCursorPosition = This.TextView.GetTextPositionFromPoint(targetPoint, /*snapToText:*/ true); } // Use acceleratedcursorPosition instead of real one to make scrolling reasonable faster if (acceleratedCursorPosition != null) { snappedCursorPosition = acceleratedCursorPosition; } } using (This.Selection.DeclareChangeBlock()) { // Check end-of-container condition if (snappedCursorPosition.GetNextInsertionPosition(LogicalDirection.Forward) == null && snappedCursorPosition.ParentType != null) // { // We are at the end of text container. Check whether mouse is farther than a last character Rect lastCharacterRect = snappedCursorPosition.GetCharacterRect(LogicalDirection.Backward); if (mouseMovePoint.X > lastCharacterRect.X + lastCharacterRect.Width) { snappedCursorPosition = This.TextContainer.End; } } // Move the caret/selection to match the cursor position. This.Selection.ExtendSelectionByMouse(snappedCursorPosition, This._forceWordSelection, This._forceParagraphSelection); } } } } }
// Token: 0x06003884 RID: 14468 RVA: 0x000FD66C File Offset: 0x000FB86C private static void OnMouseMoveWithFocus(TextEditor This, MouseEventArgs e) { if (This._mouseCapturingInProgress) { return; } TextEditor._ThreadLocalStore.PureControlShift = false; Point position = e.GetPosition(This.TextView.RenderScope); TextEditorMouse.UpdateCursor(This, position); Invariant.Assert(This.Selection != null); if (e.LeftButton != MouseButtonState.Pressed) { return; } if (!This.UiScope.IsMouseCaptured) { return; } This.TextView.ThrottleBackgroundTasksForUserInput(); if (This._tableColResizeInfo != null) { This._tableColResizeInfo.UpdateAdorner(position); return; } e.Handled = true; Invariant.Assert(This.Selection != null); ITextPointer textPointer = This.TextView.GetTextPositionFromPoint(position, true); Invariant.Assert(This.Selection != null); if (textPointer == null) { This.RequestExtendSelection(position); return; } This.CancelExtendSelection(); Invariant.Assert(This.Selection != null); if (!This._dragDropProcess.SourceOnMouseMove(position)) { FrameworkElement scroller = This._Scroller; if (scroller != null && This.UiScope is TextBoxBase) { ITextPointer textPointer2 = null; Point point = new Point(position.X, position.Y); Point position2 = e.GetPosition(scroller); double num = ((TextBoxBase)This.UiScope).ViewportHeight; double num2 = 16.0; if (position2.Y < 0.0 - num2) { Rect rectangleFromTextPosition = This.TextView.GetRectangleFromTextPosition(textPointer); point = new Point(point.X, rectangleFromTextPosition.Bottom - num); textPointer2 = This.TextView.GetTextPositionFromPoint(point, true); } else if (position2.Y > num + num2) { Rect rectangleFromTextPosition2 = This.TextView.GetRectangleFromTextPosition(textPointer); point = new Point(point.X, rectangleFromTextPosition2.Top + num); textPointer2 = This.TextView.GetTextPositionFromPoint(point, true); } double num3 = ((TextBoxBase)This.UiScope).ViewportWidth; if (position2.X < 0.0) { point = new Point(point.X - num2, point.Y); textPointer2 = This.TextView.GetTextPositionFromPoint(point, true); } else if (position2.X > num3) { point = new Point(point.X + num2, point.Y); textPointer2 = This.TextView.GetTextPositionFromPoint(point, true); } if (textPointer2 != null) { textPointer = textPointer2; } } using (This.Selection.DeclareChangeBlock()) { if (textPointer.GetNextInsertionPosition(LogicalDirection.Forward) == null && textPointer.ParentType != null) { Rect characterRect = textPointer.GetCharacterRect(LogicalDirection.Backward); if (position.X > characterRect.X + characterRect.Width) { textPointer = This.TextContainer.End; } } This.Selection.ExtendSelectionByMouse(textPointer, This._forceWordSelection, This._forceParagraphSelection); } } }