Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.7.0/WinFormsUI-2.7.0/Docking/NestedPaneCollection.cs @ 17197

Last change on this file since 17197 was 8616, checked in by mkommend, 12 years ago

#1939: Added DockPanelSuite 2.7.0 to ExtLibs.

File size: 5.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Collections.ObjectModel;
4using System.Drawing;
5
6namespace WeifenLuo.WinFormsUI.Docking
7{
8  public sealed class NestedPaneCollection : ReadOnlyCollection<DockPane>
9  {
10    private INestedPanesContainer m_container;
11    private VisibleNestedPaneCollection m_visibleNestedPanes;
12
13    internal NestedPaneCollection(INestedPanesContainer container)
14            : base(new List<DockPane>())
15    {
16      m_container = container;
17      m_visibleNestedPanes = new VisibleNestedPaneCollection(this);
18    }
19
20    public INestedPanesContainer Container
21    {
22      get { return m_container; }
23    }
24   
25    public VisibleNestedPaneCollection VisibleNestedPanes
26    {
27      get { return m_visibleNestedPanes;  }
28    }
29
30    public DockState DockState
31    {
32      get { return Container.DockState; }
33    }
34
35    public bool IsFloat
36    {
37      get { return DockState == DockState.Float;  }
38    }
39
40    internal void Add(DockPane pane)
41    {
42      if (pane == null)
43        return;
44
45      NestedPaneCollection oldNestedPanes = (pane.NestedPanesContainer == null) ? null : pane.NestedPanesContainer.NestedPanes;
46      if (oldNestedPanes != null)
47        oldNestedPanes.InternalRemove(pane);
48      Items.Add(pane);
49      if (oldNestedPanes != null)
50        oldNestedPanes.CheckFloatWindowDispose();
51    }
52
53    private void CheckFloatWindowDispose()
54    {
55      if (Count == 0 && Container.DockState == DockState.Float)
56      {
57        FloatWindow floatWindow = (FloatWindow)Container;
58        if (!floatWindow.Disposing && !floatWindow.IsDisposed)
59                                        if (!Win32Helper.IsRunningOnMono)
60          NativeMethods.PostMessage(((FloatWindow)Container).Handle, FloatWindow.WM_CHECKDISPOSE, 0, 0);
61      }
62    }
63
64        /// <summary>
65        /// Switches a pane with its first child in the pane hierarchy. (The actual hiding happens elsewhere.)
66        /// </summary>
67        /// <param name="pane">Pane to switch</param>
68        internal void SwitchPaneWithFirstChild(DockPane pane)
69        {
70            if (!Contains(pane))
71                return;
72
73            NestedDockingStatus statusPane = pane.NestedDockingStatus;
74            DockPane lastNestedPane = null;
75            for (int i = Count - 1; i > IndexOf(pane); i--)
76            {
77                if (this[i].NestedDockingStatus.PreviousPane == pane)
78                {
79                    lastNestedPane = this[i];
80                    break;
81                }
82            }
83
84            if (lastNestedPane != null)
85            {
86                int indexLastNestedPane = IndexOf(lastNestedPane);
87                Items[IndexOf(pane)] = lastNestedPane;
88                Items[indexLastNestedPane] = pane;
89                NestedDockingStatus lastNestedDock = lastNestedPane.NestedDockingStatus;
90
91                DockAlignment newAlignment;
92                if (lastNestedDock.Alignment == DockAlignment.Left)
93                    newAlignment = DockAlignment.Right;
94                else if (lastNestedDock.Alignment == DockAlignment.Right)
95                    newAlignment = DockAlignment.Left;
96                else if (lastNestedDock.Alignment == DockAlignment.Top)
97                    newAlignment = DockAlignment.Bottom;
98                else
99                    newAlignment = DockAlignment.Top;
100                double newProportion = 1 - lastNestedDock.Proportion;
101
102                lastNestedDock.SetStatus(this, statusPane.PreviousPane, statusPane.Alignment, statusPane.Proportion);
103                for (int i = indexLastNestedPane - 1; i > IndexOf(lastNestedPane); i--)
104                {
105                    NestedDockingStatus status = this[i].NestedDockingStatus;
106                    if (status.PreviousPane == pane)
107                        status.SetStatus(this, lastNestedPane, status.Alignment, status.Proportion);
108                }
109
110                statusPane.SetStatus(this, lastNestedPane, newAlignment, newProportion);
111            }
112        }
113
114    internal void Remove(DockPane pane)
115    {
116      InternalRemove(pane);
117      CheckFloatWindowDispose();
118    }
119
120    private void InternalRemove(DockPane pane)
121    {
122      if (!Contains(pane))
123        return;
124
125      NestedDockingStatus statusPane = pane.NestedDockingStatus;
126      DockPane lastNestedPane = null;
127      for (int i=Count - 1; i> IndexOf(pane); i--)
128      {
129        if (this[i].NestedDockingStatus.PreviousPane == pane)
130        {
131          lastNestedPane = this[i];
132          break;
133        }
134      }
135
136      if (lastNestedPane != null)
137      {
138        int indexLastNestedPane = IndexOf(lastNestedPane);
139        Items.Remove(lastNestedPane);
140        Items[IndexOf(pane)] = lastNestedPane;
141        NestedDockingStatus lastNestedDock = lastNestedPane.NestedDockingStatus;
142        lastNestedDock.SetStatus(this, statusPane.PreviousPane, statusPane.Alignment, statusPane.Proportion);
143        for (int i=indexLastNestedPane - 1; i>IndexOf(lastNestedPane); i--)
144        {
145          NestedDockingStatus status = this[i].NestedDockingStatus;
146          if (status.PreviousPane == pane)
147            status.SetStatus(this, lastNestedPane, status.Alignment, status.Proportion);
148        }
149      }
150      else
151        Items.Remove(pane);
152
153      statusPane.SetStatus(null, null, DockAlignment.Left, 0.5);
154      statusPane.SetDisplayingStatus(false, null, DockAlignment.Left, 0.5);
155      statusPane.SetDisplayingBounds(Rectangle.Empty, Rectangle.Empty, Rectangle.Empty);
156    }
157
158    public DockPane GetDefaultPreviousPane(DockPane pane)
159    {
160      for (int i=Count-1; i>=0; i--)
161        if (this[i] != pane)
162          return this[i];
163
164      return null;
165    }
166  }
167}
Note: See TracBrowser for help on using the repository browser.