[12503] | 1 | using System.Linq;
|
---|
| 2 | using System.Windows;
|
---|
| 3 | using Microsoft.Research.DynamicDataDisplay;
|
---|
| 4 | using Microsoft.Research.DynamicDataDisplay.Common;
|
---|
| 5 | using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
|
---|
| 6 | using System;
|
---|
| 7 | using System.Collections.Specialized;
|
---|
| 8 |
|
---|
| 9 | namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints
|
---|
| 10 | {
|
---|
| 11 | /// <summary>
|
---|
| 12 | /// Represents a collection of <see cref="ViewportConstraint"/>s.
|
---|
| 13 | /// <remarks>
|
---|
| 14 | /// ViewportConstraint that is being added should not be null.
|
---|
| 15 | /// </remarks>
|
---|
| 16 | /// </summary>
|
---|
| 17 | public sealed class ConstraintCollection : D3Collection<ViewportConstraint>
|
---|
| 18 | {
|
---|
| 19 | private readonly Viewport2D viewport;
|
---|
| 20 | internal ConstraintCollection(Viewport2D viewport)
|
---|
| 21 | {
|
---|
| 22 | if (viewport == null)
|
---|
| 23 | throw new ArgumentNullException("viewport");
|
---|
| 24 |
|
---|
| 25 | this.viewport = viewport;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | protected override void OnItemAdding(ViewportConstraint item)
|
---|
| 29 | {
|
---|
| 30 | if (item == null)
|
---|
| 31 | throw new ArgumentNullException("item");
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | protected override void OnItemAdded(ViewportConstraint item)
|
---|
| 35 | {
|
---|
| 36 | item.Changed += OnItemChanged;
|
---|
| 37 | ISupportAttachToViewport attachable = item as ISupportAttachToViewport;
|
---|
| 38 | if (attachable != null)
|
---|
| 39 | {
|
---|
| 40 | attachable.Attach(viewport);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | private void OnItemChanged(object sender, EventArgs e)
|
---|
| 45 | {
|
---|
| 46 | OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | protected override void OnItemRemoving(ViewportConstraint item)
|
---|
| 50 | {
|
---|
| 51 | ISupportAttachToViewport attachable = item as ISupportAttachToViewport;
|
---|
| 52 | if (attachable != null)
|
---|
| 53 | {
|
---|
| 54 | attachable.Detach(viewport);
|
---|
| 55 | }
|
---|
| 56 | item.Changed -= OnItemChanged;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | internal DataRect Apply(DataRect oldVisible, DataRect newVisible, Viewport2D viewport)
|
---|
| 60 | {
|
---|
| 61 | DataRect res = newVisible;
|
---|
| 62 | foreach (var constraint in this)
|
---|
| 63 | {
|
---|
| 64 | res = constraint.Apply(oldVisible, res, viewport);
|
---|
| 65 | }
|
---|
| 66 | return res;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|