Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/VisibleNestedPaneCollection.cs @ 5405

Last change on this file since 5405 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 5.8 KB
Line 
1using System.Collections.Generic;
2using System.Collections.ObjectModel;
3using System.Drawing;
4
5namespace WeifenLuo.WinFormsUI.Docking {
6  public sealed class VisibleNestedPaneCollection : ReadOnlyCollection<DockPane> {
7    private NestedPaneCollection m_nestedPanes;
8
9    internal VisibleNestedPaneCollection(NestedPaneCollection nestedPanes)
10      : base(new List<DockPane>()) {
11      m_nestedPanes = nestedPanes;
12    }
13
14    public NestedPaneCollection NestedPanes {
15      get { return m_nestedPanes; }
16    }
17
18    public INestedPanesContainer Container {
19      get { return NestedPanes.Container; }
20    }
21
22    public DockState DockState {
23      get { return NestedPanes.DockState; }
24    }
25
26    public bool IsFloat {
27      get { return NestedPanes.IsFloat; }
28    }
29
30    internal void Refresh() {
31      Items.Clear();
32      for (int i = 0; i < NestedPanes.Count; i++) {
33        DockPane pane = NestedPanes[i];
34        NestedDockingStatus status = pane.NestedDockingStatus;
35        status.SetDisplayingStatus(true, status.PreviousPane, status.Alignment, status.Proportion);
36        Items.Add(pane);
37      }
38
39      foreach (DockPane pane in NestedPanes)
40        if (pane.DockState != DockState || pane.IsHidden) {
41          pane.Bounds = Rectangle.Empty;
42          pane.SplitterBounds = Rectangle.Empty;
43          Remove(pane);
44        }
45
46      CalculateBounds();
47
48      foreach (DockPane pane in this) {
49        NestedDockingStatus status = pane.NestedDockingStatus;
50        pane.Bounds = status.PaneBounds;
51        pane.SplitterBounds = status.SplitterBounds;
52        pane.SplitterAlignment = status.Alignment;
53      }
54    }
55
56    private void Remove(DockPane pane) {
57      if (!Contains(pane))
58        return;
59
60      NestedDockingStatus statusPane = pane.NestedDockingStatus;
61      DockPane lastNestedPane = null;
62      for (int i = Count - 1; i > IndexOf(pane); i--) {
63        if (this[i].NestedDockingStatus.PreviousPane == pane) {
64          lastNestedPane = this[i];
65          break;
66        }
67      }
68
69      if (lastNestedPane != null) {
70        int indexLastNestedPane = IndexOf(lastNestedPane);
71        Items.Remove(lastNestedPane);
72        Items[IndexOf(pane)] = lastNestedPane;
73        NestedDockingStatus lastNestedDock = lastNestedPane.NestedDockingStatus;
74        lastNestedDock.SetDisplayingStatus(true, statusPane.DisplayingPreviousPane, statusPane.DisplayingAlignment, statusPane.DisplayingProportion);
75        for (int i = indexLastNestedPane - 1; i > IndexOf(lastNestedPane); i--) {
76          NestedDockingStatus status = this[i].NestedDockingStatus;
77          if (status.PreviousPane == pane)
78            status.SetDisplayingStatus(true, lastNestedPane, status.DisplayingAlignment, status.DisplayingProportion);
79        }
80      } else
81        Items.Remove(pane);
82
83      statusPane.SetDisplayingStatus(false, null, DockAlignment.Left, 0.5);
84    }
85
86    private void CalculateBounds() {
87      if (Count == 0)
88        return;
89
90      this[0].NestedDockingStatus.SetDisplayingBounds(Container.DisplayingRectangle, Container.DisplayingRectangle, Rectangle.Empty);
91
92      for (int i = 1; i < Count; i++) {
93        DockPane pane = this[i];
94        NestedDockingStatus status = pane.NestedDockingStatus;
95        DockPane prevPane = status.DisplayingPreviousPane;
96        NestedDockingStatus statusPrev = prevPane.NestedDockingStatus;
97
98        Rectangle rect = statusPrev.PaneBounds;
99        bool bVerticalSplitter = (status.DisplayingAlignment == DockAlignment.Left || status.DisplayingAlignment == DockAlignment.Right);
100
101        Rectangle rectThis = rect;
102        Rectangle rectPrev = rect;
103        Rectangle rectSplitter = rect;
104        if (status.DisplayingAlignment == DockAlignment.Left) {
105          rectThis.Width = (int)((double)rect.Width * status.DisplayingProportion) - (Measures.SplitterSize / 2);
106          rectSplitter.X = rectThis.X + rectThis.Width;
107          rectSplitter.Width = Measures.SplitterSize;
108          rectPrev.X = rectSplitter.X + rectSplitter.Width;
109          rectPrev.Width = rect.Width - rectThis.Width - rectSplitter.Width;
110        } else if (status.DisplayingAlignment == DockAlignment.Right) {
111          rectPrev.Width = (rect.Width - (int)((double)rect.Width * status.DisplayingProportion)) - (Measures.SplitterSize / 2);
112          rectSplitter.X = rectPrev.X + rectPrev.Width;
113          rectSplitter.Width = Measures.SplitterSize;
114          rectThis.X = rectSplitter.X + rectSplitter.Width;
115          rectThis.Width = rect.Width - rectPrev.Width - rectSplitter.Width;
116        } else if (status.DisplayingAlignment == DockAlignment.Top) {
117          rectThis.Height = (int)((double)rect.Height * status.DisplayingProportion) - (Measures.SplitterSize / 2);
118          rectSplitter.Y = rectThis.Y + rectThis.Height;
119          rectSplitter.Height = Measures.SplitterSize;
120          rectPrev.Y = rectSplitter.Y + rectSplitter.Height;
121          rectPrev.Height = rect.Height - rectThis.Height - rectSplitter.Height;
122        } else if (status.DisplayingAlignment == DockAlignment.Bottom) {
123          rectPrev.Height = (rect.Height - (int)((double)rect.Height * status.DisplayingProportion)) - (Measures.SplitterSize / 2);
124          rectSplitter.Y = rectPrev.Y + rectPrev.Height;
125          rectSplitter.Height = Measures.SplitterSize;
126          rectThis.Y = rectSplitter.Y + rectSplitter.Height;
127          rectThis.Height = rect.Height - rectPrev.Height - rectSplitter.Height;
128        } else
129          rectThis = Rectangle.Empty;
130
131        rectSplitter.Intersect(rect);
132        rectThis.Intersect(rect);
133        rectPrev.Intersect(rect);
134        status.SetDisplayingBounds(rect, rectThis, rectSplitter);
135        statusPrev.SetDisplayingBounds(statusPrev.LogicalBounds, rectPrev, statusPrev.SplitterBounds);
136      }
137    }
138  }
139}
Note: See TracBrowser for help on using the repository browser.