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