using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using VEPROMS.CSLA.Library; using Volian.Controls.Library; using DevComponents.DotNetBar; namespace Volian.Controls.Library { public partial class DisplayTabControl : UserControl { private Dictionary _MyPages; public event DisplayPanelEvent ItemClick; private List _RemovedItems = null; internal void OnItemClick(object sender, DisplayPanelEventArgs args) { if (ItemClick != null) ItemClick(sender, args); } public event DisplayPanelEvent ItemSelectedChanged; internal void OnItemSelectedChanged(object sender, DisplayPanelEventArgs args) { if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args); } public DisplayTabControl() { InitializeComponent(); SetUp(); } private void SetUp() { _RemovedItems = new List(); Dock = DockStyle.Fill; dotNetBarManager1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2007; _MyPages = new Dictionary(); //dotNetBarManager1.DockTabClosing += new DevComponents.DotNetBar.DockTabClosingEventHandler(dotNetBarManager1_DockTabClosing); //_MyBar.DockTabControl.CloseButtonOnTabsAlwaysDisplayed = true; SetupBar(_MyBar); dotNetBarManager1.BarTearOff += new EventHandler(dotNetBarManager1_BarTearOff); } void dotNetBarManager1_BarTearOff(object sender, EventArgs e) { Bar myBar = sender as Bar; //SetupBar(myBar); myBar.Enter += new EventHandler(myBar_Enter); } //private void ShowPG(object myObject) //{ //frmPropGridTest tmp = new frmPropGridTest(myObject); //tmp.Show(); //} private void SetupBar(Bar myBar) { if (myBar.DockTabControl != null) { myBar.DockTabControl.CloseButtonOnTabsVisible = true; myBar.DockTabControl.CloseButtonVisible = false; myBar.DockTabControl.CloseButtonPosition = DevComponents.DotNetBar.eTabCloseButtonPosition.Right; myBar.DockTabControl.Width = ClientRectangle.Width; //ShowPG(myBar); //ShowPG(myBar.DockTabControl); } myBar.DockTabClosing += new DockTabClosingEventHandler(myBar_DockTabClosing); if (!myBar.Visible) myBar.Visible = true; myBar.RecalcLayout(); } void myBar_Enter(object sender, EventArgs e) { Bar myBar = sender as Bar; myBar.Enter -= new EventHandler(myBar_Enter); SetupBar(sender as Bar); } void myBar_DockTabClosing(object sender, DockTabClosingEventArgs e) { e.RemoveDockTab = true; _RemovedItems.Add((DisplayTabItem)e.DockContainerItem); //RemoveItem((DisplayTabItem)e.DockContainerItem); if (((Bar)sender).Items.Count == 1)// Remove bar if last item is closed... { dotNetBarManager1.Bars.Remove((Bar)sender); ActivateRemainingTab(); } } private void ActivateRemainingTab() { foreach (Bar myBar in dotNetBarManager1.Bars) { if (myBar.DockSide == eDockSide.Document && myBar.Visible) { myBar.SelectedDockContainerItem.Selected = true; } } // No Document Tabs Remaining - need to raise OnItemSelectedChanged OnItemSelectedChanged(this, null); } private Bar GetFirstDocumentBar() { foreach (Bar b in dotNetBarManager1.Bars) { if (b.DockSide == eDockSide.Document && b.Visible) return b; } // If no documents bars found, create new one //_UniqueBarCount++; Bar bar = BarUtilities.CreateDocumentBar(); //bar.DockTabClosing += new DockTabClosingEventHandler(DocumentBar_DockTabClosing); //bar.Name = "barDocuments" + m_UniqueBarCount.ToString(); fillDocDockSite.GetDocumentUIManager().Dock(bar); SetupBar(bar); return bar; } //void dotNetBarManager1_DockTabClosing(object sender, DevComponents.DotNetBar.DockTabClosingEventArgs e) //{ // e.RemoveDockTab = true; // _RemovedItems.Add((DisplayTabItem)e.DockContainerItem); // //RemoveItem((DisplayTabItem)e.DockContainerItem); // if (((Bar)sender).Items.Count == 1) // Remove bar if last item is closed... // dotNetBarManager1.Bars.Remove((Bar)sender); //} public DevComponents.DotNetBar.Bar MyBar { get { return _MyBar; } } public DisplayTabItem SelectedTab { get { return (DisplayTabItem)_MyBar.SelectedDockContainerItem; } set { if (value != null) value.Selected = true; } } public DisplayTabItem OpenItem(ItemInfo myItem) { while (_RemovedItems.Count > 0) { DisplayTabItem tabItem = _RemovedItems[0]; _RemovedItems.RemoveAt(0); RemoveItem(tabItem); } _MyBar = GetParentBar(myItem); if (myItem.MyContent.MyEntry == null) return OpenDisplayTabPage(myItem); else return OpenDSOTabPage(myItem); } private Bar GetParentBar(ItemInfo myItem) { Bar myBar = null; foreach (Bar b in dotNetBarManager1.Bars) { if (b.DockSide == eDockSide.Document && b.Visible) { myBar = b; foreach (object itm in myBar.Items) { DisplayTabItem myTabItem = itm as DisplayTabItem; if (myTabItem != null && myTabItem.MyTabPanel != null) if (myTabItem.MyTabPanel.MyItem.ItemID == myItem.MyProcedure.ItemID) return myBar; } } } if (myBar == null) { // If no documents bars found, create new one //_UniqueBarCount++; myBar = BarUtilities.CreateDocumentBar(); //bar.DockTabClosing += new DockTabClosingEventHandler(DocumentBar_DockTabClosing); //bar.Name = "barDocuments" + m_UniqueBarCount.ToString(); fillDocDockSite.GetDocumentUIManager().Dock(myBar); SetupBar(myBar); } return myBar; } private DisplayTabItem OpenDisplayTabPage(ItemInfo myItem) { ItemInfo proc = myItem.MyProcedure; // Find procedure Item string key = "Item - " + proc.ItemID.ToString(); DisplayTabItem pg = null; if (_MyPages.ContainsKey(key)) // If Procedure Open use it { pg = _MyPages[key]; pg.Selected = true; //SelectedTab = pg; } else { pg = new DisplayTabItem(this.components, this, proc, key); // Open a new Procedure Tab //_MyBar.Items.Add(pg); _MyPages.Add(key, pg); pg.Selected = true; //SelectedTab = pg; pg.MyTabPanel.MyItem = proc; } Application.DoEvents(); pg.ItemSelected = myItem; // Select the item #if (DEBUG) pg.MyTabPanel.MyPanel.BackColor = SystemColors.Control; #else pg.MyTabPanel.MyPanel.BackColor = Color.White; #endif return pg; } internal void RemoveItem(DisplayTabItem myItem) { _MyPages.Remove(myItem.MyKey); // Can I dispose the Panel myItem.MyTabPanel.Dispose(); //myItem.Name = null; components.Remove(myItem); myItem.Dispose(); } private DisplayTabItem OpenDSOTabPage(ItemInfo myItem) { DisplayTabItem pg = null; EntryInfo myEntry = myItem.MyContent.MyEntry; string key = "Doc - " + myEntry.DocID; if (_MyPages.ContainsKey(key)) // If Procedure Open use it pg = _MyPages[key]; else { pg = new DisplayTabItem(this.components, this, myItem,key); // Open a new Procedure Tab _MyPages.Add(key, pg); } SelectedTab = pg; return pg; } } }