|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.Data;
|
|
|
using System.Drawing;
|
|
|
using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
using Mesnac.Docking;
|
|
|
using Mesnac.Core.Service;
|
|
|
using Mesnac.PlugIn.Pad;
|
|
|
|
|
|
namespace Mesnac.Gui.Workbench
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 面板封装类
|
|
|
/// </summary>
|
|
|
public partial class PadContentWrapper : DockContent
|
|
|
{
|
|
|
#region 定义变量
|
|
|
|
|
|
private PadDescriptor _padDescriptor;
|
|
|
private bool _isInitialized = false;
|
|
|
internal bool _allowInitialize = true;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 构造方法
|
|
|
|
|
|
public PadContentWrapper(PadDescriptor padDescriptor)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
if (padDescriptor == null)
|
|
|
{
|
|
|
MesnacServiceManager.Instance.LoggingService.Error("空面板...");
|
|
|
throw new ArgumentNullException("padDescriptor");
|
|
|
}
|
|
|
this._padDescriptor = padDescriptor;
|
|
|
|
|
|
this.InitPadPosition(); //初始化面板位置
|
|
|
this.ActivateContent(); //激活并加载面板中的内容
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 定义属性
|
|
|
/// <summary>
|
|
|
/// 获取IPadContent接口对象
|
|
|
/// </summary>
|
|
|
public IPadContent PadContent
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (this._padDescriptor != null)
|
|
|
{
|
|
|
return this._padDescriptor.PadContent;
|
|
|
}
|
|
|
else
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 定义方法
|
|
|
/// <summary>
|
|
|
/// 分离面板内容
|
|
|
/// </summary>
|
|
|
public void DetachContent()
|
|
|
{
|
|
|
this.Controls.Clear();
|
|
|
this._padDescriptor = null;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 激活面板,这个方法会把IPadContent中的控件加载到当前DockContent中,是显示面板内容的关键方法
|
|
|
/// </summary>
|
|
|
public void ActivateContent()
|
|
|
{
|
|
|
if (!this._allowInitialize)
|
|
|
return;
|
|
|
if (!this._isInitialized)
|
|
|
{
|
|
|
this._isInitialized = true;
|
|
|
IPadContent content = this._padDescriptor.PadContent;
|
|
|
if (content == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
Form frm = content.Control as Form;
|
|
|
if (frm != null)
|
|
|
{
|
|
|
frm.TopLevel = false;
|
|
|
frm.ControlBox = false;
|
|
|
frm.FormBorderStyle = FormBorderStyle.None;
|
|
|
frm.Dock = DockStyle.Fill;
|
|
|
frm.Visible = true;
|
|
|
frm.AutoScroll = true;
|
|
|
this.Controls.Add(frm);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
content.Control.Dock = DockStyle.Fill;
|
|
|
this.Controls.Add(content.Control);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 允许初始化面板
|
|
|
/// </summary>
|
|
|
public void AllowInitialize()
|
|
|
{
|
|
|
this._allowInitialize = true;
|
|
|
if (this.Visible && this.Width > 0)
|
|
|
{
|
|
|
this.ActivateContent();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 初始化面板位置
|
|
|
/// </summary>
|
|
|
private void InitPadPosition()
|
|
|
{
|
|
|
switch (this._padDescriptor.DockState.ToLower())
|
|
|
{
|
|
|
case "":
|
|
|
case "unknown":
|
|
|
this.ShowHint = DockState.Unknown;
|
|
|
break;
|
|
|
case "dockleft":
|
|
|
this.ShowHint = DockState.DockLeft;
|
|
|
break;
|
|
|
case "dockright":
|
|
|
this.ShowHint = DockState.DockRight;
|
|
|
break;
|
|
|
case "docktop":
|
|
|
this.ShowHint = DockState.DockTop;
|
|
|
break;
|
|
|
case "dockbottom":
|
|
|
this.ShowHint = DockState.DockBottom;
|
|
|
break;
|
|
|
case "document":
|
|
|
this.ShowHint = DockState.Document;
|
|
|
break;
|
|
|
case "float":
|
|
|
this.ShowHint = DockState.Float;
|
|
|
break;
|
|
|
case "hidden":
|
|
|
this.ShowHint = DockState.Hidden;
|
|
|
break;
|
|
|
case "dockleftautohide":
|
|
|
this.ShowHint = DockState.DockLeftAutoHide;
|
|
|
break;
|
|
|
case "dockrightautohide":
|
|
|
this.ShowHint = DockState.DockRightAutoHide;
|
|
|
break;
|
|
|
case "docktopautohide":
|
|
|
this.ShowHint = DockState.DockTopAutoHide;
|
|
|
break;
|
|
|
case "dockbottomautohide":
|
|
|
this.ShowHint = DockState.DockBottomAutoHide;
|
|
|
break;
|
|
|
default:
|
|
|
this.ShowHint = DockState.Unknown;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 事件处理程序覆盖
|
|
|
|
|
|
/// <summary>
|
|
|
/// 面板可视属性发生变化时的处理
|
|
|
/// </summary>
|
|
|
/// <param name="e"></param>
|
|
|
protected override void OnVisibleChanged(EventArgs e)
|
|
|
{
|
|
|
base.OnVisibleChanged(e);
|
|
|
if (this.Visible && this.Width > 0)
|
|
|
{
|
|
|
this.ActivateContent();
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 面板尺寸发生变化时的处理
|
|
|
/// </summary>
|
|
|
/// <param name="e"></param>
|
|
|
protected override void OnSizeChanged(EventArgs e)
|
|
|
{
|
|
|
base.OnSizeChanged(e);
|
|
|
if (this.Visible && this.Width > 0)
|
|
|
{
|
|
|
this.ActivateContent();
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取面板的持久字符串,一般是对应的完整类名
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
protected override string GetPersistString()
|
|
|
{
|
|
|
return this._padDescriptor.Class;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 关闭面板时释放响应的资源
|
|
|
/// </summary>
|
|
|
/// <param name="disposing"></param>
|
|
|
protected override void Dispose(bool disposing)
|
|
|
{
|
|
|
if (disposing && (components != null))
|
|
|
{
|
|
|
components.Dispose();
|
|
|
}
|
|
|
base.Dispose(disposing);
|
|
|
if (disposing)
|
|
|
{
|
|
|
if (this._padDescriptor != null)
|
|
|
{
|
|
|
this._padDescriptor.Dispose();
|
|
|
this._padDescriptor = null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
}
|