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 TrackBarRenderer
36 #region Private Constructor
37 private TrackBarRenderer () { }
40 #region Public Static Methods
41 public static void DrawBottomPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state)
44 throw new InvalidOperationException ();
46 VisualStyleRenderer vsr;
49 case TrackBarThumbState.Disabled:
50 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Disabled);
52 case TrackBarThumbState.Hot:
53 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Hot);
55 case TrackBarThumbState.Normal:
57 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Normal);
59 case TrackBarThumbState.Pressed:
60 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Pressed);
64 vsr.DrawBackground (g, bounds);
67 public static void DrawHorizontalThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
70 throw new InvalidOperationException ();
72 VisualStyleRenderer vsr;
75 case TrackBarThumbState.Disabled:
76 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Disabled);
78 case TrackBarThumbState.Hot:
79 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Hot);
81 case TrackBarThumbState.Normal:
83 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Normal);
85 case TrackBarThumbState.Pressed:
86 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Pressed);
90 vsr.DrawBackground (g, bounds);
93 public static void DrawHorizontalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle)
96 throw new InvalidOperationException ();
98 if (bounds.Height <= 0 || bounds.Width <= 0 || numTicks <= 0)
101 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Ticks.Normal);
103 double x = bounds.Left;
104 double delta = (double)(bounds.Width - 2) / (double)(numTicks-1);
106 for(int i = 0; i < numTicks; i++)
108 vsr.DrawEdge(g, new Rectangle((int)Math.Round(x), bounds.Top, 5, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None);
113 public static void DrawHorizontalTrack(Graphics g, Rectangle bounds)
116 throw new InvalidOperationException ();
118 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Track.Normal);
120 vsr.DrawBackground (g, bounds);
123 public static void DrawLeftPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
126 throw new InvalidOperationException ();
128 VisualStyleRenderer vsr;
131 case TrackBarThumbState.Disabled:
132 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Disabled);
134 case TrackBarThumbState.Hot:
135 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Hot);
137 case TrackBarThumbState.Normal:
139 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Normal);
141 case TrackBarThumbState.Pressed:
142 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Pressed);
146 vsr.DrawBackground (g, bounds);
149 public static void DrawRightPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
152 throw new InvalidOperationException ();
154 VisualStyleRenderer vsr;
157 case TrackBarThumbState.Disabled:
158 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Disabled);
160 case TrackBarThumbState.Hot:
161 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Hot);
163 case TrackBarThumbState.Normal:
165 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Normal);
167 case TrackBarThumbState.Pressed:
168 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Pressed);
172 vsr.DrawBackground (g, bounds);
175 public static void DrawTopPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
178 throw new InvalidOperationException ();
180 VisualStyleRenderer vsr;
183 case TrackBarThumbState.Disabled:
184 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Disabled);
186 case TrackBarThumbState.Hot:
187 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Hot);
189 case TrackBarThumbState.Normal:
191 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Normal);
193 case TrackBarThumbState.Pressed:
194 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Pressed);
198 vsr.DrawBackground (g, bounds);
201 public static void DrawVerticalThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
204 throw new InvalidOperationException ();
206 VisualStyleRenderer vsr;
209 case TrackBarThumbState.Disabled:
210 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Disabled);
212 case TrackBarThumbState.Hot:
213 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Hot);
215 case TrackBarThumbState.Normal:
217 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Normal);
219 case TrackBarThumbState.Pressed:
220 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Pressed);
224 vsr.DrawBackground (g, bounds);
227 public static void DrawVerticalTicks (Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle)
230 throw new InvalidOperationException ();
232 if (bounds.Height <= 0 || bounds.Width <= 0 || numTicks <= 0)
235 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.TicksVertical.Normal);
237 double y = bounds.Top;
238 double delta = (double)(bounds.Height - 2) / (double)(numTicks - 1);
240 for (int i = 0; i < numTicks; i++) {
241 vsr.DrawEdge (g, new Rectangle (bounds.Left, (int)Math.Round (y), bounds.Width, 5), Edges.Top, edgeStyle, EdgeEffects.None);
246 public static void DrawVerticalTrack (Graphics g, Rectangle bounds)
249 throw new InvalidOperationException ();
251 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Track.Normal);
253 vsr.DrawBackground (g, bounds);
256 public static Size GetBottomPointingThumbSize(Graphics g, TrackBarThumbState state)
259 throw new InvalidOperationException ();
261 VisualStyleRenderer vsr;
264 case TrackBarThumbState.Disabled:
265 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Disabled);
267 case TrackBarThumbState.Hot:
268 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Hot);
270 case TrackBarThumbState.Normal:
272 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Normal);
274 case TrackBarThumbState.Pressed:
275 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Pressed);
279 return vsr.GetPartSize (g, ThemeSizeType.Draw);
282 public static Size GetLeftPointingThumbSize (Graphics g, TrackBarThumbState state)
285 throw new InvalidOperationException ();
287 VisualStyleRenderer vsr;
290 case TrackBarThumbState.Disabled:
291 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Disabled);
293 case TrackBarThumbState.Hot:
294 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Hot);
296 case TrackBarThumbState.Normal:
298 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Normal);
300 case TrackBarThumbState.Pressed:
301 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Pressed);
305 return vsr.GetPartSize (g, ThemeSizeType.Draw);
308 public static Size GetRightPointingThumbSize (Graphics g, TrackBarThumbState state)
311 throw new InvalidOperationException ();
313 VisualStyleRenderer vsr;
316 case TrackBarThumbState.Disabled:
317 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Disabled);
319 case TrackBarThumbState.Hot:
320 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Hot);
322 case TrackBarThumbState.Normal:
324 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Normal);
326 case TrackBarThumbState.Pressed:
327 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Pressed);
331 return vsr.GetPartSize (g, ThemeSizeType.Draw);
334 public static Size GetTopPointingThumbSize (Graphics g, TrackBarThumbState state)
337 throw new InvalidOperationException ();
339 VisualStyleRenderer vsr;
342 case TrackBarThumbState.Disabled:
343 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Disabled);
345 case TrackBarThumbState.Hot:
346 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Hot);
348 case TrackBarThumbState.Normal:
350 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Normal);
352 case TrackBarThumbState.Pressed:
353 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Pressed);
357 return vsr.GetPartSize (g, ThemeSizeType.Draw);
361 #region Public Static Properties
362 public static bool IsSupported {
363 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }