[2134] | 1 | using System;
|
---|
| 2 | using System.Collections;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Windows.Forms;
|
---|
| 6 |
|
---|
| 7 | namespace WeifenLuo.WinFormsUI.Docking
|
---|
| 8 | {
|
---|
| 9 | partial class DockPane
|
---|
| 10 | {
|
---|
| 11 | private class SplitterControl : Control, ISplitterDragSource
|
---|
| 12 | {
|
---|
| 13 | DockPane m_pane;
|
---|
| 14 |
|
---|
| 15 | public SplitterControl(DockPane pane)
|
---|
| 16 | {
|
---|
| 17 | SetStyle(ControlStyles.Selectable, false);
|
---|
| 18 | m_pane = pane;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | public DockPane DockPane
|
---|
| 22 | {
|
---|
| 23 | get { return m_pane; }
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | private DockAlignment m_alignment;
|
---|
| 27 | public DockAlignment Alignment
|
---|
| 28 | {
|
---|
| 29 | get { return m_alignment; }
|
---|
| 30 | set
|
---|
| 31 | {
|
---|
| 32 | m_alignment = value;
|
---|
| 33 | if (m_alignment == DockAlignment.Left || m_alignment == DockAlignment.Right)
|
---|
| 34 | Cursor = Cursors.VSplit;
|
---|
| 35 | else if (m_alignment == DockAlignment.Top || m_alignment == DockAlignment.Bottom)
|
---|
| 36 | Cursor = Cursors.HSplit;
|
---|
| 37 | else
|
---|
| 38 | Cursor = Cursors.Default;
|
---|
| 39 |
|
---|
| 40 | if (DockPane.DockState == DockState.Document)
|
---|
| 41 | Invalidate();
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | protected override void OnPaint(PaintEventArgs e)
|
---|
| 46 | {
|
---|
| 47 | base.OnPaint(e);
|
---|
| 48 |
|
---|
| 49 | if (DockPane.DockState != DockState.Document)
|
---|
| 50 | return;
|
---|
| 51 |
|
---|
| 52 | Graphics g = e.Graphics;
|
---|
| 53 | Rectangle rect = ClientRectangle;
|
---|
| 54 | if (Alignment == DockAlignment.Top || Alignment == DockAlignment.Bottom)
|
---|
| 55 | g.DrawLine(SystemPens.ControlDark, rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1);
|
---|
| 56 | else if (Alignment == DockAlignment.Left || Alignment == DockAlignment.Right)
|
---|
| 57 | g.DrawLine(SystemPens.ControlDarkDark, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void OnMouseDown(MouseEventArgs e)
|
---|
| 61 | {
|
---|
| 62 | base.OnMouseDown(e);
|
---|
| 63 |
|
---|
| 64 | if (e.Button != MouseButtons.Left)
|
---|
| 65 | return;
|
---|
| 66 |
|
---|
| 67 | DockPane.DockPanel.BeginDrag(this, Parent.RectangleToScreen(Bounds));
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | #region ISplitterDragSource Members
|
---|
| 71 |
|
---|
| 72 | void ISplitterDragSource.BeginDrag(Rectangle rectSplitter)
|
---|
| 73 | {
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | void ISplitterDragSource.EndDrag()
|
---|
| 77 | {
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool ISplitterDragSource.IsVertical
|
---|
| 81 | {
|
---|
| 82 | get
|
---|
| 83 | {
|
---|
| 84 | NestedDockingStatus status = DockPane.NestedDockingStatus;
|
---|
| 85 | return (status.DisplayingAlignment == DockAlignment.Left ||
|
---|
| 86 | status.DisplayingAlignment == DockAlignment.Right);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | Rectangle ISplitterDragSource.DragLimitBounds
|
---|
| 91 | {
|
---|
| 92 | get
|
---|
| 93 | {
|
---|
| 94 | NestedDockingStatus status = DockPane.NestedDockingStatus;
|
---|
| 95 | Rectangle rectLimit = Parent.RectangleToScreen(status.LogicalBounds);
|
---|
| 96 | if (((ISplitterDragSource)this).IsVertical)
|
---|
| 97 | {
|
---|
| 98 | rectLimit.X += MeasurePane.MinSize;
|
---|
| 99 | rectLimit.Width -= 2 * MeasurePane.MinSize;
|
---|
| 100 | }
|
---|
| 101 | else
|
---|
| 102 | {
|
---|
| 103 | rectLimit.Y += MeasurePane.MinSize;
|
---|
| 104 | rectLimit.Height -= 2 * MeasurePane.MinSize;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | return rectLimit;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | void ISplitterDragSource.MoveSplitter(int offset)
|
---|
| 112 | {
|
---|
| 113 | NestedDockingStatus status = DockPane.NestedDockingStatus;
|
---|
| 114 | double proportion = status.Proportion;
|
---|
| 115 | if (status.LogicalBounds.Width <= 0 || status.LogicalBounds.Height <= 0)
|
---|
| 116 | return;
|
---|
| 117 | else if (status.DisplayingAlignment == DockAlignment.Left)
|
---|
| 118 | proportion += ((double)offset) / (double)status.LogicalBounds.Width;
|
---|
| 119 | else if (status.DisplayingAlignment == DockAlignment.Right)
|
---|
| 120 | proportion -= ((double)offset) / (double)status.LogicalBounds.Width;
|
---|
| 121 | else if (status.DisplayingAlignment == DockAlignment.Top)
|
---|
| 122 | proportion += ((double)offset) / (double)status.LogicalBounds.Height;
|
---|
| 123 | else
|
---|
| 124 | proportion -= ((double)offset) / (double)status.LogicalBounds.Height;
|
---|
| 125 |
|
---|
| 126 | DockPane.SetNestedDockingProportion(proportion);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | #region IDragSource Members
|
---|
| 130 |
|
---|
| 131 | Control IDragSource.DragControl
|
---|
| 132 | {
|
---|
| 133 | get { return this; }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | #endregion
|
---|
| 137 |
|
---|
| 138 | #endregion
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | private SplitterControl m_splitter;
|
---|
| 142 | private SplitterControl Splitter
|
---|
| 143 | {
|
---|
| 144 | get { return m_splitter; }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | internal Rectangle SplitterBounds
|
---|
| 148 | {
|
---|
| 149 | set { Splitter.Bounds = value; }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | internal DockAlignment SplitterAlignment
|
---|
| 153 | {
|
---|
| 154 | set { Splitter.Alignment = value; }
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | } |
---|