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)
30 using System.Windows.Forms.VisualStyles;
32 namespace System.Windows.Forms
34 public sealed class ScrollBarRenderer
36 #region Private Constructor
37 private ScrollBarRenderer () { }
40 #region Public Static Methods
41 public static void DrawArrowButton (Graphics g, Rectangle bounds, ScrollBarArrowButtonState state)
44 throw new InvalidOperationException ();
46 VisualStyleRenderer vsr;
49 case ScrollBarArrowButtonState.DownDisabled:
50 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled);
52 case ScrollBarArrowButtonState.DownHot:
53 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownHot);
55 case ScrollBarArrowButtonState.DownNormal:
57 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownNormal);
59 case ScrollBarArrowButtonState.DownPressed:
60 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownPressed);
62 case ScrollBarArrowButtonState.LeftDisabled:
63 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled);
65 case ScrollBarArrowButtonState.LeftHot:
66 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftHot);
68 case ScrollBarArrowButtonState.LeftNormal:
69 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftNormal);
71 case ScrollBarArrowButtonState.LeftPressed:
72 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftPressed);
74 case ScrollBarArrowButtonState.RightDisabled:
75 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightDisabled);
77 case ScrollBarArrowButtonState.RightHot:
78 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightHot);
80 case ScrollBarArrowButtonState.RightNormal:
81 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightNormal);
83 case ScrollBarArrowButtonState.RightPressed:
84 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightPressed);
86 case ScrollBarArrowButtonState.UpDisabled:
87 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpDisabled);
89 case ScrollBarArrowButtonState.UpHot:
90 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpHot);
92 case ScrollBarArrowButtonState.UpNormal:
93 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpNormal);
95 case ScrollBarArrowButtonState.UpPressed:
96 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpPressed);
100 vsr.DrawBackground(g, bounds);
103 public static void DrawHorizontalThumb (Graphics g, Rectangle bounds, ScrollBarState state)
106 throw new InvalidOperationException ();
108 VisualStyleRenderer vsr;
111 case ScrollBarState.Disabled:
112 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Disabled);
114 case ScrollBarState.Hot:
115 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot);
117 case ScrollBarState.Normal:
119 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal);
121 case ScrollBarState.Pressed:
122 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed);
126 vsr.DrawBackground (g, bounds);
129 public static void DrawHorizontalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state)
132 throw new InvalidOperationException ();
134 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperHorizontal.Normal);
136 vsr.DrawBackground (g, bounds);
139 public static void DrawLeftHorizontalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
142 throw new InvalidOperationException ();
144 VisualStyleRenderer vsr;
147 case ScrollBarState.Disabled:
148 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled);
150 case ScrollBarState.Hot:
151 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Hot);
153 case ScrollBarState.Normal:
155 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal);
157 case ScrollBarState.Pressed:
158 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Pressed);
162 vsr.DrawBackground (g, bounds);
165 public static void DrawLowerVerticalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
168 throw new InvalidOperationException ();
170 VisualStyleRenderer vsr;
173 case ScrollBarState.Disabled:
174 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled);
176 case ScrollBarState.Hot:
177 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Hot);
179 case ScrollBarState.Normal:
181 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Normal);
183 case ScrollBarState.Pressed:
184 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed);
188 vsr.DrawBackground (g, bounds);
191 public static void DrawRightHorizontalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
194 throw new InvalidOperationException ();
196 VisualStyleRenderer vsr;
199 case ScrollBarState.Disabled:
200 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled);
202 case ScrollBarState.Hot:
203 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Hot);
205 case ScrollBarState.Normal:
207 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal);
209 case ScrollBarState.Pressed:
210 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.RightTrackHorizontal.Pressed);
214 vsr.DrawBackground (g, bounds);
217 public static void DrawSizeBox (Graphics g, Rectangle bounds, ScrollBarSizeBoxState state)
220 throw new InvalidOperationException ();
222 VisualStyleRenderer vsr;
225 case ScrollBarSizeBoxState.LeftAlign:
227 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.LeftAlign);
229 case ScrollBarSizeBoxState.RightAlign:
230 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.RightAlign);
234 vsr.DrawBackground (g, bounds);
237 public static void DrawUpperVerticalTrack (Graphics g, Rectangle bounds, ScrollBarState state)
240 throw new InvalidOperationException ();
242 VisualStyleRenderer vsr;
245 case ScrollBarState.Disabled:
246 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Disabled);
248 case ScrollBarState.Hot:
249 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Hot);
251 case ScrollBarState.Normal:
253 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Normal);
255 case ScrollBarState.Pressed:
256 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.UpperTrackVertical.Pressed);
260 vsr.DrawBackground (g, bounds);
263 public static void DrawVerticalThumb (Graphics g, Rectangle bounds, ScrollBarState state)
266 throw new InvalidOperationException ();
268 VisualStyleRenderer vsr;
271 case ScrollBarState.Disabled:
272 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled);
274 case ScrollBarState.Hot:
275 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot);
277 case ScrollBarState.Normal:
279 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal);
281 case ScrollBarState.Pressed:
282 vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed);
286 vsr.DrawBackground (g, bounds);
289 public static void DrawVerticalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state)
292 throw new InvalidOperationException ();
294 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal); ;
296 vsr.DrawBackground (g, bounds);
299 public static Size GetSizeBoxSize (Graphics g, ScrollBarState state)
302 throw new InvalidOperationException ();
304 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.LeftAlign);
306 return vsr.GetPartSize(g, ThemeSizeType.Draw);
309 public static Size GetThumbGripSize (Graphics g, ScrollBarState state)
312 throw new InvalidOperationException ();
314 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal);
316 return vsr.GetPartSize (g, ThemeSizeType.Draw);
320 #region Public Static Properties
321 public static bool IsSupported {
322 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }