Exemple #1
0
        protected override void FillChildrenImpl()
        {
            base.FillChildrenImpl();
            for (var i = 0; i < CommonTreeHelper.GetChildrenCount(Visual); i++)
            {
                var child = CommonTreeHelper.GetChild(Visual, i);
                if (child != null)
                {
                    Children.Add(Construct(child, this));
                }
            }

            var grid = Visual as Grid;

            if (grid != null)
            {
                foreach (var row in grid.RowDefinitions)
                {
                    Children.Add(Construct(row, this));
                }
                foreach (var column in grid.ColumnDefinitions)
                {
                    Children.Add(Construct(column, this));
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///     Find the VisualTreeItem for the specified visual.
        ///     If the item is not found and is not part of the Snoop UI,
        ///     the tree will be adjusted to include the window the item is in.
        /// </summary>
        VisualTreeItem FindItem(object target)
        {
            var node       = rootVisualTreeItem.FindNode(target);
            var rootVisual = rootVisualTreeItem.MainVisual;

            if (node == null)
            {
                var visual = target as Visual;
                if (visual != null && rootVisual != null)
                {
                    // If target is a part of the SnoopUI, let's get out of here.
                    if (visual.IsDescendantOf(this))
                    {
                        return(null);
                    }

                    // If not in the root tree, make the root be the tree the visual is in.
                    if (!CommonTreeHelper.IsDescendantOf(visual, rootVisual))
                    {
                        var presentationSource = PresentationSource.FromVisual(visual);
                        if (presentationSource == null)
                        {
                            return(null); // Something went wrong. At least we will not crash with null ref here.
                        }

                        Root = new VisualItem(presentationSource.RootVisual, null);
                    }
                }

                rootVisualTreeItem.Reload();

                node = rootVisualTreeItem.FindNode(target);
            }
            return(node);
        }
Exemple #3
0
        static bool DoEnumerateTree(object reference, EnumerateTreeFilterCallback filterCallback,
                                    EnumerateTreeResultCallback enumeratorCallback, object misc)
        {
            for (var i = 0; i < CommonTreeHelper.GetChildrenCount(reference); ++i)
            {
                var child = CommonTreeHelper.GetChild(reference, i);

                var filterResult = HitTestFilterBehavior.Continue;
                if (filterCallback != null)
                {
                    filterResult = filterCallback(child, misc);
                }

                var enumerateSelf     = true;
                var enumerateChildren = true;

                switch (filterResult)
                {
                case HitTestFilterBehavior.Continue:
                    break;

                case HitTestFilterBehavior.ContinueSkipChildren:
                    enumerateChildren = false;
                    break;

                case HitTestFilterBehavior.ContinueSkipSelf:
                    enumerateSelf = false;
                    break;

                case HitTestFilterBehavior.ContinueSkipSelfAndChildren:
                    enumerateChildren = false;
                    enumerateSelf     = false;
                    break;

                default:
                    return(false);
                }

                if
                (
                    (enumerateSelf && enumeratorCallback != null &&
                     enumeratorCallback(child, misc) == HitTestResultBehavior.Stop) ||
                    (enumerateChildren && !DoEnumerateTree(child, filterCallback, enumeratorCallback, misc))
                )
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #4
0
        protected override void OnSelectionChanged()
        {
            // Add adorners for the visual this is representing.
            var visual_ = Visual as Visual;
            var offset  = new Thickness();

            if (visual_ == null)
            {
                var frec = Visual.Wrap <IFrameworkRenderElementContext>();
                if (frec != null && CommonTreeHelper.IsVisible(frec))
                {
                    FrameworkElement fe = frec.ElementHost.Parent;
                    visual_ = fe;
                    var rect =
                        ((Transform)RenderTreeHelper.TransformToRoot(frec)).TransformBounds(new Rect(frec.RenderSize));
                    offset = new Thickness(rect.Left, rect.Top, fe.RenderSize.Width - rect.Right,
                                           fe.RenderSize.Height - rect.Bottom);
                }
            }
            var adorners      = visual_ == null ? null : AdornerLayer.GetAdornerLayer(visual_);
            var visualElement = visual_ as UIElement;

            if (adorners != null && visualElement != null)
            {
                if (IsSelected && adorner == null)
                {
                    var border = new Border();
                    border.BorderThickness = new Thickness(4);
                    border.Margin          = offset;
                    var borderColor = new Color();
                    borderColor.ScA    = .3f;
                    borderColor.ScR    = 1;
                    border.BorderBrush = new SolidColorBrush(borderColor);

                    border.IsHitTestVisible = false;
                    adorner       = new AdornerContainer(visualElement);
                    adorner.Child = border;
                    adorners.Add(adorner);
                }
                else if (adorner != null)
                {
                    adorners.Remove(adorner);
                    adorner.Child = null;
                    adorner       = null;
                }
            }
        }
Exemple #5
0
        protected override void OnSelectionChanged()
        {
            // Add adorners for the visual this is representing.
            Visual    visual_ = this.Visual as Visual;
            Thickness offset  = new Thickness();

            if (visual_ == null)
            {
                var frec = (dynamic)this.Visual;
                if (frec != null && CommonTreeHelper.IsVisible(frec))
                {
                    var fe = DXMethods.GetParent(frec.ElementHost);
                    visual_ = fe;
                    var transform = RenderTreeHelper.TransformToRoot(frec).Inverse;
                    var trrec     = transform.TransformBounds(new Rect(fe.RenderSize));
                    offset = new Thickness(-trrec.Left, -trrec.Top, fe.RenderSize.Width - trrec.Right, fe.RenderSize.Height - trrec.Bottom);
                }
            }
            AdornerLayer adorners      = visual_ == null ? null : AdornerLayer.GetAdornerLayer(visual_);
            UIElement    visualElement = visual_ as UIElement;

            if (adorners != null && visualElement != null)
            {
                if (this.IsSelected && this.adorner == null)
                {
                    Border border = new Border();
                    border.BorderThickness = new Thickness(4);
                    border.Margin          = offset;
                    Color borderColor = new Color();
                    borderColor.ScA    = .3f;
                    borderColor.ScR    = 1;
                    border.BorderBrush = new SolidColorBrush(borderColor);

                    border.IsHitTestVisible = false;
                    this.adorner            = new AdornerContainer(visualElement);
                    adorner.Child           = border;
                    adorners.Add(adorner);
                }
                else if (this.adorner != null)
                {
                    adorners.Remove(this.adorner);
                    this.adorner.Child = null;
                    this.adorner       = null;
                }
            }
        }
Exemple #6
0
        protected override void Reload(List <VisualTreeItem> toBeRemoved)
        {
            // having the call to base.Reload here ... puts the application resources at the very top of the tree view.
            // this used to be at the bottom. putting it here makes it consistent (and easier to use) with ApplicationTreeItem
            base.Reload(toBeRemoved);

            // remove items that are no longer in tree, add new ones.
            for (int i = 0; i < CommonTreeHelper.GetChildrenCount(this.Visual); i++)
            {
                object child = CommonTreeHelper.GetChild(this.Visual, i);
                if (child != null)
                {
                    bool foundItem = false;
                    foreach (VisualTreeItem item in toBeRemoved)
                    {
                        if (item.Target == child)
                        {
                            toBeRemoved.Remove(item);
                            item.Reload();
                            foundItem = true;
                            break;
                        }
                    }
                    if (!foundItem)
                    {
                        this.Children.Add(VisualTreeItem.Construct(child, this));
                    }
                }
            }

            Grid grid = this.Visual as Grid;

            if (grid != null)
            {
                foreach (RowDefinition row in grid.RowDefinitions)
                {
                    this.Children.Add(VisualTreeItem.Construct(row, this));
                }
                foreach (ColumnDefinition column in grid.ColumnDefinitions)
                {
                    this.Children.Add(VisualTreeItem.Construct(column, this));
                }
            }
        }
Exemple #7
0
 protected override bool GetHasChildren()
 {
     return(Visual != null && CommonTreeHelper.GetChildrenCount(Visual) > 0 || Visual is Window);
 }
Exemple #8
0
        private Model3D ConvertVisualToModel3D(Visual visual, ref double z)
        {
            Model3D    model    = null;
            Rect       bounds   = VisualTreeHelper.GetContentBounds(visual);
            Viewport3D viewport = visual as Viewport3D;

            if (viewport != null)
            {
                bounds = new Rect(viewport.RenderSize);
            }
            if (this.includeEmptyVisuals)
            {
                bounds.Union(VisualTreeHelper.GetDescendantBounds(visual));
            }
            if (!bounds.IsEmpty && bounds.Width > 0 && bounds.Height > 0)
            {
                MeshGeometry3D mesh = new MeshGeometry3D();
                mesh.Positions.Add(new Point3D(bounds.Left, bounds.Top, z));
                mesh.Positions.Add(new Point3D(bounds.Right, bounds.Top, z));
                mesh.Positions.Add(new Point3D(bounds.Right, bounds.Bottom, z));
                mesh.Positions.Add(new Point3D(bounds.Left, bounds.Bottom, z));
                mesh.TextureCoordinates.Add(new Point(0, 0));
                mesh.TextureCoordinates.Add(new Point(1, 0));
                mesh.TextureCoordinates.Add(new Point(1, 1));
                mesh.TextureCoordinates.Add(new Point(0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, 1));
                mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 2, 3, 0 });
                mesh.Freeze();

                Brush           brush    = this.MakeBrushFromVisual(visual, bounds);
                DiffuseMaterial material = new DiffuseMaterial(brush);
                material.Freeze();

                model = new GeometryModel3D(mesh, material);
                ((GeometryModel3D)model).BackMaterial = material;

                z -= 1;
            }

            int childrenCount = VisualTreeHelper.GetChildrenCount(visual);

            if (childrenCount > 0)
            {
                Model3DGroup group = new Model3DGroup();
                if (model != null)
                {
                    group.Children.Add(model);
                }
                for (int i = 0; i < childrenCount; i++)
                {
                    Visual childVisual = CommonTreeHelper.GetChild(visual, i) as Visual;
                    if (childVisual != null)
                    {
                        Model3D childModel = this.ConvertVisualToModel3D(childVisual, ref z);
                        if (childModel != null)
                        {
                            group.Children.Add(childModel);
                        }
                    }
                }
                model = group;
            }

            if (model != null)
            {
                Transform transform = VisualTreeHelper.GetTransform(visual);
                Matrix    matrix    = (transform == null ? Matrix.Identity : transform.Value);
                Vector    offset    = VisualTreeHelper.GetOffset(visual);
                matrix.Translate(offset.X, offset.Y);
                if (!matrix.IsIdentity)
                {
                    Matrix3D    matrix3D    = new Matrix3D(matrix.M11, matrix.M12, 0, 0, matrix.M21, matrix.M22, 0, 0, 0, 0, 1, 0, matrix.OffsetX, matrix.OffsetY, 0, 1);
                    Transform3D transform3D = new MatrixTransform3D(matrix3D);
                    transform3D.Freeze();
                    model.Transform = transform3D;
                }
                model.Freeze();
            }

            return(model);
        }