Exemplo n.º 1
0
        public VisualTreeItem FindNode(object target)
        {
            // it might be faster to have a map for the lookup
            // check into this at some point
            if (this.Target == target)
            {
                if (DXMethods.IsChrome(Target) && target is IInputElement)
                {
                    var root = DXMethods.GetRoot(Target);
                    if (root != null)
                    {
                        var child = RenderTreeHelper.HitTest(root, System.Windows.Input.Mouse.GetPosition((IInputElement)target));
                        var node  = FindNode(child);
                        if (node != null)
                        {
                            return(node);
                        }
                    }
                }
                return(this);
            }

            foreach (VisualTreeItem child in this.Children)
            {
                VisualTreeItem node = child.FindNode(target);
                if (node != null)
                {
                    return(node);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
 public static object GetChild(object source, int index)
 {
     if (DXMethods.IsChrome(source))
     {
         return(DXMethods.GetRoot(source));
     }
     if (DXMethods.IsIFrameworkRenderElementContext(source))
     {
         var control = DXMethods.Is(source, "RenderControlBaseContext", "DevExpress.Xpf.Core.Native", false) ? ((dynamic)source).Control : null;
         var rcc     = DXMethods.RenderChildrenCount(source);
         if (index >= rcc)
         {
             if (index == rcc && control != null)
             {
                 return(control);
             }
             return(null);
         }
         return(DXMethods.GetRenderChild(source, index));
     }
     if (source is Visual)
     {
         return(VisualTreeHelper.GetChild((Visual)source, index));
     }
     return(null);
 }
Exemplo n.º 3
0
        public static VisualTreeItem Construct(object target, VisualTreeItem parent)
        {
            VisualTreeItem visualTreeItem;

            if (DXMethods.IsFrameworkRenderElementContext(target))
            {
                visualTreeItem = new VisualItem(target, parent);
            }
            else if (target is Visual)
            {
                visualTreeItem = new VisualItem((Visual)target, parent);
            }
            else if (target is ResourceDictionary)
            {
                visualTreeItem = new ResourceDictionaryItem((ResourceDictionary)target, parent);
            }
            else if (target is Application)
            {
                visualTreeItem = new ApplicationTreeItem((Application)target, parent);
            }
            else
            {
                visualTreeItem = new VisualTreeItem(target, parent);
            }

            visualTreeItem.Reload();

            return(visualTreeItem);
        }
Exemplo n.º 4
0
 private void HandleTargetOrIsActiveChanged()
 {
     if (this.IsActive && (this.Target is Visual || DXMethods.IsFrameworkRenderElementContext(this.Target)))
     {
         this.Zoomer.Target = this.Target;
     }
     else
     {
         Brush pooSniffer = (Brush)this.FindResource("previewerSnoopDogDrawingBrush");
         this.Zoomer.Target = pooSniffer;
     }
 }
Exemplo n.º 5
0
 public static object HitTest(object root, Point point)
 {
     if (hitTest == null)
     {
         hitTest = ReflectionHelper.CreateInstanceMethodHandler <Func <object, object, object> >(
             null,
             "HitTest",
             BindingFlags.Public | BindingFlags.Static,
             DXMethods.GetCoreAssembly(root).GetType("DevExpress.Xpf.Core.Native.RenderTreeHelper"),
             true, typeof(object), null, 2
             );
     }
     return(hitTest(root, point));
 }
Exemplo n.º 6
0
 public static IEnumerable <object> RenderAncestors(object context)
 {
     if (renderAncestors == null)
     {
         renderAncestors = ReflectionHelper.CreateInstanceMethodHandler <Func <object, IEnumerable> >(
             null,
             "RenderAncestors",
             BindingFlags.Public | BindingFlags.Static,
             DXMethods.GetCoreAssembly(context).GetType("DevExpress.Xpf.Core.Native.RenderTreeHelper"),
             true, typeof(IEnumerable), null
             );
     }
     return(renderAncestors(context).OfType <object>());
 }
Exemplo n.º 7
0
 public static Transform TransformToRoot(object frec)
 {
     if (transformToRoot == null)
     {
         transformToRoot = ReflectionHelper.CreateInstanceMethodHandler <Func <object, Transform> >(
             null,
             "TransformToRoot",
             BindingFlags.Public | BindingFlags.Static,
             DXMethods.GetCoreAssembly(frec).GetType("DevExpress.Xpf.Core.Native.RenderTreeHelper"),
             true, typeof(Transform), null
             );
     }
     return(transformToRoot(frec));
 }
Exemplo n.º 8
0
 public static bool IsDescendantOf(object visual, object rootVisual)
 {
     if (visual is Visual && rootVisual is Visual)
     {
         return(((Visual)visual).IsDescendantOf((Visual)rootVisual));
     }
     if (DXMethods.IsFrameworkRenderElementContext(visual) && DXMethods.IsFrameworkRenderElementContext(rootVisual))
     {
         return(RenderTreeHelper.RenderAncestors((visual)).Any(x => x == rootVisual));
     }
     if (DXMethods.IsFrameworkRenderElementContext(visual) && rootVisual is Visual)
     {
         return(DXMethods.GetParent(((dynamic)visual).ElementHost).Parent.IsDescendantOf((Visual)rootVisual));
     }
     return(false);
 }
Exemplo n.º 9
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;
                }
            }
        }
Exemplo n.º 10
0
 public FREDrawingVisual(object context)
 {
     this.context = context;
     using (var dc = this.RenderOpen()) {
         DXMethods.Render(((dynamic)context).Factory, dc, context);
         var controls = new object[] { context }.Concat(RenderTreeHelper.RenderDescendants(context));
         foreach (object ctrl in controls)
         {
             if (!DXMethods.Is(ctrl, "RenderControlBaseContext", null, false))
             {
                 continue;
             }
             var dctrl = ((dynamic)ctrl);
             dc.PushTransform((dctrl).GeneralTransform);
             dc.DrawRectangle(new VisualBrush((dctrl).Control), null, new Rect(new Point(0, 0), (dctrl).RenderSize));
             dc.Pop();
         }
         dc.Close();
     }
 }
Exemplo n.º 11
0
 public static int GetChildrenCount(object source)
 {
     if (DXMethods.IsChrome(source))
     {
         object root = DXMethods.GetRoot(source);
         if (root != null)
         {
             return(1);
         }
     }
     if (DXMethods.IsIFrameworkRenderElementContext(source))
     {
         int hasControl = DXMethods.Is(source, "RenderControlBaseContext", "DevExpress.Xpf.Core.Native", false) && ((dynamic)source).Control != null ? 1 : 0;
         return(DXMethods.RenderChildrenCount(source) + hasControl);
     }
     if (source is Visual)
     {
         return(VisualTreeHelper.GetChildrenCount((Visual)source));
     }
     return(0);
 }
Exemplo n.º 12
0
 private void HandleCanMagnify(object sender, CanExecuteRoutedEventArgs e)
 {
     e.CanExecute = (this.Target as Visual) != null || DXMethods.IsFrameworkRenderElementContext(this.Target);
     e.Handled    = true;
 }