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 { #region Private Fields /// /// This is a lookup table for all of the DisplayTabItems that are currently open /// The key is: /// "Item - " + Procedure ItemID for step pages /// "Doc - " + DocumentID for Word Documents /// private Dictionary _MyDisplayTabItems; /// /// When a Tab is closed it is added to this list. /// When another Tab is opened, any Tabs in this list are closed /// private List _RemovedDisplayTabItems = null; /// /// This stores a UniqueID for Bars as they are opened. /// A bar is the docking location for the DisplayTabItems. /// private int _UniqueBarCount; #endregion #region Events /// /// This event is raised when a the "Tab" of a DisplayItem is clicked with a mouse. /// So far this has just been used for demo purposes. It could be used to select a /// step and it's children for the purpose of copying. /// public event StepPanelEvent ItemClick; /// /// Checks to see if the ItemClick event is handled and launches it /// /// /// internal void OnItemClick(object sender, StepPanelEventArgs args) { if (ItemClick != null) ItemClick(sender, args); } /// /// This occurs when the user moves onto or off of a link within a RichTextBox /// or moves between RichTextBoxes or Pages. /// public event StepPanelLinkEvent LinkActiveChanged; /// /// Checks to see if the LinkActiveChanged event is handled and launches it /// /// /// internal void OnLinkActiveChanged(object sender, StepPanelLinkEventArgs args) { if (LinkActiveChanged != null) LinkActiveChanged(sender, args); else MessageBox.Show(args.LinkInfoText, "Unhandled Link Active Changed", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// /// This occurs when a Transition is inserted /// public event StepPanelLinkEvent LinkInsertTran; /// /// Checks to see if the 'LinkInsertTran' event is handled and launches it /// /// /// internal void OnLinkInsertTran(object sender, StepPanelLinkEventArgs args) { if (LinkInsertTran != null) LinkInsertTran(sender, args); else MessageBox.Show(args.LinkInfoText, "Unhandled Link Insert Tran", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// /// This occurs when an RO is inserted /// public event StepPanelLinkEvent LinkInsertRO; /// /// Checks to see if the 'LinkInsertRO' event is handled and launches it /// /// /// internal void OnLinkInsertRO(object sender, StepPanelLinkEventArgs args) { if (LinkInsertRO != null) LinkInsertRO(sender, args); else MessageBox.Show(args.LinkInfoText, "Unhandled Link Insert RO", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// /// This occurs when a Transition is modified /// public event StepPanelLinkEvent LinkModifyTran; /// /// Checks to see if the 'LinkModifyTran' event is handled and launches it /// /// /// internal void OnLinkModifyTran(object sender, StepPanelLinkEventArgs args) { if (LinkModifyTran != null) LinkModifyTran(sender, args); else MessageBox.Show(args.LinkInfoText, "Unhandled Link Modify Tran", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// /// This occurs when an RO is modified /// public event StepPanelLinkEvent LinkModifyRO; /// /// Checks to see if the 'LinkModifyRO' event is handled and launches it /// /// /// internal void OnLinkModifyRO(object sender, StepPanelLinkEventArgs args) { if (LinkModifyRO != null) LinkModifyRO(sender, args); else MessageBox.Show(args.LinkInfoText, "Unhandled Link Modify RO", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// /// Occurs when the user selects a different item or page /// public event StepPanelEvent ItemSelectedChanged; /// /// Checks to see if the 'ItemSelectedChanged' event is handled and launches it /// /// /// internal void OnItemSelectedChanged(object sender, StepPanelEventArgs args) { if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args); } #endregion #region Contructor & Setup public DisplayTabControl() { InitializeComponent(); SetUp(); } private void SetUp() { _RemovedDisplayTabItems = new List(); Dock = DockStyle.Fill; dotNetBarManager1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2007; _MyDisplayTabItems = new Dictionary(); SetupBar(_MyBar); dotNetBarManager1.BarTearOff += new EventHandler(dotNetBarManager1_BarTearOff); } 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; } myBar.DockTabClosing += new DockTabClosingEventHandler(myBar_DockTabClosing); if (!myBar.Visible) myBar.Visible = true; myBar.RecalcLayout(); } #endregion #region Internal Event Handlers /// /// This is code recommended by DotNetBar /// /// /// void dotNetBarManager1_BarTearOff(object sender, EventArgs e) { Bar myBar = sender as Bar; myBar.Enter += new EventHandler(myBar_Enter); } /// /// This sets-up the bar after it is selected. /// /// /// void myBar_Enter(object sender, EventArgs e) { Bar myBar = sender as Bar; myBar.Enter -= new EventHandler(myBar_Enter); SetupBar(sender as Bar); } /// /// This handles the closing of a document page /// /// /// void myBar_DockTabClosing(object sender, DockTabClosingEventArgs e) { e.RemoveDockTab = true; _RemovedDisplayTabItems.Add((DisplayTabItem)e.DockContainerItem); DisplayTabItem myTabItem = e.DockContainerItem as DisplayTabItem; if (myTabItem != null) { if (myTabItem.MyDSOTabPanel != null) { myTabItem.MyDSOTabPanel.CloseDSO(); } } if (((Bar)sender).Items.Count == 1)// Remove bar if last item is closed... { Bar bar = sender as Bar; if (bar != null) { if(dotNetBarManager1.Bars.Contains(bar.Name)) dotNetBarManager1.Bars.Remove(bar); ActivateRemainingTab(); } } } #endregion #region Public Methods /// /// Open a Step Item or a Word Item /// /// /// public DisplayTabItem OpenItem(ItemInfo myItemInfo) { while (_RemovedDisplayTabItems.Count > 0) // Clean-up any items that have been closed. { DisplayTabItem myTabItem = _RemovedDisplayTabItems[0]; _RemovedDisplayTabItems.RemoveAt(0); RemoveItem(myTabItem); } _MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item. if (myItemInfo.MyContent.MyEntry == null) // If it is a Word document open it in Word return OpenStepTabPage(myItemInfo); else // Otherwise open it in the step editor return OpenDSOTabPage(myItemInfo); } /// /// Look for a tab and set it to active. /// private void ActivateRemainingTab() { foreach (Bar myBar in dotNetBarManager1.Bars) { if (myBar.DockSide == eDockSide.Document && myBar.Visible) { if (myBar.SelectedDockContainerItem != null) { myBar.SelectedDockContainerItem.Selected = true; } } } // No Document Tabs Remaining - need to raise OnItemSelectedChanged OnItemSelectedChanged(this, null); } #endregion #region Public Properties public DevComponents.DotNetBar.Bar MyBar { get { return _MyBar; } } #endregion #region Private Methods /// /// Gets and sets the SelectedDisplayTabItem (Active Tab) /// public DisplayTabItem SelectedDisplayTabItem { get { return (DisplayTabItem)_MyBar.SelectedDockContainerItem; } set { if (value != null) { value.Focus(); value.Selected = true; } } } /// /// This returns the parent bar (current docking location) for an item. /// It creates a bar if none exist /// /// /// private Bar GetParentBar(ItemInfo myItemInfo) { Bar myBar = null; foreach (Bar b in dotNetBarManager1.Bars) { if (b.DockSide == eDockSide.Document && b.Visible) { if(myBar == null)myBar = b;// Remember the first available bar if a specific bar cannot be found foreach (object itm in b.Items) { DisplayTabItem myTabItem = itm as DisplayTabItem; if (myTabItem != null && myTabItem.MyStepTabPanel != null) if (myTabItem.MyStepTabPanel.MyProcedureItemInfo.ItemID == myItemInfo.MyProcedure.ItemID) return b; } } } if (myBar == null) { // If no documents bars found, create new one _UniqueBarCount++; myBar = BarUtilities.CreateDocumentBar(); myBar.DockTabClosing +=new DockTabClosingEventHandler(myBar_DockTabClosing); myBar.Name = "barDocuments" + _UniqueBarCount.ToString(); fillDocDockSite.GetDocumentUIManager().Dock(myBar); SetupBar(myBar); } return myBar; } /// /// This opens a Step page based upon a ItemInfo. /// /// /// /// private DisplayTabItem OpenStepTabPage(ItemInfo myItemInfo) { ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item string key = "Item - " + proc.ItemID.ToString(); DisplayTabItem pg = null; if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it { pg = _MyDisplayTabItems[key]; pg.Selected = true; SelectedDisplayTabItem = pg; } else // If not already open, create a new Page { pg = new DisplayTabItem(this.components, this, proc, key); // Open a new Procedure Tab _MyDisplayTabItems.Add(key, pg); pg.Selected = true; SelectedDisplayTabItem = pg; pg.MyStepTabPanel.MyProcedureItemInfo = proc; } Application.DoEvents(); pg.SelectedItemInfo = myItemInfo; // Select the item #if (DEBUG) pg.MyStepTabPanel.MyStepPanel.BackColor = SystemColors.Control; #else pg.MyTabPanel.MyPanel.BackColor = Color.White; #endif return pg; } /// /// This opens a Word page based upon an itemInfo. Since a word document may be a library /// document, the related DocID is used for the Word document. /// /// /// private DisplayTabItem OpenDSOTabPage(ItemInfo myItemInfo) { DisplayTabItem pg = null; EntryInfo myEntry = myItemInfo.MyContent.MyEntry; string key = "Doc - " + myEntry.DocID; if (_MyDisplayTabItems.ContainsKey(key)) // If document page open use it pg = _MyDisplayTabItems[key]; else { if (DSOTabPanel.Count > 18) // Limit the number of open document pages to 18 { MessageBox.Show("Too many Word Documents Open. Please close one of the Documents before attempting to open another"); return null; } pg = new DisplayTabItem(this.components, this, myItemInfo,key); // Open a new document page _MyDisplayTabItems.Add(key, pg); } SelectedDisplayTabItem = pg; return pg; } /// /// Clean-up after a page is closed /// /// internal void RemoveItem(DisplayTabItem myDisplayTabItem) { _MyDisplayTabItems.Remove(myDisplayTabItem.MyKey); // Dispose the Panel if(myDisplayTabItem.MyStepTabPanel!=null) myDisplayTabItem.MyStepTabPanel.Dispose(); if (myDisplayTabItem.MyDSOTabPanel != null) myDisplayTabItem.MyDSOTabPanel.CloseDSO(); components.Remove(myDisplayTabItem); myDisplayTabItem.Dispose(); } #endregion } }