Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockPanel.SplitterDragHandler.cs @ 6675

Last change on this file since 6675 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 4.0 KB
Line 
1using System.Drawing;
2using System.Windows.Forms;
3
4namespace WeifenLuo.WinFormsUI.Docking {
5  partial class DockPanel {
6    private sealed class SplitterDragHandler : DragHandler {
7      private class SplitterOutline {
8        public SplitterOutline() {
9          m_dragForm = new DragForm();
10          SetDragForm(Rectangle.Empty);
11          DragForm.BackColor = Color.Black;
12          DragForm.Opacity = 0.7;
13          DragForm.Show(false);
14        }
15
16        DragForm m_dragForm;
17        private DragForm DragForm {
18          get { return m_dragForm; }
19        }
20
21        public void Show(Rectangle rect) {
22          SetDragForm(rect);
23        }
24
25        public void Close() {
26          DragForm.Close();
27        }
28
29        private void SetDragForm(Rectangle rect) {
30          DragForm.Bounds = rect;
31          if (rect == Rectangle.Empty)
32            DragForm.Region = new Region(Rectangle.Empty);
33          else if (DragForm.Region != null)
34            DragForm.Region = null;
35        }
36      }
37
38      public SplitterDragHandler(DockPanel dockPanel)
39        : base(dockPanel) {
40      }
41
42      public new ISplitterDragSource DragSource {
43        get { return base.DragSource as ISplitterDragSource; }
44        private set { base.DragSource = value; }
45      }
46
47      private SplitterOutline m_outline;
48      private SplitterOutline Outline {
49        get { return m_outline; }
50        set { m_outline = value; }
51      }
52
53      private Rectangle m_rectSplitter;
54      private Rectangle RectSplitter {
55        get { return m_rectSplitter; }
56        set { m_rectSplitter = value; }
57      }
58
59      public void BeginDrag(ISplitterDragSource dragSource, Rectangle rectSplitter) {
60        DragSource = dragSource;
61        RectSplitter = rectSplitter;
62
63        if (!BeginDrag()) {
64          DragSource = null;
65          return;
66        }
67
68        Outline = new SplitterOutline();
69        Outline.Show(rectSplitter);
70        DragSource.BeginDrag(rectSplitter);
71      }
72
73      protected override void OnDragging() {
74        Outline.Show(GetSplitterOutlineBounds(Control.MousePosition));
75      }
76
77      protected override void OnEndDrag(bool abort) {
78        DockPanel.SuspendLayout(true);
79
80        Outline.Close();
81
82        if (!abort)
83          DragSource.MoveSplitter(GetMovingOffset(Control.MousePosition));
84
85        DragSource.EndDrag();
86        DockPanel.ResumeLayout(true, true);
87      }
88
89      private int GetMovingOffset(Point ptMouse) {
90        Rectangle rect = GetSplitterOutlineBounds(ptMouse);
91        if (DragSource.IsVertical)
92          return rect.X - RectSplitter.X;
93        else
94          return rect.Y - RectSplitter.Y;
95      }
96
97      private Rectangle GetSplitterOutlineBounds(Point ptMouse) {
98        Rectangle rectLimit = DragSource.DragLimitBounds;
99
100        Rectangle rect = RectSplitter;
101        if (rectLimit.Width <= 0 || rectLimit.Height <= 0)
102          return rect;
103
104        if (DragSource.IsVertical) {
105          rect.X += ptMouse.X - StartMousePosition.X;
106          rect.Height = rectLimit.Height;
107        } else {
108          rect.Y += ptMouse.Y - StartMousePosition.Y;
109          rect.Width = rectLimit.Width;
110        }
111
112        if (rect.Left < rectLimit.Left)
113          rect.X = rectLimit.X;
114        if (rect.Top < rectLimit.Top)
115          rect.Y = rectLimit.Y;
116        if (rect.Right > rectLimit.Right)
117          rect.X -= rect.Right - rectLimit.Right;
118        if (rect.Bottom > rectLimit.Bottom)
119          rect.Y -= rect.Bottom - rectLimit.Bottom;
120
121        return rect;
122      }
123    }
124
125    private SplitterDragHandler m_splitterDragHandler = null;
126    private SplitterDragHandler GetSplitterDragHandler() {
127      if (m_splitterDragHandler == null)
128        m_splitterDragHandler = new SplitterDragHandler(this);
129      return m_splitterDragHandler;
130    }
131
132    internal void BeginDrag(ISplitterDragSource dragSource, Rectangle rectSplitter) {
133      GetSplitterDragHandler().BeginDrag(dragSource, rectSplitter);
134    }
135  }
136}
Note: See TracBrowser for help on using the repository browser.