2 // ScrollBarRenderer.cs
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
26 // Jonathan Pobst (monkey@jpobst.com)
31 using System.Windows.Forms.VisualStyles;
33 namespace System.Windows.Forms
35 public sealed class ScrollBarRenderer
37 #region Private Constructor
38 private ScrollBarRenderer () { }
41 #region Public Static Methods
42 public static void DrawArrowButton (Graphics g, Rectangle bounds, ScrollBarArrowButtonState state)
45 throw new InvalidOperationException ();
47 VisualStyleRenderer vsr;
50 case ScrollBarArrowButtonState.DownDisabled:
51 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled);
53 case ScrollBarArrowButtonState.DownHot:
54 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownHot);
56 case ScrollBarArrowButtonState.DownNormal:
58 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownNormal);
60 case ScrollBarArrowButtonState.DownPressed:
61 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownPressed);
63 case ScrollBarArrowButtonState.LeftDisabled:
64 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled);
66 case ScrollBarArrowButtonState.LeftHot:
67 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftHot);
69 case ScrollBarArrowButtonState.LeftNormal:
70 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftNormal);
72 case ScrollBarArrowButtonState.LeftPressed:
73 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftPressed);
75 case ScrollBarArrowButtonState.RightDisabled:
76 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightDisabled);
78 case ScrollBarArrowButtonState.RightHot:
79 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightHot);
81 case ScrollBarArrowButtonState.RightNormal:
82 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightNormal);
84 case ScrollBarArrowButtonState.RightPressed:
85 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightPressed);
87 case ScrollBarArrowButtonState.UpDisabled:
88 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpDisabled);
90 case ScrollBarArrowButtonState.UpHot:
91 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpHot);
93 case ScrollBarArrowButtonState.UpNormal:
94 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpNormal);
96 case ScrollBarArrowButtonState.UpPressed:
97 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpPressed);
101 vsr.DrawBackground(g, bounds);
104 public static void DrawHorizontalThumb (Graphics g, Rectangle bounds, ScrollBarState state)
107 throw new InvalidOperationException ();
109 VisualStyleRenderer vsr;
112 case ScrollBarState.Disabled:
113 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Disabled);
115 case ScrollBarState.Hot:
116 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot);
118 case ScrollBarState.Normal:
120 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal);
122 case ScrollBarState.Pressed:
123 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed);
127 vsr.DrawBackground (g, bounds);
130 public static void DrawHorizontalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state)
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)
143 throw new InvalidOperationException ();
145 VisualStyleRenderer vsr;
148 case ScrollBarState.Disabled:
149 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled);
151 case ScrollBarState.Hot:
152 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Hot);
154 case ScrollBarState.Normal:
156 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal);
158 case ScrollBarState.Pressed:
159 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Pressed);
163 vsr.DrawBackground (g, bounds);
166 public static void DrawLowerVerticalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
169 throw new InvalidOperationException ();
171 VisualStyleRenderer vsr;
174 case ScrollBarState.Disabled:
175 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled);
177 case ScrollBarState.Hot:
178 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Hot);
180 case ScrollBarState.Normal:
182 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Normal);
184 case ScrollBarState.Pressed:
185 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed);
189 vsr.DrawBackground (g, bounds);
192 public static void DrawRightHorizontalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
195 throw new InvalidOperationException ();
197 VisualStyleRenderer vsr;
200 case ScrollBarState.Disabled:
201 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled);
203 case ScrollBarState.Hot:
204 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Hot);
206 case ScrollBarState.Normal:
208 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal);
210 case ScrollBarState.Pressed:
211 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Pressed);
215 vsr.DrawBackground (g, bounds);
218 public static void DrawSizeBox (Graphics g, Rectangle bounds, ScrollBarSizeBoxState state)
221 throw new InvalidOperationException ();
223 VisualStyleRenderer vsr;
226 case ScrollBarSizeBoxState.LeftAlign:
228 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.LeftAlign);
230 case ScrollBarSizeBoxState.RightAlign:
231 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.RightAlign);
235 vsr.DrawBackground (g, bounds);
238 public static void DrawUpperVerticalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
241 throw new InvalidOperationException ();
243 VisualStyleRenderer vsr;
246 case ScrollBarState.Disabled:
247 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Disabled);
249 case ScrollBarState.Hot:
250 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Hot);
252 case ScrollBarState.Normal:
254 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Normal);
256 case ScrollBarState.Pressed:
257 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Pressed);
261 vsr.DrawBackground (g, bounds);
264 public static void DrawVerticalThumb (Graphics g, Rectangle bounds, ScrollBarState state)
267 throw new InvalidOperationException ();
269 VisualStyleRenderer vsr;
272 case ScrollBarState.Disabled:
273 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled);
275 case ScrollBarState.Hot:
276 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot);
278 case ScrollBarState.Normal:
280 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal);
282 case ScrollBarState.Pressed:
283 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed);
287 vsr.DrawBackground (g, bounds);
290 public static void DrawVerticalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state)
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)
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)
313 throw new InvalidOperationException ();
315 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal);
317 return vsr.GetPartSize (g, ThemeSizeType.Draw);
321 #region Public Static Properties
322 public static bool IsSupported {
323 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }