Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockPane.SplitterControl.cs @ 6206

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

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

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