internal void ResolvePeerRelationships(Dictionary <int, DockableCollection> dockableCollections, DockableCollection dockableCollection) { LayoutContext dockableCollectionLayoutContext = DockingPanel.GetLayoutContext(dockableCollection); dockableCollectionLayoutContext.Edges[System.Windows.Controls.Dock.Bottom].PhysicalNeighbors.Clear(); foreach (int internalId in BottomPeers) { DockableCollection peer = dockableCollections[internalId]; LayoutContext peerLayoutContext = DockingPanel.GetLayoutContext(peer); dockableCollectionLayoutContext.Edges[System.Windows.Controls.Dock.Bottom].PhysicalNeighbors.AddLast(peerLayoutContext); } dockableCollectionLayoutContext.Edges[System.Windows.Controls.Dock.Left].PhysicalNeighbors.Clear(); foreach (int internalId in LeftPeers) { DockableCollection peer = dockableCollections[internalId]; LayoutContext peerLayoutContext = DockingPanel.GetLayoutContext(peer); dockableCollectionLayoutContext.Edges[System.Windows.Controls.Dock.Left].PhysicalNeighbors.AddLast(peerLayoutContext); } dockableCollectionLayoutContext.Edges[System.Windows.Controls.Dock.Right].PhysicalNeighbors.Clear(); foreach (int internalId in RightPeers) { DockableCollection peer = dockableCollections[internalId]; LayoutContext peerLayoutContext = DockingPanel.GetLayoutContext(peer); dockableCollectionLayoutContext.Edges[System.Windows.Controls.Dock.Right].PhysicalNeighbors.AddLast(peerLayoutContext); } dockableCollectionLayoutContext.Edges[System.Windows.Controls.Dock.Top].PhysicalNeighbors.Clear(); foreach (int internalId in TopPeers) { DockableCollection peer = dockableCollections[internalId]; LayoutContext peerLayoutContext = DockingPanel.GetLayoutContext(peer); dockableCollectionLayoutContext.Edges[System.Windows.Controls.Dock.Top].PhysicalNeighbors.AddLast(peerLayoutContext); } }
public void InsertToRightOf(DockableCollection visual, DockableCollection reference) { LayoutContext visualContext = GetLayoutContext(visual); LayoutContext referenceContext = GetLayoutContext(reference); referenceContext.InsertToRightOf(visualContext); AdjustPostHorizontalInsertion(visualContext, referenceContext); }
public void InsertBelow(DockableCollection visual, DockableCollection reference) { LayoutContext visualContext = GetLayoutContext(visual); LayoutContext referenceContext = GetLayoutContext(reference); referenceContext.InsertBelow(visualContext); AdjustPostVerticalInsertion(visualContext, referenceContext); }
private void AddChild(DockableCollection visual) { LayoutContext layoutContext = new LayoutContext(this, visual); SetLayoutContext(visual, layoutContext); LayoutContexts.Add(layoutContext); InsertByDockPosition(layoutContext); }
internal DockableCollection Create(Dock dock, DockableContextContentCreator contentCreator) { DockableCollection newCollection = new DockableCollection() { Description = this.Description, HorizontalContentAlignment = this.HorizontalContentAlignment, State = this.State, TabPosition = this.TabPosition, VerticalContentAlignment = this.VerticalContentAlignment, }; DockingPanel.SetDockPosition(newCollection, this.DockPosition); if (newCollection.IsCollapsed) { newCollection.CollapsedTabPosition = this.CollapsedTabPosition; } foreach (DockableContentDescriptor desc in Content) { FrameworkElement content = desc.RestoreDockedLayout(newCollection, contentCreator); if (content != null && desc.InternalId == CurrentTab) { newCollection.SetVisibleContent(content); } } dock.Items.Add(newCollection); if (!newCollection.IsCollapsed) { LayoutContext layoutContext = DockingPanel.GetLayoutContext(newCollection); layoutContext.Left = Left; layoutContext.Top = Top; if (IsHeightSplitterActive) { layoutContext.Size.Height.SetSplitter(LayoutHeight.Value); } else { layoutContext.Size.Height.SetInternalValue(LayoutHeight); } if (IsWidthSplitterActive) { layoutContext.Size.Width.SetSplitter(LayoutWidth.Value); } else { layoutContext.Size.Width.SetInternalValue(LayoutWidth); } layoutContext.Size.Height.SetUserValue(Height.Value); layoutContext.Size.Width.SetUserValue(Width.Value); } return(newCollection); }
public DockableCollectionDescriptor(DockableCollection dockableCollection, DockDescriptor dock, int internalId) { DockableCollection = dockableCollection; Description = dockableCollection.Description; DockPosition = DockingPanel.GetDockPosition(dockableCollection); State = dockableCollection.State; TabPosition = dockableCollection.TabPosition; HorizontalContentAlignment = dockableCollection.HorizontalContentAlignment; VerticalContentAlignment = dockableCollection.VerticalContentAlignment; if (dockableCollection.IsCollapsed) { CollapsedTabPosition = dockableCollection.CollapsedTabPosition; } else { LayoutContext layoutContext = DockingPanel.GetLayoutContext(dockableCollection); Left = layoutContext.Left.Value; Top = layoutContext.Top.Value; LayoutHeight = layoutContext.Size.Height.HasInternalValue ? layoutContext.Size.Height.InternalValue : (double?)null; LayoutWidth = layoutContext.Size.Width.HasInternalValue ? layoutContext.Size.Width.InternalValue : (double?)null; Height = layoutContext.Size.Height.UserValue; Width = layoutContext.Size.Width.UserValue; IsHeightSplitterActive = layoutContext.Size.Height.IsSplitterActive; IsWidthSplitterActive = layoutContext.Size.Width.IsSplitterActive; } BottomPeers = new List <int>(); LeftPeers = new List <int>(); RightPeers = new List <int>(); TopPeers = new List <int>(); Content = new List <DockableContentDescriptor>(); InternalId = internalId; dock.DockedCollections.Add(this); int contentId = 1; foreach (FrameworkElement dockableContent in dockableCollection.Items) { if (dockableCollection.VisibleContent == dockableContent) { CurrentTab = contentId; } new DockableContentDescriptor(dockableContent, this, contentId++); } }
internal void RestoreLayout(Dock dock, DockableContextContentCreator contentCreator) { Dictionary <int, DockableCollection> dockableCollections = new Dictionary <int, DockableCollection>(); if (MajorVersion != MetadataMajorVersion || MinorVersion > MetadataMinorVersion) { throw new InvalidDataException("Saved layout version (" + MajorVersion.ToString() + "." + MinorVersion.ToString() + " is not compatible with the expected version " + MetadataMajorVersion.ToString() + "." + MetadataMinorVersion.ToString()); } // First, create the collections and associate them with the dock foreach (DockableCollectionDescriptor desc in DockedCollections) { DockableCollection newCollection = desc.Create(dock, contentCreator); dockableCollections.Add(desc.InternalId, newCollection); } // Next, resolve their peer associations foreach (DockableCollectionDescriptor desc in DockedCollections) { DockableCollection dockableCollection = dockableCollections[desc.InternalId]; desc.ResolvePeerRelationships(dockableCollections, dockableCollection); } dock.InvalidatePhysical(); if (dock.ActualWidth != DockSize.Width || dock.ActualHeight != DockSize.Height) { dock.InvalidatePositioning(LayoutContext.PositionClasses.EveryCollection | LayoutContext.PositionClasses.All | LayoutContext.PositionClasses.Resize); } foreach (DockDescriptor desc in FloatingDocks) { dock.CreateFloatingDock(desc.Position, desc.DockSize, (DockWindow dockWindow) => { desc.RestoreLayout(dockWindow.Dock, contentCreator); }); } }
internal FrameworkElement RestoreDockedLayout(DockableCollection newCollection, DockableContextContentCreator contentCreator) { FrameworkElement content = null; if (contentCreator != null) { content = contentCreator.Invoke(TypeName, Description); if (content == null) { return(null); } } SetContentColors(content, this.Background, this.Foreground); DockingPanel.SetTabText(content, TabText); DockingPanel.SetDescriptiveText(content, Description); newCollection.Items.Add(content); return(content); }
internal void InsertByLocation(DockableCollection visual, Rect bounds, System.Windows.Controls.Dock defaultPosition) { using (new Activity(this)) { LayoutContext layoutContext = GetLayoutContext(visual); LayoutContext reference = (LayoutContexts[0] == layoutContext ? LayoutContexts[1] : LayoutContexts[0]); // If the dock resized (smaller) and the bounds are outside the dock, position the visual at the right or bottom edge if (bounds.Left >= ActualWidth) { layoutContext.InsertRight(reference); } else if (bounds.Top >= ActualHeight) { layoutContext.InsertBottom(reference); } else { // Find the visual where the new visual's midpoint was double centerX = (bounds.Left + bounds.Right) / 2; double centerY = (bounds.Top + bounds.Bottom) / 2; LayoutContext midpointReference = FindMidPoint(centerX, centerY); if (midpointReference == null) { // The midpoint is outside the dock InsertByDockPosition(layoutContext, defaultPosition); } else { // Position the visual relative to this reference double referenceX = (midpointReference.Left.Value + midpointReference.Right.Value) / 2; double referenceY = (midpointReference.Top.Value + midpointReference.Bottom.Value) / 2; if (Math.Abs(centerX - referenceX) < MinimumChildSize.Width / 2) { if (centerY < referenceY) { midpointReference.InsertAbove(layoutContext); } else { midpointReference.InsertBelow(layoutContext); } } else if (Math.Abs(centerY - referenceY) < MinimumChildSize.Height / 2) { if (centerX < referenceX) { midpointReference.InsertToLeftOf(layoutContext); } else { midpointReference.InsertToRightOf(layoutContext); } } else { midpointReference.InsertBelow(layoutContext); } } } } }
internal void SetLayoutContext(DockableCollection element, LayoutContext layoutContext) { element.SetValue(LayoutContextProperty, layoutContext); }
internal static LayoutContext GetLayoutContext(DockableCollection element) { return((LayoutContext)element.GetValue(LayoutContextProperty)); }
internal static void SetDockableCollection(FrameworkElement element, DockableCollection dockableCollection) { element.SetValue(DockableCollectionProperty, dockableCollection); }