// // Copyright (c) PlaceholderCompany. All rights reserved. // 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 { /// /// 多文档视图 /// public class DrawerTabbedView : TabbedView { /// /// 允许停靠的类型 /// public List InvalidDocumentTypes { get; set; } = new List(); /// /// Occurs when [other document activated]. /// public DocumentEventHandler OtherDocumentActivated { get; set; } /// /// Ribbon控件 /// public RibbonControl Ribbon { get; set; } /// /// Initializes a new instance of the class. /// /// 父容器 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; } /// /// Drawers the tabbed view_ document removed. /// /// The sender. /// The e. private void DrawerTabbedView_DocumentRemoved(object sender, DocumentEventArgs e) { //disposeControls(e); } /// /// Drawers the tabbed view_ showing dock guides. /// /// The sender. /// The e. 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); } /// /// Drawers the tabbed view_ document closed. /// /// The sender. /// The e. private void DrawerTabbedView_DocumentClosed(object sender, DocumentEventArgs e) { disposeControls(e); } /// /// 销毁控件内容. /// /// The e. 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; } } /// 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); } /// 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)); } /// protected override bool OnBeginDocking(BaseDocument document) { if (this.InvalidDocumentTypes.Contains(document.Control.GetType())) { return false; } return base.OnBeginDocking(document); } /// 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(); } /// 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(); } /// /// 获得临近的文档 /// /// 文档集合 /// 当前文档 /// 临近的文档 protected BaseDocument GetNeighborDocument(BaseDocument[] documents, BaseDocument document) { int nLength = documents.Length; if (nLength == 1) { return null; } int nIndex = Array.IndexOf(documents, document); if (nIndex == nLength - 1) { return documents[nIndex - 1]; } return documents[nIndex + 1]; } } }