4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Novell, Inc.
26 // Jonathan Pobst (monkey@jpobst.com)
31 using System.Windows.Forms.VisualStyles;
33 namespace System.Windows.Forms
35 public sealed class TabRenderer
37 #region Private Constructor
38 private TabRenderer () { }
41 #region Public Static Methods
42 public static void DrawTabItem (Graphics g, Rectangle bounds, TabItemState state)
44 DrawTabItem(g, bounds, String.Empty, null, TextFormatFlags.Default, null, Rectangle.Empty, false, state);
47 public static void DrawTabItem (Graphics g, Rectangle bounds, bool focused, TabItemState state)
49 DrawTabItem (g, bounds, String.Empty, null, TextFormatFlags.Default, null, Rectangle.Empty, focused, state);
52 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TabItemState state)
54 DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, null, Rectangle.Empty, false, state);
57 public static void DrawTabItem (Graphics g, Rectangle bounds, Image image, Rectangle imageRectangle, bool focused, TabItemState state)
59 DrawTabItem (g, bounds, String.Empty, null, TextFormatFlags.HorizontalCenter, image, imageRectangle, focused, state);
62 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, bool focused, TabItemState state)
64 DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, null, Rectangle.Empty, focused, state);
67 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, bool focused, TabItemState state)
69 DrawTabItem (g, bounds, tabItemText, font, flags, null, Rectangle.Empty, focused, state);
72 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, Image image, Rectangle imageRectangle, bool focused, TabItemState state)
74 DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, image, imageRectangle, focused, state);
77 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, Image image, Rectangle imageRectangle, bool focused, TabItemState state)
80 throw new InvalidOperationException ();
82 VisualStyleRenderer vsr;
85 case TabItemState.Disabled:
86 vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Disabled);
88 case TabItemState.Hot:
89 vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Hot);
91 case TabItemState.Normal:
93 vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Normal);
95 case TabItemState.Selected:
96 vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Pressed);
100 vsr.DrawBackground (g, bounds);
103 vsr.DrawImage(g, imageRectangle, image);
109 if(tabItemText != String.Empty)
110 TextRenderer.DrawText(g, tabItemText, font, bounds, SystemColors.ControlText,flags);
113 ControlPaint.DrawFocusRectangle(g, bounds);
116 public static void DrawTabPage (Graphics g, Rectangle bounds)
119 throw new InvalidOperationException ();
121 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.Tab.Pane.Normal); ;
123 vsr.DrawBackground (g, bounds);
127 #region Public Static Properties
128 public static bool IsSupported {
129 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }