using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mesnac.Docking;
using Mesnac.PlugIn.View;
namespace Mesnac.Gui.Workbench
{
///
/// 工作台窗口类
///
public partial class WorkspaceWindow : DockContent,IWorkbenchWindow
{
private IViewContent _content;
#region 构造方法
public WorkspaceWindow(IViewContent content)
{
this._content = content;
InitializeComponent();
this._content.MyOwner = this; //设置视图内容所有者为当前工作区窗口
this._content.TitleNameChanged += new EventHandler(SetTitleEvent);
SetTitleEvent(this, EventArgs.Empty);
this.TabText = this._content.TitleName;
this.Text = this._content.TitleName;
//填充控件
Form frm = this._content.Control as Form;
if (frm != null)
{
frm.TopLevel = false;
frm.ControlBox = false;
frm.FormBorderStyle = FormBorderStyle.None;
frm.Visible = true;
frm.WindowState = FormWindowState.Normal;
frm.AutoScroll = true;
frm.Dock = DockStyle.Fill;
this.Controls.Add(frm);
}
else
{
this._content.Control.Dock = DockStyle.Fill;
this.Controls.Add(this._content.Control);
}
}
#endregion
#region 标题更业务处理
///
/// 标题更改事件
///
///
///
private void SetTitleEvent(object sender, EventArgs e)
{
if (this._content == null)
{
return;
}
this.SetToolTipText();
string newTitle = this._content.TitleName;
if (newTitle != Title)
{
Title = newTitle;
}
}
///
/// 设置提示文本
///
private void SetToolTipText()
{
if (this._content != null)
{
base.ToolTipText = this._content.TitleName;
}
else
{
base.ToolTipText = null;
}
}
#endregion
#region 释放面板
///
/// 释放面板
///
public void DetachContent()
{
this._content = null;
this.Controls.Clear();
}
#endregion
#region 实现IWorkbenchWindow成员
#region 实现IWorkbenchWindow属性
///
/// 工作台窗口标题
///
public string Title
{
get
{
return this.Text;
}
set
{
this.Text = value;
OnTitleChange(EventArgs.Empty);
}
}
///
/// 视图对象
///
public IViewContent ViewContent
{
get { return this._content; }
}
///
/// 活动视图对象
///
public IViewContent ActiveViewContent
{
get { return this._content; }
}
#endregion
#region 实现IWorkbenchWindow方法
///
/// 关闭工作台窗口方法
///
/// 是否真正关闭窗口(true为关闭,false为隐藏)
/// 关闭成功返回真
public bool CloseWindow(bool isRealClose)
{
if (isRealClose)
{
this.Close();
}
else
{
this.Visible = false;
this.Hide();
}
return true;
}
///
/// 选中
///
public void SelectWindow()
{
this.Visible = true;
//this.Show();
this.Activate();
}
///
/// 重绘组件方法
///
public virtual void RedrawContent()
{
}
#endregion
#region 实现IWorkbenchWindow事件
protected virtual void OnTitleChange(EventArgs e)
{
if (TitleChanged != null)
{
TitleChanged(this, e);
}
}
///
/// 触发Reload事件
///
/// 事件对象
public void TriggerReloadEvent(EventArgs e)
{
this._content.TriggerReloadEvent(e);
}
public event EventHandler TitleChanged;
#endregion
#endregion
#region 工作台窗口关闭处理
private void WorkspaceWindow_FormClosing(object sender, FormClosingEventArgs e)
{
if (!this._content.IsRealClose)
{
e.Cancel = true;
this.Visible = false;
this.Hide();
}
else
{
Form frm = this._content.Control as Form;
if (frm != null)
{
this.Controls.Remove(frm);
frm.Close();
frm = null;
}
WorkbenchSingleton.Workbench.ViewContentCollection.Remove(this._content);
string[] keys = new string[WorkbenchSingleton.Workbench.ViewContentDic.Keys.Count];
WorkbenchSingleton.Workbench.ViewContentDic.Keys.CopyTo(keys, 0);
foreach (string key in keys)
{
if (this._content == WorkbenchSingleton.Workbench.ViewContentDic[key])
{
WorkbenchSingleton.Workbench.ViewContentDic.Remove(key);
break;
}
}
}
}
#endregion
}
}