dockpanel.cs
来自「SharpDevelop2.0.0 c#开发免费工具」· CS 代码 · 共 988 行 · 第 1/3 页
CS
988 行
// *****************************************************************************
//
// Copyright 2004, Weifen Luo
// All rights reserved. The software and associated documentation
// supplied hereunder are the proprietary information of Weifen Luo
// and are supplied subject to licence terms.
//
// WinFormsUI Library Version 1.0
// *****************************************************************************
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
namespace WeifenLuo.WinFormsUI
{
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Delegate[@name="DeserializeDockContent"]/*'/>
public delegate DockContent DeserializeDockContent(string persistString);
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/ClassDef/*'/>
[Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
public class DockPanel : Panel
{
const int WM_REFRESHACTIVEWINDOW = (int)Win32.Msgs.WM_USER + 1;
private LocalWindowsHook m_localWindowsHook;
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Constructor[@name="()"]/*'/>
public DockPanel()
{
m_extender = new DockPanelExtender(this);
m_dragHandler = new DragHandler(this);
m_panes = new DockPaneCollection();
m_floatWindows = new FloatWindowCollection();
SetStyle(ControlStyles.ResizeRedraw |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
SuspendLayout();
Font = SystemInformation.MenuFont;
m_autoHideWindow = new AutoHideWindow(this);
m_autoHideWindow.Visible = false;
m_dummyControl = new DummyControl();
m_dummyControl.Bounds = Rectangle.Empty;
m_dockWindows = new DockWindowCollection(this);
Controls.AddRange(new Control[] {
m_autoHideWindow,
m_dummyControl,
DockWindows[DockState.Document],
DockWindows[DockState.DockLeft],
DockWindows[DockState.DockRight],
DockWindows[DockState.DockTop],
DockWindows[DockState.DockBottom]
});
m_localWindowsHook = new LocalWindowsHook(HookType.WH_CALLWNDPROCRET);
m_localWindowsHook.HookInvoked += new LocalWindowsHook.HookEventHandler(this.HookEventHandler);
m_localWindowsHook.Install();
m_dummyContent = new DockContent();
ResumeLayout();
}
private AutoHideStripBase m_autoHideStripControl = null;
private AutoHideStripBase AutoHideStripControl
{
get
{
if (m_autoHideStripControl == null)
{
m_autoHideStripControl = AutoHideStripFactory.CreateAutoHideStrip(this);
Controls.Add(m_autoHideStripControl);
}
return m_autoHideStripControl;
}
}
private bool m_inRefreshingActiveWindow = false;
internal bool InRefreshingActiveWindow
{
get { return m_inRefreshingActiveWindow; }
set { m_inRefreshingActiveWindow = value; }
}
// Windows hook event handler
private void HookEventHandler(object sender, HookEventArgs e)
{
if (InRefreshingActiveWindow)
return;
Win32.CWPRETSTRUCT cwpret = (Win32.CWPRETSTRUCT)Marshal.PtrToStructure(e.lParam, typeof(Win32.CWPRETSTRUCT));
int msg = cwpret.message;
if (msg == (int)Win32.Msgs.WM_KILLFOCUS)
{
DockPane pane = GetPaneFromHandle((IntPtr)cwpret.wParam);
if (pane == null)
User32.PostMessage(this.Handle, WM_REFRESHACTIVEWINDOW, 0, 0);
}
else if (msg == (int)Win32.Msgs.WM_SETFOCUS)
User32.PostMessage(this.Handle, WM_REFRESHACTIVEWINDOW, 0, 0);
}
private bool m_disposed = false;
/// <exclude/>
protected override void Dispose(bool disposing)
{
if (!m_disposed)
{
try
{
if (disposing)
{
FloatWindows.Dispose();
Panes.Dispose();
DummyContent.Dispose();
}
m_localWindowsHook.Uninstall();
m_disposed = true;
}
finally
{
base.Dispose(disposing);
}
}
}
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Property[@name="ActiveAutoHideContent"]/*' />
[Browsable(false)]
public DockContent ActiveAutoHideContent
{
get { return AutoHideWindow.ActiveContent; }
set { AutoHideWindow.ActiveContent = value; }
}
private DockContent m_activeContent = null;
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Property[@name="ActiveContent"]/*' />
[Browsable(false)]
public DockContent ActiveContent
{
get { return m_activeContent; }
}
internal void SetActiveContent()
{
DockContent value = ActivePane == null ? null : ActivePane.ActiveContent;
if (m_activeContent == value)
return;
if (m_activeContent != null)
m_activeContent.SetIsActivated(false);
m_activeContent = value;
if (m_activeContent != null)
m_activeContent.SetIsActivated(true);
OnActiveContentChanged(EventArgs.Empty);
}
private DockPane m_activePane = null;
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Property[@name="ActivePane"]/*' />
[Browsable(false)]
public DockPane ActivePane
{
get { return m_activePane; }
}
private void SetActivePane()
{
DockPane value = GetPaneFromHandle(User32.GetFocus());
if (m_activePane == value)
return;
if (m_activePane != null)
m_activePane.SetIsActivated(false);
m_activePane = value;
if (m_activePane != null)
m_activePane.SetIsActivated(true);
}
private DockPane GetPaneFromHandle(IntPtr hWnd)
{
Control control = Control.FromChildHandle(hWnd);
DockPane pane = null;
for (; control != null; control = control.Parent)
{
pane = control as DockPane;
if (pane != null && pane.DockPanel == this)
break;
}
return pane;
}
private DockContent m_activeDocument = null;
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Property[@name="ActiveDocument"]/*' />
[Browsable(false)]
public DockContent ActiveDocument
{
get { return m_activeDocument; }
}
private void SetActiveDocument()
{
DockContent value = ActiveDocumentPane == null ? null : ActiveDocumentPane.ActiveContent;
if (m_activeDocument == value)
return;
m_activeDocument = value;
if (m_activeDocument != null)
if (m_activeDocument.HiddenMdiChild != null)
{
IntPtr hWnd = User32.GetFocus();
m_activeDocument.HiddenMdiChild.Activate();
User32.SetFocus(hWnd);
}
OnActiveDocumentChanged(EventArgs.Empty);
}
private DockPane m_activeDocumentPane = null;
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Property[@name="ActiveDocumentPane"]/*' />
[Browsable(false)]
public DockPane ActiveDocumentPane
{
get { return m_activeDocumentPane; }
}
private void SetActiveDocumentPane()
{
DockPane value = null;
if (ActivePane != null && ActivePane.DockState == DockState.Document)
value = ActivePane;
if (value == null)
{
if (ActiveDocumentPane == null)
value = DockWindows[DockState.Document].DefaultPane;
else if (ActiveDocumentPane.DockPanel != this || ActiveDocumentPane.DockState != DockState.Document)
value = DockWindows[DockState.Document].DefaultPane;
else
value = m_activeDocumentPane;
}
if (m_activeDocumentPane == value)
return;
if (m_activeDocumentPane != null)
m_activeDocumentPane.SetIsActiveDocumentPane(false);
m_activeDocumentPane = value;
if (m_activeDocumentPane != null)
m_activeDocumentPane.SetIsActiveDocumentPane(true);
}
private bool m_allowRedocking = true;
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Property[@name="AllowRedocking"]/*' />
[LocalizedCategory("Category.Docking")]
[LocalizedDescription("DockPanel.AllowRedocking.Description")]
[DefaultValue(true)]
public bool AllowRedocking
{
get { return m_allowRedocking; }
set { m_allowRedocking = value; }
}
private AutoHideWindow m_autoHideWindow;
internal AutoHideWindow AutoHideWindow
{
get { return m_autoHideWindow; }
}
private DockContentCollection m_contents = new DockContentCollection();
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Property[@name="Contents"]/*' />
[Browsable(false)]
public DockContentCollection Contents
{
get { return m_contents; }
}
private DockContent m_dummyContent;
internal DockContent DummyContent
{
get { return m_dummyContent; }
}
private DockPanelExtender m_extender;
/// <include file='CodeDoc\DockPanel.xml' path='//CodeDoc/Class[@name="DockPanel"]/Property[@name="Extender"]/*' />
[Browsable(false)]
public DockPanelExtender Extender
{
get { return m_extender; }
}
internal DockPanelExtender.IDockPaneFactory DockPaneFactory
{
get { return Extender.DockPaneFactory; }
}
internal DockPanelExtender.IFloatWindowFactory FloatWindowFactory
{
get { return Extender.FloatWindowFactory; }
}
internal DockPanelExtender.IDockPaneCaptionFactory DockPaneCaptionFactory
{
get { return Extender.DockPaneCaptionFactory; }
}
internal DockPanelExtender.IDockPaneTabFactory DockPaneTabFactory
{
get { return Extender.DockPaneTabFactory; }
}
internal DockPanelExtender.IDockPaneStripFactory DockPaneStripFactory
{
get { return Extender.DockPaneStripFactory; }
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?