File size: 5,376 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 |
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace WeifenLuo.WinFormsUI.Docking
{
partial class DockPanel
{
private sealed class SplitterDragHandler : DragHandler
{
private class SplitterOutline
{
public SplitterOutline()
{
m_dragForm = new DragForm();
SetDragForm(Rectangle.Empty);
if (Type.GetType("Mono.Runtime") == null) {
DragForm.BackColor = Color.Black;
DragForm.Opacity = 0.7;
DragForm.Show(false);
}
}
DragForm m_dragForm;
private DragForm DragForm
{
get { return m_dragForm; }
}
public void Show(Rectangle rect)
{
SetDragForm(rect);
}
public void Close()
{
DragForm.Close();
}
private void SetDragForm(Rectangle rect)
{
DragForm.Bounds = rect;
if (rect == Rectangle.Empty)
DragForm.Region = new Region(Rectangle.Empty);
else if (DragForm.Region != null)
DragForm.Region = null;
}
}
public SplitterDragHandler(DockPanel dockPanel)
: base(dockPanel)
{
}
public new ISplitterDragSource DragSource
{
get { return base.DragSource as ISplitterDragSource; }
private set { base.DragSource = value; }
}
private SplitterOutline m_outline;
private SplitterOutline Outline
{
get { return m_outline; }
set { m_outline = value; }
}
private Rectangle m_rectSplitter;
private Rectangle RectSplitter
{
get { return m_rectSplitter; }
set { m_rectSplitter = value; }
}
public void BeginDrag(ISplitterDragSource dragSource, Rectangle rectSplitter)
{
DragSource = dragSource;
RectSplitter = rectSplitter;
if (!BeginDrag())
{
DragSource = null;
return;
}
if (Type.GetType("Mono.Runtime") == null) { rectSplitter = Rectangle.Empty; }
Outline = new SplitterOutline();
Outline.Show(rectSplitter);
DragSource.BeginDrag(rectSplitter);
}
protected override void OnDragging()
{
Outline.Show(GetSplitterOutlineBounds(Control.MousePosition));
}
protected override void OnEndDrag(bool abort)
{
DockPanel.SuspendLayout(true);
Outline.Close();
if (!abort)
DragSource.MoveSplitter(GetMovingOffset(Control.MousePosition));
DragSource.EndDrag();
DockPanel.ResumeLayout(true, true);
}
private int GetMovingOffset(Point ptMouse)
{
Rectangle rect = GetSplitterOutlineBounds(ptMouse);
if (DragSource.IsVertical)
return rect.X - RectSplitter.X;
else
return rect.Y - RectSplitter.Y;
}
private Rectangle GetSplitterOutlineBounds(Point ptMouse)
{
Rectangle rectLimit = DragSource.DragLimitBounds;
Rectangle rect = RectSplitter;
if (rectLimit.Width <= 0 || rectLimit.Height <= 0)
return rect;
if (DragSource.IsVertical)
{
rect.X += ptMouse.X - StartMousePosition.X;
rect.Height = rectLimit.Height;
}
else
{
rect.Y += ptMouse.Y - StartMousePosition.Y;
rect.Width = rectLimit.Width;
}
if (rect.Left < rectLimit.Left)
rect.X = rectLimit.X;
if (rect.Top < rectLimit.Top)
rect.Y = rectLimit.Y;
if (rect.Right > rectLimit.Right)
rect.X -= rect.Right - rectLimit.Right;
if (rect.Bottom > rectLimit.Bottom)
rect.Y -= rect.Bottom - rectLimit.Bottom;
return rect;
}
}
private SplitterDragHandler m_splitterDragHandler = null;
private SplitterDragHandler GetSplitterDragHandler()
{
if (m_splitterDragHandler == null)
m_splitterDragHandler = new SplitterDragHandler(this);
return m_splitterDragHandler;
}
public void BeginDrag(ISplitterDragSource dragSource, Rectangle rectSplitter)
{
GetSplitterDragHandler().BeginDrag(dragSource, rectSplitter);
}
}
}
|