Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockWindow.cs @ 5405

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

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

File size: 6.3 KB
Line 
1using System.ComponentModel;
2using System.Drawing;
3using System.Windows.Forms;
4
5namespace WeifenLuo.WinFormsUI.Docking {
6  [ToolboxItem(false)]
7  public partial class DockWindow : Panel, INestedPanesContainer, ISplitterDragSource {
8    private DockPanel m_dockPanel;
9    private DockState m_dockState;
10    private SplitterControl m_splitter;
11    private NestedPaneCollection m_nestedPanes;
12
13    internal DockWindow(DockPanel dockPanel, DockState dockState) {
14      m_nestedPanes = new NestedPaneCollection(this);
15      m_dockPanel = dockPanel;
16      m_dockState = dockState;
17      Visible = false;
18
19      SuspendLayout();
20
21      if (DockState == DockState.DockLeft || DockState == DockState.DockRight ||
22        DockState == DockState.DockTop || DockState == DockState.DockBottom) {
23        m_splitter = new SplitterControl();
24        Controls.Add(m_splitter);
25      }
26
27      if (DockState == DockState.DockLeft) {
28        Dock = DockStyle.Left;
29        m_splitter.Dock = DockStyle.Right;
30      } else if (DockState == DockState.DockRight) {
31        Dock = DockStyle.Right;
32        m_splitter.Dock = DockStyle.Left;
33      } else if (DockState == DockState.DockTop) {
34        Dock = DockStyle.Top;
35        m_splitter.Dock = DockStyle.Bottom;
36      } else if (DockState == DockState.DockBottom) {
37        Dock = DockStyle.Bottom;
38        m_splitter.Dock = DockStyle.Top;
39      } else if (DockState == DockState.Document) {
40        Dock = DockStyle.Fill;
41      }
42
43      ResumeLayout();
44    }
45
46    public VisibleNestedPaneCollection VisibleNestedPanes {
47      get { return NestedPanes.VisibleNestedPanes; }
48    }
49
50    public NestedPaneCollection NestedPanes {
51      get { return m_nestedPanes; }
52    }
53
54    public DockPanel DockPanel {
55      get { return m_dockPanel; }
56    }
57
58    public DockState DockState {
59      get { return m_dockState; }
60    }
61
62    public bool IsFloat {
63      get { return DockState == DockState.Float; }
64    }
65
66    internal DockPane DefaultPane {
67      get { return VisibleNestedPanes.Count == 0 ? null : VisibleNestedPanes[0]; }
68    }
69
70    public virtual Rectangle DisplayingRectangle {
71      get {
72        Rectangle rect = ClientRectangle;
73        // if DockWindow is document, exclude the border
74        if (DockState == DockState.Document) {
75          rect.X += 1;
76          rect.Y += 1;
77          rect.Width -= 2;
78          rect.Height -= 2;
79        }
80          // exclude the splitter
81        else if (DockState == DockState.DockLeft)
82          rect.Width -= Measures.SplitterSize;
83        else if (DockState == DockState.DockRight) {
84          rect.X += Measures.SplitterSize;
85          rect.Width -= Measures.SplitterSize;
86        } else if (DockState == DockState.DockTop)
87          rect.Height -= Measures.SplitterSize;
88        else if (DockState == DockState.DockBottom) {
89          rect.Y += Measures.SplitterSize;
90          rect.Height -= Measures.SplitterSize;
91        }
92
93        return rect;
94      }
95    }
96
97    protected override void OnPaint(PaintEventArgs e) {
98      // if DockWindow is document, draw the border
99      if (DockState == DockState.Document)
100        e.Graphics.DrawRectangle(SystemPens.ControlDark, ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
101
102      base.OnPaint(e);
103    }
104
105    protected override void OnLayout(LayoutEventArgs levent) {
106      VisibleNestedPanes.Refresh();
107      if (VisibleNestedPanes.Count == 0) {
108        if (Visible)
109          Visible = false;
110      } else if (!Visible) {
111        Visible = true;
112        VisibleNestedPanes.Refresh();
113      }
114
115      base.OnLayout(levent);
116    }
117
118    #region ISplitterDragSource Members
119
120    void ISplitterDragSource.BeginDrag(Rectangle rectSplitter) {
121    }
122
123    void ISplitterDragSource.EndDrag() {
124    }
125
126    bool ISplitterDragSource.IsVertical {
127      get { return (DockState == DockState.DockLeft || DockState == DockState.DockRight); }
128    }
129
130    Rectangle ISplitterDragSource.DragLimitBounds {
131      get {
132        Rectangle rectLimit = DockPanel.DockArea;
133        Point location;
134        if ((Control.ModifierKeys & Keys.Shift) == 0)
135          location = Location;
136        else
137          location = DockPanel.DockArea.Location;
138
139        if (((ISplitterDragSource)this).IsVertical) {
140          rectLimit.X += MeasurePane.MinSize;
141          rectLimit.Width -= 2 * MeasurePane.MinSize;
142          rectLimit.Y = location.Y;
143          if ((Control.ModifierKeys & Keys.Shift) == 0)
144            rectLimit.Height = Height;
145        } else {
146          rectLimit.Y += MeasurePane.MinSize;
147          rectLimit.Height -= 2 * MeasurePane.MinSize;
148          rectLimit.X = location.X;
149          if ((Control.ModifierKeys & Keys.Shift) == 0)
150            rectLimit.Width = Width;
151        }
152
153        return DockPanel.RectangleToScreen(rectLimit);
154      }
155    }
156
157    void ISplitterDragSource.MoveSplitter(int offset) {
158      if ((Control.ModifierKeys & Keys.Shift) != 0)
159        SendToBack();
160
161      Rectangle rectDockArea = DockPanel.DockArea;
162      if (DockState == DockState.DockLeft && rectDockArea.Width > 0) {
163        if (DockPanel.DockLeftPortion > 1)
164          DockPanel.DockLeftPortion = Width + offset;
165        else
166          DockPanel.DockLeftPortion += ((double)offset) / (double)rectDockArea.Width;
167      } else if (DockState == DockState.DockRight && rectDockArea.Width > 0) {
168        if (DockPanel.DockRightPortion > 1)
169          DockPanel.DockRightPortion = Width - offset;
170        else
171          DockPanel.DockRightPortion -= ((double)offset) / (double)rectDockArea.Width;
172      } else if (DockState == DockState.DockBottom && rectDockArea.Height > 0) {
173        if (DockPanel.DockBottomPortion > 1)
174          DockPanel.DockBottomPortion = Height - offset;
175        else
176          DockPanel.DockBottomPortion -= ((double)offset) / (double)rectDockArea.Height;
177      } else if (DockState == DockState.DockTop && rectDockArea.Height > 0) {
178        if (DockPanel.DockTopPortion > 1)
179          DockPanel.DockTopPortion = Height + offset;
180        else
181          DockPanel.DockTopPortion += ((double)offset) / (double)rectDockArea.Height;
182      }
183    }
184
185    #region IDragSource Members
186
187    Control IDragSource.DragControl {
188      get { return this; }
189    }
190
191    #endregion
192    #endregion
193  }
194}
Note: See TracBrowser for help on using the repository browser.