2007-03-19 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ScrollBarRenderer.cs
blob0bc97c80bf90ed567f73868e4e300993337e5835
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.
23 // Copyright (c) 2006 Novell, Inc.
25 // Authors:
26 // Jonathan Pobst (monkey@jpobst.com)
29 #if NET_2_0
30 using System.Drawing;
31 using System.Windows.Forms.VisualStyles;
33 namespace System.Windows.Forms
35 public sealed class ScrollBarRenderer
37 #region Private Constructor
38 private ScrollBarRenderer () { }
39 #endregion
41 #region Public Static Methods
42 public static void DrawArrowButton (Graphics g, Rectangle bounds, ScrollBarArrowButtonState state)
44 if (!IsSupported)
45 throw new InvalidOperationException ();
47 VisualStyleRenderer vsr;
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;
101 vsr.DrawBackground(g, bounds);
104 public static void DrawHorizontalThumb (Graphics g, Rectangle bounds, ScrollBarState state)
106 if (!IsSupported)
107 throw new InvalidOperationException ();
109 VisualStyleRenderer vsr;
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;
127 vsr.DrawBackground (g, bounds);
130 public static void DrawHorizontalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state)
132 if (!IsSupported)
133 throw new InvalidOperationException ();
135 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperHorizontal.Normal);
137 vsr.DrawBackground (g, bounds);
140 public static void DrawLeftHorizontalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
142 if (!IsSupported)
143 throw new InvalidOperationException ();
145 VisualStyleRenderer vsr;
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;
163 vsr.DrawBackground (g, bounds);
166 public static void DrawLowerVerticalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
168 if (!IsSupported)
169 throw new InvalidOperationException ();
171 VisualStyleRenderer vsr;
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;
189 vsr.DrawBackground (g, bounds);
192 public static void DrawRightHorizontalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
194 if (!IsSupported)
195 throw new InvalidOperationException ();
197 VisualStyleRenderer vsr;
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;
215 vsr.DrawBackground (g, bounds);
218 public static void DrawSizeBox (Graphics g, Rectangle bounds, ScrollBarSizeBoxState state)
220 if (!IsSupported)
221 throw new InvalidOperationException ();
223 VisualStyleRenderer vsr;
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;
235 vsr.DrawBackground (g, bounds);
238 public static void DrawUpperVerticalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
240 if (!IsSupported)
241 throw new InvalidOperationException ();
243 VisualStyleRenderer vsr;
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;
261 vsr.DrawBackground (g, bounds);
264 public static void DrawVerticalThumb (Graphics g, Rectangle bounds, ScrollBarState state)
266 if (!IsSupported)
267 throw new InvalidOperationException ();
269 VisualStyleRenderer vsr;
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;
287 vsr.DrawBackground (g, bounds);
290 public static void DrawVerticalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state)
292 if (!IsSupported)
293 throw new InvalidOperationException ();
295 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal); ;
297 vsr.DrawBackground (g, bounds);
300 public static Size GetSizeBoxSize (Graphics g, ScrollBarState state)
302 if (!IsSupported)
303 throw new InvalidOperationException ();
305 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.LeftAlign);
307 return vsr.GetPartSize(g, ThemeSizeType.Draw);
310 public static Size GetThumbGripSize (Graphics g, ScrollBarState state)
312 if (!IsSupported)
313 throw new InvalidOperationException ();
315 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal);
317 return vsr.GetPartSize (g, ThemeSizeType.Draw);
319 #endregion
321 #region Public Static Properties
322 public static bool IsSupported {
323 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }
325 #endregion
328 #endif