Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/WinFormsUI/Docking/VS2005DockPaneStrip.cs @ 4539

Last change on this file since 4539 was 2134, checked in by gkronber, 15 years ago

Added up to date source of Weifen Luo dock panel suit in a separate project (and added strong name key). Removed binary versions of Weifen Luo dock panel suite and references to it. #687 (Update AdvancedOptimizationFrontend to use more recent version of Weifen Luo Docking library)

File size: 54.0 KB
Line 
1using System;
2using System.Drawing;
3using System.Drawing.Drawing2D;
4using System.Windows.Forms;
5using System.ComponentModel;
6using System.Collections;
7using System.Collections.Generic;
8
9namespace WeifenLuo.WinFormsUI.Docking
10{
11  internal class VS2005DockPaneStrip : DockPaneStripBase
12  {
13        private class TabVS2005 : Tab
14        {
15            public TabVS2005(IDockContent content)
16                : base(content)
17            {
18            }
19
20            private int m_tabX;
21            public int TabX
22            {
23                get { return m_tabX; }
24                set { m_tabX = value; }
25            }
26
27            private int m_tabWidth;
28            public int TabWidth
29            {
30                get { return m_tabWidth; }
31                set { m_tabWidth = value; }
32            }
33
34            private int m_maxWidth;
35            public int MaxWidth
36            {
37                get { return m_maxWidth; }
38                set { m_maxWidth = value; }
39            }
40
41            private bool m_flag;
42            protected internal bool Flag
43            {
44                get { return m_flag; }
45                set { m_flag = value; }
46            }
47        }
48
49        protected internal override DockPaneStripBase.Tab CreateTab(IDockContent content)
50        {
51            return new TabVS2005(content);
52        }
53
54        private sealed class InertButton : InertButtonBase
55        {
56            private Bitmap m_image0, m_image1;
57
58            public InertButton(Bitmap image0, Bitmap image1)
59                : base()
60            {
61                m_image0 = image0;
62                m_image1 = image1;
63            }
64
65            private int m_imageCategory = 0;
66            public int ImageCategory
67            {
68                get { return m_imageCategory; }
69                set
70                {
71                    if (m_imageCategory == value)
72                        return;
73
74                    m_imageCategory = value;
75                    Invalidate();
76                }
77            }
78
79            public override Bitmap Image
80            {
81                get { return ImageCategory == 0 ? m_image0 : m_image1; }
82            }
83        }
84
85    #region consts
86        private const int _ToolWindowStripGapTop = 0;
87        private const int _ToolWindowStripGapBottom = 1;
88    private const int _ToolWindowStripGapLeft = 0;
89    private const int _ToolWindowStripGapRight = 0;
90    private const int _ToolWindowImageHeight = 16;
91    private const int _ToolWindowImageWidth = 16;
92    private const int _ToolWindowImageGapTop = 3;
93    private const int _ToolWindowImageGapBottom = 1;
94    private const int _ToolWindowImageGapLeft = 2;
95    private const int _ToolWindowImageGapRight = 0;
96    private const int _ToolWindowTextGapRight = 3;
97    private const int _ToolWindowTabSeperatorGapTop = 3;
98    private const int _ToolWindowTabSeperatorGapBottom = 3;
99
100        private const int _DocumentStripGapTop = 0;
101        private const int _DocumentStripGapBottom = 1;
102    private const int _DocumentTabMaxWidth = 200;
103    private const int _DocumentButtonGapTop = 4;
104    private const int _DocumentButtonGapBottom = 4;
105    private const int _DocumentButtonGapBetween = 0;
106    private const int _DocumentButtonGapRight = 3;
107    private const int _DocumentTabGapTop = 3;
108    private const int _DocumentTabGapLeft = 3;
109    private const int _DocumentTabGapRight = 3;
110        private const int _DocumentIconGapBottom = 2;
111    private const int _DocumentIconGapLeft = 8;
112        private const int _DocumentIconGapRight = 0;
113    private const int _DocumentIconHeight = 16;
114    private const int _DocumentIconWidth = 16;
115        private const int _DocumentTextGapRight = 3;
116    #endregion
117
118        private static Bitmap _imageButtonClose;
119        private static Bitmap ImageButtonClose
120        {
121            get
122            {
123                if (_imageButtonClose == null)
124                    _imageButtonClose = Resources.DockPane_Close;
125
126                return _imageButtonClose;
127            }
128        }
129
130        private InertButton m_buttonClose;
131        private InertButton ButtonClose
132        {
133            get
134            {
135                if (m_buttonClose == null)
136                {
137                    m_buttonClose = new InertButton(ImageButtonClose, ImageButtonClose);
138                    m_toolTip.SetToolTip(m_buttonClose, ToolTipClose);
139                    m_buttonClose.Click += new EventHandler(Close_Click);
140                    Controls.Add(m_buttonClose);
141                }
142
143                return m_buttonClose;
144            }
145        }
146
147        private static Bitmap _imageButtonWindowList;
148        private static Bitmap ImageButtonWindowList
149        {
150            get
151            {
152                if (_imageButtonWindowList == null)
153                    _imageButtonWindowList = Resources.DockPane_Option;
154
155                return _imageButtonWindowList;
156            }
157        }
158
159        private static Bitmap _imageButtonWindowListOverflow;
160        private static Bitmap ImageButtonWindowListOverflow
161        {
162            get
163            {
164                if (_imageButtonWindowListOverflow == null)
165                    _imageButtonWindowListOverflow = Resources.DockPane_OptionOverflow;
166
167                return _imageButtonWindowListOverflow;
168            }
169        }
170
171        private InertButton m_buttonWindowList;
172        private InertButton ButtonWindowList
173        {
174            get
175            {
176                if (m_buttonWindowList == null)
177                {
178                    m_buttonWindowList = new InertButton(ImageButtonWindowList, ImageButtonWindowListOverflow);
179                    m_toolTip.SetToolTip(m_buttonWindowList, ToolTipSelect);
180                    m_buttonWindowList.Click += new EventHandler(WindowList_Click);
181                    Controls.Add(m_buttonWindowList);
182                }
183
184                return m_buttonWindowList;
185            }
186        }
187
188        private static GraphicsPath GraphicsPath
189        {
190            get { return VS2005AutoHideStrip.GraphicsPath; }
191        }
192
193    private IContainer m_components;
194    private ToolTip m_toolTip;
195    private IContainer Components
196    {
197      get { return m_components;  }
198    }
199
200    #region Customizable Properties
201        private static int ToolWindowStripGapTop
202        {
203            get { return _ToolWindowStripGapTop; }
204        }
205
206        private static int ToolWindowStripGapBottom
207        {
208            get { return _ToolWindowStripGapBottom; }
209        }
210
211    private static int ToolWindowStripGapLeft
212    {
213      get { return _ToolWindowStripGapLeft; }
214    }
215
216    private static int ToolWindowStripGapRight
217    {
218      get { return _ToolWindowStripGapRight;  }
219    }
220
221    private static int ToolWindowImageHeight
222    {
223      get { return _ToolWindowImageHeight;  }
224    }
225
226    private static int ToolWindowImageWidth
227    {
228      get { return _ToolWindowImageWidth; }
229    }
230
231    private static int ToolWindowImageGapTop
232    {
233      get { return _ToolWindowImageGapTop;  }
234    }
235
236    private static int ToolWindowImageGapBottom
237    {
238      get { return _ToolWindowImageGapBottom; }
239    }
240
241    private static int ToolWindowImageGapLeft
242    {
243      get { return _ToolWindowImageGapLeft; }
244    }
245
246    private static int ToolWindowImageGapRight
247    {
248      get { return _ToolWindowImageGapRight;  }
249    }
250
251    private static int ToolWindowTextGapRight
252    {
253      get { return _ToolWindowTextGapRight; }
254    }
255
256    private static int ToolWindowTabSeperatorGapTop
257    {
258      get { return _ToolWindowTabSeperatorGapTop; }
259    }
260
261    private static int ToolWindowTabSeperatorGapBottom
262    {
263      get { return _ToolWindowTabSeperatorGapBottom;  }
264    }
265
266    private static string _toolTipClose;
267    private static string ToolTipClose
268    {
269      get
270      {
271        if (_toolTipClose == null)
272          _toolTipClose = Strings.DockPaneStrip_ToolTipClose;
273        return _toolTipClose;
274      }
275    }
276
277    private static string _toolTipSelect;
278    private static string ToolTipSelect
279    {
280      get
281      {
282        if (_toolTipSelect == null)
283          _toolTipSelect = Strings.DockPaneStrip_ToolTipWindowList;
284        return _toolTipSelect;
285      }
286    }
287
288    private TextFormatFlags ToolWindowTextFormat
289    {
290      get
291            {
292                TextFormatFlags textFormat = TextFormatFlags.EndEllipsis |
293                    TextFormatFlags.HorizontalCenter |
294                    TextFormatFlags.SingleLine |
295                    TextFormatFlags.VerticalCenter;
296                if (RightToLeft == RightToLeft.Yes)
297                    return textFormat | TextFormatFlags.RightToLeft | TextFormatFlags.Right;
298                else
299                    return textFormat;
300            }
301    }
302
303        private static int DocumentStripGapTop
304        {
305            get { return _DocumentStripGapTop; }
306        }
307
308        private static int DocumentStripGapBottom
309        {
310            get { return _DocumentStripGapBottom; }
311        }
312
313    private TextFormatFlags DocumentTextFormat
314    {
315          get
316            {
317                TextFormatFlags textFormat = TextFormatFlags.EndEllipsis |
318                    TextFormatFlags.SingleLine |
319                    TextFormatFlags.VerticalCenter |
320                    TextFormatFlags.HorizontalCenter;
321                if (RightToLeft == RightToLeft.Yes)
322                    return textFormat | TextFormatFlags.RightToLeft;
323                else
324                    return textFormat;
325            }
326    }
327
328    private static int DocumentTabMaxWidth
329    {
330      get { return _DocumentTabMaxWidth;  }
331    }
332
333    private static int DocumentButtonGapTop
334    {
335      get { return _DocumentButtonGapTop; }
336    }
337
338    private static int DocumentButtonGapBottom
339    {
340      get { return _DocumentButtonGapBottom;  }
341    }
342
343    private static int DocumentButtonGapBetween
344    {
345      get { return _DocumentButtonGapBetween; }
346    }
347
348    private static int DocumentButtonGapRight
349    {
350      get { return _DocumentButtonGapRight; }
351    }
352
353    private static int DocumentTabGapTop
354    {
355      get { return _DocumentTabGapTop;  }
356    }
357
358    private static int DocumentTabGapLeft
359    {
360      get { return _DocumentTabGapLeft; }
361    }
362
363    private static int DocumentTabGapRight
364    {
365      get { return _DocumentTabGapRight;  }
366    }
367
368        private static int DocumentIconGapBottom
369        {
370            get { return _DocumentIconGapBottom; }
371        }
372
373    private static int DocumentIconGapLeft
374    {
375            get { return _DocumentIconGapLeft; }
376    }
377
378        private static int DocumentIconGapRight
379        {
380            get { return _DocumentIconGapRight; }
381        }
382
383    private static int DocumentIconWidth
384    {
385      get { return _DocumentIconWidth;  }
386    }
387
388    private static int DocumentIconHeight
389    {
390      get { return _DocumentIconHeight; }
391    }
392
393        private static int DocumentTextGapRight
394        {
395            get { return _DocumentTextGapRight; }
396        }
397
398    private static Pen PenToolWindowTabBorder
399    {
400      get { return SystemPens.GrayText; }
401    }
402
403        private static Pen PenDocumentTabActiveBorder
404        {
405            get { return SystemPens.ControlDarkDark; }
406        }
407
408        private static Pen PenDocumentTabInactiveBorder
409        {
410            get { return SystemPens.GrayText; }
411        }
412    #endregion
413
414    public VS2005DockPaneStrip(DockPane pane) : base(pane)
415    {
416      SetStyle(ControlStyles.ResizeRedraw |
417                ControlStyles.UserPaint |
418                ControlStyles.AllPaintingInWmPaint |
419                ControlStyles.OptimizedDoubleBuffer, true);
420
421      SuspendLayout();
422
423      m_components = new Container();
424      m_toolTip = new ToolTip(Components);
425            m_selectMenu = new ContextMenuStrip(Components);
426
427      ResumeLayout();
428    }
429
430    protected override void Dispose(bool disposing)
431    {
432            if (disposing)
433            {
434                Components.Dispose();
435                if (m_boldFont != null)
436                {
437                    m_boldFont.Dispose();
438                    m_boldFont = null;
439                }
440            }
441      base.Dispose (disposing);
442    }
443
444        private static Font TextFont
445        {
446            get { return SystemInformation.MenuFont; }
447        }
448
449        private Font m_font;
450        private Font m_boldFont;
451        private Font BoldFont
452        {
453            get
454            {
455                if (IsDisposed)
456                    return null;
457
458                if (m_boldFont == null)
459                {
460                    m_font = TextFont;
461                    m_boldFont = new Font(TextFont, FontStyle.Bold);
462                }
463                else if (m_font != TextFont)
464                {
465                    m_boldFont.Dispose();
466                    m_font = TextFont;
467                    m_boldFont = new Font(TextFont, FontStyle.Bold);
468                }
469
470                return m_boldFont;
471            }
472        }
473
474        private int m_startDisplayingTab = 0;
475        private int StartDisplayingTab
476        {
477            get { return m_startDisplayingTab; }
478            set
479            {
480                m_startDisplayingTab = value;
481                Invalidate();
482            }
483        }
484
485        private int m_endDisplayingTab = 0;
486        private int EndDisplayingTab
487        {
488            get { return m_endDisplayingTab; }
489            set { m_endDisplayingTab = value; }
490        }
491
492        private int m_firstDisplayingTab = 0;
493        private int FirstDisplayingTab
494        {
495            get { return m_firstDisplayingTab; }
496            set { m_firstDisplayingTab = value; }
497        }
498
499        private bool m_documentTabsOverflow = false;
500        private bool DocumentTabsOverflow
501        {
502            set
503            {
504                if (m_documentTabsOverflow == value)
505                    return;
506
507                m_documentTabsOverflow = value;
508                if (value)
509                    ButtonWindowList.ImageCategory = 1;
510                else
511                    ButtonWindowList.ImageCategory = 0;
512            }
513        }
514
515    protected internal override int MeasureHeight()
516    {
517      if (Appearance == DockPane.AppearanceStyle.ToolWindow)
518        return MeasureHeight_ToolWindow();
519      else
520        return MeasureHeight_Document();
521    }
522
523    private int MeasureHeight_ToolWindow()
524    {
525      if (DockPane.IsAutoHide || Tabs.Count <= 1)
526        return 0;
527
528            int height = Math.Max(TextFont.Height, ToolWindowImageHeight + ToolWindowImageGapTop + ToolWindowImageGapBottom)
529                + ToolWindowStripGapTop + ToolWindowStripGapBottom;
530
531      return height;
532    }
533
534    private int MeasureHeight_Document()
535    {
536      int height = Math.Max(TextFont.Height + DocumentTabGapTop,
537        ButtonClose.Height + DocumentButtonGapTop + DocumentButtonGapBottom)
538                + DocumentStripGapBottom + DocumentStripGapTop;
539
540      return height;
541    }
542
543    protected override void OnPaint(PaintEventArgs e)
544    {
545            Rectangle rect = TabsRectangle;
546
547            if (Appearance == DockPane.AppearanceStyle.Document)
548            {
549                rect.X -= DocumentTabGapLeft;
550
551                // Add these values back in so that the DockStrip color is drawn
552                // beneath the close button and window list button.
553                rect.Width += DocumentTabGapLeft +
554                    DocumentTabGapRight +
555                    DocumentButtonGapRight +
556                    ButtonClose.Width +
557                    ButtonWindowList.Width;
558
559                // It is possible depending on the DockPanel DocumentStyle to have
560                // a Document without a DockStrip.
561                if (rect.Width > 0 && rect.Height > 0)
562                {
563                    Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.StartColor;
564                    Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.EndColor;
565                    LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.LinearGradientMode;
566                    using (LinearGradientBrush brush = new LinearGradientBrush(rect, startColor, endColor, gradientMode))
567                    {
568                        e.Graphics.FillRectangle(brush, rect);
569                    }
570                }
571            }
572            else
573            {
574                Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.StartColor;
575                Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.EndColor;
576                LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.LinearGradientMode;
577                using (LinearGradientBrush brush = new LinearGradientBrush(rect, startColor, endColor, gradientMode))
578                {
579                    e.Graphics.FillRectangle(brush, rect);
580                }
581            }
582      base.OnPaint (e);
583      CalculateTabs();
584            if (Appearance == DockPane.AppearanceStyle.Document && DockPane.ActiveContent != null)
585            {
586                if (EnsureDocumentTabVisible(DockPane.ActiveContent, false))
587                    CalculateTabs();
588            }
589
590      DrawTabStrip(e.Graphics);
591    }
592
593    protected override void OnRefreshChanges()
594    {
595      SetInertButtons();
596      Invalidate();
597    }
598
599    protected internal override GraphicsPath GetOutline(int index)
600    {
601
602            if (Appearance == DockPane.AppearanceStyle.Document)
603                return GetOutline_Document(index);
604            else
605                return GetOutline_ToolWindow(index);
606
607    }
608
609        private GraphicsPath GetOutline_Document(int index)
610        {
611            Rectangle rectTab = GetTabRectangle(index);
612            rectTab.X -= rectTab.Height / 2;
613            rectTab.Intersect(TabsRectangle);
614            rectTab = RectangleToScreen(DrawHelper.RtlTransform(this, rectTab));
615            Rectangle rectPaneClient = DockPane.RectangleToScreen(DockPane.ClientRectangle);
616
617            GraphicsPath path = new GraphicsPath();
618            GraphicsPath pathTab = GetTabOutline_Document(Tabs[index], true, true, true);
619            path.AddPath(pathTab, true);
620
621            if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
622            {
623                path.AddLine(rectTab.Right, rectTab.Top, rectPaneClient.Right, rectTab.Top);
624                path.AddLine(rectPaneClient.Right, rectTab.Top, rectPaneClient.Right, rectPaneClient.Top);
625                path.AddLine(rectPaneClient.Right, rectPaneClient.Top, rectPaneClient.Left, rectPaneClient.Top);
626                path.AddLine(rectPaneClient.Left, rectPaneClient.Top, rectPaneClient.Left, rectTab.Top);
627                path.AddLine(rectPaneClient.Left, rectTab.Top, rectTab.Right, rectTab.Top);
628            }
629            else
630            {
631                path.AddLine(rectTab.Right, rectTab.Bottom, rectPaneClient.Right, rectTab.Bottom);
632                path.AddLine(rectPaneClient.Right, rectTab.Bottom, rectPaneClient.Right, rectPaneClient.Bottom);
633                path.AddLine(rectPaneClient.Right, rectPaneClient.Bottom, rectPaneClient.Left, rectPaneClient.Bottom);
634                path.AddLine(rectPaneClient.Left, rectPaneClient.Bottom, rectPaneClient.Left, rectTab.Bottom);
635                path.AddLine(rectPaneClient.Left, rectTab.Bottom, rectTab.Right, rectTab.Bottom);
636            }
637            return path;
638        }
639
640        private GraphicsPath GetOutline_ToolWindow(int index)
641        {
642            Rectangle rectTab = GetTabRectangle(index);
643            rectTab.Intersect(TabsRectangle);
644            rectTab = RectangleToScreen(DrawHelper.RtlTransform(this, rectTab));
645            int y = rectTab.Top;
646            Rectangle rectPaneClient = DockPane.RectangleToScreen(DockPane.ClientRectangle);
647
648            GraphicsPath path = new GraphicsPath();
649            GraphicsPath pathTab = GetTabOutline(Tabs[index], true, true);
650            path.AddPath(pathTab, true);
651            path.AddLine(rectTab.Left, rectTab.Top, rectPaneClient.Left, rectTab.Top);
652            path.AddLine(rectPaneClient.Left, rectTab.Top, rectPaneClient.Left, rectPaneClient.Top);
653            path.AddLine(rectPaneClient.Left, rectPaneClient.Top, rectPaneClient.Right, rectPaneClient.Top);
654            path.AddLine(rectPaneClient.Right, rectPaneClient.Top, rectPaneClient.Right, rectTab.Top);
655            path.AddLine(rectPaneClient.Right, rectTab.Top, rectTab.Right, rectTab.Top);
656            return path;
657        }
658
659    private void CalculateTabs()
660    {
661      if (Appearance == DockPane.AppearanceStyle.ToolWindow)
662        CalculateTabs_ToolWindow();
663      else
664        CalculateTabs_Document();
665    }
666
667    private void CalculateTabs_ToolWindow()
668    {
669      if (Tabs.Count <= 1 || DockPane.IsAutoHide)
670        return;
671
672      Rectangle rectTabStrip = TabStripRectangle;
673
674      // Calculate tab widths
675      int countTabs = Tabs.Count;
676            foreach (TabVS2005 tab in Tabs)
677            {
678                tab.MaxWidth = GetMaxTabWidth(Tabs.IndexOf(tab));
679                tab.Flag = false;
680            }
681
682      // Set tab whose max width less than average width
683      bool anyWidthWithinAverage = true;
684      int totalWidth = rectTabStrip.Width - ToolWindowStripGapLeft - ToolWindowStripGapRight;
685      int totalAllocatedWidth = 0;
686      int averageWidth = totalWidth / countTabs;
687      int remainedTabs = countTabs;
688      for (anyWidthWithinAverage=true; anyWidthWithinAverage && remainedTabs>0;)
689      {
690        anyWidthWithinAverage = false;
691        foreach (TabVS2005 tab in Tabs)
692        {
693          if (tab.Flag)
694            continue;
695
696          if (tab.MaxWidth <= averageWidth)
697          {
698            tab.Flag = true;
699            tab.TabWidth = tab.MaxWidth;
700            totalAllocatedWidth += tab.TabWidth;
701            anyWidthWithinAverage = true;
702            remainedTabs--;
703          }
704        }
705        if (remainedTabs != 0)
706          averageWidth = (totalWidth - totalAllocatedWidth) / remainedTabs;
707      }
708
709      // If any tab width not set yet, set it to the average width
710      if (remainedTabs > 0)
711      {
712        int roundUpWidth = (totalWidth - totalAllocatedWidth) - (averageWidth * remainedTabs);
713        foreach (TabVS2005 tab in Tabs)
714        {
715          if (tab.Flag)
716            continue;
717
718          tab.Flag = true;
719          if (roundUpWidth > 0)
720          {
721            tab.TabWidth = averageWidth + 1;
722            roundUpWidth --;
723          }
724          else
725            tab.TabWidth = averageWidth;
726        }
727      }
728
729      // Set the X position of the tabs
730      int x = rectTabStrip.X + ToolWindowStripGapLeft;
731      foreach (TabVS2005 tab in Tabs)
732      {
733        tab.TabX = x;
734        x += tab.TabWidth;
735      }
736    }
737
738        private bool CalculateDocumentTab(Rectangle rectTabStrip, ref int x, int index)
739        {
740            bool overflow = false;
741
742            TabVS2005 tab = Tabs[index] as TabVS2005;
743            tab.MaxWidth = GetMaxTabWidth(index);
744            int width = Math.Min(tab.MaxWidth, DocumentTabMaxWidth);
745            if (x + width < rectTabStrip.Right || index == StartDisplayingTab)
746            {
747                tab.TabX = x;
748                tab.TabWidth = width;
749                EndDisplayingTab = index;
750            }
751            else
752            {
753                tab.TabX = 0;
754                tab.TabWidth = 0;
755                overflow = true;
756            }
757            x += width;
758
759            return overflow;
760        }
761
762        /// <summary>
763        /// Calculate which tabs are displayed and in what order.
764        /// </summary>
765    private void CalculateTabs_Document()
766    {
767            if (m_startDisplayingTab >= Tabs.Count)
768                m_startDisplayingTab = 0;
769
770            Rectangle rectTabStrip = TabsRectangle;
771
772      int x = rectTabStrip.X + rectTabStrip.Height / 2;
773            bool overflow = false;
774
775            // Originally all new documents that were considered overflow
776            // (not enough pane strip space to show all tabs) were added to
777            // the far left (assuming not right to left) and the tabs on the
778            // right were dropped from view. If StartDisplayingTab is not 0
779            // then we are dealing with making sure a specific tab is kept in focus.
780            if (m_startDisplayingTab > 0)
781            {
782                int tempX = x;
783                TabVS2005 tab = Tabs[m_startDisplayingTab] as TabVS2005;
784                tab.MaxWidth = GetMaxTabWidth(m_startDisplayingTab);
785                int width = Math.Min(tab.MaxWidth, DocumentTabMaxWidth);
786
787                // Add the active tab and tabs to the left
788                for (int i = StartDisplayingTab; i >= 0; i--)
789                    CalculateDocumentTab(rectTabStrip, ref tempX, i);
790
791                // Store which tab is the first one displayed so that it
792                // will be drawn correctly (without part of the tab cut off)
793                FirstDisplayingTab = EndDisplayingTab;
794
795                tempX = x; // Reset X location because we are starting over
796               
797                // Start with the first tab displayed - name is a little misleading.
798                // Loop through each tab and set its location. If there is not enough
799                // room for all of them overflow will be returned.
800                for (int i = EndDisplayingTab; i < Tabs.Count; i++)
801                    overflow = CalculateDocumentTab(rectTabStrip, ref tempX, i);
802
803                // If not all tabs are shown then we have an overflow.
804                if (FirstDisplayingTab != 0)
805                    overflow = true;
806            }
807            else
808            {
809                for (int i = StartDisplayingTab; i < Tabs.Count; i++)
810                    overflow = CalculateDocumentTab(rectTabStrip, ref x, i);
811                for (int i = 0; i < StartDisplayingTab; i++)
812                    overflow = CalculateDocumentTab(rectTabStrip, ref x, i);
813
814                FirstDisplayingTab = StartDisplayingTab;
815            }
816
817            if (!overflow)
818            {
819                m_startDisplayingTab = 0;
820                FirstDisplayingTab = 0;
821                x = rectTabStrip.X + rectTabStrip.Height / 2;
822                foreach (TabVS2005 tab in Tabs)
823                {
824                    tab.TabX = x;
825                    x += tab.TabWidth;
826                }
827            }
828            DocumentTabsOverflow = overflow;
829    }
830
831        protected internal override void EnsureTabVisible(IDockContent content)
832    {
833            if (Appearance != DockPane.AppearanceStyle.Document || !Tabs.Contains(content))
834                return;
835
836            CalculateTabs();
837            EnsureDocumentTabVisible(content, true);
838    }
839
840        private bool EnsureDocumentTabVisible(IDockContent content, bool repaint)
841        {
842            int index = Tabs.IndexOf(content);
843            TabVS2005 tab = Tabs[index] as TabVS2005;
844            if (tab.TabWidth != 0)
845                return false;
846
847            StartDisplayingTab = index;
848            if (repaint)
849                Invalidate();
850
851            return true;
852        }
853
854    private int GetMaxTabWidth(int index)
855    {
856      if (Appearance == DockPane.AppearanceStyle.ToolWindow)
857        return GetMaxTabWidth_ToolWindow(index);
858      else
859        return GetMaxTabWidth_Document(index);
860    }
861
862    private int GetMaxTabWidth_ToolWindow(int index)
863    {
864      IDockContent content = Tabs[index].Content;
865      Size sizeString = TextRenderer.MeasureText(content.DockHandler.TabText, TextFont);
866      return ToolWindowImageWidth + sizeString.Width + ToolWindowImageGapLeft
867        + ToolWindowImageGapRight + ToolWindowTextGapRight;
868    }
869
870    private int GetMaxTabWidth_Document(int index)
871    {
872      IDockContent content = Tabs[index].Content;
873
874            int height = GetTabRectangle_Document(index).Height;
875
876            Size sizeText = TextRenderer.MeasureText(content.DockHandler.TabText, BoldFont, new Size(DocumentTabMaxWidth, height), DocumentTextFormat);
877
878      if (DockPane.DockPanel.ShowDocumentIcon)
879        return sizeText.Width + DocumentIconWidth + DocumentIconGapLeft + DocumentIconGapRight + DocumentTextGapRight;
880      else
881        return sizeText.Width + DocumentIconGapLeft + DocumentTextGapRight;
882    }
883
884    private void DrawTabStrip(Graphics g)
885    {
886      if (Appearance == DockPane.AppearanceStyle.Document)
887        DrawTabStrip_Document(g);
888      else
889        DrawTabStrip_ToolWindow(g);
890    }
891
892    private void DrawTabStrip_Document(Graphics g)
893    {
894      int count = Tabs.Count;
895      if (count == 0)
896        return;
897
898      Rectangle rectTabStrip = TabStripRectangle;
899
900            // Draw the tabs
901      Rectangle rectTabOnly = TabsRectangle;
902      Rectangle rectTab = Rectangle.Empty;
903            TabVS2005 tabActive = null;
904      g.SetClip(DrawHelper.RtlTransform(this, rectTabOnly));
905      for (int i=0; i<count; i++)
906      {
907        rectTab = GetTabRectangle(i);
908                if (Tabs[i].Content == DockPane.ActiveContent)
909                {
910                    tabActive = Tabs[i] as TabVS2005;
911                    continue;
912                }
913        if (rectTab.IntersectsWith(rectTabOnly))
914          DrawTab(g, Tabs[i] as TabVS2005, rectTab);
915      }
916
917            g.SetClip(rectTabStrip);
918
919            if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
920                g.DrawLine(PenDocumentTabActiveBorder, rectTabStrip.Left, rectTabStrip.Top + 1,
921                  rectTabStrip.Right, rectTabStrip.Top + 1);
922            else
923                g.DrawLine(PenDocumentTabActiveBorder, rectTabStrip.Left, rectTabStrip.Bottom - 1,
924                    rectTabStrip.Right, rectTabStrip.Bottom - 1);
925
926            g.SetClip(DrawHelper.RtlTransform(this, rectTabOnly));
927            if (tabActive != null)
928            {
929                rectTab = GetTabRectangle(Tabs.IndexOf(tabActive));
930                if (rectTab.IntersectsWith(rectTabOnly))
931                    DrawTab(g, tabActive, rectTab);
932            }
933    }
934
935    private void DrawTabStrip_ToolWindow(Graphics g)
936    {
937      Rectangle rectTabStrip = TabStripRectangle;
938
939      g.DrawLine(PenToolWindowTabBorder, rectTabStrip.Left, rectTabStrip.Top,
940        rectTabStrip.Right, rectTabStrip.Top);
941
942      for (int i=0; i<Tabs.Count; i++)
943        DrawTab(g, Tabs[i] as TabVS2005, GetTabRectangle(i));
944    }
945
946    private Rectangle GetTabRectangle(int index)
947    {
948      if (Appearance == DockPane.AppearanceStyle.ToolWindow)
949        return GetTabRectangle_ToolWindow(index);
950      else
951        return GetTabRectangle_Document(index);
952    }
953
954    private Rectangle GetTabRectangle_ToolWindow(int index)
955    {
956      Rectangle rectTabStrip = TabStripRectangle;
957
958      TabVS2005 tab = (TabVS2005)(Tabs[index]);
959      return new Rectangle(tab.TabX, rectTabStrip.Y, tab.TabWidth, rectTabStrip.Height);
960    }
961
962    private Rectangle GetTabRectangle_Document(int index)
963    {
964      Rectangle rectTabStrip = TabStripRectangle;
965      TabVS2005 tab = (TabVS2005)Tabs[index];
966
967            Rectangle rect = new Rectangle();
968            rect.X = tab.TabX;
969            rect.Width = tab.TabWidth;
970            rect.Height = rectTabStrip.Height - DocumentTabGapTop;
971
972            if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
973                rect.Y = rectTabStrip.Y + DocumentStripGapBottom;
974            else
975                rect.Y = rectTabStrip.Y + DocumentTabGapTop;
976
977      return rect;
978    }
979
980        private void DrawTab(Graphics g, TabVS2005 tab, Rectangle rect)
981    {
982      if (Appearance == DockPane.AppearanceStyle.ToolWindow)
983        DrawTab_ToolWindow(g, tab, rect);
984      else
985        DrawTab_Document(g, tab, rect);
986    }
987
988        private GraphicsPath GetTabOutline(Tab tab, bool rtlTransform, bool toScreen)
989        {
990            if (Appearance == DockPane.AppearanceStyle.ToolWindow)
991                return GetTabOutline_ToolWindow(tab, rtlTransform, toScreen);
992            else
993                return GetTabOutline_Document(tab, rtlTransform, toScreen, false);
994        }
995
996        private GraphicsPath GetTabOutline_ToolWindow(Tab tab, bool rtlTransform, bool toScreen)
997        {
998            Rectangle rect = GetTabRectangle(Tabs.IndexOf(tab));
999            if (rtlTransform)
1000                rect = DrawHelper.RtlTransform(this, rect);
1001            if (toScreen)
1002                rect = RectangleToScreen(rect);
1003
1004            DrawHelper.GetRoundedCornerTab(GraphicsPath, rect, false);
1005            return GraphicsPath;
1006        }
1007
1008        private GraphicsPath GetTabOutline_Document(Tab tab, bool rtlTransform, bool toScreen, bool full)
1009        {
1010            int curveSize = 6;
1011
1012            GraphicsPath.Reset();
1013            Rectangle rect = GetTabRectangle(Tabs.IndexOf(tab));
1014            if (rtlTransform)
1015                rect = DrawHelper.RtlTransform(this, rect);
1016            if (toScreen)
1017                rect = RectangleToScreen(rect);
1018
1019            // Draws the full angle piece for active content (or first tab)
1020            if (tab.Content == DockPane.ActiveContent || full || Tabs.IndexOf(tab) == FirstDisplayingTab)
1021            {
1022                if (RightToLeft == RightToLeft.Yes)
1023                {
1024                    if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1025                    {
1026                        // For some reason the next line draws a line that is not hidden like it is when drawing the tab strip on top.
1027                        // It is not needed so it has been commented out.
1028                        //GraphicsPath.AddLine(rect.Right, rect.Bottom, rect.Right + rect.Height / 2, rect.Bottom);
1029                        GraphicsPath.AddLine(rect.Right + rect.Height / 2, rect.Top, rect.Right - rect.Height / 2 + curveSize / 2, rect.Bottom - curveSize / 2);
1030                    }
1031                    else
1032                    {
1033                        GraphicsPath.AddLine(rect.Right, rect.Bottom, rect.Right + rect.Height / 2, rect.Bottom);
1034                        GraphicsPath.AddLine(rect.Right + rect.Height / 2, rect.Bottom, rect.Right - rect.Height / 2 + curveSize / 2, rect.Top + curveSize / 2);
1035                    }
1036                }
1037                else
1038                {
1039                    if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1040                    {
1041                        // For some reason the next line draws a line that is not hidden like it is when drawing the tab strip on top.
1042                        // It is not needed so it has been commented out.
1043                        //GraphicsPath.AddLine(rect.Left, rect.Top, rect.Left - rect.Height / 2, rect.Top);
1044                        GraphicsPath.AddLine(rect.Left - rect.Height / 2, rect.Top, rect.Left + rect.Height / 2 - curveSize / 2, rect.Bottom - curveSize / 2);
1045                    }
1046                    else
1047                    {
1048                        GraphicsPath.AddLine(rect.Left, rect.Bottom, rect.Left - rect.Height / 2, rect.Bottom);
1049                        GraphicsPath.AddLine(rect.Left - rect.Height / 2, rect.Bottom, rect.Left + rect.Height / 2 - curveSize / 2, rect.Top + curveSize / 2);
1050                    }
1051                }
1052            }
1053            // Draws the partial angle for non-active content
1054            else
1055            {
1056                if (RightToLeft == RightToLeft.Yes)
1057                {
1058                    if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1059                    {
1060                        GraphicsPath.AddLine(rect.Right, rect.Top, rect.Right, rect.Top + rect.Height / 2);
1061                        GraphicsPath.AddLine(rect.Right, rect.Top + rect.Height / 2, rect.Right - rect.Height / 2 + curveSize / 2, rect.Bottom - curveSize / 2);
1062                    }
1063                    else
1064                    {
1065                        GraphicsPath.AddLine(rect.Right, rect.Bottom, rect.Right, rect.Bottom - rect.Height / 2);
1066                        GraphicsPath.AddLine(rect.Right, rect.Bottom - rect.Height / 2, rect.Right - rect.Height / 2 + curveSize / 2, rect.Top + curveSize / 2);
1067                    }
1068                }
1069                else
1070                {
1071                    if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1072                    {
1073                        GraphicsPath.AddLine(rect.Left, rect.Top, rect.Left, rect.Top + rect.Height / 2);
1074                        GraphicsPath.AddLine(rect.Left, rect.Top + rect.Height / 2, rect.Left + rect.Height / 2 - curveSize / 2, rect.Bottom - curveSize / 2);
1075                    }
1076                    else
1077                    {
1078                        GraphicsPath.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Bottom - rect.Height / 2);
1079                        GraphicsPath.AddLine(rect.Left, rect.Bottom - rect.Height / 2, rect.Left + rect.Height / 2 - curveSize / 2, rect.Top + curveSize / 2);
1080                    }
1081                }
1082            }
1083
1084            if (RightToLeft == RightToLeft.Yes)
1085            {
1086                if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1087                {
1088                    // Draws the bottom horizontal line (short side)
1089                    GraphicsPath.AddLine(rect.Right - rect.Height / 2 - curveSize / 2, rect.Bottom, rect.Left + curveSize / 2, rect.Bottom);
1090
1091                    // Drawing the rounded corner is not necessary. The path is automatically connected
1092                    //GraphicsPath.AddArc(new Rectangle(rect.Left, rect.Top, curveSize, curveSize), 180, 90);
1093                }
1094                else
1095                {
1096                    // Draws the bottom horizontal line (short side)
1097                    GraphicsPath.AddLine(rect.Right - rect.Height / 2 - curveSize / 2, rect.Top, rect.Left + curveSize / 2, rect.Top);
1098                    GraphicsPath.AddArc(new Rectangle(rect.Left, rect.Top, curveSize, curveSize), 180, 90);
1099                }
1100            }
1101            else
1102            {
1103                if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1104                {
1105                    // Draws the bottom horizontal line (short side)
1106                    GraphicsPath.AddLine(rect.Left + rect.Height / 2 + curveSize / 2, rect.Bottom, rect.Right - curveSize / 2, rect.Bottom);
1107
1108                    // Drawing the rounded corner is not necessary. The path is automatically connected
1109                    //GraphicsPath.AddArc(new Rectangle(rect.Right - curveSize, rect.Bottom, curveSize, curveSize), 90, -90);
1110                }
1111                else
1112                {
1113                    // Draws the top horizontal line (short side)
1114                    GraphicsPath.AddLine(rect.Left + rect.Height / 2 + curveSize / 2, rect.Top, rect.Right - curveSize / 2, rect.Top);
1115
1116                    // Draws the rounded corner oppposite the angled side
1117                    GraphicsPath.AddArc(new Rectangle(rect.Right - curveSize, rect.Top, curveSize, curveSize), -90, 90);
1118                }
1119            }
1120
1121            if (Tabs.IndexOf(tab) != EndDisplayingTab &&
1122                (Tabs.IndexOf(tab) != Tabs.Count - 1 && Tabs[Tabs.IndexOf(tab) + 1].Content == DockPane.ActiveContent)
1123                && !full)
1124            {
1125                if (RightToLeft == RightToLeft.Yes)
1126                {
1127                    if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1128                    {
1129                        GraphicsPath.AddLine(rect.Left, rect.Bottom - curveSize / 2, rect.Left, rect.Bottom - rect.Height / 2);
1130                        GraphicsPath.AddLine(rect.Left, rect.Bottom - rect.Height / 2, rect.Left + rect.Height / 2, rect.Top);
1131                    }
1132                    else
1133                    {
1134                        GraphicsPath.AddLine(rect.Left, rect.Top + curveSize / 2, rect.Left, rect.Top + rect.Height / 2);
1135                        GraphicsPath.AddLine(rect.Left, rect.Top + rect.Height / 2, rect.Left + rect.Height / 2, rect.Bottom);
1136                    }
1137                }
1138                else
1139                {
1140                    if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1141                    {
1142                        GraphicsPath.AddLine(rect.Right, rect.Bottom - curveSize / 2, rect.Right, rect.Bottom - rect.Height / 2);
1143                        GraphicsPath.AddLine(rect.Right, rect.Bottom - rect.Height / 2, rect.Right - rect.Height / 2, rect.Top);
1144                    }
1145                    else
1146                    {
1147                        GraphicsPath.AddLine(rect.Right, rect.Top + curveSize / 2, rect.Right, rect.Top + rect.Height / 2);
1148                        GraphicsPath.AddLine(rect.Right, rect.Top + rect.Height / 2, rect.Right - rect.Height / 2, rect.Bottom);
1149                    }
1150                }
1151            }
1152            else
1153            {
1154                // Draw the vertical line opposite the angled side
1155                if (RightToLeft == RightToLeft.Yes)
1156                {
1157                    if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1158                        GraphicsPath.AddLine(rect.Left, rect.Bottom - curveSize / 2, rect.Left, rect.Top);
1159                    else
1160                        GraphicsPath.AddLine(rect.Left, rect.Top + curveSize / 2, rect.Left, rect.Bottom);
1161                }
1162                else
1163                {
1164                    if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
1165                        GraphicsPath.AddLine(rect.Right, rect.Bottom - curveSize / 2, rect.Right, rect.Top);
1166                    else
1167                        GraphicsPath.AddLine(rect.Right, rect.Top + curveSize / 2, rect.Right, rect.Bottom);
1168                }
1169            }
1170
1171            return GraphicsPath;
1172        }
1173
1174    private void DrawTab_ToolWindow(Graphics g, TabVS2005 tab, Rectangle rect)
1175    {
1176      Rectangle rectIcon = new Rectangle(
1177        rect.X + ToolWindowImageGapLeft,
1178        rect.Y + rect.Height - 1 - ToolWindowImageGapBottom - ToolWindowImageHeight,
1179        ToolWindowImageWidth, ToolWindowImageHeight);
1180      Rectangle rectText = rectIcon;
1181      rectText.X += rectIcon.Width + ToolWindowImageGapRight;
1182      rectText.Width = rect.Width - rectIcon.Width - ToolWindowImageGapLeft -
1183        ToolWindowImageGapRight - ToolWindowTextGapRight;
1184
1185            Rectangle rectTab = DrawHelper.RtlTransform(this, rect);
1186            rectText = DrawHelper.RtlTransform(this, rectText);
1187            rectIcon = DrawHelper.RtlTransform(this, rectIcon);
1188            GraphicsPath path = GetTabOutline(tab, true, false);
1189      if (DockPane.ActiveContent == tab.Content)
1190      {
1191                Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.StartColor;
1192                Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.EndColor;
1193                LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.LinearGradientMode;
1194        g.FillPath(new LinearGradientBrush(rectTab, startColor, endColor, gradientMode), path);
1195                g.DrawPath(PenToolWindowTabBorder, path);
1196
1197                Color textColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.TextColor;
1198                TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, TextFont, rectText, textColor, ToolWindowTextFormat);
1199      }
1200      else
1201      {
1202                Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.StartColor;
1203                Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.EndColor;
1204                LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.LinearGradientMode;
1205                g.FillPath(new LinearGradientBrush(rectTab, startColor, endColor, gradientMode), path);
1206
1207                if (Tabs.IndexOf(DockPane.ActiveContent) != Tabs.IndexOf(tab) + 1)
1208                {
1209                    Point pt1 = new Point(rect.Right, rect.Top + ToolWindowTabSeperatorGapTop);
1210                    Point pt2 = new Point(rect.Right, rect.Bottom - ToolWindowTabSeperatorGapBottom);
1211                    g.DrawLine(PenToolWindowTabBorder, DrawHelper.RtlTransform(this, pt1), DrawHelper.RtlTransform(this, pt2));
1212                }
1213
1214                Color textColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.TextColor;
1215                TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, TextFont, rectText, textColor, ToolWindowTextFormat);
1216      }
1217
1218      if (rectTab.Contains(rectIcon))
1219        g.DrawIcon(tab.Content.DockHandler.Icon, rectIcon);
1220    }
1221
1222    private void DrawTab_Document(Graphics g, TabVS2005 tab, Rectangle rect)
1223    {
1224            if (tab.TabWidth == 0)
1225                return;
1226
1227            Rectangle rectIcon = new Rectangle(
1228                rect.X + DocumentIconGapLeft,
1229                rect.Y + rect.Height - 1 - DocumentIconGapBottom - DocumentIconHeight,
1230                DocumentIconWidth, DocumentIconHeight);
1231            Rectangle rectText = rectIcon;
1232            if (DockPane.DockPanel.ShowDocumentIcon)
1233            {
1234                rectText.X += rectIcon.Width + DocumentIconGapRight;
1235                rectText.Y = rect.Y;
1236                rectText.Width = rect.Width - rectIcon.Width - DocumentIconGapLeft -
1237                    DocumentIconGapRight - DocumentTextGapRight;
1238                rectText.Height = rect.Height;
1239            }
1240            else
1241                rectText.Width = rect.Width - DocumentIconGapLeft - DocumentTextGapRight;
1242
1243            Rectangle rectTab = DrawHelper.RtlTransform(this, rect);
1244            Rectangle rectBack = DrawHelper.RtlTransform(this, rect);
1245            rectBack.Width += rect.X;
1246            rectBack.X = 0;
1247
1248            rectText = DrawHelper.RtlTransform(this, rectText);
1249            rectIcon = DrawHelper.RtlTransform(this, rectIcon);
1250            GraphicsPath path = GetTabOutline(tab, true, false);
1251            if (DockPane.ActiveContent == tab.Content)
1252            {
1253                Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.StartColor;
1254                Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.EndColor;
1255                LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.LinearGradientMode;
1256                g.FillPath(new LinearGradientBrush(rectBack, startColor, endColor, gradientMode), path);
1257                g.DrawPath(PenDocumentTabActiveBorder, path);
1258
1259                Color textColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.TextColor;
1260                if (DockPane.IsActiveDocumentPane)
1261                    TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, BoldFont, rectText, textColor, DocumentTextFormat);
1262                else
1263                    TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, TextFont, rectText, textColor, DocumentTextFormat);
1264            }
1265            else
1266            {
1267                Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.StartColor;
1268                Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.EndColor;
1269                LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.LinearGradientMode;
1270                g.FillPath(new LinearGradientBrush(rectBack, startColor, endColor, gradientMode), path);
1271                g.DrawPath(PenDocumentTabInactiveBorder, path);
1272
1273                Color textColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.TextColor;
1274                TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, TextFont, rectText, textColor, DocumentTextFormat);
1275            }
1276
1277            if (rectTab.Contains(rectIcon) && DockPane.DockPanel.ShowDocumentIcon)
1278                g.DrawIcon(tab.Content.DockHandler.Icon, rectIcon);
1279        }
1280
1281        private Rectangle TabStripRectangle
1282        {
1283            get
1284            {
1285                if (Appearance == DockPane.AppearanceStyle.Document)
1286                    return TabStripRectangle_Document;
1287                else
1288                    return TabStripRectangle_ToolWindow;
1289            }
1290        }
1291
1292        private Rectangle TabStripRectangle_ToolWindow
1293        {
1294            get
1295            {
1296                Rectangle rect = ClientRectangle;
1297                return new Rectangle(rect.X, rect.Top + ToolWindowStripGapTop, rect.Width, rect.Height - ToolWindowStripGapTop - ToolWindowStripGapBottom);
1298            }
1299        }
1300
1301        private Rectangle TabStripRectangle_Document
1302        {
1303            get
1304            {
1305                Rectangle rect = ClientRectangle;
1306                return new Rectangle(rect.X, rect.Top + DocumentStripGapTop, rect.Width, rect.Height - DocumentStripGapTop - ToolWindowStripGapBottom);
1307            }
1308        }
1309
1310    private Rectangle TabsRectangle
1311    {
1312      get
1313      {
1314        if (Appearance == DockPane.AppearanceStyle.ToolWindow)
1315          return TabStripRectangle;
1316
1317        Rectangle rectWindow = TabStripRectangle;
1318        int x = rectWindow.X;
1319        int y = rectWindow.Y;
1320        int width = rectWindow.Width;
1321        int height = rectWindow.Height;
1322
1323        x += DocumentTabGapLeft;
1324        width -= DocumentTabGapLeft +
1325            DocumentTabGapRight +
1326            DocumentButtonGapRight +
1327            ButtonClose.Width +
1328            ButtonWindowList.Width +
1329            2 * DocumentButtonGapBetween;
1330
1331        return new Rectangle(x, y, width, height);
1332      }
1333    }
1334
1335        private ContextMenuStrip m_selectMenu;
1336        private ContextMenuStrip SelectMenu
1337        {
1338            get { return m_selectMenu; }
1339        }
1340
1341        private void WindowList_Click(object sender, EventArgs e)
1342        {
1343            int x = 0;
1344            int y = ButtonWindowList.Location.Y + ButtonWindowList.Height;
1345
1346            SelectMenu.Items.Clear();
1347            foreach (TabVS2005 tab in Tabs)
1348            {
1349                IDockContent content = tab.Content;
1350                ToolStripItem item = SelectMenu.Items.Add(content.DockHandler.TabText, content.DockHandler.Icon.ToBitmap());
1351                item.Tag = tab.Content;
1352                item.Click += new EventHandler(ContextMenuItem_Click);
1353            }
1354            SelectMenu.Show(ButtonWindowList, x, y);
1355        }
1356
1357        private void ContextMenuItem_Click(object sender, EventArgs e)
1358        {
1359            ToolStripMenuItem item = sender as ToolStripMenuItem;
1360            if (item != null)
1361            {
1362                IDockContent content = (IDockContent)item.Tag;
1363                DockPane.ActiveContent = content;
1364            }
1365    }
1366 
1367    private void SetInertButtons()
1368    {
1369            if (Appearance == DockPane.AppearanceStyle.ToolWindow)
1370            {
1371                if (m_buttonClose != null)
1372                    m_buttonClose.Left = -m_buttonClose.Width;
1373
1374                if (m_buttonWindowList != null)
1375                    m_buttonWindowList.Left = -m_buttonWindowList.Width;
1376            }
1377            else
1378            {
1379                bool showCloseButton = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButton;
1380                ButtonClose.Enabled = showCloseButton;
1381                ButtonClose.Visible = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButtonVisible;
1382                ButtonClose.RefreshChanges();
1383                ButtonWindowList.RefreshChanges();
1384            }
1385    }
1386
1387    protected override void OnLayout(LayoutEventArgs levent)
1388    {
1389            if (Appearance != DockPane.AppearanceStyle.Document)
1390            {
1391                base.OnLayout(levent);
1392                return;
1393            }
1394
1395      Rectangle rectTabStrip = TabStripRectangle;
1396
1397            // Set position and size of the buttons
1398      int buttonWidth = ButtonClose.Image.Width;
1399      int buttonHeight = ButtonClose.Image.Height;
1400            int height = rectTabStrip.Height - DocumentButtonGapTop - DocumentButtonGapBottom;
1401      if (buttonHeight < height)
1402      {
1403        buttonWidth = buttonWidth * (height / buttonHeight);
1404        buttonHeight = height;
1405      }
1406      Size buttonSize = new Size(buttonWidth, buttonHeight);
1407
1408      int x = rectTabStrip.X + rectTabStrip.Width - DocumentTabGapLeft
1409        - DocumentButtonGapRight - buttonWidth;
1410      int y = rectTabStrip.Y + DocumentButtonGapTop;
1411            Point point = new Point(x, y);
1412      ButtonClose.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
1413           
1414            // If the close button is not visible draw the window list button overtop.
1415            // Otherwise it is drawn to the left of the close button.
1416            if (ButtonClose.Visible)
1417          point.Offset(-(DocumentButtonGapBetween + buttonWidth), 0);
1418           
1419            ButtonWindowList.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
1420
1421      OnRefreshChanges();
1422
1423      base.OnLayout (levent);
1424    }
1425
1426    private void Close_Click(object sender, EventArgs e)
1427    {
1428      DockPane.CloseActiveContent();
1429    }
1430
1431    protected internal override int HitTest(Point ptMouse)
1432    {
1433      Rectangle rectTabStrip = TabsRectangle;
1434            if (!TabsRectangle.Contains(ptMouse))
1435                return -1;
1436
1437            foreach (Tab tab in Tabs)
1438            {
1439                GraphicsPath path = GetTabOutline(tab, true, false);
1440                if (path.IsVisible(ptMouse))
1441                    return Tabs.IndexOf(tab);
1442            }
1443            return -1;
1444    }
1445
1446    protected override void OnMouseHover(EventArgs e)
1447    {
1448      int index = HitTest(PointToClient(Control.MousePosition));
1449      string toolTip = string.Empty;
1450
1451      base.OnMouseHover(e);
1452
1453            if (index != -1)
1454      {
1455                TabVS2005 tab = Tabs[index] as TabVS2005;
1456                if (!String.IsNullOrEmpty(tab.Content.DockHandler.ToolTipText))
1457                    toolTip = tab.Content.DockHandler.ToolTipText;
1458                else if (tab.MaxWidth > tab.TabWidth)
1459                    toolTip = tab.Content.DockHandler.TabText;
1460      }
1461
1462      if (m_toolTip.GetToolTip(this) != toolTip)
1463      {
1464        m_toolTip.Active = false;
1465        m_toolTip.SetToolTip(this, toolTip);
1466        m_toolTip.Active = true;
1467      }
1468
1469            // requires further tracking of mouse hover behavior,
1470            ResetMouseEventArgs();
1471    }
1472
1473        protected override void OnRightToLeftChanged(EventArgs e)
1474        {
1475            base.OnRightToLeftChanged(e);
1476            PerformLayout();
1477        }
1478  }
1479}
Note: See TracBrowser for help on using the repository browser.