* Makefile: Don't build make-map.exe.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TabRenderer.cs
1 //
2 // TabRenderer.cs
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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.
22 //
23 // Copyright (c) 2006 Novell, Inc.
24 //
25 // Authors:
26 //      Jonathan Pobst (monkey@jpobst.com)
27 //
28
29 #if NET_2_0
30 using System.Drawing;
31 using System.Windows.Forms.VisualStyles;
32
33 namespace System.Windows.Forms
34 {
35         public sealed class TabRenderer
36         {
37                 #region Private Constructor
38                 private TabRenderer () { }
39                 #endregion
40
41                 #region Public Static Methods
42                 public static void DrawTabItem (Graphics g, Rectangle bounds, TabItemState state)
43                 {
44                         DrawTabItem(g, bounds, String.Empty, null, TextFormatFlags.Default, null, Rectangle.Empty, false, state);
45                 }
46
47                 public static void DrawTabItem (Graphics g, Rectangle bounds, bool focused, TabItemState state)
48                 {
49                         DrawTabItem (g, bounds, String.Empty, null, TextFormatFlags.Default, null, Rectangle.Empty, focused, state);
50                 }
51                 
52                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TabItemState state)
53                 {
54                         DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, null, Rectangle.Empty, false, state);
55                 }
56
57                 public static void DrawTabItem (Graphics g, Rectangle bounds, Image image, Rectangle imageRectangle, bool focused, TabItemState state)
58                 {
59                         DrawTabItem (g, bounds, String.Empty, null, TextFormatFlags.HorizontalCenter, image, imageRectangle, focused, state);
60                 }
61
62                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, bool focused, TabItemState state)
63                 {
64                         DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, null, Rectangle.Empty, focused, state);
65                 }
66
67                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, bool focused, TabItemState state)
68                 {
69                         DrawTabItem (g, bounds, tabItemText, font, flags, null, Rectangle.Empty, focused, state);
70                 }
71
72                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, Image image, Rectangle imageRectangle, bool focused, TabItemState state)
73                 {
74                         DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, image, imageRectangle, focused, state);
75                 }
76
77                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, Image image, Rectangle imageRectangle, bool focused, TabItemState state)
78                 {
79                         if (!IsSupported)
80                                 throw new InvalidOperationException ();
81                                 
82                         VisualStyleRenderer vsr;
83                         
84                         switch (state) {
85                                 case TabItemState.Disabled:
86                                         vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Disabled);
87                                         break;
88                                 case TabItemState.Hot:
89                                         vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Hot);
90                                         break;
91                                 case TabItemState.Normal:
92                                 default:
93                                         vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Normal);
94                                         break;
95                                 case TabItemState.Selected:
96                                         vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Pressed);
97                                         break;
98                         }
99
100                         vsr.DrawBackground (g, bounds);
101                         
102                         if(image != null)
103                                 vsr.DrawImage(g, imageRectangle, image);
104                                 
105                         bounds.Offset(3,3);
106                         bounds.Height -= 6;
107                         bounds.Width -= 6;
108                         
109                         if(tabItemText != String.Empty)
110                                 TextRenderer.DrawText(g, tabItemText, font, bounds, SystemColors.ControlText,flags);
111                                 
112                         if(focused)
113                                 ControlPaint.DrawFocusRectangle(g, bounds);
114                 }
115
116                 public static void DrawTabPage (Graphics g, Rectangle bounds)
117                 {
118                         if (!IsSupported)
119                                 throw new InvalidOperationException ();
120
121                         VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.Tab.Pane.Normal); ;
122
123                         vsr.DrawBackground (g, bounds);
124                 }
125                 #endregion
126                 
127                 #region Public Static Properties
128                 public static bool IsSupported {
129                         get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }
130                 }
131                 #endregion
132         }
133 }
134 #endif