Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/WinFormsUI/Docking/VisibleNestedPaneCollection.cs @ 2594

Last change on this file since 2594 was 2134, checked in by gkronber, 15 years ago

Added up to date source of Weifen Luo dock panel suit in a separate project (and added strong name key). Removed binary versions of Weifen Luo dock panel suite and references to it. #687 (Update AdvancedOptimizationFrontend to use more recent version of Weifen Luo Docking library)

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