You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
286 lines
9.4 KiB
C#
286 lines
9.4 KiB
C#
// <copyright file="DrawerTabbedView.cs" company="PlaceholderCompany">
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
// </copyright>
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraBars.Docking2010.Customization;
|
|
using DevExpress.XtraBars.Docking2010.Views;
|
|
using DevExpress.XtraBars.Docking2010.Views.Tabbed;
|
|
using DevExpress.XtraBars.Ribbon;
|
|
|
|
using Document = DevExpress.XtraBars.Docking2010.Views.Tabbed.Document;
|
|
|
|
namespace PcgDrawR
|
|
{
|
|
/// <summary>
|
|
/// 多文档视图
|
|
/// </summary>
|
|
public class DrawerTabbedView : TabbedView
|
|
{
|
|
/// <summary>
|
|
/// 允许停靠的类型
|
|
/// </summary>
|
|
public List<Type> InvalidDocumentTypes { get; set; } = new List<Type>();
|
|
/// <summary>
|
|
/// Occurs when [other document activated].
|
|
/// </summary>
|
|
public DocumentEventHandler OtherDocumentActivated { get; set; }
|
|
/// <summary>
|
|
/// Ribbon控件
|
|
/// </summary>
|
|
public RibbonControl Ribbon { get; set; }
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="DrawerTabbedView"/> class.
|
|
/// </summary>
|
|
/// <param name="container">父容器</param>
|
|
public DrawerTabbedView(IContainer container)
|
|
: base(container)
|
|
{
|
|
this.DocumentClosed += DrawerTabbedView_DocumentClosed;
|
|
this.DocumentRemoved += DrawerTabbedView_DocumentRemoved;
|
|
this.ControlReleasing += DrawerTabbedView_ControlReleasing;
|
|
//this.ShowingDockGuides += DrawerTabbedView_ShowingDockGuides;
|
|
}
|
|
|
|
private void DrawerTabbedView_ControlReleasing(object sender, ControlReleasingEventArgs e)
|
|
{
|
|
e.KeepControl = false;
|
|
e.DisposeControl = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Drawers the tabbed view_ document removed.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void DrawerTabbedView_DocumentRemoved(object sender, DocumentEventArgs e)
|
|
{
|
|
//disposeControls(e);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Drawers the tabbed view_ showing dock guides.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void DrawerTabbedView_ShowingDockGuides(object sender, ShowingDockGuidesEventArgs e)
|
|
{
|
|
e.Configuration.Disable(DockHint.Center);
|
|
e.Configuration.Disable(DockHint.CenterLeft);
|
|
e.Configuration.Disable(DockHint.CenterRight);
|
|
e.Configuration.Disable(DockHint.CenterTop);
|
|
e.Configuration.Disable(DockHint.CenterBottom);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Drawers the tabbed view_ document closed.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void DrawerTabbedView_DocumentClosed(object sender, DocumentEventArgs e)
|
|
{
|
|
disposeControls(e);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销毁控件内容.
|
|
/// </summary>
|
|
/// <param name="e">The e.</param>
|
|
private void disposeControls(DocumentEventArgs e)
|
|
{
|
|
if (e.Document.Control is UCDrawEdit editor)
|
|
{
|
|
editor.Dispose();
|
|
editor = null;
|
|
}
|
|
if (e.Document.Control is UCVtkEdit vtkEditor)
|
|
{
|
|
vtkEditor.Dispose();
|
|
vtkEditor = null;
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override bool OnBeginFloating(BaseDocument document, FloatingReason reason)
|
|
{
|
|
if (this.InvalidDocumentTypes.Contains(document.Control.GetType()))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Document doc = document as Document;
|
|
if (doc.Control is UCDrawEdit)
|
|
{
|
|
this.Ribbon.UnMergeRibbon();
|
|
}
|
|
if (doc.Control is UCVtkEdit)
|
|
{
|
|
this.Ribbon.UnMergeRibbon();
|
|
}
|
|
|
|
if (this.GetNeighborDocument(doc.Parent.Items.ToArray(), document) is Document docNext && docNext.Control != null)
|
|
{
|
|
if (docNext.Control is UCDrawEdit editor)
|
|
{
|
|
this.Ribbon.MergeRibbon(editor.ribbonMain);
|
|
}
|
|
|
|
if (docNext.Control is UCVtkEdit vtkEditor)
|
|
{
|
|
this.Ribbon.MergeRibbon(vtkEditor.RibbonControlMain);
|
|
}
|
|
}
|
|
return base.OnBeginFloating(document, reason);
|
|
}
|
|
protected override void OnDocumentDeactivated(BaseDocument document)
|
|
{
|
|
base.OnDocumentDeactivated(document);
|
|
}
|
|
/// <inheritdoc/>
|
|
protected override void OnDocumentActivated(BaseDocument document)
|
|
{
|
|
if (this.InvalidDocumentTypes.Contains(document.Control.GetType()))
|
|
//if (!(document.Control is UCDrawEdit editor))
|
|
{
|
|
return;
|
|
}
|
|
|
|
base.OnDocumentActivated(document);
|
|
|
|
if (document == null || this.Ribbon == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (document.Control is UCDrawEdit)
|
|
{
|
|
UCDrawEdit editor = document.Control as UCDrawEdit;
|
|
if (this.ActiveFloatDocument != null)
|
|
{
|
|
UCDrawEdit editorFloat = this.ActiveFloatDocument.Control as UCDrawEdit;
|
|
if (object.ReferenceEquals(editor, editorFloat))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
this.BeginUpdate();
|
|
if (editor != null)
|
|
{
|
|
if (!object.ReferenceEquals(this.Ribbon.MergedRibbon, editor.ribbonMain))
|
|
{
|
|
this.Ribbon.MergeRibbon(editor.ribbonMain);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.Ribbon.UnMergeRibbon();
|
|
}
|
|
this.EndUpdate();
|
|
}
|
|
|
|
if (document.Control is UCVtkEdit)
|
|
{
|
|
UCVtkEdit editor = document.Control as UCVtkEdit;
|
|
if (this.ActiveFloatDocument != null)
|
|
{
|
|
UCVtkEdit editorFloat = this.ActiveFloatDocument.Control as UCVtkEdit;
|
|
if (object.ReferenceEquals(editor, editorFloat))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
this.BeginUpdate();
|
|
if (editor != null)
|
|
{
|
|
if (!object.ReferenceEquals(this.Ribbon.MergedRibbon, editor.RibbonControlMain))
|
|
{
|
|
this.Ribbon.MergeRibbon(editor.RibbonControlMain);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.Ribbon.UnMergeRibbon();
|
|
}
|
|
this.EndUpdate();
|
|
}
|
|
|
|
OtherDocumentActivated?.Invoke(this, new DocumentEventArgs(document));
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override bool OnBeginDocking(BaseDocument document)
|
|
{
|
|
if (this.InvalidDocumentTypes.Contains(document.Control.GetType()))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return base.OnBeginDocking(document);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override void OnEndDocking(BaseDocument document)
|
|
{
|
|
BeginUpdate();
|
|
if (document.Control is UCDrawEdit editor)
|
|
{
|
|
this.Ribbon.MergeRibbon(editor.ribbonMain);
|
|
}
|
|
else if (document.Control is UCVtkEdit vtkEditor)
|
|
{
|
|
this.Ribbon.MergeRibbon(vtkEditor.RibbonControlMain);
|
|
}
|
|
else
|
|
{
|
|
this.Ribbon.UnMergeRibbon();
|
|
}
|
|
|
|
base.OnEndDocking(document);
|
|
this.EndUpdate();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override void OnFloating(BaseDocument document)
|
|
{
|
|
// this.BeginUpdate();
|
|
base.OnFloating(document);
|
|
|
|
if (document.Control is UCDrawEdit editor)
|
|
{
|
|
editor.ribbonMain.Dock = DockStyle.Top;
|
|
editor.ribbonMain.SendToBack();
|
|
}
|
|
|
|
if (document.Control is UCVtkEdit vtkEditor)
|
|
{
|
|
vtkEditor.RibbonControlMain.Dock = DockStyle.Top;
|
|
vtkEditor.RibbonControlMain.SendToBack();
|
|
}
|
|
// this.EndUpdate();
|
|
}
|
|
/// <summary>
|
|
/// 获得临近的文档
|
|
/// </summary>
|
|
/// <param name="documents">文档集合</param>
|
|
/// <param name="document">当前文档</param>
|
|
/// <returns>临近的文档</returns>
|
|
protected BaseDocument GetNeighborDocument(BaseDocument[] documents, BaseDocument document)
|
|
{
|
|
int nLength = documents.Length;
|
|
if (nLength == 1)
|
|
{
|
|
return null;
|
|
}
|
|
int nIndex = Array.IndexOf<BaseDocument>(documents, document);
|
|
if (nIndex == nLength - 1)
|
|
{
|
|
return documents[nIndex - 1];
|
|
}
|
|
return documents[nIndex + 1];
|
|
}
|
|
}
|
|
}
|