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