/// <summary> /// Propagates the flags up to the root. /// </summary> /// <remarks> /// The walk stops on a node with all of the required flags set. /// </remarks> internal static void PropagateFlags( Visual e, VisualFlags flags, VisualProxyFlags proxyFlags) { while ((e != null) && (!e.CheckFlagsAnd(flags) || !e.CheckFlagsOnAllChannels(proxyFlags))) { if (e.CheckFlagsOr(VisualFlags.ShouldPostRender)) { MediaContext mctx = MediaContext.From(e.Dispatcher); if (mctx.Channel != null) { mctx.PostRender(); } } else if (e.CheckFlagsAnd(VisualFlags.NodeIsCyclicBrushRoot)) { // // For visuals that are root nodes in visual brushes we // need to fire OnChanged on the owning brushes. // Dictionary<ICyclicBrush, int> cyclicBrushToChannelsMap = CyclicBrushToChannelsMapField.GetValue(e); Debug.Assert(cyclicBrushToChannelsMap != null, "Visual brush roots need to have the visual brush to channels map!"); // // Iterate over the visual brushes and fire the OnChanged event. // foreach (ICyclicBrush cyclicBrush in cyclicBrushToChannelsMap.Keys) { cyclicBrush.FireOnChanged(); } } e.SetFlags(true, flags); e.SetFlagsOnAllChannels(true, proxyFlags); if (e._parent == null) { // Stop propagating. We are at the root of the 2D subtree. return; } Visual parentAsVisual = e._parent as Visual; if (parentAsVisual == null) { // if the parent is not null (saw this with earlier null check) and is not a Visual // it must be a Visual3D - continue the propagation Visual3D.PropagateFlags((Visual3D)e._parent, flags, proxyFlags); return; } e = parentAsVisual; } }
/// <summary> /// Recursively resets IsLayoutSuspended flag on all visuals of the whole v's sub tree. /// For UIElements also re-inserts the UIElement into Measure and / or Arrange update queues /// if necessary. /// </summary> internal static void PropagateResumeLayout(Visual parent, Visual v) { if(v.CheckFlagsAnd(VisualFlags.IsLayoutIslandRoot)) return; //the subtree is already active - happens when new elements are added to the active tree //elements are created layout-active so they don't need to be specifically unsuspended //no need to walk down in this case //if(!v.CheckFlagsAnd(VisualFlags.IsLayoutSuspended)) return; //that can be true only on top of recursion, if suspended v is being connected to suspended parent. bool parentIsSuspended = parent == null ? false : parent.CheckFlagsAnd(VisualFlags.IsLayoutSuspended); uint parentTreeLevel = parent == null ? 0 : parent.TreeLevel; if(parentIsSuspended) return; v.SetFlags(false, VisualFlags.IsLayoutSuspended); v.TreeLevel = parentTreeLevel + 1; if (v.CheckFlagsAnd(VisualFlags.IsUIElement)) { // re-insert UIElement into the update queues UIElement e = (UIElement)v; Invariant.Assert(!e.MeasureInProgress && !e.ArrangeInProgress); bool requireMeasureUpdate = e.MeasureDirty && !e.NeverMeasured && (e.MeasureRequest == null); bool requireArrangeUpdate = e.ArrangeDirty && !e.NeverArranged && (e.ArrangeRequest == null); ContextLayoutManager contextLayoutManager = (requireMeasureUpdate || requireArrangeUpdate) ? ContextLayoutManager.From(e.Dispatcher) : null; if (requireMeasureUpdate) { contextLayoutManager.MeasureQueue.Add(e); } if (requireArrangeUpdate) { contextLayoutManager.ArrangeQueue.Add(e); } } int count = v.InternalVisualChildrenCount; for (int i = 0; i < count; i++) { Visual cv = v.InternalGetVisualChild(i); if (cv != null) { PropagateResumeLayout(v, cv); } } }
/// <summary> /// DisconnectChild /// /// Derived classes must call this method to notify the Visual layer that a /// child was removed from the children collection. The Visual layer will then call /// GetChildren to find out which child has been removed. /// /// </summary> protected void RemoveVisualChild(Visual child) { if (child == null || child._parent == null) { return; } if (child._parent != this) { throw new ArgumentException(SR.Get(SRID.Visual_NotChild)); } if(InternalVisual2DOr3DChildrenCount == 0) { SetFlags(false, VisualFlags.HasChildren); } // // Remove the child on all channels its current parent is marshalled to. // for (int i = 0; i < _proxy.Count; i++) { DUCE.Channel channel = _proxy.GetChannel(i); if (child.CheckFlagsAnd(channel, VisualProxyFlags.IsConnectedToParent)) { child.SetFlags(channel, false, VisualProxyFlags.IsConnectedToParent); DUCE.IResource childResource = (DUCE.IResource)child; childResource.RemoveChildFromParent(this, channel); childResource.ReleaseOnChannel(channel); } } // Set the parent pointer to null. child._parent = null; Visual.PropagateFlags( this, VisualFlags.IsSubtreeDirtyForPrecompute, VisualProxyFlags.IsSubtreeDirtyForRender); UIElement.PropagateSuspendLayout(child); // Fire notifications child.FireOnVisualParentChanged(this); OnVisualChildrenChanged(null /* no child added */, child); }
/// <summary> /// Recursively propagates IsLayoutSuspended flag down to the whole v's sub tree. /// </summary> internal static void PropagateSuspendLayout(Visual v) { if(v.CheckFlagsAnd(VisualFlags.IsLayoutIslandRoot)) return; //the subtree is already suspended - happens when already suspended tree is further disassembled //no need to walk down in this case if(v.CheckFlagsAnd(VisualFlags.IsLayoutSuspended)) return; // (bug # 1623922) assert that a UIElement has not being // removed from the visual tree while updating layout. if ( Invariant.Strict && v.CheckFlagsAnd(VisualFlags.IsUIElement) ) { UIElement e = (UIElement)v; Invariant.Assert(!e.MeasureInProgress && !e.ArrangeInProgress); } v.SetFlags(true, VisualFlags.IsLayoutSuspended); v.TreeLevel = 0; int count = v.InternalVisualChildrenCount; for (int i = 0; i < count; i++) { Visual cv = v.InternalGetVisualChild(i); if (cv != null) { PropagateSuspendLayout(cv); } } }