예제 #1
0
        // Token: 0x0600384A RID: 14410 RVA: 0x000FB61C File Offset: 0x000F981C
        private static void ClipToElement(FrameworkElement element, GeneralTransform transform, ref double horizontalOffset, ref double verticalOffset)
        {
            Geometry clip = VisualTreeHelper.GetClip(element);
            Point    inPoint;
            Point    inPoint2;

            if (clip != null)
            {
                Rect bounds = clip.Bounds;
                inPoint  = new Point(bounds.X, bounds.Y);
                inPoint2 = new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height);
            }
            else
            {
                if (element.ActualWidth == 0.0 && element.ActualHeight == 0.0)
                {
                    return;
                }
                inPoint  = new Point(0.0, 0.0);
                inPoint2 = new Point(element.ActualWidth, element.ActualHeight);
            }
            transform.TryTransform(inPoint, out inPoint);
            transform.TryTransform(inPoint2, out inPoint2);
            horizontalOffset = TextEditorContextMenu.ClipToBounds(inPoint.X, horizontalOffset, inPoint2.X);
            verticalOffset   = TextEditorContextMenu.ClipToBounds(inPoint.Y, verticalOffset, inPoint2.Y);
        }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
        internal static void OnContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(sender);

            if (textEditor == null || textEditor.TextView == null)
            {
                return;
            }
            Point       position    = Mouse.GetPosition(textEditor.TextView.RenderScope);
            ContextMenu contextMenu = null;
            bool        flag        = false;

            if (textEditor.IsReadOnly)
            {
                if ((e.CursorLeft != -1.0 && !textEditor.Selection.Contains(position)) || (e.CursorLeft == -1.0 && textEditor.Selection.IsEmpty))
                {
                    return;
                }
            }
            else if ((textEditor.Selection.IsEmpty || e.TargetElement is TextElement) && e.TargetElement != null)
            {
                contextMenu = (ContextMenu)e.TargetElement.GetValue(FrameworkElement.ContextMenuProperty);
            }
            else if (e.CursorLeft == -1.0)
            {
                TextPointer textPointer = TextEditorContextMenu.GetContentPosition(textEditor.Selection.Start) as TextPointer;
                if (textPointer != null)
                {
                    for (TextElement textElement = textPointer.Parent as TextElement; textElement != null; textElement = (textElement.Parent as TextElement))
                    {
                        contextMenu = (ContextMenu)textElement.GetValue(FrameworkElement.ContextMenuProperty);
                        if (contextMenu != null)
                        {
                            flag = true;
                            break;
                        }
                    }
                }
            }
            if (e.CursorLeft != -1.0)
            {
                if (!TextEditorMouse.IsPointWithinInteractiveArea(textEditor, Mouse.GetPosition(textEditor.UiScope)))
                {
                    return;
                }
                if (contextMenu == null || !(e.TargetElement is UIElement))
                {
                    using (textEditor.Selection.DeclareChangeBlock())
                    {
                        if (!textEditor.Selection.Contains(position))
                        {
                            TextEditorMouse.SetCaretPositionOnMouseEvent(textEditor, position, MouseButton.Right, 1);
                        }
                    }
                }
            }
            if (contextMenu == null)
            {
                if (textEditor.UiScope.ReadLocalValue(FrameworkElement.ContextMenuProperty) == null)
                {
                    return;
                }
                contextMenu = textEditor.UiScope.ContextMenu;
            }
            textEditor.IsContextMenuOpen = true;
            if (contextMenu != null && !flag)
            {
                contextMenu.HorizontalOffset = 0.0;
                contextMenu.VerticalOffset   = 0.0;
                contextMenu.Closed          += TextEditorContextMenu.OnContextMenuClosed;
                return;
            }
            textEditor.CompleteComposition();
            if (contextMenu == null)
            {
                contextMenu = new TextEditorContextMenu.EditorContextMenu();
                ((TextEditorContextMenu.EditorContextMenu)contextMenu).AddMenuItems(textEditor, e.UserInitiated);
            }
            contextMenu.Placement       = PlacementMode.RelativePoint;
            contextMenu.PlacementTarget = textEditor.UiScope;
            ITextPointer     textPointer2  = null;
            SpellingError    spellingError = (contextMenu is TextEditorContextMenu.EditorContextMenu) ? textEditor.GetSpellingErrorAtSelection() : null;
            LogicalDirection logicalDirection;

            if (spellingError != null)
            {
                textPointer2     = spellingError.End;
                logicalDirection = LogicalDirection.Backward;
            }
            else if (e.CursorLeft == -1.0)
            {
                textPointer2     = textEditor.Selection.Start;
                logicalDirection = LogicalDirection.Forward;
            }
            else
            {
                logicalDirection = LogicalDirection.Forward;
            }
            if (textPointer2 != null && textPointer2.CreatePointer(logicalDirection).HasValidLayout)
            {
                double horizontalOffset;
                double verticalOffset;
                TextEditorContextMenu.GetClippedPositionOffsets(textEditor, textPointer2, logicalDirection, out horizontalOffset, out verticalOffset);
                contextMenu.HorizontalOffset = horizontalOffset;
                contextMenu.VerticalOffset   = verticalOffset;
            }
            else
            {
                Point position2 = Mouse.GetPosition(textEditor.UiScope);
                contextMenu.HorizontalOffset = position2.X;
                contextMenu.VerticalOffset   = position2.Y;
            }
            contextMenu.Closed += TextEditorContextMenu.OnContextMenuClosed;
            contextMenu.IsOpen  = true;
            e.Handled           = true;
        }