New test.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TabRenderer.cs
1 //\r
2 // TabRenderer.cs\r
3 //\r
4 // Permission is hereby granted, free of charge, to any person obtaining\r
5 // a copy of this software and associated documentation files (the\r
6 // "Software"), to deal in the Software without restriction, including\r
7 // without limitation the rights to use, copy, modify, merge, publish,\r
8 // distribute, sublicense, and/or sell copies of the Software, and to\r
9 // permit persons to whom the Software is furnished to do so, subject to\r
10 // the following conditions:\r
11 // \r
12 // The above copyright notice and this permission notice shall be\r
13 // included in all copies or substantial portions of the Software.\r
14 // \r
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22 //\r
23 // Copyright (c) 2006 Novell, Inc.\r
24 //\r
25 // Authors:\r
26 //      Jonathan Pobst (monkey@jpobst.com)\r
27 //\r
28 \r
29 #if NET_2_0\r
30 using System.Drawing;\r
31 using System.Windows.Forms.VisualStyles;\r
32 \r
33 namespace System.Windows.Forms\r
34 {\r
35         public sealed class TabRenderer\r
36         {\r
37                 #region Private Constructor\r
38                 private TabRenderer () { }\r
39                 #endregion\r
40 \r
41                 #region Public Static Methods\r
42                 public static void DrawTabItem (Graphics g, Rectangle bounds, TabItemState state)\r
43                 {\r
44                         DrawTabItem(g, bounds, String.Empty, null, TextFormatFlags.Default, null, Rectangle.Empty, false, state);\r
45                 }\r
46 \r
47                 public static void DrawTabItem (Graphics g, Rectangle bounds, bool focused, TabItemState state)\r
48                 {\r
49                         DrawTabItem (g, bounds, String.Empty, null, TextFormatFlags.Default, null, Rectangle.Empty, focused, state);\r
50                 }\r
51                 \r
52                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TabItemState state)\r
53                 {\r
54                         DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, null, Rectangle.Empty, false, state);\r
55                 }\r
56 \r
57                 public static void DrawTabItem (Graphics g, Rectangle bounds, Image image, Rectangle imageRectangle, bool focused, TabItemState state)\r
58                 {\r
59                         DrawTabItem (g, bounds, String.Empty, null, TextFormatFlags.HorizontalCenter, image, imageRectangle, focused, state);\r
60                 }\r
61 \r
62                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, bool focused, TabItemState state)\r
63                 {\r
64                         DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, null, Rectangle.Empty, focused, state);\r
65                 }\r
66 \r
67                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, bool focused, TabItemState state)\r
68                 {\r
69                         DrawTabItem (g, bounds, tabItemText, font, flags, null, Rectangle.Empty, focused, state);\r
70                 }\r
71 \r
72                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, Image image, Rectangle imageRectangle, bool focused, TabItemState state)\r
73                 {\r
74                         DrawTabItem (g, bounds, tabItemText, font, TextFormatFlags.HorizontalCenter, image, imageRectangle, focused, state);\r
75                 }\r
76 \r
77                 public static void DrawTabItem (Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, Image image, Rectangle imageRectangle, bool focused, TabItemState state)\r
78                 {\r
79                         if (!IsSupported)\r
80                                 throw new InvalidOperationException ();\r
81                                 \r
82                         VisualStyleRenderer vsr;\r
83                         \r
84                         switch (state) {\r
85                                 case TabItemState.Disabled:\r
86                                         vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Disabled);\r
87                                         break;\r
88                                 case TabItemState.Hot:\r
89                                         vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Hot);\r
90                                         break;\r
91                                 case TabItemState.Normal:\r
92                                 default:\r
93                                         vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Normal);\r
94                                         break;\r
95                                 case TabItemState.Selected:\r
96                                         vsr = new VisualStyleRenderer (VisualStyleElement.Tab.TabItem.Pressed);\r
97                                         break;\r
98                         }\r
99 \r
100                         vsr.DrawBackground (g, bounds);\r
101                         \r
102                         if(image != null)\r
103                                 vsr.DrawImage(g, imageRectangle, image);\r
104                                 \r
105                         bounds.Offset(3,3);\r
106                         bounds.Height -= 6;\r
107                         bounds.Width -= 6;\r
108                         \r
109                         if(tabItemText != String.Empty)\r
110                                 TextRenderer.DrawText(g, tabItemText, font, bounds, SystemColors.ControlText,flags);\r
111                                 \r
112                         if(focused)\r
113                                 ControlPaint.DrawFocusRectangle(g, bounds);\r
114                 }\r
115 \r
116                 public static void DrawTabPage (Graphics g, Rectangle bounds)\r
117                 {\r
118                         if (!IsSupported)\r
119                                 throw new InvalidOperationException ();\r
120 \r
121                         VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.Tab.Pane.Normal); ;\r
122 \r
123                         vsr.DrawBackground (g, bounds);\r
124                 }\r
125                 #endregion\r
126                 \r
127                 #region Public Static Properties\r
128                 public static bool IsSupported {\r
129                         get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }\r
130                 }\r
131                 #endregion\r
132         }\r
133 }\r
134 #endif