
1. Open Properly if all tabs are closed 2. Open to a full window view 3. Set Current Item in the Tab Control Fixed Display Panel so that when you click on an item in an inactive panel, the item clicked-on become the selected item.
226 lines
6.3 KiB
C#
226 lines
6.3 KiB
C#
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<string, DisplayTabItem> _MyPages;
|
|
public event DisplayPanelEvent ItemClick;
|
|
private List<DisplayTabItem> _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<DisplayTabItem>();
|
|
Dock = DockStyle.Fill;
|
|
dotNetBarManager1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
|
|
_MyPages = new Dictionary<string, DisplayTabItem>();
|
|
SetupBar(_MyBar);
|
|
dotNetBarManager1.BarTearOff += new EventHandler(dotNetBarManager1_BarTearOff);
|
|
}
|
|
void dotNetBarManager1_BarTearOff(object sender, EventArgs e)
|
|
{
|
|
Bar myBar = sender as Bar;
|
|
myBar.Enter += new EventHandler(myBar_Enter);
|
|
}
|
|
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();
|
|
}
|
|
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);
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
private int _UniqueBarCount;
|
|
public DevComponents.DotNetBar.Bar MyBar
|
|
{
|
|
get { return _MyBar; }
|
|
}
|
|
public DisplayTabItem SelectedTab
|
|
{
|
|
get { return (DisplayTabItem)_MyBar.SelectedDockContainerItem; }
|
|
set
|
|
{
|
|
if (value != null)
|
|
{
|
|
value.Focus();
|
|
value.Selected = true;
|
|
}
|
|
}
|
|
}
|
|
public DisplayTabItem OpenItem(ItemInfo myItem)
|
|
{
|
|
while (_RemovedItems.Count > 0)
|
|
{
|
|
DisplayTabItem myTabItem = _RemovedItems[0];
|
|
_RemovedItems.RemoveAt(0);
|
|
RemoveItem(myTabItem);
|
|
}
|
|
_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)
|
|
{
|
|
if(myBar == null)myBar = b;
|
|
foreach (object itm in b.Items)
|
|
{
|
|
DisplayTabItem myTabItem = itm as DisplayTabItem;
|
|
if (myTabItem != null && myTabItem.MyTabPanel != null)
|
|
if (myTabItem.MyTabPanel.MyItem.ItemID == myItem.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;
|
|
}
|
|
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
|
|
_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
|
|
if(myItem.MyTabPanel!=null)
|
|
myItem.MyTabPanel.Dispose();
|
|
if (myItem.MyDSOTabPanel != null)
|
|
myItem.MyDSOTabPanel.CloseDSO();
|
|
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
|
|
{
|
|
if (DSOTabPanel.Count > 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, myItem,key); // Open a new Procedure Tab
|
|
_MyPages.Add(key, pg);
|
|
}
|
|
SelectedTab = pg;
|
|
return pg;
|
|
}
|
|
}
|
|
}
|