* TabControl.cs: Show the tooltip depending on the value
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ScrollBarRenderer.cs
1 //
2 // ScrollBarRenderer.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 ScrollBarRenderer
36         {
37                 #region Private Constructor
38                 private ScrollBarRenderer () { }
39                 #endregion
40
41                 #region Public Static Methods
42                 public static void DrawArrowButton (Graphics g, Rectangle bounds, ScrollBarArrowButtonState state)
43                 {
44                         if (!IsSupported)
45                                 throw new InvalidOperationException ();
46
47                         VisualStyleRenderer vsr;
48
49                         switch (state) {
50                                 case ScrollBarArrowButtonState.DownDisabled:
51                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled);
52                                         break;
53                                 case ScrollBarArrowButtonState.DownHot:
54                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownHot);
55                                         break;
56                                 case ScrollBarArrowButtonState.DownNormal:
57                                 default:
58                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownNormal);
59                                         break;
60                                 case ScrollBarArrowButtonState.DownPressed:
61                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownPressed);
62                                         break;
63                                 case ScrollBarArrowButtonState.LeftDisabled:
64                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled);
65                                         break;
66                                 case ScrollBarArrowButtonState.LeftHot:
67                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftHot);
68                                         break;
69                                 case ScrollBarArrowButtonState.LeftNormal:
70                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftNormal);
71                                         break;
72                                 case ScrollBarArrowButtonState.LeftPressed:
73                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftPressed);
74                                         break;
75                                 case ScrollBarArrowButtonState.RightDisabled:
76                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightDisabled);
77                                         break;
78                                 case ScrollBarArrowButtonState.RightHot:
79                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightHot);
80                                         break;
81                                 case ScrollBarArrowButtonState.RightNormal:
82                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightNormal);
83                                         break;
84                                 case ScrollBarArrowButtonState.RightPressed:
85                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightPressed);
86                                         break;
87                                 case ScrollBarArrowButtonState.UpDisabled:
88                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpDisabled);
89                                         break;
90                                 case ScrollBarArrowButtonState.UpHot:
91                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpHot);
92                                         break;
93                                 case ScrollBarArrowButtonState.UpNormal:
94                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpNormal);
95                                         break;
96                                 case ScrollBarArrowButtonState.UpPressed:
97                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpPressed);
98                                         break;
99                         }
100                         
101                         vsr.DrawBackground(g, bounds);
102                 }
103
104                 public static void DrawHorizontalThumb (Graphics g, Rectangle bounds, ScrollBarState state)
105                 {
106                         if (!IsSupported)
107                                 throw new InvalidOperationException ();
108
109                         VisualStyleRenderer vsr;
110
111                         switch (state) {
112                                 case ScrollBarState.Disabled:
113                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Disabled);
114                                         break;
115                                 case ScrollBarState.Hot:
116                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot);
117                                         break;
118                                 case ScrollBarState.Normal:
119                                 default:
120                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal);
121                                         break;
122                                 case ScrollBarState.Pressed:
123                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed);
124                                         break;
125                         }
126
127                         vsr.DrawBackground (g, bounds);
128                 }
129
130                 public static void DrawHorizontalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state)
131                 {
132                         if (!IsSupported)
133                                 throw new InvalidOperationException ();
134
135                         VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperHorizontal.Normal);
136
137                         vsr.DrawBackground (g, bounds);
138                 }
139
140                 public static void DrawLeftHorizontalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
141                 {
142                         if (!IsSupported)
143                                 throw new InvalidOperationException ();
144
145                         VisualStyleRenderer vsr;
146
147                         switch (state) {
148                                 case ScrollBarState.Disabled:
149                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled);
150                                         break;
151                                 case ScrollBarState.Hot:
152                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Hot);
153                                         break;
154                                 case ScrollBarState.Normal:
155                                 default:
156                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal);
157                                         break;
158                                 case ScrollBarState.Pressed:
159                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Pressed);
160                                         break;
161                         }
162
163                         vsr.DrawBackground (g, bounds);
164                 }
165
166                 public static void DrawLowerVerticalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
167                 {
168                         if (!IsSupported)
169                                 throw new InvalidOperationException ();
170
171                         VisualStyleRenderer vsr;
172
173                         switch (state) {
174                                 case ScrollBarState.Disabled:
175                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled);
176                                         break;
177                                 case ScrollBarState.Hot:
178                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Hot);
179                                         break;
180                                 case ScrollBarState.Normal:
181                                 default:
182                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Normal);
183                                         break;
184                                 case ScrollBarState.Pressed:
185                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed);
186                                         break;
187                         }
188
189                         vsr.DrawBackground (g, bounds);
190                 }
191                 
192                 public static void DrawRightHorizontalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
193                 {
194                         if (!IsSupported)
195                                 throw new InvalidOperationException ();
196
197                         VisualStyleRenderer vsr;
198
199                         switch (state) {
200                                 case ScrollBarState.Disabled:
201                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled);
202                                         break;
203                                 case ScrollBarState.Hot:
204                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Hot);
205                                         break;
206                                 case ScrollBarState.Normal:
207                                 default:
208                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal);
209                                         break;
210                                 case ScrollBarState.Pressed:
211                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Pressed);
212                                         break;
213                         }
214
215                         vsr.DrawBackground (g, bounds);
216                 }
217
218                 public static void DrawSizeBox (Graphics g, Rectangle bounds, ScrollBarSizeBoxState state)
219                 {
220                         if (!IsSupported)
221                                 throw new InvalidOperationException ();
222
223                         VisualStyleRenderer vsr;
224
225                         switch (state) {
226                                 case ScrollBarSizeBoxState.LeftAlign:
227                                 default:
228                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.LeftAlign);
229                                         break;
230                                 case ScrollBarSizeBoxState.RightAlign:
231                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.RightAlign);
232                                         break;
233                         }
234
235                         vsr.DrawBackground (g, bounds);
236                 }
237
238                 public static void DrawUpperVerticalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
239                 {
240                         if (!IsSupported)
241                                 throw new InvalidOperationException ();
242
243                         VisualStyleRenderer vsr;
244
245                         switch (state) {
246                                 case ScrollBarState.Disabled:
247                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Disabled);
248                                         break;
249                                 case ScrollBarState.Hot:
250                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Hot);
251                                         break;
252                                 case ScrollBarState.Normal:
253                                 default:
254                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Normal);
255                                         break;
256                                 case ScrollBarState.Pressed:
257                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Pressed);
258                                         break;
259                         }
260
261                         vsr.DrawBackground (g, bounds);
262                 }
263
264                 public static void DrawVerticalThumb (Graphics g, Rectangle bounds, ScrollBarState state)
265                 {
266                         if (!IsSupported)
267                                 throw new InvalidOperationException ();
268
269                         VisualStyleRenderer vsr;
270
271                         switch (state) {
272                                 case ScrollBarState.Disabled:
273                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled);
274                                         break;
275                                 case ScrollBarState.Hot:
276                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot);
277                                         break;
278                                 case ScrollBarState.Normal:
279                                 default:
280                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal);
281                                         break;
282                                 case ScrollBarState.Pressed:
283                                         vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed);
284                                         break;
285                         }
286
287                         vsr.DrawBackground (g, bounds);
288                 }
289
290                 public static void DrawVerticalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state)
291                 {
292                         if (!IsSupported)
293                                 throw new InvalidOperationException ();
294
295                         VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal); ;
296
297                         vsr.DrawBackground (g, bounds);
298                 }
299
300                 public static Size GetSizeBoxSize (Graphics g, ScrollBarState state)
301                 {
302                         if (!IsSupported)
303                                 throw new InvalidOperationException ();
304
305                         VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.LeftAlign);
306                         
307                         return vsr.GetPartSize(g, ThemeSizeType.Draw);
308                 }
309
310                 public static Size GetThumbGripSize (Graphics g, ScrollBarState state)
311                 {
312                         if (!IsSupported)
313                                 throw new InvalidOperationException ();
314
315                         VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal);
316
317                         return vsr.GetPartSize (g, ThemeSizeType.Draw);
318                 }
319                 #endregion
320
321                 #region Public Static Properties
322                 public static bool IsSupported {
323                         get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }
324                 }
325                 #endregion
326         }
327 }
328 #endif