/// <summary>
        /// Get the bounds of an element relative to another element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="otherElement">
        /// The element relative to the other element.
        /// </param>
        /// <returns>
        /// The bounds of the element relative to another element, or null if
        /// the elements are not related.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="element"/> is null.
        /// </exception>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="otherElement"/> is null.
        /// </exception>
        public static Rect?GetBoundsRelativeTo(this FrameworkElement element, UIElement otherElement)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            else if (otherElement == null)
            {
                throw new ArgumentNullException("otherElement");
            }

            try
            {
                Point            origin, bottom;
                GeneralTransform transform = element.TransformToVisual(otherElement);
                if (transform != null &&
                    transform.TryTransform(new Point(), out origin) &&
                    transform.TryTransform(new Point(element.ActualWidth, element.ActualHeight), out bottom))
                {
                    return(new Rect(origin, bottom));
                }
            }
            catch (ArgumentException)
            {
                // Ignore any exceptions thrown while trying to transform
            }

            return(null);
        }
        /// <summary>
        /// Private helper that takes an element and transforms it's 4 points
        /// into the InkCanvas's space
        /// </summary>
        private static ElementCornerPoints GetTransformedElementCornerPoints(InkCanvasInnerCanvas canvas, UIElement childElement)
        {
            Debug.Assert(canvas != null);
            Debug.Assert(childElement != null);

            Debug.Assert(canvas.CheckAccess());

            ElementCornerPoints elementPoints = new ElementCornerPoints();

            elementPoints.Set = false;

            if (childElement.Visibility != Visibility.Visible)
            {
                //
                // this little one's not worth it...
                //
                return(elementPoints);
            }

            //
            // get the transform from us to our parent InkCavas
            //
            GeneralTransform parentTransform = childElement.TransformToAncestor(canvas);

            //

            parentTransform.TryTransform(new Point(0, 0), out elementPoints.UpperLeft);
            parentTransform.TryTransform(new Point(childElement.RenderSize.Width, 0), out elementPoints.UpperRight);
            parentTransform.TryTransform(new Point(0, childElement.RenderSize.Height), out elementPoints.LowerLeft);
            parentTransform.TryTransform(new Point(childElement.RenderSize.Width, childElement.RenderSize.Height), out elementPoints.LowerRight);

            elementPoints.Set = true;
            return(elementPoints);
        }
Exemple #3
0
        /// <summary>
        /// Private helper that takes an element and transforms it's 4 points
        /// into the InkCanvas's space
        /// </summary>
        private static ElementCornerPoints GetTransformedElementCornerPoints(InkCanvasInnerCanvas canvas, UIElement childElement)
        {
            Debug.Assert(canvas != null);
            Debug.Assert(childElement != null);

            Debug.Assert(canvas.CheckAccess());

            ElementCornerPoints elementPoints = new ElementCornerPoints();

            elementPoints.Set = false;

            if (childElement.Visibility != Visibility.Visible)
            {
                //
                // this little one's not worth it...
                //
                return(elementPoints);
            }

            //
            // get the transform from us to our parent InkCavas
            //
            GeneralTransform parentTransform = childElement.TransformToAncestor(canvas);

            // REVIEW: any of the methods below may not actually perform the transformation
            // Do we need to do anything special in that scenario?
            parentTransform.TryTransform(new Point(0, 0), out elementPoints.UpperLeft);
            parentTransform.TryTransform(new Point(childElement.RenderSize.Width, 0), out elementPoints.UpperRight);
            parentTransform.TryTransform(new Point(0, childElement.RenderSize.Height), out elementPoints.LowerLeft);
            parentTransform.TryTransform(new Point(childElement.RenderSize.Width, childElement.RenderSize.Height), out elementPoints.LowerRight);

            elementPoints.Set = true;
            return(elementPoints);
        }
Exemple #4
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);
        }
Exemple #5
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);
                }
            }
        }
Exemple #6
0
        // Calculates ribbonTab.TabHeaderLeft and ribbonTab.TabHeaderRight.
        private void RecalculateTabHeaderLeftAndRightCallback()
        {
            Ribbon    ribbon    = Ribbon;
            RibbonTab ribbonTab = RibbonTab;

            if (ribbon != null &&
                ribbonTab != null &&
                ribbon.IsAncestorOf(ribbonTab))
            {
                Thickness margin          = _outerBorder != null ? _outerBorder.Margin : new Thickness();
                Thickness borderThickness = _outerBorder != null ? _outerBorder.BorderThickness : new Thickness();

                Point leftBottom  = new Point(margin.Left + borderThickness.Left, ActualHeight);
                Point rightBottom = new Point(ActualWidth - margin.Right - borderThickness.Right, ActualHeight);

                GeneralTransform transformToRibbon = this.TransformToAncestor(ribbon);
                transformToRibbon.TryTransform(leftBottom, out leftBottom);
                transformToRibbon.TryTransform(rightBottom, out rightBottom);

                GeneralTransform transformToRibbonTab = ribbon.TransformToDescendant(ribbonTab);
                transformToRibbonTab.TryTransform(leftBottom, out leftBottom);
                transformToRibbonTab.TryTransform(rightBottom, out rightBottom);

                ribbonTab.TabHeaderLeft  = leftBottom.X;
                ribbonTab.TabHeaderRight = rightBottom.X;
            }
        }
Exemple #7
0
        // Clips a Point to the ActualWidth/Height of a containing FrameworkElement.
        private static void ClipToElement(FrameworkElement element, GeneralTransform transform,
                                          ref double horizontalOffset, ref double verticalOffset)
        {
            Point minPoint;
            Point maxPoint;

            Geometry clip = VisualTreeHelper.GetClip(element);

            if (clip != null)
            {
                Rect bounds = clip.Bounds;
                minPoint = new Point(bounds.X, bounds.Y);
                maxPoint = new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height);
            }
            else
            {
                if (element.ActualWidth == 0 && element.ActualHeight == 0)
                {
                    // Some elements, noteably Canvas, have a (0, 0) desired size
                    // and should be ignored.
                    return;
                }

                minPoint = new Point(0, 0);
                maxPoint = new Point(element.ActualWidth, element.ActualHeight);
            }

            transform.TryTransform(minPoint, out minPoint);
            transform.TryTransform(maxPoint, out maxPoint);

            // NB: ClipToBounds will handle the case where transform flips a coordinate
            // axis.  In that case, minPoint.X will be > maxPoint.X.
            horizontalOffset = ClipToBounds(minPoint.X, horizontalOffset, maxPoint.X);
            verticalOffset   = ClipToBounds(minPoint.Y, verticalOffset, maxPoint.Y);
        }
Exemple #8
0
 public static Rect?GetBoundsRelativeTo(this FrameworkElement element, UIElement otherElement)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (otherElement == null)
     {
         throw new ArgumentNullException("otherElement");
     }
     try
     {
         GeneralTransform generalTransform = element.TransformToVisual((Visual)otherElement);
         if (generalTransform != null)
         {
             Point result1;
             if (generalTransform.TryTransform(new Point(), out result1))
             {
                 Point result2;
                 if (generalTransform.TryTransform(new Point(element.ActualWidth, element.ActualHeight), out result2))
                 {
                     return(new Rect?(new Rect(result1, result2)));
                 }
             }
         }
     }
     catch (ArgumentException ex)
     {
     }
     return(new Rect?());
 }
Exemple #9
0
 // Token: 0x06006502 RID: 25858 RVA: 0x001C5614 File Offset: 0x001C3814
 internal static void DumpDocumentPage(XmlTextWriter writer, DocumentPage page, Visual parent)
 {
     writer.WriteStartElement("DocumentPage");
     writer.WriteAttributeString("Type", page.GetType().FullName);
     if (page != DocumentPage.Missing)
     {
         LayoutDump.DumpSize(writer, "Size", page.Size);
         GeneralTransform generalTransform = page.Visual.TransformToAncestor(parent);
         Point            point            = new Point(0.0, 0.0);
         generalTransform.TryTransform(point, out point);
         if (point.X != 0.0 || point.Y != 0.0)
         {
             LayoutDump.DumpPoint(writer, "Position", point);
         }
         Type type = page.GetType();
         LayoutDump.DumpCustomDocumentPage dumpCustomDocumentPage = null;
         while (dumpCustomDocumentPage == null && type != null)
         {
             dumpCustomDocumentPage = (LayoutDump._documentPageToDumpHandler[type] as LayoutDump.DumpCustomDocumentPage);
             type = type.BaseType;
         }
         if (dumpCustomDocumentPage != null)
         {
             dumpCustomDocumentPage(writer, page);
         }
     }
     writer.WriteEndElement();
 }
        /// <summary>
        /// Returns a geometry for the insertion indicator.
        /// </summary>
        /// <param name="dropTarget">The drop target.</param>
        /// <param name="insertionIndex">The insertion index within the drop
        /// target.</param>
        /// <param name="dragEventArgs">Information about the drag event.
        /// </param>
        /// <returns>The geometry for the insertion indicator.</returns>
        protected override Geometry GetInsertionIndicatorGeometry(ItemsControl dropTarget, int insertionIndex, SW.DragEventArgs dragEventArgs)
        {
            ItemsControl itemsControlAncestor = GetItemsControlAncestor((DependencyObject)dragEventArgs.OriginalSource);
            TreeViewItem treeViewItem         = dropTarget as TreeViewItem;

            // If the parent items control is the drop target then we're
            // appending the item into the child collection of the currently
            // hovered tree view item.
            if (treeViewItem != null && itemsControlAncestor != dropTarget)
            {
                GeneralTransform generalTransform = dropTarget.SafeTransformToVisual(this);
                if (generalTransform != null)
                {
                    Rect  dropTargetRect = GetTreeViewItemRectExcludingChildren(treeViewItem);
                    Point origin;
                    if (generalTransform.TryTransform(new Point(0, 0), out origin))
                    {
                        Point dropTargetPositionRelativeToDragDropTarget = origin;
                        dropTargetPositionRelativeToDragDropTarget.X += dropTargetRect.Left;
                        dropTargetPositionRelativeToDragDropTarget.Y += dropTargetRect.Top;
                        return(new RectangleGeometry {
                            Rect = new Rect(dropTargetPositionRelativeToDragDropTarget, new Size(dropTargetRect.Width, dropTargetRect.Height))
                        });
                    }
                }
            }

            return(base.GetInsertionIndicatorGeometry(dropTarget, insertionIndex, dragEventArgs));
        }
Exemple #11
0
            // Token: 0x060085BD RID: 34237 RVA: 0x0024AA08 File Offset: 0x00248C08
            private ITextPointer GetDropPosition(Visual target, Point point)
            {
                Invariant.Assert(target != null);
                Invariant.Assert(this._textEditor.TextView.IsValid);
                if (target != this._textEditor.TextView.RenderScope && target != null && this._textEditor.TextView.RenderScope.IsAncestorOf(target))
                {
                    GeneralTransform generalTransform = target.TransformToAncestor(this._textEditor.TextView.RenderScope);
                    generalTransform.TryTransform(point, out point);
                }
                ITextPointer textPointer = this.TextView.GetTextPositionFromPoint(point, true);

                if (textPointer != null)
                {
                    textPointer = textPointer.GetInsertionPosition(textPointer.LogicalDirection);
                    if (this._textEditor.AcceptsRichContent)
                    {
                        TextSegment normalizedLineRange = TextEditorSelection.GetNormalizedLineRange(this.TextView, textPointer);
                        if (!normalizedLineRange.IsNull && textPointer.CompareTo(normalizedLineRange.End) < 0 && !TextPointerBase.IsAtWordBoundary(textPointer, LogicalDirection.Forward) && this._dragSourceTextRange != null && TextPointerBase.IsAtWordBoundary(this._dragSourceTextRange.Start, LogicalDirection.Forward) && TextPointerBase.IsAtWordBoundary(this._dragSourceTextRange.End, LogicalDirection.Forward))
                        {
                            TextSegment wordRange        = TextPointerBase.GetWordRange(textPointer);
                            string      textInternal     = TextRangeBase.GetTextInternal(wordRange.Start, wordRange.End);
                            int         offsetToPosition = wordRange.Start.GetOffsetToPosition(textPointer);
                            textPointer = ((offsetToPosition < textInternal.Length / 2) ? wordRange.Start : wordRange.End);
                        }
                    }
                }
                return(textPointer);
            }
Exemple #12
0
        // Token: 0x06006500 RID: 25856 RVA: 0x001C5414 File Offset: 0x001C3614
        internal static void DumpVisual(XmlTextWriter writer, Visual visual, Visual parent)
        {
            if (visual is UIElement)
            {
                LayoutDump.DumpUIElement(writer, (UIElement)visual, parent, false);
                return;
            }
            writer.WriteStartElement(visual.GetType().Name);
            Rect visualContentBounds = visual.VisualContentBounds;

            if (!visualContentBounds.IsEmpty)
            {
                LayoutDump.DumpRect(writer, "ContentRect", visualContentBounds);
            }
            Geometry clip = VisualTreeHelper.GetClip(visual);

            if (clip != null)
            {
                LayoutDump.DumpRect(writer, "Clip.Bounds", clip.Bounds);
            }
            GeneralTransform generalTransform = visual.TransformToAncestor(parent);
            Point            point            = new Point(0.0, 0.0);

            generalTransform.TryTransform(point, out point);
            if (point.X != 0.0 || point.Y != 0.0)
            {
                LayoutDump.DumpPoint(writer, "Position", point);
            }
            LayoutDump.DumpVisualChildren(writer, "Children", visual);
            writer.WriteEndElement();
        }
Exemple #13
0
        // Token: 0x0600650D RID: 25869 RVA: 0x001C5B40 File Offset: 0x001C3D40
        private static bool DumpFlowDocumentView(XmlTextWriter writer, UIElement element, bool uiElementsOnly)
        {
            FlowDocumentView flowDocumentView = element as FlowDocumentView;
            IScrollInfo      scrollInfo       = flowDocumentView;

            if (scrollInfo.ScrollOwner != null)
            {
                Size size = new Size(scrollInfo.ExtentWidth, scrollInfo.ExtentHeight);
                if (DoubleUtil.AreClose(size, element.DesiredSize))
                {
                    LayoutDump.DumpSize(writer, "Extent", size);
                }
                Point point = new Point(scrollInfo.HorizontalOffset, scrollInfo.VerticalOffset);
                if (!DoubleUtil.IsZero(point.X) || !DoubleUtil.IsZero(point.Y))
                {
                    LayoutDump.DumpPoint(writer, "Offset", point);
                }
            }
            FlowDocumentPage documentPage     = flowDocumentView.Document.BottomlessFormatter.DocumentPage;
            GeneralTransform generalTransform = documentPage.Visual.TransformToAncestor(flowDocumentView);
            Point            point2           = new Point(0.0, 0.0);

            generalTransform.TryTransform(point2, out point2);
            if (!DoubleUtil.IsZero(point2.X) && !DoubleUtil.IsZero(point2.Y))
            {
                LayoutDump.DumpPoint(writer, "PagePosition", point2);
            }
            LayoutDump.DumpFlowDocumentPage(writer, documentPage);
            return(false);
        }
Exemple #14
0
        public void SimulateMouseLeftDoubleClick(UIElement element, Point pt)
        {
            GeneralTransform transform = GetTransformToRootElement(element);

            transform.TryTransform(pt, out pt);
            _mouse.SimulateLeftDoubleClick(this.MainWindow, pt);
        }
Exemple #15
0
        /// <summary>
        /// Calculates the new Value of this control using a location and relative source.
        /// The location is translated to the control, and then used to set the value.
        /// </summary>
        /// <param name="location">A point.</param>
        /// <param name="locationRelativeSource">The UIElement that the point originated from.</param>
        private void PerformValueCalculation(Point location, UIElement locationRelativeSource)
        {
            GeneralTransform gt = locationRelativeSource.TransformToVisual(this);

            gt.TryTransform(location, out location);

            double numberOfPositions = _filledItemCollection.Count;

            if (AllowHalfItemIncrement)
            {
                numberOfPositions *= 2;
            }

            double newValue;

            if (Orientation == Orientation.Horizontal)
            {
                newValue = Math.Ceiling(location.X / ActualWidth * numberOfPositions);
            }
            else
            {
                newValue = Math.Ceiling(location.Y / ActualHeight * numberOfPositions);
            }

            if (!AllowSelectingZero && newValue <= 0)
            {
                newValue = 1;
            }

            Value = newValue;
        }
Exemple #16
0
        // ------------------------------------------------------------------
        // Dump paragraph offset.
        // ------------------------------------------------------------------
        private static Visual DumpParagraphOffset(XmlTextWriter writer, ParagraphResult paragraph, Visual visualParent)
        {
            Type paragraphResultType = paragraph.GetType();

            System.Reflection.FieldInfo field = paragraphResultType.GetField("_paraClient", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            object paraClient     = field.GetValue(paragraph);
            Type   paraClientType = paraClient.GetType();

            System.Reflection.PropertyInfo prop = paraClientType.GetProperty("Visual", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            Visual visual = (Visual)prop.GetValue(paraClient, null);

            // Dump transform relative to its parent
            if (visualParent.IsAncestorOf(visual))
            {
                GeneralTransform g     = visual.TransformToAncestor(visualParent);
                Point            point = new Point(0.0f, 0.0f);
                g.TryTransform(point, out point);

                if (point.X != 0 || point.Y != 0)
                {
                    DumpPoint(writer, "Origin", point);
                }
            }

            return(visual);
        }
Exemple #17
0
        // ------------------------------------------------------------------
        // Dump content of DocumentPage.
        // ------------------------------------------------------------------
        internal static void DumpDocumentPage(XmlTextWriter writer, DocumentPage page, Visual parent)
        {
            writer.WriteStartElement("DocumentPage");
            writer.WriteAttributeString("Type", page.GetType().FullName);

            if (page != DocumentPage.Missing)
            {
                DumpSize(writer, "Size", page.Size);

                // Dump transform relative to its parent
                GeneralTransform g     = page.Visual.TransformToAncestor(parent);
                Point            point = new Point(0, 0);
                g.TryTransform(point, out point);
                if (point.X != 0 || point.Y != 0)
                {
                    DumpPoint(writer, "Position", point);
                }

                // Dump page specific information
                Type t = page.GetType();
                DumpCustomDocumentPage dumpDocumentPage = null;
                while (dumpDocumentPage == null && t != null)
                {
                    dumpDocumentPage = _documentPageToDumpHandler[t] as DumpCustomDocumentPage;
                    t = t.BaseType;
                }
                if (dumpDocumentPage != null)
                {
                    dumpDocumentPage(writer, page);
                }
            }

            writer.WriteEndElement();
        }
        private Rect GetBounds(StylusPoint stylusPoint,
                               Point position,
                               IInputElement relativeTo,
                               GeneralTransform elementToRoot,
                               GeneralTransform rootToElement)
        {
            // Get width and heith in pixel value
            double width  = GetStylusPointWidthOrHeight(stylusPoint, /*isWidth*/ true);
            double height = GetStylusPointWidthOrHeight(stylusPoint, /*isWidth*/ false);

            // Get the position with respect to root
            Point rootPoint;

            if (elementToRoot == null ||
                !elementToRoot.TryTransform(position, out rootPoint))
            {
                rootPoint = position;
            }

            // Create a Rect with respect to root and transform it to element coordinate space
            Rect rectBounds = new Rect(rootPoint.X - width * 0.5, rootPoint.Y - height * 0.5, width, height);

            if (rootToElement != null)
            {
                rectBounds = rootToElement.TransformBounds(rectBounds);
            }
            return(rectBounds);
        }
Exemple #19
0
            public override bool TryTransform(Point inPoint, out Point result)
            {
                bool ok = false;

                result = new Point();

                // Both the normal and the inverse require the point to first be
                // translated from world space to unit space.
                Point?unitSpace = Effect.WorldToUnit(inPoint, _worldBounds);

                if (unitSpace != null)
                {
                    // Now just run through the normal or the inverse version of the
                    // inner effect.
                    GeneralTransform innerToUse = GetCorrectInnerTransform();

                    Point unitResult;
                    if (innerToUse.TryTransform(unitSpace.Value, out unitResult))
                    {
                        // Both the normal and the inverse require the unit-space result
                        // to be converted back to world space
                        Point?worldSpace = Effect.UnitToWorld(unitResult, _worldBounds);
                        if (worldSpace != null)
                        {
                            result = worldSpace.Value;
                            ok     = true;
                        }
                    }
                }

                return(ok);
            }
        /// <summary>
        /// Retrieves the location and dimensions of a TreeViewItem excluding
        /// its children.
        /// </summary>
        /// <param name="treeViewItem">The tree view item.</param>
        /// <returns>The location and dimensions of the TreeViewItem excluding
        /// its children.</returns>
        protected virtual Rect GetTreeViewItemRectExcludingChildren(TreeViewItem treeViewItem)
        {
            if (treeViewItem.IsExpanded)
            {
                FrameworkElement rootVisual = treeViewItem.GetVisualChildren().FirstOrDefault() as FrameworkElement;
                if (rootVisual != null)
                {
                    FrameworkElement header =
                        rootVisual
                        .GetLogicalDescendents()
                        .Where(element => element.Name == "Header").FirstOrDefault();
                    if (header != null)
                    {
                        Rect             rectangle        = new Rect(0, 0, 0, 0);
                        GeneralTransform generalTransform = header.SafeTransformToVisual(treeViewItem);
                        Point            origin;
                        if (generalTransform != null && generalTransform.TryTransform(new Point(0, 0), out origin))
                        {
                            rectangle = new Rect(origin, header.GetSize());
                        }
                        return(rectangle);
                    }
                }
            }

            return(new Rect(new Point(), treeViewItem.GetSize()));
        }
Exemple #21
0
        public static Point LocationOnScreen(Visual visual)
        {
            Application currApp   = Application.Current;
            Window      appWindow = currApp != null ? currApp.MainWindow : null;

            if (appWindow == null || !appWindow.IsAncestorOf(visual))
            {
                appWindow = FindParentWindow(visual);
            }
            Point            relativeToWindow        = new Point(0, 0);
            GeneralTransform targetToWindowTransform = visual.TransformToVisual(appWindow);

            if (!targetToWindowTransform.TryTransform(new Point(0, 0), out relativeToWindow))
            {
                throw new Exception("Failed to transform point.");
            }
            //
            // Add 4 to X and 24 to Y because _window.Left/Top return Content position, so we
            // adjust for the window chrome.
            //
            // Adding DPI scaling.  Will multiply actual points and the buffer noted above
            // by the current DPI/96..
            relativeToWindow = new Point(Monitor.ConvertLogicalToScreen(Dimension.Width, relativeToWindow.X), Monitor.ConvertLogicalToScreen(Dimension.Height, relativeToWindow.Y));

            Point relativeToScreen = new Point(relativeToWindow.X + appWindow.Left + Monitor.ConvertLogicalToScreen(Dimension.Width, 4.0), relativeToWindow.Y + appWindow.Top + Monitor.ConvertLogicalToScreen(Dimension.Height, 24.0));

            return(relativeToScreen);
        }
        /// <summary>
        /// Private clone implementation
        /// </summary>
        private StylusPointCollection Clone(GeneralTransform transform, StylusPointDescription descriptionToUse, int count)
        {
            Debug.Assert(count <= this.Count);
            //
            // We don't need to copy our _stylusPointDescription because it is immutable
            // and we don't need to copy our StylusPoints, because they are structs.
            //
            StylusPointCollection newCollection =
                new StylusPointCollection(descriptionToUse, count);

            bool isIdentity = (transform is Transform) ? ((Transform)transform).IsIdentity : false;

            for (int x = 0; x < count; x++)
            {
                if (isIdentity)
                {
                    ((List <StylusPoint>)newCollection.Items).Add(this[x]);
                }
                else
                {
                    Point       point       = new Point();
                    StylusPoint stylusPoint = this[x];
                    point.X = stylusPoint.X;
                    point.Y = stylusPoint.Y;
                    transform.TryTransform(point, out point);
                    stylusPoint.X = point.X;
                    stylusPoint.Y = point.Y;
                    ((List <StylusPoint>)newCollection.Items).Add(stylusPoint);
                }
            }
            return(newCollection);
        }
        /// <summary>
        /// Internal ctor called by input with a raw int[]
        /// </summary>
        /// <param name="stylusPointDescription">stylusPointDescription</param>
        /// <param name="rawPacketData">rawPacketData</param>
        /// <param name="tabletToView">tabletToView</param>
        /// <param name="tabletToViewMatrix">tabletToView</param>
        internal StylusPointCollection(StylusPointDescription stylusPointDescription, int[] rawPacketData, GeneralTransform tabletToView, Matrix tabletToViewMatrix)
        {
            if (null == stylusPointDescription)
            {
                throw new ArgumentNullException("stylusPointDescription");
            }
            _stylusPointDescription = stylusPointDescription;

            int lengthPerPoint    = stylusPointDescription.GetInputArrayLengthPerPoint();
            int logicalPointCount = rawPacketData.Length / lengthPerPoint;

            Debug.Assert(0 == rawPacketData.Length % lengthPerPoint, "Invalid assumption about packet length, there shouldn't be any remainder");

            //
            // set our capacity and validate
            //
            ((List <StylusPoint>) this.Items).Capacity = logicalPointCount;
            for (int count = 0, i = 0; count < logicalPointCount; count++, i += lengthPerPoint)
            {
                //first, determine the x, y values by xf-ing them
                Point p = new Point(rawPacketData[i], rawPacketData[i + 1]);
                if (tabletToView != null)
                {
                    tabletToView.TryTransform(p, out p);
                }
                else
                {
                    p = tabletToViewMatrix.Transform(p);
                }

                int  startIndex           = 2;
                bool containsTruePressure = stylusPointDescription.ContainsTruePressure;
                if (containsTruePressure)
                {
                    //don't copy pressure in the int[] for extra data
                    startIndex++;
                }

                int[] data       = null;
                int   dataLength = lengthPerPoint - startIndex;
                if (dataLength > 0)
                {
                    //copy the rest of the data
                    var rawArrayStartIndex = i + startIndex;
                    data = rawPacketData.AsSpan(rawArrayStartIndex, dataLength).ToArray();
                }

                StylusPoint newPoint = new StylusPoint(p.X, p.Y, StylusPoint.DefaultPressure, _stylusPointDescription, data, false, false);
                if (containsTruePressure)
                {
                    //use the algorithm to set pressure in StylusPoint
                    int pressure = rawPacketData[i + 2];
                    newPoint.SetPropertyValue(StylusPointProperties.NormalPressure, pressure);
                }

                //this does not go through our protected virtuals
                ((List <StylusPoint>) this.Items).Add(newPoint);
            }
        }
        // Token: 0x06006DBE RID: 28094 RVA: 0x001F8850 File Offset: 0x001F6A50
        private static LassoSelectionBehavior.ElementCornerPoints GetTransformedElementCornerPoints(InkCanvasInnerCanvas canvas, UIElement childElement)
        {
            LassoSelectionBehavior.ElementCornerPoints result = default(LassoSelectionBehavior.ElementCornerPoints);
            result.Set = false;
            if (childElement.Visibility != Visibility.Visible)
            {
                return(result);
            }
            GeneralTransform generalTransform = childElement.TransformToAncestor(canvas);

            generalTransform.TryTransform(new Point(0.0, 0.0), out result.UpperLeft);
            generalTransform.TryTransform(new Point(childElement.RenderSize.Width, 0.0), out result.UpperRight);
            generalTransform.TryTransform(new Point(0.0, childElement.RenderSize.Height), out result.LowerLeft);
            generalTransform.TryTransform(new Point(childElement.RenderSize.Width, childElement.RenderSize.Height), out result.LowerRight);
            result.Set = true;
            return(result);
        }
        // Token: 0x06002EF5 RID: 12021 RVA: 0x000D4514 File Offset: 0x000D2714
        private Rect _GetTransformedCaretRect(GeneralTransform transform, Point origin, double height)
        {
            Point point = origin;

            point.Y += height;
            transform.TryTransform(origin, out origin);
            transform.TryTransform(point, out point);
            Rect result = new Rect(origin, point);

            if (result.Width > 0.0)
            {
                result.X    += result.Width / 2.0;
                result.Width = 0.0;
            }
            if (result.Height < 1.0)
            {
                result.Height = 1.0;
            }
            return(result);
        }
Exemple #26
0
        private Point TransformPointToToolBar(ToolBar toolBar, Point point)
        {
            Point            p         = point;
            GeneralTransform transform = this.TransformToDescendant(toolBar);

            if (transform != null)
            {
                transform.TryTransform(point, out p);
            }
            return(p);
        }
Exemple #27
0
        // Token: 0x0600585A RID: 22618 RVA: 0x00187904 File Offset: 0x00185B04
        private Point TransformPointToToolBar(ToolBar toolBar, Point point)
        {
            Point            result           = point;
            GeneralTransform generalTransform = base.TransformToDescendant(toolBar);

            if (generalTransform != null)
            {
                generalTransform.TryTransform(point, out result);
            }
            return(result);
        }
Exemple #28
0
        // ------------------------------------------------------------------
        // Dump content of UIElement.
        // ------------------------------------------------------------------
        private static void DumpUIElement(XmlTextWriter writer, UIElement element, Visual parent, bool uiElementsOnly)
        {
            writer.WriteStartElement(element.GetType().Name);

            // Dump layout information
            DumpSize(writer, "DesiredSize", element.DesiredSize);
            DumpSize(writer, "ComputedSize", element.RenderSize);
            Geometry clip = VisualTreeHelper.GetClip(element);

            if (clip != null)
            {
                DumpRect(writer, "Clip.Bounds", clip.Bounds);
            }

            // Dump transform relative to its parent
            GeneralTransform g     = element.TransformToAncestor(parent);
            Point            point = new Point(0, 0);

            g.TryTransform(point, out point);
            if (point.X != 0 || point.Y != 0)
            {
                DumpPoint(writer, "Position", point);
            }

            // Dump element specific information
            bool childrenHandled = false;
            Type t = element.GetType();
            DumpCustomUIElement dumpElement = null;

            while (dumpElement == null && t != null)
            {
                dumpElement = _elementToDumpHandler[t] as DumpCustomUIElement;
                t           = t.BaseType;
            }
            if (dumpElement != null)
            {
                childrenHandled = dumpElement(writer, element, uiElementsOnly);
            }

            if (!childrenHandled)
            {
                if (uiElementsOnly)
                {
                    DumpUIElementChildren(writer, "Children", element);
                }
                else
                {
                    DumpVisualChildren(writer, "Children", element);
                }
            }

            writer.WriteEndElement();
        }
        internal HitTestResultBehavior RaiseCallback(HitTestResultCallback resultCallback,
                                                     HitTestFilterCallback filterCallback,
                                                     HitTestResultBehavior lastResult,
                                                     double distanceAdjustment)
        {
            results.Sort(RayHitTestResult.CompareByDistanceToRayOrigin);

            for (int i = 0, count = results.Count; i < count; i++)
            {
                RayHitTestResult result = results[i];

                result.SetDistanceToRayOrigin(result.DistanceToRayOrigin + distanceAdjustment);

                Viewport2DVisual3D viewport2DVisual3D = result.VisualHit as Viewport2DVisual3D;
                if (viewport2DVisual3D != null)
                {
                    Point  intersectionPoint;
                    Visual viewport2DVisual3DChild = viewport2DVisual3D.Visual;

                    if (viewport2DVisual3DChild != null)
                    {
                        if (Viewport2DVisual3D.GetIntersectionInfo(result, out intersectionPoint))
                        {
                            // convert the resulting point to visual coordinates
                            Point            visualPoint = Viewport2DVisual3D.TextureCoordsToVisualCoords(intersectionPoint, viewport2DVisual3DChild);
                            GeneralTransform gt          = viewport2DVisual3DChild.TransformToOuterSpace().Inverse;

                            Point pointOnChild;
                            if (gt != null && gt.TryTransform(visualPoint, out pointOnChild))
                            {
                                HitTestResultBehavior behavior2D = viewport2DVisual3DChild.HitTestPoint(filterCallback,
                                                                                                        resultCallback,
                                                                                                        new PointHitTestParameters(pointOnChild));

                                if (behavior2D == HitTestResultBehavior.Stop)
                                {
                                    return(HitTestResultBehavior.Stop);
                                }
                            }
                        }
                    }
                }

                HitTestResultBehavior behavior = resultCallback(results[i]);

                if (behavior == HitTestResultBehavior.Stop)
                {
                    return(HitTestResultBehavior.Stop);
                }
            }

            return(lastResult);
        }
        // Token: 0x06002EF1 RID: 12017 RVA: 0x000D3FAC File Offset: 0x000D21AC
        private ITextPointer _SnapToText(Point point)
        {
            FixedNode[]  line = this.Container.FixedTextBuilder.GetLine(this.PageIndex, point);
            ITextPointer textPointer;

            if (line != null && line.Length != 0)
            {
                double    num       = double.MaxValue;
                double    xoffset   = 0.0;
                Glyphs    glyphs    = null;
                FixedNode fixedNode = line[0];
                foreach (FixedNode fixedNode2 in line)
                {
                    Glyphs           glyphsElement    = this.FixedPage.GetGlyphsElement(fixedNode2);
                    GeneralTransform generalTransform = this.FixedPage.TransformToDescendant(glyphsElement);
                    Point            inPoint          = point;
                    if (generalTransform != null)
                    {
                        generalTransform.TryTransform(inPoint, out inPoint);
                    }
                    GlyphRun glyphRun = glyphsElement.ToGlyphRun();
                    Rect     rect     = glyphRun.ComputeAlignmentBox();
                    rect.Offset(glyphsElement.OriginX, glyphsElement.OriginY);
                    double num2 = Math.Max(0.0, (inPoint.X > rect.X) ? (inPoint.X - rect.Right) : (rect.X - inPoint.X));
                    double num3 = Math.Max(0.0, (inPoint.Y > rect.Y) ? (inPoint.Y - rect.Bottom) : (rect.Y - inPoint.Y));
                    double num4 = num2 + num3;
                    if (glyphs == null || num4 < num)
                    {
                        num       = num4;
                        glyphs    = glyphsElement;
                        fixedNode = fixedNode2;
                        xoffset   = inPoint.X;
                    }
                }
                int offset;
                LogicalDirection edge;
                this._GlyphRunHitTest(glyphs, xoffset, out offset, out edge);
                FixedPosition fixedPosition = new FixedPosition(fixedNode, offset);
                textPointer = this._CreateTextPointer(fixedPosition, edge);
            }
            else if (point.Y < this.FixedPage.Height / 2.0)
            {
                textPointer = ((ITextPointer)this.Start).CreatePointer(LogicalDirection.Forward);
                textPointer.MoveToInsertionPosition(LogicalDirection.Forward);
            }
            else
            {
                textPointer = ((ITextPointer)this.End).CreatePointer(LogicalDirection.Backward);
                textPointer.MoveToInsertionPosition(LogicalDirection.Backward);
            }
            return(textPointer);
        }