File size: 5,444 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 |
using System.Drawing;
using System.Windows.Forms;
namespace WeifenLuo.WinFormsUI.Docking
{
partial class DockPane
{
internal class DefaultSplitterControl : SplitterControlBase
{
public DefaultSplitterControl(DockPane pane) : base(pane)
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (DockPane.DockState != DockState.Document)
return;
Graphics g = e.Graphics;
Rectangle rect = ClientRectangle;
if (Alignment == DockAlignment.Top || Alignment == DockAlignment.Bottom)
g.DrawLine(SystemPens.ControlDark, rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1);
else if (Alignment == DockAlignment.Left || Alignment == DockAlignment.Right)
g.DrawLine(SystemPens.ControlDarkDark, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom);
}
}
public class SplitterControlBase : Control, ISplitterDragSource
{
DockPane m_pane;
public SplitterControlBase(DockPane pane)
{
SetStyle(ControlStyles.Selectable, false);
m_pane = pane;
}
public DockPane DockPane
{
get { return m_pane; }
}
private DockAlignment m_alignment;
public DockAlignment Alignment
{
get { return m_alignment; }
set
{
m_alignment = value;
if (m_alignment == DockAlignment.Left || m_alignment == DockAlignment.Right)
Cursor = Cursors.VSplit;
else if (m_alignment == DockAlignment.Top || m_alignment == DockAlignment.Bottom)
Cursor = Cursors.HSplit;
else
Cursor = Cursors.Default;
if (DockPane.DockState == DockState.Document)
Invalidate();
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button != MouseButtons.Left)
return;
DockPane.DockPanel.BeginDrag(this, Parent.RectangleToScreen(Bounds));
}
#region ISplitterDragSource Members
void ISplitterDragSource.BeginDrag(Rectangle rectSplitter)
{
}
void ISplitterDragSource.EndDrag()
{
}
bool ISplitterDragSource.IsVertical
{
get
{
NestedDockingStatus status = DockPane.NestedDockingStatus;
return (status.DisplayingAlignment == DockAlignment.Left ||
status.DisplayingAlignment == DockAlignment.Right);
}
}
Rectangle ISplitterDragSource.DragLimitBounds
{
get
{
NestedDockingStatus status = DockPane.NestedDockingStatus;
Rectangle rectLimit = Parent.RectangleToScreen(status.LogicalBounds);
if (((ISplitterDragSource)this).IsVertical)
{
rectLimit.X += MeasurePane.MinSize;
rectLimit.Width -= 2 * MeasurePane.MinSize;
}
else
{
rectLimit.Y += MeasurePane.MinSize;
rectLimit.Height -= 2 * MeasurePane.MinSize;
}
return rectLimit;
}
}
void ISplitterDragSource.MoveSplitter(int offset)
{
NestedDockingStatus status = DockPane.NestedDockingStatus;
double proportion = status.Proportion;
if (status.LogicalBounds.Width <= 0 || status.LogicalBounds.Height <= 0)
return;
else if (status.DisplayingAlignment == DockAlignment.Left)
proportion += ((double)offset) / (double)status.LogicalBounds.Width;
else if (status.DisplayingAlignment == DockAlignment.Right)
proportion -= ((double)offset) / (double)status.LogicalBounds.Width;
else if (status.DisplayingAlignment == DockAlignment.Top)
proportion += ((double)offset) / (double)status.LogicalBounds.Height;
else
proportion -= ((double)offset) / (double)status.LogicalBounds.Height;
DockPane.SetNestedDockingProportion(proportion);
}
#region IDragSource Members
Control IDragSource.DragControl
{
get { return this; }
}
#endregion
#endregion
}
private SplitterControlBase m_splitter;
private SplitterControlBase Splitter
{
get { return m_splitter; }
}
internal Rectangle SplitterBounds
{
set { Splitter.Bounds = value; }
}
internal DockAlignment SplitterAlignment
{
set { Splitter.Alignment = value; }
}
}
} |