[12503] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows;
|
---|
| 6 | using System.Windows.Controls;
|
---|
| 7 | using System.Windows.Media;
|
---|
| 8 | using System.Collections;
|
---|
| 9 | using Microsoft.Research.DynamicDataDisplay.Charts;
|
---|
| 10 |
|
---|
| 11 | namespace Microsoft.Research.DynamicDataDisplay.Common
|
---|
| 12 | {
|
---|
| 13 | /// <summary>
|
---|
| 14 | /// Collection of UI children of <see cref="IndependentArrangePanel"/>.
|
---|
| 15 | /// </summary>
|
---|
| 16 | internal sealed class UIChildrenCollection : UIElementCollection
|
---|
| 17 | {
|
---|
| 18 | IndividualArrangePanel hostPanel;
|
---|
| 19 |
|
---|
| 20 | /// <summary>
|
---|
| 21 | /// Initializes a new instance of the <see cref="UIChildrenCollection"/> class.
|
---|
| 22 | /// </summary>
|
---|
| 23 | internal UIChildrenCollection(UIElement visualParent, FrameworkElement logicalParent)
|
---|
| 24 | : base(visualParent, logicalParent)
|
---|
| 25 | {
|
---|
| 26 | hostPanel = (IndividualArrangePanel)visualParent;
|
---|
| 27 | visualChildren = new VisualCollection(visualParent);
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | private readonly VisualCollection visualChildren;
|
---|
| 31 | private bool isAddingMany = false;
|
---|
| 32 | public bool IsAddingMany
|
---|
| 33 | {
|
---|
| 34 | get { return isAddingMany; }
|
---|
| 35 | set { isAddingMany = value; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public override int Add(UIElement element)
|
---|
| 39 | {
|
---|
| 40 | if (element == null)
|
---|
| 41 | throw new ArgumentNullException("element");
|
---|
| 42 |
|
---|
| 43 | SetLogicalParent(element);
|
---|
| 44 |
|
---|
| 45 | var index = visualChildren.Add(element);
|
---|
| 46 |
|
---|
| 47 | if (!isAddingMany)
|
---|
| 48 | {
|
---|
| 49 | hostPanel.InvalidateMeasure();
|
---|
| 50 | }
|
---|
| 51 | else
|
---|
| 52 | {
|
---|
| 53 | hostPanel.OnChildAdded((FrameworkElement)element);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | return index;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | public override void Clear()
|
---|
| 60 | {
|
---|
| 61 | if (visualChildren.Count > 0)
|
---|
| 62 | {
|
---|
| 63 | Visual[] visualArray = new Visual[visualChildren.Count];
|
---|
| 64 | for (int i = 0; i < visualChildren.Count; i++)
|
---|
| 65 | {
|
---|
| 66 | visualArray[i] = visualChildren[i];
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | visualChildren.Clear();
|
---|
| 70 |
|
---|
| 71 | for (int i = 0; i < visualArray.Length; i++)
|
---|
| 72 | {
|
---|
| 73 | UIElement element = visualArray[i] as UIElement;
|
---|
| 74 | if (element != null)
|
---|
| 75 | {
|
---|
| 76 | ClearLogicalParent(element);
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | public override bool Contains(UIElement element)
|
---|
| 83 | {
|
---|
| 84 | return visualChildren.Contains(element);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public override void CopyTo(Array array, int index)
|
---|
| 88 | {
|
---|
| 89 | visualChildren.CopyTo(array, index);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public override void CopyTo(UIElement[] array, int index)
|
---|
| 93 | {
|
---|
| 94 | visualChildren.CopyTo(array, index);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | public override IEnumerator GetEnumerator()
|
---|
| 98 | {
|
---|
| 99 | return visualChildren.GetEnumerator();
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | public override int IndexOf(UIElement element)
|
---|
| 103 | {
|
---|
| 104 | return visualChildren.IndexOf(element);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | public override void Insert(int index, UIElement element)
|
---|
| 108 | {
|
---|
| 109 | if (element == null)
|
---|
| 110 | throw new ArgumentNullException("element");
|
---|
| 111 |
|
---|
| 112 | hostPanel.OnChildAdded((FrameworkElement)element);
|
---|
| 113 | SetLogicalParent(element);
|
---|
| 114 | visualChildren.Insert(index, element);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | public override void Remove(UIElement element)
|
---|
| 118 | {
|
---|
| 119 | visualChildren.Remove(element);
|
---|
| 120 | ClearLogicalParent(element);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | public override void RemoveAt(int index)
|
---|
| 124 | {
|
---|
| 125 | UIElement element = visualChildren[index] as UIElement;
|
---|
| 126 | visualChildren.RemoveAt(index);
|
---|
| 127 | if (element != null)
|
---|
| 128 | {
|
---|
| 129 | ClearLogicalParent(element);
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | public override void RemoveRange(int index, int count)
|
---|
| 134 | {
|
---|
| 135 | int actualCount = visualChildren.Count;
|
---|
| 136 | if (count > (actualCount - index))
|
---|
| 137 | {
|
---|
| 138 | count = actualCount - index;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | if (count > 0)
|
---|
| 142 | {
|
---|
| 143 | Visual[] visualArray = new Visual[count];
|
---|
| 144 | int copyIndex = index;
|
---|
| 145 | for (int i = 0; i < count; i++)
|
---|
| 146 | {
|
---|
| 147 | visualArray[i] = visualChildren[copyIndex];
|
---|
| 148 | copyIndex++;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | visualChildren.RemoveRange(index, count);
|
---|
| 152 |
|
---|
| 153 | for (int i = 0; i < count; i++)
|
---|
| 154 | {
|
---|
| 155 | UIElement element = visualArray[i] as UIElement;
|
---|
| 156 | if (element != null)
|
---|
| 157 | {
|
---|
| 158 | ClearLogicalParent(element);
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | public override UIElement this[int index]
|
---|
| 165 | {
|
---|
| 166 | get
|
---|
| 167 | {
|
---|
| 168 | return visualChildren[index] as UIElement;
|
---|
| 169 | }
|
---|
| 170 | set
|
---|
| 171 | {
|
---|
| 172 | if (value == null)
|
---|
| 173 | throw new ArgumentNullException("value");
|
---|
| 174 |
|
---|
| 175 | if (visualChildren[index] != value)
|
---|
| 176 | {
|
---|
| 177 | UIElement element = visualChildren[index] as UIElement;
|
---|
| 178 | if (element != null)
|
---|
| 179 | {
|
---|
| 180 | ClearLogicalParent(element);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | hostPanel.OnChildAdded((FrameworkElement)value);
|
---|
| 184 | visualChildren[index] = value;
|
---|
| 185 | SetLogicalParent(value);
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | public override int Capacity
|
---|
| 191 | {
|
---|
| 192 | get { return visualChildren.Capacity; }
|
---|
| 193 | set { visualChildren.Capacity = value; }
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | public override int Count
|
---|
| 197 | {
|
---|
| 198 | get { return visualChildren.Count; }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | public override bool IsSynchronized
|
---|
| 202 | {
|
---|
| 203 | get { return visualChildren.IsSynchronized; }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | public override object SyncRoot
|
---|
| 207 | {
|
---|
| 208 | get { return visualChildren.SyncRoot; }
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 | }
|
---|