private void CalculateTabs_Document()
{
if (this.m_startDisplayingTab >= Tabs.Count)
this.m_startDisplayingTab = 0;
Rectangle rectTabStrip = this.TabsRectangle;
int x = rectTabStrip.X + rectTabStrip.Height / 2;
bool overflow = false;
// Originally all new documents that were considered overflow
// (not enough pane strip space to show all tabs) were added to
// the far left (assuming not right to left) and the tabs on the
// right were dropped from view. If StartDisplayingTab is not 0
// then we are dealing with making sure a specific tab is kept in focus.
if (this.m_startDisplayingTab > 0)
{
int tempX = x;
var tab = Tabs[this.m_startDisplayingTab] as TabVS2005;
tab.MaxWidth = this.GetMaxTabWidth(this.m_startDisplayingTab);
// Add the active tab and tabs to the left
for (int i = this.StartDisplayingTab; i >= 0; i--)
this.CalculateDocumentTab(rectTabStrip, ref tempX, i);
// Store which tab is the first one displayed so that it
// will be drawn correctly (without part of the tab cut off)
this.FirstDisplayingTab = this.EndDisplayingTab;
tempX = x; // Reset X location because we are starting over
// Start with the first tab displayed - name is a little misleading.
// Loop through each tab and set its location. If there is not enough
// room for all of them overflow will be returned.
for (int i = this.EndDisplayingTab; i < Tabs.Count; i++)
overflow = this.CalculateDocumentTab(rectTabStrip, ref tempX, i);
// If not all tabs are shown then we have an overflow.
if (this.FirstDisplayingTab != 0)
overflow = true;
}
else
{
for (int i = this.StartDisplayingTab; i < Tabs.Count; i++)
overflow = this.CalculateDocumentTab(rectTabStrip, ref x, i);
for (int i = 0; i < this.StartDisplayingTab; i++)
overflow = this.CalculateDocumentTab(rectTabStrip, ref x, i);
this.FirstDisplayingTab = this.StartDisplayingTab;
}
if (!overflow)
{
this.m_startDisplayingTab = 0;
this.FirstDisplayingTab = 0;
x = rectTabStrip.X + rectTabStrip.Height / 2;
foreach (TabVS2005 tab in Tabs)
{
tab.TabX = x;
x += tab.TabWidth;
}
}
this.DocumentTabsOverflow = overflow;
}