| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:DockWindow.cs
- * 2.功能描述:类文件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2014/09/01 1.00 新建
- *******************************************************************************/
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- namespace Dongke.IBOSS.PRD.Basics.DockPanel
- {
- [ToolboxItem(false)]
- public partial class DockWindow : Panel, INestedPanesContainer, ISplitterDragSource
- {
- private DockPanel m_dockPanel;
- private DockState m_dockState;
- private SplitterControl m_splitter;
- private NestedPaneCollection m_nestedPanes;
- internal DockWindow(DockPanel dockPanel, DockState dockState)
- {
- m_nestedPanes = new NestedPaneCollection(this);
- m_dockPanel = dockPanel;
- m_dockState = dockState;
- Visible = false;
- SuspendLayout();
- if (DockState == DockState.DockLeft || DockState == DockState.DockRight ||
- DockState == DockState.DockTop || DockState == DockState.DockBottom)
- {
- m_splitter = new SplitterControl();
- Controls.Add(m_splitter);
- }
- if (DockState == DockState.DockLeft)
- {
- Dock = DockStyle.Left;
- m_splitter.Dock = DockStyle.Right;
- }
- else if (DockState == DockState.DockRight)
- {
- Dock = DockStyle.Right;
- m_splitter.Dock = DockStyle.Left;
- }
- else if (DockState == DockState.DockTop)
- {
- Dock = DockStyle.Top;
- m_splitter.Dock = DockStyle.Bottom;
- }
- else if (DockState == DockState.DockBottom)
- {
- Dock = DockStyle.Bottom;
- m_splitter.Dock = DockStyle.Top;
- }
- else if (DockState == DockState.Document)
- {
- Dock = DockStyle.Fill;
- }
- ResumeLayout();
- }
- public VisibleNestedPaneCollection VisibleNestedPanes
- {
- get
- {
- return NestedPanes.VisibleNestedPanes;
- }
- }
- public NestedPaneCollection NestedPanes
- {
- get
- {
- return m_nestedPanes;
- }
- }
- public DockPanel DockPanel
- {
- get
- {
- return m_dockPanel;
- }
- }
- public DockState DockState
- {
- get
- {
- return m_dockState;
- }
- }
- public bool IsFloat
- {
- get
- {
- return DockState == DockState.Float;
- }
- }
- internal DockPane DefaultPane
- {
- get
- {
- return VisibleNestedPanes.Count == 0 ? null : VisibleNestedPanes[0];
- }
- }
- public virtual Rectangle DisplayingRectangle
- {
- get
- {
- Rectangle rect = ClientRectangle;
- // if DockWindow is document, exclude the border
- if (DockState == DockState.Document)
- {
- rect.X += 1;
- rect.Y += 1;
- rect.Width -= 2;
- rect.Height -= 2;
- }
- // exclude the splitter
- else if (DockState == DockState.DockLeft)
- rect.Width -= Measures.SplitterSize;
- else if (DockState == DockState.DockRight)
- {
- rect.X += Measures.SplitterSize;
- rect.Width -= Measures.SplitterSize;
- }
- else if (DockState == DockState.DockTop)
- rect.Height -= Measures.SplitterSize;
- else if (DockState == DockState.DockBottom)
- {
- rect.Y += Measures.SplitterSize;
- rect.Height -= Measures.SplitterSize;
- }
- return rect;
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- // if DockWindow is document, draw the border
- if (DockState == DockState.Document)
- e.Graphics.DrawRectangle(SystemPens.ControlDark, ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
- base.OnPaint(e);
- }
- protected override void OnLayout(LayoutEventArgs levent)
- {
- VisibleNestedPanes.Refresh();
- if (VisibleNestedPanes.Count == 0)
- {
- if (Visible)
- Visible = false;
- }
- else if (!Visible)
- {
- Visible = true;
- VisibleNestedPanes.Refresh();
- }
- base.OnLayout(levent);
- }
- #region ISplitterDragSource Members
- void ISplitterDragSource.BeginDrag(Rectangle rectSplitter)
- {
- }
- void ISplitterDragSource.EndDrag()
- {
- }
- bool ISplitterDragSource.IsVertical
- {
- get
- {
- return (DockState == DockState.DockLeft || DockState == DockState.DockRight);
- }
- }
- Rectangle ISplitterDragSource.DragLimitBounds
- {
- get
- {
- Rectangle rectLimit = DockPanel.DockArea;
- Point location;
- if ((Control.ModifierKeys & Keys.Shift) == 0)
- location = Location;
- else
- location = DockPanel.DockArea.Location;
- if (((ISplitterDragSource)this).IsVertical)
- {
- rectLimit.X += MeasurePane.MinSize;
- rectLimit.Width -= 2 * MeasurePane.MinSize;
- rectLimit.Y = location.Y;
- if ((Control.ModifierKeys & Keys.Shift) == 0)
- rectLimit.Height = Height;
- }
- else
- {
- rectLimit.Y += MeasurePane.MinSize;
- rectLimit.Height -= 2 * MeasurePane.MinSize;
- rectLimit.X = location.X;
- if ((Control.ModifierKeys & Keys.Shift) == 0)
- rectLimit.Width = Width;
- }
- return DockPanel.RectangleToScreen(rectLimit);
- }
- }
- void ISplitterDragSource.MoveSplitter(int offset)
- {
- if ((Control.ModifierKeys & Keys.Shift) != 0)
- SendToBack();
- Rectangle rectDockArea = DockPanel.DockArea;
- if (DockState == DockState.DockLeft && rectDockArea.Width > 0)
- {
- if (DockPanel.DockLeftPortion > 1)
- DockPanel.DockLeftPortion = Width + offset;
- else
- DockPanel.DockLeftPortion += ((double)offset) / (double)rectDockArea.Width;
- }
- else if (DockState == DockState.DockRight && rectDockArea.Width > 0)
- {
- if (DockPanel.DockRightPortion > 1)
- DockPanel.DockRightPortion = Width - offset;
- else
- DockPanel.DockRightPortion -= ((double)offset) / (double)rectDockArea.Width;
- }
- else if (DockState == DockState.DockBottom && rectDockArea.Height > 0)
- {
- if (DockPanel.DockBottomPortion > 1)
- DockPanel.DockBottomPortion = Height - offset;
- else
- DockPanel.DockBottomPortion -= ((double)offset) / (double)rectDockArea.Height;
- }
- else if (DockState == DockState.DockTop && rectDockArea.Height > 0)
- {
- if (DockPanel.DockTopPortion > 1)
- DockPanel.DockTopPortion = Height + offset;
- else
- DockPanel.DockTopPortion += ((double)offset) / (double)rectDockArea.Height;
- }
- }
- #region IDragSource Members
- Control IDragSource.DragControl
- {
- get
- {
- return this;
- }
- }
- #endregion
- #endregion
- }
- }
|